-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathviewConfig.js
219 lines (195 loc) · 5.04 KB
/
viewConfig.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/// /@ts-check
const { WOQLRule } = require('./woqlRule');
/**
* Generic functions / configs that are available to all config types
* @module ViewConfig
* @constructor
*/
function ViewConfig() {
this.rules = [];
}
ViewConfig.prototype.render = function (func) {
if (func) this.view_render = func;
return this.view_render;
};
ViewConfig.prototype.renderer = function (val) {
if (val) this.view_renderer = val;
return this.view_renderer;
};
ViewConfig.prototype.getRulesJSON = function () {
const jr = [];
// eslint-disable-next-line no-plusplus
for (let i = 0; i < this.rules.length; i++) {
jr.push(this.rules[i].json());
}
return jr;
};
ViewConfig.prototype.getBasicJSON = function () {
const jr = {};
if (this.view_render) jr.render = this.view_render;
if (this.view_renderer) jr.renderer = this.view_renderer;
if (this.vbindings) jr.bindings = this.vbindings;
return jr;
};
ViewConfig.prototype.loadBasicJSON = function (json) {
if (json.render) this.view_render = json.view_render;
if (json.renderer) this.view_renderer = json.view_renderer;
if (json.bindings) this.vbindings = json.bindings;
};
ViewConfig.prototype.getBasicprettyPrint = function () {
let str = '';
if (typeof this.render() !== 'undefined') {
str += `view.render(${this.render()})\n`;
}
if (typeof this.renderer() !== 'undefined') {
str += `view.renderer('${this.renderer()}')\n`;
}
if (typeof this.bindings() !== 'undefined') {
str += `view.bindings('${this.bindings()}')\n`;
}
return str;
};
ViewConfig.prototype.bindings = function (bindings) {
if (typeof bindings !== 'undefined') {
this.vbindings = bindings;
}
return this.vbindings;
};
/**
* @module WOQLViewRule
* @constructor
*/
function WOQLViewRule() {
WOQLRule.call(this);
this.rule = {};
}
Object.setPrototypeOf(WOQLViewRule.prototype, WOQLRule.prototype);
WOQLViewRule.prototype.prettyPrint = function (type) {
let str = '';
if (this.pattern) {
str = this.pattern.prettyPrint(type);
}
if (typeof this.color() !== 'undefined') {
str += `.color([${this.color().join(',')}])`;
}
if (typeof this.hidden() !== 'undefined') {
str += `.hidden(${this.hidden()})`;
}
if (typeof this.size() !== 'undefined') {
str += `.size('${this.size()}')`;
}
if (typeof this.icon() !== 'undefined') {
str += `.icon(${JSON.stringify(this.icon())})`;
}
if (typeof this.text() !== 'undefined') {
str += `.text(${JSON.stringify(this.text())})`;
}
if (typeof this.border() !== 'undefined') {
str += `.border(${JSON.stringify(this.border())})`;
}
if (typeof this.args() !== 'undefined') {
str += `.args(${JSON.stringify(this.args())})`;
}
if (typeof this.renderer() !== 'undefined') {
str += `.renderer('${this.renderer()}')`;
}
if (typeof this.render() !== 'undefined') {
str += `.render(${this.render()})`;
}
if (typeof this.click() !== 'undefined') {
str += `.click(${this.click()})`;
}
if (typeof this.hover() !== 'undefined') {
str += `.hover(${this.hover()})`;
}
return str;
};
WOQLViewRule.prototype.json = function (mjson) {
if (!mjson) {
const json = {};
if (this.pattern) json.pattern = this.pattern.json();
json.rule = this.rule;
return json;
}
this.rule = mjson.rule || {};
if (mjson.pattern) this.pattern.setPattern(mjson.pattern);
return this;
};
WOQLViewRule.prototype.size = function (size) {
if (typeof size === 'undefined') {
return this.rule.size;
}
this.rule.size = size;
return this;
};
WOQLViewRule.prototype.color = function (color) {
if (typeof color === 'undefined') {
return this.rule.color;
}
this.rule.color = color;
return this;
};
WOQLViewRule.prototype.icon = function (json) {
if (json) {
this.rule.icon = json;
return this;
}
return this.rule.icon;
};
WOQLViewRule.prototype.text = function (json) {
if (json) {
this.rule.text = json;
return this;
}
return this.rule.text;
};
WOQLViewRule.prototype.border = function (json) {
if (json) {
this.rule.border = json;
return this;
}
return this.rule.border;
};
WOQLViewRule.prototype.renderer = function (rend) {
if (typeof rend === 'undefined') {
return this.rule.renderer;
}
this.rule.renderer = rend;
return this;
};
WOQLViewRule.prototype.render = function (func) {
if (typeof func === 'undefined') {
return this.rule.render;
}
this.rule.render = func;
return this;
};
WOQLViewRule.prototype.click = function (onClick) {
if (onClick) {
this.rule.click = onClick;
return this;
}
return this.rule.click;
};
WOQLViewRule.prototype.hover = function (onHover) {
if (onHover) {
this.rule.hover = onHover;
return this;
}
return this.rule.hover;
};
WOQLViewRule.prototype.hidden = function (hidden) {
if (typeof hidden === 'undefined') {
return this.rule.hidden;
}
this.rule.hidden = hidden;
return this;
};
WOQLViewRule.prototype.args = function (args) {
if (typeof args === 'undefined') {
return this.rule.args;
}
this.rule.args = args;
return this;
};
module.exports = { WOQLViewRule, ViewConfig };