diff --git a/setup-wizard/docs.txt b/setup-wizard/docs.txt index c413def83..9870613b2 100644 --- a/setup-wizard/docs.txt +++ b/setup-wizard/docs.txt @@ -12,19 +12,17 @@ setup.disk.list Response { logicalname: string - labels: string[] + partitions: { + logicalname: string + label: string | null + capacity: number + used: number | null + }[], capacity: number - used: number - }[] - -setup.recovery.list - Request - - Response - { - logicalname: string - version: string - name: string + 'embassy-os': { + version: string + name: string + } | null }[] setup.recovery.status diff --git a/setup-wizard/src/app/pages/embassy/embassy.page.html b/setup-wizard/src/app/pages/embassy/embassy.page.html index efb78da03..d3eba0d71 100644 --- a/setup-wizard/src/app/pages/embassy/embassy.page.html +++ b/setup-wizard/src/app/pages/embassy/embassy.page.html @@ -44,8 +44,8 @@

{{ drive.logicalname }}

-

{{ drive.labels.length ? drive.labels.join(' / ') : 'unnamed' }}

-

Using {{drive.used.toFixed(2)}} of {{drive.capacity.toFixed(2)}} GiB

+

{{ getLabelLabel(drive) }}

+

Using {{ getUsage(drive) }} of {{drive.capacity.toFixed(2)}} GiB

diff --git a/setup-wizard/src/app/pages/embassy/embassy.page.ts b/setup-wizard/src/app/pages/embassy/embassy.page.ts index 17df9fd24..afa262b27 100644 --- a/setup-wizard/src/app/pages/embassy/embassy.page.ts +++ b/setup-wizard/src/app/pages/embassy/embassy.page.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core' import { iosTransitionAnimation, LoadingController, ModalController, NavController } from '@ionic/angular' -import { ApiService, EmbassyDrive } from 'src/app/services/api/api.service' +import { ApiService, Drive } from 'src/app/services/api/api.service' import { StateService } from 'src/app/services/state.service' import { PasswordPage } from '../password/password.page' @@ -11,7 +11,7 @@ import { PasswordPage } from '../password/password.page' }) export class EmbassyPage { embassyDrives = [] - selectedDrive: EmbassyDrive = null + selectedDrive: Drive = null loading = true window = window @@ -24,11 +24,12 @@ export class EmbassyPage { ) {} async ngOnInit() { - this.embassyDrives = await this.apiService.getEmbassyDrives() + const drives = (await this.apiService.getDrives()).filter(d => !d['embassy-os']) + this.embassyDrives = (await this.apiService.getDrives()).filter(d => !d['embassy-os']) this.loading = false } - async chooseDrive(drive: EmbassyDrive) { + async chooseDrive(drive: Drive) { const modal = await this.modalController.create({ component: PasswordPage, componentProps: { @@ -62,4 +63,19 @@ export class EmbassyPage { }) await modal.present(); } + + getLabelLabel(drive: Drive) { + const labels = drive.partitions.map(p => p.label).filter(l => !!l) + return labels.length ? labels.join(' / ') : 'unnamed' + } + + getUsage(drive: Drive) { + let usage = 0 + drive.partitions.forEach(par => { + if(par.used) { + usage += par.used + } + }) + return usage.toFixed(2) + } } diff --git a/setup-wizard/src/app/pages/password/password.page.html b/setup-wizard/src/app/pages/password/password.page.html index baaf1d4a8..ada4e9352 100644 --- a/setup-wizard/src/app/pages/password/password.page.html +++ b/setup-wizard/src/app/pages/password/password.page.html @@ -11,7 +11,7 @@

Choose a password for your embassy. You will need it every time you log in. If you lose it you will be permanently locked out of your embassy.

-

Warning: After submit, any data currently stored on {{ embassyDrive.labels.length ? embassyDrive.labels.join(' / ') : embassyDrive.logicalname }} will be wiped.

+

Warning: After submit, any data currently stored on {{ getLabelLabel(embassyDrive) }} will be wiped.

Password: diff --git a/setup-wizard/src/app/pages/password/password.page.ts b/setup-wizard/src/app/pages/password/password.page.ts index 4b3af3f56..8066a3bf5 100644 --- a/setup-wizard/src/app/pages/password/password.page.ts +++ b/setup-wizard/src/app/pages/password/password.page.ts @@ -1,6 +1,6 @@ import { Component, Input } from '@angular/core' import { LoadingController, ModalController } from '@ionic/angular' -import { ApiService, EmbassyDrive, RecoveryDrive } from 'src/app/services/api/api.service' +import { ApiService, Drive } from 'src/app/services/api/api.service' import { StateService } from 'src/app/services/state.service' @Component({ @@ -9,8 +9,8 @@ import { StateService } from 'src/app/services/state.service' styleUrls: ['password.page.scss'], }) export class PasswordPage { - @Input() recoveryDrive: RecoveryDrive - @Input() embassyDrive: EmbassyDrive + @Input() recoveryDrive: Drive + @Input() embassyDrive: Drive pwError = '' password = '' @@ -53,7 +53,6 @@ export class PasswordPage { async submitPw () { this.validate() - console.log('here') if (this.password !== this.passwordVer) { this.verError="*passwords do not match" } @@ -84,4 +83,19 @@ export class PasswordPage { cancel () { this.modalController.dismiss() } + + getLabelLabel(drive: Drive) { + const labels = drive.partitions.map(p => p.label).filter(l => !!l) + return labels.length ? labels.join(' / ') : 'unnamed' + } + + getUsage(drive: Drive) { + let usage = 0 + drive.partitions.forEach(par => { + if(par.used) { + usage += par.used + } + }) + return usage + } } diff --git a/setup-wizard/src/app/pages/recover/recover.page.html b/setup-wizard/src/app/pages/recover/recover.page.html index e88b34651..38a45c3ec 100644 --- a/setup-wizard/src/app/pages/recover/recover.page.html +++ b/setup-wizard/src/app/pages/recover/recover.page.html @@ -44,17 +44,17 @@

{{ drive.logicalname }}

-

{{ drive.name }}

-

Embassy version: {{drive.version}}

+

{{ drive['embassy-os'].name }}

+

Embassy version: {{drive['embassy-os'].version}}

- - + + Next diff --git a/setup-wizard/src/app/pages/recover/recover.page.ts b/setup-wizard/src/app/pages/recover/recover.page.ts index 80481443e..2fdeb9cd5 100644 --- a/setup-wizard/src/app/pages/recover/recover.page.ts +++ b/setup-wizard/src/app/pages/recover/recover.page.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core' import { iosTransitionAnimation, ModalController, NavController } from '@ionic/angular' -import { ApiService, RecoveryDrive } from 'src/app/services/api/api.service' +import { ApiService, Drive } from 'src/app/services/api/api.service' import { StateService } from 'src/app/services/state.service' import { PasswordPage } from '../password/password.page' @@ -12,7 +12,7 @@ import { PasswordPage } from '../password/password.page' export class RecoverPage { passwords = {} recoveryDrives = [] - selectedDrive: RecoveryDrive = null + selectedDrive: Drive = null loading = true window = window @@ -24,11 +24,11 @@ export class RecoverPage { ) {} async ngOnInit() { - this.recoveryDrives = await this.apiService.getRecoveryDrives() + this.recoveryDrives = (await this.apiService.getDrives()).filter(d => !!d['embassy-os']) this.loading = false } - async chooseDrive(drive: RecoveryDrive) { + async chooseDrive(drive: Drive) { if (this.selectedDrive?.logicalname === drive.logicalname) { this.selectedDrive = null @@ -37,7 +37,7 @@ export class RecoverPage { this.selectedDrive = drive } - if (drive.version.startsWith('0.2') || this.passwords[drive.logicalname]) return + if (drive['embassy-os'].version.startsWith('0.2') || this.passwords[drive.logicalname]) return const modal = await this.modalController.create({ component: PasswordPage, diff --git a/setup-wizard/src/app/services/api/api.service.ts b/setup-wizard/src/app/services/api/api.service.ts index 7d8ce5a1d..7a2c75401 100644 --- a/setup-wizard/src/app/services/api/api.service.ts +++ b/setup-wizard/src/app/services/api/api.service.ts @@ -4,8 +4,7 @@ export abstract class ApiService { protected error$: Subject = new Subject(); watchError$ = this.error$.asObservable(); abstract verifyProductKey (key: string): Promise; - abstract getEmbassyDrives (): Promise; - abstract getRecoveryDrives (): Promise; + abstract getDrives (): Promise; abstract getDataTransferProgress (): Promise; abstract verifyRecoveryPassword (logicalname: string, password: string): Promise; abstract setupEmbassy (setupInfo: { @@ -30,15 +29,17 @@ export interface SetupEmbassyRes { "tor-address": string } -export interface EmbassyDrive { - logicalname: string; - labels: string[]; - capacity: number; - used: number; -} - -export interface RecoveryDrive { - logicalname: string; - version: string; - name: string; -} +export interface Drive { + logicalname: string + partitions: { + logicalname: string + label: string | null + capacity: number + used: number | null + }[], + capacity: number + 'embassy-os': { + version: string + name: string + } | null +}[] diff --git a/setup-wizard/src/app/services/api/live-api.service.ts b/setup-wizard/src/app/services/api/live-api.service.ts index 6eb217585..15d5e9f2f 100644 --- a/setup-wizard/src/app/services/api/live-api.service.ts +++ b/setup-wizard/src/app/services/api/live-api.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core' -import { ApiService, EmbassyDrive, RecoveryDrive, SetupEmbassyRes, TransferProgressRes, VerifyProductKeyRes } from './api.service' +import { ApiService, Drive, SetupEmbassyRes, TransferProgressRes, VerifyProductKeyRes } from './api.service' import { HttpService } from './http.service' @Injectable({ @@ -25,20 +25,13 @@ export class LiveApiService extends ApiService { }) } - async getEmbassyDrives() { - return this.http.rpcRequest({ + async getDrives() { + return this.http.rpcRequest({ method: 'setup.disk.list', params: {} }) } - async getRecoveryDrives() { - return this.http.rpcRequest({ - method: 'setup.recovery.list', - params: {} - }) - } - async verifyRecoveryPassword(logicalname, password) { return this.http.rpcRequest({ method: 'setup.recovery.test-password', diff --git a/setup-wizard/src/app/services/api/mock-api.service.ts b/setup-wizard/src/app/services/api/mock-api.service.ts index f288bff9d..6c5f87c51 100644 --- a/setup-wizard/src/app/services/api/mock-api.service.ts +++ b/setup-wizard/src/app/services/api/mock-api.service.ts @@ -27,20 +27,66 @@ export class MockApiService extends ApiService { } } - async getEmbassyDrives() { + async getDrives() { return [ { logicalname: 'Name1', - labels: ['label 1', 'label 2'], - capacity: 1600.66666, - used: 200.1255312, + partitions: [{ + logicalname: 'Name1', + label: 'label 1', + capacity: 100000, + used: 200.1255312 + }, { + logicalname: 'Name1', + label: 'label 2', + capacity: 50000, + used: 200.1255312 + }], + capacity: 150000, + 'embassy-os': null }, { logicalname: 'Name2', - labels: [], + partitions: [{ + logicalname: 'Name2', + label: null, + capacity: 1600.01234, + used: 0.00, + }], capacity: 1600.01234, - used: 0.00, + 'embassy-os': null + }, + { + logicalname: 'Name3', + partitions: [{ + logicalname: 'Name3', + label: 'label 1', + capacity: null, + used: null + }], + capacity: 100000, + 'embassy-os': { + version: '0.3.3', + name: 'My Embassy' + } + }, + { + logicalname: 'Name4', + partitions: [{ + logicalname: 'Name4', + label: null, + capacity: 10000, + used: null + }], + capacity: 10000, + 'embassy-os': { + version: '0.2.7', + name: 'My Embassy' + } } + + + ] } diff --git a/setup-wizard/src/app/services/state.service.ts b/setup-wizard/src/app/services/state.service.ts index 619f2d1ac..b6877a7d7 100644 --- a/setup-wizard/src/app/services/state.service.ts +++ b/setup-wizard/src/app/services/state.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core' import { BehaviorSubject } from 'rxjs'; -import { ApiService, EmbassyDrive, RecoveryDrive } from './api/api.service' +import { ApiService, Drive } from './api/api.service' @Injectable({ providedIn: 'root' @@ -8,9 +8,9 @@ import { ApiService, EmbassyDrive, RecoveryDrive } from './api/api.service' export class StateService { polling = false - embassyDrive: EmbassyDrive; + embassyDrive: Drive; embassyPassword: string - recoveryDrive: RecoveryDrive; + recoveryDrive: Drive; recoveryPassword: string dataTransferProgress: { bytesTransfered: number; totalBytes: number } | null; dataProgress = 0;