UNPKG

@adaptabletools/adaptable

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

63 lines (62 loc) 2.54 kB
import * as ModuleConstants from '../Utilities/Constants/ModuleConstants'; import { AdaptableModuleBase } from './AdaptableModuleBase'; export class NoteModule extends AdaptableModuleBase { constructor(api) { super(ModuleConstants.NoteModuleId, ModuleConstants.NoteFriendlyName, 'note', 'NotePopup', 'Notes', api); } isModuleAvailable() { // Note module doesn't support autogenerated primary keys return super.isModuleAvailable() && !this.api.optionsApi.isAutogeneratePrimaryKey(); } getModuleAdaptableObjects() { return this.api.noteApi.getAllNotes(); } createContextMenuItems(menuContext) { if (!this.isModuleAvailable()) { return; } if (!this.api.noteApi.internalApi.areNotesSupported()) { return; } if (menuContext.isRowGroupColumn || menuContext.isGroupedNode) { return; } const isReadOnly = this.api.entitlementApi.getEntitlementAccessLevelForModule(this.moduleInfo.ModuleName) === 'ReadOnly'; if (isReadOnly) { return undefined; } const isCellNotable = typeof this.api.optionsApi?.getNoteOptions()?.isCellNotable === 'function' ? this.api.optionsApi.getNoteOptions().isCellNotable({ gridCell: menuContext.gridCell, ...this.api.internalApi.buildBaseContext(), }) : true; if (!isCellNotable) { return; } const note = this.api.noteApi.getNoteForCell({ PrimaryKeyValue: menuContext.primaryKeyValue, ColumnId: menuContext.adaptableColumn.columnId, }); if (note) { return [ this.createMenuItemClickFunction('note-remove', 'Remove Note', this.moduleInfo.Glyph, () => { this.api.noteApi.deleteNote(note); }), ]; } else { return [ this.createMenuItemClickFunction('note-add', 'Add Note', this.moduleInfo.Glyph, () => { // add an empty one this.api.noteApi.addNote('', menuContext.primaryKeyValue, menuContext.adaptableColumn.columnId); this.api.internalApi.getAnnotationsService().showPopup({ PrimaryKeyValue: menuContext.primaryKeyValue, ColumnId: menuContext.adaptableColumn.columnId, }, true); }), ]; } } }