2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import {Component, EventEmitter, Input, Output, ViewChild, ViewEncapsulation} from "@angular/core";
22 import {PathsAndNamesDefinition} from "../../../../models/paths-and-names";
25 selector: 'gab-column-provider',
26 templateUrl: './generic-artifact-browser-column-provider.component.html',
27 styleUrls: ['./generic-artifact-browser-column-provider.component.less'],
28 encapsulation: ViewEncapsulation.None
30 export class GenericArtifactBrowserColumnProviderComponent {
32 pathsAndNames: PathsAndNamesDefinition[];
35 onCancel = new EventEmitter();
37 onSave = new EventEmitter();
39 @ViewChild('generalForm') generalForm;
45 checkNameDuplications(event) {
46 const tmp = event.target.value;
47 if (tmp && !this.columnsContainsName(tmp)) {
49 this.generalForm.form.controls['name'].setErrors(null);
51 this.generalForm.form.controls['name'].setErrors({incorrect: true});
55 checkPathDuplications(event) {
56 const tmp = event.target.value;
57 if (tmp && !this.columnsContainsPath(tmp)) {
59 this.generalForm.form.controls['path'].setErrors(null);
61 this.generalForm.form.controls['path'].setErrors({incorrect: true});
65 cancelAddingNewColumn() {
74 this.updateColumnFilter(this.name, this.path);
78 private updateColumnFilter = (name: string, prop: string): void => {
79 this.pathsAndNames.push(new PathsAndNamesDefinition(prop, name));
80 this.generalForm.form.controls['name'].setValue("");
81 this.generalForm.form.controls['path'].setValue("");
84 private columnsContainsName = (name: string): boolean => {
85 const columnDefinitions = this.pathsAndNames.filter(column => column.friendlyName.toLowerCase() === name.toLowerCase());
86 return columnDefinitions.length > 0;
89 private columnsContainsPath = (path: string): boolean => {
90 const columnDefinitions = this.pathsAndNames.filter(column => column.path.toLowerCase() === path.toLowerCase());
91 return columnDefinitions.length > 0;