loading polish

This commit is contained in:
Drew Ansbacher
2021-06-30 17:31:57 -06:00
committed by Aiden McClelland
parent b761c3dabd
commit 44d58f3b6e
6 changed files with 90 additions and 51 deletions

View File

@@ -6,25 +6,31 @@
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content> <ion-content>
<div *ngIf="!stateService.dataDrive"> <div *ngIf="!stateService.dataDrive && dataDrives">
<h2 color="light">Select Data Drive</h2> <div *ngIf="!dataDrives.length">
<ion-card <h2 color="light">No data drives found</h2>
*ngFor="let drive of dataDrives" <p color="light">Please connect a data drive to your embassy and refresh the page.</p>
(click)="selectDrive(drive)" </div>
button="true" <div *ngIf="dataDrives.length">
[class.selected]="selectedDrive?.logicalname === drive.logicalname" <h2 color="light">Select Data Drive</h2>
color="light" <ion-card
> *ngFor="let drive of dataDrives"
<ion-card-header> (click)="selectDrive(drive)"
<ion-card-title>{{drive.logicalname}}</ion-card-title> button="true"
<ion-card-subtitle>{{drive.labels}}</ion-card-subtitle> [class.selected]="selectedDrive?.logicalname === drive.logicalname"
</ion-card-header> color="light"
>
<ion-card-content> <ion-card-header>
Currently using {{drive.used}} out of {{drive.capacity}} bytes. <ion-card-title>{{drive.logicalname}}</ion-card-title>
</ion-card-content> <ion-card-subtitle>{{drive.labels}}</ion-card-subtitle>
</ion-card> </ion-card-header>
<ion-button (click)="warn()" color="primary" [disabled]="!selectedDrive">Next</ion-button>
<ion-card-content>
Currently using {{drive.used}} out of {{drive.capacity}} bytes.
</ion-card-content>
</ion-card>
<ion-button (click)="warn()" color="primary" [disabled]="!selectedDrive">Next</ion-button>
</div>
</div> </div>
<div *ngIf="stateService.dataDrive"> <div *ngIf="stateService.dataDrive">
<ion-card <ion-card

View File

@@ -10,7 +10,7 @@ import { PasswordPage } from '../password/password.page'
styleUrls: ['home.page.scss'], styleUrls: ['home.page.scss'],
}) })
export class HomePage { export class HomePage {
dataDrives = [] dataDrives = null
selectedDrive: DataDrive = null selectedDrive: DataDrive = null
constructor( constructor(
@@ -22,8 +22,16 @@ export class HomePage {
) {} ) {}
async ngOnInit() { async ngOnInit() {
const loader = await this.loadingCtrl.create({
message: 'Selecting data drive'
})
if(!this.stateService.dataDrive) { if(!this.stateService.dataDrive) {
const loader = await this.loadingCtrl.create({
message: 'Fetching data drives'
})
await loader.present()
this.dataDrives = await this.apiService.getDataDrives() this.dataDrives = await this.apiService.getDataDrives()
loader.dismiss()
} }
} }
@@ -61,8 +69,17 @@ export class HomePage {
} }
async chooseDrive() { async chooseDrive() {
await this.apiService.selectDataDrive(this.selectedDrive.logicalname) const loader = await this.loadingCtrl.create({
this.stateService.dataDrive = this.selectedDrive message: 'Selecting data drive'
})
await loader.present()
try {
await this.apiService.selectDataDrive(this.selectedDrive.logicalname)
this.stateService.dataDrive = this.selectedDrive
} catch (e) {
} finally {
loader.dismiss()
}
} }
async presentPasswordModal() { async presentPasswordModal() {

View File

@@ -6,25 +6,32 @@
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content> <ion-content>
<div *ngIf="!stateService.recoveryDrive"> <div *ngIf="!stateService.recoveryDrive && dataDrives?.length">
<h2 color="light">Select Recovery Drive</h2> <div *ngIf="!dataDrives.length">
<ion-card <h2 color="light">No recovery drives found</h2>
*ngFor="let drive of dataDrives" <p color="light">Please connect a recovery drive to your embassy and refresh the page.</p>
(click)="selectDrive(drive)" </div>
button="true" <div>
[class.selected]="selectedDrive?.logicalname === drive.logicalname" <h2 color="light">Select Recovery Drive</h2>
color="light" <ion-card
> *ngFor="let drive of dataDrives"
<ion-card-header> (click)="selectDrive(drive)"
<ion-card-title>{{drive.logicalname}}</ion-card-title> button="true"
<ion-card-subtitle>{{drive.name}}</ion-card-subtitle> [class.selected]="selectedDrive?.logicalname === drive.logicalname"
</ion-card-header> color="light"
>
<ion-card-content> <ion-card-header>
Currently running {{drive.version}} <ion-card-title>{{drive.logicalname}}</ion-card-title>
</ion-card-content> <ion-card-subtitle>{{drive.name}}</ion-card-subtitle>
</ion-card> </ion-card-header>
<ion-button (click)="chooseDrive()" color="primary" [disabled]="!selectedDrive">Next</ion-button>
<ion-card-content>
Currently running {{drive.version}}
</ion-card-content>
</ion-card>
<ion-button (click)="chooseDrive()" color="primary" [disabled]="!selectedDrive">Next</ion-button>
</div>
</div> </div>
<div *ngIf="stateService.recoveryDrive"> <div *ngIf="stateService.recoveryDrive">
<h2>Progress: {{ 100 * stateService.dataProgress }}% <ion-spinner *ngIf="stateService.dataProgress !== 1"></ion-spinner> </h2> <h2>Progress: {{ 100 * stateService.dataProgress }}% <ion-spinner *ngIf="stateService.dataProgress !== 1"></ion-spinner> </h2>

View File

@@ -10,7 +10,7 @@ import { PasswordPage } from '../password/password.page'
styleUrls: ['recover.page.scss'], styleUrls: ['recover.page.scss'],
}) })
export class RecoverPage { export class RecoverPage {
dataDrives = [] dataDrives = null
selectedDrive: RecoveryDrive = null selectedDrive: RecoveryDrive = null
constructor( constructor(
@@ -23,7 +23,13 @@ export class RecoverPage {
async ngOnInit() { async ngOnInit() {
if(!this.stateService.recoveryDrive) { if(!this.stateService.recoveryDrive) {
const loader = await this.loadingCtrl.create({
message: 'Fetching recovery drives'
})
await loader.present()
this.dataDrives = await this.apiService.getRecoveryDrives() this.dataDrives = await this.apiService.getRecoveryDrives()
loader.dismiss()
} else { } else {
this.stateService.pollDataTransferProgress() this.stateService.pollDataTransferProgress()
} }

View File

@@ -14,14 +14,16 @@ export class MockApiService extends ApiService {
async getState() { async getState() {
await pauseFor(2000) await pauseFor(2000)
return { return {
'data-drive': null, 'data-drive':
// { // null,
// logicalname: 'name1', {
// labels: ['label 1', 'label 2'], logicalname: 'name1',
// capacity: 1600, labels: ['label 1', 'label 2'],
// used: 200, capacity: 1600,
// }, used: 200,
'recovery-drive': null, },
'recovery-drive':
null,
// { // {
// logicalname: 'name1', // logicalname: 'name1',
// version: '0.3.3', // version: '0.3.3',

View File

@@ -27,6 +27,8 @@ export class StateService {
} }
async pollDataTransferProgress() { async pollDataTransferProgress() {
await pauseFor(7000)
if ( if (
this.dataTransferProgress?.totalBytes && this.dataTransferProgress?.totalBytes &&
this.dataTransferProgress.bytesTransfered === this.dataTransferProgress.totalBytes this.dataTransferProgress.bytesTransfered === this.dataTransferProgress.totalBytes
@@ -40,7 +42,6 @@ export class StateService {
if (this.dataTransferProgress.totalBytes) { if (this.dataTransferProgress.totalBytes) {
this.dataProgress = this.dataTransferProgress.bytesTransfered / this.dataTransferProgress.totalBytes this.dataProgress = this.dataTransferProgress.bytesTransfered / this.dataTransferProgress.totalBytes
} }
await pauseFor(7000)
this.pollDataTransferProgress() this.pollDataTransferProgress()
} }
} }