UNPKG

@progress/kendo-angular-grid

Version:

Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.

86 lines (85 loc) 4.12 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { ChangeDetectorRef, Directive, Inject, NgZone } from '@angular/core'; import { ToolBarButtonComponent } from '@progress/kendo-angular-toolbar'; import { Subscription } from 'rxjs'; import { cancelIcon, columnsIcon, fileExcelIcon, filePdfIcon, pencilIcon, plusIcon, saveIcon, sparklesIcon, trashIcon } from '@progress/kendo-svg-icons'; import { isPresent } from '@progress/kendo-angular-common'; import { ContextService } from './provider.service'; import { ToolbarToolName } from '../navigation/toolbar-tool-name'; import * as i0 from "@angular/core"; import * as i1 from "@progress/kendo-angular-toolbar"; import * as i2 from "./provider.service"; const ICONS_MAP = { edit: { svgIcon: pencilIcon, icon: 'pencil' }, save: { svgIcon: saveIcon, icon: 'save' }, cancel: { svgIcon: cancelIcon, icon: 'cancel' }, remove: { svgIcon: trashIcon, icon: 'trash' }, add: { svgIcon: plusIcon, icon: 'plus' }, excelExport: { svgIcon: fileExcelIcon, icon: 'file-excel' }, pdfExport: { svgIcon: filePdfIcon, icon: 'file-pdf' }, columns: { svgIcon: columnsIcon, icon: 'columns' }, aiAssistant: { svgIcon: sparklesIcon, icon: 'sparkles' } }; /** * @hidden */ export class ToolbarToolBase { host; commandName; ctx; zone; cdr; clickSub = new Subscription(); constructor(host, commandName, ctx, zone, cdr) { this.host = host; this.commandName = commandName; this.ctx = ctx; this.zone = zone; this.cdr = cdr; } ngOnInit() { this.clickSub = this.host.click.subscribe(e => this.onClick(e)); const hasIcon = (isPresent(this.host.toolbarOptions.icon) && this.host.toolbarOptions.icon !== '') && (isPresent(this.host.overflowOptions.icon) && this.host.overflowOptions.icon !== ''); const hasSvgIcon = isPresent(this.host.toolbarOptions.svgIcon) && isPresent(this.host.overflowOptions.svgIcon); if (!hasIcon) { this.host.icon = ICONS_MAP[this.commandName].icon; } if (!hasSvgIcon) { this.host.svgIcon = ICONS_MAP[this.commandName].svgIcon; } } ngAfterViewInit() { const hasText = isPresent(this.host.text); if (!hasText) { this.zone.runOutsideAngular(() => { setTimeout(() => { const messageKey = this.commandName === ToolbarToolName.columns ? 'columns' : `${this.commandName}ToolbarToolText`; this.host.text = this.ctx.localization.get(messageKey); this.zone.run(() => { this.cdr.markForCheck(); }); }); }); } } ngOnDestroy() { this.clickSub.unsubscribe(); } onClick(_e) { } get buttonElement() { return this.host.getButton(); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToolbarToolBase, deps: [{ token: i1.ToolBarButtonComponent }, { token: 'command' }, { token: i2.ContextService }, { token: i0.NgZone }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: ToolbarToolBase, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToolbarToolBase, decorators: [{ type: Directive, args: [{}] }], ctorParameters: () => [{ type: i1.ToolBarButtonComponent }, { type: undefined, decorators: [{ type: Inject, args: ['command'] }] }, { type: i2.ContextService }, { type: i0.NgZone }, { type: i0.ChangeDetectorRef }] });