This repository has been archived by the owner on Aug 3, 2021. It is now read-only.
/
controller.js
208 lines (157 loc) · 5.36 KB
/
controller.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
export class Controller {
constructor(vGrid) {
//main context
this.vGrid = vGrid;
//main element
this.element = vGrid.element;
}
getContext() {
let c = this.vGrid;
//column configuration
this.colConfig = c.colConfig;
//aurelia classes
this.viewCompiler = c.viewCompiler;
this.container = c.container;
this.viewResources = c.viewResources;
this.taskQueue = c.taskQueue;
//classes
this.htmlCache = c.htmlCache;
this.htmlHeightWidth = c.htmlHeightWidth;
this.viewSlots = c.viewSlots;
this.columnBindingContext = c.columnBindingContext;
this.rowDataBinder = c.rowDataBinder;
this.mainMarkup = c.mainMarkup;
this.mainScrollEvents = c.mainScrollEvents;
this.rowMarkup = c.rowMarkup;
this.rowScrollEvents = c.rowScrollEvents;
this.rowClickHandler = c.rowClickHandler;
this.htmlcolumnMarkupCache = c.columnMarkup;
this.columnMarkup = c.columnMarkup;
this.groupingElements = c.groupingElements;
this.loadingScreen = c.loadingScreen;
this.contextMenu = c.contextMenu;
//attributes
this.bindingContext = c.bindingContext;
this.overrideContext = c.overrideContext;
this.attRowHeight = c.attRowHeight;
this.attHeaderHeight = c.attHeaderHeight;
this.attFooterHeight = c.attFooterHeight;
this.attPanelHeight = c.attPanelHeight;
this.attMultiSelect = c.attMultiSelect;
this.attManualSelection = c.attManualSelection;
this.attGridConnector = c.attGridConnector;
}
createGrid() {
//sets default height and widths of the grid
this.htmlHeightWidth.addDefaultsAttributes(this.attHeaderHeight, this.attRowHeight, this.attFooterHeight, this.attPanelHeight);
//generate main markup and updates our cache
this.mainMarkup.generateMainMarkup();
this.htmlCache.updateMainMarkup();
this.rowDataBinder.init();
//starts the scroll events on main html markup (left/main/right)
this.mainScrollEvents.init();
//creates main row markup and attaches them, then we chache this html also
this.rowMarkup.init(this.attRowHeight);
this.htmlCache.updateRowsMarkup();
//add scroll events (the one that moves the actual rows when scroling)
this.rowScrollEvents.init(this.attRowHeight);
//creates the views/viewports we need
this.columnMarkup.init(this.colConfig, this.overrideContext);
//more updates to main markup
this.htmlHeightWidth.setWidthFromColumnConfig(this.colConfig);
//register the rowClick handler (when clicking on rows)
this.rowClickHandler.init(this.attMultiSelect, this.attManualSelection, this);
//create grouping elements helper... pretty much just creates view when dragging to group box
this.groupingElements.init(this);
//loading screen view
this.loadingScreen.init(this.overrideContext);
//add context menu
this.contextMenu.init();
}
//misc function, all calls to/from gridconnector will go in functions here, mostly.. I think...
getElement(row, isDown, callback) {
this.attGridConnector.getElement({
row: row,
isDown: isDown,
callback: callback
});
}
getOperatorName(name) {
return this.attGridConnector.getFilterOperatorName(name);
}
expandGroup(id) {
this.attGridConnector.expandGroup(id);
}
collapseGroup(id) {
this.attGridConnector.collapseGroup(id);
}
select(row) {
this.attGridConnector.select(row);
}
addToGrouping(attribute) {
let currentGrouping = this.attGridConnector.getGrouping();
currentGrouping.push(attribute);
this.attGridConnector.group(currentGrouping, true);
}
removeFromGrouping(attribute) {
let currentGrouping = this.attGridConnector.getGrouping();
let index = currentGrouping.indexOf(attribute);
if (index !== -1) {
currentGrouping.splice(index, 1);
this.attGridConnector.group(currentGrouping, true);
}
}
getSelectionContext() {
return this.attGridConnector.selection;
}
raiseEvent(name, data = {}) {
let event = new CustomEvent(name, {
detail: data,
bubbles: true
});
this.element.dispatchEvent(event);
return event;
}
setLoadingScreen(value, msg, collectionLength) {
if (value) {
return this.loadingScreen.enable(msg, collectionLength);
} else {
return this.loadingScreen.disable();
}
}
updateHeights() {
this.rowScrollEvents.setCollectionLength(this.attGridConnector.length());
this.htmlHeightWidth.setCollectionLength(this.attGridConnector.length());
}
updateHeaderGrouping(groups) {
let length = groups.length;
this.columnBindingContext.setupgrouping = length;
this.htmlHeightWidth.adjustWidthsColumns(this.columnBindingContext, length);
}
collectionLength() {
return this.attGridConnector.length();
}
triggerScroll(position) {
if (position === null || position === undefined) {
position = this.htmlCache.avg_content_main.scrollTop;
} else {
this.htmlCache.avg_content_main.scrollTop = position;
}
this.raiseEvent("avg-scroll", {
isScrollBarScrolling: true,
isDown: true,
newTopPosition: position
});
}
rebindAllRows() {
this.raiseEvent("avg-rebind-all-rows", {
rowCache: this.htmlCache.rowCache,
downScroll: true
});
}
addEventListeners() {
this.element.addEventListener("getElement", (event) => {
this.attGridConnector.getElement(event.detail);
});
}
}