-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from netgrif/NAE-1929
[NAE-1929] Data field type list of strings
- Loading branch information
Showing
12 changed files
with
192 additions
and
2 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
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
18 changes: 18 additions & 0 deletions
18
...onents-core/src/lib/data-fields/string-collection-field/models/string-collection-field.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,18 @@ | ||
import {DataField} from '../../models/abstract-data-field'; | ||
import {Behavior} from '../../models/behavior'; | ||
import {Layout} from '../../models/layout'; | ||
import {Validation} from '../../models/validation'; | ||
import {Component, ComponentPrefixes} from '../../models/component'; | ||
|
||
export class StringCollectionField extends DataField<Array<string>> { | ||
|
||
constructor(stringId: string, title: string, initialValue: Array<string>, behavior: Behavior, | ||
placeholder?: string, description?: string, layout?: Layout, validations?: Array<Validation>, component?: Component, | ||
parentTaskId?: string) { | ||
super(stringId, title, initialValue, behavior, placeholder, description, layout, validations, component, parentTaskId); | ||
} | ||
|
||
public getTypedComponentType(): string { | ||
return ComponentPrefixes.STRING_COLLECTION + this.getComponentType(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...eld/string-collection-default-field/abstract-string-collection-default-field.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,55 @@ | ||
import {Component, ElementRef, Inject, OnInit, Optional, ViewChild} from '@angular/core'; | ||
import {AbstractBaseDataFieldComponent} from '../../base-component/abstract-base-data-field.component'; | ||
import {TranslateService} from '@ngx-translate/core'; | ||
import {DATA_FIELD_PORTAL_DATA, DataFieldPortalData} from '../../models/data-field-portal-data-injection-token'; | ||
import {StringCollectionField} from '../models/string-collection-field'; | ||
import {ENTER, COMMA, SEMICOLON} from '@angular/cdk/keycodes'; | ||
import {MatChipInputEvent} from '@angular/material/chips'; | ||
|
||
@Component({ | ||
selector: 'ncc-abstract-string-collection-default-field', | ||
template: '', | ||
}) | ||
export abstract class AbstractStringCollectionDefaultFieldComponent extends AbstractBaseDataFieldComponent<StringCollectionField> implements OnInit { | ||
|
||
@ViewChild('input') input: ElementRef; | ||
public separatorKeysCodes: number[] = [ENTER]; | ||
|
||
protected constructor(protected _translate: TranslateService, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<StringCollectionField>) { | ||
super(dataFieldPortalData); | ||
} | ||
|
||
ngOnInit() { | ||
if (this.dataField?.component?.properties?.semicolon === 'true') { | ||
this.separatorKeysCodes.push(SEMICOLON); | ||
} | ||
if (this.dataField?.component?.properties?.comma === 'true') { | ||
this.separatorKeysCodes.push(COMMA); | ||
} | ||
} | ||
|
||
remove(value: string): void { | ||
const index = this.dataField.value.indexOf(value); | ||
|
||
if (index >= 0) { | ||
const choiceArray = [...this.dataField.value]; | ||
choiceArray.splice(index, 1); | ||
this.dataField.value = choiceArray; | ||
} | ||
} | ||
|
||
add(event: MatChipInputEvent | FocusEvent): void { | ||
const value = event['value'] ?? (event['target']?.['value'] ?? ''); | ||
|
||
if (value && value.trim()) { | ||
this.dataField.value = (this.dataField.value === null || this.dataField.value === undefined) ? [] : this.dataField.value | ||
const choiceArray = [...this.dataField.value]; | ||
choiceArray.push(value); | ||
this.dataField.value = choiceArray; | ||
this.input.nativeElement.value = ''; | ||
} else { | ||
this.input.nativeElement.value = ''; | ||
} | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
...tion-field/string-collection-default-field/string-collection-default-field.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<mat-form-field [appearance]="dataField.materialAppearance" class="full-width" color="primary"> | ||
<mat-label *ngIf="!showLargeLayout.value">{{dataField.title}}</mat-label> | ||
<mat-chip-list #chipList aria-label="Autocomplete" [formControl]="formControlRef"> | ||
<mat-chip | ||
*ngFor="let option of dataField.value" (removed)="remove(option)"> | ||
{{option}} | ||
<button *ngIf="!formControlRef.disabled" matChipRemove> | ||
<mat-icon>cancel</mat-icon> | ||
</button> | ||
</mat-chip> | ||
<input | ||
matInput | ||
#input | ||
[placeholder]="dataField.placeholder" | ||
[required]="dataField.behavior.required" | ||
[matChipInputFor]="chipList" | ||
(matChipInputTokenEnd)="add($event)" | ||
(blur)="add($event)" | ||
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"> | ||
</mat-chip-list> | ||
<mat-hint [ngClass]="{'mat-hint-disabled': formControlRef.disabled}">{{dataField.description}}</mat-hint> | ||
<mat-error | ||
*ngIf="dataField.isInvalid(formControlRef)">{{'dataField.validations.required' | translate}}</mat-error> | ||
</mat-form-field> |
5 changes: 5 additions & 0 deletions
5
...tion-field/string-collection-default-field/string-collection-default-field.component.scss
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,5 @@ | ||
.full-width { | ||
display: block; | ||
margin: 0 auto; | ||
width: 100%; | ||
} |
46 changes: 46 additions & 0 deletions
46
...n-field/string-collection-default-field/string-collection-default-field.component.spec.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,46 @@ | ||
import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {StringCollectionDefaultFieldComponent} from './string-collection-default-field.component'; | ||
import {Component} from '@angular/core'; | ||
import {StringCollectionField, TranslateLibModule} from 'netgrif-components-core'; | ||
import {HttpClientTestingModule} from '@angular/common/http/testing'; | ||
|
||
describe('StringCollectionDefaultFieldComponent', () => { | ||
let component: StringCollectionDefaultFieldComponent; | ||
let fixture: ComponentFixture<TestWrapperComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
TranslateLibModule, | ||
HttpClientTestingModule | ||
], | ||
declarations: [StringCollectionDefaultFieldComponent] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TestWrapperComponent); | ||
component = fixture.debugElement.children[0].componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
|
||
@Component({ | ||
selector: 'nc-test-wrapper', | ||
template: '<nc-string-collection-default-field [dataField]="field"></nc-string-collection-default-field>' | ||
}) | ||
class TestWrapperComponent { | ||
field = new StringCollectionField('', '', ['633c6187bb12a90925e0a17e'], { | ||
required: true, | ||
optional: true, | ||
visible: true, | ||
editable: true, | ||
hidden: true | ||
}, undefined, undefined, undefined, []); | ||
} |
22 changes: 22 additions & 0 deletions
22
...ection-field/string-collection-default-field/string-collection-default-field.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,22 @@ | ||
import {Component, Inject, Optional} from '@angular/core'; | ||
import { | ||
AbstractStringCollectionDefaultFieldComponent, | ||
DATA_FIELD_PORTAL_DATA, | ||
DataFieldPortalData, | ||
TaskRefField | ||
} from 'netgrif-components-core'; | ||
import {TranslateService} from '@ngx-translate/core'; | ||
|
||
@Component({ | ||
selector: 'nc-string-collection-default-field', | ||
templateUrl: './string-collection-default-field.component.html', | ||
styleUrls: ['./string-collection-default-field.component.scss'] | ||
}) | ||
export class StringCollectionDefaultFieldComponent extends AbstractStringCollectionDefaultFieldComponent { | ||
|
||
constructor(protected _translate: TranslateService, | ||
@Optional() @Inject(DATA_FIELD_PORTAL_DATA) dataFieldPortalData: DataFieldPortalData<TaskRefField>) { | ||
super(_translate, dataFieldPortalData) | ||
} | ||
|
||
} |