From 3b6b8ed59b3ae06428d937b4691e80f492b062e4 Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Thu, 22 Sep 2016 01:14:15 +0100 Subject: [PATCH] Added some upgrades to demo and added the component to demo shell --- demo-shell-ng2/app/app.component.html | 4 + .../components/profile/profile.component.ts | 16 ++++ .../ng2-alfresco-upload/demo/index.html | 1 + .../ng2-alfresco-userinfo/demo/index.html | 3 +- .../ng2-alfresco-userinfo/demo/package.json | 47 +++++++---- .../ng2-alfresco-userinfo/demo/src/main.ts | 5 +- .../ng2-alfresco-userinfo/package.json | 51 ++++++------ .../src/services/bpmUser.service.ts | 38 +++++---- .../src/services/ecmUser.service.ts | 16 +++- .../src/userinfo.component.html | 25 +++--- .../src/userinfo.component.ts | 80 +++++++++---------- 11 files changed, 167 insertions(+), 119 deletions(-) diff --git a/demo-shell-ng2/app/app.component.html b/demo-shell-ng2/app/app.component.html index e4b21d6861..d8131ce30b 100644 --- a/demo-shell-ng2/app/app.component.html +++ b/demo-shell-ng2/app/app.component.html @@ -21,6 +21,10 @@ Login +
+ +
+ `, directives: [ UserInfoComponent ], - providers: [AlfrescoAuthenticationService, AlfrescoSettingsService] + providers: [AlfrescoAuthenticationService, AlfrescoSettingsService, MDL] }) diff --git a/ng2-components/ng2-alfresco-userinfo/package.json b/ng2-components/ng2-alfresco-userinfo/package.json index 34b6de40e7..538102137b 100644 --- a/ng2-components/ng2-alfresco-userinfo/package.json +++ b/ng2-components/ng2-alfresco-userinfo/package.json @@ -4,9 +4,7 @@ "version": "0.1.0", "author": "vito albano ", "scripts": { - "postinstall": "typings install", - "clean": "rimraf dist node_modules typings", - "typings": "typings install", + "clean": "rimraf dist node_modules", "license-check": "echo 'license check is disabled'", "build": "npm run tslint && rimraf dist && tsc && npm run copy-dist && npm run license-check", "build:w": "npm run tslint && rimraf dist && npm run watch-task", @@ -21,7 +19,6 @@ "test-browser": "npm run build && concurrently \"karma start karma.conf.js --reporters kjhtml\" \"npm run watch-task\"", "posttest": "remap-istanbul -i coverage/report/coverage-final.json -o coverage/report -t html && remap-istanbul -i coverage/report/coverage-final.json -o coverage/report/coverage-final.json", "coverage": "npm run test && wsrv -o -p 9875 ./coverage/report", - "prepublish": "npm run build", "travis": "echo 'placeholder'" }, "main": "./dist/index.js", @@ -33,10 +30,13 @@ "bugs": { "url": "https://github.com/alfresco/ng2-alfresco-userinfo/issues" }, + "dependencies": { + "alfresco-js-api": "^0.3.0", "@angular/common": "2.0.0-rc.3", "@angular/compiler": "2.0.0-rc.3", "@angular/core": "2.0.0-rc.3", + "@angular/forms": "0.1.1", "@angular/http": "2.0.0-rc.3", "@angular/platform-browser": "2.0.0-rc.3", "@angular/platform-browser-dynamic": "2.0.0-rc.3", @@ -44,34 +44,35 @@ "@angular/router-deprecated": "2.0.0-rc.2", "@angular/upgrade": "2.0.0-rc.3", "systemjs": "0.19.27", - "core-js": "^2.4.0", - "reflect-metadata": "^0.1.3", + "core-js": "2.4.0", + "reflect-metadata": "0.1.3", "rxjs": "5.0.0-beta.6", - "zone.js": "^0.6.12", + "zone.js": "0.6.12", "ng2-translate": "2.2.2", - "alfresco-js-api": "^0.3.0", - "ng2-alfresco-core": "0.3.2" + "ng2-alfresco-core": "0.3.2", + "material-design-icons": "2.2.3", + "material-design-lite": "1.1.3" }, "devDependencies": { - "angular-cli": "1.0.0-beta.9", - "concurrently": "^2.1.0", - "cpx": "^1.3.1", - "jasmine-ajax": "^3.2.0", + "@types/core-js": "^0.9.32", + "@types/jasmine": "^2.2.33", + "cpx": "1.3.1", + "jasmine-ajax": "3.2.0", "jasmine-core": "2.4.1", - "karma": "~0.13.22", - "karma-chrome-launcher": "~1.0.1", - "karma-coverage": "^1.0.0", - "karma-jasmine": "~1.0.2", + "karma": "0.13.22", + "karma-chrome-launcher": "1.0.1", + "karma-coverage": "1.0.0", + "karma-jasmine": "1.0.2", "karma-jasmine-ajax": "^0.1.13", - "karma-jasmine-html-reporter": "^0.2.0", - "karma-mocha-reporter": "^2.0.3", - "remap-istanbul": "^0.6.3", + "karma-jasmine-html-reporter": "0.2.0", + "karma-mocha-reporter": "2.0.3", + "license-check": "1.1.5", + "remap-istanbul": "0.6.3", "rimraf": "2.5.2", - "traceur": "^0.0.91", - "tslint": "^3.8.1", - "typescript": "^1.8.10", - "typings": "^1.0.4", - "wsrv": "^0.1.3" + "traceur": "0.0.91", + "tslint": "3.8.1", + "typescript": "^2.0.2", + "wsrv": "^0.1.5" }, "keywords": [ "component", 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 455e04bd70..5d3f2bd163 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/bpmUser.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/bpmUser.service.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; import { Observable } from 'rxjs/Rx'; @@ -29,37 +29,35 @@ import { BpmUserModel } from '../models/bpmUser.model'; @Injectable() export class BPMUserService { - constructor(public authService: AlfrescoAuthenticationService) {} + constructor(private authService: AlfrescoAuthenticationService, + private settingService: AlfrescoSettingsService) { + } /** * get User Information via ECM * @param userName - the user name */ getCurrentUserInfo(): Observable { - return Observable.fromPromise(this.callApiGetProfile()) - .map( - data => data - ) - .do( - data => console.log('Node data', data) - ) // eyeball results in the console - .catch(this.handleError); + if ( this.authService.getAlfrescoApi().bpmAuth.isLoggedIn() ) { + return Observable.fromPromise(this.callApiGetProfile()) + .map( + data => data + ) + .do( + data => console.log('Node data', data) + ) // eyeball results in the console + .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(); + getCurrentUserProfileImage(): string { + if ( this.authService.getAlfrescoApi().bpmAuth.isLoggedIn() ) { + return this.settingService.getBPMApiBaseUrl() + '/api/enterprise/profile-picture'; + } } private callApiGetProfile() { 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 1f6dd6c7d5..e85f34b116 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/ecmUser.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/ecmUser.service.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core'; import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; import { Observable } from 'rxjs/Rx'; @@ -29,23 +29,33 @@ import { EcmUserModel } from '../models/ecmUser.model'; @Injectable() export class ECMUserService { - constructor(private apiService: AlfrescoApiService) {} + constructor(private authService: AlfrescoAuthenticationService, + private contentService: AlfrescoContentService) {} /** * get User Information via ECM * @param userName - the user name */ getUserInfo(userName: string): Observable { + if ( this.authService.getAlfrescoApi().ecmAuth.isLoggedIn() ) { return Observable.fromPromise(this.callApiGetPersonInfo(userName)) .map( data => data['entry']) .do( data => console.log('Node data', data['entry']) ) // eyeball results in the console .catch(this.handleError); + } } private callApiGetPersonInfo(userName: string, opts?: any) { - return this.apiService.getInstance().core.peopleApi.getPerson(userName, opts); + return this.authService.getAlfrescoApi().core.peopleApi.getPerson(userName, opts); + } + + getCurrentUserProfileImageUrl(avatarId: string) { + if ( avatarId ) { + let nodeObj = {entry: {id: avatarId}}; + return this.contentService.getContentUrl(nodeObj); + } } /** diff --git a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html index 153b90b6bd..bf39e21403 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html +++ b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html @@ -1,9 +1,16 @@ -
-
- {{ecmUser.firstName}} {{ecmUser.lastName}} - {{bpmUser.fullname}} - -
-
+{{ecmUser.firstName}} {{ecmUser.lastName}} +{{bpmUser.fullname}} + + +
    +
  • Some Action
  • +
  • Another Action
  • +
  • Disabled Action
  • +
  • Yet Another Action
  • +
diff --git a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts index 49f38942f0..20becdb6b3 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts @@ -15,12 +15,12 @@ * limitations under the License. */ -import { Component, OnInit, Input } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { ECMUserService } from './services/ecmUser.service'; import { BPMUserService } from './services/bpmUser.service'; import { EcmUserModel } from './models/ecmUser.model'; import { BpmUserModel } from './models/bpmUser.model'; -import { AlfrescoContentService } from 'ng2-alfresco-core'; +import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; declare let __moduleName: string; @@ -29,14 +29,11 @@ declare let __moduleName: string; moduleId: __moduleName, styleUrls: ['./userinfo.component.css'], templateUrl: './userinfo.component.html', - providers: [ ECMUserService, BPMUserService, AlfrescoContentService ] + providers: [ECMUserService, BPMUserService, AlfrescoAuthenticationService] }) export class UserInfoComponent implements OnInit { - @Input() - userEmail: string; - private ecmUser: EcmUserModel; private bpmUser: BpmUserModel; public bpmUserImage: any; @@ -46,51 +43,48 @@ export class UserInfoComponent implements OnInit { constructor(private ecmUserService: ECMUserService, private bpmUserService: BPMUserService, - private contentService: AlfrescoContentService) { + public authService: AlfrescoAuthenticationService) { } ngOnInit() { - this.ecmUserService.getUserInfo(this.userEmail) - .subscribe( - res => { - this.ecmUser = res; - this.getUserProfileImage(); - console.log(this.ecmUserImage); - } - ); - this.bpmUserService.getCurrentUserInfo() - .subscribe( - res => { - this.bpmUser = res; - } - ); - + if (this.authService.getAlfrescoApi().ecmAuth.isLoggedIn()) { + this.ecmUserService.getUserInfo('-me-') + .subscribe( + (res) => { + this.ecmUser = res; + this.getUserProfileImage(); + } + ); + } + if (this.authService.getAlfrescoApi().bpmAuth.isLoggedIn()) { + this.bpmUserService.getCurrentUserInfo() + .subscribe( + (res) => { + this.bpmUser = res; + this.getUserProfileImage(); + } + ); + } } 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 - ); - } + if (this.ecmUser) { + this.ecmUserImage = this.ecmUserService.getCurrentUserProfileImageUrl(this.ecmUser.avatarId); + } + if (this.bpmUser) { + this.bpmUserImage = this.bpmUserService.getCurrentUserProfileImage(); + } } 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'; - } + if (this.ecmUserImage) { + return this.ecmUserImage; + } + if (this.bpmUserImage) { + return this.bpmUserImage; + } + if (!this.ecmUserImage && !this.bpmUserImage) { + return this.baseComponentPath + '/img/anonymous.gif'; + } } - - }