Added progress bar to file downloads

Added two new API calls, to update the server to a particular version and to get the updater status

You can now update through the UI, and a status dialog displays after
This commit is contained in:
Isaac Grynsztein
2020-04-02 21:53:08 -04:00
parent 458e4b45f8
commit c36867d368
17 changed files with 345 additions and 40 deletions

View File

@@ -0,0 +1,18 @@
<div style="display: block">
<div style="display: inline-block">
<ng-container i18n="Select a version">Select a version:</ng-container>
</div>
<div *ngIf="availableVersions" style="display: inline-block; margin-left: 15px;">
<mat-form-field>
<mat-select [(ngModel)]="selectedVersion">
<mat-option *ngFor="let version of availableVersionsFiltered" [value]="version['tag_name']">
{{version['tag_name'] + (version === latestStableRelease ? ' - Latest Stable' : '') + (version['tag_name'] === CURRENT_VERSION ? ' - Current Version' : '')}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div *ngIf="selectedVersion && selectedVersion !== CURRENT_VERSION" style="display: inline-block; margin-left: 15px;">
<button (click)="updateServer()" color="accent" mat-raised-button><mat-icon>update</mat-icon>&nbsp;&nbsp;
<ng-container *ngIf="selectedVersion > CURRENT_VERSION">Upgrade to</ng-container><ng-container *ngIf="selectedVersion < CURRENT_VERSION">Downgrade to</ng-container>&nbsp;{{selectedVersion}}</button>
</div>
</div>

View File

View File

@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { UpdaterComponent } from './updater.component';
describe('UpdaterComponent', () => {
let component: UpdaterComponent;
let fixture: ComponentFixture<UpdaterComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ UpdaterComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UpdaterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,62 @@
import { Component, OnInit } from '@angular/core';
import { PostsService } from 'app/posts.services';
import { CURRENT_VERSION } from 'app/consts';
import { MatDialog } from '@angular/material/dialog';
import { UpdateProgressDialogComponent } from 'app/dialogs/update-progress-dialog/update-progress-dialog.component';
@Component({
selector: 'app-updater',
templateUrl: './updater.component.html',
styleUrls: ['./updater.component.scss']
})
export class UpdaterComponent implements OnInit {
availableVersions = null;
availableVersionsFiltered = [];
versionsShowLimit = 5;
latestStableRelease = null;
selectedVersion = null;
CURRENT_VERSION = CURRENT_VERSION;
constructor(private postsService: PostsService, private dialog: MatDialog) { }
ngOnInit(): void {
this.getAvailableVersions();
}
updateServer() {
this.postsService.updateServer(this.selectedVersion).subscribe(res => {
if (res['success']) {
this.openUpdateProgressDialog();
}
});
}
getAvailableVersions() {
this.availableVersionsFiltered = [];
this.postsService.getAvailableRelease().subscribe(res => {
this.availableVersions = res;
for (let i = 0; i < this.availableVersions.length; i++) {
const currentVersion = this.availableVersions[i];
// if a stable release has not been found and the version is not "rc" (meaning it's stable) then set it as the stable release
if (!this.latestStableRelease && !currentVersion.tag_name.includes('rc')) {
this.latestStableRelease = currentVersion;
this.selectedVersion = this.latestStableRelease.tag_name;
}
if (this.latestStableRelease && i >= this.versionsShowLimit) {
break;
}
this.availableVersionsFiltered.push(currentVersion);
}
});
}
openUpdateProgressDialog() {
this.dialog.open(UpdateProgressDialogComponent, {
minWidth: '300px',
minHeight: '200px'
});
}
}