-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ui: add template expression widget
- Loading branch information
Showing
7 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...ts/utask-lib/src/lib/@components/resolution-expression/resolution-expression.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String[]>([]); | ||
private _result$ = new BehaviorSubject<String | null>(null); | ||
private _error$ = new BehaviorSubject<String | null>(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); | ||
} | ||
); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...d/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<form *ngIf="formGroup" nz-form [formGroup]="formGroup" [nzLayout]="'vertical'" (ngSubmit)="submit()"> | ||
<nz-form-item> | ||
<nz-form-label nzFor="step" [nzRequired]="true">Step</nz-form-label> | ||
<nz-form-control nzErrorTip="Please select step!"> | ||
<nz-select formControlName="step" nzPlaceHolder="Please select"> | ||
<nz-option *ngFor="let step of steps$ | async" [nzLabel]="step" [nzValue]="step"></nz-option> | ||
</nz-select> | ||
</nz-form-control> | ||
</nz-form-item> | ||
<nz-form-item> | ||
<nz-form-label nzFor="expression" [nzRequired]="true">Template expression</nz-form-label> | ||
<nz-form-control nzErrorTip="Please set a valid value for expression!"> | ||
<input type="string" formControlName="expression" nz-input [placeholder]="'{{.input}}'"/> | ||
</nz-form-control> | ||
</nz-form-item> | ||
</form> | ||
<lib-utask-error-message *ngIf="error$ | async as error" [data]="error"> | ||
</lib-utask-error-message> | ||
<div class="buttons"> | ||
<button nz-button nzType="secondary" type="button" (click)="reset()">Reset</button> | ||
<button nz-button nzType="primary" [disabled]="!formGroup.valid" type="button" (click)="submit()">Submit</button> | ||
</div> | ||
<div *ngIf="result$ | async as result" class="result"> | ||
<pre>{{ result }}</pre> | ||
</div> |
13 changes: 13 additions & 0 deletions
13
...d/projects/utask-lib/src/lib/@components/resolution-expression/resolution-expression.sass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters