Skip to content

Commit 4f8bf0e

Browse files
committed
Merge pull request #782 from bryk/namespace-selector-frontend
Frontend for namespace selection
2 parents 07ace54 + 36e3397 commit 4f8bf0e

File tree

78 files changed

+742
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+742
-351
lines changed

i18n/messages-en.xtb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,6 @@
138138
<translation id="2586490478144382446" key="MSG_PET_SET_LIST_HEADER_PODS" source="/home/floreks/Projects/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: pods.">Pods</translation>
139139
<translation id="1017086337822469058" key="MSG_PET_SET_LIST_HEADER_AGE" source="/home/floreks/Projects/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: age.">Age</translation>
140140
<translation id="5744665687208066898" key="MSG_PET_SET_LIST_HEADER_IMAGES" source="/home/floreks/Projects/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: images.">Images</translation>
141+
<translation id="2997495891426796243" key="MSG_NAMESPACE_NOT_SELECTED" source="/usr/local/google/home/bryk/src/github.com/dashboard/.tmp/serve/app-dev.js" desc="Text for dropdown item that indicates that no namespace was selected">namespace not selected</translation>
142+
<translation id="5143266087600531180" key="MSG_NAMESPACE_SELECT_ARIA_LABEL" source="/usr/local/google/home/bryk/src/github.com/dashboard/.tmp/serve/app-dev.js" desc="Text describing what namespace selector is">Selector for namespaces</translation>
141143
</translationbundle>

i18n/messages-ja.xtb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,6 @@
138138
<translation id="2586490478144382446" key="MSG_PET_SET_LIST_HEADER_PODS" source="/home/floreks/Projects/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: pods.">Pods</translation>
139139
<translation id="1017086337822469058" key="MSG_PET_SET_LIST_HEADER_AGE" source="/home/floreks/Projects/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: age.">Age</translation>
140140
<translation id="5744665687208066898" key="MSG_PET_SET_LIST_HEADER_IMAGES" source="/home/floreks/Projects/dashboard/.tmp/serve/app-dev.js" desc="Pet set list header: images.">Images</translation>
141+
<translation id="2997495891426796243" key="MSG_NAMESPACE_NOT_SELECTED" source="/usr/local/google/home/bryk/src/github.com/dashboard/.tmp/serve/app-dev.js" desc="Text for dropdown item that indicates that no namespace was selected">namespace not selected</translation>
142+
<translation id="5143266087600531180" key="MSG_NAMESPACE_SELECT_ARIA_LABEL" source="/usr/local/google/home/bryk/src/github.com/dashboard/.tmp/serve/app-dev.js" desc="Text describing what namespace selector is">Selector for namespaces</translation>
141143
</translationbundle>

src/app/backend/resource/common/resourcechannels.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func GetDaemonSetListChannel(client client.DaemonSetsNamespacer,
333333
filteredItems = append(filteredItems, item)
334334
}
335335
}
336-
list.Items = filteredItems;
336+
list.Items = filteredItems
337337
for i := 0; i < numReads; i++ {
338338
channel.List <- list
339339
channel.Error <- err
@@ -366,8 +366,7 @@ func GetPetSetListChannel(client client.PetSetNamespacer,
366366
filteredItems = append(filteredItems, item)
367367
}
368368
}
369-
370-
petSets.Items = filteredItems;
369+
petSets.Items = filteredItems
371370
for i := 0; i < numReads; i++ {
372371
channel.List <- petSets
373372
channel.Error <- err

src/app/externs/uirouter.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2015 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @fileoverview Externs for angular UI router that are missing from official ones.
17+
*
18+
* @externs
19+
*/
20+
21+
const kdUiRouter = {};
22+
23+
/**
24+
* @constructor
25+
*/
26+
kdUiRouter.$stateProvider = function() {};
27+
28+
/**
29+
* @param {string} parent
30+
* @param {Function} callback
31+
*/
32+
kdUiRouter.$stateProvider.prototype.decorator = function(parent, callback) {};

src/app/frontend/chrome/chrome.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
<md-toolbar class="kd-toolbar">
1818
<div class="md-toolbar-tools kd-toolbar-tools">
19-
<a ui-sref="workload" ui-sref-opts="{ reload: true }" tabindex="-1">
19+
<a ng-href="{{ctrl.getLogoHref()}}" tabindex="-1">
2020
<md-icon md-svg-icon="assets/images/kubernetes-logo.svg" class="kd-toolbar-logo"></md-icon>
2121
</a>
2222
<h2>
2323
<span>kubernetes</span>
2424
</h2>
2525
<div flex="auto" ui-view="toolbar"></div>
26+
<kd-namespace-select></kd-namespace-select>
2627
</div>
2728
</md-toolbar>
2829

@@ -34,6 +35,8 @@ <h2>
3435
<md-progress-circular md-mode="indeterminate" md-diameter="96">
3536
</md-progress-circular>
3637
</div>
37-
<div ng-switch-when="false" ng-transclude class="kd-app-content"></div>
38+
<div ng-switch-when="false" class="kd-app-content">
39+
<div ui-view></div>
40+
</div>
3841
</div>
3942
</md-content>

src/app/frontend/chrome/chrome_controller.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import {actionbarViewName} from './chrome_state';
16+
import {stateName as workloadState} from 'workloads/workloads_state';
1617

1718
/**
1819
* Controller for the chrome directive.
@@ -22,9 +23,10 @@ import {actionbarViewName} from './chrome_state';
2223
export default class ChromeController {
2324
/**
2425
* @param {!ui.router.$state} $state
26+
* @param {!angular.Scope} $scope
2527
* @ngInject
2628
*/
27-
constructor($state) {
29+
constructor($state, $scope) {
2830
/**
2931
* By default this is true to show loading for the first page.
3032
* @export {boolean}
@@ -33,8 +35,16 @@ export default class ChromeController {
3335

3436
/** @private {!ui.router.$state} */
3537
this.state_ = $state;
38+
39+
this.registerStateChangeListeners($scope);
3640
}
3741

42+
/**
43+
* @return {string}
44+
* @export
45+
*/
46+
getLogoHref() { return this.state_.href(workloadState); }
47+
3848
/**
3949
* @return {boolean}
4050
* @export

src/app/frontend/chrome/chrome_directive.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/app/frontend/chrome/chrome_module.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import chromeDirective from './chrome_directive';
15+
import stateConfig from './chrome_stateconfig';
1616
import componentsModule from 'common/components/components_module';
17+
import namespaceModule from 'common/namespace/namespace_module';
1718

1819
/**
1920
* Angular module containing navigation chrome for the application.
@@ -25,5 +26,6 @@ export default angular
2526
'ngMaterial',
2627
'ui.router',
2728
componentsModule.name,
29+
namespaceModule.name,
2830
])
29-
.directive('chrome', chromeDirective);
31+
.config(stateConfig);

src/app/frontend/chrome/chrome_state.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
/**
16+
* Name of the namespace state. This state should be used as a parent state for all root states.
17+
* It provides gobal namespace option for all URLs.
18+
*/
19+
export const stateName = 'chrome';
20+
1521
/** Name of the view. Can be used in state config to define toolbar view */
1622
export const toolbarViewName = 'toolbar';
1723

@@ -20,3 +26,22 @@ export const toolbarViewName = 'toolbar';
2026
* be used for, e.g., breadcrumbs or view-specific action buttons.
2127
*/
2228
export const actionbarViewName = 'actionbar';
29+
30+
/**
31+
* Parameter name of the namespace selection param. Mostly for internal use.
32+
*/
33+
export const namespaceParam = 'namespace';
34+
35+
/**
36+
* All properties are @exported and in sync with URL param names.
37+
* @final
38+
*/
39+
export class StateParams {
40+
/**
41+
* @param {string|undefined} namespace
42+
*/
43+
constructor(namespace) {
44+
/** @export {string|undefined} */
45+
this.namespace = namespace;
46+
}
47+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2015 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import ChromeController from './chrome_controller';
16+
import {stateName, namespaceParam} from './chrome_state';
17+
18+
/**
19+
* Namespace is an abstract state with no path, but with one parameter ?namespace= that
20+
* is always accepted (since namespace is above all).
21+
*
22+
* This state must always be the root in a state tree. This is enforced during app startup.
23+
*
24+
* @param {!ui.router.$stateProvider|kdUiRouter.$stateProvider} $stateProvider
25+
* @ngInject
26+
*/
27+
export default function stateConfig($stateProvider) {
28+
$stateProvider.state(stateName, {
29+
url: `?${namespaceParam}`,
30+
abstract: true,
31+
templateUrl: 'chrome/chrome.html',
32+
controller: ChromeController,
33+
controllerAs: 'ctrl',
34+
});
35+
$stateProvider.decorator('parent', requireParentState);
36+
}
37+
38+
/**
39+
* @param {!Object} stateExtend
40+
* @param {function(?):!ui.router.$state} parentFn
41+
* @return {!ui.router.$state}
42+
*/
43+
function requireParentState(stateExtend, parentFn) {
44+
/** @type {!ui.router.$state} */
45+
let state = stateExtend['self'];
46+
if (!state.parent && state.name !== stateName) {
47+
throw new Error(
48+
`State "${state.name}" requires parent state to be set to ` +
49+
`${stateName}. This is likely a programming error.`);
50+
}
51+
return parentFn(stateExtend);
52+
}

0 commit comments

Comments
 (0)