Skip to content

Commit

Permalink
chore: DRY data offer form (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
kulgg authored Jul 30, 2024
1 parent 118f054 commit 72a0c7f
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 377 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<edit-asset-form-label
[htmlFor]="fieldId"
[label]="label"
[ctrl]="ctrl"></edit-asset-form-label>

<mat-form-field class="w-full mt-1">
<input
matInput
type="text"
[id]="fieldId"
[formControl]="ctrl"
[placeholder]="placeholder" />
<mat-error *ngIf="ctrl.errors?.url">
{{ validationMessages.invalidUrlMessage }}
</mat-error>
<mat-error *ngIf="ctrl.errors?.email">
{{ validationMessages.invalidEmailMessage }}
</mat-error>
<mat-error *ngIf="ctrl.errors?.pattern">
{{ validationMessages.invalidWhitespacesOrColonsMessage }}
</mat-error>
<mat-error *ngIf="ctrl.errors?.requiresPrefix">
{{ validationMessages.invalidPrefix('ID', 'urn:artifact') }}
</mat-error>
<mat-error *ngIf="ctrl.errors?.exists">
{{ ctrl.errors?.exists }}
</mat-error>
<mat-hint *ngIf="!hideHint">
<ng-content></ng-content>
</mat-hint>
</mat-form-field>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {Component, Input} from '@angular/core';
import {FormControl} from '@angular/forms';
import {ValidationMessages} from 'src/app/core/validators/validation-messages';

@Component({
selector: 'edit-asset-form-input',
templateUrl: './edit-asset-form-input.component.html',
})
export class EditAssetFormInputComponent {
@Input() ctrl!: FormControl<string>;
@Input() fieldId = 'missing-id-' + Math.random().toString(36).substring(7);
@Input() label!: string;
@Input() placeholder: string = '...';
@Input() hideHint: boolean = false;

constructor(public validationMessages: ValidationMessages) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<edit-asset-form-label
[htmlFor]="fieldId"
[label]="label"
[ctrl]="ctrl"></edit-asset-form-label>

<mat-form-field class="w-full mt-1">
<textarea
matInput
[class]="textareaClasses"
[id]="fieldId"
[formControl]="ctrl"
[placeholder]="placeholder"></textarea>
<mat-error *ngIf="ctrl.invalid && ctrl.errors?.jsonInvalid">
{{ validationMessages.invalidJsonMessage }}
</mat-error>
<mat-hint *ngIf="!hideHint">
<ng-content></ng-content>
</mat-hint>
</mat-form-field>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {Component, Input} from '@angular/core';
import {FormControl} from '@angular/forms';
import {ValidationMessages} from 'src/app/core/validators/validation-messages';

@Component({
selector: 'edit-asset-form-textarea',
templateUrl: './edit-asset-form-textarea.component.html',
})
export class EditAssetFormTextareaComponent {
@Input() ctrl!: FormControl<string>;
@Input() fieldId = 'missing-id-' + Math.random().toString(36).substring(7);
@Input() label!: string;
@Input() placeholder: string = '...';
@Input() hideHint: boolean = false;
@Input() textareaClasses: string = 'h-36';

constructor(public validationMessages: ValidationMessages) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import {DataSubcategoryItemsPipe} from './data-subcategory-select/data-subcatego
import {DataSubcategorySelectComponent} from './data-subcategory-select/data-subcategory-select.component';
import {EditAssetFormDataAddressTypeSelectComponent} from './edit-asset-form-data-address-type-select/edit-asset-form-data-address-type-select.component';
import {EditAssetFormGroupComponent} from './edit-asset-form-group/edit-asset-form-group.component';
import {EditAssetFormInputComponent} from './edit-asset-form-input/edit-asset-form-input.component';
import {EditAssetFormLabelComponent} from './edit-asset-form-label/edit-asset-form-label.component';
import {EditAssetFormTextareaComponent} from './edit-asset-form-textarea/edit-asset-form-textarea.component';
import {EditAssetFormComponent} from './edit-asset-form/edit-asset-form.component';
import {KeywordSelectComponent} from './keyword-select/keyword-select.component';
import {LanguageSelectComponent} from './language-select/language-select.component';
Expand Down Expand Up @@ -75,6 +77,8 @@ import {TransportModeSelectComponent} from './transport-mode-select/transport-mo
EditAssetFormComponent,
EditAssetFormGroupComponent,
EditAssetFormLabelComponent,
EditAssetFormInputComponent,
EditAssetFormTextareaComponent,
KeywordSelectComponent,
DataCategorySelectComponent,
DataSubcategorySelectComponent,
Expand Down
Loading

0 comments on commit 72a0c7f

Please sign in to comment.