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

Improvements for the manager #655

Merged
merged 1 commit into from
Jan 14, 2021
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
7 changes: 6 additions & 1 deletion static/skywire-manager-src/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { StartComponent } from './components/pages/start/start.component';
import { LoginComponent } from './components/pages/login/login.component';
import { NodeListComponent } from './components/pages/node-list/node-list.component';
import { NodeComponent } from './components/pages/node/node.component';
Expand All @@ -15,6 +16,10 @@ import { NodeInfoComponent } from './components/pages/node/node-info/node-info.c
import { AllLabelsComponent } from './components/pages/settings/all-labels/all-labels.component';

const routes: Routes = [
{
path: '',
component: StartComponent
},
{
path: 'login',
component: LoginComponent
Expand Down Expand Up @@ -121,7 +126,7 @@ const routes: Routes = [
},
{
path: '**',
redirectTo: 'login'
redirectTo: ''
},
];

Expand Down
2 changes: 2 additions & 0 deletions static/skywire-manager-src/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { StartComponent } from './components/pages/start/start.component';
import { LoginComponent } from './components/pages/login/login.component';
import { NodeListComponent } from './components/pages/node-list/node-list.component';
import { NodeComponent } from './components/pages/node/node.component';
Expand Down Expand Up @@ -93,6 +94,7 @@ const globalRippleConfig: RippleGlobalOptions = {
@NgModule({
declarations: [
AppComponent,
StartComponent,
LoginComponent,
NodeListComponent,
NodeComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,16 @@ export class NodeListComponent implements OnInit, OnDestroy {
this.updateTimeSubscription.unsubscribe();
this.navigationsSubscription.unsubscribe();
this.languageSubscription.unsubscribe();
this.dataFiltererSubscription.unsubscribe();

if (this.updateSubscription) {
this.updateSubscription.unsubscribe();
}

this.dataSortedSubscription.unsubscribe();
this.dataSorter.dispose();

this.dataFiltererSubscription.unsubscribe();
this.dataFilterer.dispose();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ export class NodeAppsListComponent implements OnDestroy {
},
];

/**
* Indicates that, after updating the data, it has to be updated again after a small delay.
*/
private refreshAgain = false;

private navigationsSubscription: Subscription;
private operationSubscriptionsGroup: Subscription[] = [];

Expand Down Expand Up @@ -193,6 +198,7 @@ export class NodeAppsListComponent implements OnDestroy {
this.dataSortedSubscription.unsubscribe();
this.dataFiltererSubscription.unsubscribe();
this.dataSorter.dispose();
this.dataFilterer.dispose();
}

/**
Expand Down Expand Up @@ -238,7 +244,7 @@ export class NodeAppsListComponent implements OnDestroy {
*/
changeStateOfSelected(startApps: boolean) {
const elementsToChange: string[] = [];
// Ignore all elements shich already have the desired settings applied.
// Ignore all elements which already have the desired settings applied.
this.selections.forEach((val, key) => {
if (val) {
if ((startApps && this.appsMap.get(key).status !== 1) || (!startApps && this.appsMap.get(key).status === 1)) {
Expand Down Expand Up @@ -384,14 +390,22 @@ export class NodeAppsListComponent implements OnDestroy {
confirmationDialog.close();
}

// Make the parent page reload the data.
setTimeout(() => NodeComponent.refreshCurrentDisplayedData(), 50);
// Make the parent page reload the data and do it again after a small delay, to catch
// slow changes.
setTimeout(() => {
this.refreshAgain = true;
NodeComponent.refreshCurrentDisplayedData();
}, 50);
this.snackbarService.showDone('apps.operation-completed');
}, (err: OperationError) => {
err = processServiceError(err);

// Make the parent page reload the data.
setTimeout(() => NodeComponent.refreshCurrentDisplayedData(), 50);
// Make the parent page reload the data and do it again after a small delay, to catch
// slow changes.
setTimeout(() => {
this.refreshAgain = true;
NodeComponent.refreshCurrentDisplayedData();
}, 50);

if (confirmationDialog) {
confirmationDialog.componentInstance.showDone('confirmation.error-header-text', err.translatableErrorMsg);
Expand Down Expand Up @@ -474,6 +488,13 @@ export class NodeAppsListComponent implements OnDestroy {
}

this.dataSource = this.appsToShow;

// Refresh the data again after a small delay, if requested.
if (this.refreshAgain) {
this.refreshAgain = false;

setTimeout(() => NodeComponent.refreshCurrentDisplayedData(), 2000);
}
}

/**
Expand Down Expand Up @@ -532,16 +553,28 @@ export class NodeAppsListComponent implements OnDestroy {
if (confirmationDialog) {
confirmationDialog.close();
}
// Make the parent page reload the data.
setTimeout(() => NodeComponent.refreshCurrentDisplayedData(), 50);

// Make the parent page reload the data and do it again after a small delay, to catch
// slow changes.
setTimeout(() => {
this.refreshAgain = true;
NodeComponent.refreshCurrentDisplayedData();
}, 50);

this.snackbarService.showDone('apps.operation-completed');
} else {
this.changeAppsValRecursively(names, changingAutostart, newVal, confirmationDialog);
}
}, (err: OperationError) => {
err = processServiceError(err);

setTimeout(() => NodeComponent.refreshCurrentDisplayedData(), 50);
// Make the parent page reload the data and do it again after a small delay, to catch
// slow changes.
setTimeout(() => {
this.refreshAgain = true;
NodeComponent.refreshCurrentDisplayedData();
}, 50);

if (confirmationDialog) {
confirmationDialog.componentInstance.showDone('confirmation.error-header-text', err.translatableErrorMsg);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export class RouteListComponent implements OnDestroy {
this.dataSortedSubscription.unsubscribe();
this.dataFiltererSubscription.unsubscribe();
this.dataSorter.dispose();
this.dataFilterer.dispose();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="h-100 w-100">
<app-loading-indicator></app-loading-indicator>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';

import { AuthService, AuthStates } from '../../../services/auth.service';

/**
* Initial utility page for redirecting the user to the real appropriate initial page.
* It redirects to the login page if the user is unauthorized and to the visor list in
* all other cases.
*/
@Component({
selector: 'app-start',
templateUrl: './start.component.html',
styleUrls: ['./start.component.scss']
})
export class StartComponent implements OnInit, OnDestroy {
private verificationSubscription: Subscription;

constructor(
private authService: AuthService,
private router: Router,
) { }

ngOnInit() {
// Check if the user is unauthorized.
this.verificationSubscription = this.authService.checkLogin().subscribe(response => {
if (response !== AuthStates.NotLogged) {
this.router.navigate(['nodes'], { replaceUrl: true });
} else {
this.router.navigate(['login'], { replaceUrl: true });
}
}, () => {
// In case of error, go to the visor list. While trying to get the list, additional
// comprobations will be performed in that page.
this.router.navigate(['nodes'], { replaceUrl: true });
});
}

ngOnDestroy() {
this.verificationSubscription.unsubscribe();
}
}
13 changes: 4 additions & 9 deletions static/skywire-manager-src/src/app/services/node.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,11 @@ export class NodeService {

// Get for how many ms the saved data is still valid.
const momentOfLastCorrectUpdate = this.nodeListSubject.value ? this.nodeListSubject.value.momentOfLastCorrectUpdate : 0;
const remainingTime = this.calculateRemainingTime(momentOfLastCorrectUpdate);
let remainingTime = this.calculateRemainingTime(momentOfLastCorrectUpdate);
remainingTime = remainingTime > 0 ? remainingTime : 0;

if (remainingTime === 0) {
// Get the data from the backend.
this.nodeListSubject.next(null);
this.startDataSubscription(0, true);
} else {
// Use the data obtained the last time and schedule an update after the appropriate time.
this.startDataSubscription(remainingTime, true);
}
// Use the data obtained the last time and schedule an update after the appropriate time.
this.startDataSubscription(remainingTime, true);
}

/**
Expand Down