-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NAE-1929] Data field type list of strings #227
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c6e5fc9
[NAE-1929] Data field type list of strings
Kovy95 67ebb87
[NAE-1929] Data field type list of strings
Kovy95 a0694da
[NAE-1929] Data field type list of strings
Kovy95 57dfd14
[NAE-1929] Data field type list of strings
Kovy95 aaa9793
[NAE-1929] Data field type list of strings
Kovy95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error in @angular/cdk/keycodes:
On Slovak keyboard layout for macOS,
SEMICOLON
does not correspond to the expected input. Pressing;
results in no response, but pressingô
acts as a separator. Code adjustment is required for proper functionality of the;
key to align with the Slovak keyboard layout on macOS.