mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-968] Added Site Dropdown component to document list (#2093)
* [ADF-968] added demo project and new component * [ADF-968] added default option choice * [ADF-968] - moved site dropdown into documentlist * [ADF-968] fixed test for new component * [ADF-968] removed fdescribe for single cases * [ADF-968] fixed test to check rendering * [ADF-968] added conversion to Boolean forced by alfresco-js-api * [ADF-968]- moved site service into core * [ADF-968] reflected changes on js-api index * [ADF-968] fixed wrongly merged path from rebase * [ADF-968] fixed wrongly merged path from rebase * [ADF-968] fixed import problem on demo shell demo * [ADF-968] revert changes on package.json * [ADF-968] removed wrong package-lock * [ADF-968] applied changes from PR * [ADF-968] reindented file html
This commit is contained in:
@@ -120,6 +120,7 @@ export * from './src/models/card-view-textitem.model';
|
||||
export * from './src/models/card-view-dateitem.model';
|
||||
export * from './src/models/file.model';
|
||||
export * from './src/models/permissions.enum';
|
||||
export * from './src/models/site.model';
|
||||
|
||||
export * from './src/models/index';
|
||||
|
||||
|
87
ng2-components/ng2-alfresco-core/src/models/site.model.ts
Normal file
87
ng2-components/ng2-alfresco-core/src/models/site.model.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export class SiteModel {
|
||||
role: string;
|
||||
visibility: string;
|
||||
guid: string;
|
||||
description: string;
|
||||
id: string;
|
||||
preset: string;
|
||||
title: string;
|
||||
contents: SiteContentsModel[] = [];
|
||||
members: SiteMembersModel[] = [];
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj && obj.entry) {
|
||||
this.role = obj.entry.role || null;
|
||||
this.visibility = obj.entry.visibility || null;
|
||||
this.guid = obj.entry.guid || null;
|
||||
this.description = obj.entry.description || null;
|
||||
this.id = obj.entry.id || null;
|
||||
this.preset = obj.entry.preset;
|
||||
this.title = obj.entry.title;
|
||||
|
||||
if (obj.relations && obj.relations.containers) {
|
||||
obj.relations.containers.list.entries.forEach((content) => {
|
||||
this.contents.push(new SiteContentsModel(content.entry));
|
||||
});
|
||||
}
|
||||
|
||||
if (obj.relations && obj.relations.members) {
|
||||
obj.relations.members.list.entries.forEach((member) => {
|
||||
this.members.push(new SiteMembersModel(member.entry));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class SiteContentsModel {
|
||||
id: string;
|
||||
folderId: string;
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj) {
|
||||
this.id = obj.id || null;
|
||||
this.folderId = obj.folderId || null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class SiteMembersModel {
|
||||
role: string;
|
||||
firstName: string;
|
||||
emailNotificationsEnabled: boolean = false;
|
||||
company: any;
|
||||
id: string;
|
||||
enable: boolean = false;
|
||||
email: string;
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj) {
|
||||
this.role = obj.role;
|
||||
this.firstName = obj.firstName || null;
|
||||
this.emailNotificationsEnabled = obj.emailNotificationsEnabled;
|
||||
this.company = obj.company || null;
|
||||
this.id = obj.id || null;
|
||||
this.enable = obj.enable;
|
||||
this.email = obj.email;
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,157 +15,141 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, inject, TestBed } from '@angular/core/testing';
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AlfrescoSettingsService } from './alfresco-settings.service';
|
||||
import { AppConfigModule } from './app-config.service';
|
||||
import { NodesApiService } from './nodes-api.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { SitesApiService } from './sites-api.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { UserPreferencesService } from './user-preferences.service';
|
||||
|
||||
class TestConfig {
|
||||
service: any = null;
|
||||
setup: any = {
|
||||
rejectGetSites: false
|
||||
};
|
||||
declare let jasmine: any;
|
||||
|
||||
constructor(setup: any = {}) {
|
||||
Object.assign(this.setup, setup);
|
||||
describe('Sites service', () => {
|
||||
|
||||
const { alfrescoApiServiceMock } = this;
|
||||
|
||||
const alfrescoApiServiceProvider = {
|
||||
provide: AlfrescoApiService,
|
||||
useValue: alfrescoApiServiceMock
|
||||
};
|
||||
let service;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppConfigModule.forRoot('app.config.json', {
|
||||
pagination: {
|
||||
size: 20
|
||||
ecmHost: 'http://localhost:9876/ecm',
|
||||
files: {
|
||||
excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git']
|
||||
}
|
||||
})
|
||||
],
|
||||
providers: [
|
||||
alfrescoApiServiceProvider,
|
||||
SitesApiService,
|
||||
NodesApiService,
|
||||
AlfrescoApiService,
|
||||
UserPreferencesService,
|
||||
AuthenticationService,
|
||||
AlfrescoSettingsService,
|
||||
StorageService
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.get(SitesApiService);
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('Should get a list of users sites', (done) => {
|
||||
service.getSites().subscribe((data) => {
|
||||
expect(data[0].title).toBe('FAKE');
|
||||
done();
|
||||
});
|
||||
|
||||
inject([ SitesApiService ], (service: SitesApiService) => {
|
||||
this.service = service;
|
||||
})();
|
||||
}
|
||||
|
||||
private get alfrescoApiServiceMock(): any {
|
||||
const { setup } = this;
|
||||
|
||||
const nodePagingSample = {
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: {} },
|
||||
{ entry: {} }
|
||||
],
|
||||
pagination: {}
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'json',
|
||||
responseText: {
|
||||
'list': {
|
||||
'pagination': {
|
||||
'count': 1,
|
||||
'hasMoreItems': false,
|
||||
'totalItems': 1,
|
||||
'skipCount': 0,
|
||||
'maxItems': 100
|
||||
},
|
||||
'entries': [
|
||||
{
|
||||
'entry': {
|
||||
'role': 'SiteManager',
|
||||
'visibility': 'PUBLIC',
|
||||
'guid': 'b4cff62a-664d-4d45-9302-98723eac1319',
|
||||
'description': 'This is a Sample Alfresco Team site.',
|
||||
'id': 'swsdp',
|
||||
'title': 'FAKE'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const sitesApiMock = {
|
||||
getSites: jasmine.createSpy('getSites').and.callFake(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setup.rejectGetSites
|
||||
? reject()
|
||||
: resolve(nodePagingSample);
|
||||
});
|
||||
})
|
||||
};
|
||||
it('Should get single sites via siteId', (done) => {
|
||||
service.getSite('fake-site-id').subscribe((data) => {
|
||||
expect(data.title).toBe('FAKE-SINGLE-TITLE');
|
||||
done();
|
||||
});
|
||||
|
||||
return {
|
||||
getInstance: () => {
|
||||
return {
|
||||
core: { sitesApi: sitesApiMock }
|
||||
};
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'json',
|
||||
responseText: {
|
||||
'entry': {
|
||||
'role': 'SiteManager',
|
||||
'visibility': 'PUBLIC',
|
||||
'guid': 'b4cff62a-664d-4d45-9302-98723eac1319',
|
||||
'description': 'This is a Sample Alfresco Team site.',
|
||||
'id': 'swsdp',
|
||||
'preset': 'site-dashboard',
|
||||
'title': 'FAKE-SINGLE-TITLE'
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
get getSitesSpy(): any {
|
||||
return this.service.sitesApi.getSites;
|
||||
}
|
||||
|
||||
get getSitesArgs(): any[] {
|
||||
return this.getSitesSpy.calls.mostRecent().args;
|
||||
}
|
||||
}
|
||||
|
||||
describe('Sites API', () => {
|
||||
describe('getSites', () => {
|
||||
describe('Provide a NodePaging', () => {
|
||||
beforeEach(() => {
|
||||
this.config = new TestConfig();
|
||||
});
|
||||
|
||||
it('provides a node paging with entries', async(() => {
|
||||
this.config.service.getSites().subscribe((paging) => {
|
||||
const { list: { entries, pagination } } = paging;
|
||||
|
||||
expect(entries).toEqual(jasmine.any(Array));
|
||||
expect(pagination).toEqual(jasmine.any(Object));
|
||||
expect(entries.length).toBe(2);
|
||||
});
|
||||
}));
|
||||
it('deleteSite should perform a call against the server', (done) => {
|
||||
service.deleteSite('fake-site-id').subscribe(() => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().method).toBe('DELETE');
|
||||
expect(jasmine.Ajax.requests.mostRecent().url)
|
||||
.toContain('alfresco/api/-default-/public/alfresco/versions/1/sites/fake-site-id');
|
||||
done();
|
||||
});
|
||||
|
||||
describe('Manage query options', () => {
|
||||
beforeEach(() => {
|
||||
this.config = new TestConfig();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 204
|
||||
});
|
||||
});
|
||||
|
||||
this.getCalledArgs = () => {
|
||||
return this.config.getSitesArgs;
|
||||
};
|
||||
});
|
||||
|
||||
it('has default options', async(() => {
|
||||
this.config.service.getSites();
|
||||
|
||||
const [ { maxItems, skipCount } ] = this.getCalledArgs();
|
||||
|
||||
expect(maxItems).toBe(20);
|
||||
expect(skipCount).toBe(0);
|
||||
}));
|
||||
|
||||
it('combines custom and default options', async(() => {
|
||||
this.config.service.getSites({
|
||||
maxItems: 5
|
||||
});
|
||||
|
||||
const [ { maxItems, skipCount } ] = this.getCalledArgs();
|
||||
|
||||
expect(maxItems).toBe(5);
|
||||
expect(skipCount).toBe(0);
|
||||
}));
|
||||
it('getSites catch errors call', (done) => {
|
||||
service.getSites().subscribe(() => {
|
||||
}, () => {
|
||||
done();
|
||||
});
|
||||
|
||||
describe('Error handling', () => {
|
||||
beforeEach(() => {
|
||||
const config = new TestConfig({
|
||||
rejectGetSites: true
|
||||
});
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 403
|
||||
});
|
||||
});
|
||||
|
||||
this.service = config.service;
|
||||
this.spy = spyOn(config.service, 'handleError')
|
||||
.and.callThrough();
|
||||
});
|
||||
it('getSite catch errors call', (done) => {
|
||||
service.getSite('error-id').subscribe(() => {
|
||||
}, () => {
|
||||
done();
|
||||
});
|
||||
|
||||
it('handles error on failure', async(() => {
|
||||
this.service.getSites().subscribe(() => {
|
||||
expect(this.spy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 403
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MinimalNodeEntryEntity, NodePaging } from 'alfresco-js-api';
|
||||
import { Response } from '@angular/http';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { SiteModel } from '../models/site.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { NodesApiService } from './nodes-api.service';
|
||||
import { UserPreferencesService } from './user-preferences.service';
|
||||
|
||||
@Injectable()
|
||||
@@ -27,36 +27,54 @@ export class SitesApiService {
|
||||
|
||||
constructor(
|
||||
private apiService: AlfrescoApiService,
|
||||
private nodesApi: NodesApiService,
|
||||
private preferences: UserPreferencesService) {}
|
||||
private preferences: UserPreferencesService) { }
|
||||
|
||||
private get sitesApi() {
|
||||
return this.apiService.getInstance().core.sitesApi;
|
||||
}
|
||||
|
||||
getSites(options: any = {}): Observable<NodePaging> {
|
||||
const { sitesApi, handleError } = this;
|
||||
getSites(opts: any = {}): any {
|
||||
const defaultOptions = {
|
||||
maxItems: this.preferences.paginationSize,
|
||||
skipCount: 0,
|
||||
include: [ 'properties' ]
|
||||
include: ['properties']
|
||||
};
|
||||
const queryOptions = Object.assign({}, defaultOptions, options);
|
||||
const promise = sitesApi.getSites(queryOptions);
|
||||
|
||||
return Observable
|
||||
.fromPromise(promise)
|
||||
.catch(handleError);
|
||||
const queryOptions = Object.assign({}, defaultOptions, opts);
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.sitesApi.getSites(queryOptions))
|
||||
.map((res: any) => res.list.entries)
|
||||
.map((objList) => this.convertToModel(objList))
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getSiteDocumentLibrary(siteId: string): Observable<MinimalNodeEntryEntity> {
|
||||
const { nodesApi } = this;
|
||||
|
||||
return nodesApi
|
||||
.getNode(siteId, { relativePath: '/documentLibrary' });
|
||||
getSite(siteId: string, opts?: any): any {
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.sitesApi.getSite(siteId, opts))
|
||||
.map((res: any) => new SiteModel(res))
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
private handleError(error: any): Observable<any> {
|
||||
return Observable.of(error);
|
||||
deleteSite(siteId: string, permanentFlag: boolean = true): any {
|
||||
let options: any = {};
|
||||
options.permanent = permanentFlag;
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.sitesApi.deleteSite(siteId, options)
|
||||
.catch(this.handleError));
|
||||
}
|
||||
|
||||
getSiteContent(siteId: string): Observable<any> {
|
||||
return this.getSite(siteId, { relations: ['containers'] });
|
||||
}
|
||||
|
||||
getSiteMembers(siteId: string): Observable<any> {
|
||||
return this.getSite(siteId, { relations: ['members'] });
|
||||
}
|
||||
|
||||
private handleError(error: Response): any {
|
||||
console.error(error);
|
||||
return Observable.throw(error || 'Server error');
|
||||
}
|
||||
|
||||
private convertToModel(objList: any[]) {
|
||||
let convertedList: SiteModel[] = [];
|
||||
if (objList && objList.length > 0) {
|
||||
objList.forEach((element: any) => {
|
||||
convertedList.push(new SiteModel(element));
|
||||
});
|
||||
}
|
||||
return convertedList;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user