mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +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
@@ -17,25 +17,24 @@
|
||||
|
||||
import { ModuleWithProviders, NgModule } from '@angular/core';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { CoreModule } from 'ng2-alfresco-core';
|
||||
import { CoreModule, SearchService } from 'ng2-alfresco-core';
|
||||
import { DocumentListModule } from 'ng2-alfresco-documentlist';
|
||||
import { SearchAutocompleteComponent } from './src/components/search-autocomplete.component';
|
||||
import { SearchControlComponent } from './src/components/search-control.component';
|
||||
import { SearchComponent } from './src/components/search.component';
|
||||
import { SearchService } from './src/services/search.service';
|
||||
|
||||
// services
|
||||
export * from './src/services/search.service';
|
||||
export { SearchOptions, SearchService } from 'ng2-alfresco-core';
|
||||
export * from './src/components/search.component';
|
||||
export * from './src/components/search-control.component';
|
||||
export * from './src/components/search-autocomplete.component';
|
||||
|
||||
// Old Deprecated export
|
||||
import { SearchService as AlfrescoSearchService } from 'ng2-alfresco-core';
|
||||
import { SearchAutocompleteComponent as AlfrescoSearchAutocompleteComponent } from './src/components/search-autocomplete.component';
|
||||
import { SearchControlComponent as AlfrescoSearchControlComponent } from './src/components/search-control.component';
|
||||
import { SearchComponent as AlfrescoSearchComponent } from './src/components/search.component';
|
||||
import { SearchService as AlfrescoSearchService } from './src/services/search.service';
|
||||
export { SearchService as AlfrescoSearchService } from './src/services/search.service';
|
||||
export { SearchService as AlfrescoSearchService } from 'ng2-alfresco-core';
|
||||
export { SearchComponent as AlfrescoSearchComponent } from './src/components/search.component';
|
||||
export { SearchControlComponent as AlfrescoSearchControlComponent } from './src/components/search-control.component';
|
||||
export { SearchAutocompleteComponent as AlfrescoSearchAutocompleteComponent } from './src/components/search-autocomplete.component';
|
||||
|
@@ -23,9 +23,9 @@ import {
|
||||
AlfrescoContentService,
|
||||
AlfrescoSettingsService,
|
||||
AlfrescoTranslationService,
|
||||
CoreModule
|
||||
CoreModule,
|
||||
SearchService
|
||||
} from 'ng2-alfresco-core';
|
||||
import { SearchService } from '../services/search.service';
|
||||
import { errorJson, folderResult, noResult, result, results } from './../assets/search.component.mock';
|
||||
import { TranslationMock } from './../assets/translation.service.mock';
|
||||
import { SearchAutocompleteComponent } from './search-autocomplete.component';
|
||||
|
@@ -17,9 +17,8 @@
|
||||
|
||||
import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild } from '@angular/core';
|
||||
import { MinimalNodeEntity } from 'alfresco-js-api';
|
||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, SearchOptions, SearchService } from 'ng2-alfresco-core';
|
||||
import { ThumbnailService } from 'ng2-alfresco-core';
|
||||
import { SearchOptions, SearchService } from './../services/search.service';
|
||||
|
||||
declare var require: any;
|
||||
|
||||
|
@@ -17,8 +17,7 @@
|
||||
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ThumbnailService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
|
||||
import { SearchService } from '../services/search.service';
|
||||
import { AlfrescoTranslationService, CoreModule, SearchService } from 'ng2-alfresco-core';
|
||||
import { result } from './../assets/search.component.mock';
|
||||
import { TranslationMock } from './../assets/translation.service.mock';
|
||||
import { SearchAutocompleteComponent } from './search-autocomplete.component';
|
||||
|
@@ -18,11 +18,10 @@
|
||||
import { DebugElement, ReflectiveInjector, SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { AlfrescoTranslationService, CoreModule, NotificationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, CoreModule, NotificationService, SearchService } from 'ng2-alfresco-core';
|
||||
import { DocumentListModule } from 'ng2-alfresco-documentlist';
|
||||
import { PermissionModel } from 'ng2-alfresco-documentlist';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { SearchService } from '../services/search.service';
|
||||
import { TranslationMock } from './../assets/translation.service.mock';
|
||||
import { SearchComponent } from './search.component';
|
||||
|
||||
@@ -242,7 +241,7 @@ describe('SearchComponent', () => {
|
||||
fixture.detectChanges();
|
||||
let errorEl = element.querySelector('[data-automation-id="search_error_message"]');
|
||||
expect(errorEl).not.toBeNull();
|
||||
expect((<any>errorEl).innerText).toBe('SEARCH.RESULTS.ERROR');
|
||||
expect((<any> errorEl).innerText).toBe('SEARCH.RESULTS.ERROR');
|
||||
done();
|
||||
});
|
||||
|
||||
|
@@ -18,9 +18,8 @@
|
||||
import { Component, EventEmitter, Input, OnChanges, OnInit, Optional, Output, SimpleChanges } from '@angular/core';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
import { NodePaging, Pagination } from 'alfresco-js-api';
|
||||
import { AlfrescoTranslationService, NotificationService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoTranslationService, NotificationService, SearchOptions, SearchService } from 'ng2-alfresco-core';
|
||||
import { PermissionModel } from 'ng2-alfresco-documentlist';
|
||||
import { SearchOptions, SearchService } from './../services/search.service';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-search, alfresco-search',
|
||||
|
@@ -1,107 +0,0 @@
|
||||
/*!
|
||||
* @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 { AlfrescoApiService, CoreModule } from 'ng2-alfresco-core';
|
||||
import { fakeApi, fakeError, fakeSearch } from '../assets/search.service.mock';
|
||||
import { SearchService } from './search.service';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
describe('SearchService', () => {
|
||||
|
||||
let service: SearchService;
|
||||
let apiService: AlfrescoApiService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule
|
||||
],
|
||||
providers: [
|
||||
SearchService
|
||||
]
|
||||
}).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();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
@@ -1,63 +0,0 @@
|
||||
/*!
|
||||
* @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 { AlfrescoApiService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
|
||||
/**
|
||||
* Internal service used by Document List component.
|
||||
*/
|
||||
@Injectable()
|
||||
export class SearchService {
|
||||
|
||||
constructor(public authService: AlfrescoAuthenticationService,
|
||||
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