-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathutils.spec.ts
244 lines (226 loc) · 8.4 KB
/
utils.spec.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import {
PdfCellRenderArgs, ToolbarArgs, RenameReportArgs, RemoveReportArgs, SaveReportArgs, FetchReportArgs, LoadReportArgs,
NumberFormattingEventArgs
} from '../src/common/base/interface';
import { BeforeExportEventArgs } from '../src';
import { isNullOrUndefined, addClass, removeClass } from '@syncfusion/ej2-base';
import { Dialog } from '@syncfusion/ej2-popups';
import { TreeView } from '@syncfusion/ej2-navigations';
export function copyObject(source: any, destiation: any): Object {
for (let prop of source) {
destiation[prop] = source[prop];
}
return destiation;
}
export function disableDialogAnimation(dialogObject: Dialog): void {
dialogObject.animationSettings = { effect: 'None' };
dialogObject.dataBind();
dialogObject.hide();
}
export function getEventObject(eventType: string, eventName: string, currentTarget?: Element, target?: Element, x?: number, y?: number): Object {
let tempEvent: any = document.createEvent(eventType);
tempEvent.initEvent(eventName, true, true);
let returnObject: any = copyObject(tempEvent, {});
returnObject.preventDefault = () => { return true; };
if (!isNullOrUndefined(x)) {
returnObject.pageX = x;
returnObject.clientX = x;
}
if (!isNullOrUndefined(y)) {
returnObject.pageY = y;
returnObject.clientY = y;
}
if (!isNullOrUndefined(currentTarget)) {
returnObject.currentTarget = currentTarget;
}
if (!isNullOrUndefined(target)) {
returnObject.target = returnObject.srcElement = returnObject.toElement = target;
returnObject.offsetY = 7;
}
returnObject.type = 'mouse';
return returnObject;
}
export function setMouseCordinates(eventarg: any, x: number, y: number): Object {
eventarg.pageX = x;
eventarg.pageY = y;
eventarg.clientX = x;
eventarg.clientY = y;
eventarg.offsetY = 7;
return eventarg;
}
export function triggerMouseEvent(node: HTMLElement, eventType: string, x?: number, y?: number) {
let mouseEve: MouseEvent = document.createEvent('MouseEvents');
if (x && y) {
mouseEve.initMouseEvent(eventType, true, true, window, 0, 0, 0, x, y, false, false, false, false, 0, null);
} else {
mouseEve.initEvent(eventType, true, true);
}
node.dispatchEvent(mouseEve);
}
export function triggerEvent(node: HTMLElement, eventType: string) {
let mouseEve: MouseEvent = document.createEvent('MouseEvents');
mouseEve.initEvent(eventType, true, true);
node.dispatchEvent(mouseEve);
}
export function saveReport(args: SaveReportArgs): void {
let reports: SaveReportArgs[] = [];
let isSaved: boolean = false;
if (localStorage.pivotviewReports && localStorage.pivotviewReports !== "") {
reports = JSON.parse(localStorage.pivotviewReports);
}
if (args.report && args.reportName && args.reportName !== '') {
reports.map(function (item: any): any {
if (args.reportName === item.reportName) {
item.report = args.report; isSaved = true;
}
});
if (!isSaved) {
reports.push(args);
}
localStorage.pivotviewReports = JSON.stringify(reports);
}
}
export function fetchReport(args: FetchReportArgs): void {
let reportCollection: string[] = [];
let reeportList: string[] = [];
if (localStorage.pivotviewReports && localStorage.pivotviewReports !== "") {
reportCollection = JSON.parse(localStorage.pivotviewReports);
}
reportCollection.map(function (item: any): void { reeportList.push(item.reportName); });
args.reportName = reeportList;
}
export function loadReport(args: LoadReportArgs): void {
let reportCollection: string[] = [];
if (localStorage.pivotviewReports && localStorage.pivotviewReports !== "") {
reportCollection = JSON.parse(localStorage.pivotviewReports);
}
reportCollection.map(function (item: any): void {
if (args.reportName === item.reportName) {
args.report = item.report;
}
});
if (args.report) {
this.dataSource = JSON.parse(args.report).dataSource;
}
}
export function removeReport(args: RemoveReportArgs): void {
let reportCollection: any[] = [];
if (localStorage.pivotviewReports && localStorage.pivotviewReports !== "") {
reportCollection = JSON.parse(localStorage.pivotviewReports);
}
for (let i: number = 0; i < reportCollection.length; i++) {
if (reportCollection[i].reportName === args.reportName) {
reportCollection.splice(i, 1);
}
}
if (localStorage.pivotviewReports && localStorage.pivotviewReports !== "") {
localStorage.pivotviewReports = JSON.stringify(reportCollection);
}
}
export function renameReport(args: RenameReportArgs): void {
let reportCollection: string[] = [];
if (localStorage.pivotviewReports && localStorage.pivotviewReports !== "") {
reportCollection = JSON.parse(localStorage.pivotviewReports);
}
reportCollection.map(function (item: any): any { if (args.reportName === item.reportName) { item.reportName = args.rename; } });
if (localStorage.pivotviewReports && localStorage.pivotviewReports !== "") {
localStorage.pivotviewReports = JSON.stringify(reportCollection);
}
}
export function newReport(): void {
}
export function beforeToolbarRender(args: ToolbarArgs): void {
args.customToolbar.splice(4, 0, {
prefixIcon: 'e-new-report e-icons', tooltipText: 'ADD', id: 'new-report'
});
}
export function beforeExport(args: BeforeExportEventArgs): void {
args.dataCollections.push(args.dataCollections[0]);
args.header = 'This is Header';
args.footer = 'This is Footer';
args.style = {
header: {
bold: true,
border: { color: '#000000', dashStyle: 'DashDot', width: 2 },
fontColor: '#bd1616',
fontName: 'Symbol',
underline: true,
italic: true,
strikeout: true,
fontSize: 8
},
record: {
bold: true,
border: { color: '#000000', dashStyle: 'Dot', width: 2 },
fontColor: '#bd1616',
fontName: 'Courier',
underline: true,
italic: true,
strikeout: true,
fontSize: 8
}
};
}
export function pdfCellRender(args: PdfCellRenderArgs): void {
if (args.pivotCell && args.pivotCell.formattedText == 'balance') {
args.style = {
backgroundColor: '#bd1616',
bold: true,
textBrushColor: '#00FFFF',
textPenColor: '#0000FF',
border: { color: '#000000', dashStyle: 'DashDotDot', width: 2 },
underline: true,
italic: true,
strikeout: true,
fontSize: 8,
fontFamily: undefined
};
} else if (args.pivotCell && args.pivotCell.formattedText == 'blue') {
args.style = {
backgroundColor: '#bd1616',
bold: true,
textBrushColor: '#00FFFF',
textPenColor: '#0000FF',
border: { color: '#000000', dashStyle: 'Dash', width: 2 },
underline: true,
italic: true,
strikeout: true,
fontSize: 8,
fontFamily: 'TimesNewRoman'
};
} else if (args.pivotCell && args.pivotCell.formattedText == 'true') {
args.style = {
backgroundColor: '#bd1616',
bold: true,
textBrushColor: '#00FFFF',
textPenColor: '#0000FF',
border: undefined,
underline: true,
italic: true,
strikeout: true,
fontSize: 8,
fontFamily: 'TimesRoman'
};
} else {
args.style = {
backgroundColor: '#bd1616',
bold: true,
textBrushColor: '#00FFFF',
textPenColor: '#0000FF',
border: { color: '#000000', dashStyle: 'DashDotDot', width: 2 },
underline: true,
italic: true,
strikeout: true,
fontSize: 8,
fontFamily: 'ZapfDingbats'
};
}
}
export function checkTreeNode(treeObj: TreeView, li: Element): void {
removeClass(treeObj.element.querySelectorAll('li'), ['e-node-focus', 'e-active']);
addClass([li], ['e-node-focus', 'e-active']);
(treeObj as any).checkNode((li).getAttribute('data-uid'));
}
export function numberFormatting(args: NumberFormattingEventArgs): void {
args.cancel = true;
}