From a8c7486a26d57416b2c3df8c3dc8605d3214fed3 Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Tue, 20 Sep 2016 17:03:13 +0100 Subject: [PATCH] Added the change for user image --- .../components/profile/AboutComponent.java | 55 +++++++ .../components/profile/profile.component.html | 0 .../components/profile/profile.component.ts | 0 .../ng2-alfresco-userinfo/demo/src/main.ts | 106 +++++++++++-- .../src/img/anonymous.gif | Bin 0 -> 1765 bytes .../src/services/bpmUser.service.ts | 19 ++- .../src/services/ecmUser.service.ts | 2 +- .../src/userinfo.component.css | 14 ++ .../src/userinfo.component.html | 144 +----------------- .../src/userinfo.component.ts | 60 +++++++- 10 files changed, 239 insertions(+), 161 deletions(-) create mode 100644 demo-shell-ng2/app/components/profile/AboutComponent.java create mode 100644 demo-shell-ng2/app/components/profile/profile.component.html create mode 100644 demo-shell-ng2/app/components/profile/profile.component.ts create mode 100644 ng2-components/ng2-alfresco-userinfo/src/img/anonymous.gif create mode 100644 ng2-components/ng2-alfresco-userinfo/src/userinfo.component.css 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 0000000000000000000000000000000000000000..e1b58fa57dfcdfd452ec498c98b930aa905d21d6 GIT binary patch literal 1765 zcmb8pizCyC0|4;vcMq|L=guW!Vi%c59pzQG$YVmt(9<&qUk|0_<~^#dpPrfJR`3LkEhFNwuD*UseB%E9NpnxZIwFun4Gh4>giwRA zc0?x^01y1ne**w~537AIAf!0BrjESujDjDc-khY>t=wMO?<%F(;}2yFR74Dt%}a)P zREJt`!8kwqm|RZoeK}|r3IHK##rgzkWXR z#*`{VI@~f{tInV0ukwK$G*WXf9#@J?Z!6r2$!xjap@7u(QUCMI;#?2#}9bcnDw%MSwt8tuX$>-NEJGdr(T*AtL&uqN~#WT z-g_QP^LsP+c=+}i&ztKwm?_}Wl%Vf);6;vy(fFPKq-Krf{zpQvQICg(?Ug@>Nx&U+ zjC*f3!1kFY4zS~t!;(qN5%NIU3H4v3)8o8SJ&}xYli-Iq9S6HVS;BT^QM6I<7xiew zs43F&{rZ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!#)Y{1Gd3YvBL>qqDmh!%F}{e44g(m3 zaqT=bY?~3aCoJ(;oj;Ql3NL$?!}~e$!?~b?QkCYp)qa#vtFm`QZozZZrH&eTD*&+g E7ZAQxl>h($ literal 0 HcmV?d00001 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'; + } + } + + }