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 update and restart buttons #1239

Merged
merged 2 commits into from
Jun 2, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class NodeListComponent implements OnInit, OnDestroy {
tabsData: TabButtonData[] = [];
options: MenuOptionData[] = [];
showDmsgInfo = false;
canLogOut = true;
hasUpdatableNodes = false;

// Vars for the pagination functionality.
allNodes: Node[];
Expand Down Expand Up @@ -138,13 +140,12 @@ export class NodeListComponent implements OnInit, OnDestroy {
route: ActivatedRoute,
) {
// Configure the options menu shown in the top bar.
this.updateOptionsMenu(true);
this.updateOptionsMenu();

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

// Show the dmsg info if the dmsg url was used.
Expand Down Expand Up @@ -233,18 +234,19 @@ export class NodeListComponent implements OnInit, OnDestroy {

/**
* Configures the options menu shown in the top bar.
* @param showLogoutOption If the logout option must be included.
*/
private updateOptionsMenu(showLogoutOption: boolean) {
this.options = [
{
private updateOptionsMenu() {
this.options = [];

if (this.hasUpdatableNodes) {
this.options.push({
name: 'nodes.update-all',
actionName: 'updateAll',
icon: 'get_app'
}
];
});
}

if (showLogoutOption) {
if (this.canLogOut) {
this.options.push({
name: 'common.logout',
actionName: 'logout',
Expand Down Expand Up @@ -366,6 +368,15 @@ export class NodeListComponent implements OnInit, OnDestroy {
// If the data was obtained.
if (result.data && !result.error) {
this.allNodes = result.data as Node[];

this.hasUpdatableNodes = false;
this.allNodes.forEach(node => {
if (GeneralUtils.checkIfTagIsUpdatable(node.buildTag)) {
this.hasUpdatableNodes = true;
}
});
this.updateOptionsMenu();

if (this.showDmsgInfo) {
// Add the label data to the array, to be able to use it for filtering and sorting.
this.allNodes.forEach(node => {
Expand Down Expand Up @@ -461,7 +472,7 @@ export class NodeListComponent implements OnInit, OnDestroy {

const nodesData: NodeData[] = [];
this.dataSource.forEach(node => {
if (node.online) {
if (node.online && GeneralUtils.checkIfTagIsUpdatable(node.buildTag)) {
nodesData.push({
key: node.localPk,
label: node.label,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';
import { Injector } from '@angular/core';

import { BasicTerminalComponent } from './basic-terminal/basic-terminal.component';
Expand All @@ -27,8 +26,11 @@ export class NodeActionsHelper {
private showingFullList: boolean;
private currentNode: Node;
private currentNodeKey: string;
private canBeUpdated = false;
private canBeRestarted = false;

options: MenuOptionData[] = [];

returnButtonText: string;

private rebootSubscription: Subscription;
Expand All @@ -39,7 +41,6 @@ export class NodeActionsHelper {
private router: Router;
private snackbarService: SnackbarService;
private nodeService: NodeService;
private translateService: TranslateService;
private storageService: StorageService;

constructor(injector: Injector, showingFullList: boolean) {
Expand All @@ -48,42 +49,63 @@ export class NodeActionsHelper {
this.router = injector.get(Router);
this.snackbarService = injector.get(SnackbarService);
this.nodeService = injector.get(NodeService);
this.translateService = injector.get(TranslateService);
this.storageService = injector.get(StorageService);

// Options for the menu shown in the top bar.
this.showingFullList = showingFullList;
this.returnButtonText = !showingFullList ? 'nodes.title' : 'node.title';

this.updateOptions();
}

/**
* Options for the menu shown in the top bar.
*/
private updateOptions() {
this.options = [
{
name: 'actions.menu.terminal',
actionName: 'terminal',
icon: 'laptop'
},
{
name: 'actions.menu.reboot',
actionName: 'reboot',
icon: 'rotate_right'
},
{
name: 'actions.menu.update',
actionName: 'update',
icon: 'get_app',
},
{
name: 'actions.menu.logs',
actionName: 'logs',
icon: 'subject',
}
];

this.showingFullList = showingFullList;
this.returnButtonText = !showingFullList ? 'nodes.title' : 'node.title';
if (this.canBeRestarted) {
this.options.push({
name: 'actions.menu.reboot',
actionName: 'reboot',
icon: 'rotate_right'
});
}

if (this.canBeUpdated) {
this.options.push({
name: 'actions.menu.update',
actionName: 'update',
icon: 'get_app',
});
}
}

/**
* Allows to set the data of the current node.
*/
setCurrentNode(currentNode: Node) {
this.currentNode = currentNode;

if (GeneralUtils.checkIfTagIsUpdatable(currentNode.buildTag)) {
this.canBeUpdated = true;
this.canBeRestarted = true;
} else {
this.canBeUpdated = false;
this.canBeRestarted = false;
}

this.updateOptions();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ export class NodeService {
node.online = response.online;
node.localPk = response.overview.local_pk;
node.autoconnectTransports = response.public_autoconnect;
node.buildTag = response.build_tag ? response.build_tag : '';

// Ip.
if (response.overview && response.overview.local_ip && (response.overview.local_ip as string).trim()) {
Expand Down
20 changes: 20 additions & 0 deletions static/skywire-manager-src/src/app/utils/generalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,24 @@ export default class GeneralUtils {

return dialog.open(ConfirmationComponent, config);
}

/**
* Checks the tag of a node, to know if the node is updatable via API calls.
*/
static checkIfTagIsUpdatable(tag: string) {
if (
tag === undefined ||
tag === null ||
tag.toUpperCase() === 'Windows'.toUpperCase() ||
tag.toUpperCase() === 'Win'.toUpperCase() ||
tag.toUpperCase() === 'Mac'.toUpperCase() ||
tag.toUpperCase() === 'Macos'.toUpperCase() ||
tag.toUpperCase() === 'Mac OS'.toUpperCase() ||
tag.toUpperCase() === 'Darwin'.toUpperCase()
) {
return false;
}

return true;
}
}