From 177c9694af2e0041030481cae8d7158fc82c0159 Mon Sep 17 00:00:00 2001 From: Mario Romano Date: Wed, 9 Nov 2016 12:27:44 +0000 Subject: [PATCH] #878 doc,demo and code improvements userinfo component --- .../ng2-activiti-analytics/README.md | 10 ++ .../ng2-activiti-diagrams/README.md | 10 ++ ng2-components/ng2-activiti-form/README.md | 10 ++ .../ng2-activiti-processlist/README.md | 10 ++ .../ng2-activiti-tasklist/README.md | 10 ++ ng2-components/ng2-alfresco-core/README.md | 10 ++ .../AlfrescoAuthentication.service.ts | 2 +- .../ng2-alfresco-datatable/README.md | 10 ++ .../ng2-alfresco-documentlist/README.md | 10 ++ ng2-components/ng2-alfresco-login/README.md | 10 ++ ng2-components/ng2-alfresco-search/README.md | 10 ++ ng2-components/ng2-alfresco-tag/README.md | 10 ++ ng2-components/ng2-alfresco-upload/README.md | 10 ++ .../ng2-alfresco-userinfo/README.md | 159 ++++++++++++------ .../ng2-alfresco-userinfo/demo/package.json | 22 --- .../ng2-alfresco-userinfo/demo/src/main.ts | 4 +- .../demo/systemjs.config.js | 1 - .../ng2-alfresco-userinfo/package.json | 18 -- .../src/components/user-info.component.ts | 31 +++- ng2-components/ng2-alfresco-viewer/README.md | 10 ++ .../ng2-alfresco-webscript/README.md | 10 ++ 21 files changed, 269 insertions(+), 108 deletions(-) diff --git a/ng2-components/ng2-activiti-analytics/README.md b/ng2-components/ng2-activiti-analytics/README.md index 136f8cad99..166bf6e17c 100644 --- a/ng2-components/ng2-activiti-analytics/README.md +++ b/ng2-components/ng2-activiti-analytics/README.md @@ -302,6 +302,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) diff --git a/ng2-components/ng2-activiti-diagrams/README.md b/ng2-components/ng2-activiti-diagrams/README.md index 686783f682..5192d5647a 100644 --- a/ng2-components/ng2-activiti-diagrams/README.md +++ b/ng2-components/ng2-activiti-diagrams/README.md @@ -211,6 +211,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) \ No newline at end of file diff --git a/ng2-components/ng2-activiti-form/README.md b/ng2-components/ng2-activiti-form/README.md index 164722c525..f8c02b3ac8 100644 --- a/ng2-components/ng2-activiti-form/README.md +++ b/ng2-components/ng2-activiti-form/README.md @@ -371,6 +371,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) diff --git a/ng2-components/ng2-activiti-processlist/README.md b/ng2-components/ng2-activiti-processlist/README.md index 6ff436c351..be0d6f1308 100644 --- a/ng2-components/ng2-activiti-processlist/README.md +++ b/ng2-components/ng2-activiti-processlist/README.md @@ -411,6 +411,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) diff --git a/ng2-components/ng2-activiti-tasklist/README.md b/ng2-components/ng2-activiti-tasklist/README.md index 5a860a5885..e8db244743 100644 --- a/ng2-components/ng2-activiti-tasklist/README.md +++ b/ng2-components/ng2-activiti-tasklist/README.md @@ -343,6 +343,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) diff --git a/ng2-components/ng2-alfresco-core/README.md b/ng2-components/ng2-alfresco-core/README.md index de14e82d01..616e997f0b 100644 --- a/ng2-components/ng2-alfresco-core/README.md +++ b/ng2-components/ng2-alfresco-core/README.md @@ -246,6 +246,16 @@ before performing unit testing. npm run coverage ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts index 90064f06ef..9d25072986 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts @@ -105,10 +105,10 @@ export class AlfrescoAuthenticationService { * @returns {Observable|Observable} */ public logout() { + this.removeTicket(); return Observable.fromPromise(this.callApiLogout()) .map(res => res) .do(response => { - this.removeTicket(); return response; }) .catch(this.handleError); diff --git a/ng2-components/ng2-alfresco-datatable/README.md b/ng2-components/ng2-alfresco-datatable/README.md index 401b24edb6..60f33a654d 100644 --- a/ng2-components/ng2-alfresco-datatable/README.md +++ b/ng2-components/ng2-alfresco-datatable/README.md @@ -482,6 +482,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-documentlist/README.md b/ng2-components/ng2-alfresco-documentlist/README.md index 7b72db8845..738bd97733 100644 --- a/ng2-components/ng2-alfresco-documentlist/README.md +++ b/ng2-components/ng2-alfresco-documentlist/README.md @@ -779,6 +779,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-login/README.md b/ng2-components/ng2-alfresco-login/README.md index 08b32efd9d..1735cbcfc2 100644 --- a/ng2-components/ng2-alfresco-login/README.md +++ b/ng2-components/ng2-alfresco-login/README.md @@ -312,6 +312,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) diff --git a/ng2-components/ng2-alfresco-search/README.md b/ng2-components/ng2-alfresco-search/README.md index 006dd6f30d..4092139241 100644 --- a/ng2-components/ng2-alfresco-search/README.md +++ b/ng2-components/ng2-alfresco-search/README.md @@ -285,6 +285,16 @@ platformBrowserDynamic().bootstrapModule(AppModule); npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-tag/README.md b/ng2-components/ng2-alfresco-tag/README.md index 36e75ba3d2..2e989d0983 100644 --- a/ng2-components/ng2-alfresco-tag/README.md +++ b/ng2-components/ng2-alfresco-tag/README.md @@ -308,6 +308,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) diff --git a/ng2-components/ng2-alfresco-upload/README.md b/ng2-components/ng2-alfresco-upload/README.md index 6ba7121d26..a5f3ea9cef 100644 --- a/ng2-components/ng2-alfresco-upload/README.md +++ b/ng2-components/ng2-alfresco-upload/README.md @@ -311,6 +311,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-userinfo/README.md b/ng2-components/ng2-alfresco-userinfo/README.md index 21b95c61ac..373bbd8ab7 100644 --- a/ng2-components/ng2-alfresco-userinfo/README.md +++ b/ng2-components/ng2-alfresco-userinfo/README.md @@ -1,4 +1,5 @@ # Alfresco User Info Component for Angular 2 +

travis
@@ -11,8 +12,8 @@
   <a href= Coverage Status - - npm downloads + + npm downloads license @@ -31,78 +32,130 @@

-### Node -To correctly use this component check that on your machine is running Node version 5.0.0 or higher. - - ## Prerequisites Before you start using this development framework, make sure you have installed all required software and done all the -necessary configuration, see this [page](https://github.com/Alfresco/alfresco-ng2-components/blob/master/PREREQUISITES.md). +necessary configuration [prerequisites](https://github.com/Alfresco/alfresco-ng2-components/blob/master/PREREQUISITES.md). -## Installation +## Install -```bash -npm install ng2-alfresco-userinfo --save -``` -## Dependencies +Follow the 3 steps below: -Add the following dependency to your index.html: -```html - -``` - -You must separately install the following libraries for your application: - -- [ng2-translate](https://github.com/ocombe/ng2-translate) -- [ng2-alfresco-core](https://www.npmjs.com/package/ng2-alfresco-core) +1. Npm -```sh -npm install --save ng2-translate ng2-alfresco-core -``` - -#### Material Design Lite + ```sh + npm install ng2-alfresco-userinfo --save + ``` -The style of this component is based on [material design](https://getmdl.io/), so if you want to visualize it correctly you have to add the material -design dependency to your project: +2. Html -```sh -npm install --save material-design-icons material-design-lite -``` + Include these dependencies in your index.html page: -Also make sure you include these dependencies in your `index.html` file: + ```html -```html - - - - -``` - -## Example + + + + + + + + + + + + + + + + + + + + + + + + + ``` + +3. SystemJs + + Add the following components to your systemjs.config.js file: + + - ng2-translate + - alfresco-js-api + - ng2-alfresco-core + - ng2-alfresco-userinfo + + Please refer to the following example file: [systemjs.config.js](demo/systemjs + .config.js) . ## Basic usage ```html - - + ``` ### Properties | Name | Type | Default | Description | | --- | --- | --- | --- | -| ecmBackgroundImage | string | | Custom path for the background banner image for ECM users | -| bpmBackgroundImage | string | | Custom path for the background banner image for BPM users | -| menuOpenType | string | bottom-right | Custom choice for opening menu bottom right or bottom left | -| fallBackThumbnailImage | string | image at ng2-alfresco-userinfo/src/img/anonymous.gif | Fallback image for profile when thubnail is missing| +| `ecmBackgroundImage` | string | ng2-alfresco-userinfo/src/img/orangeBanner.gif | Custom path for the background banner image for ECM users | +| `bpmBackgroundImage` | string | ng2-alfresco-userinfo/src/img/blueBanner.gif | Custom path for the background banner image for BPM users | +| `menuOpenType` | string | right | Custom choice for opening menu bottom : `right` or `left` | +| `fallBackThumbnailImage` | string | ng2-alfresco-userinfo/src/img/anonymous.gif | Fallback image for profile when thubnail is missing| This will show a round icon with user and on click some user information are showed. If user is logged in with ECM and BPM the ECM image will be showed. +## Build from sources + +Alternatively you can build component from sources with the following commands: + + +```sh +npm install +npm run build +``` + +### Build the files and keep watching for changes + +```sh +$ npm run build:w +``` + +## Running unit tests + +```sh +npm test +``` + +### Running unit tests in browser + +```sh +npm test-browser +``` + +This task rebuilds all the code, runs tslint, license checks and other quality check tools +before performing unit testing. + +### Code coverage + +```sh +npm run coverage +``` + +## Demo + +If you want have a demo of how the component works, please check the demo folder : + +```sh +cd demo +npm install +npm start +``` + ## NPM scripts | Command | Description | @@ -113,10 +166,6 @@ If user is logged in with ECM and BPM the ECM image will be showed. | npm run test-browser | Run unit tests in the browser | npm run coverage | Run unit tests and display code coverage report | -## History +## License -For detailed changelog, check [Releases](https://github.com/alfresco/ng2-alfresco-userinfo/releases). - -## Contributors - -[Contributors](https://github.com/alfresco/ng2-alfresco-userinfo/graphs/contributors) \ No newline at end of file +[Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-userinfo/demo/package.json b/ng2-components/ng2-alfresco-userinfo/demo/package.json index 89001b7434..5cb3aff079 100644 --- a/ng2-components/ng2-alfresco-userinfo/demo/package.json +++ b/ng2-components/ng2-alfresco-userinfo/demo/package.json @@ -16,28 +16,6 @@ }, "license": "Apache-2.0", "dependencies": { - "@angular/common": "2.0.0", - "@angular/compiler": "2.0.0", - "@angular/core": "2.0.0", - "@angular/forms": "2.0.0", - "@angular/http": "2.0.0", - "@angular/platform-browser": "2.0.0", - "@angular/platform-browser-dynamic": "2.0.0", - "@angular/router": "3.0.0", - "@angular/upgrade": "2.0.0", - "@types/node": "^6.0.42", - "core-js": "^2.4.1", - "reflect-metadata": "^0.1.3", - "rxjs": "5.0.0-beta.12", - "systemjs": "0.19.27", - "zone.js": "^0.6.23", - - "material-design-icons": "2.2.3", - "material-design-lite": "1.2.1", - "ng2-translate": "2.5.0", - - "alfresco-js-api": "^0.3.0", - "ng2-alfresco-core": "^0.3.0", "ng2-alfresco-userinfo": "0.3.2" }, "devDependencies": { diff --git a/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts b/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts index 171af79d8d..d7981d6240 100644 --- a/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts @@ -24,7 +24,7 @@ import { CoreModule } from 'ng2-alfresco-core'; import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; @Component({ - selector: 'alfresco-app-demo', + selector: 'alfresco-app-demo', template: `

START DEMO USERINFO

@@ -43,7 +43,7 @@ import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfr

- +

diff --git a/ng2-components/ng2-alfresco-userinfo/demo/systemjs.config.js b/ng2-components/ng2-alfresco-userinfo/demo/systemjs.config.js index 8ccc6d9aea..772783f002 100644 --- a/ng2-components/ng2-alfresco-userinfo/demo/systemjs.config.js +++ b/ng2-components/ng2-alfresco-userinfo/demo/systemjs.config.js @@ -38,7 +38,6 @@ defaultExtension: 'js' }, 'ng2-translate': { defaultExtension: 'js' }, - 'ng2-alfresco-core': { main: './index.js', defaultExtension: 'js'}, 'ng2-alfresco-userinfo': { main: './index.js', defaultExtension: 'js'}, 'alfresco-js-api': { main: './alfresco-js-api.js', defaultExtension: 'js'} diff --git a/ng2-components/ng2-alfresco-userinfo/package.json b/ng2-components/ng2-alfresco-userinfo/package.json index 302a0b705b..5ad2f74f4c 100644 --- a/ng2-components/ng2-alfresco-userinfo/package.json +++ b/ng2-components/ng2-alfresco-userinfo/package.json @@ -31,24 +31,6 @@ "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" }, "dependencies": { - "@angular/common": "2.0.0", - "@angular/compiler": "2.0.0", - "@angular/core": "2.0.0", - "@angular/forms": "2.0.0", - "@angular/http": "2.0.0", - "@angular/platform-browser": "2.0.0", - "@angular/platform-browser-dynamic": "2.0.0", - "@angular/router": "3.0.0", - "@angular/upgrade": "2.0.0", - "@types/node": "^6.0.42", - "core-js": "^2.4.1", - "reflect-metadata": "^0.1.3", - "rxjs": "5.0.0-beta.12", - "systemjs": "0.19.27", - "zone.js": "^0.6.23", - - "alfresco-js-api": "^0.3.0", - "ng2-translate": "2.5.0", "ng2-alfresco-core": "0.3.2" }, "devDependencies": { diff --git a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts index 422c23987a..e1fcf12546 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/components/user-info.component.ts @@ -15,12 +15,14 @@ * limitations under the License. */ -import { Component, OnInit, Input } from '@angular/core'; +import { Component, OnInit, Input, AfterViewChecked } from '@angular/core'; import { EcmUserModel } from './../models/ecm-user.model'; import { BpmUserModel } from './../models/bpm-user.model'; import { EcmUserService } from './../services/ecm-user.service'; import { BpmUserService } from './../services/bpm-user.service'; -import { AlfrescoSettingsService, AlfrescoTranslationService } from 'ng2-alfresco-core'; +import { AlfrescoTranslationService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; + +declare let componentHandler: any; @Component({ selector: 'ng2-alfresco-userinfo', @@ -28,8 +30,7 @@ import { AlfrescoSettingsService, AlfrescoTranslationService } from 'ng2-alfresc styleUrls: ['./user-info.component.css'], templateUrl: './user-info.component.html' }) - -export class UserInfoComponent implements OnInit { +export class UserInfoComponent implements AfterViewChecked, OnInit { @Input() ecmBackgroundImage: string; @@ -53,16 +54,27 @@ export class UserInfoComponent implements OnInit { constructor(private ecmUserService: EcmUserService, private bpmUserService: BpmUserService, - public setting: AlfrescoSettingsService, + private authService: AlfrescoAuthenticationService, private translate: AlfrescoTranslationService) { if (translate) { translate.addTranslationFolder('node_modules/ng2-alfresco-userinfo/src'); } } + ngAfterViewChecked() { + // workaround for MDL issues with dynamic components + if (componentHandler) { + componentHandler.upgradeAllRegistered(); + } + } + ngOnInit() { - if (this.setting.getProviders() === 'ECM' || - this.setting.getProviders() === 'ALL') { + this.getEcmUserInfo(); + this.getBpmUserInfo(); + } + + getEcmUserInfo(): void { + if (this.authService.isEcmLoggedIn()) { this.ecmUserService.getCurrentUserInfo() .subscribe((res) => { this.ecmUser = res; @@ -70,9 +82,10 @@ export class UserInfoComponent implements OnInit { } ); } + } - if (this.setting.getProviders() === 'BPM' || - this.setting.getProviders() === 'ALL') { + getBpmUserInfo(): void { + if (this.authService.isBpmLoggedIn()) { this.bpmUserService.getCurrentUserInfo() .subscribe((res) => { this.bpmUser = res; diff --git a/ng2-components/ng2-alfresco-viewer/README.md b/ng2-components/ng2-alfresco-viewer/README.md index 36ef77c70f..e7e46063c9 100644 --- a/ng2-components/ng2-alfresco-viewer/README.md +++ b/ng2-components/ng2-alfresco-viewer/README.md @@ -267,6 +267,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE) diff --git a/ng2-components/ng2-alfresco-webscript/README.md b/ng2-components/ng2-alfresco-webscript/README.md index ce54ee7040..4f86f12016 100644 --- a/ng2-components/ng2-alfresco-webscript/README.md +++ b/ng2-components/ng2-alfresco-webscript/README.md @@ -328,6 +328,16 @@ npm install npm start ``` +## NPM scripts + +| Command | Description | +| --- | --- | +| npm run build | Build component | +| npm run build:w | Build component and keep watching the changes | +| npm run test | Run unit tests in the console | +| npm run test-browser | Run unit tests in the browser +| npm run coverage | Run unit tests and display code coverage report | + ## License [Apache Version 2.0](https://github.com/Alfresco/alfresco-ng2-components/blob/master/LICENSE)