From c6178973fb5c5c60254f3c75ad593953d96d8d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20B=C3=A9trancourt?= Date: Fri, 6 May 2022 10:22:42 +0000 Subject: [PATCH] feat: ui: add template expression widget --- .../resolution-expression.component.ts | 71 +++++++++++++++++++ .../resolution-expression.html | 25 +++++++ .../resolution-expression.sass | 13 ++++ .../src/lib/@models/resolution.model.ts | 7 +- .../utask-lib/src/lib/@routes/task/task.html | 11 +++ .../src/lib/@services/api.service.ts | 11 +++ .../utask-lib/src/lib/utask-lib.module.ts | 2 + 7 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.component.ts create mode 100644 ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.html create mode 100644 ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.sass diff --git a/ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.component.ts b/ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.component.ts new file mode 100644 index 000000000..62c024c9d --- /dev/null +++ b/ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.component.ts @@ -0,0 +1,71 @@ +import { ChangeDetectionStrategy, Component, Input } from "@angular/core"; +import { FormBuilder, FormGroup, Validators } from "@angular/forms"; +import { BehaviorSubject } from "rxjs"; +import Resolution from "../../@models/resolution.model"; +import { ApiService } from "../../@services/api.service"; + +@Component({ + selector: "lib-utask-resoution-expression", + templateUrl: "./resolution-expression.html", + styleUrls: ["./resolution-expression.sass"], + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class ResolutionExpressionComponent { + private _resolution: Resolution; + private _steps$ = new BehaviorSubject([]); + private _result$ = new BehaviorSubject(null); + private _error$ = new BehaviorSubject(null); + + readonly formGroup: FormGroup; + + readonly steps$ = this._steps$.asObservable(); + readonly result$ = this._result$.asObservable(); + readonly error$ = this._error$.asObservable(); + + @Input("resolution") set resolution(r: Resolution) { + if ((this._resolution = r)) { + this._steps$.next(Object.keys(r.steps)); + } else { + this._steps$.next([]); + } + } + + get resolution(): Resolution { + return this._resolution; + } + + constructor(private _api: ApiService, _builder: FormBuilder) { + this.formGroup = _builder.group({ + step: ["", [Validators.required]], + expression: ["", [Validators.required]], + }); + } + + reset(): void { + this.formGroup.reset(); + this._result$.next(null); + this._error$.next(null); + } + + submit(): void { + const { step, expression } = this.formGroup.value; + + this._api.resolution + .templating(this._resolution, step, expression) + .subscribe( + (result) => { + if (result.error) { + this._result$.next(null); + this._error$.next(result.error); + } else { + this._result$.next(result.result); + this._error$.next(null); + } + }, + (e) => { + this._result$.next(null); + this._error$.next(e.error.error); + } + ); + } +} diff --git a/ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.html b/ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.html new file mode 100644 index 000000000..d43e3878c --- /dev/null +++ b/ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.html @@ -0,0 +1,25 @@ +
+ + Step + + + + + + + + Template expression + + + + +
+ + +
+ + +
+
+
{{ result }}
+
diff --git a/ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.sass b/ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.sass new file mode 100644 index 000000000..e200cc3e5 --- /dev/null +++ b/ui/dashboard/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.sass @@ -0,0 +1,13 @@ +.buttons + margin-top: 1em + + button + margin-right: 0.5em + +.result + margin-top: 1em + border: 1px solid #d9d9d9 + padding: 1em + + pre + margin: 0 diff --git a/ui/dashboard/projects/utask-lib/src/lib/@models/resolution.model.ts b/ui/dashboard/projects/utask-lib/src/lib/@models/resolution.model.ts index b61419999..aed641367 100644 --- a/ui/dashboard/projects/utask-lib/src/lib/@models/resolution.model.ts +++ b/ui/dashboard/projects/utask-lib/src/lib/@models/resolution.model.ts @@ -14,4 +14,9 @@ export default class Resolution { task_id: string; task_title: string; steps: { [key: string]: Step }; -} \ No newline at end of file +} + +export class TemplateExpression { + result: string; + error?: string; +} diff --git a/ui/dashboard/projects/utask-lib/src/lib/@routes/task/task.html b/ui/dashboard/projects/utask-lib/src/lib/@routes/task/task.html index 64a3dd806..7f3f86368 100644 --- a/ui/dashboard/projects/utask-lib/src/lib/@routes/task/task.html +++ b/ui/dashboard/projects/utask-lib/src/lib/@routes/task/task.html @@ -272,6 +272,17 @@ + + +
+ Template expression +   +
+
+ +
+
diff --git a/ui/dashboard/projects/utask-lib/src/lib/@services/api.service.ts b/ui/dashboard/projects/utask-lib/src/lib/@services/api.service.ts index c1dc5a101..4ecbabef2 100644 --- a/ui/dashboard/projects/utask-lib/src/lib/@services/api.service.ts +++ b/ui/dashboard/projects/utask-lib/src/lib/@services/api.service.ts @@ -5,6 +5,7 @@ import { Observable } from 'rxjs'; import { HttpClient, HttpResponse } from '@angular/common/http'; import Meta from '../@models/meta.model'; import Template from '../@models/template.model'; +import Resolution, { TemplateExpression } from '../@models/resolution.model'; export class ParamsListTasks { page_size?: number; @@ -314,6 +315,16 @@ export class ApiServiceResolution { resolution ); } + + templating(resolution: Resolution, step: string, expression: string) { + return this.http.post( + `${this.base}resolution/${resolution.id}/templating`, + { + step_name: step, + templating_expression: expression, + } + ); + } } @Injectable({ diff --git a/ui/dashboard/projects/utask-lib/src/lib/utask-lib.module.ts b/ui/dashboard/projects/utask-lib/src/lib/utask-lib.module.ts index f7def5106..0dfa4c737 100644 --- a/ui/dashboard/projects/utask-lib/src/lib/utask-lib.module.ts +++ b/ui/dashboard/projects/utask-lib/src/lib/utask-lib.module.ts @@ -15,6 +15,7 @@ import { InputsFormComponent } from './@components/inputs-form/inputs-form.compo import { InputTagsComponent } from './@components/input-tags/input-tags.component'; import { InputEditorComponent } from './@components/input-editor/input-editor.component'; import { LoaderComponent } from './@components/loader/loader.component'; +import { ResolutionExpressionComponent } from './@components/resolution-expression/resolution-expression.component'; import { MetaResolve } from './@resolves/meta.resolve'; import { ModalApiYamlComponent } from './@modals/modal-api-yaml/modal-api-yaml.component'; import { ModalEditResolutionStepStateComponent } from './@modals/modal-edit-resolution-step-state/modal-edit-resolution-step-state.component'; @@ -77,6 +78,7 @@ const components: any[] = [ ModalEditResolutionStepStateComponent, ModalApiYamlEditComponent, NzModalContentWithErrorComponent, + ResolutionExpressionComponent, StepNodeComponent, StepsListComponent, StepsViewerComponent,