mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
improve test service
This commit is contained in:
@@ -56,11 +56,10 @@ The following component needs to be added to your systemjs.config:
|
|||||||
|
|
||||||
- ng2-translate
|
- ng2-translate
|
||||||
- ng2-alfresco-core
|
- ng2-alfresco-core
|
||||||
- ng2-alfresco-datatable
|
|
||||||
|
|
||||||
Please refer to the following example to have an idea of how your systemjs.config should look like :
|
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
|
#### 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
|
The style of this component is based on material design, so if you want to visualize it correctly you have to add the material
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ng2-alfresco-tag-demo",
|
"name": "ng2-alfresco-tag-demo",
|
||||||
"description": "Alfresco Angular2 Tag - Demo",
|
"description": "Alfresco Angular2 Tag - Demo",
|
||||||
"version": "0.2.0",
|
"version": "0.3.0",
|
||||||
"author": "Alfresco Software, Ltd.",
|
"author": "Alfresco Software, Ltd.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -37,11 +37,10 @@
|
|||||||
"material-design-icons": "2.2.3",
|
"material-design-icons": "2.2.3",
|
||||||
"material-design-lite": "1.1.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-translate": "2.2.2",
|
||||||
"ng2-alfresco-core": "^0.2.0",
|
"ng2-alfresco-core": "^0.3.0"
|
||||||
"ng2-alfresco-datatable": "^0.2.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"concurrently": "2.0.0",
|
"concurrently": "2.0.0",
|
||||||
|
@@ -33,8 +33,8 @@ import {TAGCOMPONENT, TAGSERVICES} from 'ng2-alfresco-tag';
|
|||||||
template: `
|
template: `
|
||||||
<label for="token"><b>Insert a valid access token / ticket:</b></label><br>
|
<label for="token"><b>Insert a valid access token / ticket:</b></label><br>
|
||||||
<input id="token" type="text" size="48" (change)="updateToken();documentList.reload()" [(ngModel)]="token"><br>
|
<input id="token" type="text" size="48" (change)="updateToken();documentList.reload()" [(ngModel)]="token"><br>
|
||||||
<label for="token"><b>Insert the ip of your Alfresco instance:</b></label><br>
|
<label for="host"><b>Insert the ip of your Alfresco instance:</b></label><br>
|
||||||
<input id="token" type="text" size="48" (change)="updateHost();documentList.reload()" [(ngModel)]="ecmHost"><br><br>
|
<input id="host" type="text" size="48" (change)="updateHost();documentList.reload()" [(ngModel)]="ecmHost"><br><br>
|
||||||
<div *ngIf="!authenticated" style="color:#FF2323">
|
<div *ngIf="!authenticated" style="color:#FF2323">
|
||||||
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 token to perform
|
||||||
operations.
|
operations.
|
||||||
|
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
'ng2-translate': 'node_modules/ng2-translate',
|
'ng2-translate': 'node_modules/ng2-translate',
|
||||||
'ng2-alfresco-core': 'node_modules/ng2-alfresco-core/dist',
|
'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'
|
'ng2-alfresco-tag': 'node_modules/ng2-alfresco-tag/dist'
|
||||||
};
|
};
|
||||||
// packages tells the System loader how to load when no filename and/or no extension
|
// packages tells the System loader how to load when no filename and/or no extension
|
||||||
@@ -23,7 +22,6 @@
|
|||||||
|
|
||||||
'ng2-translate': { defaultExtension: 'js' },
|
'ng2-translate': { defaultExtension: 'js' },
|
||||||
'ng2-alfresco-core': { main: 'index.js', 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' }
|
'ng2-alfresco-tag': { main: 'index.js', defaultExtension: 'js' }
|
||||||
};
|
};
|
||||||
var ngPackageNames = [
|
var ngPackageNames = [
|
||||||
|
@@ -17,6 +17,10 @@ module.exports = function (config) {
|
|||||||
{pattern: 'node_modules/@angular/**/*.js', 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/@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-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/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: 'node_modules/material-design-lite/material.min.js', included: true, watched: false},
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ng2-alfresco-tag",
|
"name": "ng2-alfresco-tag",
|
||||||
"description": "Alfresco tag component",
|
"description": "Alfresco tag component",
|
||||||
"version": "0.2.0",
|
"version": "0.3.0",
|
||||||
"author": "Alfresco Software, Ltd.",
|
"author": "Alfresco Software, Ltd.",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"typings": "./dist/index.d.ts",
|
"typings": "./dist/index.d.ts",
|
||||||
@@ -44,11 +44,10 @@
|
|||||||
"@angular/upgrade": "2.0.0-rc.3",
|
"@angular/upgrade": "2.0.0-rc.3",
|
||||||
"systemjs": "0.19.27",
|
"systemjs": "0.19.27",
|
||||||
"core-js": "^2.4.0",
|
"core-js": "^2.4.0",
|
||||||
"alfresco-js-api": "^0.2.0",
|
"alfresco-js-api": "^0.3.0",
|
||||||
|
|
||||||
"ng2-translate": "2.2.2",
|
"ng2-translate": "2.2.2",
|
||||||
"ng2-alfresco-core": "^0.2.0",
|
"ng2-alfresco-core": "^0.3.0",
|
||||||
"ng2-alfresco-datatable": "^0.2.0",
|
|
||||||
"reflect-metadata": "^0.1.3",
|
"reflect-metadata": "^0.1.3",
|
||||||
"rxjs": "5.0.0-beta.6",
|
"rxjs": "5.0.0-beta.6",
|
||||||
"zone.js": "^0.6.12"
|
"zone.js": "^0.6.12"
|
||||||
|
@@ -15,3 +15,39 @@
|
|||||||
* limitations under the License.
|
* 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();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@@ -48,7 +48,6 @@ export class TagActionsComponent {
|
|||||||
|
|
||||||
tagsEntries: any;
|
tagsEntries: any;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param authService
|
* @param authService
|
||||||
|
@@ -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();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
@@ -54,8 +54,7 @@ export class TagList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refreshTagEcm() {
|
refreshTagEcm() {
|
||||||
|
this.tagService.getAllTheTags().subscribe((data) => {
|
||||||
this.tagService.getAllTheTags().then((data) => {
|
|
||||||
this.tagsEntries = data;
|
this.tagsEntries = data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
@@ -15,9 +15,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Component, Input} from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import {AlfrescoAuthenticationService} from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||||
import {TagService} from '../services/tag.service';
|
import { TagService } from '../services/tag.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -38,9 +38,6 @@ export class TagNodeList {
|
|||||||
@Input()
|
@Input()
|
||||||
nodeId: string;
|
nodeId: string;
|
||||||
|
|
||||||
@Input()
|
|
||||||
properties: string;
|
|
||||||
|
|
||||||
tagsEntries: any;
|
tagsEntries: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,7 +45,6 @@ export class TagNodeList {
|
|||||||
* @param authService
|
* @param authService
|
||||||
*/
|
*/
|
||||||
constructor(public authService: AlfrescoAuthenticationService, private tagService: TagService) {
|
constructor(public authService: AlfrescoAuthenticationService, private tagService: TagService) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes) {
|
ngOnChanges(changes) {
|
||||||
@@ -56,15 +52,9 @@ export class TagNodeList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refreshTag() {
|
refreshTag() {
|
||||||
if (this.nodeId) {
|
this.tagService.getTagsByNodeId(this.nodeId).then((data) => {
|
||||||
this.tagService.getTagsByNodeId(this.nodeId).then((data) => {
|
this.tagsEntries = data;
|
||||||
this.tagsEntries = data;
|
});
|
||||||
});
|
|
||||||
} else if (this.properties) {
|
|
||||||
this.tagService.getTagsByProperties(this.properties).then((data) => {
|
|
||||||
this.tagsEntries = data;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTag(tag: string) {
|
removeTag(tag: string) {
|
||||||
|
114
ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts
Normal file
114
ng2-components/ng2-alfresco-tag/src/services/tag.service.spec.ts
Normal file
@@ -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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -15,128 +15,51 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {AlfrescoAuthenticationService} from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||||
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @returns {TagService} .
|
||||||
* 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;
|
declare let __moduleName: string;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TagService {
|
export class TagService {
|
||||||
|
|
||||||
cacheTagList: any = [];
|
|
||||||
|
|
||||||
promiseCache: any;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param authService
|
* @param authService
|
||||||
*/
|
*/
|
||||||
constructor(public authService: AlfrescoAuthenticationService) {
|
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 {
|
getTagsByNodeId(nodeId: string): any {
|
||||||
return new Promise((resolve, reject) => {
|
return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.getNodeTags(nodeId))
|
||||||
this.authService.getAlfrescoApi().core.tagsApi.getNodeTags(nodeId).then((data) => {
|
.catch(this.handleError);
|
||||||
resolve(data.list.entries);
|
|
||||||
}, function (error) {
|
|
||||||
console.log('Error' + error);
|
|
||||||
reject();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllTheTags() {
|
getAllTheTags() {
|
||||||
return new Promise((resolve, reject) => {
|
return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.getTags())
|
||||||
this.authService.getAlfrescoApi().core.tagsApi.getTags().then((data) => {
|
.catch(this.handleError);
|
||||||
resolve(data.list.entries);
|
|
||||||
}, function (error) {
|
|
||||||
console.log('Error' + error);
|
|
||||||
reject();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addTag(nodeId: string, tagName: string): any {
|
addTag(nodeId: string, tagName: string): any {
|
||||||
return new Promise((resolve, reject) => {
|
let alfrescoApi = this.authService.getAlfrescoApi();
|
||||||
let alfrescoApi = this.authService.getAlfrescoApi();
|
let tagBody = new alfrescoApi.core.TagBody();
|
||||||
let tagBody = new alfrescoApi.core.TagBody();
|
tagBody.tag = tagName;
|
||||||
tagBody.tag = tagName;
|
|
||||||
this.authService.getAlfrescoApi().core.tagsApi.addTag(nodeId, tagBody).then((res) => {
|
return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.addTag(nodeId, tagBody))
|
||||||
this.cacheTagList.push(res);
|
.catch(this.handleError);
|
||||||
resolve(res);
|
|
||||||
}, function (error) {
|
|
||||||
console.log('Error' + error);
|
|
||||||
reject();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTag(nodeId: string, tag: string): any {
|
removeTag(nodeId: string, tag: string): any {
|
||||||
return new Promise((resolve, reject) => {
|
return Observable.fromPromise(this.authService.getAlfrescoApi().core.tagsApi.removeTag(nodeId, tag))
|
||||||
this.authService.getAlfrescoApi().core.tagsApi.removeTag(nodeId, tag).then(() => {
|
.catch(this.handleError);
|
||||||
resolve();
|
}
|
||||||
}, function (error) {
|
|
||||||
console.log('Error' + error);
|
private handleError(error: any) {
|
||||||
reject();
|
console.error(error);
|
||||||
});
|
return Observable.throw(error || 'Server error');
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -85,8 +85,7 @@ describe('Test ng2-alfresco-webscript', () => {
|
|||||||
|
|
||||||
component.ngOnChanges().then(() => {
|
component.ngOnChanges().then(() => {
|
||||||
webscriptComponentFixture.detectChanges();
|
webscriptComponentFixture.detectChanges();
|
||||||
let request = jasmine.Ajax.requests.mostRecent();
|
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://localhost:8080/alfresco/service/sample/folder/Company%20Home');
|
||||||
expect(request.url).toBe('http://localhost:8080/alfresco/service/sample/folder/Company%20Home');
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user