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

Remove the logout option from the manager if not needed #596

Merged
merged 1 commit into from
Nov 7, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { TranslateService } from '@ngx-translate/core';

import { NodeService, BackendData } from '../../../services/node.service';
import { Node } from '../../../app.datatypes';
import { AuthService } from '../../../services/auth.service';
import { AuthService, AuthStates } from '../../../services/auth.service';
import { EditLabelComponent } from '../../layout/edit-label/edit-label.component';
import { StorageService, LabeledElementTypes } from '../../../services/storage.service';
import { TabButtonData, MenuOptionData } from '../../layout/top-bar/top-bar.component';
Expand Down Expand Up @@ -107,6 +107,7 @@ export class NodeListComponent implements OnInit, OnDestroy {
}
];

private authVerificationSubscription: Subscription;
private dataSubscription: Subscription;
private updateTimeSubscription: Subscription;
private updateSubscription: Subscription;
Expand Down Expand Up @@ -136,6 +137,16 @@ export class NodeListComponent implements OnInit, OnDestroy {
private translateService: TranslateService,
route: ActivatedRoute,
) {
// Configure the options menu shown in the top bar.
this.updateOptionsMenu(true);

// Check if logout button must be removed.
this.authVerificationSubscription = this.authService.checkLogin().subscribe(response => {
if (response === AuthStates.AuthDisabled) {
this.updateOptionsMenu(false);
}
});

// Show the dmsg info if the dmsg url was used.
this.showDmsgInfo = this.router.url.indexOf('dmsg') !== -1;

Expand Down Expand Up @@ -213,25 +224,33 @@ export class NodeListComponent implements OnInit, OnDestroy {
}
];

// Options for the menu shown in the top bar.
// Refresh the data after languaje changes, to ensure the labels used for filtering
// are updated.
this.languageSubscription = this.translateService.onLangChange.subscribe(() => {
this.nodeService.forceNodeListRefresh();
});
}

/**
* Configures the options menu shown in the top bar.
* @param showLogoutOption If the logout option must be included.
*/
private updateOptionsMenu(showLogoutOption: boolean) {
this.options = [
{
name: 'nodes.update-all',
actionName: 'updateAll',
icon: 'get_app'
},
{
name: 'common.logout',
actionName: 'logout',
icon: 'power_settings_new'
}
];

// Refresh the data after languaje changes, to ensure the labels used for filtering
// are updated.
this.languageSubscription = this.translateService.onLangChange.subscribe(() => {
this.nodeService.forceNodeListRefresh();
});
if (showLogoutOption) {
this.options.push({
name: 'common.logout',
actionName: 'logout',
icon: 'power_settings_new'
});
}
}

ngOnInit() {
Expand All @@ -250,6 +269,7 @@ export class NodeListComponent implements OnInit, OnDestroy {

ngOnDestroy() {
this.nodeService.stopRequestingNodeList();
this.authVerificationSubscription.unsubscribe();
this.dataSubscription.unsubscribe();
this.updateTimeSubscription.unsubscribe();
this.navigationsSubscription.unsubscribe();
Expand Down