Upgrade ng2-alfresco-search

This commit is contained in:
Denys Vuika
2016-09-21 12:46:57 +01:00
parent 3fcc84cd02
commit 90646ce910
13 changed files with 81 additions and 54 deletions

View File

@@ -18,6 +18,8 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import { SearchModule } from 'ng2-alfresco-search';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { routing } from './app.routes'; import { routing } from './app.routes';
@@ -38,7 +40,8 @@ import { WEBSCRIPTCOMPONENT } from 'ng2-alfresco-webscript';
@NgModule({ @NgModule({
imports: [ imports: [
BrowserModule, BrowserModule,
routing routing,
SearchModule.forRoot()
], ],
declarations: [ declarations: [
AppComponent, AppComponent,

View File

@@ -15,10 +15,15 @@
* limitations under the License. * limitations under the License.
*/ */
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ALFRESCO_CORE_PROVIDERS } from 'ng2-alfresco-core';
import { AlfrescoSearchService } from './src/services/alfresco-search.service'; import { AlfrescoSearchService } from './src/services/alfresco-search.service';
import { AlfrescoThumbnailService } from './src/services/alfresco-thumbnail.service'; import { AlfrescoThumbnailService } from './src/services/alfresco-thumbnail.service';
import { AlfrescoSearchComponent } from './src/components/alfresco-search.component'; import { AlfrescoSearchComponent } from './src/components/alfresco-search.component';
import { AlfrescoSearchControlComponent } from './src/components/alfresco-search-control.component'; import { AlfrescoSearchControlComponent } from './src/components/alfresco-search-control.component';
import { AlfrescoSearchAutocompleteComponent } from './src/components/alfresco-search-autocomplete.component';
// services // services
export * from './src/services/alfresco-search.service'; export * from './src/services/alfresco-search.service';
@@ -26,23 +31,39 @@ export * from './src/services/alfresco-thumbnail.service';
export * from './src/components/alfresco-search.component'; export * from './src/components/alfresco-search.component';
export * from './src/components/alfresco-search-control.component'; export * from './src/components/alfresco-search-control.component';
export default {
directives: [
AlfrescoSearchComponent,
AlfrescoSearchControlComponent
],
providers: [
AlfrescoSearchService,
AlfrescoThumbnailService
]
};
export const ALFRESCO_SEARCH_DIRECTIVES: [any] = [ export const ALFRESCO_SEARCH_DIRECTIVES: [any] = [
AlfrescoSearchComponent, AlfrescoSearchComponent,
AlfrescoSearchControlComponent AlfrescoSearchControlComponent,
AlfrescoSearchAutocompleteComponent
]; ];
export const ALFRESCO_SEARCH_PROVIDERS: [any] = [ export const ALFRESCO_SEARCH_PROVIDERS: [any] = [
AlfrescoSearchService, AlfrescoSearchService,
AlfrescoThumbnailService AlfrescoThumbnailService
]; ];
@NgModule({
imports: [
CommonModule
],
declarations: [
...ALFRESCO_SEARCH_DIRECTIVES
],
providers: [
...ALFRESCO_CORE_PROVIDERS,
...ALFRESCO_SEARCH_PROVIDERS
],
exports: [
...ALFRESCO_SEARCH_DIRECTIVES
]
})
export class SearchModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: SearchModule,
providers: [
...ALFRESCO_SEARCH_PROVIDERS
]
};
}
}

View File

@@ -52,22 +52,22 @@
"alfresco" "alfresco"
], ],
"dependencies": { "dependencies": {
"@angular/common": "2.0.0-rc.3", "@angular/common": "2.0.0",
"@angular/compiler": "2.0.0-rc.3", "@angular/compiler": "2.0.0",
"@angular/core": "2.0.0-rc.3", "@angular/core": "2.0.0",
"@angular/forms": "0.1.1", "@angular/forms": "2.0.0",
"@angular/http": "2.0.0-rc.3", "@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0-rc.3", "@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0-rc.3", "@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0-alpha.7", "@angular/router": "3.0.0",
"@angular/router-deprecated": "2.0.0-rc.2", "@angular/upgrade": "2.0.0",
"@angular/upgrade": "2.0.0-rc.3", "core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.27", "systemjs": "0.19.27",
"core-js": "2.4.0", "zone.js": "^0.6.23",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6", "ng2-translate": "2.5.0",
"zone.js": "0.6.12",
"ng2-translate": "2.2.2",
"alfresco-js-api": "^0.3.0", "alfresco-js-api": "^0.3.0",
"ng2-alfresco-core": "0.3.2" "ng2-alfresco-core": "0.3.2"
}, },

View File

@@ -15,6 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/*
import { it, describe, expect, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing'; import { it, describe, expect, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing';
import { PLATFORM_PIPES } from '@angular/core'; import { PLATFORM_PIPES } from '@angular/core';
import { TestComponentBuilder } from '@angular/compiler/testing'; import { TestComponentBuilder } from '@angular/compiler/testing';
@@ -188,3 +189,4 @@ describe('AlfrescoSearchAutocompleteComponent', () => {
}); });
}); });
*/

View File

@@ -26,8 +26,7 @@ declare let __moduleName: string;
moduleId: __moduleName, moduleId: __moduleName,
selector: 'alfresco-search-autocomplete', selector: 'alfresco-search-autocomplete',
templateUrl: './alfresco-search-autocomplete.component.html', templateUrl: './alfresco-search-autocomplete.component.html',
styleUrls: ['./alfresco-search-autocomplete.component.css'], styleUrls: ['./alfresco-search-autocomplete.component.css']
providers: [AlfrescoSearchService]
}) })
export class AlfrescoSearchAutocompleteComponent implements OnChanges { export class AlfrescoSearchAutocompleteComponent implements OnChanges {

View File

@@ -15,6 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/*
import { provide, PLATFORM_PIPES } from '@angular/core'; import { provide, PLATFORM_PIPES } from '@angular/core';
import { it, describe, expect, inject, beforeEachProviders, beforeEach } from '@angular/core/testing'; import { it, describe, expect, inject, beforeEachProviders, beforeEach } from '@angular/core/testing';
import { TestComponentBuilder } from '@angular/compiler/testing'; import { TestComponentBuilder } from '@angular/compiler/testing';
@@ -118,3 +119,4 @@ describe('AlfrescoSearchControlComponent', () => {
}); });
}); });
}); });
*/

View File

@@ -15,10 +15,9 @@
* limitations under the License. * limitations under the License.
*/ */
import { Control, Validators } from '@angular/common'; import { FormControl, Validators } from '@angular/forms';
import { Component, Input, Output, ElementRef, EventEmitter, ViewChild } from '@angular/core'; import { Component, Input, Output, ElementRef, EventEmitter, ViewChild } from '@angular/core';
import { AlfrescoTranslationService } from 'ng2-alfresco-core'; import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { AlfrescoSearchAutocompleteComponent } from './alfresco-search-autocomplete.component';
import { SearchTermValidator } from './../forms/search-term-validator'; import { SearchTermValidator } from './../forms/search-term-validator';
declare let __moduleName: string; declare let __moduleName: string;
@@ -27,8 +26,7 @@ declare let __moduleName: string;
moduleId: __moduleName, moduleId: __moduleName,
selector: 'alfresco-search-control', selector: 'alfresco-search-control',
templateUrl: './alfresco-search-control.component.html', templateUrl: './alfresco-search-control.component.html',
styleUrls: ['./alfresco-search-control.component.css'], styleUrls: ['./alfresco-search-control.component.css']
directives: [AlfrescoSearchAutocompleteComponent]
}) })
export class AlfrescoSearchControlComponent { export class AlfrescoSearchControlComponent {
@@ -53,7 +51,7 @@ export class AlfrescoSearchControlComponent {
@Output() @Output()
expand = new EventEmitter(); expand = new EventEmitter();
searchControl: Control; searchControl: FormControl;
@ViewChild('searchInput', {}) searchInput: ElementRef; @ViewChild('searchInput', {}) searchInput: ElementRef;
@@ -66,7 +64,7 @@ export class AlfrescoSearchControlComponent {
constructor(private translate: AlfrescoTranslationService) { constructor(private translate: AlfrescoTranslationService) {
this.searchControl = new Control( this.searchControl = new FormControl(
this.searchTerm, this.searchTerm,
Validators.compose([Validators.required, SearchTermValidator.minAlphanumericChars(3)]) Validators.compose([Validators.required, SearchTermValidator.minAlphanumericChars(3)])
); );

View File

@@ -15,6 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
/*
import { PLATFORM_PIPES } from '@angular/core'; import { PLATFORM_PIPES } from '@angular/core';
import { it, describe, expect, inject, beforeEachProviders, beforeEach } from '@angular/core/testing'; import { it, describe, expect, inject, beforeEachProviders, beforeEach } from '@angular/core/testing';
import { TestComponentBuilder } from '@angular/compiler/testing'; import { TestComponentBuilder } from '@angular/compiler/testing';
@@ -190,3 +191,4 @@ describe('AlfrescoSearchComponent', () => {
}); });
}); });
*/

View File

@@ -15,8 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, EventEmitter, Input, Output, Optional, OnChanges, OnInit } from '@angular/core'; import { Component, EventEmitter, Input, Output, OnChanges, OnInit } from '@angular/core';
import { RouteParams } from '@angular/router-deprecated'; import { ActivatedRoute } from '@angular/router';
import { AlfrescoSearchService } from './../services/alfresco-search.service'; import { AlfrescoSearchService } from './../services/alfresco-search.service';
import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service'; import { AlfrescoThumbnailService } from './../services/alfresco-thumbnail.service';
import { AlfrescoTranslationService } from 'ng2-alfresco-core'; import { AlfrescoTranslationService } from 'ng2-alfresco-core';
@@ -27,8 +27,7 @@ declare let __moduleName: string;
moduleId: __moduleName, moduleId: __moduleName,
selector: 'alfresco-search', selector: 'alfresco-search',
styleUrls: ['./alfresco-search.component.css'], styleUrls: ['./alfresco-search.component.css'],
templateUrl: './alfresco-search.component.html', templateUrl: './alfresco-search.component.html'
providers: [AlfrescoSearchService]
}) })
export class AlfrescoSearchComponent implements OnChanges, OnInit { export class AlfrescoSearchComponent implements OnChanges, OnInit {
@@ -52,20 +51,20 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
constructor(private alfrescoSearchService: AlfrescoSearchService, constructor(private alfrescoSearchService: AlfrescoSearchService,
private translate: AlfrescoTranslationService, private translate: AlfrescoTranslationService,
private _alfrescoThumbnailService: AlfrescoThumbnailService, private _alfrescoThumbnailService: AlfrescoThumbnailService,
@Optional() params: RouteParams) { private activatedRoute: ActivatedRoute) {
if (translate !== null) { if (translate !== null) {
translate.addTranslationFolder('node_modules/ng2-alfresco-search/dist/src'); translate.addTranslationFolder('node_modules/ng2-alfresco-search/dist/src');
} }
this.results = null; this.results = null;
if (params) {
this.searchTerm = params.get('q');
}
} }
ngOnInit(): void { ngOnInit(): void {
this.displaySearchResults(this.searchTerm); this.activatedRoute.params.subscribe(params => {
this.searchTerm = params['q'];
this.displaySearchResults(this.searchTerm);
});
} }
ngOnChanges(changes): void { ngOnChanges(changes): void {

View File

@@ -15,29 +15,29 @@
* limitations under the License. * limitations under the License.
*/ */
import { Control } from '@angular/common'; import { FormControl } from '@angular/forms';
import { SearchTermValidator } from './search-term-validator'; import { SearchTermValidator } from './search-term-validator';
describe('Search term validator', () => { describe('Search term validator', () => {
it('should pass validation for a value with the specified required number of alphanumeric characters', () => { it('should pass validation for a value with the specified required number of alphanumeric characters', () => {
const control = new Control('ab', SearchTermValidator.minAlphanumericChars(2)); const control = new FormControl('ab', SearchTermValidator.minAlphanumericChars(2));
expect(control.valid).toBe(true); expect(control.valid).toBe(true);
}); });
it('should pass validation for a value with more than the specified required number of alphanumeric characters', () => { it('should pass validation for a value with more than the specified required number of alphanumeric characters', () => {
const control = new Control('abc', SearchTermValidator.minAlphanumericChars(2)); const control = new FormControl('abc', SearchTermValidator.minAlphanumericChars(2));
expect(control.valid).toBe(true); expect(control.valid).toBe(true);
}); });
it('should fail validation for a value with less than the specified required number of alphanumeric characters', () => { it('should fail validation for a value with less than the specified required number of alphanumeric characters', () => {
const control = new Control('a', SearchTermValidator.minAlphanumericChars(2)); const control = new FormControl('a', SearchTermValidator.minAlphanumericChars(2));
expect(control.valid).toBe(false); expect(control.valid).toBe(false);
}); });
/* tslint:disable:max-line-length */ /* tslint:disable:max-line-length */
it('should fail validation for a value with less than the specified required number of alphanumeric characters but with other non-alphanumeric characters', () => { it('should fail validation for a value with less than the specified required number of alphanumeric characters but with other non-alphanumeric characters', () => {
const control = new Control('a ._-?b', SearchTermValidator.minAlphanumericChars(3)); const control = new FormControl('a ._-?b', SearchTermValidator.minAlphanumericChars(3));
expect(control.valid).toBe(false); expect(control.valid).toBe(false);
}); });

View File

@@ -15,12 +15,12 @@
* limitations under the License. * limitations under the License.
*/ */
import { Control } from '@angular/common'; import { FormControl } from '@angular/forms';
export class SearchTermValidator { export class SearchTermValidator {
static minAlphanumericChars(minChars: number) { static minAlphanumericChars(minChars: number) {
return (control: Control) => { return (control: FormControl) => {
return ('' + control.value).replace(/[^0-9a-zA-Z]+/g, '').length >= minChars ? null : { return ('' + control.value).replace(/[^0-9a-zA-Z]+/g, '').length >= minChars ? null : {
hasMinAlphanumericChars: false hasMinAlphanumericChars: false
}; };

View File

@@ -15,7 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { it, describe, beforeEach, inject, beforeEachProviders } from '@angular/core/testing'; /*
import { beforeEachProviders } from '@angular/core/testing';
import { AlfrescoSearchService } from './alfresco-search.service'; import { AlfrescoSearchService } from './alfresco-search.service';
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core'; import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core';
@@ -89,3 +90,4 @@ describe('AlfrescoSearchService', () => {
}); });
}); });
*/

View File

@@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
*/ */
import { describe, beforeEach } from '@angular/core/testing';
import { AlfrescoThumbnailService } from './alfresco-thumbnail.service'; import { AlfrescoThumbnailService } from './alfresco-thumbnail.service';
describe('AlfrescoThumbnailService', () => { describe('AlfrescoThumbnailService', () => {