@progress/kendo-angular-grid 21.2.0 → 21.3.0-develop.2
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.
- package/common/id.service.d.ts +2 -0
- package/esm2022/column-menu/column-menu-chooser.component.mjs +1 -2
- package/esm2022/column-menu/column-menu.component.mjs +4 -6
- package/esm2022/columns/column-base.mjs +1 -2
- package/esm2022/common/id.service.mjs +4 -0
- package/esm2022/grid.component.mjs +325 -274
- package/esm2022/package-metadata.mjs +2 -2
- package/esm2022/rendering/header/header.component.mjs +4 -4
- package/esm2022/rendering/toolbar/tools/ai-assistant/ai-assistant.component.mjs +11 -588
- package/esm2022/rendering/toolbar/tools/ai-assistant/ai-request-response.service.mjs +624 -0
- package/fesm2022/progress-kendo-angular-grid.mjs +1456 -1370
- package/grid.component.d.ts +41 -1
- package/package.json +25 -25
- package/rendering/toolbar/tools/ai-assistant/ai-assistant.component.d.ts +3 -23
- package/rendering/toolbar/tools/ai-assistant/ai-request-response.service.d.ts +61 -0
- package/schematics/ngAdd/index.js +7 -7
|
@@ -8,14 +8,12 @@ import { HttpClient, HttpRequest } from '@angular/common/http';
|
|
|
8
8
|
import { ContextService } from './../../../../common/provider.service';
|
|
9
9
|
import { ColumnInfoService } from './../../../../common/column-info.service';
|
|
10
10
|
import { GridAIAssistantResponseSuccessEvent, GridAIAssistantResponseErrorEvent } from './models';
|
|
11
|
-
import {
|
|
12
|
-
import { isCheckboxColumn } from '../../../../columns/column-base';
|
|
13
|
-
import { CommandColumnComponent } from '../../../../columns/command-column.component';
|
|
14
|
-
import { isPresent } from '@progress/kendo-angular-common';
|
|
11
|
+
import { GridAIRequestResponseService } from './ai-request-response.service';
|
|
15
12
|
import * as i0 from "@angular/core";
|
|
16
13
|
import * as i1 from "@angular/common/http";
|
|
17
14
|
import * as i2 from "./../../../../common/provider.service";
|
|
18
15
|
import * as i3 from "./../../../../common/column-info.service";
|
|
16
|
+
import * as i4 from "./ai-request-response.service";
|
|
19
17
|
/**
|
|
20
18
|
* @hidden
|
|
21
19
|
*/
|
|
@@ -24,6 +22,7 @@ export class AiAssistantComponent {
|
|
|
24
22
|
ctx;
|
|
25
23
|
columnInfoService;
|
|
26
24
|
zone;
|
|
25
|
+
aiRequestResponseService;
|
|
27
26
|
aiPrompt;
|
|
28
27
|
activeView = 0;
|
|
29
28
|
requestUrl;
|
|
@@ -40,42 +39,15 @@ export class AiAssistantComponent {
|
|
|
40
39
|
// flat columns used for highlight utilities (expects { field })
|
|
41
40
|
columns = [];
|
|
42
41
|
leafColumns = [];
|
|
43
|
-
// nested tree representing the actual Grid column components sent to the AI service
|
|
44
|
-
columnsTree = [];
|
|
45
42
|
idCounter = 0;
|
|
46
|
-
constructor(http, ctx, columnInfoService, zone) {
|
|
43
|
+
constructor(http, ctx, columnInfoService, zone, aiRequestResponseService) {
|
|
47
44
|
this.http = http;
|
|
48
45
|
this.ctx = ctx;
|
|
49
46
|
this.columnInfoService = columnInfoService;
|
|
50
47
|
this.zone = zone;
|
|
48
|
+
this.aiRequestResponseService = aiRequestResponseService;
|
|
51
49
|
}
|
|
52
50
|
ngAfterViewInit() {
|
|
53
|
-
// Build a nested GridColumnDescriptor tree based on the actual Grid columns structure.
|
|
54
|
-
// This includes root columns and their nested children (for ColumnGroup and SpanColumn).
|
|
55
|
-
const rootColumns = this.ctx?.grid?.columnList?.rootColumns() || [];
|
|
56
|
-
const buildDescriptor = (col) => {
|
|
57
|
-
const hasChildren = Boolean(col.hasChildren && col.childrenArray?.length);
|
|
58
|
-
const descriptor = {
|
|
59
|
-
id: col.id,
|
|
60
|
-
field: col.field
|
|
61
|
-
};
|
|
62
|
-
if (hasChildren) {
|
|
63
|
-
descriptor.header = col.displayTitle;
|
|
64
|
-
descriptor.columns = col.childrenArray.map((c) => buildDescriptor(c));
|
|
65
|
-
}
|
|
66
|
-
// For special columns that don't have a field, emit an optional type token
|
|
67
|
-
// so the AI service knows how to treat them (checkbox/command/reorder)
|
|
68
|
-
if (!col.field) {
|
|
69
|
-
if (isCheckboxColumn(col)) {
|
|
70
|
-
descriptor.type = 'checkbox';
|
|
71
|
-
}
|
|
72
|
-
else if (col instanceof CommandColumnComponent) {
|
|
73
|
-
descriptor.type = 'command';
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return descriptor;
|
|
77
|
-
};
|
|
78
|
-
this.columnsTree = rootColumns.map((col) => buildDescriptor(col));
|
|
79
51
|
// Preserve a flat columns array (fields) for highlight utilities.
|
|
80
52
|
// Use leafNamedColumns as the canonical list of leaf columns with display titles.
|
|
81
53
|
this.leafColumns = this.columnInfoService.leafNamedColumns || [];
|
|
@@ -103,8 +75,7 @@ export class AiAssistantComponent {
|
|
|
103
75
|
this.lastMessage = ev.prompt;
|
|
104
76
|
}
|
|
105
77
|
this.requestData = {
|
|
106
|
-
//
|
|
107
|
-
columns: this.columnsTree,
|
|
78
|
+
columns: [], // Will be populated by service
|
|
108
79
|
promptMessage: ev.prompt,
|
|
109
80
|
url: this.requestUrl,
|
|
110
81
|
requestOptions: {
|
|
@@ -112,16 +83,7 @@ export class AiAssistantComponent {
|
|
|
112
83
|
}
|
|
113
84
|
};
|
|
114
85
|
if (!this.requestOptions.body) {
|
|
115
|
-
|
|
116
|
-
role: this.requestData.requestOptions.role,
|
|
117
|
-
contents: [
|
|
118
|
-
{
|
|
119
|
-
text: this.requestData.promptMessage
|
|
120
|
-
}
|
|
121
|
-
],
|
|
122
|
-
columns: this.requestData.columns
|
|
123
|
-
};
|
|
124
|
-
this.requestData.requestOptions.body = requestBody;
|
|
86
|
+
this.requestData.requestOptions.body = this.aiRequestResponseService.buildRequestBody(this.requestData.promptMessage, this.requestData.requestOptions.role);
|
|
125
87
|
}
|
|
126
88
|
this.aiToolDirective.promptRequest.emit({ requestData: this.requestData, isRetry: ev.isRetry });
|
|
127
89
|
if (!this.requestUrl) {
|
|
@@ -156,12 +118,11 @@ export class AiAssistantComponent {
|
|
|
156
118
|
return;
|
|
157
119
|
}
|
|
158
120
|
const messages = [];
|
|
159
|
-
// Include optional top-level message from the response
|
|
160
121
|
if (responseBody.message) {
|
|
161
122
|
messages.push(responseBody.message);
|
|
162
123
|
}
|
|
163
|
-
|
|
164
|
-
|
|
124
|
+
const commandMessages = this.aiRequestResponseService.processCommands(responseBody.commands || [], this.columns, this.leafColumns);
|
|
125
|
+
messages.push(...commandMessages);
|
|
165
126
|
const responseContentStart = [`${this.ctx.localization.get('aiAssistantOutputCardBodyContent')} \n`];
|
|
166
127
|
const responseContentBody = messages
|
|
167
128
|
.map((output, idx) => `${idx + 1} ${output}`)
|
|
@@ -201,545 +162,7 @@ export class AiAssistantComponent {
|
|
|
201
162
|
this.currentRequestSubscription = null;
|
|
202
163
|
}
|
|
203
164
|
}
|
|
204
|
-
|
|
205
|
-
if (newItems?.length === 0) {
|
|
206
|
-
updateGrid([]);
|
|
207
|
-
}
|
|
208
|
-
else if (newItems?.length) {
|
|
209
|
-
let mergedArray = [...newItems];
|
|
210
|
-
const newFields = newItems.map(getField);
|
|
211
|
-
const existingItemsToKeep = currentItems.filter(item => !newFields.includes(getField(item)));
|
|
212
|
-
mergedArray = [...mergedArray, ...existingItemsToKeep];
|
|
213
|
-
updateGrid(mergedArray);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
processCommands(commands, messages) {
|
|
217
|
-
if (!commands?.length) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
const isFilterable = Boolean(this.ctx.grid.filterable);
|
|
221
|
-
const isSortable = Boolean(this.ctx.grid.sortable);
|
|
222
|
-
const isGroupable = Boolean(this.ctx.grid.groupable);
|
|
223
|
-
const findColumnById = (id) => this.ctx.grid.columnList.toArray().find((c) => c.id === id);
|
|
224
|
-
const updateColumnHierarchy = (column, updater) => {
|
|
225
|
-
const changed = [];
|
|
226
|
-
const queue = [column];
|
|
227
|
-
while (queue.length) {
|
|
228
|
-
const current = queue.shift();
|
|
229
|
-
if (!current) {
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
const didChange = updater(current);
|
|
233
|
-
if (didChange) {
|
|
234
|
-
changed.push(current);
|
|
235
|
-
}
|
|
236
|
-
if (current.hasChildren && current.childrenArray?.length) {
|
|
237
|
-
queue.push(...current.childrenArray);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return changed;
|
|
241
|
-
};
|
|
242
|
-
commands.forEach((cmd) => {
|
|
243
|
-
let displayMessage = cmd.message || '';
|
|
244
|
-
if (this.isColumnCommand(cmd.type)) {
|
|
245
|
-
if (cmd.id) {
|
|
246
|
-
const column = findColumnById(cmd.id);
|
|
247
|
-
const replacement = this.getColumnReplacement(column);
|
|
248
|
-
displayMessage = this.replaceQuotedColumnId(displayMessage, replacement);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
messages.push(displayMessage);
|
|
252
|
-
switch (cmd.type) {
|
|
253
|
-
case 'GridSort':
|
|
254
|
-
if (!isSortable) {
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
// cmd.sort is a SortDescriptor - replace or merge with existing sort
|
|
258
|
-
this.processArrayResponse([cmd.sort], this.ctx.grid.currentState.sort || [], (item) => item.field, (mergedArray) => this.ctx.grid.sortChange.next(mergedArray));
|
|
259
|
-
break;
|
|
260
|
-
case 'GridClearSort':
|
|
261
|
-
if (!isSortable) {
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
this.ctx.grid.sortChange.next([]);
|
|
265
|
-
break;
|
|
266
|
-
case 'GridFilter':
|
|
267
|
-
if (!isFilterable) {
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
this.processFilterResponse(cmd.filter);
|
|
271
|
-
break;
|
|
272
|
-
case 'GridClearFilter':
|
|
273
|
-
if (!isFilterable) {
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
this.ctx.grid.filterChange.next(undefined);
|
|
277
|
-
break;
|
|
278
|
-
case 'GridGroup':
|
|
279
|
-
if (!isGroupable) {
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
this.processArrayResponse([cmd.group], this.ctx.grid.currentState.group || [], (item) => item.field, (mergedArray) => this.ctx.grid.groupChange.next(mergedArray));
|
|
283
|
-
break;
|
|
284
|
-
case 'GridClearGroup':
|
|
285
|
-
if (!isGroupable) {
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
this.ctx.grid.groupChange.next([]);
|
|
289
|
-
break;
|
|
290
|
-
case 'GridHighlight':
|
|
291
|
-
if (!this.ctx.highlightDirective) {
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
this.processHighlightResponse([cmd.highlight]);
|
|
295
|
-
break;
|
|
296
|
-
case 'GridClearHighlight':
|
|
297
|
-
if (!this.ctx.highlightDirective) {
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
this.ctx.highlightDirective['setState']([]);
|
|
301
|
-
break;
|
|
302
|
-
case 'GridSelect': {
|
|
303
|
-
this.processSelectionResponse([cmd.select], messages);
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
case 'GridClearSelect': {
|
|
307
|
-
const selectionInstance = this.getSelectionInstance();
|
|
308
|
-
if (!selectionInstance) {
|
|
309
|
-
this.updateLastMessage(messages, this.ctx.localization?.get('aiAssistantSelectionNotEnabled'));
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
this.applySelectionState(selectionInstance, []);
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
case 'GridColumnResize': {
|
|
316
|
-
const col = findColumnById(cmd.id);
|
|
317
|
-
if (!col) {
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
// parse size (accept numeric or strings like '200px')
|
|
321
|
-
let newWidth;
|
|
322
|
-
if (typeof cmd.size === 'number') {
|
|
323
|
-
newWidth = cmd.size;
|
|
324
|
-
}
|
|
325
|
-
else if (typeof cmd.size === 'string') {
|
|
326
|
-
const numericPart = parseFloat(cmd.size);
|
|
327
|
-
if (!isNaN(numericPart)) {
|
|
328
|
-
newWidth = numericPart;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
if (typeof newWidth === 'number') {
|
|
332
|
-
const oldWidth = col.width;
|
|
333
|
-
// set the column width (ColumnBase.width setter handles string -> number)
|
|
334
|
-
col.width = newWidth;
|
|
335
|
-
// emit columnResize event with ColumnResizeArgs[]
|
|
336
|
-
const args = [{ column: col, oldWidth: oldWidth, newWidth: newWidth }];
|
|
337
|
-
this.ctx.grid.columnResize.emit(args);
|
|
338
|
-
}
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
case 'GridColumnReorder': {
|
|
342
|
-
const col = findColumnById(cmd.id);
|
|
343
|
-
if (!col) {
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
const newPosition = Number(cmd.position);
|
|
347
|
-
if (!isNaN(newPosition) && newPosition >= 0) {
|
|
348
|
-
this.changeColumnPosition(col, newPosition);
|
|
349
|
-
}
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
case 'GridColumnShow':
|
|
353
|
-
case 'GridColumnHide': {
|
|
354
|
-
const col = findColumnById(cmd.id);
|
|
355
|
-
if (!col) {
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
const targetHidden = cmd.type === 'GridColumnHide';
|
|
359
|
-
const changed = updateColumnHierarchy(col, (current) => {
|
|
360
|
-
if (current.hidden === targetHidden) {
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
current.hidden = targetHidden;
|
|
364
|
-
return true;
|
|
365
|
-
});
|
|
366
|
-
if (changed.length) {
|
|
367
|
-
this.columnInfoService.changeVisibility(changed);
|
|
368
|
-
}
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
case 'GridColumnLock':
|
|
372
|
-
case 'GridColumnUnlock': {
|
|
373
|
-
const col = findColumnById(cmd.id);
|
|
374
|
-
if (!col) {
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
const targetLocked = cmd.type === 'GridColumnLock';
|
|
378
|
-
const changed = updateColumnHierarchy(col, (current) => {
|
|
379
|
-
if (current.locked === targetLocked) {
|
|
380
|
-
return false;
|
|
381
|
-
}
|
|
382
|
-
current.locked = targetLocked;
|
|
383
|
-
return true;
|
|
384
|
-
});
|
|
385
|
-
if (changed.length) {
|
|
386
|
-
this.columnInfoService.changeLocked(changed);
|
|
387
|
-
}
|
|
388
|
-
break;
|
|
389
|
-
}
|
|
390
|
-
case 'GridPage': {
|
|
391
|
-
this.processPageCommand(cmd);
|
|
392
|
-
break;
|
|
393
|
-
}
|
|
394
|
-
case 'GridPageSize': {
|
|
395
|
-
this.processPageSizeCommand(cmd);
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
case 'GridExportExcel': {
|
|
399
|
-
this.runExportWithFileName(this.ctx.excelComponent, cmd.fileName, () => this.ctx.grid.saveAsExcel());
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
case 'GridExportPDF': {
|
|
403
|
-
this.runExportWithFileName(this.ctx.pdfComponent, cmd.fileName, () => this.ctx.grid.emitPDFExportEvent());
|
|
404
|
-
break;
|
|
405
|
-
}
|
|
406
|
-
default:
|
|
407
|
-
// Unknown command - ignore
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
runExportWithFileName(component, fileName, action) {
|
|
413
|
-
if (!component || !fileName) {
|
|
414
|
-
action();
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
const previousFileName = component.fileName;
|
|
418
|
-
component.fileName = fileName;
|
|
419
|
-
action();
|
|
420
|
-
const isExcel = component === this.ctx.excelComponent;
|
|
421
|
-
if (isExcel) {
|
|
422
|
-
this.zone.runOutsideAngular(() => {
|
|
423
|
-
this.ctx.excelComponent.fileCreated.subscribe(() => {
|
|
424
|
-
component.fileName = previousFileName;
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
component.fileName = previousFileName;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
processPageCommand(command) {
|
|
433
|
-
const pageSize = this.getCurrentPageSizeValue();
|
|
434
|
-
if (!isPresent(pageSize) || pageSize <= 0) {
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
const total = this.getTotalItemsCount();
|
|
438
|
-
const requestedPage = Number(command.page);
|
|
439
|
-
let targetPage = Number.isFinite(requestedPage) ? Math.floor(requestedPage) : 1;
|
|
440
|
-
if (targetPage < 1) {
|
|
441
|
-
targetPage = 1;
|
|
442
|
-
}
|
|
443
|
-
if (isPresent(total) && pageSize > 0) {
|
|
444
|
-
const maxPage = Math.max(1, Math.ceil(total / pageSize));
|
|
445
|
-
targetPage = Math.min(targetPage, maxPage);
|
|
446
|
-
}
|
|
447
|
-
const skip = (targetPage - 1) * pageSize;
|
|
448
|
-
this.emitGridPageChange(skip, pageSize);
|
|
449
|
-
}
|
|
450
|
-
processPageSizeCommand(command) {
|
|
451
|
-
const rawPageSize = Number(command.pageSize);
|
|
452
|
-
if (!Number.isFinite(rawPageSize)) {
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
const newPageSize = Math.max(1, Math.floor(rawPageSize));
|
|
456
|
-
const skip = Math.max(0, this.ctx.grid?.skip ?? 0);
|
|
457
|
-
this.ensurePageSizeOption(newPageSize);
|
|
458
|
-
this.emitGridPageChange(skip, newPageSize);
|
|
459
|
-
}
|
|
460
|
-
emitGridPageChange(skip, take) {
|
|
461
|
-
const grid = this.ctx.grid;
|
|
462
|
-
const normalizedSkip = Math.max(0, Math.floor(skip));
|
|
463
|
-
const normalizedTake = Math.max(1, Math.floor(take));
|
|
464
|
-
grid.skip = normalizedSkip;
|
|
465
|
-
grid.pageSize = normalizedTake;
|
|
466
|
-
grid.pageChange.emit({ skip: normalizedSkip, take: normalizedTake });
|
|
467
|
-
}
|
|
468
|
-
ensurePageSizeOption(pageSize) {
|
|
469
|
-
const grid = this.ctx.grid;
|
|
470
|
-
if (!grid) {
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
const pageable = grid.pageable;
|
|
474
|
-
if (!pageable || typeof pageable === 'boolean') {
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
const pageSizes = pageable.pageSizes;
|
|
478
|
-
if (!Array.isArray(pageSizes) || pageSizes.length === 0) {
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
if (pageSizes.includes(pageSize)) {
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
const uniqueSizes = [pageSize, ...pageSizes.filter(size => size !== pageSize)];
|
|
485
|
-
grid.pageable = {
|
|
486
|
-
...pageable,
|
|
487
|
-
pageSizes: uniqueSizes
|
|
488
|
-
};
|
|
489
|
-
const changeDetector = grid?.changeDetectorRef;
|
|
490
|
-
if (changeDetector && typeof changeDetector.markForCheck === 'function') {
|
|
491
|
-
changeDetector.markForCheck();
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
getCurrentPageSizeValue() {
|
|
495
|
-
const grid = this.ctx.grid;
|
|
496
|
-
if (!grid) {
|
|
497
|
-
return null;
|
|
498
|
-
}
|
|
499
|
-
const candidates = [grid.pageSize, grid.currentState?.take, this.ctx.dataBindingDirective?.['state']?.take];
|
|
500
|
-
for (const candidate of candidates) {
|
|
501
|
-
if (typeof candidate === 'number' && candidate > 0) {
|
|
502
|
-
return candidate;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
const pageable = grid.pageable;
|
|
506
|
-
if (pageable && typeof pageable === 'object' && Array.isArray(pageable.pageSizes)) {
|
|
507
|
-
const numericSize = pageable.pageSizes.find(size => typeof size === 'number' && size > 0);
|
|
508
|
-
if (numericSize) {
|
|
509
|
-
return numericSize;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
const originalData = this.ctx.dataBindingDirective?.['originalData'];
|
|
513
|
-
if (Array.isArray(originalData) && originalData.length > 0) {
|
|
514
|
-
return originalData.length;
|
|
515
|
-
}
|
|
516
|
-
return null;
|
|
517
|
-
}
|
|
518
|
-
getTotalItemsCount() {
|
|
519
|
-
const grid = this.ctx.grid;
|
|
520
|
-
if (!grid) {
|
|
521
|
-
return null;
|
|
522
|
-
}
|
|
523
|
-
const gridData = grid.data;
|
|
524
|
-
if (gridData && typeof gridData.total === 'number') {
|
|
525
|
-
return gridData.total;
|
|
526
|
-
}
|
|
527
|
-
const view = grid.view;
|
|
528
|
-
if (view && typeof view.total === 'number') {
|
|
529
|
-
return view.total;
|
|
530
|
-
}
|
|
531
|
-
const originalData = this.ctx.dataBindingDirective?.['originalData'];
|
|
532
|
-
if (Array.isArray(originalData)) {
|
|
533
|
-
return originalData.length;
|
|
534
|
-
}
|
|
535
|
-
return null;
|
|
536
|
-
}
|
|
537
|
-
getSelectionInstance() {
|
|
538
|
-
const selectionDirective = this.ctx.grid?.selectionDirective;
|
|
539
|
-
if (selectionDirective && typeof selectionDirective === 'object') {
|
|
540
|
-
return selectionDirective;
|
|
541
|
-
}
|
|
542
|
-
const defaultSelection = this.ctx.grid?.defaultSelection;
|
|
543
|
-
if (defaultSelection && typeof defaultSelection === 'object') {
|
|
544
|
-
return defaultSelection;
|
|
545
|
-
}
|
|
546
|
-
return null;
|
|
547
|
-
}
|
|
548
|
-
updateLastMessage(messages, newMessage) {
|
|
549
|
-
if (!messages.length) {
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
messages[messages.length - 1] = newMessage;
|
|
553
|
-
}
|
|
554
|
-
getHighlightItems(descriptors) {
|
|
555
|
-
if (!descriptors?.length) {
|
|
556
|
-
return [];
|
|
557
|
-
}
|
|
558
|
-
const data = this.ctx.dataBindingDirective?.['originalData'] || [];
|
|
559
|
-
return highlightBy(data, descriptors, this.columns);
|
|
560
|
-
}
|
|
561
|
-
processSelectionResponse(selection, messages) {
|
|
562
|
-
const selectionInstance = this.getSelectionInstance();
|
|
563
|
-
if (!selectionInstance) {
|
|
564
|
-
this.updateLastMessage(messages, this.ctx.localization?.get('aiAssistantSelectionNotEnabled'));
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
const descriptors = (selection || []).filter((descriptor) => Boolean(descriptor));
|
|
568
|
-
if (descriptors.length === 0) {
|
|
569
|
-
this.applySelectionState(selectionInstance, []);
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
const highlightItems = this.getHighlightItems(descriptors);
|
|
573
|
-
if (!highlightItems.length) {
|
|
574
|
-
this.applySelectionState(selectionInstance, []);
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
const hasCellSelections = highlightItems.some(item => isPresent(item.columnKey));
|
|
578
|
-
const hasRowSelections = highlightItems.some(item => !isPresent(item.columnKey));
|
|
579
|
-
const isCellMode = selectionInstance.isCellSelectionMode;
|
|
580
|
-
if ((!isCellMode && hasCellSelections) || (isCellMode && hasRowSelections)) {
|
|
581
|
-
const key = isCellMode ? 'aiAssistantSelectionRowModeRequired' : 'aiAssistantSelectionCellModeRequired';
|
|
582
|
-
this.updateLastMessage(messages, this.ctx.localization?.get(key));
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
const selectionState = this.mapHighlightItemsToSelection(selectionInstance, highlightItems, isCellMode);
|
|
586
|
-
this.applySelectionState(selectionInstance, selectionState);
|
|
587
|
-
}
|
|
588
|
-
mapHighlightItemsToSelection(selectionInstance, highlightItems, isCellMode) {
|
|
589
|
-
const data = this.ctx.dataBindingDirective?.['originalData'] || [];
|
|
590
|
-
if (isCellMode) {
|
|
591
|
-
const mapped = highlightItems
|
|
592
|
-
.filter(item => isPresent(item.itemKey) && isPresent(item.columnKey))
|
|
593
|
-
.map(item => {
|
|
594
|
-
const rowIndex = item.itemKey;
|
|
595
|
-
const columnIndex = item.columnKey;
|
|
596
|
-
const dataItem = data[rowIndex];
|
|
597
|
-
if (!isPresent(dataItem)) {
|
|
598
|
-
return null;
|
|
599
|
-
}
|
|
600
|
-
if (typeof selectionInstance['getSelectionItem'] === 'function') {
|
|
601
|
-
const columnComponent = this.leafColumns[columnIndex];
|
|
602
|
-
const selectionItem = selectionInstance['getSelectionItem']({ dataItem, index: rowIndex }, columnComponent, columnIndex);
|
|
603
|
-
if (selectionItem && isPresent(selectionItem.itemKey) && isPresent(selectionItem.columnKey)) {
|
|
604
|
-
return selectionItem;
|
|
605
|
-
}
|
|
606
|
-
return null;
|
|
607
|
-
}
|
|
608
|
-
const itemKey = typeof selectionInstance.getItemKey === 'function'
|
|
609
|
-
? selectionInstance.getItemKey({ dataItem, index: rowIndex })
|
|
610
|
-
: rowIndex;
|
|
611
|
-
return isPresent(itemKey) ? { itemKey, columnKey: columnIndex } : null;
|
|
612
|
-
})
|
|
613
|
-
.filter((item) => isPresent(item));
|
|
614
|
-
return mapped.filter((item, index, self) => self.findIndex(other => other.itemKey === item.itemKey && other.columnKey === item.columnKey) === index);
|
|
615
|
-
}
|
|
616
|
-
const rowKeys = highlightItems
|
|
617
|
-
.filter(item => isPresent(item.itemKey))
|
|
618
|
-
.map(item => {
|
|
619
|
-
const rowIndex = item.itemKey;
|
|
620
|
-
const dataItem = data[rowIndex];
|
|
621
|
-
if (!isPresent(dataItem)) {
|
|
622
|
-
return null;
|
|
623
|
-
}
|
|
624
|
-
if (typeof selectionInstance.getItemKey === 'function') {
|
|
625
|
-
return selectionInstance.getItemKey({ dataItem, index: rowIndex });
|
|
626
|
-
}
|
|
627
|
-
return rowIndex;
|
|
628
|
-
})
|
|
629
|
-
.filter(isPresent);
|
|
630
|
-
return Array.from(new Set(rowKeys));
|
|
631
|
-
}
|
|
632
|
-
applySelectionState(selectionInstance, selectionState) {
|
|
633
|
-
selectionInstance.selectedKeys = selectionState;
|
|
634
|
-
if (typeof selectionInstance['setState'] === 'function') {
|
|
635
|
-
selectionInstance['setState'](selectionState);
|
|
636
|
-
}
|
|
637
|
-
const changeDetector = selectionInstance['cd'];
|
|
638
|
-
if (changeDetector && typeof changeDetector.markForCheck === 'function') {
|
|
639
|
-
changeDetector.markForCheck();
|
|
640
|
-
}
|
|
641
|
-
if (typeof selectionInstance['notifyChange'] === 'function') {
|
|
642
|
-
selectionInstance['notifyChange']();
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
replaceQuotedColumnId(message, replacement) {
|
|
646
|
-
if (!replacement) {
|
|
647
|
-
const columnIdPattern = /(?:"|")(k-grid\d+-col\d+)(?:"|")\s*/g;
|
|
648
|
-
return message.replace(columnIdPattern, '').replace(/\s{2,}/g, ' ').trim();
|
|
649
|
-
}
|
|
650
|
-
const columnIdPattern = /(?:"|")(k-grid\d+-col\d+)(?:"|")/g;
|
|
651
|
-
return message.replace(columnIdPattern, (match) => {
|
|
652
|
-
const isEncoded = match.startsWith('"');
|
|
653
|
-
return isEncoded ? `"${replacement}"` : `"${replacement}"`;
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
isColumnCommand(type) {
|
|
657
|
-
return type === 'GridColumnResize' ||
|
|
658
|
-
type === 'GridColumnReorder' ||
|
|
659
|
-
type === 'GridColumnShow' ||
|
|
660
|
-
type === 'GridColumnHide' ||
|
|
661
|
-
type === 'GridColumnLock' ||
|
|
662
|
-
type === 'GridColumnUnlock';
|
|
663
|
-
}
|
|
664
|
-
getColumnReplacement(column) {
|
|
665
|
-
if (!column) {
|
|
666
|
-
return '';
|
|
667
|
-
}
|
|
668
|
-
if (column.title && String(column.title).trim()) {
|
|
669
|
-
return String(column.title).trim();
|
|
670
|
-
}
|
|
671
|
-
if (column.field && String(column.field).trim()) {
|
|
672
|
-
return String(column.field).trim();
|
|
673
|
-
}
|
|
674
|
-
return '';
|
|
675
|
-
}
|
|
676
|
-
processHighlightResponse(highlight) {
|
|
677
|
-
const highlightedItems = this.getHighlightItems(highlight);
|
|
678
|
-
this.ctx.highlightDirective['setState'](highlightedItems);
|
|
679
|
-
}
|
|
680
|
-
processFilterResponse(filter) {
|
|
681
|
-
const processedFilter = convertDateStringsInFilter(filter);
|
|
682
|
-
const clearFilter = Object.keys(processedFilter).length === 0;
|
|
683
|
-
if (clearFilter) {
|
|
684
|
-
this.ctx.grid.filterChange.next(undefined);
|
|
685
|
-
}
|
|
686
|
-
else if (processedFilter?.filters.length) {
|
|
687
|
-
const currentFilter = this.ctx.grid.currentState.filter;
|
|
688
|
-
let mergedFilter = processedFilter;
|
|
689
|
-
if (currentFilter && currentFilter.filters?.length > 0) {
|
|
690
|
-
mergedFilter = {
|
|
691
|
-
logic: 'and',
|
|
692
|
-
filters: [
|
|
693
|
-
currentFilter,
|
|
694
|
-
processedFilter
|
|
695
|
-
]
|
|
696
|
-
};
|
|
697
|
-
}
|
|
698
|
-
this.ctx.grid.filterChange.next(mergedFilter);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
changeColumnPosition(column, newPosition) {
|
|
702
|
-
const grid = this.ctx.grid;
|
|
703
|
-
if (!grid?.columns) {
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
const currentColumns = grid.columns.toArray();
|
|
707
|
-
const currentIndex = currentColumns.findIndex(col => col === column);
|
|
708
|
-
if (currentIndex === -1) {
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
if (newPosition < 0 || newPosition >= currentColumns.length) {
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
const sortedColumns = currentColumns
|
|
715
|
-
.map((col, idx) => ({ col, physicalIndex: idx, visualOrder: col.orderIndex ?? idx }))
|
|
716
|
-
.sort((a, b) => a.visualOrder - b.visualOrder);
|
|
717
|
-
const currentVisualPos = sortedColumns.findIndex(item => item.physicalIndex === currentIndex);
|
|
718
|
-
if (currentVisualPos === newPosition) {
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
currentColumns.forEach((col, idx) => {
|
|
722
|
-
const sortedIndex = sortedColumns.findIndex(item => item.physicalIndex === idx);
|
|
723
|
-
if (idx === currentIndex) {
|
|
724
|
-
col.orderIndex = newPosition;
|
|
725
|
-
}
|
|
726
|
-
else if (currentVisualPos < newPosition) {
|
|
727
|
-
col.orderIndex = (sortedIndex > currentVisualPos && sortedIndex <= newPosition)
|
|
728
|
-
? sortedIndex - 1 : sortedIndex;
|
|
729
|
-
}
|
|
730
|
-
else {
|
|
731
|
-
col.orderIndex = (sortedIndex >= newPosition && sortedIndex < currentVisualPos)
|
|
732
|
-
? sortedIndex + 1 : sortedIndex;
|
|
733
|
-
}
|
|
734
|
-
col.isReordered = true;
|
|
735
|
-
});
|
|
736
|
-
grid.columnReorder.emit({
|
|
737
|
-
column: column,
|
|
738
|
-
oldIndex: currentVisualPos,
|
|
739
|
-
newIndex: newPosition
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: AiAssistantComponent, deps: [{ token: i1.HttpClient }, { token: i2.ContextService }, { token: i3.ColumnInfoService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
|
|
165
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: AiAssistantComponent, deps: [{ token: i1.HttpClient }, { token: i2.ContextService }, { token: i3.ColumnInfoService }, { token: i0.NgZone }, { token: i4.GridAIRequestResponseService }], target: i0.ɵɵFactoryTarget.Component });
|
|
743
166
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: AiAssistantComponent, isStandalone: true, selector: "ng-component", viewQueries: [{ propertyName: "aiPrompt", first: true, predicate: AIPromptComponent, descendants: true }], ngImport: i0, template: `
|
|
744
167
|
<kendo-aiprompt
|
|
745
168
|
#aiPrompt
|
|
@@ -843,7 +266,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
|
|
|
843
266
|
</kendo-aiprompt>
|
|
844
267
|
`
|
|
845
268
|
}]
|
|
846
|
-
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.ContextService }, { type: i3.ColumnInfoService }, { type: i0.NgZone }], propDecorators: { aiPrompt: [{
|
|
269
|
+
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.ContextService }, { type: i3.ColumnInfoService }, { type: i0.NgZone }, { type: i4.GridAIRequestResponseService }], propDecorators: { aiPrompt: [{
|
|
847
270
|
type: ViewChild,
|
|
848
271
|
args: [AIPromptComponent]
|
|
849
272
|
}] } });
|