Skip to content

Commit

Permalink
add selection of multiple values and toggle button
Browse files Browse the repository at this point in the history
  • Loading branch information
lsteinmann committed Dec 19, 2024
1 parent ca7c892 commit 0e8a5c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class FixOutliersModalComponent {

public valuelist: Valuelist;
public selectedValue: string;
public selectedValues: Array<string>;
public inputType: string;
public replaceAll: boolean;
public countAffected: number;
Expand All @@ -46,6 +47,7 @@ export class FixOutliersModalComponent {

public cancel = () => this.activeModal.dismiss('cancel');

public isInvalid = () => !(this.selectedValue || (this.selectedValues.length > 0));

public async onKeyDown(event: KeyboardEvent) {

Expand All @@ -58,9 +60,8 @@ export class FixOutliersModalComponent {
this.projectDocument = await this.datastore.get('project');
this.valuelist = await this.getValuelist(this.document, this.field);
this.inputType = await this.field.inputType;
console.log(this.inputType)
console.log(this.valuelist.values)
this.affectedDocuments = [];
this.selectedValues = [];

const foundDocuments: Array<Document> = (await this.datastore.find({
constraints: { ['outlierValues:contain']: this.outlierValue }
Expand Down Expand Up @@ -88,7 +89,7 @@ export class FixOutliersModalComponent {

public async performReplacement() {

if (!this.selectedValue) return;
if (this.isInvalid()) return;

const fixingDataInProgressModal: NgbModalRef = this.openFixingDataInProgressModal();

Expand All @@ -104,16 +105,27 @@ export class FixOutliersModalComponent {
this.activeModal.close();
}

public clickCheckbox(value: string) {
public toggleCheckboxValue(value: string) {

/** TODO */
console.log(value)
if (this.selectedValues.includes(value)) {
this.selectedValues.splice(this.selectedValues.indexOf(value), 1);
} else {
this.selectedValues.push(value);
}
/** console.log(this.selectedValues)
console.log(this.selectedValues.length)
console.log(this.isInvalid())
console.log(value) */
}

public isSelectedValue(value: string) {

/** TODO */
return false;
public isPreselectedValue(value: string) {

if (this.document.resource[this.field.name].includes(value)) {
return true;
} else {
return false;
}
}

private openFixingDataInProgressModal(): NgbModalRef {
Expand Down Expand Up @@ -165,7 +177,8 @@ export class FixOutliersModalComponent {
private getReplacement(document: Document, entry: any, field: Field): any {

if (isString(entry) && entry === this.outlierValue) {
return this.selectedValue;
console.log(entry)
/*return this.selectedValue;*/
} else if (isObject(entry)) {
if (field.inputType === Field.InputType.DIMENSION
&& entry[Dimension.MEASUREMENTPOSITION] === this.outlierValue) {
Expand All @@ -178,6 +191,9 @@ export class FixOutliersModalComponent {
entry.endValue = this.selectedValue;
} else if (field.inputType === Field.InputType.COMPOSITE) {
this.replaceValueInCompositeEntry(document, entry, field);
} else if (field.inputType === Field.InputType.CHECKBOXES) {
console.log(entry)
/* return this.selectedValues */
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.fixOutliers.header">
</searchable-select>
</div>
<div *ngIf="inputType == 'checkboxes'">
{{getValues()}}
<div *ngFor="let value of getValues()" class="checkbox form-check form-check-inline">
<label class="form-check-label">
<input class="form-check-input" [value]="value" type="checkbox" (click)="clickCheckbox(value)" [checked]="isSelectedValue(value)">
{{value}}
<input class="form-check-input" [value]="value" type="checkbox" (click)="toggleCheckboxValue(value)" [checked]="isPreselectedValue(value)">
{{getValueLabel(value)}}
</label>
</div>
</div>
Expand Down Expand Up @@ -61,7 +60,7 @@ <h5 class="modal-title" i18n="@@navbar.taskbar.fixOutliers.header">

<div class="modal-footer">
<div id="confirm-replacement-button" class="btn btn-primary"
[ngClass]="{ 'disabled': !selectedValue }"
[ngClass]="{ 'disabled': isInvalid() }"
(click)="performReplacement()">
<span i18n="@@buttons.ok">OK</span>
</div>
Expand Down

0 comments on commit 0e8a5c9

Please sign in to comment.