add config ip to login demo

This commit is contained in:
Mario Romano
2016-06-02 16:25:09 +01:00
parent 99bac064df
commit b173e7c1ee
2 changed files with 59 additions and 47 deletions

View File

@@ -30,26 +30,38 @@ import { ALFRESCO_CORE_PROVIDERS, AlfrescoTranslationService, AlfrescoTranslatio
]) ])
@Component({ @Component({
selector: 'my-app', selector: 'my-app',
template: '<alfresco-login method="POST" (onSuccess)="mySuccessMethod($event)" (onError)="myErrorMethod($event)"></alfresco-login>', template: `<label for="token"><b>Insert the ip of your Alfresco instance:</b></label><br>
<input id="token" type="text" size="48" (change)="updateHost()" [(ngModel)]="host"><br><br>
{{ status }}
<hr>
<alfresco-login method="POST" (onSuccess)="mySuccessMethod($event)" (onError)="myErrorMethod($event)"></alfresco-login>`,
directives: [ROUTER_DIRECTIVES, AlfrescoLoginComponent] directives: [ROUTER_DIRECTIVES, AlfrescoLoginComponent]
}) })
export class AppComponent { export class AppComponent {
constructor(public auth: AlfrescoAuthenticationService, public host: string = 'http://192.168.99.100:8080';
public router: Router,
alfrescoSettingsService: AlfrescoSettingsService) {
alfrescoSettingsService.host = 'http://192.168.99.100:8080';
public token: string;
public status: string = '';
constructor(public auth: AlfrescoAuthenticationService, public router: Router, private alfrescoSettingsService: AlfrescoSettingsService) {
alfrescoSettingsService.host = this.host;
}
public updateHost(): void {
this.alfrescoSettingsService.host = this.host;
} }
mySuccessMethod($event) { mySuccessMethod($event) {
console.log('Success Login EventEmitt called with: ' + $event.value); console.log('Success Login EventEmitt called with: ' + $event.value);
this.status = $event.value;
} }
myErrorMethod($event) { myErrorMethod($event) {
console.log('Error Login EventEmitt called with: ' + $event.value); console.log('Error Login EventEmitt called with: ' + $event.value);
this.status = $event.value;
} }
} }
bootstrap(AppComponent, [ bootstrap(AppComponent, [

View File

@@ -15,28 +15,28 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, OnInit } from 'angular2/core'; import { Component, OnInit } from 'angular2/core';
import { bootstrap } from 'angular2/platform/browser'; import { bootstrap } from 'angular2/platform/browser';
import { HTTP_PROVIDERS } from 'angular2/http'; import { HTTP_PROVIDERS } from 'angular2/http';
import { import {
ALFRESCO_CORE_PROVIDERS, ALFRESCO_CORE_PROVIDERS,
AlfrescoSettingsService, AlfrescoSettingsService,
AlfrescoAuthenticationService AlfrescoAuthenticationService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core'; } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { ALFRESCO_ULPOAD_COMPONENTS, UploadService } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload'; import { ALFRESCO_ULPOAD_COMPONENTS, UploadService } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
@Component({ @Component({
selector: 'my-app', selector: 'my-app',
template: `<label for="token"><b>Insert a valid access token / ticket:</b></label><br> template: `<label for="token"><b>Insert a valid access token / ticket:</b></label><br>
<input id="token" type="text" size="48" (change)="updateToken()" [(ngModel)]="token"><br> <input id="token" type="text" size="48" (change)="updateToken()" [(ngModel)]="token"><br>
<label for="token"><b>Insert the ip of your Alfresco instance:</b></label><br> <label for="token"><b>Insert the ip of your Alfresco instance:</b></label><br>
<input id="token" type="text" size="48" (change)="updateHost()" [(ngModel)]="host"><br><br> <input id="token" type="text" size="48" (change)="updateHost()" [(ngModel)]="host"><br><br>
<div *ngIf="!authenticated" style="color:#FF2323"> <div *ngIf="!authenticated" style="color:#FF2323">
Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid token to perform Authentication failed to ip {{ host }} with user: admin, admin, you can still try to add a valid token to perform
operations. operations.
</div> </div>
<hr> <hr>
<alfresco-upload-button [showUdoNotificationBar]="true" <alfresco-upload-button [showUdoNotificationBar]="true"
[uploadFolders]="false" [uploadFolders]="false"
[multipleFiles]="false" [multipleFiles]="false"
@@ -66,51 +66,51 @@ import { ALFRESCO_ULPOAD_COMPONENTS, UploadService } from 'ng2-alfresco-upload/d
DRAG HERE DRAG HERE
</div> </div>
</alfresco-upload-drag-area> </alfresco-upload-drag-area>
<file-uploading-dialog></file-uploading-dialog> <file-uploading-dialog></file-uploading-dialog>
`, `,
directives: [ALFRESCO_ULPOAD_COMPONENTS] directives: [ALFRESCO_ULPOAD_COMPONENTS]
}) })
export class MyDemoApp implements OnInit { export class MyDemoApp implements OnInit {
authenticated: boolean; authenticated: boolean;
host: string = 'http://192.168.99.101:8080'; host: string = 'http://192.168.99.100:8080';
token: string; token: string;
constructor(private authService: AlfrescoAuthenticationService, private alfrescoSettingsService: AlfrescoSettingsService) { constructor(private authService: AlfrescoAuthenticationService, private alfrescoSettingsService: AlfrescoSettingsService) {
alfrescoSettingsService.host = this.host; alfrescoSettingsService.host = this.host;
if (localStorage.getItem('token')) { if (localStorage.getItem('token')) {
this.token = localStorage.getItem('token'); this.token = localStorage.getItem('token');
} }
} }
public updateToken(): void { public updateToken(): void {
localStorage.setItem('token', this.token); localStorage.setItem('token', this.token);
} }
public updateHost(): void { public updateHost(): void {
this.alfrescoSettingsService.host = this.host; this.alfrescoSettingsService.host = this.host;
} }
public customMethod(event: Object): void { public customMethod(event: Object): void {
console.log('File uploaded'); console.log('File uploaded');
} }
public ngOnInit(): void { public ngOnInit(): void {
this.login(); this.login();
} }
public login(): void { public login(): void {
this.authService.login('admin', 'admin').subscribe(token => { this.authService.login('admin', 'admin').subscribe(token => {
this.authenticated = true; this.authenticated = true;
}); });
} }
} }
bootstrap(MyDemoApp, [ bootstrap(MyDemoApp, [
HTTP_PROVIDERS, HTTP_PROVIDERS,
ALFRESCO_CORE_PROVIDERS, ALFRESCO_CORE_PROVIDERS,
UploadService UploadService
]); ]);