Implemented update in ui

This commit is contained in:
Lukas Metzger 2018-04-29 19:40:57 +02:00
parent b77c8232f9
commit 8db7040211
8 changed files with 136 additions and 11 deletions

View file

@ -0,0 +1,12 @@
export class UpdateApitype {
public updateRequired = false;
public currentVersion = 0;
public targetVersion = 0;
constructor(init: Object) {
Object.assign(this, init);
}
}

View file

@ -1,3 +1,4 @@
import { UpdateComponent } from './pages/update/update.component';
import { EditCredentialsComponent } from './pages/edit-credentials/edit-credentials.component'; import { EditCredentialsComponent } from './pages/edit-credentials/edit-credentials.component';
import { NativeGuard } from './services/native-guard.service'; import { NativeGuard } from './services/native-guard.service';
import { LoggedOutGuard } from './services/logged-out-guard.service'; import { LoggedOutGuard } from './services/logged-out-guard.service';
@ -34,6 +35,10 @@ const routes: Routes = [
path: 'setup', path: 'setup',
component: SetupComponent component: SetupComponent
}, },
{
path: 'update',
component: UpdateComponent
},
{ {
path: '', path: '',
pathMatch: 'prefix', pathMatch: 'prefix',

View file

@ -1,19 +1,26 @@
import { UpdateOperation } from './operations/update.operations';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Component } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { StateService } from './services/state.service'; import { StateService } from './services/state.service';
import { SessionOperation } from './operations/session.operation'; import { SessionOperation } from './operations/session.operation';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
templateUrl: './app.component.html', templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'] styleUrls: ['./app.component.scss']
}) })
export class AppComponent { export class AppComponent implements OnInit {
constructor(public gs: StateService, private session: SessionOperation, private router: Router) { } constructor(public gs: StateService, private session: SessionOperation, private router: Router, private update: UpdateOperation) { }
public async onLogout() { async ngOnInit() {
await this.session.logout(); if (await this.update.updateRequired()) {
this.router.navigate(['/logout']); this.router.navigate(['/update']);
} }
}
public async onLogout() {
await this.session.logout();
this.router.navigate(['/logout']);
}
} }

View file

@ -1,3 +1,5 @@
import { UpdateOperation } from './operations/update.operations';
import { UpdateComponent } from './pages/update/update.component';
import { CredentialsOperation } from './operations/credentials.operations'; import { CredentialsOperation } from './operations/credentials.operations';
import { EditCredentialsComponent } from './pages/edit-credentials/edit-credentials.component'; import { EditCredentialsComponent } from './pages/edit-credentials/edit-credentials.component';
import { EditAuthAddComponent } from './pages/edit-auth/edit-auth-add.component'; import { EditAuthAddComponent } from './pages/edit-auth/edit-auth-add.component';
@ -74,7 +76,8 @@ import { SetupComponent } from './pages/setup/setup.component';
EditAuthLineComponent, EditAuthLineComponent,
EditAuthAddComponent, EditAuthAddComponent,
EditCredentialsComponent, EditCredentialsComponent,
SetupComponent SetupComponent,
UpdateComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
@ -91,6 +94,7 @@ import { SetupComponent } from './pages/setup/setup.component';
UsersOperation, UsersOperation,
RecordsOperation, RecordsOperation,
CredentialsOperation, CredentialsOperation,
UpdateOperation,
AuthGuard, AuthGuard,
AdminGuard, AdminGuard,
NativeGuard, NativeGuard,

View file

@ -0,0 +1,35 @@
import { UpdateApitype } from './../apitypes/Update.apitype';
import { PermissionApitype } from './../apitypes/Permission.apitype';
import { UserApitype } from './../apitypes/User.apitype';
import { ListApitype } from './../apitypes/List.apitype';
import { Injectable } from '@angular/core';
import { HttpService } from '../services/http.service';
import { StateService } from '../services/state.service';
import { SessionApitype } from '../apitypes/Session.apitype';
@Injectable()
export class UpdateOperation {
constructor(private http: HttpService, private gs: StateService) { }
public async updateRequired(): Promise<boolean> {
return (await this.updateStatus()).updateRequired;
}
public async updateStatus(): Promise<UpdateApitype> {
return new UpdateApitype(await this.http.get('/update'));
}
public async doUpgrade(): Promise<boolean | string> {
try {
await this.http.post('/update', { dummy: true });
return true;
} catch (e) {
if (e.response.status === 500) {
return e.response.data.error;
} else {
return e.message;
}
}
}
}

View file

@ -0,0 +1,14 @@
<div class="row">
<div class="col-12">
<p class="font-weight-bold">Update PDNS Manager</p>
<p>Upgrading from {{ currentVersion }} to {{ targetVersion }}.</p>
<app-alert *ngIf="errorMessage">
<app-alert-message>{{ errorMessage }}</app-alert-message>
</app-alert>
<button class="btn btn-primary" (click)="onSubmit()">Upgrade</button>
<app-fa-icon class="ml-3" icon="spinner" size=2 animate="pulse" [hidden]="!loading"></app-fa-icon>
</div>
</div>

View file

@ -0,0 +1,48 @@
import { UpdateOperation } from './../../operations/update.operations';
import { HttpService } from './../../services/http.service';
import { PasswordValidationUtil } from './../../utils/password-validation.util';
import { Router } from '@angular/router';
import { FormGroup, Validators, FormBuilder } from '@angular/forms';
import { OnInit, Component } from '@angular/core';
import { isString } from 'util';
@Component({
selector: 'app-update',
templateUrl: './update.component.html',
styleUrls: ['./update.component.scss']
})
export class UpdateComponent implements OnInit {
public errorMessage = '';
public loading = false;
public currentVersion = 0;
public targetVersion = 0;
constructor(private update: UpdateOperation, private router: Router) { }
async ngOnInit() {
const info = await this.update.updateStatus();
if (!info.updateRequired) {
this.router.navigate(['/']);
}
this.currentVersion = info.currentVersion;
this.targetVersion = info.targetVersion;
}
public async onSubmit() {
this.errorMessage = '';
this.loading = true;
const res = await this.update.doUpgrade();
if (res === true) {
this.router.navigate(['/']);
} else {
this.errorMessage = res.toString();
this.loading = false;
}
}
}