-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWidgetFactory.ts
228 lines (220 loc) · 5.81 KB
/
WidgetFactory.ts
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
220
221
222
223
224
225
226
227
228
import Notebook from "./Notebook";
import Page from "./Page";
import Group from "./Group";
import Button from "./Button";
import ButtonGroup from "./ButtonGroup";
import Label from "./Label";
import Char from "./Char";
import Text from "./Text";
import Selection from "./Selection";
import Many2one from "./Many2one";
import Markdown from "./Markdown";
import Boolean from "./Boolean";
import Integer from "./Integer";
import Widget from "./Widget";
import Float from "./Float";
import FloatTime from "./FloatTime";
import HTMLPreview from "./HTMLPreview";
import ProgressBar from "./ProgressBar";
import Date from "./Date";
import DateTime from "./DateTime";
import One2many from "./One2many";
import NewLine from "./NewLine";
import Separator from "./Separator";
import Reference from "./Reference";
import Binary from "./Binary";
import Image from "./Image";
import FiberGrid from "./FiberGrid";
import Timeline from "./Timeline";
import Indicator from "./Indicator";
import Tags from "./Tags";
import Tag from "./Tag";
import Radio from "./Radio";
import MultiCheckbox from "./MultiCheckbox";
import Switch from "./Switch";
import Steps from "./Steps";
import CodeEditor from "./CodeEditor";
import Avatar from "./Avatar";
import Time from "./Time";
import Alert from "./Alert";
import Comments from "./Comments";
import JSONField from "./JSONField";
import Email from "./Email";
import Spinner from "./Spinner";
class WidgetFactory {
/**
* Widget class
*/
_widgetClass: any;
setWidgetClass(type: string): void {
switch (type) {
case "notebook":
this._widgetClass = Notebook;
break;
case "page":
this._widgetClass = Page;
break;
case "group":
this._widgetClass = Group;
break;
case "label":
this._widgetClass = Label;
break;
case "char":
this._widgetClass = Char;
break;
case "text":
this._widgetClass = Text;
break;
case "button":
this._widgetClass = Button;
break;
case "buttonGroup":
this._widgetClass = ButtonGroup;
break;
case "selection":
this._widgetClass = Selection;
break;
case "many2one":
this._widgetClass = Many2one;
break;
case "boolean":
this._widgetClass = Boolean;
break;
case "integer":
this._widgetClass = Integer;
break;
case "float":
this._widgetClass = Float;
break;
case "float_time":
this._widgetClass = FloatTime;
break;
case "date":
this._widgetClass = Date;
break;
case "datetime":
this._widgetClass = DateTime;
break;
case "progressbar":
this._widgetClass = ProgressBar;
break;
case "markdown":
this._widgetClass = Markdown;
break;
case "many2many":
case "one2many":
case "one2many_list":
this._widgetClass = One2many;
break;
case "newline":
this._widgetClass = NewLine;
break;
case "separator":
this._widgetClass = Separator;
break;
case "url":
this._widgetClass = Char;
break;
case "email":
this._widgetClass = Email;
break;
case "reference":
this._widgetClass = Reference;
break;
case "binary":
this._widgetClass = Binary;
break;
case "image":
this._widgetClass = Image;
break;
case "fiber_grid":
this._widgetClass = FiberGrid;
break;
case "timeline":
this._widgetClass = Timeline;
break;
case "indicator":
this._widgetClass = Indicator;
break;
case "tags":
this._widgetClass = Tags;
break;
case "tag":
this._widgetClass = Tag;
break;
case "avatar":
this._widgetClass = Avatar;
break;
case "radio":
this._widgetClass = Radio;
break;
case "multicheckbox":
this._widgetClass = MultiCheckbox;
break;
case "switch":
this._widgetClass = Switch;
break;
case "steps":
this._widgetClass = Steps;
break;
case "codeeditor":
this._widgetClass = CodeEditor;
break;
case "time":
this._widgetClass = Time;
break;
case "html_preview":
this._widgetClass = HTMLPreview;
break;
case "alert":
this._widgetClass = Alert;
break;
case "comments_timeline":
this._widgetClass = Comments;
break;
case "json":
this._widgetClass = JSONField;
break;
case "arrow_steps":
this._widgetClass = JSONField;
break;
case "spinner":
this._widgetClass = Spinner;
break;
default:
break;
}
}
createWidget(type: string, props: any) {
this._widgetClass = undefined;
let finalType = type;
this.setWidgetClass(type);
// Fallback to default widget, we try to use the fields type widget if it exists
if (this._widgetClass === undefined) {
finalType = props.fieldsWidgetType;
this.setWidgetClass(props.fieldsWidgetType);
}
if (this._widgetClass === undefined) {
this._widgetClass = Widget;
}
// TODO: Widget Class constructors should use only the props needed, not all props.
switch (type) {
// Specific cases (only selected props should be used)
case "notebook":
case "page":
case "group":
return new this._widgetClass({ ...props, type: finalType });
case "button":
return new this._widgetClass({
...props,
type,
buttonType: props.type,
});
// Generic case
default:
return new this._widgetClass({ ...props, type: finalType });
}
}
}
export default WidgetFactory;