This repository has been archived by the owner on May 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generateJSON.js
164 lines (155 loc) · 5.16 KB
/
generateJSON.js
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
155
156
157
158
159
160
161
162
163
164
function getJSON(params) {
let columns = [];
let attract = {name: "Узнаёт", variants: []};
let connection = {name: "Подключает", variants: []};
if (params.attractionChannel.includes("shop")) {
/*let temp = steps.shopAttract;
String.prototype.splice = function (idx, rem, str) {
return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
};
console.log("suka1", temp.steps[1].info, temp.steps[1].info.indexOf("%"));
if (temp.steps[1].info.indexOf("%") >= 0) {
temp.steps[1].info = temp.steps[1].info.splice(temp.steps[1].info.indexOf("%"), 1, params.demoPeriod);
}
attract.variants.push(temp);*/
}
let sms = steps.smsInfo;
if (params.isPromo) {
/*-let temp = steps.promoAttract;
String.prototype.splice = function (idx, rem, str) {
return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
};
if (temp.info.indexOf("%") >= 0) {
temp.info = temp.info.splice(temp.indexOf("%"), 1, params.demoPeriod);
}
attract.variants.push(temp);*/
sms = steps.smsPayed;
let line = [];
line.push(steps.promoAttract);
line.push(sms);
attract.variants.push(line);
connection.variants.push(steps.paidConnection);
}
if (params.attractionChannel.includes("alreadyInstalled")) {
let line = [];
line.push(steps.stockAttract);
line.push(sms);
attract.variants.push(line);
}
if (params.attractionChannel.includes("ad")) {
let line = [];
line.push(steps.adAttract);
line.push(sms);
attract.variants.push(line);
}
if (params.attractionChannel.includes("operatorCall")) {
let line = [];
line.push(steps.operatorCallAttract);
line.push(sms);
attract.variants.push(line);
}
if (params.attractionChannel.includes("sms")) {
let line = [];
line.push(steps.smsCallAttract);
line.push(sms);
attract.variants.push(line);
}
if (params.attractionChannel.includes("shop")) {
let line = [];
line.push(steps.shopAttract);
line.push(sms);
attract.variants.push(line);
}
columns.push(attract);
let enter = {name: "Подключает", variants: []};
let enterInfo = "Подключение возможно";
if (params.howAble.includes("lk")) {
enterInfo += "\nв личном кабинете"
}
if (params.howAble.includes("callCenter")) {
enterInfo += "\nв коллцентре"
}
if (params.howAble.includes("shop")) {
enterInfo += "\nв магазине"
}
if (params.howAble.length > 0) {
let temp = steps.ableFunc;
temp.info = enterInfo;
enter.variants.push([temp]);
}
columns.push(enter);
let use;
use = {name: "Использует", variants: []};
let whereInfo = "Управление возможно в следующих местах: ";
if (params.whereInfo.includes("lk")) {
whereInfo += "\nв личном кабинете"
}
if (params.whereInfo.includes("callCenter")) {
whereInfo += "\nв коллцентре"
}
if (params.whereInfo.includes("shop")) {
whereInfo += "\nв магазине"
}
if (params.whereInfo.length > 0) {
let temp = steps.waysWhereInfo;
temp.info = whereInfo;
use.variants.push([temp]);
}
if (params.howPaid !== "free") {
let line = [];
line.push(steps.smsPayed);
use.variants.push(line);
}
columns.push(use);
// Реакция на изменения
let reaction = {name: "Реакция на изменения", variants: []};
if (params.howPaid !== "free") {
reaction.variants.push([steps.PaidReaction]);
reaction.variants.push([steps.CallReaction]);
reaction.variants.push([steps.DisableReaction]);
}
console.log("Radius", params.radius);
if (params.radius) {
reaction.variants.push([steps.changeRadius]);
}
columns.push(reaction);
// Отключает
let exit = columns.disconnect = {name: "Отключает", variants: []};
let disableInfo = "Отключение возможно";
if (params.howDisable.includes("lk")) {
disableInfo += "\nв личном кабинете"
}
if (params.howDisable.includes("callCenter")) {
disableInfo += "\nв коллцентре"
}
if (params.howDisable.includes("shop")) {
disableInfo += "\nв магазине"
}
if (params.howDisable.length > 0) {
let temp = steps.disableFunc;
temp.info = disableInfo;
exit.variants.push([temp]);
}
columns.push(exit);
columns = {"states": columns, name: params.name};
return JSON.stringify(columns);
}
// Пример входящих данных
let formData = {
howPaid: "monthly",
isPromo: true,
howDisable: [
"lk",
"shop"
],
whereInfo: [
"lk",
"callCenter"
],
attractionChannel: [
"ad",
"shop"
],
name: "Some name",
demoPeriod: 30
};