Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update breadcrumbs to show last 3 states for entire app #1471

Merged
merged 4 commits into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/frontend/chrome/chrome.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2 class="kd-logo-menu" flex="none">
<md-icon md-svg-icon="assets/images/kubernetes-logo-text.svg" class="kd-toolbar-logo">
</md-icon>
</h2>
<kd-breadcrumbs class="kd-actionbar-breadcrumbs" limit="2"
<kd-breadcrumbs class="kd-actionbar-breadcrumbs" limit="3"
flex="auto" layout="row"></kd-breadcrumbs>
<div flex="auto" ui-view="toolbar"></div>
<kd-actionbar></kd-actionbar>
Expand Down
45 changes: 44 additions & 1 deletion src/app/frontend/chrome/nav/nav_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,29 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';

/**
* @final
*/
export class NavService {
/**
* @param {!./../../common/state/futurestate_service.FutureStateService} kdFutureStateService
* @param {!ui.router.$state} $state
* @ngInject
*/
constructor() {
constructor(kdFutureStateService, $state) {
/** @private {!Array<string>} */
this.states_ = [];

/** @private {./nav_component.NavController} */
this.navComponent_ = null;

/** @private {!ui.router.$state} */
this.state_ = $state;

/** @private {!./../../common/state/futurestate_service.FutureStateService} */
this.kdFutureStateService_ = kdFutureStateService;
}

/**
Expand All @@ -31,6 +44,36 @@ export class NavService {
this.navComponent_ = navComponent;
}

/**
* Registers state in the global list of all nav states.
* @param {string} stateName
*/
registerState(stateName) {
this.states_.push(stateName);
}

/**
* Returns true when the given nav state is active.
* @param {string} stateName
* @return {boolean}
*/
isActive(stateName) {
let state = this.kdFutureStateService_.state;
while (state) {
let lastIndex = this.states_.lastIndexOf(state.name);
if (lastIndex !== -1) {
return this.states_[lastIndex] === stateName;
}

if (state.data && state.data[breadcrumbsConfig]) {
state = this.state_.get(state.data[breadcrumbsConfig]['parent']);
} else {
state = null;
}
}
return false;
}

/**
*/
toggle() {
Expand Down
28 changes: 10 additions & 18 deletions src/app/frontend/chrome/nav/navitem_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,29 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';

/**
* @final
*/
export class NavItemController {
/**
* @param {!ui.router.$state} $state
* @param {!./../../common/state/futurestate_service.FutureStateService} kdFutureStateService
* @param {!./nav_service.NavService} kdNavService
* @ngInject
*/
constructor($state, kdFutureStateService) {
constructor($state, kdNavService) {
/** @export {string} */
this.state;

/** @private {!ui.router.$state} */
this.state_ = $state;

/** @private {!./../../common/state/futurestate_service.FutureStateService} */
this.kdFutureStateService_ = kdFutureStateService;
/** @private {!./nav_service.NavService} */
this.kdNavService_ = kdNavService;
}

/** @export */
$onInit() {
this.kdNavService_.registerState(this.state);
}

/**
Expand All @@ -47,18 +50,7 @@ export class NavItemController {
* @export
*/
isActive() {
let state = this.kdFutureStateService_.state;
while (state) {
if (state.name === this.state) {
return true;
}
if (state && state.data && state.data[breadcrumbsConfig]) {
state = this.state_.get(state.data[breadcrumbsConfig]['parent']);
} else {
state = null;
}
}
return false;
return this.kdNavService_.isActive(this.state);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class BreadcrumbsService {
getParentState(state) {
let conf = this.getBreadcrumbConfig(state);
let result = null;

if (conf && conf.parent) {
if (typeof conf.parent === 'string') {
result = this.state_.get(conf.parent);
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/configmaplist/configmaplist_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as parentStateName} from 'config/state';

import {ConfigMapListController} from './configmaplist_controller';
import {stateName, stateUrl} from './configmaplist_state';
Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_CONFIG_MAPS_LABEL,
'parent': parentStateName,
},
},
views: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/daemonsetlist/daemonsetlist_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as workloadsStateName} from 'workloads/workloads_state';

import {DaemonSetListController} from './daemonsetlist_controller';
import {stateName, stateUrl} from './daemonsetlist_state';
Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_DAEMON_SETS_LABEL,
'parent': workloadsStateName,
},
},
views: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/deploymentlist/deploymentlist_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as workloadsStateName} from 'workloads/workloads_state';

import {DeploymentListController} from './deploymentlist_controller';
import {stateName, stateUrl} from './deploymentlist_state';
Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_DEPLOYMENTS_LABEL,
'parent': workloadsStateName,
},
},
views: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/ingresslist/list_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as parentStateName} from 'servicesanddiscovery/state';

import {IngressListController} from './list_controller';
import {stateName} from './list_state';
Expand All @@ -33,6 +34,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_INGRESSS_LABEL,
'parent': parentStateName,
},
},
views: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/joblist/joblist_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as workloadsStateName} from 'workloads/workloads_state';

import {JobListController} from './joblist_controller';
import {stateName, stateUrl} from './joblist_state';
Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_JOBS_LABEL,
'parent': workloadsStateName,
},
},
views: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/namespacelist/namespacelist_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {stateName as parentStateName} from 'admin/state';
import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';

Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_NAMESPACES_LABEL,
'parent': parentStateName,
},
},
views: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/nodelist/nodelist_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {stateName as parentStateName} from 'admin/state';
import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';

Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_NODES_LABEL,
'parent': parentStateName,
},
},
views: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {stateName as parentStateName} from 'admin/state';
import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';

Expand All @@ -33,6 +34,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_PERSISTENT_VOLUMES_LABEL,
'parent': parentStateName,
},
},
views: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/podlist/podlist_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as workloadsStateName} from 'workloads/workloads_state';

import {PodListController} from './podlist_controller';
import {stateName, stateUrl} from './podlist_state';
Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_PODS_LABEL,
'parent': workloadsStateName,
},
},
views: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/replicasetlist/replicasetlist_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as workloadsStateName} from 'workloads/workloads_state';

import {ReplicaSetListController} from './replicasetlist_controller';
import {stateName, stateUrl} from './replicasetlist_state';
Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_REPLICA_SETS_LABEL,
'parent': workloadsStateName,
},
},
views: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as workloadsStateName} from 'workloads/workloads_state';

import {ReplicationControllerListController} from './replicationcontrollerlist_controller';
import {stateName, stateUrl} from './replicationcontrollerlist_state';
Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_RC_LABEL,
'parent': workloadsStateName,
},
},
views: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/secretlist/list_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as parentStateName} from 'config/state';

import {SecretListController} from './list_controller';
import {stateName} from './list_state';
Expand All @@ -33,6 +34,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_SECRETS_LABEL,
'parent': parentStateName,
},
},
views: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/frontend/servicelist/servicelist_stateconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as parentStateName} from 'servicesanddiscovery/state';

import {ServiceListController} from './servicelist_controller';
import {stateName, stateUrl} from './servicelist_state';
Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_SERVICES_LABEL,
'parent': parentStateName,
},
},
views: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {stateName as chromeStateName} from 'chrome/chrome_state';
import {breadcrumbsConfig} from 'common/components/breadcrumbs/breadcrumbs_service';
import {stateName as workloadsStateName} from 'workloads/workloads_state';

import {StatefulSetListController} from './statefulsetlist_controller';
import {stateName, stateUrl} from './statefulsetlist_state';
Expand All @@ -34,6 +35,7 @@ export default function stateConfig($stateProvider) {
data: {
[breadcrumbsConfig]: {
'label': i18n.MSG_BREADCRUMBS_STATEFUL_SETS_LABEL,
'parent': workloadsStateName,
},
},
views: {
Expand Down
Loading