[ADF-2035] Drag and drop is not working on Processes - attachment List (#2736)

* fix upload for process attachment list
export ActivitiContentService
ProcessService.createOrUpdateProcessInstanceVariables has incorrect method signature

* fix signature methods

* fix test parameters
This commit is contained in:
Eugenio Romano 2017-11-27 14:39:33 +00:00 committed by GitHub
parent 2f07fa339d
commit bdc06e3eed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 113 additions and 55 deletions

View File

@ -1,15 +1,17 @@
<div id="attachment-process-list" *ngIf="processInstanceId"> <div id="attachment-process-list" *ngIf="processInstanceId">
<h5>Attachments</h5>
<div class="adf-no-form-container"> <div class="adf-no-form-container">
<adf-upload-drag-area <adf-upload-drag-area
[parentId]="processInstanceId" [parentId]="processInstanceId"
[disabled]="isCompletedProcess()"> [disabled]="isCompletedProcess()">
<adf-process-attachment-list #processAttachList <adf-process-attachment-list #processAttachList
*ngIf="processInstanceId" *ngIf="processInstanceId"
[disabled]="isCompletedProcess()" [disabled]="isCompletedProcess()"
[processInstanceId]="processInstanceId" [processInstanceId]="processInstanceId"
(attachmentClick)="onAttachmentClick($event)"> (attachmentClick)="onAttachmentClick($event)">
</adf-process-attachment-list> </adf-process-attachment-list>
</adf-upload-drag-area> </adf-upload-drag-area>
<adf-create-process-attachment <adf-create-process-attachment

View File

@ -28,15 +28,16 @@ import { UploadService } from '@alfresco/adf-core';
export class ProcessAttachmentsComponent implements OnInit, OnChanges { export class ProcessAttachmentsComponent implements OnInit, OnChanges {
@Input()
processInstanceId: string;
@ViewChild(ProcessAttachmentListComponent) @ViewChild(ProcessAttachmentListComponent)
processAttachList: ProcessAttachmentListComponent; processAttachList: ProcessAttachmentListComponent;
fileShowed: boolean = false; @Input()
processInstanceId: string;
fileShowed = false;
content: Blob; content: Blob;
contentName: string; contentName: string;
processInstance: ProcessInstance; processInstance: ProcessInstance;
constructor(private uploadService: UploadService, private processService: ProcessService) { constructor(private uploadService: UploadService, private processService: ProcessService) {
@ -48,7 +49,8 @@ export class ProcessAttachmentsComponent implements OnInit, OnChanges {
ngOnChanges() { ngOnChanges() {
if (this.processInstanceId) { if (this.processInstanceId) {
this.processService.getProcess(this.processInstanceId).subscribe((processInstance: ProcessInstance) => { this.processService.getProcess(this.processInstanceId)
.subscribe((processInstance: ProcessInstance) => {
this.processInstance = processInstance; this.processInstance = processInstance;
}); });
} }

View File

@ -104,8 +104,8 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
@Input() @Input()
appId: number = null; appId: number = null;
fileShowed: boolean = false; fileShowed = false;
selectFirstReport: boolean = false; selectFirstReport = false;
private tabs = { tasks: 0, processes: 1, reports: 2 }; private tabs = { tasks: 0, processes: 1, reports: 2 };
@ -122,7 +122,7 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
maxItems: 10, maxItems: 10,
totalItems: 0 totalItems: 0
}; };
taskPage: number = 0; taskPage = 0;
processSchemaColumns: any[] = []; processSchemaColumns: any[] = [];
activeTab: number = this.tabs.tasks; // tasks|processes|reports activeTab: number = this.tabs.tasks; // tasks|processes|reports
@ -133,11 +133,11 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
sub: Subscription; sub: Subscription;
blobFile: any; blobFile: any;
flag: boolean = true; flag = true;
dataTasks: ObjectDataTableAdapter; dataTasks: ObjectDataTableAdapter;
dataProcesses: ObjectDataTableAdapter; dataProcesses: ObjectDataTableAdapter;
presetColoum: string = 'default'; presetColoum = 'default';
fieldValidators = [ fieldValidators = [
...FORM_FIELD_VALIDATORS, ...FORM_FIELD_VALIDATORS,
@ -170,12 +170,12 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
}); });
formService.validateDynamicTableRow.subscribe( formService.validateDynamicTableRow.subscribe(
(e: ValidateDynamicTableRowEvent) => { (validateDynamicTableRowEvent: ValidateDynamicTableRowEvent) => {
const row: DynamicTableRow = e.row; const row: DynamicTableRow = validateDynamicTableRowEvent.row;
if (row && row.value && row.value.name === 'admin') { if (row && row.value && row.value.name === 'admin') {
e.summary.isValid = false; validateDynamicTableRowEvent.summary.isValid = false;
e.summary.message = 'Sorry, wrong value. You cannot use "admin".'; validateDynamicTableRowEvent.summary.message = 'Sorry, wrong value. You cannot use "admin".';
e.preventDefault(); validateDynamicTableRowEvent.preventDefault();
} }
} }
); );
@ -240,7 +240,7 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
this.activeTab = this.tabs.processes; this.activeTab = this.tabs.processes;
} }
this.sub = this.route.params.subscribe(params => { this.sub = this.route.params.subscribe(params => {
let applicationId = params['appId']; const applicationId = params['appId'];
if (applicationId && applicationId !== '0') { if (applicationId && applicationId !== '0') {
this.appId = params['appId']; this.appId = params['appId'];
} }
@ -417,10 +417,10 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit
loadStencilScriptsInPageFromProcessService() { loadStencilScriptsInPageFromProcessService() {
this.apiService.getInstance().activiti.scriptFileApi.getControllers().then(response => { this.apiService.getInstance().activiti.scriptFileApi.getControllers().then(response => {
if (response) { if (response) {
let s = document.createElement('script'); const stencilSript = document.createElement('script');
s.type = 'text/javascript'; stencilSript.type = 'text/javascript';
s.text = response; stencilSript.text = response;
this.elementRef.nativeElement.appendChild(s); this.elementRef.nativeElement.appendChild(stencilSript);
} }
}); });
} }

View File

@ -1,17 +1,24 @@
<div id="attachment-task-list" *ngIf="taskId"> <div id="attachment-task-list" *ngIf="taskId">
<div class="adf-no-form-container"> <div class="adf-no-form-container">
<adf-upload-drag-area <adf-upload-drag-area
[parentId]="taskId"> [parentId]="taskId">
<adf-task-attachment-list #taskAttachList <adf-task-attachment-list #taskAttachList
[disabled]="isCompletedTask()" [disabled]="isCompletedTask()"
(attachmentClick)="onAttachmentClick($event)" [taskId]="taskId"
[taskId]="taskId"> (attachmentClick)="onAttachmentClick($event)">
<div adf-empty-list> <div adf-empty-list>
<div adf-empty-list-header class="adf-empty-list-header"> {{'ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER' | translate}} </div> <div adf-empty-list-header class="adf-empty-list-header"> {{'ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER'
| translate}}
</div>
<div adf-empty-list-body> <div adf-empty-list-body>
<div fxHide.lt-md="true" class="adf-empty-list-drag_drop">{{'ADF_TASK_LIST.ATTACHMENT.EMPTY.DRAG-AND-DROP.TITLE' | translate}}</div> <div fxHide.lt-md="true" class="adf-empty-list-drag_drop">
<div fxHide.lt-md="true" class="adf-empty-list__any-files-here-to-add"> {{'ADF_TASK_LIST.ATTACHMENT.EMPTY.DRAG-AND-DROP.SUBTITLE' | translate}} </div> {{'ADF_TASK_LIST.ATTACHMENT.EMPTY.DRAG-AND-DROP.TITLE' | translate}}
</div>
<div fxHide.lt-md="true" class="adf-empty-list__any-files-here-to-add">
{{'ADF_TASK_LIST.ATTACHMENT.EMPTY.DRAG-AND-DROP.SUBTITLE' | translate}}
</div>
</div> </div>
</div> </div>
</adf-task-attachment-list> </adf-task-attachment-list>

View File

@ -16,7 +16,7 @@
*/ */
import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core'; import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
import { TaskListService, TaskAttachmentListComponent } from '@alfresco/adf-process-services'; import { TaskListService, TaskAttachmentListComponent, TaskDetailsModel } from '@alfresco/adf-process-services';
import { UploadService } from '@alfresco/adf-core'; import { UploadService } from '@alfresco/adf-core';
@Component({ @Component({
@ -33,15 +33,13 @@ export class TaskAttachmentsComponent implements OnInit, OnChanges {
@Input() @Input()
taskId: string; taskId: string;
fileShowed: boolean = false; fileShowed = false;
content: Blob; content: Blob;
contentName: string; contentName: string;
taskDetails: any; taskDetails: any;
constructor(private uploadService: UploadService, constructor(private uploadService: UploadService, private activitiTaskList: TaskListService) {
private activitiTaskList: TaskListService) {
} }
ngOnInit() { ngOnInit() {
@ -50,9 +48,9 @@ export class TaskAttachmentsComponent implements OnInit, OnChanges {
ngOnChanges() { ngOnChanges() {
if (this.taskId) { if (this.taskId) {
this.activitiTaskList.getTaskDetails(this.taskId).map((res) => res).subscribe( this.activitiTaskList.getTaskDetails(this.taskId).map((res) => res)
(res: any) => { .subscribe((taskDetails: TaskDetailsModel) => {
this.taskDetails = res; this.taskDetails = taskDetails;
}); });
} }
} }

View File

@ -18,7 +18,7 @@
import { ContentService, ThumbnailService } from '@alfresco/adf-core'; import { ContentService, ThumbnailService } from '@alfresco/adf-core';
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, NgZone, OnChanges, Output, SimpleChanges, ViewChild, ViewEncapsulation } from '@angular/core'; import { AfterViewInit, Component, ElementRef, EventEmitter, Input, NgZone, OnChanges, Output, SimpleChanges, ViewChild, ViewEncapsulation } from '@angular/core';
import { ProcessContentService, UploadService } from '@alfresco/adf-core'; import { ProcessContentService, UploadService } from '@alfresco/adf-core';
import { ProcessUploadService } from '../task-list/services/process-upload.service'; import { TaskUploadService } from '../task-list/services/task-upload.service';
@Component({ @Component({
selector: 'adf-task-attachment-list', selector: 'adf-task-attachment-list',
@ -26,7 +26,7 @@ import { ProcessUploadService } from '../task-list/services/process-upload.servi
templateUrl: './task-attachment-list.component.html', templateUrl: './task-attachment-list.component.html',
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
providers: [ providers: [
{ provide: UploadService, useClass: ProcessUploadService } { provide: UploadService, useClass: TaskUploadService }
] ]
}) })
export class TaskAttachmentListComponent implements OnChanges, AfterViewInit { export class TaskAttachmentListComponent implements OnChanges, AfterViewInit {

View File

@ -56,7 +56,7 @@ describe('ActivitiFilters', () => {
}); });
beforeEach(() => { beforeEach(() => {
processFilterService = new ProcessFilterService(null, null); processFilterService = new ProcessFilterService(null);
appsProcessService = new AppsProcessService(null, null); appsProcessService = new AppsProcessService(null, null);
filterList = new ProcessFiltersComponent(processFilterService, appsProcessService); filterList = new ProcessFiltersComponent(processFilterService, appsProcessService);
}); });

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { AlfrescoApiService, LogService } from '@alfresco/adf-core'; import { AlfrescoApiService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { FilterProcessRepresentationModel } from '../models/filter-process.model'; import { FilterProcessRepresentationModel } from '../models/filter-process.model';
@ -24,8 +24,7 @@ import 'rxjs/add/observable/throw';
@Injectable() @Injectable()
export class ProcessFilterService { export class ProcessFilterService {
constructor(private alfrescoApiService: AlfrescoApiService, constructor(private alfrescoApiService: AlfrescoApiService) {
private logService: LogService) {
} }
getProcessFilters(appId: number): Observable<FilterProcessRepresentationModel[]> { getProcessFilters(appId: number): Observable<FilterProcessRepresentationModel[]> {
@ -72,7 +71,7 @@ export class ProcessFilterService {
* @param appId * @param appId
* @returns {FilterProcessRepresentationModel[]} * @returns {FilterProcessRepresentationModel[]}
*/ */
public createDefaultFilters(appId: number): Observable<any[]> { public createDefaultFilters(appId: number): Observable<FilterProcessRepresentationModel[]> {
let runningFilter = this.getRunningFilterInstance(appId); let runningFilter = this.getRunningFilterInstance(appId);
let runningObservable = this.addProcessFilter(runningFilter); let runningObservable = this.addProcessFilter(runningFilter);
@ -103,7 +102,7 @@ export class ProcessFilterService {
observer.complete(); observer.complete();
}, },
(err: any) => { (err: any) => {
this.logService.error(err); this.handleProcessError(err)
}); });
}); });
} }

View File

@ -35,7 +35,6 @@ describe('ProcessService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [ providers: [
ProcessService ProcessService
] ]

View File

@ -126,24 +126,24 @@ export class ProcessService {
.catch(err => this.handleProcessError(err)); .catch(err => this.handleProcessError(err));
} }
getProcessInstanceVariables(processDefinitionId: string): Observable<ProcessInstanceVariable[]> { getProcessInstanceVariables(processInstanceId: string): Observable<ProcessInstanceVariable[]> {
return Observable.fromPromise( return Observable.fromPromise(
this.alfrescoApiService.getInstance().activiti.processInstanceVariablesApi.getProcessInstanceVariables(processDefinitionId) this.alfrescoApiService.getInstance().activiti.processInstanceVariablesApi.getProcessInstanceVariables(processInstanceId)
) )
.map((processVars: any[]) => processVars.map((pd) => new ProcessInstanceVariable(pd))) .map((processVars: any[]) => processVars.map((pd) => new ProcessInstanceVariable(pd)))
.catch(err => this.handleProcessError(err)); .catch(err => this.handleProcessError(err));
} }
createOrUpdateProcessInstanceVariables(processDefinitionId: string, variables: ProcessInstanceVariable[]): Observable<ProcessInstanceVariable[]> { createOrUpdateProcessInstanceVariables(processInstanceId: string, variables: ProcessInstanceVariable[]): Observable<ProcessInstanceVariable[]> {
return Observable.fromPromise( return Observable.fromPromise(
this.alfrescoApiService.getInstance().activiti.processInstanceVariablesApi.createOrUpdateProcessInstanceVariables(processDefinitionId, variables) this.alfrescoApiService.getInstance().activiti.processInstanceVariablesApi.createOrUpdateProcessInstanceVariables(processInstanceId, variables)
) )
.catch(err => this.handleProcessError(err)); .catch(err => this.handleProcessError(err));
} }
deleteProcessInstanceVariable(processDefinitionId: string, variableName: string): Observable<void> { deleteProcessInstanceVariable(processInstanceId: string, variableName: string): Observable<void> {
return Observable.fromPromise( return Observable.fromPromise(
this.alfrescoApiService.getInstance().activiti.processInstanceVariablesApi.deleteProcessInstanceVariable(processDefinitionId, variableName) this.alfrescoApiService.getInstance().activiti.processInstanceVariablesApi.deleteProcessInstanceVariable(processInstanceId, variableName)
) )
.catch(err => this.handleProcessError(err)); .catch(err => this.handleProcessError(err));
} }

View File

@ -26,6 +26,7 @@ export * from './components/start-task.component';
export * from './services/tasklist.service'; export * from './services/tasklist.service';
export * from './services/process-upload.service'; export * from './services/process-upload.service';
export * from './services/task-upload.service';
export * from './services/task-filter.service'; export * from './services/task-filter.service';
export * from './models/filter.model'; export * from './models/filter.model';
@ -33,3 +34,4 @@ export * from './models/task-details.model';
export * from './models/task-details.event'; export * from './models/task-details.event';
export * from './models/user-event.model'; export * from './models/user-event.model';
export * from './models/start-task.model'; export * from './models/start-task.model';
export * from './models/task-list.model';

View File

@ -34,8 +34,8 @@ export class ProcessUploadService extends UploadService {
let opts = { let opts = {
isRelatedContent: true isRelatedContent: true
}; };
let taskId = file.options.parentId; let processInstanceId = file.options.parentId;
let promise = this.instanceApi.getInstance().activiti.contentApi.createRelatedContentOnTask(taskId, file.file, opts); let promise = this.instanceApi.getInstance().activiti.contentApi.createRelatedContentOnProcessInstance(processInstanceId, file.file, opts);
promise.catch(err => this.handleError(err)); promise.catch(err => this.handleError(err));

View File

@ -0,0 +1,49 @@
/*!
* @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 { AlfrescoApiService, AppConfigService, UploadService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/throw';
@Injectable()
export class TaskUploadService extends UploadService {
instanceApi: AlfrescoApiService;
constructor(apiService: AlfrescoApiService, appConfigService: AppConfigService) {
super(apiService, appConfigService);
this.instanceApi = apiService;
}
getUploadPromise(file: any): any {
let opts = {
isRelatedContent: true
};
let taskId = file.options.parentId;
let promise = this.instanceApi.getInstance().activiti.contentApi.createRelatedContentOnTask(taskId, file.file, opts);
promise.catch(err => this.handleError(err));
return promise;
}
private handleError(error: any) {
return Observable.throw(error || 'Server error');
}
}