This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor form component and allow custom buttons in modal
Signed-off-by: GuessWhoSamFoo <foos@vmware.com>
- Loading branch information
GuessWhoSamFoo
committed
Sep 12, 2020
1 parent
a580cbe
commit 2e88d98
Showing
13 changed files
with
254 additions
and
350 deletions.
There are no files selected for viewing
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
71 changes: 41 additions & 30 deletions
71
web/src/app/modules/shared/components/presentation/card/card.component.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 |
---|---|---|
@@ -1,45 +1,56 @@ | ||
<ng-container | ||
*ngTemplateOutlet="currentAction ? action : content" | ||
></ng-container> | ||
<div class="card"> | ||
<div class="card-block"> | ||
<ng-container | ||
*ngTemplateOutlet="currentAction ? action : content" | ||
></ng-container> | ||
</div> | ||
<ng-container *ngTemplateOutlet="currentAction ? formFooter : actionFooter"></ng-container> | ||
</div> | ||
|
||
|
||
<ng-template #action> | ||
<h3 class="card-title">{{ currentAction.title }}</h3> | ||
<app-form | ||
#appForm | ||
[form]="currentAction.form" | ||
[title]="currentAction.title" | ||
(submit)="onActionSubmit($event)" | ||
(cancel)="onActionCancel()" | ||
> | ||
</app-form> | ||
</ng-template> | ||
|
||
<ng-template #content> | ||
<div class="card"> | ||
<div class="card-block"> | ||
<ng-container *ngIf="v.config.alert"> | ||
<div class="alert alert-{{ v.config.alert.type }} alert-sm"> | ||
<div class="alert-item static"> | ||
<span class="alert-text"> | ||
{{ v.config.alert.message }} | ||
</span> | ||
</div> | ||
</div> | ||
</ng-container> | ||
<h4 class="card-title"> | ||
<app-view-title [views]="title"></app-view-title> | ||
</h4> | ||
<ng-template #formFooter> | ||
<div class="card-footer"> | ||
<button class="btn btn-primary btn-sm" type="submit" (click)="onActionSubmit()">Submit</button> | ||
<button class="btn btn-sm" type="button" (click)="onActionCancel()"> | ||
Cancel | ||
</button> | ||
</div> | ||
</ng-template> | ||
|
||
<div class="card-text"> | ||
<app-view-container [view]="body"></app-view-container> | ||
<ng-template #actionFooter> | ||
<div class="card-footer" *ngIf="v.config.actions?.length > 0"> | ||
<ng-container *ngFor="let action of v.config.actions; trackBy: trackByFn"> | ||
<button class="btn btn-sm btn-link" (click)="setAction(action)"> | ||
{{ action.name }} | ||
</button> | ||
</ng-container> | ||
</div> | ||
</ng-template> | ||
|
||
<ng-template #content> | ||
<ng-container *ngIf="v.config.alert"> | ||
<div class="alert alert-{{ v.config.alert.type }} alert-sm"> | ||
<div class="alert-item static"> | ||
<span class="alert-text"> | ||
{{ v.config.alert.message }} | ||
</span> | ||
</div> | ||
</div> | ||
</ng-container> | ||
<h4 class="card-title"> | ||
<app-view-title [views]="title"></app-view-title> | ||
</h4> | ||
|
||
<div class="card-footer" *ngIf="v.config.actions?.length > 0"> | ||
<ng-container *ngFor="let action of v.config.actions; trackBy: trackByFn"> | ||
<button class="btn btn-sm btn-link" (click)="setAction(action)"> | ||
{{ action.name }} | ||
</button> | ||
</ng-container> | ||
</div> | ||
<div class="card-text"> | ||
<app-view-container [view]="body"></app-view-container> | ||
</div> | ||
</ng-template> |
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
182 changes: 89 additions & 93 deletions
182
web/src/app/modules/shared/components/presentation/form/form.component.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 |
---|---|---|
@@ -1,95 +1,91 @@ | ||
<form clrForm [formGroup]="formGroup" (ngSubmit)="onFormSubmit()"> | ||
<div class="card"> | ||
<div class="card-block"> | ||
<h3 class="card-title">{{ title }}</h3> | ||
<ng-container *ngFor="let field of form.fields"> | ||
<ng-container [ngSwitch]="field.type"> | ||
<ng-container *ngSwitchCase="'checkbox'"> | ||
<clr-checkbox-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<clr-checkbox-wrapper | ||
*ngFor="let opt of fieldChoices(field); trackBy: trackByFn" | ||
> | ||
<input | ||
type="checkbox" | ||
clrCheckbox | ||
[formControlName]="field.name" | ||
[value]="opt.value" | ||
[checked]="opt.checked" | ||
/> | ||
<label>{{ opt.label }}</label> | ||
</clr-checkbox-wrapper> | ||
</clr-checkbox-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'radio'"> | ||
<clr-radio-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<clr-radio-wrapper | ||
*ngFor="let opt of fieldChoices(field); trackBy: trackByFn" | ||
> | ||
<input | ||
type="radio" | ||
clrRadio | ||
[formControlName]="field.name" | ||
[value]="opt.value" | ||
/> | ||
<label>{{ opt.label }}</label> | ||
</clr-radio-wrapper> | ||
</clr-radio-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'text'"> | ||
<clr-input-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<input clrInput type="text" [formControlName]="field.name" /> | ||
</clr-input-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'number'"> | ||
<clr-input-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<input clrInput type="number" [formControlName]="field.name" /> | ||
</clr-input-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'password'"> | ||
<clr-input-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<input clrInput type="password" [formControlName]="field.name" /> | ||
</clr-input-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'select'"> | ||
<clr-select-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<select | ||
clrSelect | ||
[formControlName]="field.name" | ||
[multiple]="field.configuration.multiple" | ||
> | ||
<option | ||
*ngFor="let opt of fieldChoices(field); trackBy: trackByFn" | ||
[value]="opt.value" | ||
> | ||
{{ opt.label }} | ||
</option> | ||
</select> | ||
</clr-select-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'textarea'"> | ||
<clr-textarea-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<textarea clrTextarea [formControlName]="field.name"></textarea> | ||
</clr-textarea-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'hidden'"> </ng-container> | ||
<ng-container *ngSwitchDefault> | ||
Unable to display form field type {{ field.type }} | ||
</ng-container> | ||
</ng-container> | ||
<form clrForm [formGroup]="formGroup" > | ||
<ng-container *ngFor="let field of form.fields; trackBy: trackByFn"> | ||
<ng-container [ngSwitch]="field.type"> | ||
<ng-container *ngSwitchCase="'checkbox'"> | ||
<clr-checkbox-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<clr-checkbox-wrapper | ||
*ngFor="let opt of fieldChoices(field); trackBy: trackByFn" | ||
> | ||
<input | ||
type="checkbox" | ||
clrCheckbox | ||
[formControlName]="field.name" | ||
[value]="opt.value" | ||
[checked]="opt.checked" | ||
/> | ||
<label>{{ opt.label }}</label> | ||
</clr-checkbox-wrapper> | ||
<clr-control-error>{{ field.error }}</clr-control-error> | ||
</clr-checkbox-container> | ||
</ng-container> | ||
</div> | ||
<div class="card-footer"> | ||
<button class="btn btn-primary btn-sm" type="submit">Submit</button> | ||
<button class="btn btn-sm" type="button" (click)="onFormCancel()"> | ||
Cancel | ||
</button> | ||
</div> | ||
</div> | ||
<ng-container *ngSwitchCase="'radio'"> | ||
<clr-radio-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<clr-radio-wrapper | ||
*ngFor="let opt of fieldChoices(field); trackBy: trackByFn" | ||
> | ||
<input | ||
type="radio" | ||
clrRadio | ||
[formControlName]="field.name" | ||
[value]="opt.value" | ||
/> | ||
<label>{{ opt.label }}</label> | ||
</clr-radio-wrapper> | ||
<clr-control-error>{{ field.error }}</clr-control-error> | ||
</clr-radio-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'text'"> | ||
<clr-input-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<input clrInput type="text" [formControlName]="field.name" /> | ||
<clr-control-error>{{ field.error }}</clr-control-error> | ||
</clr-input-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'number'"> | ||
<clr-input-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<input clrInput type="number" [formControlName]="field.name" /> | ||
<clr-control-error>{{ field.error }}</clr-control-error> | ||
</clr-input-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'password'"> | ||
<clr-input-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<input clrInput type="password" [formControlName]="field.name" /> | ||
<clr-control-error>{{ field.error }}</clr-control-error> | ||
</clr-input-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'select'"> | ||
<clr-select-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<select | ||
clrSelect | ||
[formControlName]="field.name" | ||
[multiple]="field.configuration.multiple" | ||
> | ||
<option | ||
*ngFor="let opt of fieldChoices(field); trackBy: trackByFn" | ||
[value]="opt.value" | ||
> | ||
{{ opt.label }} | ||
</option> | ||
</select> | ||
<clr-control-error>{{ field.error }}</clr-control-error> | ||
</clr-select-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'textarea'"> | ||
<clr-textarea-container> | ||
<label [for]="field.name">{{ field.label }}</label> | ||
<textarea clrTextarea [formControlName]="field.name"></textarea> | ||
<clr-control-error>{{ field.error }}</clr-control-error> | ||
</clr-textarea-container> | ||
</ng-container> | ||
<ng-container *ngSwitchCase="'hidden'"> </ng-container> | ||
<ng-container *ngSwitchDefault> | ||
Unable to display form field type {{ field.type }} | ||
</ng-container> | ||
</ng-container> | ||
</ng-container> | ||
</form> |
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
Oops, something went wrong.