mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1041] Node picker, first iteration (#2122)
* First try * Dialog basic functionality * Search input * Hammering it together * Fist working proto for copy * Fix the tests and tslint errors for a happier world * Add more tests (and test shells for the future) * copyNode and moveNode methods * Copy and move actions for content type * Extract common parts in favor of using them in folder content type also * Small fixes * Copy and Move actions for folders as well * Style fixes, ui behaviours and tests needed to be written * Move duplicated search service from documentlist to core * Use search service from core within the search component * Fix dialog width * Update docs * Tests for node selector * Change seletionMade event's name to select
This commit is contained in:
committed by
Eugenio Romano
parent
952da3ab99
commit
4fd8bfb875
@@ -85,6 +85,7 @@ export { UpdateNotification } from './src/services/card-view-update.service';
|
||||
export { ClickNotification } from './src/services/card-view-update.service';
|
||||
export { AppConfigModule } from './src/services/app-config.service';
|
||||
export { UserPreferencesService } from './src/services/user-preferences.service';
|
||||
import { SearchService } from './src/services/search.service';
|
||||
|
||||
export { DeletedNodesApiService } from './src/services/deleted-nodes-api.service';
|
||||
export { FavoritesApiService } from './src/services/favorites-api.service';
|
||||
|
@@ -0,0 +1,63 @@
|
||||
/*!
|
||||
* @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 let fakeSearch = {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 1,
|
||||
hasMoreItems: false,
|
||||
totalItems: 1,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: '123',
|
||||
name: 'MyDoc',
|
||||
content: {
|
||||
mimetype: 'text/plain'
|
||||
},
|
||||
createdByUser: {
|
||||
displayName: 'John Doe'
|
||||
},
|
||||
modifiedByUser: {
|
||||
displayName: 'John Doe'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
export let fakeError = {
|
||||
error: {
|
||||
errorKey: 'Search failed',
|
||||
statusCode: 400,
|
||||
briefSummary: '08220082 search failed',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
};
|
||||
|
||||
export let fakeApi = {
|
||||
core: {
|
||||
queriesApi: {
|
||||
findNodes: (term, opts) => Promise.resolve(fakeSearch)
|
||||
}
|
||||
}
|
||||
};
|
@@ -0,0 +1,123 @@
|
||||
/*!
|
||||
* @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 { async, TestBed } from '@angular/core/testing';
|
||||
import { fakeApi, fakeError, fakeSearch } from '../assets/search.service.mock';
|
||||
import { CookieServiceMock } from './../assets/cookie.service.mock';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AlfrescoSettingsService } from './alfresco-settings.service';
|
||||
import { AppConfigModule } from './app-config.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { CookieService } from './cookie.service';
|
||||
import { LogService } from './log.service';
|
||||
import { SearchService } from './search.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { UserPreferencesService } from './user-preferences.service';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
describe('SearchService', () => {
|
||||
|
||||
let service: SearchService;
|
||||
let apiService: AlfrescoApiService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppConfigModule
|
||||
],
|
||||
providers: [
|
||||
SearchService,
|
||||
AuthenticationService,
|
||||
AlfrescoApiService,
|
||||
AlfrescoSettingsService,
|
||||
AuthenticationService,
|
||||
StorageService,
|
||||
UserPreferencesService,
|
||||
{ provide: CookieService, useClass: CookieServiceMock },
|
||||
LogService
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.get(SearchService);
|
||||
apiService = TestBed.get(AlfrescoApiService);
|
||||
spyOn(apiService, 'getInstance').and.returnValue(fakeApi);
|
||||
});
|
||||
|
||||
it('should call search API with no additional options', (done) => {
|
||||
let searchTerm = 'searchTerm63688';
|
||||
spyOn(fakeApi.core.queriesApi, 'findNodes').and.returnValue(Promise.resolve(fakeSearch));
|
||||
service.getNodeQueryResults(searchTerm).subscribe(
|
||||
() => {
|
||||
expect(fakeApi.core.queriesApi.findNodes).toHaveBeenCalledWith(searchTerm, undefined);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should call search API with additional options', (done) => {
|
||||
let searchTerm = 'searchTerm63688', options = {
|
||||
include: [ 'path' ],
|
||||
rootNodeId: '-root-',
|
||||
nodeType: 'cm:content'
|
||||
};
|
||||
spyOn(fakeApi.core.queriesApi, 'findNodes').and.returnValue(Promise.resolve(fakeSearch));
|
||||
service.getNodeQueryResults(searchTerm, options).subscribe(
|
||||
() => {
|
||||
expect(fakeApi.core.queriesApi.findNodes).toHaveBeenCalledWith(searchTerm, options);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return search results returned from the API', (done) => {
|
||||
service.getNodeQueryResults('').subscribe(
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toEqual(fakeSearch);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should notify errors returned from the API', (done) => {
|
||||
spyOn(fakeApi.core.queriesApi, 'findNodes').and.returnValue(Promise.reject(fakeError));
|
||||
service.getNodeQueryResults('').subscribe(
|
||||
() => {},
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toEqual(fakeError);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should notify a general error if the API does not return a specific error', (done) => {
|
||||
spyOn(fakeApi.core.queriesApi, 'findNodes').and.returnValue(Promise.reject(null));
|
||||
service.getNodeQueryResults('').subscribe(
|
||||
() => {},
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toEqual('Server error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,64 @@
|
||||
/*!
|
||||
* @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 { Injectable } from '@angular/core';
|
||||
import { NodePaging } from 'alfresco-js-api';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
|
||||
/**
|
||||
* Internal service used by Document List component.
|
||||
*/
|
||||
@Injectable()
|
||||
export class SearchService {
|
||||
|
||||
constructor(public authService: AuthenticationService,
|
||||
private apiService: AlfrescoApiService) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a search against the repository
|
||||
*
|
||||
* @param term Search term
|
||||
* @param options Additional options passed to the search
|
||||
* @returns {Observable<NodePaging>} Search results
|
||||
*/
|
||||
getNodeQueryResults(term: string, options?: SearchOptions): Observable<NodePaging> {
|
||||
return Observable.fromPromise(this.getQueryNodesPromise(term, options))
|
||||
.map(res => <NodePaging> res)
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
getQueryNodesPromise(term: string, opts: SearchOptions): Promise<NodePaging> {
|
||||
return this.apiService.getInstance().core.queriesApi.findNodes(term, opts);
|
||||
}
|
||||
|
||||
private handleError(error: any): Observable<any> {
|
||||
return Observable.throw(error || 'Server error');
|
||||
}
|
||||
}
|
||||
|
||||
export interface SearchOptions {
|
||||
skipCount?: number;
|
||||
maxItems?: number;
|
||||
rootNodeId?: string;
|
||||
nodeType?: string;
|
||||
include?: string[];
|
||||
orderBy?: string;
|
||||
fields?: string[];
|
||||
}
|
Reference in New Issue
Block a user