update service and demo search

This commit is contained in:
Mario Romano
2016-06-02 17:15:14 +01:00
parent 754c5297b5
commit 675b28c237
2 changed files with 36 additions and 24 deletions

View File

@@ -35,15 +35,20 @@ import {
@Component({ @Component({
selector: 'alfresco-search-demo', selector: 'alfresco-search-demo',
template: ` template: `<label for="token"><b>Insert a valid access token / ticket:</b></label><br>
<div class="container" *ngIf="authenticated"> <input id="token" type="text" size="48" (change)="updateToken()" [(ngModel)]="token"><br>
<alfresco-search-control [searchTerm]="searchTerm" <label for="token"><b>Insert the ip of your Alfresco instance:</b></label><br>
(searchChange)="searchTermChange($event);"></alfresco-search-control> <input id="token" type="text" size="48" (change)="updateHost()" [(ngModel)]="host"><br><br>
<alfresco-search [searchTerm]="searchTerm"></alfresco-search> <div *ngIf="!authenticated" style="color:#FF2323">
</div> Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid token to perform
<div *ngIf="!authenticated"> operations.
Authentication failed to ip {{ host }} </div>
</div> <hr>
<div class="container" >
<alfresco-search-control [searchTerm]="searchTerm"
(searchChange)="searchTermChange($event);"></alfresco-search-control>
<alfresco-search [searchTerm]="searchTerm"></alfresco-search>
</div>
`, `,
styles: [':host > .container {padding: 10px}'], styles: [':host > .container {padding: 10px}'],
providers: [ALFRESCO_SEARCH_PROVIDERS], providers: [ALFRESCO_SEARCH_PROVIDERS],
@@ -56,18 +61,33 @@ class SearchDemo implements OnInit {
public searchTerm: string = 'test'; public searchTerm: string = 'test';
host: string = 'http://192.168.99.101:8080'; host: string = 'http://192.168.99.100:8080';
token: string;
constructor( constructor(
private authService: AlfrescoAuthenticationService, private authService: AlfrescoAuthenticationService,
settings: AlfrescoSettingsService, private alfrescoSettingsService: AlfrescoSettingsService,
translation: AlfrescoTranslationService, translation: AlfrescoTranslationService,
searchService: AlfrescoService) { searchService: AlfrescoService) {
settings.host = this.host; alfrescoSettingsService.host = this.host;
if (localStorage.getItem('token')) {
this.token = localStorage.getItem('token');
}
translation.translationInit(); translation.translationInit();
} }
public updateToken(): void {
localStorage.setItem('token', this.token);
}
public updateHost(): void {
this.alfrescoSettingsService.host = this.host;
this.login();
}
ngOnInit() { ngOnInit() {
this.login(); this.login();
} }

View File

@@ -29,26 +29,18 @@ declare let AlfrescoApi: any;
@Injectable() @Injectable()
export class AlfrescoService { export class AlfrescoService {
private _host: string = 'http://127.0.0.1:8080';
private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1'; private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1';
constructor(private http: Http, constructor(private http: Http,
private settings: AlfrescoSettingsService) { private settings: AlfrescoSettingsService) {
if (settings) {
this._host = settings.host;
}
} }
public get host(): string { public getHost(): string {
return this._host; return this.settings.host;
}
public set host(value: string) {
this._host = value;
} }
private getBaseUrl(): string { private getBaseUrl(): string {
return this.host + this._baseUrlPath; return this.getHost() + this._baseUrlPath;
} }
private getAlfrescoTicket() { private getAlfrescoTicket() {
@@ -106,7 +98,7 @@ export class AlfrescoService {
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getContentUrl(document: any) { getContentUrl(document: any) {
return this._host + return this.getHost() +
'/alfresco/service/api/node/workspace/SpacesStore/' + '/alfresco/service/api/node/workspace/SpacesStore/' +
document.entry.id + '/content'; document.entry.id + '/content';
} }