mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
cancellable events for DataTable and DocumentList (#1682)
* cancellable events for DataTable and DocumentList * more typed events and code fixes * code fixes
This commit is contained in:
committed by
Eugenio Romano
parent
3e342863fd
commit
4ca18bc8f9
@@ -464,7 +464,7 @@ describe('DocumentList', () => {
|
||||
it('should emit [nodeClick] event on row click', () => {
|
||||
let node = new NodeMinimalEntry();
|
||||
let row = new ShareDataRow(node);
|
||||
let event = <DataRowEvent> {value: row};
|
||||
let event = new DataRowEvent(row, null);
|
||||
|
||||
spyOn(documentList, 'onNodeClick').and.callThrough();
|
||||
documentList.onRowClick(event);
|
||||
@@ -474,7 +474,7 @@ describe('DocumentList', () => {
|
||||
it('should emit [nodeDblClick] event on row double-click', () => {
|
||||
let node = new NodeMinimalEntry();
|
||||
let row = new ShareDataRow(node);
|
||||
let event = <DataRowEvent> {value: row};
|
||||
let event = new DataRowEvent(row, null);
|
||||
|
||||
spyOn(documentList, 'onNodeDblClick').and.callThrough();
|
||||
documentList.onRowDblClick(event);
|
||||
|
@@ -32,10 +32,11 @@ import {
|
||||
import { Subject } from 'rxjs/Rx';
|
||||
import { MinimalNodeEntity, MinimalNodeEntryEntity, NodePaging, Pagination } from 'alfresco-js-api';
|
||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
import { DataRowEvent, DataTableComponent, ObjectDataColumn } from 'ng2-alfresco-datatable';
|
||||
import { DataRowEvent, DataTableComponent, ObjectDataColumn, DataCellEvent, DataRowActionEvent } from 'ng2-alfresco-datatable';
|
||||
import { DocumentListService } from './../services/document-list.service';
|
||||
import { ContentActionModel } from './../models/content-action.model';
|
||||
import { ShareDataTableAdapter, ShareDataRow, RowFilter, ImageResolver } from './../data/share-datatable-adapter';
|
||||
import { NodeEntityEvent, NodeEntryEvent } from './node.event';
|
||||
|
||||
declare var module: any;
|
||||
|
||||
@@ -116,16 +117,16 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
node: NodePaging = null;
|
||||
|
||||
@Output()
|
||||
nodeClick: EventEmitter<any> = new EventEmitter();
|
||||
nodeClick: EventEmitter<NodeEntityEvent> = new EventEmitter<NodeEntityEvent>();
|
||||
|
||||
@Output()
|
||||
nodeDblClick: EventEmitter<any> = new EventEmitter();
|
||||
nodeDblClick: EventEmitter<NodeEntityEvent> = new EventEmitter<NodeEntityEvent>();
|
||||
|
||||
@Output()
|
||||
folderChange: EventEmitter<any> = new EventEmitter();
|
||||
folderChange: EventEmitter<NodeEntryEvent> = new EventEmitter<NodeEntryEvent>();
|
||||
|
||||
@Output()
|
||||
preview: EventEmitter<any> = new EventEmitter();
|
||||
preview: EventEmitter<NodeEntityEvent> = new EventEmitter<NodeEntityEvent>();
|
||||
|
||||
@Output()
|
||||
success: EventEmitter<any> = new EventEmitter();
|
||||
@@ -231,7 +232,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
});
|
||||
}
|
||||
|
||||
isEmptyTemplateDefined() {
|
||||
isEmptyTemplateDefined(): boolean {
|
||||
if (this.dataTable) {
|
||||
if (this.emptyFolderTemplate) {
|
||||
return true;
|
||||
@@ -278,12 +279,10 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
|
||||
performNavigation(node: MinimalNodeEntity): boolean {
|
||||
if (node && node.entry && node.entry.isFolder) {
|
||||
|
||||
this.currentFolderId = node.entry.id;
|
||||
this.folderNode = node.entry;
|
||||
|
||||
this.loadFolder();
|
||||
this.folderChange.emit({node: node.entry});
|
||||
this.folderChange.emit(new NodeEntryEvent(node.entry));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -365,25 +364,24 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
|
||||
onPreviewFile(node: MinimalNodeEntity) {
|
||||
if (node) {
|
||||
this.preview.emit({
|
||||
value: node
|
||||
});
|
||||
this.preview.emit(new NodeEntityEvent(node));
|
||||
}
|
||||
}
|
||||
|
||||
onNodeClick(node: MinimalNodeEntity) {
|
||||
this.nodeClick.emit({
|
||||
value: node
|
||||
});
|
||||
let event = new NodeEntityEvent(node);
|
||||
this.nodeClick.emit(event);
|
||||
|
||||
if (this.navigate && this.navigationMode === DocumentListComponent.SINGLE_CLICK_NAVIGATION) {
|
||||
if (node && node.entry) {
|
||||
if (node.entry.isFile) {
|
||||
this.onPreviewFile(node);
|
||||
}
|
||||
if (!event.defaultPrevented) {
|
||||
if (this.navigate && this.navigationMode === DocumentListComponent.SINGLE_CLICK_NAVIGATION) {
|
||||
if (node && node.entry) {
|
||||
if (node.entry.isFile) {
|
||||
this.onPreviewFile(node);
|
||||
}
|
||||
|
||||
if (node.entry.isFolder) {
|
||||
this.performNavigation(node);
|
||||
if (node.entry.isFolder) {
|
||||
this.performNavigation(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -395,18 +393,19 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
}
|
||||
|
||||
onNodeDblClick(node: MinimalNodeEntity) {
|
||||
this.nodeDblClick.emit({
|
||||
value: node
|
||||
});
|
||||
let event = new NodeEntityEvent(node);
|
||||
this.nodeDblClick.emit(event);
|
||||
|
||||
if (this.navigate && this.navigationMode === DocumentListComponent.DOUBLE_CLICK_NAVIGATION) {
|
||||
if (node && node.entry) {
|
||||
if (node.entry.isFile) {
|
||||
this.onPreviewFile(node);
|
||||
}
|
||||
if (!event.defaultPrevented) {
|
||||
if (this.navigate && this.navigationMode === DocumentListComponent.DOUBLE_CLICK_NAVIGATION) {
|
||||
if (node && node.entry) {
|
||||
if (node.entry.isFile) {
|
||||
this.onPreviewFile(node);
|
||||
}
|
||||
|
||||
if (node.entry.isFolder) {
|
||||
this.performNavigation(node);
|
||||
if (node.entry.isFolder) {
|
||||
this.performNavigation(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,9 +416,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
this.onNodeDblClick(item);
|
||||
}
|
||||
|
||||
onShowRowContextMenu(event) {
|
||||
onShowRowContextMenu(event: DataCellEvent) {
|
||||
if (this.contextMenuActions) {
|
||||
let args = event.args;
|
||||
let args = event.value;
|
||||
let node = (<ShareDataRow> args.row).node;
|
||||
if (node) {
|
||||
args.actions = this.getContextActions(node) || [];
|
||||
@@ -427,9 +426,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
}
|
||||
}
|
||||
|
||||
onShowRowActionsMenu(event) {
|
||||
onShowRowActionsMenu(event: DataCellEvent) {
|
||||
if (this.contentActions) {
|
||||
let args = event.args;
|
||||
let args = event.value;
|
||||
let node = (<ShareDataRow> args.row).node;
|
||||
if (node) {
|
||||
args.actions = this.getNodeActions(node) || [];
|
||||
@@ -437,9 +436,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
}
|
||||
}
|
||||
|
||||
onExecuteRowAction(event) {
|
||||
onExecuteRowAction(event: DataRowActionEvent) {
|
||||
if (this.contentActions) {
|
||||
let args = event.args;
|
||||
let args = event.value;
|
||||
let node = (<ShareDataRow> args.row).node;
|
||||
let action = (<ContentActionModel> args.action);
|
||||
this.executeContentAction(node, action);
|
||||
@@ -455,17 +454,17 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
||||
this.success.emit(event);
|
||||
}
|
||||
|
||||
public onChangePageSize(event: Pagination): void {
|
||||
onChangePageSize(event: Pagination): void {
|
||||
this.pageSize = event.maxItems;
|
||||
this.reload();
|
||||
}
|
||||
|
||||
public onNextPage(event: Pagination): void {
|
||||
onNextPage(event: Pagination): void {
|
||||
this.skipCount = event.skipCount;
|
||||
this.reload();
|
||||
}
|
||||
|
||||
public onPrevPage(event: Pagination): void {
|
||||
onPrevPage(event: Pagination): void {
|
||||
this.skipCount = event.skipCount;
|
||||
this.reload();
|
||||
}
|
||||
|
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { BaseEvent } from 'ng2-alfresco-core';
|
||||
import { MinimalNodeEntity, MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||
|
||||
export class NodeEntityEvent extends BaseEvent<MinimalNodeEntity> {
|
||||
constructor(entity: MinimalNodeEntity) {
|
||||
super();
|
||||
this.value = entity;
|
||||
}
|
||||
}
|
||||
|
||||
export class NodeEntryEvent extends BaseEvent<MinimalNodeEntryEntity> {
|
||||
constructor(entity: MinimalNodeEntryEntity) {
|
||||
super();
|
||||
this.value = entity;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user