Skip to content
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

feat(value): improve list value (DEV-951) #757

Merged
merged 1 commit into from May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,8 +1,17 @@
<span *ngIf="mode !== 'read' && listRootNode !== undefined">
<button class="md-button" mat-stroked-button [matMenuTriggerFor]="mainMenu" type="button" placeholder="List value">
<span *ngIf="!selectedNode">Select list value</span>
<span *ngIf="selectedNode">{{selectedNode.label}}</span>
</button>

<!-- button to select a list node -->
<span [matTooltip]="(!selectedNode && !listRootNode.children.length) ? 'This list doesn\'t have any node values' : 'Select list value'" [matTooltipPosition]="'above'">
<button mat-stroked-button [matMenuTriggerFor]="mainMenu" type="button" placeholder="List value" [disabled]="!selectedNode && !listRootNode.children.length">

<!-- if no node is selected: display list label; if the list does not have any list nodes, the button should be disabled -->
<span *ngIf="!selectedNode">{{listRootNode.label}}</span>

<!-- if a node is selected: display node label -->
<span *ngIf="selectedNode">{{selectedNode.label}}</span>

</button>
</span>

<mat-menu #mainMenu="matMenu" [overlapTrigger]="false">
<span *ngFor="let child of listRootNode.children">
Expand All @@ -22,6 +31,7 @@
</span>
</span>
</mat-menu>

<mat-error *ngIf="valueFormControl.hasError('valueNotChanged') && valueFormControl.dirty">
<span class="custom-error-message">New value must be different than the current value.</span>
</mat-error>
Expand Down
Expand Up @@ -160,7 +160,7 @@ describe('ListValueComponent', () => {

expect(valuesSpy.v2.list.getList).toHaveBeenCalledTimes(1);
expect(valuesSpy.v2.list.getList).toHaveBeenCalledWith('http://rdfh.ch/lists/0001/treeList');
expect(testHostComponent.inputValueComponent.listRootNode.children.length).toEqual(1);
expect(testHostComponent.inputValueComponent.listRootNode.children.length).toEqual(0);

const openListButtonDe = valueComponentDe.query(By.css('button'));

Expand Down
Expand Up @@ -68,14 +68,12 @@ export class ListValueComponent extends BaseValueDirective implements OnInit, On
}
if (this.valueFormControl !== undefined) {
if (this.mode !== 'read') {
this.listRootNode = new ListNodeV2();
const rootNodeIris = this.propertyDef.guiAttributes;
for (const rootNodeIri of rootNodeIris) {
// get rid of the "hlist"
const trimmedRootNodeIRI = rootNodeIri.substr(7, rootNodeIri.length - (1 + 7));
this._dspApiConnection.v2.list.getList(trimmedRootNodeIRI).subscribe(
(response2: ListNodeV2) => {
this.listRootNode.children.push(response2);
(response: ListNodeV2) => {
this.listRootNode = response;
}, (error: ApiResponseError) => {
this._errorHandler.showMessage(error);
});
Expand Down Expand Up @@ -126,11 +124,8 @@ export class ListValueComponent extends BaseValueDirective implements OnInit, On
}

const newListValue = new CreateListValue();


newListValue.listNode = this.valueFormControl.value;


if (this.commentFormControl.value !== null && this.commentFormControl.value !== '') {
newListValue.valueHasComment = this.commentFormControl.value;
}
Expand Down