summaryrefslogtreecommitdiffstats
path: root/public/src/app/store/store.ts
blob: 5ae4f24e15d0b18b5712193b1274d5d305c84214 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { Injectable } from '@angular/core';
import { findIndex } from 'lodash';
import { action, computed, observable, toJS } from 'mobx';
import { groupBy, prop, compose, values } from 'ramda';

@Injectable()
export class Store {
  @observable sdcParmas;
  @observable isOwner;
  @observable mcUuid;
  @observable cdump;
  @observable tabsProperties;
  @observable tabIndex = 0;
  @observable isEditMode = false;
  @observable loader = false;
  @observable cdumpIsDirty = false;
  @observable expandAdvancedSetting = [];
  @observable expandImports = [];
  @observable generalflow;
  @observable vfiName;
  @observable flowType;
  @observable ifrmaeMessenger;
  @observable waitForSave = false;
  @observable displaySDCDialog = false;
  // error dialog
  @observable displayErrorDialog = false;
  @observable ErrorContent = [];

  // rule-engine
  @observable tabParmasForRule;
  @observable ruleList = new Array();
  @observable groupList = new Array();
  @observable ruleListExistParams;
  @observable ruleEditorInitializedState;
  @observable isLeftVisible;
  @observable inprogress;
  @observable notifyIdValue = '';

  @action
  updateRuleInList(rule) {
    console.log('current list:', toJS(this.ruleList));
    console.log('new rule', rule);
    const ruleIndex = findIndex(this.ruleList, function(ruleFromList) {
      console.log(
        `find match rule: list - ${ruleFromList.uid}, rule - ${rule.uid}`
      );
      return ruleFromList.uid === rule.uid;
    });
    if (ruleIndex > -1) {
      console.log('update rule');
      this.ruleList[ruleIndex] = rule;
    } else {
      console.log('new rule');
      this.ruleList.push(rule);
    }
    // handle group list
    if (rule.groupId !== undefined) {
      this.groupList
        .filter(item => item.groupId === rule.groupId)
        .map(item2 => {
          if (item2.list === undefined) {
            item2.list = new Array();
          }
          const ruleItemIndex = findIndex(
            item2.list,
            ruleFromList => ruleFromList.uid === rule.uid
          );
          if (ruleItemIndex > -1) {
            item2.list[ruleItemIndex] = rule;
          } else {
            item2.list.push(rule);
          }
        });
    }
  }

  @action
  updateRuleList(listOfRules) {
    this.ruleList = listOfRules;
    console.log(toJS(this.ruleList));
    const fn = compose(values, groupBy(prop('groupId')))(listOfRules);
    const dis = fn.map(item => {
      return { groupId: item[0].groupId, phase: item[0].phase, list: item };
    });
    console.log(dis);
    this.groupList = dis;
  }

  @action
  deleteFromGroup(groupId) {
    this.groupList = this.groupList.filter(item => item.groupId !== groupId);
  }

  @action
  removeRuleFromList(uid, groupId) {
    this.ruleList = this.ruleList.filter(item => item.uid !== uid);
    // remove from group
    this.groupList.forEach(item => {
      if (item.groupId === groupId) {
        item.list = item.list.filter(listItem => listItem.uid !== uid);
      }
      return item;
    });
  }

  @action
  resetRuleList() {
    this.ruleList = new Array();
    this.groupList = new Array();
  }

  @action
  changeStateForEditor(data) {
    this.ruleEditorInitializedState = data;
  }

  @action
  setTabIndex(value) {
    this.tabIndex = value;
  }

  @action
  setTabsProperties(nodes) {
    this.tabsProperties = nodes.map(tabItem => {
      return tabItem.properties.map(x => {
        if (!x.assignment) {
          x.assignment = {};
          x.assignment.value = '';
        }
        if (x.value) {
          if (typeof x.value === 'object') {
            x.value = '';
          }
        } else if (!x.value) {
          if (typeof x.assignment.value === 'object') {
            x.value = '';
          }
          // else {   x.value = x.assignment.value; }
        }
        return x;
      });
    });
    nodes.map(() => {
      this.expandAdvancedSetting.push(false);
      this.expandImports.push(false);
    });
    console.log('tabsProperties: %o', this.tabsProperties.toJS());
  }

  @computed
  get configurationForm() {
    return this.tabIndex >= 0 ? this.tabsProperties[this.tabIndex] : null;
  }
}