cancel
Showing results for 
Search instead for 
Did you mean: 

DocumentListComponent action handler customization not working

jameswu1818
Champ in-the-making
Champ in-the-making

Someone please help us. In DocumentListComponent, we want to run our customized code for download action. so that we can run our code before calling the default ‘download’ handler; or not calling the default handler at all.

 

According to documents

https://alfresco.github.io/adf-component-catalog/components/ContentActionComponent.html

https://alfresco.github.io/adf-component-catalog/injectables/DocumentActionsService.html

 

, it is possible to register a new customized action to replace default ‘download’ action handler. But it does not work for us. Following is excerpt of our code, that is very similar to samples provided. Neither myDocumentActionHandler() nor customDownloadBehavior() is called when the actions are selected from the three dot action menu.

 

============= html ===========

<adf-document-list
 
#documentList

  [multiselect]=
true
 
[allowDropFiles]="false"
 
[navigationMode]="'dblclick'"
 
[contextMenuActions]="true"
 
[contentActions]="true"
 
[selectionMode]="'multiple'"
 
currentFolderId={{parentFolder.folderId}}
 
(preview)="showPreview($event)"
 
[sorting]="['name', 'ASC']">

  <
content-actions>

   
<content-action
     
target="document"
     
title="APP.ACTIONS.DOWNLOAD"
     
handler="download" >
    </
content-action>

    <
content-action
     
target="document"
     
title="My Handler"
     
handler="my-handler" >
    </
content-action>     <!- - other actions - - >
  </content-actions>     <!- - other column defs - -></adf-document-list>

 

============= controller ===========

// other imports …
import { DocumentListComponent, DocumentActionsService } from '@alfresco/adf-content-services';


@Component({
selector: 'app-doc-list',
 
templateUrl: './doc-list.component.html',
 
styleUrls: ['./doc-list.component.scss']
})
export class DocListComponent extends BrowseResult {


 
// other properteis …

 
originalDownloadHandler;

 
constructor(documentActions: DocumentActionsService,
              //

) {
   
super(peopleApi, rfsDocumentService);

    documentActions.
setHandler(
     
'my-handler',
     
this.myDocumentActionHandler.bind(this)
    );

   
this.originalDownloadHandler = documentActions.getHandler('download');
    documentActions.
setHandler(
     
'download',
     
this.customDownloadBehavior.bind(this)
    );

  }

 
myDocumentActionHandler(obj: any) {
   
console.log('my custom action handler is never called');
  }

 
customDownloadBehavior(obj: any) {
   
console.log('my custom download behavior is never called');
   
this.originalDownloadHandler(obj);
  }

 

  // other functions …
}

4 REPLIES 4

dvuika
Star Collaborator
Star Collaborator

You can take full control over the action execution using "(execute)" event. In that case you won't need hacking services:

<content-action
  target="all"
  title="Custom actions"
  (execute)="runCustomAction($event)">

</content-action>

And in the controller class:

runCustomAction(event) {
  console.log(event);
}

jameswu1818
Champ in-the-making
Champ in-the-making

Thank you for your answer. But why handler does not work though. Since it is documented, there must be a reason to use it. In our case, we want to reuse the default download code.

  customDownloadBehavior(obj: any) {
    if (do_something_in_our_biz_logic(obj)) {

        
this.originalDownloadHandler(obj);

    }
  }

Maybe related to "this" context and how you invoke the old one. Anyway, you can check the source code: alfresco-ng2-components/document-actions.service.ts at development · Alfresco/alfresco-ng2-component... The only thing the "download" handler does is calling this line of code:

this.nodeActionsService.downloadNode(obj);

You can make that call from your handlers as well, or step thought the code in the debugger to see what's going on.

Same issue here, I followed the documentation and my custom handler "delete" is not calling my custom behaviour. 

I then used the "execute" event, but I needed to rewrite the DocumentActionsService#delete method myself.