mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2500] fix trashcan bug plus refactoring documentlist (#3136)
* [ADF-2500] The full content of Trashcan is not displayed. fix pagination problem and add tests * refactor code * custom resources services * move custom resources in separate service part 2 * move custom resources in separate service part 3 * move isCustomResources in custom resources * move getCorrispondinNodeIds in custom services * reorganize code * add pagination interface * remove permissions check document list and use the common cs method remove the merge option and move it in the paginator * make infinte scrolling always use the target * restore loading infinite page * fix license header * fix type problems * breadcrumb test service * fix test * export CustomResourcesService * fix test pagination * fix content ndoe test * remove timeout content node selector test * fix after rebase * ripristinate observalbe in search service * fix wrong type return stub document list test * fix search service * fix test document list * move handle error in common method * restore observable in search control * Update search-control.component.spec.ts * fix after rebase * add import switchmap * core import in karma conf * missing commas * fix mocks * fix mock searchquerybody * search test fix
This commit is contained in:
committed by
Denys Vuika
parent
79789cb070
commit
07c247ca11
@@ -15,50 +15,33 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
DataCellEvent,
|
||||
DataColumn,
|
||||
DataRowActionEvent,
|
||||
DataSorting,
|
||||
DataTableComponent,
|
||||
DisplayMode,
|
||||
ObjectDataColumn,
|
||||
PaginatedComponent,
|
||||
PaginationQueryParams,
|
||||
PermissionsEnum,
|
||||
ContentService
|
||||
} from '@alfresco/adf-core';
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
AppConfigService,
|
||||
DataColumnListComponent,
|
||||
UserPreferencesService
|
||||
} from '@alfresco/adf-core';
|
||||
import {
|
||||
AfterContentInit, Component, ContentChild, ElementRef, EventEmitter, HostListener, Input, NgZone,
|
||||
OnChanges, OnDestroy, OnInit, Output, SimpleChanges, TemplateRef, ViewChild, ViewEncapsulation
|
||||
} from '@angular/core';
|
||||
|
||||
import {
|
||||
DeletedNodesPaging,
|
||||
MinimalNodeEntity,
|
||||
MinimalNodeEntryEntity,
|
||||
NodePaging,
|
||||
PersonEntry,
|
||||
SitePaging,
|
||||
Pagination
|
||||
} from 'alfresco-js-api';
|
||||
ContentService, DataCellEvent, DataColumn, DataRowActionEvent, DataSorting, DataTableComponent,
|
||||
DisplayMode, ObjectDataColumn, PaginatedComponent, AppConfigService, DataColumnListComponent,
|
||||
UserPreferencesService, PaginationModel
|
||||
} from '@alfresco/adf-core';
|
||||
|
||||
import { MinimalNodeEntity, MinimalNodeEntryEntity, NodePaging } from 'alfresco-js-api';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
import { presetsDefaultModel } from '../models/preset.model';
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
|
||||
import { ShareDataRow } from './../data/share-data-row.model';
|
||||
import { ShareDataTableAdapter } from './../data/share-datatable-adapter';
|
||||
|
||||
import { presetsDefaultModel } from '../models/preset.model';
|
||||
import { ContentActionModel } from './../models/content-action.model';
|
||||
import { PermissionStyleModel } from './../models/permissions-style.model';
|
||||
import { DocumentListService } from './../services/document-list.service';
|
||||
import { NodeEntityEvent, NodeEntryEvent } from './node.event';
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
import { CustomResourcesService } from './../services/custom-resources.service';
|
||||
|
||||
export enum PaginationStrategy {
|
||||
Finite,
|
||||
@@ -77,7 +60,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
static DOUBLE_CLICK_NAVIGATION: string = 'dblclick';
|
||||
static DEFAULT_PAGE_SIZE: number = 20;
|
||||
|
||||
@ContentChild(DataColumnListComponent) columnList: DataColumnListComponent;
|
||||
@ContentChild(DataColumnListComponent)
|
||||
columnList: DataColumnListComponent;
|
||||
|
||||
/** Include additional information about the node in the server request.for example: association, isLink, isLocked and others. */
|
||||
@Input()
|
||||
@@ -191,14 +175,16 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
@Input()
|
||||
node: NodePaging = null;
|
||||
|
||||
/** Default value is stored into user preference settings */
|
||||
/** Default value is stored into user preference settings use it only if you are not using the pagination */
|
||||
@Input()
|
||||
maxItems: number;
|
||||
|
||||
/** @deprecated 2.3.0 define it in pagination */
|
||||
/** Number of elements to skip over for pagination purposes */
|
||||
@Input()
|
||||
skipCount: number = 0;
|
||||
|
||||
/** @deprecated 2.3.0 */
|
||||
/** Set document list to work in infinite scrolling mode */
|
||||
@Input()
|
||||
enableInfiniteScrolling: boolean = false;
|
||||
@@ -233,39 +219,26 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
@ViewChild('dataTable')
|
||||
dataTable: DataTableComponent;
|
||||
|
||||
errorMessage;
|
||||
actions: ContentActionModel[] = [];
|
||||
emptyFolderTemplate: TemplateRef<any>;
|
||||
noPermissionTemplate: TemplateRef<any>;
|
||||
contextActionHandler: Subject<any> = new Subject();
|
||||
data: ShareDataTableAdapter;
|
||||
infiniteLoading: boolean = false;
|
||||
noPermission: boolean = false;
|
||||
selection = new Array<MinimalNodeEntity>();
|
||||
|
||||
pagination: BehaviorSubject<Pagination>;
|
||||
|
||||
private _pagination: BehaviorSubject<PaginationModel>;
|
||||
private layoutPresets = {};
|
||||
private currentNodeAllowableOperations: string[] = [];
|
||||
private CREATE_PERMISSION = 'create';
|
||||
|
||||
private contextActionHandlerSubscription: Subscription;
|
||||
|
||||
constructor(private documentListService: DocumentListService,
|
||||
private ngZone: NgZone,
|
||||
private elementRef: ElementRef,
|
||||
private apiService: AlfrescoApiService,
|
||||
private appConfig: AppConfigService,
|
||||
private preferences: UserPreferencesService,
|
||||
private contentService?: ContentService) {
|
||||
this.maxItems = this.preferences.paginationSize;
|
||||
|
||||
this.pagination = new BehaviorSubject<Pagination>(<Pagination> {
|
||||
maxItems: this.preferences.paginationSize,
|
||||
skipCount: 0,
|
||||
totalItems: 0,
|
||||
hasMoreItems: false
|
||||
});
|
||||
private customResourcesService: CustomResourcesService,
|
||||
private contentService: ContentService) {
|
||||
}
|
||||
|
||||
getContextActions(node: MinimalNodeEntity) {
|
||||
@@ -284,16 +257,75 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
return null;
|
||||
}
|
||||
|
||||
contextActionCallback(action) {
|
||||
if (action) {
|
||||
this.executeContentAction(action.node, action.model);
|
||||
}
|
||||
/** @deprecated 2.3.0 define it in pagination */
|
||||
get supportedPageSizes(): number[] {
|
||||
return this.preferences.getDefaultPageSizes();
|
||||
}
|
||||
|
||||
get hasCustomLayout(): boolean {
|
||||
return this.columnList && this.columnList.columns && this.columnList.columns.length > 0;
|
||||
}
|
||||
|
||||
private getDefaultSorting(): DataSorting {
|
||||
let defaultSorting: DataSorting;
|
||||
if (this.sorting) {
|
||||
const [key, direction] = this.sorting;
|
||||
defaultSorting = new DataSorting(key, direction);
|
||||
}
|
||||
return defaultSorting;
|
||||
}
|
||||
|
||||
private getLayoutPreset(name: string = 'default'): DataColumn[] {
|
||||
return (this.layoutPresets[name] || this.layoutPresets['default']).map(col => new ObjectDataColumn(col));
|
||||
}
|
||||
|
||||
get pagination(): BehaviorSubject<PaginationModel> {
|
||||
let maxItems = this.preferences.paginationSize;
|
||||
|
||||
if (!this._pagination) {
|
||||
if (this.maxItems) {
|
||||
maxItems = this.maxItems;
|
||||
}
|
||||
|
||||
let defaultPagination = <PaginationModel> {
|
||||
maxItems: maxItems,
|
||||
skipCount: 0,
|
||||
totalItems: 0,
|
||||
hasMoreItems: false
|
||||
};
|
||||
|
||||
this._pagination = new BehaviorSubject<PaginationModel>(defaultPagination);
|
||||
}
|
||||
|
||||
return this._pagination;
|
||||
}
|
||||
|
||||
isEmptyTemplateDefined(): boolean {
|
||||
if (this.dataTable) {
|
||||
if (this.emptyFolderTemplate) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isNoPermissionTemplateDefined(): boolean {
|
||||
if (this.dataTable) {
|
||||
if (this.noPermissionTemplate) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isMobile(): boolean {
|
||||
return !!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
||||
}
|
||||
|
||||
isEmpty() {
|
||||
return !this.data || this.data.getRows().length === 0;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.loadLayoutPresets();
|
||||
this.data = new ShareDataTableAdapter(this.documentListService, null, this.getDefaultSorting());
|
||||
@@ -333,10 +365,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (this.isSkipCountChanged(changes) ||
|
||||
this.isMaxItemsChanged(changes)) {
|
||||
this.reload(this.enableInfiniteScrolling);
|
||||
}
|
||||
this.resetSelection();
|
||||
|
||||
if (changes.folderNode && changes.folderNode.currentValue) {
|
||||
this.loadFolder();
|
||||
} else if (changes.currentFolderId && changes.currentFolderId.currentValue) {
|
||||
@@ -346,17 +376,18 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
if (!this.hasCustomLayout) {
|
||||
this.setupDefaultColumns(changes.currentFolderId.currentValue);
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
|
||||
this.loadFolderByNodeId(changes.currentFolderId.currentValue);
|
||||
} else if (this.data) {
|
||||
if (changes.node && changes.node.currentValue) {
|
||||
this.resetSelection();
|
||||
|
||||
this.data.loadPage(changes.node.currentValue);
|
||||
this.pagination.next(changes.node.currentValue.list.pagination);
|
||||
this.onDataReady(changes.node.currentValue);
|
||||
} else if (changes.rowFilter) {
|
||||
this.data.setFilter(changes.rowFilter.currentValue);
|
||||
if (this.currentFolderId) {
|
||||
this.loadFolderNodesByFolderNodeId(this.currentFolderId, this.maxItems, this.skipCount);
|
||||
this.loadFolderNodesByFolderNodeId(this.currentFolderId, this.pagination.getValue()).catch(err => this.error.emit(err));
|
||||
}
|
||||
} else if (changes.imageResolver) {
|
||||
this.data.setImageResolver(changes.imageResolver.currentValue);
|
||||
@@ -364,14 +395,15 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
}
|
||||
|
||||
reload(merge: boolean = false) {
|
||||
reload() {
|
||||
this.ngZone.run(() => {
|
||||
this.resetSelection();
|
||||
|
||||
if (this.folderNode) {
|
||||
this.loadFolder(merge);
|
||||
this.loadFolder();
|
||||
} else if (this.currentFolderId) {
|
||||
this.loadFolderByNodeId(this.currentFolderId, merge);
|
||||
this.loading = true;
|
||||
this.loadFolderByNodeId(this.currentFolderId);
|
||||
} else if (this.node) {
|
||||
this.data.loadPage(this.node);
|
||||
this.onDataReady(this.node);
|
||||
@@ -379,30 +411,10 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
});
|
||||
}
|
||||
|
||||
isEmptyTemplateDefined(): boolean {
|
||||
if (this.dataTable) {
|
||||
if (this.emptyFolderTemplate) {
|
||||
return true;
|
||||
}
|
||||
contextActionCallback(action) {
|
||||
if (action) {
|
||||
this.executeContentAction(action.node, action.model);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isNoPermissionTemplateDefined(): boolean {
|
||||
if (this.dataTable) {
|
||||
if (this.noPermissionTemplate) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isMobile(): boolean {
|
||||
return !!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
||||
}
|
||||
|
||||
isEmpty() {
|
||||
return !this.data || this.data.getRows().length === 0;
|
||||
}
|
||||
|
||||
getNodeActions(node: MinimalNodeEntity | any): ContentActionModel[] {
|
||||
@@ -411,20 +423,17 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
if (node && node.entry) {
|
||||
if (node.entry.isFile) {
|
||||
target = 'document';
|
||||
}
|
||||
|
||||
if (node.entry.isFolder) {
|
||||
} else if (node.entry.isFolder) {
|
||||
target = 'folder';
|
||||
}
|
||||
|
||||
if (target) {
|
||||
let ltarget = target.toLowerCase();
|
||||
let actionsByTarget = this.actions.filter(entry => {
|
||||
return entry.target.toLowerCase() === ltarget;
|
||||
return entry.target.toLowerCase() === target;
|
||||
}).map(action => new ContentActionModel(action));
|
||||
|
||||
actionsByTarget.forEach((action) => {
|
||||
this.checkPermission(node, action);
|
||||
this.disableActionsWithNoPermissions(node, action);
|
||||
});
|
||||
|
||||
return actionsByTarget;
|
||||
@@ -434,26 +443,10 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
return [];
|
||||
}
|
||||
|
||||
checkPermission(node: any, action: ContentActionModel): ContentActionModel {
|
||||
if (action.permission && !~[PermissionsEnum.COPY, PermissionsEnum.LOCK].indexOf(action.permission)) {
|
||||
if (this.hasPermissions(node)) {
|
||||
let permissions = node.entry.allowableOperations;
|
||||
let findPermission = permissions.find(permission => permission === action.permission);
|
||||
if (!findPermission && action.disableWithNoPermission === true) {
|
||||
action.disabled = true;
|
||||
}
|
||||
}
|
||||
disableActionsWithNoPermissions(node: MinimalNodeEntity, action: ContentActionModel) {
|
||||
if (action.permission && node.entry.allowableOperations && !this.contentService.hasPermission(node.entry, action.permission)) {
|
||||
action.disabled = true;
|
||||
}
|
||||
|
||||
if (action.permission === PermissionsEnum.LOCK) {
|
||||
action.disabled = !this.contentService.hasPermission(node.entry, PermissionsEnum.LOCK);
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
private hasPermissions(node: any): boolean {
|
||||
return node.entry.allowableOperations ? true : false;
|
||||
}
|
||||
|
||||
@HostListener('contextmenu', ['$event'])
|
||||
@@ -472,7 +465,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
|
||||
performCustomSourceNavigation(node: MinimalNodeEntity): boolean {
|
||||
if (this.isCustomSource(this.currentFolderId)) {
|
||||
if (this.customResourcesService.isCustomSource(this.currentFolderId)) {
|
||||
this.updateFolderData(node);
|
||||
return true;
|
||||
}
|
||||
@@ -482,18 +475,13 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
updateFolderData(node: MinimalNodeEntity): void {
|
||||
this.currentFolderId = node.entry.id;
|
||||
this.folderNode = node.entry;
|
||||
this.skipCount = 0;
|
||||
this.currentNodeAllowableOperations = node.entry['allowableOperations'] ? node.entry['allowableOperations'] : [];
|
||||
this.loadFolder();
|
||||
this.folderChange.emit(new NodeEntryEvent(node.entry));
|
||||
}
|
||||
|
||||
updateCustomSourceData(nodeId: string, merge: boolean): void {
|
||||
updateCustomSourceData(nodeId: string): void {
|
||||
this.folderNode = null;
|
||||
this.currentFolderId = nodeId;
|
||||
if (!merge) {
|
||||
this.skipCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -519,10 +507,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
}
|
||||
|
||||
loadFolder(merge: boolean = false) {
|
||||
if (merge) {
|
||||
this.infiniteLoading = true;
|
||||
} else {
|
||||
loadFolder() {
|
||||
if (!this.pagination.getValue().merge) {
|
||||
this.loading = true;
|
||||
}
|
||||
|
||||
@@ -532,70 +518,55 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
this.setupDefaultColumns(nodeId);
|
||||
}
|
||||
if (nodeId) {
|
||||
this.loadFolderNodesByFolderNodeId(nodeId, this.maxItems, this.skipCount, merge).catch(err => this.error.emit(err));
|
||||
this.loadFolderNodesByFolderNodeId(nodeId, this.pagination.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
// gets folder node and its content
|
||||
loadFolderByNodeId(nodeId: string, merge: boolean = false) {
|
||||
this.loading = true;
|
||||
this.resetSelection();
|
||||
|
||||
if (nodeId === '-trashcan-') {
|
||||
this.loadTrashcan(merge);
|
||||
} else if (nodeId === '-sharedlinks-') {
|
||||
this.loadSharedLinks(merge);
|
||||
} else if (nodeId === '-sites-') {
|
||||
this.loadSites(merge);
|
||||
} else if (nodeId === '-mysites-') {
|
||||
this.loadMemberSites(merge);
|
||||
} else if (nodeId === '-favorites-') {
|
||||
this.loadFavorites(merge);
|
||||
} else if (nodeId === '-recent-') {
|
||||
this.loadRecent(merge);
|
||||
loadFolderByNodeId(nodeId: string) {
|
||||
if (this.customResourcesService.isCustomSource(nodeId)) {
|
||||
this.updateCustomSourceData(nodeId);
|
||||
this.customResourcesService.loadFolderByNodeId(nodeId, this.pagination.getValue(), this.includeFields)
|
||||
.subscribe((page: NodePaging) => {
|
||||
this.onPageLoaded(page);
|
||||
}, err => {
|
||||
this.error.emit(err);
|
||||
});
|
||||
} else {
|
||||
this.documentListService
|
||||
.getFolderNode(nodeId, this.includeFields)
|
||||
.then(node => {
|
||||
.subscribe((node: MinimalNodeEntryEntity) => {
|
||||
this.folderNode = node;
|
||||
this.currentFolderId = node.id;
|
||||
this.skipCount = 0;
|
||||
this.currentNodeAllowableOperations = node['allowableOperations'] ? node['allowableOperations'] : [];
|
||||
return this.loadFolderNodesByFolderNodeId(node.id, this.maxItems, this.skipCount, merge);
|
||||
})
|
||||
.catch(err => {
|
||||
if (JSON.parse(err.message).error.statusCode === 403) {
|
||||
this.loading = false;
|
||||
this.noPermission = true;
|
||||
|
||||
if (node.id) {
|
||||
this.currentFolderId = node.id;
|
||||
}
|
||||
this.error.emit(err);
|
||||
return this.loadFolderNodesByFolderNodeId(node.id, this.pagination.getValue())
|
||||
.catch(err => this.handleError(err));
|
||||
}, err => {
|
||||
this.handleError(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
loadFolderNodesByFolderNodeId(id: string, maxItems: number, skipCount: number, merge: boolean = false): Promise<any> {
|
||||
loadFolderNodesByFolderNodeId(id: string, pagination: PaginationModel): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.resetSelection();
|
||||
|
||||
this.documentListService
|
||||
.getFolder(null, {
|
||||
maxItems: maxItems,
|
||||
skipCount: skipCount,
|
||||
maxItems: pagination.maxItems,
|
||||
skipCount: pagination.skipCount,
|
||||
rootFolderId: id
|
||||
}, this.includeFields)
|
||||
.subscribe(
|
||||
val => {
|
||||
this.data.loadPage(<NodePaging> val, merge);
|
||||
nodePaging => {
|
||||
this.data.loadPage(<NodePaging> nodePaging, this.pagination.getValue().merge);
|
||||
this.loading = false;
|
||||
this.infiniteLoading = false;
|
||||
this.onDataReady(val);
|
||||
this.onDataReady(nodePaging);
|
||||
resolve(true);
|
||||
},
|
||||
error => {
|
||||
reject(error);
|
||||
}, err => {
|
||||
this.handleError(err);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
resetSelection() {
|
||||
@@ -604,144 +575,11 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
this.noPermission = false;
|
||||
}
|
||||
|
||||
private isSkipCountChanged(changePage: SimpleChanges) {
|
||||
return changePage.skipCount &&
|
||||
!changePage.skipCount.isFirstChange() &&
|
||||
changePage.skipCount.currentValue &&
|
||||
changePage.skipCount.currentValue !== changePage.skipCount.previousValue;
|
||||
}
|
||||
|
||||
private isMaxItemsChanged(changePage: SimpleChanges) {
|
||||
return changePage.maxItems &&
|
||||
!changePage.maxItems.isFirstChange() &&
|
||||
changePage.maxItems.currentValue &&
|
||||
changePage.maxItems.currentValue !== changePage.maxItems.previousValue;
|
||||
}
|
||||
|
||||
private loadTrashcan(merge: boolean = false): void {
|
||||
this.updateCustomSourceData('-trashcan-', merge);
|
||||
|
||||
const options = {
|
||||
include: ['path', 'properties'],
|
||||
maxItems: this.maxItems,
|
||||
skipCount: this.skipCount
|
||||
};
|
||||
this.apiService.nodesApi.getDeletedNodes(options)
|
||||
.then((page: DeletedNodesPaging) => this.onPageLoaded(page, merge))
|
||||
.catch(error => this.error.emit(error));
|
||||
}
|
||||
|
||||
private loadSharedLinks(merge: boolean = false): void {
|
||||
this.updateCustomSourceData('-sharedlinks-', merge);
|
||||
|
||||
const options = {
|
||||
include: ['properties', 'allowableOperations', 'path'],
|
||||
maxItems: this.maxItems,
|
||||
skipCount: this.skipCount
|
||||
};
|
||||
this.apiService.sharedLinksApi.findSharedLinks(options)
|
||||
.then((page: NodePaging) => this.onPageLoaded(page, merge))
|
||||
.catch(error => this.error.emit(error));
|
||||
}
|
||||
|
||||
private loadSites(merge: boolean = false): void {
|
||||
this.updateCustomSourceData('-sites-', merge);
|
||||
|
||||
const options = {
|
||||
include: ['properties'],
|
||||
maxItems: this.maxItems,
|
||||
skipCount: this.skipCount
|
||||
};
|
||||
|
||||
this.apiService.sitesApi.getSites(options)
|
||||
.then((page: NodePaging) => {
|
||||
page.list.entries.map(
|
||||
({ entry }: any) => {
|
||||
entry.name = entry.name || entry.title;
|
||||
return { entry };
|
||||
}
|
||||
);
|
||||
this.onPageLoaded(page, merge);
|
||||
})
|
||||
.catch(error => this.error.emit(error));
|
||||
}
|
||||
|
||||
private loadMemberSites(merge: boolean = false): void {
|
||||
this.updateCustomSourceData('-mysites-', merge);
|
||||
|
||||
const options = {
|
||||
include: ['properties'],
|
||||
maxItems: this.maxItems,
|
||||
skipCount: this.skipCount
|
||||
};
|
||||
|
||||
this.apiService.peopleApi.getSiteMembership('-me-', options)
|
||||
.then((result: SitePaging) => {
|
||||
let page: NodePaging = {
|
||||
list: {
|
||||
entries: result.list.entries
|
||||
.map(({ entry: { site } }: any) => {
|
||||
site.allowableOperations = site.allowableOperations ? site.allowableOperations : [this.CREATE_PERMISSION];
|
||||
site.name = site.name || site.title;
|
||||
return {
|
||||
entry: site
|
||||
};
|
||||
}),
|
||||
pagination: result.list.pagination
|
||||
}
|
||||
};
|
||||
|
||||
this.onPageLoaded(page, merge);
|
||||
})
|
||||
.catch(error => this.error.emit(error));
|
||||
}
|
||||
|
||||
private loadFavorites(merge: boolean = false): void {
|
||||
this.updateCustomSourceData('-favorites-', merge);
|
||||
|
||||
const options = {
|
||||
maxItems: this.maxItems,
|
||||
skipCount: this.skipCount,
|
||||
where: '(EXISTS(target/file) OR EXISTS(target/folder))',
|
||||
include: ['properties', 'allowableOperations', 'path']
|
||||
};
|
||||
|
||||
this.apiService.favoritesApi.getFavorites('-me-', options)
|
||||
.then((result: NodePaging) => {
|
||||
let page: NodePaging = {
|
||||
list: {
|
||||
entries: result.list.entries
|
||||
.map(({ entry: { target } }: any) => ({
|
||||
entry: target.file || target.folder
|
||||
}))
|
||||
.map(({ entry }: any) => {
|
||||
entry.properties = {
|
||||
'cm:title': entry.title,
|
||||
'cm:description': entry.description
|
||||
};
|
||||
return { entry };
|
||||
}),
|
||||
pagination: result.list.pagination
|
||||
}
|
||||
};
|
||||
this.onPageLoaded(page, merge);
|
||||
})
|
||||
.catch(error => this.error.emit(error));
|
||||
}
|
||||
|
||||
private loadRecent(merge: boolean = false): void {
|
||||
this.updateCustomSourceData('-recent-', merge);
|
||||
|
||||
this.getRecentFiles('-me-')
|
||||
.then((page: NodePaging) => this.onPageLoaded(page, merge))
|
||||
.catch(error => this.error.emit(error));
|
||||
}
|
||||
|
||||
private onPageLoaded(page: NodePaging, merge: boolean = false) {
|
||||
if (page) {
|
||||
this.data.loadPage(page, merge);
|
||||
private onPageLoaded(nodePaging: NodePaging) {
|
||||
if (nodePaging) {
|
||||
this.data.loadPage(nodePaging, this.pagination.getValue().merge);
|
||||
this.loading = false;
|
||||
this.onDataReady(page);
|
||||
this.onDataReady(nodePaging);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -876,48 +714,16 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
}
|
||||
|
||||
private getDefaultSorting(): DataSorting {
|
||||
let defaultSorting: DataSorting;
|
||||
if (this.sorting) {
|
||||
const [key, direction] = this.sorting;
|
||||
defaultSorting = new DataSorting(key, direction);
|
||||
}
|
||||
return defaultSorting;
|
||||
}
|
||||
|
||||
canNavigateFolder(node: MinimalNodeEntity): boolean {
|
||||
if (this.isCustomSource(this.currentFolderId)) {
|
||||
return false;
|
||||
let canNavigateFolder: boolean = false;
|
||||
|
||||
if (this.customResourcesService.isCustomSource(this.currentFolderId)) {
|
||||
canNavigateFolder = false;
|
||||
} else if (node && node.entry && node.entry.isFolder) {
|
||||
canNavigateFolder = true;
|
||||
}
|
||||
|
||||
if (node && node.entry && node.entry.isFolder) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
isCustomSource(folderId: string): boolean {
|
||||
const sources = ['-trashcan-', '-sharedlinks-', '-sites-', '-mysites-', '-favorites-', '-recent-'];
|
||||
|
||||
if (sources.indexOf(folderId) > -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
hasCurrentNodePermission(permission: string): boolean {
|
||||
let hasPermission: boolean = false;
|
||||
if (this.currentNodeAllowableOperations.length > 0) {
|
||||
let permFound = this.currentNodeAllowableOperations.find(element => element === permission);
|
||||
hasPermission = permFound ? true : false;
|
||||
}
|
||||
return hasPermission;
|
||||
}
|
||||
|
||||
hasCreatePermission() {
|
||||
return this.hasCurrentNodePermission(this.CREATE_PERMISSION);
|
||||
return canNavigateFolder;
|
||||
}
|
||||
|
||||
private loadLayoutPresets(): void {
|
||||
@@ -930,33 +736,30 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
}
|
||||
|
||||
private getLayoutPreset(name: string = 'default'): DataColumn[] {
|
||||
return (this.layoutPresets[name] || this.layoutPresets['default']).map(col => new ObjectDataColumn(col));
|
||||
private onDataReady(nodePaging: NodePaging) {
|
||||
this.ready.emit(nodePaging);
|
||||
|
||||
this.pagination.next(nodePaging.list.pagination);
|
||||
}
|
||||
|
||||
private onDataReady(page: NodePaging) {
|
||||
this.ready.emit(page);
|
||||
updatePagination(pagination: PaginationModel) {
|
||||
this.reload();
|
||||
}
|
||||
|
||||
if (page && page.list && page.list.pagination) {
|
||||
this.pagination.next(page.list.pagination);
|
||||
} else {
|
||||
this.pagination.next(null);
|
||||
// TODO: remove it from here
|
||||
getCorrespondingNodeIds(nodeId: string): Observable<string[]> {
|
||||
if (this.customResourcesService.isCustomSource(nodeId)) {
|
||||
return this.customResourcesService.getCorrespondingNodeIds(nodeId, this.pagination.getValue());
|
||||
} else if (nodeId) {
|
||||
return new Observable(observer => {
|
||||
this.documentListService.getFolderNode(nodeId, this.includeFields)
|
||||
.subscribe((node: MinimalNodeEntryEntity) => {
|
||||
observer.next([node.id]);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
updatePagination(params: PaginationQueryParams) {
|
||||
const needsReload = this.maxItems !== params.maxItems || this.skipCount !== params.skipCount;
|
||||
|
||||
this.maxItems = params.maxItems;
|
||||
this.skipCount = params.skipCount;
|
||||
|
||||
if (needsReload) {
|
||||
this.reload(this.enableInfiniteScrolling);
|
||||
}
|
||||
}
|
||||
|
||||
get supportedPageSizes(): number[] {
|
||||
return this.preferences.getDefaultPageSizes();
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
@@ -966,67 +769,15 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
}
|
||||
|
||||
getCorrespondingNodeIds(nodeId: string): Promise<string[]> {
|
||||
if (nodeId === '-trashcan-') {
|
||||
return this.apiService.nodesApi.getDeletedNodes()
|
||||
.then(result => result.list.entries.map(node => node.entry.id));
|
||||
|
||||
} else if (nodeId === '-sharedlinks-') {
|
||||
return this.apiService.sharedLinksApi.findSharedLinks()
|
||||
.then(result => result.list.entries.map(node => node.entry.nodeId));
|
||||
|
||||
} else if (nodeId === '-sites-') {
|
||||
return this.apiService.sitesApi.getSites()
|
||||
.then(result => result.list.entries.map(node => node.entry.guid));
|
||||
|
||||
} else if (nodeId === '-mysites-') {
|
||||
return this.apiService.peopleApi.getSiteMembership('-me-')
|
||||
.then(result => result.list.entries.map(node => node.entry.guid));
|
||||
|
||||
} else if (nodeId === '-favorites-') {
|
||||
return this.apiService.favoritesApi.getFavorites('-me-')
|
||||
.then(result => result.list.entries.map(node => node.entry.targetGuid));
|
||||
|
||||
} else if (nodeId === '-recent-') {
|
||||
return this.getRecentFiles('-me-')
|
||||
.then(result => result.list.entries.map(node => node.entry.id));
|
||||
|
||||
} else if (nodeId) {
|
||||
return this.documentListService.getFolderNode(nodeId, this.includeFields)
|
||||
.then(node => [node.id]);
|
||||
private handleError(err: any) {
|
||||
if (err.message) {
|
||||
if (JSON.parse(err.message).error.statusCode === 403) {
|
||||
this.loading = false;
|
||||
this.noPermission = true;
|
||||
}
|
||||
}
|
||||
this.error.emit(err);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
resolve([]);
|
||||
});
|
||||
}
|
||||
|
||||
getRecentFiles(personId: string): Promise<NodePaging> {
|
||||
return this.apiService.peopleApi.getPerson(personId)
|
||||
.then((person: PersonEntry) => {
|
||||
const username = person.entry.id;
|
||||
const query = {
|
||||
query: {
|
||||
query: '*',
|
||||
language: 'afts'
|
||||
},
|
||||
filterQueries: [
|
||||
{ query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` },
|
||||
{ query: `cm:modifier:${username} OR cm:creator:${username}` },
|
||||
{ query: `TYPE:"content" AND -TYPE:"app:filelink" AND -TYPE:"fm:post"` }
|
||||
],
|
||||
include: ['path', 'properties', 'allowableOperations'],
|
||||
sort: [{
|
||||
type: 'FIELD',
|
||||
field: 'cm:modified',
|
||||
ascending: false
|
||||
}],
|
||||
paging: {
|
||||
maxItems: this.maxItems,
|
||||
skipCount: this.skipCount
|
||||
}
|
||||
};
|
||||
return this.apiService.searchApi.search(query);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user