raise-common-lib 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,420 @@
1
+ import {
2
+ Component,
3
+ EventEmitter,
4
+ Input,
5
+ OnInit,
6
+ Output,
7
+ TemplateRef,
8
+ OnChanges,
9
+ ViewChild,
10
+ SimpleChanges,
11
+ ChangeDetectorRef,
12
+ } from '@angular/core';
13
+ import { GridComponent } from '@syncfusion/ej2-angular-grids';
14
+
15
+ import { BeforeOpenCloseEventArgs } from '@syncfusion/ej2-angular-inputs';
16
+ import { IActionMenuItem, IColumnField } from '../constant';
17
+
18
+ @Component({
19
+ selector: 'kt-common-grid',
20
+ templateUrl: './index.component.html',
21
+ styleUrls: ['./index.component.scss'],
22
+ })
23
+ export class CommonGridComponent implements OnInit, OnChanges {
24
+ @ViewChild('grid', { static: false })
25
+ public grid: GridComponent;
26
+ @Input() showCheckBox = true;
27
+ @Input() loaded = true;
28
+ @Input() hiddenLoaded = false;
29
+ @Input() authorized = true; // Dataset是否授权,未授权则显示权限错误提示
30
+ // only use for local data pagination
31
+ @Input() selectedDiffKey = '';
32
+ @Input() gridHeight = '';
33
+ // 这玩意必填,不然filter columnChooser都会报错
34
+ @Input() gridId = 'grid';
35
+ @Input() resizeSettings = { mode: 'Auto' };
36
+ @Input() filterSettings = { type: 'Menu' };
37
+ @Input() template: any;
38
+ @Input() fields: IColumnField[] = [];
39
+ @Input() dataSource = [];
40
+ @Input() editSettings;
41
+ @Input() columnTemplate: TemplateRef<any>;
42
+ @Input() pageSettings;
43
+ @Input() allowPaging = true;
44
+ @Input() clipMode = 'EllipsisWithTooltip';
45
+ @Input() checkBoxWidth = 32; // col 数量过少的时候,check宽度会拉伸,这时候设置null
46
+ @Input() childGrid;
47
+
48
+ /**
49
+ * Sample: [
50
+ {
51
+ text: "Preview",
52
+ target: ".e-content",
53
+ id: "preview-icon",
54
+ iconCss: "preview",
55
+ },
56
+ {
57
+ text: "Download",
58
+ target: ".e-content",
59
+ id: "download-icon",
60
+ iconCss: "download",
61
+ }
62
+ ]
63
+ 用于定义row中 点击事件
64
+ */
65
+ @Input() contextMenuItems: IActionMenuItem[] = [];
66
+ // @Input() selectionSettings = { checkboxOnly: true, type: "Multiple" };
67
+ @Input() selectionSettings = {
68
+ type: 'Multiple',
69
+ // persistSelection: true,
70
+ checkboxOnly: true,
71
+ };
72
+ @Input() alwaysShowCheckbox: boolean = false;
73
+ @Input() defaultRecord: any;
74
+ @Input() disableSystemRow: boolean = false; // 禁用IsSytem = true的整行
75
+
76
+ @Output() recordDoubleClick = new EventEmitter();
77
+ @Output() actionComplete = new EventEmitter();
78
+ @Output() rowSelected = new EventEmitter();
79
+ @Output() rowDeselected = new EventEmitter();
80
+ @Output() onContextMenu = new EventEmitter();
81
+ @Output() actionHandler = new EventEmitter();
82
+ @Output() queryCellInfo = new EventEmitter();
83
+ @Output() recordClick = new EventEmitter();
84
+ @Output() actionBegin = new EventEmitter();
85
+ @Output() rowDataBound = new EventEmitter();
86
+ @Output() dataBound = new EventEmitter();
87
+ @Output() exportQueryCellInfo = new EventEmitter();
88
+ @Output() rowSelecting = new EventEmitter();
89
+
90
+ selectId = [];
91
+ startPaging = false;
92
+ indexList = [];
93
+ className = 'grid-loading';
94
+
95
+ public translation;
96
+
97
+ constructor(private ref: ChangeDetectorRef) {
98
+ this.translation = JSON.parse(localStorage.getItem('translation'));
99
+ }
100
+
101
+ ngOnInit(): void {
102
+ if (this.hiddenLoaded) this.className = '';
103
+ this.ref && this.ref.markForCheck();
104
+ }
105
+
106
+ trackByFn(index, item) {
107
+ return index; // or a unique identifier in your object
108
+ }
109
+ ngOnChanges(changes: SimpleChanges) {
110
+ if (changes.dataSource && changes.dataSource.currentValue) {
111
+ if (
112
+ this.allowPaging &&
113
+ changes.dataSource.currentValue.length &&
114
+ !this.pageSettings
115
+ ) {
116
+ this.pageSettings =
117
+ changes.dataSource.currentValue.length > 9
118
+ ? {
119
+ pageSizes: ['All', '25', '50', '100'],
120
+ pageSize: 50,
121
+ }
122
+ : null;
123
+ }
124
+ }
125
+ }
126
+
127
+ _load() {
128
+ if (!this.authorized) {
129
+ (this.grid.localeObj as any).localeStrings.EmptyRecord =
130
+ this.translation.YOU_DO_NOT_HAVE_THE_DATASET_PERMISSION ||
131
+ "You don't have the dataset permission to view the record.";
132
+ }
133
+ }
134
+
135
+ _dataBound(args: any) {
136
+ // 整个组件加载完成时的回调函数
137
+ var pagerContainer = document.querySelector('.e-pagercontainer');
138
+ if (pagerContainer) {
139
+ var linkElements = pagerContainer.querySelectorAll('.e-link');
140
+ linkElements.forEach(function (element) {
141
+ element.removeAttribute('href'); // SMP2-10310 删除分页器的href属性
142
+ });
143
+ }
144
+ if (this.selectedDiffKey) {
145
+ setTimeout(() => {
146
+ this.chooseRecords();
147
+ });
148
+ }
149
+ this.dataBound.emit(args);
150
+ }
151
+
152
+ _exportQueryCellInfo(args) {
153
+ this.exportQueryCellInfo.emit(args);
154
+ }
155
+
156
+ _recordDoubleClick($event) {
157
+ this.recordDoubleClick.emit($event);
158
+ }
159
+ /**
160
+ * [selectionSettings]="{ checkboxOnly: true }"
161
+ [showCheckBox]="true"
162
+ 控件使用时,必须配置上面两个属性,否则,全选会失效
163
+ */
164
+ _rowSelected($event) {
165
+ if (this.selectedDiffKey) {
166
+ if ($event.isHeaderCheckboxClicked && Array.isArray($event.data)) {
167
+ if ($event.data && $event.data.length) {
168
+ $event.data.forEach((item) => {
169
+ item.isSelected = true;
170
+ this.selectId.push(item);
171
+ });
172
+ this.dataSource.forEach((data) => {
173
+ $event.data.forEach((_data) => {
174
+ if (_data[this.selectedDiffKey] === data[this.selectedDiffKey]) {
175
+ data.isSelected = true;
176
+ }
177
+ });
178
+ });
179
+ }
180
+ } else {
181
+ $event.data.isSelected = true;
182
+ this.selectId.push($event.data);
183
+ this.dataSource.forEach((data) => {
184
+ if (
185
+ data[this.selectedDiffKey] === $event.data[this.selectedDiffKey]
186
+ ) {
187
+ data.isSelected = true;
188
+ }
189
+ });
190
+ }
191
+ this.ref && this.ref.markForCheck();
192
+ }
193
+ this.rowSelected.emit($event);
194
+ }
195
+
196
+ _rowDeselected($event) {
197
+ if (this.selectedDiffKey) {
198
+ if (this.startPaging) {
199
+ return;
200
+ }
201
+ if ($event.isHeaderCheckboxClicked && Array.isArray($event.data)) {
202
+ $event.data.forEach((item) => {
203
+ item.isSelected = false;
204
+ });
205
+ this.selectId = [];
206
+ this.dataSource.forEach((data) => {
207
+ $event.data.forEach((_data) => {
208
+ if (_data[this.selectedDiffKey] === data[this.selectedDiffKey]) {
209
+ data.isSelected = false;
210
+ }
211
+ });
212
+ });
213
+ } else {
214
+ $event.data.isSelected = false;
215
+ this.selectId = this.selectId.filter(
216
+ (item) =>
217
+ item[this.selectedDiffKey] !== $event.data[this.selectedDiffKey]
218
+ );
219
+ this.dataSource.forEach((data) => {
220
+ if (
221
+ data[this.selectedDiffKey] === $event.data[this.selectedDiffKey]
222
+ ) {
223
+ data.isSelected = false;
224
+ }
225
+ });
226
+ }
227
+ this.ref && this.ref.markForCheck();
228
+ }
229
+ this.rowDeselected.emit($event);
230
+ }
231
+
232
+ _onContextMenu(args) {
233
+ this.onContextMenu.emit(args);
234
+ }
235
+
236
+ _actionBegin(args) {
237
+ if (
238
+ this.selectedDiffKey &&
239
+ (args.requestType === 'paging' ||
240
+ args.requestType === 'searching' ||
241
+ args.requestType === 'filtering' ||
242
+ args.requestType === 'sorting')
243
+ ) {
244
+ this.startPaging = true;
245
+ }
246
+ this.actionBegin.emit(args);
247
+ }
248
+
249
+ search(keywords) {
250
+ this.grid.search(keywords);
251
+ }
252
+ selectRows(indexList: number[]) {
253
+ this.grid.selectRows(indexList);
254
+ }
255
+ selectRow(index) {
256
+ this.grid.selectRow(index);
257
+ }
258
+ getCurrentViewRecords() {
259
+ return this.grid.getCurrentViewRecords();
260
+ }
261
+
262
+ customiseCell($event) {
263
+ this.queryCellInfo.emit($event);
264
+ }
265
+
266
+ contextMenuOpen(args?: BeforeOpenCloseEventArgs): void {
267
+ const data = (args as BeforeOpenCloseEventArgs | any).rowInfo.rowData;
268
+ if (!data) {
269
+ args.cancel = true;
270
+ return;
271
+ }
272
+ let enableItems = [];
273
+ let hideItems = [];
274
+ this.grid.contextMenuModule.contextMenu.refresh(); // 每次点击按钮弹窗前需再次初始化状态 否则不更新;
275
+ this.contextMenuItems.forEach((item: IActionMenuItem) => {
276
+ // 用于处理部分按钮disabled的情况
277
+ if (
278
+ item.disabled ||
279
+ (data.disableItem && data.disableItem.includes(item.iconCss))
280
+ ) {
281
+ enableItems.push(item.text);
282
+ // this.grid.contextMenuModule.contextMenu.enableItems(
283
+ // [item.text],
284
+ // false
285
+ // );
286
+ }
287
+ // 用于处理部分按钮需要hide的情况
288
+ if (
289
+ item.isHide ||
290
+ (data.hideItem && data.hideItem.includes(item.iconCss))
291
+ ) {
292
+ hideItems.push(item.text);
293
+ // this.grid.contextMenuModule.contextMenu.hideItems(
294
+ // [item.text],
295
+ // false
296
+ // );
297
+ }
298
+ });
299
+ this.grid.contextMenuModule.contextMenu.enableItems(enableItems, false);
300
+ this.grid.contextMenuModule.contextMenu.hideItems(hideItems, false);
301
+ }
302
+
303
+ _actionHandler($event) {
304
+ if (
305
+ this.selectedDiffKey &&
306
+ ($event.requestType === 'paging' ||
307
+ $event.requestType === 'searching' ||
308
+ $event.requestType === 'filtering' ||
309
+ $event.requestType === 'sorting')
310
+ ) {
311
+ this.indexList = [];
312
+ setTimeout(() => {
313
+ this.chooseRecords();
314
+ this.startPaging = false;
315
+ this.ref && this.ref.detectChanges();
316
+ this.ref && this.ref.markForCheck();
317
+ });
318
+ }
319
+ this.actionHandler.emit($event);
320
+ this.actionComplete.emit($event);
321
+ }
322
+
323
+ private chooseRecords() {
324
+ this.indexList = [];
325
+ this.dataSource.forEach((data) => {
326
+ this.grid.getCurrentViewRecords().forEach((row: any, i) => {
327
+ if (
328
+ row &&
329
+ data[this.selectedDiffKey] === row[this.selectedDiffKey] &&
330
+ data.isSelected
331
+ ) {
332
+ this.indexList.push(i);
333
+ }
334
+ });
335
+ });
336
+
337
+ this.grid.selectRows(this.indexList);
338
+ }
339
+
340
+ _recordClick($event) {
341
+ this.recordClick.emit($event);
342
+ }
343
+ refresh() {
344
+ this.grid.refresh();
345
+ }
346
+ _rowSelecting(e) {
347
+ this.rowSelecting.emit(e);
348
+ }
349
+ refreshColumns() {
350
+ this.grid.refreshColumns();
351
+ }
352
+ refreshHeader() {
353
+ this.grid.refreshHeader();
354
+ }
355
+
356
+ export(excelExportProperties?) {
357
+ this.grid.excelExport(excelExportProperties);
358
+ }
359
+
360
+ getSelectedRecords() {
361
+ return this.grid.getSelectedRecords();
362
+ }
363
+
364
+ _rowDataBound($event) {
365
+ if (this.disableSystemRow && $event.data && $event.data.IsSystem) {
366
+ $event.row.classList.add('e-disabled');
367
+ }
368
+ this.rowDataBound.emit($event);
369
+ }
370
+
371
+ clearSelection() {
372
+ this.grid.clearSelection();
373
+ }
374
+
375
+ excelExport() {
376
+ this.grid.excelExport();
377
+ }
378
+
379
+ addItem() {
380
+ this.grid.addRecord({ ...this.defaultRecord, isNew: true }, 0);
381
+ setTimeout(() => {
382
+ this.grid.selectRow(0);
383
+ this.grid.startEdit();
384
+ }, 30);
385
+ }
386
+
387
+ saveItem() {
388
+ this.grid.endEdit();
389
+ }
390
+
391
+ editItem(index) {
392
+ setTimeout(() => {
393
+ this.grid.selectRow(Number(index));
394
+ this.grid.startEdit();
395
+ }, 30);
396
+ }
397
+
398
+ deleteItem(index) {
399
+ this.grid.selectRow(Number(index));
400
+ var selectedRecord = this.grid.getSelectedRecords()[0] as any;
401
+ this.grid.deleteRecord(selectedRecord as string);
402
+ }
403
+
404
+ cancelItem(index) {
405
+ this.grid.closeEdit();
406
+ this.deleteItem(index);
407
+ }
408
+
409
+ public showLoading() {
410
+ this.className = 'grid-loading';
411
+ this.ref && this.ref.markForCheck();
412
+ this.ref && this.ref.detectChanges();
413
+ }
414
+
415
+ public hideLoading() {
416
+ this.className = '';
417
+ this.ref && this.ref.markForCheck();
418
+ this.ref && this.ref.detectChanges();
419
+ }
420
+ }
@@ -0,0 +1,59 @@
1
+ import { ContextMenuItemModel } from "@syncfusion/ej2-angular-grids";
2
+
3
+ export interface IColumnField {
4
+ columnName: string;
5
+ columnDisplayName: string;
6
+ visible: boolean;
7
+ /**
8
+ * sample: { class: 'hideColumnFilterClass' }
9
+ * 可以考虑在部分情况下给column增加class等attribute
10
+ */
11
+ customAttributes?: string;
12
+ // 不填默认是Left
13
+ textAlign?: "Left" | "Right" | "Center";
14
+ width?: number;
15
+ dataType?: string;
16
+ format?: string;
17
+ translationCode?: string;
18
+ showColumnMenu?: boolean;
19
+ showTemplate?: boolean;
20
+ allowFiltering?: boolean;
21
+ allowSorting?: boolean;
22
+ allowEditing?: boolean;
23
+ minWidth?: number | string;
24
+ editType?: string;
25
+ dropdownParams?: any;
26
+ dateComparer?: any;
27
+ sortComparer?: any;
28
+ clipMode?: string;
29
+ filter?: any;
30
+ colName?: string;
31
+ validationRules?: any;
32
+ }
33
+
34
+ export interface IActionMenuItem extends ContextMenuItemModel {
35
+ disabled?: boolean;
36
+ isHide?: boolean;
37
+ }
38
+
39
+ export enum ButtonColorType {
40
+ PRIMARY = "primary",
41
+ CANCEL = "cancel",
42
+ }
43
+
44
+ enum IconPosition {
45
+ FRONT = "front",
46
+ BEHIND = "behind",
47
+ }
48
+
49
+ export interface BaseButton {
50
+ label: string;
51
+ type?: ButtonColorType;
52
+ icon?: string;
53
+ iconPosition?: IconPosition;
54
+ callMethod?: string;
55
+ translationCode?: string;
56
+ value?: any;
57
+ }
58
+
59
+ export interface DrawerButton extends BaseButton {}
@@ -0,0 +1,48 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { CommonGridComponent } from './common-grid/index.component';
3
+ import { CommonModule } from '@angular/common';
4
+
5
+ import {
6
+ GridModule,
7
+ PageService,
8
+ SortService,
9
+ FilterService,
10
+ ExcelExportService,
11
+ EditService,
12
+ ResizeService,
13
+ ToolbarService,
14
+ ColumnChooserService,
15
+ AggregateService,
16
+ ColumnMenuService,
17
+ DetailRowService,
18
+ SelectionService,
19
+ PagerModule,
20
+ GroupService,
21
+ GridAllModule,
22
+ } from '@syncfusion/ej2-angular-grids';
23
+
24
+ @NgModule({
25
+ declarations: [
26
+ CommonGridComponent,
27
+ ],
28
+ imports: [CommonModule, GridModule, PagerModule, GridAllModule],
29
+ providers: [
30
+ PageService,
31
+ SortService,
32
+ FilterService,
33
+ ExcelExportService,
34
+ EditService,
35
+ ResizeService,
36
+ ToolbarService,
37
+ ColumnChooserService,
38
+ AggregateService,
39
+ ColumnMenuService,
40
+ DetailRowService,
41
+ SelectionService,
42
+ GroupService,
43
+ ],
44
+ exports: [
45
+ CommonGridComponent,
46
+ ]
47
+ })
48
+ export class RaiseCommonLibModule { }
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Public API Surface of raise-common-lib
3
+ */
4
+ export * from './lib/common-grid/index.component';
5
+ export * from './lib/raise-common-lib.module';
@@ -0,0 +1,26 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../out-tsc/lib",
5
+ "target": "es2015",
6
+ "declaration": true,
7
+ "inlineSources": true,
8
+ "types": [],
9
+ "lib": [
10
+ "dom",
11
+ "es2018"
12
+ ]
13
+ },
14
+ "angularCompilerOptions": {
15
+ "annotateForClosureCompiler": true,
16
+ "skipTemplateCodegen": true,
17
+ "strictMetadataEmit": true,
18
+ "fullTemplateTypeCheck": true,
19
+ "strictInjectionParameters": true,
20
+ "enableResourceInlining": true
21
+ },
22
+ "exclude": [
23
+ "src/test.ts",
24
+ "**/*.spec.ts"
25
+ ]
26
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../out-tsc/spec",
5
+ "types": [
6
+ "jasmine",
7
+ "node"
8
+ ]
9
+ },
10
+ "files": [
11
+ "src/test.ts"
12
+ ],
13
+ "include": [
14
+ "**/*.spec.ts",
15
+ "**/*.d.ts"
16
+ ]
17
+ }
package/tslint.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../tslint.json",
3
+ "rules": {
4
+ "directive-selector": [
5
+ true,
6
+ "attribute",
7
+ "lib",
8
+ "camelCase"
9
+ ],
10
+ "component-selector": [
11
+ true,
12
+ "element",
13
+ "lib",
14
+ "kebab-case"
15
+ ]
16
+ }
17
+ }