added create-from functionality

This commit is contained in:
lotte
2020-06-29 22:17:41 +02:00
parent 32c8d9de03
commit 1cb0bb72e4
50 changed files with 408 additions and 237 deletions

View File

@@ -0,0 +1,13 @@
<label for="file-upload-{{index}}" class="d-flex align-items-center m-0">
<span class="btn btn-light">
{{'process.new.parameter.file.upload-button' | translate}}
</span>
<span class="file-name ml-1">{{fileObject?.name}}</span>
</label>
<input requireFile #file="ngModel" type="file" name="file-upload-{{index}}" id="file-upload-{{index}}" class="form-control-file d-none" [ngModel]="fileObject" (ngModelChange)="setFile($event)"/>
<div *ngIf="file.invalid && (file.dirty || file.touched)"
class="alert alert-danger validation-error">
<div *ngIf="file.errors.required">
{{'process.new.parameter.file.required' | translate}}
</div>
</div>

View File

@@ -0,0 +1,6 @@
.file-name {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

View File

@@ -0,0 +1,57 @@
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { FormsModule, NgForm, ReactiveFormsModule } from '@angular/forms';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { By } from '@angular/platform-browser';
import { FileValueInputComponent } from './file-value-input.component';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { FileValueAccessorDirective } from '../../../../../shared/utils/file-value-accessor.directive';
import { FileValidator } from '../../../../../shared/utils/require-file.validator';
import { TranslateLoaderMock } from '../../../../../shared/mocks/translate-loader.mock';
describe('FileValueInputComponent', () => {
let component: FileValueInputComponent;
let fixture: ComponentFixture<FileValueInputComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormsModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderMock
}
})],
declarations: [FileValueInputComponent, FileValueAccessorDirective, FileValidator],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FileValueInputComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should not show a validation error if the input field was left untouched but left empty', () => {
const validationError = fixture.debugElement.query(By.css('.validation-error'));
expect(validationError).toBeFalsy();
});
it('should show a validation error if the input field was touched but left empty', () => {
const input = fixture.debugElement.query(By.css('input'));
input.triggerEventHandler('blur', null);
fixture.detectChanges();
const validationError = fixture.debugElement.query(By.css('.validation-error'));
expect(validationError).toBeTruthy();
});
});

View File

@@ -0,0 +1,26 @@
import { Component, Optional } from '@angular/core';
import { ValueInputComponent } from '../value-input.component';
import { ControlContainer, NgForm } from '@angular/forms';
import { controlContainerFactory } from '../../../process-form.component';
/**
* Represents the user inputted value of a file parameter
*/
@Component({
selector: 'ds-file-value-input',
templateUrl: './file-value-input.component.html',
styleUrls: ['./file-value-input.component.scss'],
viewProviders: [ { provide: ControlContainer,
useFactory: controlContainerFactory,
deps: [[new Optional(), NgForm]] } ]
})
export class FileValueInputComponent extends ValueInputComponent<File> {
/**
* The current value of the file
*/
fileObject: File;
setFile(files) {
this.fileObject = files.length > 0 ? files[0] : undefined;
this.updateValue.emit(this.fileObject);
}
}