blob: 2f9c82b8299bdcc40999e1a2e03ec4caad22a3d5 [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import {Component, EventEmitter, forwardRef, Input, Output} from "@angular/core";
import {NG_VALUE_ACCESSOR} from "@angular/forms";
import {IAPISearchOptions, IAPIStatementModel} from "../../../../core";
import {arrayJoin, filterDistinctValues} from "../../../../util/store";
import {StatementTableComponent} from "../../../layout/statement-table";
import {AbstractControlValueAccessorComponent} from "../../common";
import {ISelectOption} from "../../select";
@Component({
selector: "app-statement-select",
templateUrl: "statement-select.component.html",
styleUrls: ["statement-select.component.scss"],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => StatementSelectComponent),
multi: true
}
]
})
export class StatementSelectComponent extends AbstractControlValueAccessorComponent<number[]> {
@Input()
public appIsLoading: boolean;
@Input()
public appSearchText: string;
@Input()
public appStatementTypeOptions: ISelectOption<number>[];
@Input()
public appSearchContent: IAPIStatementModel[];
@Output()
public appSearch: EventEmitter<IAPISearchOptions> = new EventEmitter();
public columns = [...StatementTableComponent.STATEMENT_SELECT_COLUMNS];
public toggle(id: number, isSelected: boolean) {
if (isSelected) {
const value = filterDistinctValues(arrayJoin(this.appValue, [id]))
.sort((a, b) => a - b);
this.writeValue(value, true);
} else {
const value = arrayJoin(this.appValue)
.filter((statementId) => statementId !== id);
this.writeValue(value, true);
}
}
}