diff --git a/demo-shell-ng2/package.json b/demo-shell-ng2/package.json index 53f2e3b1fd..36b258bb91 100644 --- a/demo-shell-ng2/package.json +++ b/demo-shell-ng2/package.json @@ -60,6 +60,7 @@ "@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", diff --git a/ng2-components/ng2-alfresco-core/index.ts b/ng2-components/ng2-alfresco-core/index.ts index 075b8a526e..c55723ef05 100644 --- a/ng2-components/ng2-alfresco-core/index.ts +++ b/ng2-components/ng2-alfresco-core/index.ts @@ -27,7 +27,8 @@ import { AlfrescoTranslationLoader, AlfrescoTranslationService, AlfrescoAuthenticationService, - AlfrescoContentService + AlfrescoContentService, + RenditionsService } from './src/services/index'; import { MATERIAL_DESIGN_DIRECTIVES } from './src/components/material/index'; @@ -44,6 +45,7 @@ export const ALFRESCO_CORE_PROVIDERS: any[] = [ AlfrescoSettingsService, AlfrescoTranslationLoader, AlfrescoTranslationService, + RenditionsService, ...CONTEXT_MENU_PROVIDERS ]; diff --git a/ng2-components/ng2-alfresco-core/src/assets/AlfrescoApi.mock.ts b/ng2-components/ng2-alfresco-core/src/assets/AlfrescoApi.mock.ts index 3835e67611..85e93b30ba 100644 --- a/ng2-components/ng2-alfresco-core/src/assets/AlfrescoApi.mock.ts +++ b/ng2-components/ng2-alfresco-core/src/assets/AlfrescoApi.mock.ts @@ -15,7 +15,6 @@ * limitations under the License. */ - export class AlfrescoApiMock { login(username: string, password: string) { diff --git a/ng2-components/ng2-alfresco-core/src/assets/renditionsService.mock.ts b/ng2-components/ng2-alfresco-core/src/assets/renditionsService.mock.ts new file mode 100644 index 0000000000..91c7d1148a --- /dev/null +++ b/ng2-components/ng2-alfresco-core/src/assets/renditionsService.mock.ts @@ -0,0 +1,81 @@ +/*! + * @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. + */ + +export var fakeRedition = { + 'entry': { + 'id': 'pdf', + 'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'}, + 'status': 'NOT_CREATED' + } +}; + +export var fakeReditionCreated = { + 'entry': { + 'id': 'pdf', + 'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'}, + 'status': 'CREATED' + } +}; + +export var fakeReditionsList = { + 'list': { + 'pagination': { + 'count': 6, + 'hasMoreItems': false, + 'totalItems': 6, + 'skipCount': 0, + 'maxItems': 100 + }, + 'entries': [{ + 'entry': { + 'id': 'avatar', + 'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'}, + 'status': 'NOT_CREATED' + } + }, { + 'entry': { + 'id': 'avatar32', + 'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'}, + 'status': 'NOT_CREATED' + } + }, { + 'entry': { + 'id': 'doclib', + 'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'}, + 'status': 'NOT_CREATED' + } + }, { + 'entry': { + 'id': 'imgpreview', + 'content': {'mimeType': 'image/jpeg', 'mimeTypeName': 'JPEG Image'}, + 'status': 'NOT_CREATED' + } + }, { + 'entry': { + 'id': 'medium', + 'content': {'mimeType': 'image/jpeg', 'mimeTypeName': 'JPEG Image'}, + 'status': 'NOT_CREATED' + } + }, { + 'entry': { + 'id': 'pdf', + 'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'}, + 'status': 'NOT_CREATED' + } + }] + } +}; diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.spec.ts index fe897b95fc..36e261ba7d 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.spec.ts @@ -46,6 +46,4 @@ describe('AlfrescoSettingsService', () => { service.bpmHost = address; expect(service.bpmHost).toBe(address); }); - - }); diff --git a/ng2-components/ng2-alfresco-core/src/services/renditions.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/renditions.service.spec.ts index d99483d5cc..747c88bdec 100644 --- a/ng2-components/ng2-alfresco-core/src/services/renditions.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/renditions.service.spec.ts @@ -18,6 +18,11 @@ import { ReflectiveInjector } from '@angular/core'; import { AlfrescoApiService } from './AlfrescoApi.service'; import { RenditionsService } from './renditions.service'; +import { + fakeRedition, + fakeReditionCreated, + fakeReditionsList +} from '../assets/renditionsService.mock'; declare let jasmine: any; declare let AlfrescoApi: any; @@ -25,62 +30,6 @@ declare let AlfrescoApi: any; describe('RenditionsService', () => { let service, injector; - let fakeRedition = { - 'entry': { - 'id': 'pdf', - 'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'}, - 'status': 'NOT_CREATED' - } - }; - - let fakeReditionsList = { - 'list': { - 'pagination': { - 'count': 6, - 'hasMoreItems': false, - 'totalItems': 6, - 'skipCount': 0, - 'maxItems': 100 - }, - 'entries': [{ - 'entry': { - 'id': 'avatar', - 'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'}, - 'status': 'NOT_CREATED' - } - }, { - 'entry': { - 'id': 'avatar32', - 'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'}, - 'status': 'NOT_CREATED' - } - }, { - 'entry': { - 'id': 'doclib', - 'content': {'mimeType': 'image/png', 'mimeTypeName': 'PNG Image'}, - 'status': 'NOT_CREATED' - } - }, { - 'entry': { - 'id': 'imgpreview', - 'content': {'mimeType': 'image/jpeg', 'mimeTypeName': 'JPEG Image'}, - 'status': 'NOT_CREATED' - } - }, { - 'entry': { - 'id': 'medium', - 'content': {'mimeType': 'image/jpeg', 'mimeTypeName': 'JPEG Image'}, - 'status': 'NOT_CREATED' - } - }, { - 'entry': { - 'id': 'pdf', - 'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'}, - 'status': 'NOT_CREATED' - } - }] - } - }; beforeEach(() => { injector = ReflectiveInjector.resolveAndCreate([ AlfrescoApiService, @@ -98,9 +47,9 @@ describe('RenditionsService', () => { jasmine.Ajax.uninstall(); }); - it('Get redition list service should call the server with the ID passed', (done) => { + it('Get redition list service should return the list', (done) => { service.getRenditionsListByNodeId('fake-node-id').subscribe((res) => { - expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions'); + expect(res.list.entries[0].entry.id).toBe('avatar'); done(); }); @@ -111,34 +60,6 @@ describe('RenditionsService', () => { }); }); - it('Get redition service should call the server with the ID passed', (done) => { - service.getRendition('fake-node-id', 'pdf').subscribe((res) => { - expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions/pdf'); - expect(res.entry.status).toBe('NOT_CREATED'); - done(); - }); - - jasmine.Ajax.requests.mostRecent().respondWith({ - 'status': 200, - contentType: 'application/json', - responseText: JSON.stringify(fakeRedition) - }); - }); - - it('isRenditionsAvailable service should call the server with the ID passed and return false if is not created', (done) => { - service.isRenditionAvailable('fake-node-id', 'pdf').subscribe((res) => { - expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions/pdf'); - expect(res).toBe(false); - done(); - }); - - jasmine.Ajax.requests.mostRecent().respondWith({ - 'status': 200, - contentType: 'application/json', - responseText: JSON.stringify(fakeRedition) - }); - }); - it('Create redition service should call the server with the ID passed and the asked encoding', (done) => { service.createRendition('fake-node-id', 'pdf').subscribe((res) => { expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions'); @@ -165,5 +86,67 @@ describe('RenditionsService', () => { responseText: 'error' }); }); -}); + it('isConversionPossible should return true if is possible convert', (done) => { + service.isConversionPossible('fake-node-id', 'pdf').subscribe((res) => { + expect(res).toBe(true); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 200, + contentType: 'application/json', + responseText: JSON.stringify(fakeRedition) + }); + }); + + it('isConversionPossible should return false if is not possible to convert', (done) => { + service.isConversionPossible('fake-node-id', 'pdf').subscribe((res) => { + expect(res).toBe(false); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 403, + contentType: 'application/json' + }); + }); + + it('isRenditionsAvailable should return true if the conversion exist', (done) => { + service.isRenditionAvailable('fake-node-id', 'pdf').subscribe((res) => { + expect(res).toBe(true); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 200, + contentType: 'application/json', + responseText: JSON.stringify(fakeReditionCreated) + }); + }); + + it('isRenditionsAvailable should return false if the conversion not exist', (done) => { + service.isRenditionAvailable('fake-node-id', 'pdf').subscribe((res) => { + expect(res).toBe(false); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 200, + contentType: 'application/json', + responseText: JSON.stringify(fakeRedition) + }); + }); + + it('isRenditionsAvailable should return false if the conversion get error', (done) => { + service.isRenditionAvailable('fake-node-id', 'pdf').subscribe((res) => { + expect(res).toBe(false); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 400, + contentType: 'application/json' + }); + }); +}); diff --git a/ng2-components/ng2-alfresco-core/src/services/renditions.service.ts b/ng2-components/ng2-alfresco-core/src/services/renditions.service.ts index 3960c5948d..8b36899227 100644 --- a/ng2-components/ng2-alfresco-core/src/services/renditions.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/renditions.service.ts @@ -40,6 +40,21 @@ export class RenditionsService { } observer.next(isAvailable); observer.complete(); + }, () => { + observer.next(false); + observer.complete(); + }); + }); + } + + isConversionPossible(nodeId: string, encoding: string) { + return Observable.create((observer) => { + this.getRendition(nodeId, encoding).subscribe(() => { + observer.next(true); + observer.complete(); + }, () => { + observer.next(false); + observer.complete(); }); }); } @@ -55,7 +70,7 @@ export class RenditionsService { } createRendition(nodeId: string, encoding: string) { - return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.createRendition(nodeId, {id: 'pdf'})) + return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.createRendition(nodeId, {id: encoding})) .catch(this.handleError); } diff --git a/ng2-components/ng2-alfresco-core/tslint.json b/ng2-components/ng2-alfresco-core/tslint.json index 23d636b1eb..4ce54ea73b 100644 --- a/ng2-components/ng2-alfresco-core/tslint.json +++ b/ng2-components/ng2-alfresco-core/tslint.json @@ -35,7 +35,7 @@ "no-arg": true, "no-bitwise": false, "no-conditional-assignment": true, - "no-consecutive-blank-lines": false, + "no-consecutive-blank-lines": true, "no-console": [ true, "debug", diff --git a/ng2-components/ng2-alfresco-userinfo/package.json b/ng2-components/ng2-alfresco-userinfo/package.json index 6afe347b8b..4f1752b1b2 100644 --- a/ng2-components/ng2-alfresco-userinfo/package.json +++ b/ng2-components/ng2-alfresco-userinfo/package.json @@ -6,7 +6,7 @@ "main": "./dist/index.js", "typings": "./dist/index.d.ts", "scripts": { - "clean": "rimraf dist node_modules", + "clean": "npm install rimraf && rimraf dist node_modules typings", "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\"", diff --git a/scripts/npm-clean.sh b/scripts/npm-clean.sh index eeffa98fc0..0d5679972c 100755 --- a/scripts/npm-clean.sh +++ b/scripts/npm-clean.sh @@ -4,19 +4,19 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" for PACKAGE in \ ng2-activiti-analytics \ - ng2-activiti-form \ - ng2-activiti-processlist \ - ng2-activiti-tasklist \ ng2-alfresco-core \ ng2-alfresco-datatable \ ng2-alfresco-documentlist \ + ng2-activiti-form \ ng2-alfresco-login \ + ng2-activiti-processlist \ ng2-alfresco-search \ + ng2-activiti-tasklist \ ng2-alfresco-tag \ ng2-alfresco-upload \ + ng2-alfresco-userinfo \ ng2-alfresco-viewer \ - ng2-alfresco-webscript \ - ng2-alfresco-userinfo + ng2-alfresco-webscript 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 966f1833df..01a6ad805f 100755 --- a/scripts/npm-link-demo-shell.sh +++ b/scripts/npm-link-demo-shell.sh @@ -56,27 +56,15 @@ npm link ng2-activiti-tasklist npm link npm run build -#LINK VIEWER -echo "====== linking component: ng2-alfresco-viewer =====" -cd "$DIR/../ng2-components/ng2-alfresco-viewer" -npm link ng2-alfresco-core -npm link -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 build - #LINK ALL THE OTHERS COMPONENTS for PACKAGE in \ + ng2-activiti-analytics \ ng2-alfresco-login \ ng2-alfresco-search \ + ng2-alfresco-userinfo \ ng2-alfresco-upload \ - ng2-activiti-analytics \ - ng2-alfresco-userinfo + ng2-alfresco-tag \ + ng2-alfresco-viewer do DESTDIR="$DIR/../ng2-components/${PACKAGE}" echo "====== linking component: ${PACKAGE} ====="