diff --git a/frontend/projects/ui/src/app/components/form-object/form-object.module.ts b/frontend/projects/ui/src/app/components/form-object/form-object.module.ts index 229015290..5c05aad36 100644 --- a/frontend/projects/ui/src/app/components/form-object/form-object.module.ts +++ b/frontend/projects/ui/src/app/components/form-object/form-object.module.ts @@ -6,7 +6,6 @@ import { SharedPipesModule } from '@start9labs/shared' import { TuiElasticContainerModule } from '@taiga-ui/kit' import { TuiExpandModule } from '@taiga-ui/core' import { EnumListPageModule } from 'src/app/modals/enum-list/enum-list.module' - import { FormLabelComponent } from './form-label/form-label.component' import { FormObjectComponent } from './form-object/form-object.component' import { FormUnionComponent } from './form-union/form-union.component' @@ -14,7 +13,6 @@ import { GetErrorPipe, ToWarningTextPipe, ToElementIdPipe, - GetControlPipe, ToEnumListDisplayPipe, ToRangePipe, } from './form-object.pipes' @@ -28,7 +26,6 @@ import { GetErrorPipe, ToEnumListDisplayPipe, ToElementIdPipe, - GetControlPipe, ToRangePipe, ], imports: [ diff --git a/frontend/projects/ui/src/app/components/form-object/form-object.pipes.ts b/frontend/projects/ui/src/app/components/form-object/form-object.pipes.ts index 8a8ad74f0..97b73a583 100644 --- a/frontend/projects/ui/src/app/components/form-object/form-object.pipes.ts +++ b/frontend/projects/ui/src/app/components/form-object/form-object.pipes.ts @@ -74,19 +74,3 @@ export class ToElementIdPipe implements PipeTransform { return getElementId(objectId, key, index) } } - -@Pipe({ - name: 'getControl', -}) -export class GetControlPipe implements PipeTransform { - transform( - formGroup: FormGroup, - key: string, - index?: number, - ): AbstractControl { - const abstractControl = formGroup.get(key)! - if (index !== undefined) - return (abstractControl as UntypedFormArray).at(index) - return abstractControl - } -} diff --git a/frontend/projects/ui/src/app/components/form-object/form-object/form-object.component.html b/frontend/projects/ui/src/app/components/form-object/form-object/form-object.component.html index 020539d8c..e787d7390 100644 --- a/frontend/projects/ui/src/app/components/form-object/form-object/form-object.component.html +++ b/frontend/projects/ui/src/app/components/form-object/form-object/form-object.component.html @@ -63,18 +63,14 @@

- + {{ errors | getError : $any(spec)['pattern-description'] }}

- + - -
+ + + + - + + + + + {{ spec.name }} + + (Edited) + + + +
+ + Browse... + - - -
-

{{ control.value.name }}

-
- + +
+

{{ control.value.name }}

+
+ +
-
- -
- +
+
+
+

+ + {{ errors | getError }} + +

+
@@ -242,7 +267,7 @@

- + {{ errors | getError }}

@@ -353,7 +378,7 @@

{{ errors | getError : $any(spec)['pattern-description'] }} @@ -396,7 +421,7 @@

- + {{ errors | getError }}

diff --git a/frontend/projects/ui/src/app/modals/app-config/app-config.page.ts b/frontend/projects/ui/src/app/modals/app-config/app-config.page.ts index 1a8f7bb26..0fae102f8 100644 --- a/frontend/projects/ui/src/app/modals/app-config/app-config.page.ts +++ b/frontend/projects/ui/src/app/modals/app-config/app-config.page.ts @@ -17,7 +17,6 @@ import { InputSpec } from 'start-sdk/types/config-types' import { DataModel, PackageDataEntry, - PackageState, } from 'src/app/services/patch-db/data-model' import { PatchDB } from 'patch-db-client' import { UntypedFormGroup } from '@angular/forms' @@ -139,32 +138,64 @@ export class AppConfigPage { this.saving = true + const config = this.configForm!.value + + const fileKeys = Object.keys(config).filter( + key => config[key] instanceof File, + ) + + let loader: HTMLIonLoadingElement | undefined + if (fileKeys.length) { + loader = await this.loadingCtrl.create({ + message: `Uploading File${fileKeys.length > 1 ? 's' : ''}...`, + }) + await loader.present() + + try { + const hashes = await Promise.all( + fileKeys.map(key => this.embassyApi.uploadFile(config[key])), + ) + fileKeys.forEach((key, i) => (config[key] = hashes[i])) + } catch (e: any) { + this.errToast.present(e) + } finally { + await loader.dismiss() + return + } + } + if (await hasCurrentDeps(this.patch, this.pkgId)) { - this.dryConfigure() + this.dryConfigure(config, loader) } else { - this.configure() + this.configure(config, loader) } } - private async dryConfigure() { - const loader = await this.loadingCtrl.create({ - message: 'Checking dependent services...', - }) - await loader.present() + private async dryConfigure( + config: Record, + loader?: HTMLIonLoadingElement, + ) { + const message = 'Checking dependent services...' + if (loader) { + loader.message = message + } else { + loader = await this.loadingCtrl.create({ message }) + await loader.present() + } try { const breakages = await this.embassyApi.drySetPackageConfig({ id: this.pkgId, - config: this.configForm!.value, + config, }) if (isEmptyObject(breakages)) { - this.configure(loader) + this.configure(config, loader) } else { await loader.dismiss() const proceed = await this.presentAlertBreakages(breakages) if (proceed) { - this.configure() + this.configure(config) } else { this.saving = false } @@ -176,7 +207,10 @@ export class AppConfigPage { } } - private async configure(loader?: HTMLIonLoadingElement) { + private async configure( + config: Record, + loader?: HTMLIonLoadingElement, + ) { const message = 'Saving...' if (loader) { loader.message = message @@ -188,7 +222,7 @@ export class AppConfigPage { try { await this.embassyApi.setPackageConfig({ id: this.pkgId, - config: this.configForm!.value, + config, }) this.modalCtrl.dismiss() } catch (e: any) { diff --git a/frontend/projects/ui/src/app/services/api/api.fixures.ts b/frontend/projects/ui/src/app/services/api/api.fixures.ts index c2bdd5d39..9e93cf71b 100644 --- a/frontend/projects/ui/src/app/services/api/api.fixures.ts +++ b/frontend/projects/ui/src/app/services/api/api.fixures.ts @@ -847,7 +847,7 @@ export module Mock { name: 'Needed File', type: 'file', description: 'A file we need', - placeholder: 'Testing placeholder', + placeholder: null, // @TODO delete warning: 'Testing warning', nullable: false, extensions: ['.png'], diff --git a/frontend/projects/ui/src/app/services/api/embassy-api.service.ts b/frontend/projects/ui/src/app/services/api/embassy-api.service.ts index c37fcc716..c11324eaf 100644 --- a/frontend/projects/ui/src/app/services/api/embassy-api.service.ts +++ b/frontend/projects/ui/src/app/services/api/embassy-api.service.ts @@ -30,7 +30,9 @@ export abstract class ApiService { abstract getStatic(url: string): Promise // for sideloading packages - abstract uploadPackage(guid: string, body: Blob): Promise + abstract uploadPackage(guid: string, body: Blob): Promise + + abstract uploadFile(body: Blob): Promise // db diff --git a/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts b/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts index 3ad146c69..73007227b 100644 --- a/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts +++ b/frontend/projects/ui/src/app/services/api/embassy-live-api.service.ts @@ -31,7 +31,7 @@ export class LiveApiService extends ApiService { private readonly patch: PatchDB, ) { super() - ; (window as any).rpcClient = this + ;(window as any).rpcClient = this } // for getting static files: ex icons, instructions, licenses @@ -44,7 +44,7 @@ export class LiveApiService extends ApiService { } // for sideloading packages - async uploadPackage(guid: string, body: Blob): Promise { + async uploadPackage(guid: string, body: Blob): Promise { return this.httpRequest({ method: Method.POST, body, @@ -53,6 +53,15 @@ export class LiveApiService extends ApiService { }) } + async uploadFile(body: Blob): Promise { + return this.httpRequest({ + method: Method.POST, + body, + url: `/rest/upload`, + responseType: 'text', + }) + } + // db async setDbValue( diff --git a/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts b/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts index 5aa51c02e..65c13aa03 100644 --- a/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts +++ b/frontend/projects/ui/src/app/services/api/embassy-mock-api.service.ts @@ -86,9 +86,13 @@ export class MockApiService extends ApiService { return markdown } - async uploadPackage(guid: string, body: Blob): Promise { + async uploadPackage(guid: string, body: Blob): Promise { await pauseFor(2000) - return 'success' + } + + async uploadFile(body: Blob): Promise { + await pauseFor(2000) + return 'returnedhash' } // db