mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-920] Process Header Component - Refactoring (#2073)
[ADF-920] Process Header Component - Refactoring
This commit is contained in:
committed by
Eugenio Romano
parent
9113170f2c
commit
82e8dfa3b0
@@ -15,9 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||
import { AlfrescoTranslationService, LogService } from 'ng2-alfresco-core';
|
||||
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { AlfrescoTranslationService, CardViewDateItemModel, CardViewItem, CardViewTextItemModel, LogService } from 'ng2-alfresco-core';
|
||||
import { ProcessInstance } from '../models/process-instance.model';
|
||||
|
||||
declare let componentHandler: any;
|
||||
@@ -27,19 +26,12 @@ declare let componentHandler: any;
|
||||
templateUrl: './process-instance-header.component.html',
|
||||
styleUrls: ['./process-instance-header.component.css']
|
||||
})
|
||||
export class ProcessInstanceHeaderComponent {
|
||||
|
||||
@Input()
|
||||
showDiagram: boolean = true;
|
||||
export class ProcessInstanceHeaderComponent implements OnChanges {
|
||||
|
||||
@Input()
|
||||
processInstance: ProcessInstance;
|
||||
|
||||
@Output()
|
||||
onError: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
@Output()
|
||||
showProcessDiagram: EventEmitter<any> = new EventEmitter<any>();
|
||||
properties: CardViewItem [];
|
||||
|
||||
constructor(private translate: AlfrescoTranslationService,
|
||||
private logService: LogService) {
|
||||
@@ -49,37 +41,47 @@ export class ProcessInstanceHeaderComponent {
|
||||
}
|
||||
}
|
||||
|
||||
getStartedByFullName(): string {
|
||||
if (this.processInstance && this.processInstance.startedBy) {
|
||||
return (this.processInstance.startedBy.firstName && this.processInstance.startedBy.firstName !== 'null'
|
||||
? this.processInstance.startedBy.firstName + ' ' : '') +
|
||||
this.processInstance.startedBy.lastName;
|
||||
}
|
||||
return '';
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
this.refreshData();
|
||||
}
|
||||
|
||||
getFormatDate(value, format: string) {
|
||||
let datePipe = new DatePipe('en-US');
|
||||
try {
|
||||
return datePipe.transform(value, format);
|
||||
} catch (err) {
|
||||
this.logService.error(`ProcessListInstanceHeader: error parsing date ${value} to format ${format}`);
|
||||
refreshData() {
|
||||
if (this.processInstance) {
|
||||
this.properties = [
|
||||
new CardViewTextItemModel({label: 'Status:', value: this.getProcessStatus(), key: 'status'}),
|
||||
new CardViewDateItemModel({label: 'Due Date:', value: this.processInstance.ended, format: 'MMM DD YYYY', key: 'dueDate', default: 'No date'}),
|
||||
new CardViewTextItemModel({label: 'Category:', value: this.processInstance.processDefinitionCategory, key: 'category', default: 'No category'}),
|
||||
new CardViewTextItemModel(
|
||||
{
|
||||
label: 'Created By:',
|
||||
value: this.getStartedByFullName(),
|
||||
key: 'assignee',
|
||||
default: 'No assignee'
|
||||
}),
|
||||
new CardViewDateItemModel({label: 'Created:', value: this.processInstance.started, format: 'MMM DD YYYY', key: 'created'}),
|
||||
new CardViewTextItemModel({label: 'Id:', value: this.processInstance.id, key: 'id'}),
|
||||
new CardViewTextItemModel({label: 'Description:', value: this.processInstance.processDefinitionDescription, key: 'description', default: 'No description'})
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
getProcessStatus(): string {
|
||||
if (this.processInstance) {
|
||||
return this.isRunning() ? 'Running' : 'Completed';
|
||||
}
|
||||
}
|
||||
|
||||
getStartedByFullName(): string {
|
||||
let fullName = '';
|
||||
if (this.processInstance && this.processInstance.startedBy) {
|
||||
fullName += this.processInstance.startedBy.firstName || '';
|
||||
fullName += fullName ? ' ' : '';
|
||||
fullName += this.processInstance.startedBy.lastName || '';
|
||||
}
|
||||
return fullName;
|
||||
}
|
||||
|
||||
isRunning(): boolean {
|
||||
return this.processInstance && !this.processInstance.ended;
|
||||
}
|
||||
|
||||
isDiagramDisabled(): boolean {
|
||||
return !this.isRunning() ? true : undefined;
|
||||
}
|
||||
|
||||
showDiagramEvent() {
|
||||
this.showProcessDiagram.emit({value: this.processInstance.id});
|
||||
}
|
||||
|
||||
isShowDiagram(): boolean {
|
||||
return this.showDiagram;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user