summaryrefslogtreecommitdiffstats
path: root/public/src/app/bar-icons/bar-icons.component.ts
blob: bf930f3e21a1cf936a34aebe5b102b6d847d6291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Component, Input, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms';
import { includes } from 'lodash';
import { Store } from '../store/store';

@Component({
  selector: 'app-bar-icons',
  templateUrl: './bar-icons.component.html',
  styleUrls: ['./bar-icons.component.scss']
})
export class BarIconsComponent {
  configuration;
  @Input() tabName: string;
  @ViewChild('cdumpConfForm') cdumpConfForm: NgForm;
  dropDownTypes = {
    none: 1,
    regularDDL: 2,
    booleanDDL: 3
  };

  constructor(public store: Store) {}

  onChange(e) {
    this.store.cdumpIsDirty = true;
  }

  isPropertyDdl(property) {
    if (property.hasOwnProperty('constraints')) {
      if (includes(property.constraints[0].valid_values, property.value)) {
        return this.dropDownTypes.regularDDL;
      } else if (
        property.hasOwnProperty('type') &&
        property.type === 'boolean'
      ) {
        if (!(property.value === 'false')) {
          property.value = true;
        }
        return this.dropDownTypes.booleanDDL;
      }
    }
    return this.dropDownTypes.none;
  }

  genrateBarTestId() {
    return `${this.tabName}-bar-icon-container`;
  }

  enableSetting() {
    this.store.expandAdvancedSetting[this.store.tabIndex] = !this.store
      .expandAdvancedSetting[this.store.tabIndex];
  }
}