mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACA-1530] allow calling download action from extensions (#500)
* download action * use download action everywhere
This commit is contained in:
@@ -64,6 +64,11 @@
|
|||||||
"type": "EDIT_FOLDER",
|
"type": "EDIT_FOLDER",
|
||||||
"payload": null
|
"payload": null
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "aca:actions/download",
|
||||||
|
"type": "DOWNLOAD_NODES",
|
||||||
|
"payload": null
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"id": "aca:actions/info",
|
"id": "aca:actions/info",
|
||||||
@@ -202,8 +207,20 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"disabled": false,
|
"disabled": false,
|
||||||
"id": "aca:toolbar/edit-folder",
|
"id": "aca:toolbar/download",
|
||||||
"order": 20,
|
"order": 20,
|
||||||
|
"title": "APP.ACTIONS.DOWNLOAD",
|
||||||
|
"icon": "get_app",
|
||||||
|
"target": {
|
||||||
|
"types": ["folder", "file"],
|
||||||
|
"permissions": [],
|
||||||
|
"action": "aca:actions/download"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"disabled": false,
|
||||||
|
"id": "aca:toolbar/edit-folder",
|
||||||
|
"order": 30,
|
||||||
"title": "APP.ACTIONS.EDIT",
|
"title": "APP.ACTIONS.EDIT",
|
||||||
"icon": "create",
|
"icon": "create",
|
||||||
"target": {
|
"target": {
|
||||||
@@ -213,6 +230,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"disabled": false,
|
"disabled": false,
|
||||||
"id": "aca:action3",
|
"id": "aca:action3",
|
||||||
|
@@ -71,7 +71,6 @@ import { ExperimentalGuard } from './common/services/experimental-guard.service'
|
|||||||
|
|
||||||
import { InfoDrawerComponent } from './components/info-drawer/info-drawer.component';
|
import { InfoDrawerComponent } from './components/info-drawer/info-drawer.component';
|
||||||
import { EditFolderDirective } from './directives/edit-folder.directive';
|
import { EditFolderDirective } from './directives/edit-folder.directive';
|
||||||
import { DownloadNodesDirective } from './directives/download-nodes.directive';
|
|
||||||
import { AppStoreModule } from './store/app-store.module';
|
import { AppStoreModule } from './store/app-store.module';
|
||||||
import { PaginationDirective } from './directives/pagination.directive';
|
import { PaginationDirective } from './directives/pagination.directive';
|
||||||
import { DocumentListDirective } from './directives/document-list.directive';
|
import { DocumentListDirective } from './directives/document-list.directive';
|
||||||
@@ -134,7 +133,6 @@ import { SearchResultsRowComponent } from './components/search/search-results-ro
|
|||||||
InfoDrawerComponent,
|
InfoDrawerComponent,
|
||||||
SharedLinkViewComponent,
|
SharedLinkViewComponent,
|
||||||
EditFolderDirective,
|
EditFolderDirective,
|
||||||
DownloadNodesDirective,
|
|
||||||
PaginationDirective,
|
PaginationDirective,
|
||||||
DocumentListDirective,
|
DocumentListDirective,
|
||||||
ExperimentalDirective
|
ExperimentalDirective
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
mat-icon-button
|
mat-icon-button
|
||||||
color="primary"
|
color="primary"
|
||||||
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
|
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
|
||||||
[adfNodeDownload]="selection.nodes">
|
(click)="downloadSelection()">
|
||||||
<mat-icon>get_app</mat-icon>
|
<mat-icon>get_app</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@@ -41,7 +41,7 @@
|
|||||||
color="primary"
|
color="primary"
|
||||||
mat-icon-button
|
mat-icon-button
|
||||||
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
|
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
|
||||||
[adfNodeDownload]="selection.nodes">
|
(click)="downloadSelection()">
|
||||||
<mat-icon>get_app</mat-icon>
|
<mat-icon>get_app</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@@ -30,7 +30,7 @@ import { Store } from '@ngrx/store';
|
|||||||
import { MinimalNodeEntity, MinimalNodeEntryEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntity, MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||||
import { takeUntil } from 'rxjs/operators';
|
import { takeUntil } from 'rxjs/operators';
|
||||||
import { Subject, Subscription } from 'rxjs/Rx';
|
import { Subject, Subscription } from 'rxjs/Rx';
|
||||||
import { ViewNodeAction, SetSelectedNodesAction } from '../store/actions';
|
import { ViewNodeAction, SetSelectedNodesAction, DownloadNodesAction } from '../store/actions';
|
||||||
import { appSelection, sharedUrl, currentFolder } from '../store/selectors/app.selectors';
|
import { appSelection, sharedUrl, currentFolder } from '../store/selectors/app.selectors';
|
||||||
import { AppStore } from '../store/states/app.state';
|
import { AppStore } from '../store/states/app.state';
|
||||||
import { SelectionState } from '../store/states/selection.state';
|
import { SelectionState } from '../store/states/selection.state';
|
||||||
@@ -154,6 +154,10 @@ export abstract class PageComponent implements OnInit, OnDestroy {
|
|||||||
this.documentList.display = this.displayMode;
|
this.documentList.display = this.displayMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
downloadSelection() {
|
||||||
|
this.store.dispatch(new DownloadNodesAction());
|
||||||
|
}
|
||||||
|
|
||||||
// this is where each application decides how to treat an action and what to do
|
// this is where each application decides how to treat an action and what to do
|
||||||
// the ACA maps actions to the NgRx actions as an example
|
// the ACA maps actions to the NgRx actions as an example
|
||||||
runAction(actionId: string) {
|
runAction(actionId: string) {
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
mat-icon-button
|
mat-icon-button
|
||||||
color="primary"
|
color="primary"
|
||||||
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
|
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
|
||||||
[adfNodeDownload]="selection.nodes">
|
(click)="downloadSelection()">
|
||||||
<mat-icon>get_app</mat-icon>
|
<mat-icon>get_app</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
color="primary"
|
color="primary"
|
||||||
mat-icon-button
|
mat-icon-button
|
||||||
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
|
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
|
||||||
[acaDownloadNodes]="selection.nodes">
|
(click)="downloadSelection()">
|
||||||
<mat-icon>get_app</mat-icon>
|
<mat-icon>get_app</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
color="primary"
|
color="primary"
|
||||||
mat-icon-button
|
mat-icon-button
|
||||||
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
|
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
|
||||||
[adfNodeDownload]="selection.nodes">
|
(click)="downloadSelection()">
|
||||||
<mat-icon>get_app</mat-icon>
|
<mat-icon>get_app</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@@ -1,58 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @license
|
|
||||||
* Alfresco Example Content Application
|
|
||||||
*
|
|
||||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
|
||||||
*
|
|
||||||
* This file is part of the Alfresco Example Content Application.
|
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
|
||||||
* provided under the following open source license terms:
|
|
||||||
*
|
|
||||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Directive, HostListener, Input } from '@angular/core';
|
|
||||||
import { Store } from '@ngrx/store';
|
|
||||||
import { AppStore } from '../store/states/app.state';
|
|
||||||
import { MinimalNodeEntity } from 'alfresco-js-api';
|
|
||||||
import { DownloadNodesAction } from '../store/actions';
|
|
||||||
|
|
||||||
@Directive({
|
|
||||||
selector: '[acaDownloadNodes]'
|
|
||||||
})
|
|
||||||
export class DownloadNodesDirective {
|
|
||||||
// tslint:disable-next-line:no-input-rename
|
|
||||||
@Input('acaDownloadNodes')
|
|
||||||
nodes: Array<MinimalNodeEntity> | MinimalNodeEntity;
|
|
||||||
|
|
||||||
constructor(private store: Store<AppStore>) {}
|
|
||||||
|
|
||||||
@HostListener('click')
|
|
||||||
onClick() {
|
|
||||||
const targets = Array.isArray(this.nodes) ? this.nodes : [this.nodes];
|
|
||||||
const toDownload = targets.map(node => {
|
|
||||||
const { id, nodeId, name, isFile, isFolder } = node.entry;
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: nodeId || id,
|
|
||||||
name,
|
|
||||||
isFile,
|
|
||||||
isFolder
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
this.store.dispatch(new DownloadNodesAction(toDownload));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -63,7 +63,7 @@ export class PurgeDeletedNodesAction implements Action {
|
|||||||
|
|
||||||
export class DownloadNodesAction implements Action {
|
export class DownloadNodesAction implements Action {
|
||||||
readonly type = DOWNLOAD_NODES;
|
readonly type = DOWNLOAD_NODES;
|
||||||
constructor(public payload: NodeInfo[] = []) {}
|
constructor(public payload: MinimalNodeEntity[] = []) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateFolderAction implements Action {
|
export class CreateFolderAction implements Action {
|
||||||
|
@@ -31,10 +31,15 @@ import { map } from 'rxjs/operators';
|
|||||||
import { DownloadNodesAction, DOWNLOAD_NODES } from '../actions';
|
import { DownloadNodesAction, DOWNLOAD_NODES } from '../actions';
|
||||||
import { NodeInfo } from '../models';
|
import { NodeInfo } from '../models';
|
||||||
import { ContentApiService } from '../../services/content-api.service';
|
import { ContentApiService } from '../../services/content-api.service';
|
||||||
|
import { MinimalNodeEntity } from 'alfresco-js-api';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { AppStore } from '../states';
|
||||||
|
import { appSelection } from '../selectors/app.selectors';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DownloadEffects {
|
export class DownloadEffects {
|
||||||
constructor(
|
constructor(
|
||||||
|
private store: Store<AppStore>,
|
||||||
private actions$: Actions,
|
private actions$: Actions,
|
||||||
private contentApi: ContentApiService,
|
private contentApi: ContentApiService,
|
||||||
private dialog: MatDialog
|
private dialog: MatDialog
|
||||||
@@ -42,15 +47,35 @@ export class DownloadEffects {
|
|||||||
|
|
||||||
@Effect({ dispatch: false })
|
@Effect({ dispatch: false })
|
||||||
downloadNode$ = this.actions$.pipe(
|
downloadNode$ = this.actions$.pipe(
|
||||||
ofType<DownloadNodesAction>(DOWNLOAD_NODES),
|
ofType<DownloadNodesAction>(DOWNLOAD_NODES),
|
||||||
map(action => {
|
map(action => {
|
||||||
if (action.payload && action.payload.length > 0) {
|
if (action.payload && action.payload.length > 0) {
|
||||||
this.downloadNodes(action.payload);
|
this.downloadNodes(action.payload);
|
||||||
}
|
} else {
|
||||||
})
|
this.store
|
||||||
|
.select(appSelection)
|
||||||
|
.take(1)
|
||||||
|
.subscribe(selection => {
|
||||||
|
if (selection && !selection.isEmpty) {
|
||||||
|
this.downloadNodes(selection.nodes);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
private downloadNodes(nodes: Array<NodeInfo>) {
|
private downloadNodes(toDownload: Array<MinimalNodeEntity>) {
|
||||||
|
const nodes = toDownload.map(node => {
|
||||||
|
const { id, nodeId, name, isFile, isFolder } = node.entry;
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: nodeId || id,
|
||||||
|
name,
|
||||||
|
isFile,
|
||||||
|
isFolder
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
if (!nodes || nodes.length === 0) {
|
if (!nodes || nodes.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user