mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Use JS API to fetch node info and set related attached content
- Add new service - Remove old HTTP-based methods from FormService - Refactoring Refs #621
This commit is contained in:
@@ -40,7 +40,7 @@ describe('ActivitiForm', () => {
|
|||||||
]);
|
]);
|
||||||
window['componentHandler'] = componentHandler;
|
window['componentHandler'] = componentHandler;
|
||||||
|
|
||||||
formService = new FormService(null, null, null, null);
|
formService = new FormService(null, null);
|
||||||
formComponent = new ActivitiForm(formService, visibilityService, null, null);
|
formComponent = new ActivitiForm(formService, visibilityService, null, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ import {
|
|||||||
import { MATERIAL_DESIGN_DIRECTIVES } from 'ng2-alfresco-core';
|
import { MATERIAL_DESIGN_DIRECTIVES } from 'ng2-alfresco-core';
|
||||||
import { EcmModelService } from './../services/ecm-model.service';
|
import { EcmModelService } from './../services/ecm-model.service';
|
||||||
import { FormService } from './../services/form.service';
|
import { FormService } from './../services/form.service';
|
||||||
|
import { ActivitiAlfrescoContentService } from './../services/activiti-alfresco.service';
|
||||||
import { NodeService } from './../services/node.service';
|
import { NodeService } from './../services/node.service';
|
||||||
import { FormModel, FormOutcomeModel, FormValues, FormFieldModel, FormOutcomeEvent } from './widgets/core/index';
|
import { FormModel, FormOutcomeModel, FormValues, FormFieldModel, FormOutcomeEvent } from './widgets/core/index';
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ import { WidgetVisibilityService } from './../services/widget-visibility.servic
|
|||||||
templateUrl: './activiti-form.component.html',
|
templateUrl: './activiti-form.component.html',
|
||||||
styleUrls: ['./activiti-form.component.css'],
|
styleUrls: ['./activiti-form.component.css'],
|
||||||
directives: [MATERIAL_DESIGN_DIRECTIVES, ContainerWidget, TabsWidget],
|
directives: [MATERIAL_DESIGN_DIRECTIVES, ContainerWidget, TabsWidget],
|
||||||
providers: [EcmModelService, FormService, WidgetVisibilityService, NodeService]
|
providers: [EcmModelService, FormService, ActivitiAlfrescoContentService, WidgetVisibilityService, NodeService]
|
||||||
})
|
})
|
||||||
export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
|
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
|
||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
import { FormService } from '../../../services/form.service';
|
import { ActivitiAlfrescoContentService } from '../../../services/activiti-alfresco.service';
|
||||||
import { ExternalContent } from '../core/external-content';
|
import { ExternalContent } from '../core/external-content';
|
||||||
import { ExternalContentLink } from '../core/external-content-link';
|
import { ExternalContentLink } from '../core/external-content-link';
|
||||||
import { FormFieldModel } from '../core/form-field.model';
|
import { FormFieldModel } from '../core/form-field.model';
|
||||||
@@ -51,7 +51,7 @@ export class AttachWidget extends WidgetComponent implements OnInit {
|
|||||||
@ViewChild('dialog')
|
@ViewChild('dialog')
|
||||||
dialog: any;
|
dialog: any;
|
||||||
|
|
||||||
constructor(private formService: FormService) {
|
constructor(private contentService: ActivitiAlfrescoContentService) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ export class AttachWidget extends WidgetComponent implements OnInit {
|
|||||||
|
|
||||||
private getExternalContentNodes() {
|
private getExternalContentNodes() {
|
||||||
|
|
||||||
this.formService.getAlfrescoNodes(this.selectedFolderAccountId, this.selectedFolderPathId)
|
this.contentService.getAlfrescoNodes(this.selectedFolderAccountId, this.selectedFolderPathId)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(nodes) => {
|
(nodes) => {
|
||||||
this.selectedFolderNodes = nodes;
|
this.selectedFolderNodes = nodes;
|
||||||
@@ -103,7 +103,7 @@ export class AttachWidget extends WidgetComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectFile(node: ExternalContent, $event: any) {
|
selectFile(node: ExternalContent, $event: any) {
|
||||||
this.formService.linkAlfrescoNode(this.selectedFolderAccountId, node, this.selectedFolderSiteId).subscribe(
|
this.contentService.linkAlfrescoNode(this.selectedFolderAccountId, node, this.selectedFolderSiteId).subscribe(
|
||||||
(link: ExternalContentLink) => {
|
(link: ExternalContentLink) => {
|
||||||
this.selectedFile = node;
|
this.selectedFile = node;
|
||||||
this.field.value = [link];
|
this.field.value = [link];
|
||||||
|
@@ -28,7 +28,7 @@ describe('DropdownWidget', () => {
|
|||||||
let widget: DropdownWidget;
|
let widget: DropdownWidget;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
formService = new FormService(null, null, null, null);
|
formService = new FormService(null, null);
|
||||||
widget = new DropdownWidget(formService);
|
widget = new DropdownWidget(formService);
|
||||||
widget.field = new FormFieldModel(new FormModel());
|
widget.field = new FormFieldModel(new FormModel());
|
||||||
});
|
});
|
||||||
|
@@ -29,7 +29,7 @@ describe('TypeaheadWidget', () => {
|
|||||||
let widget: TypeaheadWidget;
|
let widget: TypeaheadWidget;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
formService = new FormService(null, null, null, null);
|
formService = new FormService(null, null);
|
||||||
widget = new TypeaheadWidget(formService);
|
widget = new TypeaheadWidget(formService);
|
||||||
widget.field = new FormFieldModel(new FormModel());
|
widget.field = new FormFieldModel(new FormModel());
|
||||||
});
|
});
|
||||||
|
@@ -0,0 +1,90 @@
|
|||||||
|
/*!
|
||||||
|
* @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 { Observable } from 'rxjs/Rx';
|
||||||
|
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||||
|
import { ExternalContent } from '../components/widgets/core/external-content';
|
||||||
|
import { ExternalContentLink } from '../components/widgets/core/external-content-link';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ActivitiAlfrescoContentService {
|
||||||
|
|
||||||
|
static UNKNOWN_ERROR_MESSAGE: string = 'Unknown error';
|
||||||
|
static GENERIC_ERROR_MESSAGE: string = 'Server error';
|
||||||
|
|
||||||
|
constructor(private authService: AlfrescoAuthenticationService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of child nodes below the specified folder
|
||||||
|
*
|
||||||
|
* @param accountId
|
||||||
|
* @param folderId
|
||||||
|
* @returns {null}
|
||||||
|
*/
|
||||||
|
getAlfrescoNodes(accountId: string, folderId: string): Observable<[ExternalContent]> {
|
||||||
|
let apiService: any = this.authService.getAlfrescoApi();
|
||||||
|
let accountShortId = accountId.replace('alfresco-', '');
|
||||||
|
return Observable.fromPromise(apiService.activiti.alfrescoApi.getContentInFolder(accountShortId, folderId))
|
||||||
|
.map(this.toJsonArray)
|
||||||
|
.catch(this.handleError);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of child nodes below the specified folder
|
||||||
|
*
|
||||||
|
* @param accountId
|
||||||
|
* @param node
|
||||||
|
* @param siteId
|
||||||
|
* @returns {null}
|
||||||
|
*/
|
||||||
|
linkAlfrescoNode(accountId: string, node: ExternalContent, siteId: string): Observable<ExternalContentLink> {
|
||||||
|
let apiService: any = this.authService.getAlfrescoApi();
|
||||||
|
return Observable.fromPromise(apiService.activiti.contentApi.createTemporaryRelatedContent({
|
||||||
|
link: true,
|
||||||
|
name: node.title,
|
||||||
|
simpleType: node.simpleType,
|
||||||
|
source: accountId,
|
||||||
|
sourceId: node.id + '@' + siteId
|
||||||
|
})).map(this.toJson).catch(this.handleError);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(res: any) {
|
||||||
|
if (res) {
|
||||||
|
return res || {};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
toJsonArray(res: any) {
|
||||||
|
if (res) {
|
||||||
|
return res.data || [];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
handleError(error: any): Observable<any> {
|
||||||
|
let errMsg = ActivitiAlfrescoContentService.UNKNOWN_ERROR_MESSAGE;
|
||||||
|
if (error) {
|
||||||
|
errMsg = (error.message) ? error.message :
|
||||||
|
error.status ? `${error.status} - ${error.statusText}` : ActivitiAlfrescoContentService.GENERIC_ERROR_MESSAGE;
|
||||||
|
}
|
||||||
|
console.error(errMsg);
|
||||||
|
return Observable.throw(errMsg);
|
||||||
|
}
|
||||||
|
}
|
@@ -18,16 +18,13 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
import { AlfrescoApiService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
import { AlfrescoApiService } from 'ng2-alfresco-core';
|
||||||
import { FormValues } from './../components/widgets/core/index';
|
import { FormValues } from './../components/widgets/core/index';
|
||||||
import { FormDefinitionModel } from '../models/form-definition.model';
|
import { FormDefinitionModel } from '../models/form-definition.model';
|
||||||
import { EcmModelService } from './ecm-model.service';
|
import { EcmModelService } from './ecm-model.service';
|
||||||
import { GroupModel } from './../components/widgets/core/group.model';
|
import { GroupModel } from './../components/widgets/core/group.model';
|
||||||
import { GroupUserModel } from './../components/widgets/core/group-user.model';
|
import { GroupUserModel } from './../components/widgets/core/group-user.model';
|
||||||
import { ExternalContent } from '../components/widgets/core/external-content';
|
|
||||||
import { ExternalContentLink } from '../components/widgets/core/external-content-link';
|
|
||||||
|
|
||||||
import {Http, Response, RequestOptions, Headers} from '@angular/http';
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FormService {
|
export class FormService {
|
||||||
|
|
||||||
@@ -35,8 +32,7 @@ export class FormService {
|
|||||||
static GENERIC_ERROR_MESSAGE: string = 'Server error';
|
static GENERIC_ERROR_MESSAGE: string = 'Server error';
|
||||||
|
|
||||||
constructor(private ecmModelService: EcmModelService,
|
constructor(private ecmModelService: EcmModelService,
|
||||||
private apiService: AlfrescoApiService,
|
private apiService: AlfrescoApiService) {
|
||||||
private alfrescoSettingsService: AlfrescoSettingsService, private http: Http) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -278,67 +274,6 @@ export class FormService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of child nodes below the specified folder
|
|
||||||
*
|
|
||||||
* @param accountId
|
|
||||||
* @param nodeId
|
|
||||||
* @returns {null}
|
|
||||||
*/
|
|
||||||
getAlfrescoNodes(accountId: string, nodeId: string): Observable<[ExternalContent]> {
|
|
||||||
let accountPath = accountId.replace('-', '/');
|
|
||||||
let headers = new Headers();
|
|
||||||
headers.append('Authorization', this.authService.getTicketBpm());
|
|
||||||
return this.http.get(
|
|
||||||
`${this.alfrescoSettingsService.bpmHost}/activiti-app/` +
|
|
||||||
`app/rest/integration/${accountPath}/folders/${nodeId}/content`,
|
|
||||||
new RequestOptions({
|
|
||||||
headers: headers,
|
|
||||||
withCredentials: true
|
|
||||||
}))
|
|
||||||
.map(this.extractData)
|
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of child nodes below the specified folder
|
|
||||||
*
|
|
||||||
* @param accountId
|
|
||||||
* @param node
|
|
||||||
* @param siteId
|
|
||||||
* @returns {null}
|
|
||||||
*/
|
|
||||||
linkAlfrescoNode(accountId: string, node: ExternalContent, siteId: string): Observable<ExternalContentLink> {
|
|
||||||
let headers = new Headers();
|
|
||||||
headers.append('Content-Type', 'application/json');
|
|
||||||
headers.append('Authorization', this.authService.getTicketBpm());
|
|
||||||
return this.http.post(
|
|
||||||
`${this.alfrescoSettingsService.bpmHost}/activiti-app/app/rest/content`,
|
|
||||||
JSON.stringify({
|
|
||||||
link: true,
|
|
||||||
name: node.title,
|
|
||||||
simpleType: node.simpleType,
|
|
||||||
source: accountId,
|
|
||||||
sourceId: node.id + '@' + siteId
|
|
||||||
}),
|
|
||||||
new RequestOptions({
|
|
||||||
headers: headers,
|
|
||||||
withCredentials: true
|
|
||||||
}))
|
|
||||||
.map(this.extractBody)
|
|
||||||
.catch(this.handleError);
|
|
||||||
}
|
|
||||||
|
|
||||||
private extractBody(res: Response) {
|
|
||||||
let body = res.json();
|
|
||||||
return body || { };
|
|
||||||
}
|
|
||||||
|
|
||||||
private extractData(res: Response) {
|
|
||||||
let body = res.json();
|
|
||||||
return body.data || { };
|
|
||||||
}
|
|
||||||
|
|
||||||
getFormId(res: any) {
|
getFormId(res: any) {
|
||||||
let result = null;
|
let result = null;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user