diff --git a/demo-shell-ng2/app/components/profile/AboutComponent.java b/demo-shell-ng2/app/components/profile/AboutComponent.java new file mode 100644 index 0000000000..30b667a14a --- /dev/null +++ b/demo-shell-ng2/app/components/profile/AboutComponent.java @@ -0,0 +1,55 @@ +/*! + * @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 { Component, OnInit } from '@angular/core'; +import { Http } from '@angular/http'; +import { + ALFRESCO_DATATABLE_DIRECTIVES, + ObjectDataTableAdapter /*, + DataSorting, + ObjectDataRow, + ObjectDataColumn*/ +} from 'ng2-alfresco-datatable'; + +declare let __moduleName: string; + +@Component({ + moduleId: __moduleName, + selector: 'about-page', + templateUrl: './about.component.html', + directives: [ALFRESCO_DATATABLE_DIRECTIVES] +}) +export class AboutComponent implements OnInit { + + data: ObjectDataTableAdapter; + + constructor(private http: Http) {} + + ngOnInit() { + // this.data = new ObjectDataTableAdapter(); + this.http.get('/versions').subscribe(response => { + let data = response.json() || {}; + let packages = data.packages || []; + + this.data = new ObjectDataTableAdapter(packages, [ + { type: 'text', key: 'name', title: 'Name', sortable: true }, + { type: 'text', key: 'version', title: 'Version', sortable: true } + ]); + }); + + } +} diff --git a/demo-shell-ng2/app/components/profile/profile.component.html b/demo-shell-ng2/app/components/profile/profile.component.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/demo-shell-ng2/app/components/profile/profile.component.ts b/demo-shell-ng2/app/components/profile/profile.component.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts b/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts index a7c5c03cb1..5e5ff8772c 100644 --- a/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts @@ -11,7 +11,43 @@ import { @Component({ selector: 'my-app', - template: `

START

`, + styles: [`:host h1 { font-size:22px }`], + template: ` +

START DEMO USERINFO

+
+

+ +

+

+ +

+
+
+ +
+

+
+

+ Username + +

+

+ Password + +

+ +
+{{loginErrorMessage}} + +`, directives: [ UserInfoComponent ], providers: [AlfrescoAuthenticationService, AlfrescoSettingsService] }) @@ -19,30 +55,68 @@ import { class UserInfoDemo implements OnInit { + public userToLogin: string = 'admin'; + public password: string = 'admin'; + public loginErrorMessage: string; + public providers: string = 'BPM'; private authenticated: boolean; private token: any; constructor(private authService: AlfrescoAuthenticationService, private settingsService: AlfrescoSettingsService) { - this.settingsService.setProviders('ALL'); } - public ngOnInit(): void { - this.login(); + ngOnInit() { + this.settingsService.setProviders(this.providers); } - login() { - this.authService.login('test', 'test').subscribe( - token => { - console.log(token); - this.token = token; - this.authenticated = true; - }, - error => { - console.log(error); - this.authenticated = false; - }); - } + attemptLogin() { + this.loginErrorMessage = ''; + this.login(this.userToLogin, this.password); + } + + logout() { + this.authService.logout(); + } + + login(user, password) { + this.settingsService.setProviders(this.providers); + this.authService.login(user, password).subscribe( + token => { + console.log(token); + this.token = token; + this.authenticated = true; + }, + error => { + console.log(error); + this.authenticated = false; + this.loginErrorMessage = error; + }); + } + + isLoggedIn(): boolean { + return this.authService.isLoggedIn(); + } + + toggleECM(checked) { + if (checked && this.providers === 'BPM') { + this.providers = 'ALL'; + } else if (checked) { + this.providers = 'ECM'; + } else { + this.providers = undefined; + } + } + + toggleBPM(checked) { + if (checked && this.providers === 'ECM') { + this.providers = 'ALL'; + } else if (checked) { + this.providers = 'BPM'; + } else { + this.providers = undefined; + } + } } bootstrap(UserInfoDemo, [ diff --git a/ng2-components/ng2-alfresco-userinfo/src/img/anonymous.gif b/ng2-components/ng2-alfresco-userinfo/src/img/anonymous.gif new file mode 100644 index 0000000000..e1b58fa57d Binary files /dev/null and b/ng2-components/ng2-alfresco-userinfo/src/img/anonymous.gif differ diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/bpmUser.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/bpmUser.service.ts index 593079a8cf..455e04bd70 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/bpmUser.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/bpmUser.service.ts @@ -18,7 +18,7 @@ import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; -import { Observable } from 'rxjs/Observable'; +import { Observable } from 'rxjs/Rx'; import { BpmUserModel } from '../models/bpmUser.model'; /** * @@ -46,10 +46,25 @@ export class BPMUserService { .catch(this.handleError); } + /** + * get User Information via ECM + * @param userName - the user name + */ + getCurrentUserProfileImage(): Observable { + return Observable.fromPromise(this.callApiGetProfileImage()) + .do( + data => console.log('Node data', data) + ) // eyeball results in the console + .catch(this.handleError); + } + + private callApiGetProfileImage() { + return this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture(); + } + private callApiGetProfile() { return this.authService.getAlfrescoApi().activiti.profileApi.getProfile(); } - /** * Throw the error * @param error diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/ecmUser.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/ecmUser.service.ts index dbb005892a..1f6dd6c7d5 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/ecmUser.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/ecmUser.service.ts @@ -18,7 +18,7 @@ import { AlfrescoApiService } from 'ng2-alfresco-core'; import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; -import { Observable } from 'rxjs/Observable'; +import { Observable } from 'rxjs/Rx'; import { EcmUserModel } from '../models/ecmUser.model'; /** * diff --git a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.css b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.css new file mode 100644 index 0000000000..9f59213ab7 --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.css @@ -0,0 +1,14 @@ +.profile-image { + text-align: center; + border-radius: 90%; + width: 40px; + margin-right: 0%; + cursor: pointer; + border: 2px solid #999999; +} + +.button-profile { + display: inline-block; + margin-right: -10px; + border: 0px; +} diff --git a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html index 4a1c172487..153b90b6bd 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html +++ b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html @@ -1,139 +1,9 @@ -
-
- -
- ECM - BPM -
- - -
-
    -
  • - - person - {{ecmUser.firstName}} {{ecmUser.lastName}} - -
  • -
  • - Id: - -
  • -
  • - Description: - -
  • -
  • - Email: - -
  • -
  • - Skype Id: - -
  • -
  • - Google Id: - -
  • -
  • - Instant Message Id: - -
  • -
  • - Job Title: - -
  • -
  • - Location: - -
  • -
  • - Mobile: - -
  • -
  • - Telephone: - -
  • -
  • - User Status: - -
  • -
  • - Enabled: - -
  • -
  • - Email Notifications: - -
  • -
-
-
-
    -
  • - - person - {{bpmUser.fullname}} - -
  • -
  • - Id: - -
  • -
  • - Email: - -
  • -
  • - Status: - -
  • -
  • - Tenant Name: - -
  • -
  • - Company: - -
  • -
+
+
+ {{ecmUser.firstName}} {{ecmUser.lastName}} + {{bpmUser.fullname}} +
-
diff --git a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts index f29d945b8e..49f38942f0 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts @@ -1,3 +1,19 @@ +/*! + * @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 { Component, OnInit, Input } from '@angular/core'; import { ECMUserService } from './services/ecmUser.service'; @@ -11,7 +27,7 @@ declare let __moduleName: string; @Component({ selector: 'ng2-alfresco-userinfo', moduleId: __moduleName, - styles: [`:host h1 { font-size:22px }`], + styleUrls: ['./userinfo.component.css'], templateUrl: './userinfo.component.html', providers: [ ECMUserService, BPMUserService, AlfrescoContentService ] }) @@ -23,6 +39,10 @@ export class UserInfoComponent implements OnInit { private ecmUser: EcmUserModel; private bpmUser: BpmUserModel; + public bpmUserImage: any; + public ecmUserImage: any; + + private baseComponentPath = __moduleName.replace('userinfo.component.js', ''); constructor(private ecmUserService: ECMUserService, private bpmUserService: BPMUserService, @@ -32,15 +52,45 @@ export class UserInfoComponent implements OnInit { ngOnInit() { this.ecmUserService.getUserInfo(this.userEmail) .subscribe( - res => this.ecmUser = res + res => { + this.ecmUser = res; + this.getUserProfileImage(); + console.log(this.ecmUserImage); + } ); this.bpmUserService.getCurrentUserInfo() .subscribe( - res => this.bpmUser = res + res => { + this.bpmUser = res; + } ); + } - public getDocumentThumbnailUrl(avatarId: string): string { - return this.contentService.getDocumentThumbnailUrl(document); + private getUserProfileImage() { + if (this.ecmUser && this.ecmUser.avatarId) { + let nodeObj = { entry: { id: this.ecmUser.avatarId } }; + this.ecmUserImage = this.contentService.getContentUrl(nodeObj); + } + if (this.bpmUser) { + this.bpmUserService.getCurrentUserProfileImage() + .subscribe( + res => this.bpmUserImage = res + ); + } } + + public getUserAvatar() { + if (this.ecmUserImage) { + return this.ecmUserImage; + } + if (this.bpmUserImage) { + return this.bpmUserImage; + } + if (!this.ecmUserImage && !this.bpmUserImage) { + return this.baseComponentPath + '/img/anonymous.gif'; + } + } + + }