Custom Action via Object Actions Menu

Custom Action via Object Actions Menu

 

Example: O365 File Edit

Description

In this example, we create an action with which we will be able to edit o365 files (e. g. word) in a new tab in a o365 editor.

Implementation

  1. Use a CLI command to generate a plug-in component with the name o365-edit.

    eo g action o365-edit

     

  2. Update o365-edit.component.ts to extend DmsObjectTarget and implement SimpleAction interface.

    o365-edit.component.ts

    import { Component } from '@angular/core'; import { DmsObjectTarget, PluginsService, SelectionRange, SimpleAction } from '@eo-sdk/client'; import { TranslateService } from '@eo-sdk/core'; import { Observable, of } from 'rxjs'; @Component({ selector: 'app-o365-edit', template: ``, styles: `` }) export class O365EditComponent extends DmsObjectTarget implements SimpleAction { label: string; description: string; iconSrc = 'assets/_default/svg/ic_edit.svg'; priority = 15; group = 'common'; range = SelectionRange.SINGLE_SELECT; constructor(private translate: TranslateService, private pluginsService: PluginsService) { super(); this.label = this.translate.instant('o365-edit.action.label'); this.description = this.translate.instant('o365-edit.action.description'); } isExecutable(item: any | any[]): Observable<boolean | boolean[]> { return of(item.rights.edit && item.content?.contents[0].mimetype.match(/word|presentation|excel|powerpoint|spreadsheet/)); } run(selection: any[]): void { const item = selection[0]; const user = this.pluginsService.api.session.getUser(); const win = window.open(location.origin + '/dashlet365/?id=' + item.id + '&version=' + item.version + '&type=' + item.typeName + '&locale=' + user.userSettings.clientlocale + '&action=editnew&mimeTypeGroup=WORD&conversion=none'); win.addEventListener('beforeunload', () => window.postMessage(JSON.stringify({ MessageId: 'Host_PostmessageObjectUpdating', Values: { osid: item.id } }))); } }

     

  3. Use a CLI command to generate labels/translations.

    eo g label eo.custom.action.o365-edit.action.label --en "Edit o365 file" --de "O365-Datei bearbeiten"

     

    eo g label eo.custom.action.o365-edit.action.description --en "Edit the o365 file for this object" --de "Bearbeite die O365-Datei für dieses Objekt"