mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
support page picker for document list (#2424)
This commit is contained in:
committed by
Eugenio Romano
parent
80b6e15420
commit
12f5a219f5
@@ -16,7 +16,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { AlfrescoApi, ContentApi, NodesApi, RenditionsApi } from 'alfresco-js-api';
|
import {
|
||||||
|
AlfrescoApi, ContentApi, FavoritesApi, NodesApi,
|
||||||
|
PeopleApi, RenditionsApi, SharedlinksApi, SitesApi
|
||||||
|
} from 'alfresco-js-api';
|
||||||
import * as alfrescoApi from 'alfresco-js-api';
|
import * as alfrescoApi from 'alfresco-js-api';
|
||||||
import { AppConfigService } from './app-config.service';
|
import { AppConfigService } from './app-config.service';
|
||||||
import { StorageService } from './storage.service';
|
import { StorageService } from './storage.service';
|
||||||
@@ -42,6 +45,26 @@ export class AlfrescoApiService {
|
|||||||
return this.getInstance().core.renditionsApi;
|
return this.getInstance().core.renditionsApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get sharedLinksApi(): SharedlinksApi {
|
||||||
|
return this.getInstance().core.sharedlinksApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
get sitesApi(): SitesApi {
|
||||||
|
return this.getInstance().core.sitesApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
get favoritesApi(): FavoritesApi {
|
||||||
|
return this.getInstance().core.favoritesApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
get peopleApi(): PeopleApi {
|
||||||
|
return this.getInstance().core.peopleApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
get searchApi() {
|
||||||
|
return this.getInstance().search.searchApi;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(private appConfig: AppConfigService,
|
constructor(private appConfig: AppConfigService,
|
||||||
private storage: StorageService) {
|
private storage: StorageService) {
|
||||||
|
|
||||||
|
@@ -55,6 +55,7 @@
|
|||||||
*ngIf="isPaginationNeeded()"
|
*ngIf="isPaginationNeeded()"
|
||||||
class="adf-documentlist-pagination"
|
class="adf-documentlist-pagination"
|
||||||
(changePageSize)="onChangePageSize($event)"
|
(changePageSize)="onChangePageSize($event)"
|
||||||
|
(changePageNumber)="onChangePageNumber($event)"
|
||||||
(nextPage)="onNextPage($event)"
|
(nextPage)="onNextPage($event)"
|
||||||
(prevPage)="onPrevPage($event)"
|
(prevPage)="onPrevPage($event)"
|
||||||
[pagination]="pagination"
|
[pagination]="pagination"
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import { CUSTOM_ELEMENTS_SCHEMA, NgZone, SimpleChange, TemplateRef } from '@angular/core';
|
import { CUSTOM_ELEMENTS_SCHEMA, NgZone, SimpleChange, TemplateRef } from '@angular/core';
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { Pagination } from 'alfresco-js-api';
|
||||||
import { AlfrescoApiService, AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
|
import { AlfrescoApiService, AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
|
||||||
import { DataColumn, DataTableComponent } from 'ng2-alfresco-datatable';
|
import { DataColumn, DataTableComponent } from 'ng2-alfresco-datatable';
|
||||||
import { DataTableModule } from 'ng2-alfresco-datatable';
|
import { DataTableModule } from 'ng2-alfresco-datatable';
|
||||||
@@ -76,7 +77,6 @@ describe('DocumentList', () => {
|
|||||||
fixture = TestBed.createComponent(DocumentListComponent);
|
fixture = TestBed.createComponent(DocumentListComponent);
|
||||||
|
|
||||||
let translateService = TestBed.get(AlfrescoTranslationService);
|
let translateService = TestBed.get(AlfrescoTranslationService);
|
||||||
// spyOn(translateService, 'addTranslationFolder').and.stub();
|
|
||||||
spyOn(translateService, 'get').and.callFake((key) => {
|
spyOn(translateService, 'get').and.callFake((key) => {
|
||||||
return Observable.of(key);
|
return Observable.of(key);
|
||||||
});
|
});
|
||||||
@@ -905,11 +905,10 @@ describe('DocumentList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch trashcan', () => {
|
it('should fetch trashcan', () => {
|
||||||
const nodesApi = apiService.getInstance().core.nodesApi;
|
spyOn(apiService.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve(null));
|
||||||
spyOn(nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve(null));
|
|
||||||
|
|
||||||
documentList.loadFolderByNodeId('-trashcan-');
|
documentList.loadFolderByNodeId('-trashcan-');
|
||||||
expect(nodesApi.getDeletedNodes).toHaveBeenCalled();
|
expect(apiService.nodesApi.getDeletedNodes).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch shared links', () => {
|
it('should fetch shared links', () => {
|
||||||
@@ -937,20 +936,40 @@ describe('DocumentList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch recent', (done) => {
|
it('should fetch recent', (done) => {
|
||||||
|
|
||||||
const person = { entry: { id: 'person '} };
|
const person = { entry: { id: 'person '} };
|
||||||
const peopleApi = apiService.getInstance().core.peopleApi;
|
|
||||||
const searchApi = apiService.getInstance().search.searchApi;
|
|
||||||
|
|
||||||
spyOn(peopleApi, 'getPerson').and.returnValue(Promise.resolve(person));
|
spyOn(apiService.peopleApi, 'getPerson').and.returnValue(Promise.resolve(person));
|
||||||
spyOn(searchApi, 'search').and.returnValue(Promise.resolve(null));
|
spyOn(apiService.searchApi, 'search').and.returnValue(Promise.resolve(null));
|
||||||
|
|
||||||
documentList.loadFolderByNodeId('-recent-');
|
documentList.loadFolderByNodeId('-recent-');
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
expect(peopleApi.getPerson).toHaveBeenCalledWith('-me-');
|
expect(apiService.peopleApi.getPerson).toHaveBeenCalledWith('-me-');
|
||||||
expect(searchApi.search).toHaveBeenCalled();
|
expect(apiService.searchApi.search).toHaveBeenCalled();
|
||||||
done();
|
done();
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should switch to another page', () => {
|
||||||
|
spyOn(documentList, 'reload').and.stub();
|
||||||
|
|
||||||
|
const page1: Pagination = {
|
||||||
|
maxItems: 5,
|
||||||
|
skipCount: 0
|
||||||
|
};
|
||||||
|
const page2: Pagination = {
|
||||||
|
maxItems: 5,
|
||||||
|
skipCount: 10
|
||||||
|
};
|
||||||
|
|
||||||
|
documentList.onChangePageNumber(page1);
|
||||||
|
expect(documentList.pageSize).toBe(page1.maxItems);
|
||||||
|
expect(documentList.skipCount).toBe(page1.skipCount);
|
||||||
|
|
||||||
|
documentList.onChangePageNumber(page2);
|
||||||
|
expect(documentList.pageSize).toBe(page2.maxItems);
|
||||||
|
expect(documentList.skipCount).toBe(page2.skipCount);
|
||||||
|
|
||||||
|
expect(documentList.reload).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -172,30 +172,6 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
this.supportedPageSizes = appConfig.get('document-list.supportedPageSizes', [5, 10, 15, 20]);
|
this.supportedPageSizes = appConfig.get('document-list.supportedPageSizes', [5, 10, 15, 20]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private get nodesApi() {
|
|
||||||
return this.apiService.getInstance().core.nodesApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
private get sharedLinksApi() {
|
|
||||||
return this.apiService.getInstance().core.sharedlinksApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
private get sitesApi() {
|
|
||||||
return this.apiService.getInstance().core.sitesApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
private get favoritesApi() {
|
|
||||||
return this.apiService.getInstance().core.favoritesApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
private get peopleApi() {
|
|
||||||
return this.apiService.getInstance().core.peopleApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
private get searchApi() {
|
|
||||||
return this.apiService.getInstance().search.searchApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
getContextActions(node: MinimalNodeEntity) {
|
getContextActions(node: MinimalNodeEntity) {
|
||||||
if (node && node.entry) {
|
if (node && node.entry) {
|
||||||
let actions = this.getNodeActions(node);
|
let actions = this.getNodeActions(node);
|
||||||
@@ -495,7 +471,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
maxItems: this.pageSize,
|
maxItems: this.pageSize,
|
||||||
skipCount: this.skipCount
|
skipCount: this.skipCount
|
||||||
};
|
};
|
||||||
this.nodesApi.getDeletedNodes(options).then((page: NodePaging) => {
|
this.apiService.nodesApi.getDeletedNodes(options).then((page: NodePaging) => {
|
||||||
this.onPageLoaded(page);
|
this.onPageLoaded(page);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -506,7 +482,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
maxItems: this.pageSize,
|
maxItems: this.pageSize,
|
||||||
skipCount: this.skipCount
|
skipCount: this.skipCount
|
||||||
};
|
};
|
||||||
this.sharedLinksApi.findSharedLinks(options).then((page: NodePaging) => {
|
this.apiService.sharedLinksApi.findSharedLinks(options).then((page: NodePaging) => {
|
||||||
this.onPageLoaded(page);
|
this.onPageLoaded(page);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -518,7 +494,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
skipCount: this.skipCount
|
skipCount: this.skipCount
|
||||||
};
|
};
|
||||||
|
|
||||||
this.sitesApi.getSites(options).then((page: NodePaging) => {
|
this.apiService.sitesApi.getSites(options).then((page: NodePaging) => {
|
||||||
this.onPageLoaded(page);
|
this.onPageLoaded(page);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -531,7 +507,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
include: [ 'properties', 'allowableOperations', 'path' ]
|
include: [ 'properties', 'allowableOperations', 'path' ]
|
||||||
};
|
};
|
||||||
|
|
||||||
this.favoritesApi.getFavorites('-me-', options).then((result: NodePaging) => {
|
this.apiService.favoritesApi.getFavorites('-me-', options).then((result: NodePaging) => {
|
||||||
let page: NodePaging = {
|
let page: NodePaging = {
|
||||||
list: {
|
list: {
|
||||||
entries: result.list.entries
|
entries: result.list.entries
|
||||||
@@ -553,7 +529,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
}
|
}
|
||||||
|
|
||||||
private loadRecent(): void {
|
private loadRecent(): void {
|
||||||
this.peopleApi.getPerson('-me-').then((person: PersonEntry) => {
|
this.apiService.peopleApi.getPerson('-me-').then((person: PersonEntry) => {
|
||||||
const username = person.entry.id;
|
const username = person.entry.id;
|
||||||
const query = {
|
const query = {
|
||||||
query: {
|
query: {
|
||||||
@@ -577,7 +553,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.searchApi.search(query).then(page => this.onPageLoaded(page));
|
this.apiService.searchApi.search(query).then(page => this.onPageLoaded(page));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -733,6 +709,12 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
this.reload();
|
this.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onChangePageNumber(page: Pagination): void {
|
||||||
|
this.pageSize = page.maxItems;
|
||||||
|
this.skipCount = page.skipCount;
|
||||||
|
this.reload();
|
||||||
|
}
|
||||||
|
|
||||||
onNextPage(event: Pagination): void {
|
onNextPage(event: Pagination): void {
|
||||||
this.skipCount = event.skipCount;
|
this.skipCount = event.skipCount;
|
||||||
this.reload();
|
this.reload();
|
||||||
|
Reference in New Issue
Block a user