From b75c9b7be98a6a5c4f3f516ac1b4ec69f9875c17 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 20 Jul 2016 11:11:33 +0100 Subject: [PATCH] #440 task selector - simple task selector for dev/demo purposes --- .../components/activiti-form.component.css | 4 ++ .../components/activiti-form.component.html | 47 +++++++++++-------- .../src/components/activiti-form.component.ts | 31 ++++++------ .../src/components/widgets/widget.model.ts | 2 +- .../src/services/form.service.ts | 15 ++++++ 5 files changed, 62 insertions(+), 37 deletions(-) create mode 100644 ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.css diff --git a/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.css b/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.css new file mode 100644 index 0000000000..0258de8fe1 --- /dev/null +++ b/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.css @@ -0,0 +1,4 @@ +.activiti-task-list__item:hover { + cursor: pointer; + font-weight: bold; +} diff --git a/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.html b/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.html index 2ebf12ebda..90fd2cc0a4 100644 --- a/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.html +++ b/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.html @@ -1,23 +1,32 @@ -
-
- +
+ +
+
No tasks found
+
+
    +
  • + + launch + {{task.name}} + +
+
-
- + +
+
+

Please select a Task

+
+
+
+ +
+
+ +
+
- - diff --git a/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.ts b/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.ts index b58555e359..e01118d03f 100644 --- a/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.ts +++ b/ng2-components/ng2-alfresco-activiti-form/src/components/activiti-form.component.ts @@ -27,18 +27,11 @@ import { FormModel } from './widgets/widget.model'; declare let __moduleName: string; declare var componentHandler; -@Component({ - selector: 'child-component', - template: 'Hello {{name}}' -}) -class ChildComponent { - name: string; -} - @Component({ moduleId: __moduleName, selector: 'activiti-form', templateUrl: './activiti-form.component.html', + styleUrls: ['./activiti-form.component.css'], directives: [WIDGET_DIRECTIVES], providers: [ FormService @@ -48,23 +41,20 @@ export class ActivitiForm implements OnInit, AfterViewChecked { task: any; form: FormModel; + tasks: any[] = []; hasForm(): boolean { return this.form ? true : false; } + hasTasks(): boolean { + return this.tasks && this.tasks.length > 0; + } + constructor(private formService: FormService) {} ngOnInit() { - this.formService.getTask('1').subscribe(task => { - // console.log(task); - this.task = task; - - this.formService.getTaskForm('1').subscribe(form => { - // console.log(form); - this.form = new FormModel(form); - }); - }); + this.formService.getTasks().subscribe(val => this.tasks = val || []); } ngAfterViewChecked() { @@ -74,4 +64,11 @@ export class ActivitiForm implements OnInit, AfterViewChecked { } } + onTaskClicked(task, e) { + // alert(`Task: ${task.name} clicked.`); + this.formService + .getTaskForm(task.id) + .subscribe(form => this.form = new FormModel(form)); + } + } diff --git a/ng2-components/ng2-alfresco-activiti-form/src/components/widgets/widget.model.ts b/ng2-components/ng2-alfresco-activiti-form/src/components/widgets/widget.model.ts index 4d7174e135..4154c6f561 100644 --- a/ng2-components/ng2-alfresco-activiti-form/src/components/widgets/widget.model.ts +++ b/ng2-components/ng2-alfresco-activiti-form/src/components/widgets/widget.model.ts @@ -106,7 +106,7 @@ export class ContainerModel extends FormWidgetModel { Object.keys(json.fields).map(key => { let fields = (json.fields[key] || []).map(f => new FormFieldModel(form, f)); - let col = this.columns[parseInt(key) - 1]; + let col = this.columns[parseInt(key, 10) - 1]; col.fields = fields; }); } diff --git a/ng2-components/ng2-alfresco-activiti-form/src/services/form.service.ts b/ng2-components/ng2-alfresco-activiti-form/src/services/form.service.ts index cc730c049c..5e08e9e604 100644 --- a/ng2-components/ng2-alfresco-activiti-form/src/services/form.service.ts +++ b/ng2-components/ng2-alfresco-activiti-form/src/services/form.service.ts @@ -27,6 +27,16 @@ export class FormService { constructor(private http: Http) { } + getTasks(): Observable { + let url = `${this.basePath}/api/enterprise/tasks/query`; + let body = JSON.stringify({}); + let options = this.getRequestOptions(); + + return this.http.post(url, body, options) + .map(this.toJsonArray) + .catch(this.handleError); + } + getTask(id: string): Observable { let url = `${this.basePath}/api/enterprise/tasks/${id}`; let options = this.getRequestOptions(); @@ -63,6 +73,11 @@ export class FormService { return body || {}; } + private toJsonArray(res: Response) { + let body = res.json(); + return body.data || []; + } + private handleError (error: any) { // In a real world app, we might use a remote logging infrastructure // We'd also dig deeper into the error to get a better message