From ef20d6aafd7680a3e2a7a1528e237d6ac713e997 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Fri, 2 Sep 2016 16:10:52 +0100 Subject: [PATCH 1/9] move tag component appfest --- ng2-components/ng2-alfresco-tag/.editorconfig | 23 +++ ng2-components/ng2-alfresco-tag/.gitignore | 13 ++ ng2-components/ng2-alfresco-tag/.travis.yml | 12 ++ ng2-components/ng2-alfresco-tag/LICENSE | 13 ++ ng2-components/ng2-alfresco-tag/README.md | 131 ++++++++++++++++ .../assets/license_header.txt | 16 ++ .../ng2-alfresco-tag/demo/.editorconfig | 10 ++ .../ng2-alfresco-tag/demo/.gitignore | 6 + .../ng2-alfresco-tag/demo/README.md | 19 +++ .../ng2-alfresco-tag/demo/index.html | 39 +++++ .../ng2-alfresco-tag/demo/package.json | 65 ++++++++ .../ng2-alfresco-tag/demo/src/main.ts | 121 +++++++++++++++ .../ng2-alfresco-tag/demo/systemjs.config.js | 57 +++++++ .../ng2-alfresco-tag/demo/tsconfig.json | 19 +++ .../ng2-alfresco-tag/demo/tslint.json | 124 +++++++++++++++ .../ng2-alfresco-tag/demo/typings.json | 7 + .../ng2-alfresco-tag/demo/wsrv-config.json | 5 + ng2-components/ng2-alfresco-tag/index.ts | 41 +++++ .../ng2-alfresco-tag/karma-test-shim.js | 107 +++++++++++++ ng2-components/ng2-alfresco-tag/karma.conf.js | 88 +++++++++++ ng2-components/ng2-alfresco-tag/package.json | 93 ++++++++++++ .../src/components/tag-actions.component.css | 23 +++ .../src/components/tag-actions.component.html | 40 +++++ .../components/tag-actions.component.spec.ts | 17 +++ .../src/components/tag-actions.component.ts | 82 ++++++++++ .../src/components/tag-list.component.html | 11 ++ .../src/components/tag-list.component.ts | 62 ++++++++ .../components/tag-node-list.component.css | 65 ++++++++ .../components/tag-node-list.component.html | 8 + .../src/components/tag-node-list.component.ts | 75 +++++++++ .../src/services/tag.service.ts | 142 ++++++++++++++++++ ng2-components/ng2-alfresco-tag/tsconfig.json | 27 ++++ ng2-components/ng2-alfresco-tag/tslint.json | 121 +++++++++++++++ ng2-components/ng2-alfresco-tag/typings.json | 7 + 34 files changed, 1689 insertions(+) create mode 100644 ng2-components/ng2-alfresco-tag/.editorconfig create mode 100644 ng2-components/ng2-alfresco-tag/.gitignore create mode 100644 ng2-components/ng2-alfresco-tag/.travis.yml create mode 100644 ng2-components/ng2-alfresco-tag/LICENSE create mode 100644 ng2-components/ng2-alfresco-tag/README.md create mode 100644 ng2-components/ng2-alfresco-tag/assets/license_header.txt create mode 100644 ng2-components/ng2-alfresco-tag/demo/.editorconfig create mode 100644 ng2-components/ng2-alfresco-tag/demo/.gitignore create mode 100644 ng2-components/ng2-alfresco-tag/demo/README.md create mode 100644 ng2-components/ng2-alfresco-tag/demo/index.html create mode 100644 ng2-components/ng2-alfresco-tag/demo/package.json create mode 100644 ng2-components/ng2-alfresco-tag/demo/src/main.ts create mode 100644 ng2-components/ng2-alfresco-tag/demo/systemjs.config.js create mode 100644 ng2-components/ng2-alfresco-tag/demo/tsconfig.json create mode 100644 ng2-components/ng2-alfresco-tag/demo/tslint.json create mode 100644 ng2-components/ng2-alfresco-tag/demo/typings.json create mode 100644 ng2-components/ng2-alfresco-tag/demo/wsrv-config.json create mode 100644 ng2-components/ng2-alfresco-tag/index.ts create mode 100644 ng2-components/ng2-alfresco-tag/karma-test-shim.js create mode 100644 ng2-components/ng2-alfresco-tag/karma.conf.js create mode 100644 ng2-components/ng2-alfresco-tag/package.json create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.css create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-list.component.html create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.css create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.html create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts create mode 100644 ng2-components/ng2-alfresco-tag/src/services/tag.service.ts create mode 100644 ng2-components/ng2-alfresco-tag/tsconfig.json create mode 100644 ng2-components/ng2-alfresco-tag/tslint.json create mode 100644 ng2-components/ng2-alfresco-tag/typings.json diff --git a/ng2-components/ng2-alfresco-tag/.editorconfig b/ng2-components/ng2-alfresco-tag/.editorconfig new file mode 100644 index 0000000000..75a2477db7 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/.editorconfig @@ -0,0 +1,23 @@ +# http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 4 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[package.json] +indent_style = space +indent_size = 2 + +[karma.conf.js] +indent_style = space +indent_size = 2 + +[*.md] +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/ng2-components/ng2-alfresco-tag/.gitignore b/ng2-components/ng2-alfresco-tag/.gitignore new file mode 100644 index 0000000000..3bea8a0c07 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/.gitignore @@ -0,0 +1,13 @@ +npm-debug.log +node_modules +jspm_packages +.idea +typings +coverage +src/**/*.js +src/**/*.js.map +src/**/*.d.ts +demo/**/*.js +demo/**/*.js.map +demo/**/*.d.ts +!systemjs.config.js diff --git a/ng2-components/ng2-alfresco-tag/.travis.yml b/ng2-components/ng2-alfresco-tag/.travis.yml new file mode 100644 index 0000000000..ab817d7644 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/.travis.yml @@ -0,0 +1,12 @@ +language: node_js +node_js: + - v5 + - v4 + - '0.12' + - '0.10' +install: npm install +sudo: false +after_success: + npm run coverage +# Send coverage data to Coveralls +after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" diff --git a/ng2-components/ng2-alfresco-tag/LICENSE b/ng2-components/ng2-alfresco-tag/LICENSE new file mode 100644 index 0000000000..de3d8c60b8 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/LICENSE @@ -0,0 +1,13 @@ +Copyright 2016 Alfresco + +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. diff --git a/ng2-components/ng2-alfresco-tag/README.md b/ng2-components/ng2-alfresco-tag/README.md new file mode 100644 index 0000000000..a9be7dd0c5 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/README.md @@ -0,0 +1,131 @@ +# Alfresco Tag Component for Angular 2 +

+ + travis
+    Status + + + travis
+    Status + + + Coverage Status + + + npm downloads + + + license + + + alfresco component + + + angular 2 + + + typescript + + + node version + +

+ +### Node +To correctly use this component check that on your machine is running Node version 5.0.0 or higher. + +## Install + +```sh +npm install --save ng2-alfresco-tag +``` + +Components included: + +* Alfresco Tag Component + +#### Dependencies + +Add the following dependency to your index.html: + +```html + +``` + +The following component needs to be added to your systemjs.config: + +- ng2-translate +- ng2-alfresco-core +- ng2-alfresco-datatable + +Please refer to the following example to have an idea of how your systemjs.config should look like : + +https://github.com/Alfresco/alfresco-ng2-components/blob/master/ng2-components/ng2-alfresco-webscript/demo/systemjs.config.js + +#### Style +The style of this component is based on material design, so if you want to visualize it correctly you have to add the material +design dependency to your project: + +```sh +npm install --save material-design-icons material-design-lite +``` + +Also make sure you include these dependencies in your .html page: + +```html + + + + +``` + +#### Basic usage + + + +## 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 +``` + diff --git a/ng2-components/ng2-alfresco-tag/assets/license_header.txt b/ng2-components/ng2-alfresco-tag/assets/license_header.txt new file mode 100644 index 0000000000..83fd1531a3 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/assets/license_header.txt @@ -0,0 +1,16 @@ +/*! + * @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. + */ \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-tag/demo/.editorconfig b/ng2-components/ng2-alfresco-tag/demo/.editorconfig new file mode 100644 index 0000000000..8ed330c4a2 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/.editorconfig @@ -0,0 +1,10 @@ + +root = true + +[{src,scripts}/**.{ts,json,js}] +end_of_line = crlf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 diff --git a/ng2-components/ng2-alfresco-tag/demo/.gitignore b/ng2-components/ng2-alfresco-tag/demo/.gitignore new file mode 100644 index 0000000000..6afdbb8367 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/.gitignore @@ -0,0 +1,6 @@ +typings/ +node_modules/ +.idea +dist/ +!systemjs.config.js +!browser-sync-config.js diff --git a/ng2-components/ng2-alfresco-tag/demo/README.md b/ng2-components/ng2-alfresco-tag/demo/README.md new file mode 100644 index 0000000000..8d399e6fef --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/README.md @@ -0,0 +1,19 @@ +# ng2-alfresco-tag - Demo + +* To install dependencies + +```sh +$ npm install +``` + +* To provide a live demo + +```sh +$ npm run start +``` + +* To clean npm_modules and typings folder + +```sh +$ npm run clean +``` diff --git a/ng2-components/ng2-alfresco-tag/demo/index.html b/ng2-components/ng2-alfresco-tag/demo/index.html new file mode 100644 index 0000000000..ee97252ec1 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/index.html @@ -0,0 +1,39 @@ + + + + + Alfresco Angular 2 Tag - Demo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ng2-components/ng2-alfresco-tag/demo/package.json b/ng2-components/ng2-alfresco-tag/demo/package.json new file mode 100644 index 0000000000..3271a9e5c0 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/package.json @@ -0,0 +1,65 @@ +{ + "name": "ng2-alfresco-tag-demo", + "description": "Alfresco Angular2 Tag - Demo", + "version": "0.2.0", + "author": "Alfresco Software, Ltd.", + "main": "index.js", + "scripts": { + "clean": "rimraf dist node_modules typings", + "typings": "typings install", + "postinstall": "npm run typings && npm run build", + "start": "concurrently \"npm run build:w\" \"npm run server\" ", + "server": "wsrv -o -s -l", + "build": "npm run tslint && rimraf dist && tsc", + "build:w": "npm run tslint && rimraf dist && tsc -w", + "tslint": "npm run tslint-src && npm run tslint-root", + "tslint-src": "tslint -c tslint.json 'src/{,**/}**.ts'", + "tslint-root": "tslint -c tslint.json *.ts" + }, + "license": "Apache-2.0", + "dependencies": { + "@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", + "@angular/router": "3.0.0-alpha.7", + "@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", + "rxjs": "5.0.0-beta.6", + "zone.js": "0.6.12", + + "material-design-icons": "2.2.3", + "material-design-lite": "1.1.3", + + "alfresco-js-api": "^0.2.0", + + "ng2-translate": "2.2.2", + "ng2-alfresco-core": "^0.2.0", + "ng2-alfresco-datatable": "^0.2.0" + }, + "devDependencies": { + "concurrently": "2.0.0", + "rimraf": "2.5.2", + "tslint": "3.8.1", + "typescript": "1.8.10", + "typings": "1.0.4", + "wsrv": "0.1.3" + }, + "contributors": [ + { + "name": "Eugenio Romano", + "email": "eugenio.romano@alfresco.com" + } + ], + "keywords": [ + "angular2", + "typescript", + "alfresco" + ] +} diff --git a/ng2-components/ng2-alfresco-tag/demo/src/main.ts b/ng2-components/ng2-alfresco-tag/demo/src/main.ts new file mode 100644 index 0000000000..39ca262b90 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/src/main.ts @@ -0,0 +1,121 @@ +/*! + * @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 {bootstrap} from '@angular/platform-browser-dynamic'; +import {HTTP_PROVIDERS} from '@angular/http'; + +import { + ALFRESCO_CORE_PROVIDERS, + AlfrescoSettingsService, + AlfrescoAuthenticationService, + CONTEXT_MENU_DIRECTIVES +} from 'ng2-alfresco-core'; + +import {TAGCOMPONENT, TAGSERVICES} from 'ng2-alfresco-tag'; + +@Component({ + selector: 'alfresco-tag-demo', + template: ` +
+
+
+

+
+ Authentication failed to ip {{ ecmHost }} with user: admin, admin, you can still try to add a valid token to perform + operations. +
+
+
+
+
+
+
+
List Tags ECM
+
+ Tag list By Node ID + +
+
+ Tag list By Node Properties + +
+
+
+ `, + directives: [TAGCOMPONENT, CONTEXT_MENU_DIRECTIVES], + providers: [TAGSERVICES] +}) +class TagDemo implements OnInit { + + propertiesDemo: string = '{"cm:taggable": ["008e722c-bf2a-4426-832c-29d1a9b174a8", "0350ff75-badb-40e5-b7de-1091a855dd70"]}'; + + @Input() + nodeId: string = '1a0b110f-1e09-4ca2-b367-fe25e4964a4e'; + + currentPath: string = '/'; + + authenticated: boolean; + + ecmHost: string = 'http://127.0.0.1:8080'; + + token: string; + + constructor(private authService: AlfrescoAuthenticationService, + private settingsService: AlfrescoSettingsService) { + + settingsService.ecmHost = this.ecmHost; + if (this.authService.getTicket()) { + this.token = this.authService.getTicket(); + } + } + + public updateToken(): void { + localStorage.setItem('token', this.token); + } + + public updateHost(): void { + this.settingsService.ecmHost = this.ecmHost; + this.login(); + } + + ngOnInit() { + this.login(); + } + + login() { + this.authService.login('admin', 'admin', ['ECM']).subscribe( + token => { + console.log(token); + this.token = token; + this.authenticated = true; + }, + error => { + console.log(error); + this.authenticated = false; + }); + } + + logData(data) { + console.log(data); + } +} + +bootstrap(TagDemo, [ + HTTP_PROVIDERS, + ALFRESCO_CORE_PROVIDERS +]); diff --git a/ng2-components/ng2-alfresco-tag/demo/systemjs.config.js b/ng2-components/ng2-alfresco-tag/demo/systemjs.config.js new file mode 100644 index 0000000000..9ae03109fd --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/systemjs.config.js @@ -0,0 +1,57 @@ +/** + * System configuration for Angular 2 samples + * Adjust as necessary for your application needs. + */ +(function(global) { + // map tells the System loader where to look for things + var map = { + 'app': 'dist', // 'dist', + '@angular': 'node_modules/@angular', + 'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api', + 'rxjs': 'node_modules/rxjs', + + 'ng2-translate': 'node_modules/ng2-translate', + 'ng2-alfresco-core': 'node_modules/ng2-alfresco-core/dist', + 'ng2-alfresco-datatable': 'node_modules/ng2-alfresco-datatable/dist', + 'ng2-alfresco-tag': 'node_modules/ng2-alfresco-tag/dist' + }; + // packages tells the System loader how to load when no filename and/or no extension + var packages = { + 'app': { main: 'main.js', defaultExtension: 'js' }, + 'rxjs': { defaultExtension: 'js' }, + 'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }, + + 'ng2-translate': { defaultExtension: 'js' }, + 'ng2-alfresco-core': { main: 'index.js', defaultExtension: 'js' }, + 'ng2-alfresco-datatable': { main: 'index.js', defaultExtension: 'js' }, + 'ng2-alfresco-tag': { main: 'index.js', defaultExtension: 'js' } + }; + var ngPackageNames = [ + 'common', + 'compiler', + 'core', + 'http', + 'platform-browser', + 'platform-browser-dynamic', + 'router', + 'router-deprecated', + 'upgrade' + ]; + // Individual files (~300 requests): + function packIndex(pkgName) { + packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' }; + } + // Bundled (~40 requests): + function packUmd(pkgName) { + packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' }; + } + // Most environments should use UMD; some (Karma) need the individual index files + var setPackageConfig = System.packageWithIndex ? packIndex : packUmd; + // Add package entries for angular packages + ngPackageNames.forEach(setPackageConfig); + var config = { + map: map, + packages: packages + }; + System.config(config); +})(this); diff --git a/ng2-components/ng2-alfresco-tag/demo/tsconfig.json b/ng2-components/ng2-alfresco-tag/demo/tsconfig.json new file mode 100644 index 0000000000..772c3a7e75 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "system", + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "sourceMap": true, + "removeComments": true, + "declaration": true, + "outDir": "dist" + }, + "exclude": [ + "dist", + "node_modules", + "typings/main", + "typings/main.d.ts" + ] +} diff --git a/ng2-components/ng2-alfresco-tag/demo/tslint.json b/ng2-components/ng2-alfresco-tag/demo/tslint.json new file mode 100644 index 0000000000..e550ac11d4 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/tslint.json @@ -0,0 +1,124 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "arguments", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space", + "check-lowercase" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "label-undefined": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "public-before-private", + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": true, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": false, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-key": true, + "no-duplicate-variable": true, + "no-empty": true, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": true, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unreachable": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-tag/demo/typings.json b/ng2-components/ng2-alfresco-tag/demo/typings.json new file mode 100644 index 0000000000..7e0e18568d --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/typings.json @@ -0,0 +1,7 @@ +{ + "globalDependencies": { + "core-js": "registry:dt/core-js#0.0.0+20160317120654", + "jasmine": "registry:dt/jasmine#2.2.0+20160505161446", + "node": "registry:dt/node#4.0.0+20160509154515" + } +} diff --git a/ng2-components/ng2-alfresco-tag/demo/wsrv-config.json b/ng2-components/ng2-alfresco-tag/demo/wsrv-config.json new file mode 100644 index 0000000000..d8f11c2698 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/demo/wsrv-config.json @@ -0,0 +1,5 @@ +{ + "watch": [ + "node_modules/ng2-alfresco-tag/dist/**/*.{html,htm,css,js}" + ] +} diff --git a/ng2-components/ng2-alfresco-tag/index.ts b/ng2-components/ng2-alfresco-tag/index.ts new file mode 100644 index 0000000000..875973d728 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/index.ts @@ -0,0 +1,41 @@ +/*! + * @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 { TagActionsComponent } from './src/components/tag-actions.component'; +import { TagList } from './src/components/tag-list.component'; +import { TagNodeList } from './src/components/tag-node-list.component'; +import { TagService } from './src/services/tag.service'; + +export * from './src/components/tag-actions.component'; +export * from './src/components/tag-list.component'; +export * from './src/components/tag-node-list.component'; +export * from './src/services/tag.service'; + +export default { + components: [TagActionsComponent, TagList, TagNodeList] +}; + +export const TAGCOMPONENT: [any] = [ + TagActionsComponent, + TagList, + TagNodeList +]; + +export const TAGSERVICES: [any] = [ + TagService +]; + diff --git a/ng2-components/ng2-alfresco-tag/karma-test-shim.js b/ng2-components/ng2-alfresco-tag/karma-test-shim.js new file mode 100644 index 0000000000..f484dd4747 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/karma-test-shim.js @@ -0,0 +1,107 @@ +// Tun on full stack traces in errors to help debugging +Error.stackTraceLimit = Infinity; + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; + +__karma__.loaded = function() {}; + +var map = { + 'app': 'base/dist', + 'rxjs': 'base/node_modules/rxjs', + '@angular': 'base/node_modules/@angular', + 'ng2-translate' : '/base/node_modules/ng2-translate', + 'ng2-alfresco-core': '/base/node_modules/ng2-alfresco-core/dist' +}; + +var packages = { + 'app': { main: 'main.js', defaultExtension: 'js' }, + 'rxjs': { defaultExtension: 'js' }, + 'ng2-translate': { defaultExtension: 'js' }, + 'ng2-alfresco-core': { main: 'index.js', defaultExtension: 'js' } +}; + +var packageNames = [ + '@angular/common', + '@angular/compiler', + '@angular/core', + '@angular/http', + '@angular/platform-browser', + '@angular/platform-browser-dynamic', + '@angular/router', + '@angular/router-deprecated', + '@angular/testing', + '@angular/upgrade' +]; + +packageNames.forEach(function(pkgName) { + packages[pkgName] = { main: 'index.js', defaultExtension: 'js' }; +}); + +packages['base/dist'] = { + defaultExtension: 'js', + format: 'register', + map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {}) +}; + +var config = { + map: map, + packages: packages +}; + +System.config(config); + +System.import('@angular/platform-browser/src/browser/browser_adapter') + .then(function(browser_adapter) { browser_adapter.BrowserDomAdapter.makeCurrent(); }) + .then(function () { + return Promise.all([ + System.import('@angular/core/testing'), + System.import('@angular/platform-browser-dynamic/testing') + ]) + }) + .then(function (providers) { + var testing = providers[0]; + var testingBrowser = providers[1]; + + testing.setBaseTestProviders( + testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, + testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); + + }) + .then(function() { return Promise.all(resolveTestFiles()); }) + .then( + function() { + __karma__.start(); + }, + function(error) { + if(typeof __karma__.error == 'function') { + __karma__.error(error.stack || error); + }else{ + console.error(error); + } + } + ); +function createPathRecords(pathsMapping, appPath) { + var pathParts = appPath.split('/'); + var moduleName = './' + pathParts.slice(Math.max(pathParts.length - 2, 1)).join('/'); + moduleName = moduleName.replace(/\.js$/, ''); + pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath]; + return pathsMapping; +} + +function onlyAppFiles(filePath) { + return /\/base\/dist\/(?!.*\.spec\.js$).*\.js$/.test(filePath); +} + +function onlySpecFiles(path) { + return /\.spec\.js$/.test(path); +} + +function resolveTestFiles() { + return Object.keys(window.__karma__.files) // All files served by Karma. + .filter(onlySpecFiles) + .map(function(moduleName) { + // loads all spec files via their global module names (e.g. + // 'base/dist/vg-player/vg-player.spec') + return System.import(moduleName); + }); +} diff --git a/ng2-components/ng2-alfresco-tag/karma.conf.js b/ng2-components/ng2-alfresco-tag/karma.conf.js new file mode 100644 index 0000000000..c488ed18cb --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/karma.conf.js @@ -0,0 +1,88 @@ +'use strict'; + +module.exports = function (config) { + config.set({ + + basePath: '.', + + frameworks: ['jasmine-ajax', 'jasmine'], + + files: [ + // paths loaded by Karma + {pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: true}, + {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false}, + {pattern: 'node_modules/zone.js/dist/zone.js', included: true, watched: true}, + {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false}, + {pattern: 'node_modules/rxjs/**/*.map', included: false, watched: false}, + {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false}, + {pattern: 'node_modules/@angular/**/*.map', included: false, watched: false}, + {pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false}, + {pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.js', included: true, watched: false}, + + {pattern: 'node_modules/material-design-lite/material.min.js', included: true, watched: false}, + {pattern: 'karma-test-shim.js', included: true, watched: true}, + + // paths loaded via module imports + {pattern: 'dist/**/*.js', included: false, watched: true}, + {pattern: 'dist/**/*.html', included: true, served: true, watched: true}, + {pattern: 'dist/**/*.css', included: true, served: true, watched: true}, + + // paths to support debugging with source maps in dev tools + {pattern: 'src/**/*.ts', included: false, watched: false}, + {pattern: 'dist/**/*.js.map', included: false, watched: false} + ], + + // proxied base paths + proxies: { + // required for component assets fetched by Angular's compiler + '/src/': '/base/src/' + }, + + // list of files to exclude + exclude: [ + 'node_modules/**/*spec.js' + ], + + port: 9876, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + colors: true, + + autoWatch: true, + + browsers: ['Chrome'], + + // Karma plugins loaded + plugins: [ + 'karma-jasmine', + 'karma-coverage', + 'karma-jasmine-ajax', + 'karma-chrome-launcher', + 'karma-mocha-reporter', + 'karma-jasmine-html-reporter' + ], + + // Coverage reporter generates the coverage + reporters: ['mocha', 'coverage', 'kjhtml'], + + // Source files that you wanna generate coverage for. + // Do not include tests or libraries (these files will be instrumented by Istanbul) + preprocessors: { + 'dist/**/!(*spec).js': ['coverage'] + }, + + coverageReporter: { + dir: 'coverage/', + subdir: 'report', + reporters: [ + {type: 'text'}, + {type: 'text-summary'}, + {type: 'json', file: 'coverage-final.json'}, + {type: 'html'} + ] + } + }) +}; diff --git a/ng2-components/ng2-alfresco-tag/package.json b/ng2-components/ng2-alfresco-tag/package.json new file mode 100644 index 0000000000..d503697e15 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/package.json @@ -0,0 +1,93 @@ +{ + "name": "ng2-alfresco-tag", + "description": "Alfresco tag component", + "version": "0.2.0", + "author": "Alfresco Software, Ltd.", + "main": "./dist/index.js", + "typings": "./dist/index.d.ts", + "scripts": { + "postinstall": "typings install", + "clean": "rimraf dist node_modules typings", + "typings": "typings install", + "build": "npm run tslint && rimraf dist && tsc && npm run copy-dist && license-check", + "build:w": "npm run tslint && rimraf dist && npm run watch-task", + "watch-task": "concurrently \"npm run tsc:w\" \"npm run copy-dist:w\" \"license-check\"", + "tslint": "tslint -c tslint.json *.ts && tslint -c tslint.json 'src/{,**/}**.ts'", + "copy-dist": "cpx \"./src/**/*.{html,css,json,png,jpg,gif,svg}\" ./dist/src", + "copy-dist:w": "cpx \"./src/**/*.{html,css,json,png,jpg,gif,svg}\" ./dist/src -w", + "tsc": "tsc", + "tsc:w": "tsc -w", + "pretest": "npm run build", + "test": "karma start karma.conf.js --reporters mocha,coverage --single-run", + "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'" + }, + "repository": { + "type": "git", + "url": "https://github.com/Alfresco/alfresco-ng2-components.git" + }, + "bugs": { + "url": "https://github.com/Alfresco/alfresco-ng2-components/issues" + }, + "dependencies": { + "@angular/common": "2.0.0-rc.3", + "@angular/compiler": "2.0.0-rc.3", + "@angular/core": "2.0.0-rc.3", + "@angular/http": "2.0.0-rc.3", + "@angular/platform-browser": "2.0.0-rc.3", + "@angular/platform-browser-dynamic": "2.0.0-rc.3", + "@angular/router": "3.0.0-alpha.7", + "@angular/router-deprecated": "2.0.0-rc.2", + "@angular/upgrade": "2.0.0-rc.3", + "systemjs": "0.19.27", + "core-js": "^2.4.0", + "alfresco-js-api": "^0.2.0", + + "ng2-translate": "2.2.2", + "ng2-alfresco-core": "^0.2.0", + "ng2-alfresco-datatable": "^0.2.0", + "reflect-metadata": "^0.1.3", + "rxjs": "5.0.0-beta.6", + "zone.js": "^0.6.12" + }, + "devDependencies": { + "concurrently": "^2.1.0", + "coveralls": "^2.11.9", + "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-jasmine-ajax": "^0.1.13", + "karma-jasmine-html-reporter": "^0.2.0", + "karma-mocha-reporter": "^2.0.3", + "license-check": "^1.0.4", + "material-design-lite": "^1.1.3", + "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" + }, + "keywords": [ + "tag", + "alfresco-component" + ], + "license-check-config": { + "src": [ + "./dist/**/*.js" + ], + "path": "assets/license_header.txt", + "blocking": false, + "logInfo": false, + "logError": true + }, + "license": "Apache-2.0" +} diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.css b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.css new file mode 100644 index 0000000000..e4ba2f2216 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.css @@ -0,0 +1,23 @@ +.tag-container { + width: 300px; +} + +.tag-element { + padding: 0px 0px 0px 9px!important; +} + +.tag-input { + float: left; + margin-left: 11px!important; +} + +.tag-container-input{ + padding-top: 11px; + width: 190px; + float: left; + margin-right: 15px; +} + +.tag-button{ + float:left +} diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html new file mode 100644 index 0000000000..40c6b3a67e --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html @@ -0,0 +1,40 @@ + +
+
  • + + {{currentEntry.entry.tag}} + + + delete + +
  • +
  • +
    + +
    + +
  • +
    + + + + diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts new file mode 100644 index 0000000000..9f5dfcd9e9 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts @@ -0,0 +1,17 @@ +/*! + * @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. + */ + diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts new file mode 100644 index 0000000000..74c76e9077 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts @@ -0,0 +1,82 @@ +/*! + * @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, Input, Output, EventEmitter} from '@angular/core'; +import {AlfrescoAuthenticationService} from 'ng2-alfresco-core'; +import {TagService} from '../services/tag.service'; + +/** + * + * This component, provide a list of the tags relative a node with actions button to add or remove new tag + * + * @returns {TagComponent} . + */ +declare let __moduleName: string; + +@Component({ + moduleId: __moduleName, + selector: 'alfresco-tag-node-actions-list', + templateUrl: './tag-actions.component.html', + styleUrls: ['./tag-actions.component.css'] +}) +export class TagActionsComponent { + + @Input() + nodeId: string; + + @Input() + isContextMenu: boolean = false; + + @Output() + onSuccess: EventEmitter = new EventEmitter(); + + newTagName: string; + + tagsEntries: any; + + + /** + * Constructor + * @param authService + */ + constructor(public authService: AlfrescoAuthenticationService, private tagService: TagService) { + + } + + ngOnChanges(changes) { + return this.refreshTag(); + } + + refreshTag() { + this.tagService.getTagsByNodeId(this.nodeId).then((data) => { + this.tagsEntries = data; + }); + } + + addTag() { + this.tagService.addTag(this.nodeId, this.newTagName).then((res) => { + this.refreshTag(); + this.onSuccess.emit(res.entry.id); + }); + } + + removeTag(tag: string) { + this.tagService.removeTag(this.nodeId, tag).then(() => { + this.refreshTag(); + }); + } +} diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.html b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.html new file mode 100644 index 0000000000..663f5abc4c --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.html @@ -0,0 +1,11 @@ +
    +
    +
      +
    • + + {{currentEntry.entry.tag}} + +
    • +
    +
    +
    diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts new file mode 100644 index 0000000000..c9a1bd0f59 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts @@ -0,0 +1,62 @@ +/*! + * @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, Input} from '@angular/core'; +import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { TagService} from '../services/tag.service'; + +/** + * + * This component provide a list of all the tag inside the ECM + * + * @returns {TagList} . + */ +declare let __moduleName: string; + +@Component({ + moduleId: __moduleName, + selector: 'alfresco-tag-list', + templateUrl: './tag-list.component.html', + styleUrls: ['./tag.component.css'] + +}) +export class TagList { + + tagsEntries: any; + + @Input() + tagUlId: string = 'tg-id'; + + /** + * Constructor + * @param authService + */ + constructor(public authService: AlfrescoAuthenticationService, private tagService: TagService) { + + } + + ngOnInit(changes) { + return this.refreshTagEcm(); + } + + refreshTagEcm() { + + this.tagService.getAllTheTags().then((data) => { + this.tagsEntries = data; + }); + } +} diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.css b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.css new file mode 100644 index 0000000000..51eea7ab8d --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.css @@ -0,0 +1,65 @@ +.tags { + padding-left: 7px; + padding-right: 7px; +} + +.tags li { + display: inline; +} + +.tag-name { + cursor: default; + float:left; + max-height: 22px; + max-width: 100px; + background-color: #8EC44B; + -webkit-border-radius: 4px 0px 0px 4px; + -moz-border-radius: 4px 0px 0px 4px; + border-radius: 4px 0px 0px 4px; + position: relative; + color: #fff; + display: inline-block; + text-decoration: none; + font-family: arial, helvetica, sans-serif; + font-size: 14px; + zoom: 1; + line-height: 22px; + padding: 0 0px 0 10px; + margin: 4px 0px 4px 8px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.tag-delete { + cursor: pointer; + float:left; + max-height: 22px; + max-width: 30px; + background-color: #8EC44B; + -webkit-border-radius: 0px 4px 4px 0px; + -moz-border-radius: 0px 4px 4px 0px; + border-radius: 0px 4px 4px 0px; + position: relative; + color: #fff; + display: inline-block; + text-decoration: none; + font-family: arial, helvetica, sans-serif; + font-size: 14px; + zoom: 1; + line-height: 22px; + padding: 0 4px 0 6px; + margin: 4px 4px 4px 0px; + white-space: nowrap; + overflow: hidden; +} + + +.tag-delete:hover{ + color: lightgray; +} + + +.delete-icon{ + font-size: 22px!important; +} diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.html b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.html new file mode 100644 index 0000000000..7b7a44a923 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.html @@ -0,0 +1,8 @@ +
    + +
    diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts new file mode 100644 index 0000000000..f3025bd39f --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts @@ -0,0 +1,75 @@ +/*! + * @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, Input} from '@angular/core'; +import {AlfrescoAuthenticationService} from 'ng2-alfresco-core'; +import {TagService} from '../services/tag.service'; + +/** + * + * This component, ShowNodeTag a list of the tag on relative a node + * + * @returns {TagNodeList} . + */ +declare let __moduleName: string; + +@Component({ + moduleId: __moduleName, + selector: 'alfresco-tag-node-list', + templateUrl: './tag-node-list.component.html', + styleUrls: ['./tag-node-list.component.css'] +}) +export class TagNodeList { + + @Input() + nodeId: string; + + @Input() + properties: string; + + tagsEntries: any; + + /** + * Constructor + * @param authService + */ + constructor(public authService: AlfrescoAuthenticationService, private tagService: TagService) { + + } + + ngOnChanges(changes) { + return this.refreshTag(); + } + + refreshTag() { + if (this.nodeId) { + this.tagService.getTagsByNodeId(this.nodeId).then((data) => { + this.tagsEntries = data; + }); + } else if (this.properties) { + this.tagService.getTagsByProperties(this.properties).then((data) => { + this.tagsEntries = data; + }); + } + } + + removeTag(tag: string) { + this.tagService.removeTag(this.nodeId, tag).then(() => { + this.refreshTag(); + }); + } +} diff --git a/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts b/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts new file mode 100644 index 0000000000..ee1db27d9c --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts @@ -0,0 +1,142 @@ +/*! + * @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 {Injectable} from '@angular/core'; +import {AlfrescoAuthenticationService} from 'ng2-alfresco-core'; + +/** + * + * This component, provide a list of the tags relative a node with actions button to add or remove new tag + * + * @returns {TagComponent} . + */ +declare let __moduleName: string; + +@Injectable() +export class TagService { + + cacheTagList: any = []; + + promiseCache: any; + + /** + * Constructor + * @param authService + */ + constructor(public authService: AlfrescoAuthenticationService) { + this.promiseCache = new Promise((resolve) => { + this.getAllTheTags().then((data) => { + this.cacheTagList = data; + resolve(data); + }); + }); + } + + getTagsByProperties(properties: string) { + return new Promise((resolve) => { + if (!this.cacheTagList) { + this.promiseCache.then((data) => { + this.cacheTagList = data; + resolve(this._associateTagByNodeProperties(properties, data)); + }); + } else { + resolve(this._associateTagByNodeProperties(properties, this.cacheTagList)); + } + }); + } + + _associateTagByNodeProperties(properties: any, tagList: any) { + let tagsArray = []; + if (properties) { + try { + let jsonProps; + + if (typeof properties !== 'object') { + jsonProps = JSON.parse(properties); + } else { + jsonProps = properties; + } + + if (jsonProps.hasOwnProperty('cm:taggable')) { + jsonProps['cm:taggable'].forEach((currentTagId) => { + if (tagList && tagList.length > 0) { + let tag = tagList.filter((currentCacheTag) => { + if (currentCacheTag.entry.id === currentTagId) { + return currentCacheTag.entry; + } + }); + if (tag && tag.length > 0) { + tagsArray.push(tag[0]); + } + } + }); + } + } catch (error) { + console.log('error' + error); + } + } + return tagsArray; + } + + getTagsByNodeId(nodeId: string): any { + return new Promise((resolve, reject) => { + this.authService.getAlfrescoApi().core.tagsApi.getNodeTags(nodeId).then((data) => { + resolve(data.list.entries); + }, function (error) { + console.log('Error' + error); + reject(); + }); + }); + } + + getAllTheTags() { + return new Promise((resolve, reject) => { + this.authService.getAlfrescoApi().core.tagsApi.getTags().then((data) => { + resolve(data.list.entries); + }, function (error) { + console.log('Error' + error); + reject(); + }); + }); + } + + addTag(nodeId: string, tagName: string): any { + return new Promise((resolve, reject) => { + let alfrescoApi = this.authService.getAlfrescoApi(); + let tagBody = new alfrescoApi.core.TagBody(); + tagBody.tag = tagName; + this.authService.getAlfrescoApi().core.tagsApi.addTag(nodeId, tagBody).then((res) => { + this.cacheTagList.push(res); + resolve(res); + }, function (error) { + console.log('Error' + error); + reject(); + }); + }); + } + + removeTag(nodeId: string, tag: string): any { + return new Promise((resolve, reject) => { + this.authService.getAlfrescoApi().core.tagsApi.removeTag(nodeId, tag).then(() => { + resolve(); + }, function (error) { + console.log('Error' + error); + reject(); + }); + }); + } +} diff --git a/ng2-components/ng2-alfresco-tag/tsconfig.json b/ng2-components/ng2-alfresco-tag/tsconfig.json new file mode 100644 index 0000000000..e4d2ae201a --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "system", + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "sourceMap": true, + "removeComments": true, + "declaration": true, + "noLib": false, + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "noImplicitAny": false, + "noImplicitReturns": false, + "noImplicitUseStrict": false, + "noFallthroughCasesInSwitch": true, + "outDir": "dist" + }, + "exclude": [ + "demo", + "node_modules", + "typings/main", + "typings/main.d.ts", + "dist" + ] +} diff --git a/ng2-components/ng2-alfresco-tag/tslint.json b/ng2-components/ng2-alfresco-tag/tslint.json new file mode 100644 index 0000000000..ba706079f4 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/tslint.json @@ -0,0 +1,121 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "label-undefined": true, + "max-line-length": [ + true, + 180 + ], + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": false, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": false, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-key": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": true, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unreachable": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module", + "check-decl" + ] + } +} diff --git a/ng2-components/ng2-alfresco-tag/typings.json b/ng2-components/ng2-alfresco-tag/typings.json new file mode 100644 index 0000000000..7e0e18568d --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/typings.json @@ -0,0 +1,7 @@ +{ + "globalDependencies": { + "core-js": "registry:dt/core-js#0.0.0+20160317120654", + "jasmine": "registry:dt/jasmine#2.2.0+20160505161446", + "node": "registry:dt/node#4.0.0+20160509154515" + } +} From 0ee2a1654c3d31c7788d296235931bcbf976dee7 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Mon, 5 Sep 2016 13:56:35 +0200 Subject: [PATCH 2/9] improve test service --- ng2-components/ng2-alfresco-tag/README.md | 3 +- .../ng2-alfresco-tag/demo/package.json | 7 +- .../ng2-alfresco-tag/demo/src/main.ts | 4 +- .../ng2-alfresco-tag/demo/systemjs.config.js | 2 - ng2-components/ng2-alfresco-tag/karma.conf.js | 4 + ng2-components/ng2-alfresco-tag/package.json | 7 +- .../components/tag-actions.component.spec.ts | 36 ++++++ .../src/components/tag-actions.component.ts | 1 - .../src/components/tag-list.component.spec.ts | 53 ++++++++ .../src/components/tag-list.component.ts | 3 +- .../tag-node-list.component.spec.ts | 60 +++++++++ .../src/components/tag-node-list.component.ts | 22 +--- .../src/services/tag.service.spec.ts | 114 +++++++++++++++++ .../src/services/tag.service.ts | 119 ++++-------------- .../src/webscript.component.spec.ts | 3 +- 15 files changed, 305 insertions(+), 133 deletions(-) create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts create mode 100644 ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts create mode 100644 ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts diff --git a/ng2-components/ng2-alfresco-tag/README.md b/ng2-components/ng2-alfresco-tag/README.md index a9be7dd0c5..acc53e0444 100644 --- a/ng2-components/ng2-alfresco-tag/README.md +++ b/ng2-components/ng2-alfresco-tag/README.md @@ -56,11 +56,10 @@ The following component needs to be added to your systemjs.config: - ng2-translate - ng2-alfresco-core -- ng2-alfresco-datatable Please refer to the following example to have an idea of how your systemjs.config should look like : -https://github.com/Alfresco/alfresco-ng2-components/blob/master/ng2-components/ng2-alfresco-webscript/demo/systemjs.config.js +https://github.com/Alfresco/alfresco-ng2-components/blob/master/ng2-components/ng2-alfresco-tag/demo/systemjs.config.js #### Style The style of this component is based on material design, so if you want to visualize it correctly you have to add the material diff --git a/ng2-components/ng2-alfresco-tag/demo/package.json b/ng2-components/ng2-alfresco-tag/demo/package.json index 3271a9e5c0..05f8895f5a 100644 --- a/ng2-components/ng2-alfresco-tag/demo/package.json +++ b/ng2-components/ng2-alfresco-tag/demo/package.json @@ -1,7 +1,7 @@ { "name": "ng2-alfresco-tag-demo", "description": "Alfresco Angular2 Tag - Demo", - "version": "0.2.0", + "version": "0.3.0", "author": "Alfresco Software, Ltd.", "main": "index.js", "scripts": { @@ -37,11 +37,10 @@ "material-design-icons": "2.2.3", "material-design-lite": "1.1.3", - "alfresco-js-api": "^0.2.0", + "alfresco-js-api": "^0.3.0", "ng2-translate": "2.2.2", - "ng2-alfresco-core": "^0.2.0", - "ng2-alfresco-datatable": "^0.2.0" + "ng2-alfresco-core": "^0.3.0" }, "devDependencies": { "concurrently": "2.0.0", diff --git a/ng2-components/ng2-alfresco-tag/demo/src/main.ts b/ng2-components/ng2-alfresco-tag/demo/src/main.ts index 39ca262b90..e6300c6a1c 100644 --- a/ng2-components/ng2-alfresco-tag/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-tag/demo/src/main.ts @@ -33,8 +33,8 @@ import {TAGCOMPONENT, TAGSERVICES} from 'ng2-alfresco-tag'; template: `

    -
    -

    +
    +

    Authentication failed to ip {{ ecmHost }} with user: admin, admin, you can still try to add a valid token to perform operations. diff --git a/ng2-components/ng2-alfresco-tag/demo/systemjs.config.js b/ng2-components/ng2-alfresco-tag/demo/systemjs.config.js index 9ae03109fd..a14e75e0ba 100644 --- a/ng2-components/ng2-alfresco-tag/demo/systemjs.config.js +++ b/ng2-components/ng2-alfresco-tag/demo/systemjs.config.js @@ -12,7 +12,6 @@ 'ng2-translate': 'node_modules/ng2-translate', 'ng2-alfresco-core': 'node_modules/ng2-alfresco-core/dist', - 'ng2-alfresco-datatable': 'node_modules/ng2-alfresco-datatable/dist', 'ng2-alfresco-tag': 'node_modules/ng2-alfresco-tag/dist' }; // packages tells the System loader how to load when no filename and/or no extension @@ -23,7 +22,6 @@ 'ng2-translate': { defaultExtension: 'js' }, 'ng2-alfresco-core': { main: 'index.js', defaultExtension: 'js' }, - 'ng2-alfresco-datatable': { main: 'index.js', defaultExtension: 'js' }, 'ng2-alfresco-tag': { main: 'index.js', defaultExtension: 'js' } }; var ngPackageNames = [ diff --git a/ng2-components/ng2-alfresco-tag/karma.conf.js b/ng2-components/ng2-alfresco-tag/karma.conf.js index c488ed18cb..c84efe0a76 100644 --- a/ng2-components/ng2-alfresco-tag/karma.conf.js +++ b/ng2-components/ng2-alfresco-tag/karma.conf.js @@ -17,6 +17,10 @@ module.exports = function (config) { {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false}, {pattern: 'node_modules/@angular/**/*.map', included: false, watched: false}, {pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false}, + {pattern: 'node_modules/ng2-alfresco-datatable/dist/**/*.js', included: false, served: true, watched: false}, + {pattern: 'node_modules/ng2-alfresco-datatable/dist/**/*.html', included: false, served: true, watched: false}, + {pattern: 'node_modules/ng2-alfresco-datatable/dist/**/*.css', included: false, served: true, watched: false}, + {pattern: 'node_modules/ng2-translate/**/*.js', included: false, served: true, watched: false}, {pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.js', included: true, watched: false}, {pattern: 'node_modules/material-design-lite/material.min.js', included: true, watched: false}, diff --git a/ng2-components/ng2-alfresco-tag/package.json b/ng2-components/ng2-alfresco-tag/package.json index d503697e15..780714bdf0 100644 --- a/ng2-components/ng2-alfresco-tag/package.json +++ b/ng2-components/ng2-alfresco-tag/package.json @@ -1,7 +1,7 @@ { "name": "ng2-alfresco-tag", "description": "Alfresco tag component", - "version": "0.2.0", + "version": "0.3.0", "author": "Alfresco Software, Ltd.", "main": "./dist/index.js", "typings": "./dist/index.d.ts", @@ -44,11 +44,10 @@ "@angular/upgrade": "2.0.0-rc.3", "systemjs": "0.19.27", "core-js": "^2.4.0", - "alfresco-js-api": "^0.2.0", + "alfresco-js-api": "^0.3.0", "ng2-translate": "2.2.2", - "ng2-alfresco-core": "^0.2.0", - "ng2-alfresco-datatable": "^0.2.0", + "ng2-alfresco-core": "^0.3.0", "reflect-metadata": "^0.1.3", "rxjs": "5.0.0-beta.6", "zone.js": "^0.6.12" diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts index 9f5dfcd9e9..78dbc712c5 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts @@ -15,3 +15,39 @@ * limitations under the License. */ + +import { describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { TagService } from '../services/tag.service'; + +declare let jasmine: any; + +describe('Tag actions', () => { + + let service; + + beforeEachProviders(() => { + + return [ + AlfrescoSettingsService, + AlfrescoAuthenticationService, + TagService + ]; + }); + + beforeEach(inject([TagService], (tagService: TagService) => { + service = tagService; + })); + + describe('Content tests', () => { + + beforeEach(() => { + jasmine.Ajax.install(); + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + }); +}); diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts index 74c76e9077..bd0d7d50e4 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts @@ -48,7 +48,6 @@ export class TagActionsComponent { tagsEntries: any; - /** * Constructor * @param authService diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts new file mode 100644 index 0000000000..49b0c333d9 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.spec.ts @@ -0,0 +1,53 @@ +/*! + * @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 { describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { TagService } from '../services/tag.service'; + +declare let jasmine: any; + +describe('Tag list', () => { + + let service; + + beforeEachProviders(() => { + + return [ + AlfrescoSettingsService, + AlfrescoAuthenticationService, + TagService + ]; + }); + + beforeEach(inject([TagService], (tagService: TagService) => { + service = tagService; + })); + + describe('Content tests', () => { + + beforeEach(() => { + jasmine.Ajax.install(); + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + }); +}); diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts index c9a1bd0f59..9e48474af1 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-list.component.ts @@ -54,8 +54,7 @@ export class TagList { } refreshTagEcm() { - - this.tagService.getAllTheTags().then((data) => { + this.tagService.getAllTheTags().subscribe((data) => { this.tagsEntries = data; }); } diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts new file mode 100644 index 0000000000..7730604026 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.spec.ts @@ -0,0 +1,60 @@ +/*! + * @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 { describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { TagService } from '../services/tag.service'; + +declare let jasmine: any; + +describe('Tag relative node list', () => { + + let service; + + beforeEachProviders(() => { + + return [ + AlfrescoSettingsService, + AlfrescoAuthenticationService, + TagService + ]; + }); + + describe('Content tests', () => { + + beforeEach(() => { + jasmine.Ajax.install(); + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + it('getTagsByNodeId catch errors call', (done) => { + service.getTagsByNodeId('fake-node-id', 'fake-tag').subscribe(() => { + }, () => { + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 403 + }); + }); + + }); +}); diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts index f3025bd39f..05960c8f7a 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-node-list.component.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import {Component, Input} from '@angular/core'; -import {AlfrescoAuthenticationService} from 'ng2-alfresco-core'; -import {TagService} from '../services/tag.service'; +import { Component, Input } from '@angular/core'; +import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { TagService } from '../services/tag.service'; /** * @@ -38,9 +38,6 @@ export class TagNodeList { @Input() nodeId: string; - @Input() - properties: string; - tagsEntries: any; /** @@ -48,7 +45,6 @@ export class TagNodeList { * @param authService */ constructor(public authService: AlfrescoAuthenticationService, private tagService: TagService) { - } ngOnChanges(changes) { @@ -56,15 +52,9 @@ export class TagNodeList { } refreshTag() { - if (this.nodeId) { - this.tagService.getTagsByNodeId(this.nodeId).then((data) => { - this.tagsEntries = data; - }); - } else if (this.properties) { - this.tagService.getTagsByProperties(this.properties).then((data) => { - this.tagsEntries = data; - }); - } + this.tagService.getTagsByNodeId(this.nodeId).then((data) => { + this.tagsEntries = data; + }); } removeTag(tag: string) { diff --git a/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts b/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts new file mode 100644 index 0000000000..61e0621be7 --- /dev/null +++ b/ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts @@ -0,0 +1,114 @@ +/*! + * @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 { describe, expect, it, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { TagService } from './tag.service'; + +declare let jasmine: any; + +describe('Tag service', () => { + + let service; + + beforeEachProviders(() => { + + return [ + AlfrescoSettingsService, + AlfrescoAuthenticationService, + TagService + ]; + }); + + beforeEach(inject([TagService], (tagService: TagService) => { + service = tagService; + })); + + describe('Content tests', () => { + + beforeEach(() => { + jasmine.Ajax.install(); + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + it('removeTag should perform a call against the server', (done) => { + service.removeTag('fake-node-id', 'fake-tag').subscribe(() => { + expect(jasmine.Ajax.requests.mostRecent().method).toBe('DELETE'); + expect(jasmine.Ajax.requests.mostRecent().url) + .toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags/fake-tag'); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200 + }); + }); + + it('addTag should perform a call against the server', (done) => { + service.addTag('fake-node-id', 'fake-tag').subscribe(() => { + expect(jasmine.Ajax.requests.mostRecent().method).toBe('POST'); + expect(jasmine.Ajax.requests.mostRecent().url) + .toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags'); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200 + }); + }); + + it('getAllTheTags should perform a call against the server', (done) => { + service.getAllTheTags('fake-node-id', 'fake-tag').subscribe(() => { + expect(jasmine.Ajax.requests.mostRecent().method).toBe('GET'); + expect(jasmine.Ajax.requests.mostRecent().url) + .toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/tags'); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200 + }); + }); + + it('getTagsByNodeId should perform a call against the server', (done) => { + service.getTagsByNodeId('fake-node-id', 'fake-tag').subscribe(() => { + expect(jasmine.Ajax.requests.mostRecent().method).toBe('GET'); + expect(jasmine.Ajax.requests.mostRecent().url) + .toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags'); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200 + }); + }); + + it('getTagsByNodeId catch errors call', (done) => { + service.getTagsByNodeId('fake-node-id', 'fake-tag').subscribe(() => { + }, () => { + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 403 + }); + }); + }); +}); diff --git a/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts b/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts index ee1db27d9c..528f1c18e0 100644 --- a/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts +++ b/ng2-components/ng2-alfresco-tag/src/services/tag.service.ts @@ -15,128 +15,51 @@ * limitations under the License. */ -import {Injectable} from '@angular/core'; -import {AlfrescoAuthenticationService} from 'ng2-alfresco-core'; +import { Injectable } from '@angular/core'; +import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { Observable } from 'rxjs/Rx'; /** - * - * This component, provide a list of the tags relative a node with actions button to add or remove new tag - * - * @returns {TagComponent} . + * @returns {TagService} . */ declare let __moduleName: string; @Injectable() export class TagService { - cacheTagList: any = []; - - promiseCache: any; - /** * Constructor * @param authService */ constructor(public authService: AlfrescoAuthenticationService) { - this.promiseCache = new Promise((resolve) => { - this.getAllTheTags().then((data) => { - this.cacheTagList = data; - resolve(data); - }); - }); - } - - getTagsByProperties(properties: string) { - return new Promise((resolve) => { - if (!this.cacheTagList) { - this.promiseCache.then((data) => { - this.cacheTagList = data; - resolve(this._associateTagByNodeProperties(properties, data)); - }); - } else { - resolve(this._associateTagByNodeProperties(properties, this.cacheTagList)); - } - }); - } - - _associateTagByNodeProperties(properties: any, tagList: any) { - let tagsArray = []; - if (properties) { - try { - let jsonProps; - - if (typeof properties !== 'object') { - jsonProps = JSON.parse(properties); - } else { - jsonProps = properties; - } - - if (jsonProps.hasOwnProperty('cm:taggable')) { - jsonProps['cm:taggable'].forEach((currentTagId) => { - if (tagList && tagList.length > 0) { - let tag = tagList.filter((currentCacheTag) => { - if (currentCacheTag.entry.id === currentTagId) { - return currentCacheTag.entry; - } - }); - if (tag && tag.length > 0) { - tagsArray.push(tag[0]); - } - } - }); - } - } catch (error) { - console.log('error' + error); - } - } - return tagsArray; } getTagsByNodeId(nodeId: string): any { - return new Promise((resolve, reject) => { - this.authService.getAlfrescoApi().core.tagsApi.getNodeTags(nodeId).then((data) => { - resolve(data.list.entries); - }, function (error) { - console.log('Error' + error); - reject(); - }); - }); + return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.getNodeTags(nodeId)) + .catch(this.handleError); } getAllTheTags() { - return new Promise((resolve, reject) => { - this.authService.getAlfrescoApi().core.tagsApi.getTags().then((data) => { - resolve(data.list.entries); - }, function (error) { - console.log('Error' + error); - reject(); - }); - }); + return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.getTags()) + .catch(this.handleError); } addTag(nodeId: string, tagName: string): any { - return new Promise((resolve, reject) => { - let alfrescoApi = this.authService.getAlfrescoApi(); - let tagBody = new alfrescoApi.core.TagBody(); - tagBody.tag = tagName; - this.authService.getAlfrescoApi().core.tagsApi.addTag(nodeId, tagBody).then((res) => { - this.cacheTagList.push(res); - resolve(res); - }, function (error) { - console.log('Error' + error); - reject(); - }); - }); + let alfrescoApi = this.authService.getAlfrescoApi(); + let tagBody = new alfrescoApi.core.TagBody(); + tagBody.tag = tagName; + + return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.addTag(nodeId, tagBody)) + .catch(this.handleError); } removeTag(nodeId: string, tag: string): any { - return new Promise((resolve, reject) => { - this.authService.getAlfrescoApi().core.tagsApi.removeTag(nodeId, tag).then(() => { - resolve(); - }, function (error) { - console.log('Error' + error); - reject(); - }); - }); + return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.removeTag(nodeId, tag)) + .catch(this.handleError); + } + + private handleError(error: any) { + console.error(error); + return Observable.throw(error || 'Server error'); } } diff --git a/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts b/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts index fd11aa8534..c212100195 100644 --- a/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts +++ b/ng2-components/ng2-alfresco-webscript/src/webscript.component.spec.ts @@ -85,8 +85,7 @@ describe('Test ng2-alfresco-webscript', () => { component.ngOnChanges().then(() => { webscriptComponentFixture.detectChanges(); - let request = jasmine.Ajax.requests.mostRecent(); - expect(request.url).toBe('http://localhost:8080/alfresco/service/sample/folder/Company%20Home'); + expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://localhost:8080/alfresco/service/sample/folder/Company%20Home'); done(); }); From 530ca19b1d5e36a34e325dea014230114e08c24e Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Mon, 5 Sep 2016 14:07:16 +0200 Subject: [PATCH 3/9] update scripts build --- .travis.yml | 2 ++ README.md | 1 + appveyor.yml | 1 + ng2-components/README.md | 1 + ng2-components/update.sh | 3 +++ scripts/npm-build-all.sh | 3 ++- scripts/npm-check.sh | 3 ++- scripts/npm-clean.sh | 3 ++- scripts/npm-link-demo-shell.sh | 11 ++++++++++- scripts/npm-publish.sh | 3 ++- scripts/update-version.sh | 6 ++++-- 11 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 871656636c..9c3f5bad81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,7 @@ env: - MODULE=ng2-alfresco-upload - MODULE=ng2-alfresco-viewer - MODULE=ng2-alfresco-webscript + - MODULE=ng2-alfresco-tag - MODULE=ng2-activiti-form - MODULE=ng2-activiti-tasklist - MODULE=ng2-activiti-processlist @@ -79,3 +80,4 @@ cache: - ng2-components/ng2-alfresco-upload/node_modules - ng2-components/ng2-alfresco-viewer/node_modules - ng2-components/ng2-alfresco-webscript/node_modules + - ng2-components/ng2-alfresco-tag/node_modules diff --git a/README.md b/README.md index 29820028e0..a079dca669 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ The following is a list of some of the components that you can use when building - [Login](ng2-components/ng2-alfresco-login/README.md) - [Upload](ng2-components/ng2-alfresco-upload/README.md) - [Webscript viewer](ng2-components/ng2-alfresco-webscript/README.md) +- [Tag list and controls](ng2-components/ng2-alfresco-tag/README.md) You can browse all the components at the following [page](http://devproducts.alfresco.com/). diff --git a/appveyor.yml b/appveyor.yml index 6487d8bafb..6710861642 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,6 +14,7 @@ environment: - COMPONENT_NAME: ng2-alfresco-search - COMPONENT_NAME: ng2-alfresco-upload - COMPONENT_NAME: ng2-alfresco-viewer + - COMPONENT_NAME: ng2-alfresco-tag - COMPONENT_NAME: ng2-alfresco-webscript - COMPONENT_NAME: ng2-activiti-form - COMPONENT_NAME: ng2-activiti-tasklist diff --git a/ng2-components/README.md b/ng2-components/README.md index 6189597f42..f20200fb5d 100644 --- a/ng2-components/README.md +++ b/ng2-components/README.md @@ -43,6 +43,7 @@ - [Login](ng2-alfresco-login/README.md) - [Upload](ng2-alfresco-upload/README.md) - [Webscript Viewer](ng2-components/ng2-alfresco-webscript/README.md) +- [Tag list and controls](ng2-components/ng2-alfresco-tag/README.md) ## BPM components diff --git a/ng2-components/update.sh b/ng2-components/update.sh index ee0a6c36ba..df9f5c4548 100755 --- a/ng2-components/update.sh +++ b/ng2-components/update.sh @@ -31,3 +31,6 @@ (cd ng2-alfresco-webscript; npm update;) (cd ng2-alfresco-webscript/demo; npm update;) + +(cd ng2-alfresco-tag; npm update;) +(cd ng2-alfresco-tag/demo; npm update;) diff --git a/scripts/npm-build-all.sh b/scripts/npm-build-all.sh index 96bc696f73..7d6aa0edf2 100755 --- a/scripts/npm-build-all.sh +++ b/scripts/npm-build-all.sh @@ -13,7 +13,8 @@ for PACKAGE in \ ng2-alfresco-search \ ng2-alfresco-upload \ ng2-alfresco-viewer \ - ng2-alfresco-webscript + ng2-alfresco-webscript \ + ng2-alfresco-tag do DESTDIR="$DIR/../ng2-components/${PACKAGE}" echo "====== build components : ${PACKAGE} =====" diff --git a/scripts/npm-check.sh b/scripts/npm-check.sh index 6f6d1cbf1e..3819da367e 100755 --- a/scripts/npm-check.sh +++ b/scripts/npm-check.sh @@ -17,7 +17,8 @@ for PACKAGE in \ ng2-alfresco-search \ ng2-alfresco-upload \ ng2-alfresco-viewer \ - ng2-alfresco-webscript + ng2-alfresco-webscript \ + ng2-alfresco-tag do echo "====== Check component: ${PACKAGE} =====" cd "$DIR/../ng2-components/${PACKAGE}" diff --git a/scripts/npm-clean.sh b/scripts/npm-clean.sh index c1d492be4c..f4d1e78ebc 100755 --- a/scripts/npm-clean.sh +++ b/scripts/npm-clean.sh @@ -13,7 +13,8 @@ for PACKAGE in \ ng2-alfresco-search \ ng2-alfresco-upload \ ng2-alfresco-viewer \ - ng2-alfresco-webscript + ng2-alfresco-webscript \ + ng2-alfresco-tag do echo "====== clean component: ${PACKAGE} =====" cd "$DIR/../ng2-components/${PACKAGE}" diff --git a/scripts/npm-link-demo-shell.sh b/scripts/npm-link-demo-shell.sh index 1f7416b3fd..1254b822b8 100755 --- a/scripts/npm-link-demo-shell.sh +++ b/scripts/npm-link-demo-shell.sh @@ -73,6 +73,14 @@ npm link npm run typings npm run build +#LINK TAG +echo "====== linking component: ng2-alfresco-tag =====" +cd "$DIR/../ng2-components/ng2-alfresco-tag" +npm link ng2-alfresco-core +npm link +npm run typings +npm run build + #LINK ALL THE OTHERS COMPONENTS for PACKAGE in \ ng2-alfresco-login \ @@ -102,7 +110,8 @@ for PACKAGE in \ ng2-alfresco-search \ ng2-alfresco-upload \ ng2-alfresco-viewer \ - ng2-alfresco-webscript + ng2-alfresco-webscript \ + ng2-alfresco-tag do DESTDIR="$DIR/../ng2-components/${PACKAGE}" echo "====== demo shell linking: ${PACKAGE} =====" diff --git a/scripts/npm-publish.sh b/scripts/npm-publish.sh index 98f4954326..f72018f253 100755 --- a/scripts/npm-publish.sh +++ b/scripts/npm-publish.sh @@ -15,7 +15,8 @@ for PACKAGE in \ ng2-alfresco-search \ ng2-alfresco-upload \ ng2-alfresco-viewer \ - ng2-alfresco-webscript + ng2-alfresco-webscript \ + ng2-alfresco-tag do DESTDIR="$DIR/../ng2-components/${PACKAGE}" echo "====== PUBLISHING: ${DESTDIR} =====" diff --git a/scripts/update-version.sh b/scripts/update-version.sh index 11e116989e..c28f515f4e 100755 --- a/scripts/update-version.sh +++ b/scripts/update-version.sh @@ -25,7 +25,8 @@ for PACKAGE in \ ng2-alfresco-search \ ng2-alfresco-upload \ ng2-alfresco-viewer \ - ng2-alfresco-webscript + ng2-alfresco-webscript \ + ng2-alfresco-tag do DESTDIR="$DIR/../ng2-components/${PACKAGE}" echo "====== UPDATE VERSION of ${PACKAGE} to ${VERSION} version in all the package.json ======" @@ -43,7 +44,8 @@ for PACKAGE in \ ng2-alfresco-search \ ng2-alfresco-upload \ ng2-alfresco-viewer \ - ng2-alfresco-webscript + ng2-alfresco-webscript \ + ng2-alfresco-tag do DESTDIR="$DIR/../ng2-components/${PACKAGE}" echo "====== UPDATE VERSION OF ${PACKAGE} to ${VERSION} version ======" From 8dfef264e3dfd99a51a67985e45fcefed78446cc Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Mon, 5 Sep 2016 16:10:59 +0200 Subject: [PATCH 4/9] demo tag --- .../ng2-alfresco-tag/demo/src/main.ts | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/ng2-components/ng2-alfresco-tag/demo/src/main.ts b/ng2-components/ng2-alfresco-tag/demo/src/main.ts index e6300c6a1c..6013e23be4 100644 --- a/ng2-components/ng2-alfresco-tag/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-tag/demo/src/main.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import {Component, OnInit, Input} from '@angular/core'; -import {bootstrap} from '@angular/platform-browser-dynamic'; -import {HTTP_PROVIDERS} from '@angular/http'; +import { Component, OnInit, Input } from '@angular/core'; +import { bootstrap } from '@angular/platform-browser-dynamic'; +import { HTTP_PROVIDERS } from '@angular/http'; import { ALFRESCO_CORE_PROVIDERS, @@ -26,17 +26,17 @@ import { CONTEXT_MENU_DIRECTIVES } from 'ng2-alfresco-core'; -import {TAGCOMPONENT, TAGSERVICES} from 'ng2-alfresco-tag'; +import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag'; @Component({ selector: 'alfresco-tag-demo', template: ` -
    -
    +
    +

    -

    +

    - Authentication failed to ip {{ ecmHost }} with user: admin, admin, you can still try to add a valid token to perform + Authentication failed to ip {{ ecmHost }} with user: admin, admin, you can still try to add a valid ticket to perform operations.

    @@ -73,35 +73,28 @@ class TagDemo implements OnInit { ecmHost: string = 'http://127.0.0.1:8080'; - token: string; + ticket: string; constructor(private authService: AlfrescoAuthenticationService, private settingsService: AlfrescoSettingsService) { settingsService.ecmHost = this.ecmHost; - if (this.authService.getTicket()) { - this.token = this.authService.getTicket(); + settingsService.setProviders('ECM'); + + if (this.authService.getTicketEcm()) { + this.ticket = this.authService.getTicketEcm(); } } - public updateToken(): void { - localStorage.setItem('token', this.token); - } - - public updateHost(): void { - this.settingsService.ecmHost = this.ecmHost; - this.login(); - } - ngOnInit() { this.login(); } login() { - this.authService.login('admin', 'admin', ['ECM']).subscribe( - token => { - console.log(token); - this.token = token; + this.authService.login('admin', 'admin').subscribe( + ticket => { + console.log(ticket); + this.ticket = this.authService.getTicketEcm(); this.authenticated = true; }, error => { @@ -110,11 +103,19 @@ class TagDemo implements OnInit { }); } + public updateTicket(): void { + localStorage.setItem('ticket-ECM', this.ticket); + } + + public updateHost(): void { + this.settingsService.ecmHost = this.ecmHost; + this.login(); + } + logData(data) { console.log(data); } } - bootstrap(TagDemo, [ HTTP_PROVIDERS, ALFRESCO_CORE_PROVIDERS From 053855afd1f30dc84232a850d91628c141b4c395 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Mon, 5 Sep 2016 19:05:35 +0200 Subject: [PATCH 5/9] improve code coverage --- .../alfresco-search.component.spec.ts | 8 +- .../ng2-alfresco-tag/demo/src/main.ts | 12 +- .../src/components/tag-actions.component.html | 29 +++-- .../components/tag-actions.component.spec.ts | 103 ++++++++++++++++-- .../src/components/tag-actions.component.ts | 22 ++-- .../src/components/tag-list.component.html | 6 +- .../src/components/tag-list.component.spec.ts | 58 ++++++++-- .../src/components/tag-list.component.ts | 15 ++- .../components/tag-node-list.component.html | 6 +- .../tag-node-list.component.spec.ts | 79 ++++++++++++-- .../src/components/tag-node-list.component.ts | 12 +- .../src/webscript.component.spec.ts | 3 +- 12 files changed, 272 insertions(+), 81 deletions(-) diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts index 055a6f043a..84de11eaf2 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.spec.ts @@ -43,7 +43,7 @@ describe('AlfrescoSearchComponent', () => { entry: { id: '123', name: 'MyDoc', - isFile : true, + isFile: true, content: { mimetype: 'text/plain' }, @@ -128,8 +128,8 @@ describe('AlfrescoSearchComponent', () => { component.resultsEmitter.subscribe(x => { alfrescoSearchComponentFixture.detectChanges(); - expect( element.querySelector('#result_user_0').innerHTML).toBe('John Doe'); - expect( element.querySelector('#result_name_0').innerHTML).toBe('MyDoc'); + expect(element.querySelector('#result_user_0').innerHTML).toBe('John Doe'); + expect(element.querySelector('#result_name_0').innerHTML).toBe('MyDoc'); done(); }); @@ -144,7 +144,7 @@ describe('AlfrescoSearchComponent', () => { it('should display no result if no result are returned', (done) => { component.resultsEmitter.subscribe(x => { alfrescoSearchComponentFixture.detectChanges(); - expect( element.querySelector('#search_no_result')).not.toBe(null); + expect(element.querySelector('#search_no_result')).not.toBe(null); done(); }); diff --git a/ng2-components/ng2-alfresco-tag/demo/src/main.ts b/ng2-components/ng2-alfresco-tag/demo/src/main.ts index 6013e23be4..2e1241c0ff 100644 --- a/ng2-components/ng2-alfresco-tag/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-tag/demo/src/main.ts @@ -31,7 +31,7 @@ import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag'; @Component({ selector: 'alfresco-tag-demo', template: ` -
    +




    @@ -40,7 +40,7 @@ import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag'; operations.

    -
    +

    @@ -50,10 +50,6 @@ import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag'; Tag list By Node ID
    -
    - Tag list By Node Properties - -
    `, @@ -62,10 +58,8 @@ import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag'; }) class TagDemo implements OnInit { - propertiesDemo: string = '{"cm:taggable": ["008e722c-bf2a-4426-832c-29d1a9b174a8", "0350ff75-badb-40e5-b7de-1091a855dd70"]}'; - @Input() - nodeId: string = '1a0b110f-1e09-4ca2-b367-fe25e4964a4e'; + nodeId: string = '74cd8a96-8a21-47e5-9b3b-a1b3e296787d'; currentPath: string = '/'; diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html index 40c6b3a67e..2ec53cb492 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html @@ -1,39 +1,36 @@
    -
  • - +
  • + {{currentEntry.entry.tag}} - - delete - +
    + delete +
  • -
  • - -