Skip to content

Commit 7affa5e

Browse files
authored
feat(value): refactor boolean value (DEV-98) (#554)
* fix(value): display boolean value even it doesn't exist * style(boolean value): display checkbox instead of true or false * refactor(boolean-value): format code * chore(advanced search): compare boolean value in useful way * style(search): refactor advanced search * style(search): refactor advanced search * style(search): resolve style issue in date picker * test(search): fix tests * test(search): fix test in advanced search * style(value): fixing styling issue in boolean value
1 parent 436c270 commit 7affa5e

30 files changed

Lines changed: 178 additions & 92 deletions

‎src/app/workspace/resource/properties/properties.component.html‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ <h3 class="label mat-title">
137137
</div>
138138
<!-- Add button -->
139139
<div *ngIf="addValueIsAllowed(prop) && project?.status">
140-
<button mat-icon-button type="button" class="value-action create"
140+
<!-- boolen value will always be displayed even if value is not defined (value = false) -->
141+
<span *ngIf="prop.propDef.objectType === booleanValueTypeIri">
142+
<app-boolean-value [mode]="'read'" class="boolean-value"></app-boolean-value>
143+
</span>
144+
<button *ngIf="prop.propDef.objectType !== booleanValueTypeIri" mat-icon-button type="button" class="value-action create"
141145
(click)="showAddValueForm(prop, $event)"
142146
title="Add a new value">
143147
<mat-icon>add_box</mat-icon>

‎src/app/workspace/resource/properties/properties.component.spec.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,11 @@ describe('PropertiesComponent', () => {
402402
// so the amount of add buttons on the page should increase by 1
403403
// standoff links value and has incoming link value are system props and cannot be added: -2
404404
addButtons = propertyViewComponentDe.queryAll(By.css('button.create'));
405-
expect(addButtons.length).toEqual(18);
405+
expect(addButtons.length).toEqual(17);
406+
407+
// in case of boolean value, we do not display the add button, but the boolean value itself
408+
const booleanValue = propertyViewComponentDe.queryAll(By.css('.boolean-value'));
409+
expect(booleanValue.length).toEqual(1);
406410

407411
});
408412

‎src/app/workspace/resource/properties/properties.component.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
122122

123123
representationConstants = RepresentationConstants;
124124

125+
booleanValueTypeIri = Constants.BooleanValue;
126+
125127
hasIncomingLinkIri = Constants.KnoraApiV2 + Constants.HashDelimiter + 'hasIncomingLinkValue';
126128

127129
project: ReadProject;

‎src/app/workspace/resource/resource-instance-form/select-properties/switch-properties/switch-properties.component.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<app-text-value-as-string #createVal *ngSwitchCase="'ReadTextValueAsString'" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName" [textArea]="textArea"></app-text-value-as-string>
33
<app-text-value-as-xml #createVal *ngSwitchCase="'ReadTextValueAsXml'" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-text-value-as-xml>
44
<app-int-value #createVal *ngSwitchCase="constants.IntValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-int-value>
5-
<app-boolean-value #createVal *ngSwitchCase="constants.BooleanValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-boolean-value>
5+
<app-boolean-value #createVal *ngSwitchCase="constants.BooleanValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName" [moreSpace]="true"></app-boolean-value>
66
<app-uri-value #createVal *ngSwitchCase="constants.UriValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-uri-value>
77
<app-decimal-value #createVal *ngSwitchCase="constants.DecimalValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-decimal-value>
88
<app-color-value #createVal *ngSwitchCase="constants.ColorValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-color-value>

‎src/app/workspace/resource/values/boolean-value/boolean-value.component.html‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<span *ngIf="mode === 'read'; else showForm" class="read-mode-view">
2-
<span class="rm-value">{{valueFormControl.value | formattedBoolean:preferredDisplayType}}</span>
2+
<span class="rm-value">
3+
<mat-icon>{{valueFormControl.value ? 'check_box' : 'check_box_outline_blank'}}</mat-icon>
4+
</span>
35
<span class="rm-comment" *ngIf="shouldShowComment">{{commentFormControl.value}}</span>
46
</span>
57
<ng-template #showForm>
68
<span [formGroup]="form" (ngSubmit)="onSubmit()">
7-
<mat-checkbox [formControlName]="'value'" class="value boolValue child-value-component">
8-
{{valueFormControl.value | formattedBoolean:preferredDisplayType}}
9+
10+
<mat-checkbox [formControlName]="'value'" class="value boolValue child-value-component" [class.more-space]="moreSpace">
911
</mat-checkbox>
1012
<mat-error *ngIf="valueFormControl.hasError('valueNotChanged') && valueFormControl.dirty">
1113
<span class="custom-error-message">New value must be different than the current value.</span>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
@import "../../../../../assets/style/viewer";
2+
3+
.read-mode-view .mat-icon,
4+
.boolValue {
5+
margin-top: 4px;
6+
margin-left: 4px;
7+
display: block;
8+
9+
&.more-space {
10+
margin-top: 16px;
11+
}
12+
}
13+

‎src/app/workspace/resource/values/boolean-value/boolean-value.component.spec.ts‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('BooleanValueComponent', () => {
114114

115115
expect(testHostComponent.booleanValueComponent.mode).toEqual('read');
116116

117-
expect(valueReadModeNativeElement.innerText).toEqual('true');
117+
expect(valueReadModeNativeElement.innerText).toEqual('check_box');
118118
});
119119

120120
it('should make an existing value editable', () => {
@@ -127,7 +127,6 @@ describe('BooleanValueComponent', () => {
127127
valueBooleanNativeElement = valueBooleanDebugElement.nativeElement;
128128

129129
checkboxEl = valueBooleanDebugElement.query(By.css('input[type="checkbox"]')).nativeElement;
130-
checkboxLabel = valueBooleanDebugElement.query(By.css('span[class="mat-checkbox-label"]')).nativeElement;
131130

132131
expect(testHostComponent.booleanValueComponent.mode).toEqual('update');
133132

@@ -137,8 +136,6 @@ describe('BooleanValueComponent', () => {
137136

138137
expect(checkboxEl.checked).toBe(true);
139138

140-
expect(checkboxLabel.innerText).toEqual('true');
141-
142139
checkboxEl.click();
143140

144141
testHostFixture.detectChanges();
@@ -155,7 +152,6 @@ describe('BooleanValueComponent', () => {
155152

156153
expect(checkboxEl.disabled).toBe(false);
157154

158-
expect(checkboxLabel.innerText).toEqual('false');
159155
});
160156

161157
it('should validate an existing value with an added comment', () => {
@@ -168,7 +164,6 @@ describe('BooleanValueComponent', () => {
168164
valueBooleanNativeElement = valueBooleanDebugElement.nativeElement;
169165

170166
checkboxEl = valueBooleanDebugElement.query(By.css('input[type="checkbox"]')).nativeElement;
171-
checkboxLabel = valueBooleanDebugElement.query(By.css('span[class="mat-checkbox-label"]')).nativeElement;
172167

173168
commentBooleanDebugElement = valueComponentDe.query(By.css('textarea.comment'));
174169
commentBooleanNativeElement = commentBooleanDebugElement.nativeElement;
@@ -181,8 +176,6 @@ describe('BooleanValueComponent', () => {
181176

182177
expect(checkboxEl.checked).toBe(true);
183178

184-
expect(checkboxLabel.innerText).toEqual('true');
185-
186179
commentBooleanNativeElement.value = 'this is a comment';
187180

188181
commentBooleanNativeElement.dispatchEvent(new Event('input'));
@@ -208,7 +201,6 @@ describe('BooleanValueComponent', () => {
208201
valueBooleanNativeElement = valueBooleanDebugElement.nativeElement;
209202

210203
checkboxEl = valueBooleanDebugElement.query(By.css('input[type="checkbox"]')).nativeElement;
211-
checkboxLabel = valueBooleanDebugElement.query(By.css('span[class="mat-checkbox-label"]')).nativeElement;
212204

213205
expect(testHostComponent.booleanValueComponent.mode).toEqual('update');
214206

@@ -218,16 +210,12 @@ describe('BooleanValueComponent', () => {
218210

219211
expect(checkboxEl.checked).toBe(true);
220212

221-
expect(checkboxLabel.innerText).toEqual('true');
222-
223213
checkboxEl.click();
224214

225215
testHostFixture.detectChanges();
226216

227217
expect(checkboxEl.checked).toBe(false);
228218

229-
expect(checkboxLabel.innerText).toEqual('false');
230-
231219
testHostComponent.booleanValueComponent.resetFormControl();
232220

233221
testHostFixture.detectChanges();
@@ -236,7 +224,6 @@ describe('BooleanValueComponent', () => {
236224

237225
expect(checkboxEl.checked).toBe(true);
238226

239-
expect(checkboxLabel.innerText).toEqual('true');
240227
});
241228

242229
it('should set a new display value', () => {
@@ -250,7 +237,7 @@ describe('BooleanValueComponent', () => {
250237

251238
testHostFixture.detectChanges();
252239

253-
expect(valueReadModeNativeElement.innerText).toEqual('false');
240+
expect(valueReadModeNativeElement.innerText).toEqual('check_box_outline_blank');
254241

255242
expect(testHostComponent.booleanValueComponent.form.valid).toBeTruthy();
256243
});
@@ -273,7 +260,6 @@ describe('BooleanValueComponent', () => {
273260
let valueBooleanDebugElement: DebugElement;
274261
let valueBooleanNativeElement;
275262
let checkboxEl;
276-
let checkboxLabel;
277263
let commentBooleanDebugElement: DebugElement;
278264
let commentBooleanNativeElement;
279265

@@ -292,7 +278,6 @@ describe('BooleanValueComponent', () => {
292278
valueBooleanDebugElement = valueComponentDe.query(By.css('mat-checkbox'));
293279
valueBooleanNativeElement = valueBooleanDebugElement.nativeElement;
294280
checkboxEl = valueBooleanDebugElement.query(By.css('input[type="checkbox"]')).nativeElement;
295-
checkboxLabel = valueBooleanDebugElement.query(By.css('span[class="mat-checkbox-label"]')).nativeElement;
296281

297282
commentBooleanDebugElement = valueComponentDe.query(By.css('textarea.comment'));
298283
commentBooleanNativeElement = commentBooleanDebugElement.nativeElement;
@@ -301,7 +286,6 @@ describe('BooleanValueComponent', () => {
301286
expect(testHostComponent.booleanValueComponent.form.valid).toBeTruthy();
302287
expect(checkboxEl.disabled).toBe(false);
303288
expect(checkboxEl.checked).toBe(false);
304-
expect(checkboxLabel.innerText).toEqual('false');
305289
expect(commentBooleanNativeElement.value).toEqual('');
306290
});
307291

‎src/app/workspace/resource/values/boolean-value/boolean-value.component.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export class BooleanValueComponent extends BaseValueDirective implements OnInit,
1616

1717
@Input() displayValue?: ReadBooleanValue;
1818

19+
@Input() moreSpace?: boolean;
20+
1921
valueFormControl: FormControl;
2022
commentFormControl: FormControl;
2123

‎src/app/workspace/search/advanced-search/advanced-search.component.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<form *ngIf="!errorMessage" [formGroup]="form" (ngSubmit)="submit()" class="dsp-form-content">
1+
<form *ngIf="!errorMessage" [formGroup]="form" (ngSubmit)="submit()" class="app-form-content">
22

33
<div *ngIf="ontologiesMetadata?.ontologies.length > 0">
44
<app-search-select-ontology [formGroup]="form" [ontologiesMetadata]="ontologiesMetadata"
@@ -8,7 +8,7 @@
88
<app-resource-and-property-selection *ngIf="activeOntology !== undefined" #resAndPropSel [formGroup]="form" [activeOntology]="activeOntology" [topLevel]="true">
99
</app-resource-and-property-selection>
1010

11-
<div class="dsp-form-action">
11+
<div class="app-form-action">
1212
<button class="reset" mat-button type="button" (click)="resourceAndPropertySelection?.resetForm()" [disabled]="this.activeOntology === undefined">
1313
Reset
1414
</button>

‎src/app/workspace/search/advanced-search/advanced-search.component.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
ViewChild
1111
} from '@angular/core';
1212
import { FormBuilder, FormGroup } from '@angular/forms';
13-
import { ApiResponseError, Constants, KnoraApiConnection, OntologiesMetadata } from '@dasch-swiss/dsp-js';
13+
import { ApiResponseError, Constants, KnoraApiConnection, OntologiesMetadata, OntologyMetadata } from '@dasch-swiss/dsp-js';
1414
import { Subscription } from 'rxjs';
1515
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
1616
import { NotificationService } from 'src/app/main/services/notification.service';
@@ -100,6 +100,9 @@ export class AdvancedSearchComponent implements OnInit, OnDestroy, AfterViewChec
100100
response.ontologies = response.ontologies.filter(onto => onto.attachedToProject !== Constants.SystemProjectIRI);
101101

102102
this.ontologiesMetadata = response;
103+
104+
this.preSelectFirstOntology(this.ontologiesMetadata.ontologies);
105+
103106
},
104107
(error: ApiResponseError) => {
105108
this._notification.openSnackBar(error);
@@ -112,18 +115,28 @@ export class AdvancedSearchComponent implements OnInit, OnDestroy, AfterViewChec
112115
response.ontologies = response.ontologies.filter(onto => onto.attachedToProject !== Constants.SystemProjectIRI);
113116

114117
this.ontologiesMetadata = response;
118+
119+
this.preSelectFirstOntology(this.ontologiesMetadata.ontologies);
120+
115121
},
116122
(error: ApiResponseError) => {
117123
this._notification.openSnackBar(error);
118124
this.errorMessage = error;
119125
});
120126
}
127+
121128
}
122129

123130
setActiveOntology(ontologyIri: string) {
124131
this.activeOntology = ontologyIri;
125132
}
126133

134+
preSelectFirstOntology(ontologies: OntologyMetadata[]) {
135+
if (ontologies.length === 1) {
136+
this.activeOntology = ontologies[0].id;
137+
}
138+
}
139+
127140
submit() {
128141

129142
if (!this.formValid) {

0 commit comments

Comments
 (0)