#440 decouple component and it's demo content

- moved demo-related code to ‘demo app’
- clean alfresco-form component api
This commit is contained in:
Denys Vuika 2016-07-21 15:59:45 +01:00
parent 145cb88e1f
commit 57adc26b8b
8 changed files with 120 additions and 75 deletions

View File

@ -0,0 +1,4 @@
.activiti-task-list__item:hover {
cursor: pointer;
font-weight: bold;
}

View File

@ -0,0 +1,22 @@
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col">
<div *ngIf="!hasTasks()">No tasks found</div>
<div *ngIf="hasTasks()">
<ul class="mdl-list">
<li *ngFor="let task of tasks"
class="mdl-list__item activiti-task-list__item"
(click)="onTaskClicked(task, $event)">
<span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-icon">launch</i>
{{task.name}}
</span>
</ul>
</div>
</div>
<div class="mdl-cell mdl-cell--10-col">
<activiti-form [taskId]="selectedTask?.id"></activiti-form>
</div>
</div>

View File

@ -15,16 +15,45 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component } from '@angular/core'; import { Component, OnInit, AfterViewChecked } from '@angular/core';
import { ActivitiForm } from 'ng2-alfresco-activiti-form'; import { ActivitiForm, FormService } from 'ng2-alfresco-activiti-form';
declare let __moduleName: string;
declare var componentHandler;
@Component({ @Component({
moduleId: __moduleName,
selector: 'activiti-demo', selector: 'activiti-demo',
template: ` templateUrl: './activiti-demo.component.html',
<activiti-form></activiti-form> styleUrls: ['./activiti-demo.component.css'],
`, directives: [ActivitiForm],
directives: [ActivitiForm] providers: [FormService]
}) })
export class ActivitiDemoComponent { export class ActivitiDemoComponent implements OnInit, AfterViewChecked {
tasks: any[] = [];
selectedTask: any;
hasTasks(): boolean {
return this.tasks && this.tasks.length > 0;
}
constructor(private formService: FormService) {}
ngOnInit() {
this.formService.getTasks().subscribe(val => this.tasks = val || []);
}
ngAfterViewChecked() {
// workaround for MDL issues with dynamic components
if (componentHandler) {
componentHandler.upgradeAllRegistered();
}
}
onTaskClicked(task, e) {
this.selectedTask = task;
}
} }

View File

@ -1,3 +1,7 @@
# Alfresco Activiti Form component for Angular 2 # Alfresco Activiti Form component for Angular 2
TBD TBD
```html
<activiti-form [taskId]="selectedTask?.id"></activiti-form>
```

View File

@ -16,3 +16,5 @@
*/ */
export * from './src/components/activiti-form.component'; export * from './src/components/activiti-form.component';
export * from './src/services/form.service';
export * from './src/components/widgets/index';

View File

@ -7,12 +7,6 @@
background-color: #fff; background-color: #fff;
} }
.activiti-task-list__item:hover {
cursor: pointer;
font-weight: bold;
}
.activiti-form-debug-container { .activiti-form-debug-container {
padding: 10px; padding: 10px;
} }

View File

@ -1,53 +1,38 @@
<div class="mdl-grid"> <div>
<div *ngIf="!hasForm()">
<div class="mdl-cell mdl-cell--2-col"> <h3 style="text-align: center">Please select a Task</h3>
<div *ngIf="!hasTasks()">No tasks found</div>
<div *ngIf="hasTasks()">
<ul class="mdl-list">
<li *ngFor="let task of tasks"
class="mdl-list__item activiti-task-list__item"
(click)="onTaskClicked(task, $event)">
<span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-icon">launch</i>
{{task.name}}
</span>
</ul>
</div>
</div> </div>
<div *ngIf="hasForm()">
<div class="mdl-cell mdl-cell--10-col"> <div class="mdl-card mdl-shadow--2dp activiti-form-container">
<div *ngIf="!hasForm()"> <div *ngIf="form.taskName" class="mdl-card__title">
<h3 style="text-align: center">Please select a Task</h3> <h2 class="mdl-card__title-text">{{form.taskName}}</h2>
</div> </div>
<div *ngIf="hasForm()"> <div class="mdl-card__media">
<div *ngIf="form.hasTabs()">
<tabs-widget [tabs]="form.tabs"></tabs-widget>
</div>
<div class="mdl-card mdl-shadow--2dp activiti-form-container"> <div *ngIf="!form.hasTabs() && form.hasFields()">
<div *ngIf="task" class="mdl-card__title"> <container-widget [content]="form.fields[0]"></container-widget>
<h2 class="mdl-card__title-text">{{task.name}}</h2>
</div>
<div class="mdl-card__media">
<div *ngIf="form.hasTabs()">
<tabs-widget [tabs]="form.tabs"></tabs-widget>
</div>
<div *ngIf="!form.hasTabs() && form.hasFields()">
<container-widget [content]="form.fields[0]"></container-widget>
</div>
</div>
<div *ngIf="form.hasOutcomes()" class="mdl-card__actions mdl-card--border">
<button *ngFor="let outcome of form.outcomes"
alfresco-mdl-button
[class.mdl-button--colored]="!outcome.isSystem"
(click)="onOutcomeClicked(outcome, $event)">
{{outcome.name}}
</button>
</div> </div>
</div> </div>
<div *ngIf="form.hasOutcomes()" class="mdl-card__actions mdl-card--border">
<button *ngFor="let outcome of form.outcomes"
alfresco-mdl-button
[class.mdl-button--colored]="!outcome.isSystem"
(click)="onOutcomeClicked(outcome, $event)">
{{outcome.name}}
</button>
</div>
</div> </div>
</div> </div>
</div> </div>
<!--
For debugging and data visualisation purposes,
will be removed during future revisions
-->
<div class="activiti-form-debug-container"> <div class="activiti-form-debug-container">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-1" [class.is-checked]="debugMode"> <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-1" [class.is-checked]="debugMode">
@ -62,8 +47,5 @@
<h4>Form</h4> <h4>Form</h4>
<pre>{{form.json | json}}</pre> <pre>{{form.json | json}}</pre>
<h4>Task</h4>
<pre>{{task | json}}</pre>
</div> </div>
</div> </div>

View File

@ -17,8 +17,9 @@
import { import {
Component, Component,
OnInit, OnInit, AfterViewChecked, OnChanges,
AfterViewChecked SimpleChange,
Input
} from '@angular/core'; } from '@angular/core';
import { MATERIAL_DESIGN_DIRECTIVES } from 'ng2-alfresco-core'; import { MATERIAL_DESIGN_DIRECTIVES } from 'ng2-alfresco-core';
@ -39,26 +40,24 @@ declare var componentHandler;
directives: [MATERIAL_DESIGN_DIRECTIVES, ContainerWidget, TabsWidget], directives: [MATERIAL_DESIGN_DIRECTIVES, ContainerWidget, TabsWidget],
providers: [FormService] providers: [FormService]
}) })
export class ActivitiForm implements OnInit, AfterViewChecked { export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
@Input()
taskId: string;
task: any;
form: FormModel; form: FormModel;
tasks: any[] = [];
debugMode: boolean = false; debugMode: boolean = false;
hasForm(): boolean { hasForm(): boolean {
return this.form ? true : false; return this.form ? true : false;
} }
hasTasks(): boolean {
return this.tasks && this.tasks.length > 0;
}
constructor(private formService: FormService) {} constructor(private formService: FormService) {}
ngOnInit() { ngOnInit() {
this.formService.getTasks().subscribe(val => this.tasks = val || []); if (this.taskId) {
this.loadForm(this.taskId);
}
} }
ngAfterViewChecked() { ngAfterViewChecked() {
@ -68,14 +67,14 @@ export class ActivitiForm implements OnInit, AfterViewChecked {
} }
} }
onTaskClicked(task, e) { ngOnChanges(changes: {[propertyName: string]: SimpleChange}) {
// alert(`Task: ${task.name} clicked.`); let taskId = changes['taskId'];
this.task = task; if (taskId && taskId.currentValue) {
this.formService this.loadForm(taskId.currentValue);
.getTaskForm(task.id) }
.subscribe(form => this.form = new FormModel(form));
} }
onOutcomeClicked(outcome: FormOutcomeModel, event?: Event) { onOutcomeClicked(outcome: FormOutcomeModel, event?: Event) {
if (outcome) { if (outcome) {
if (outcome.isSystem) { if (outcome.isSystem) {
@ -87,6 +86,15 @@ export class ActivitiForm implements OnInit, AfterViewChecked {
} }
} }
private loadForm(taskId: string) {
this.formService
.getTaskForm(taskId)
.subscribe(
form => this.form = new FormModel(form),
err => console.log(err)
);
}
private saveTaskForm() { private saveTaskForm() {
let form = { let form = {
values: this.form.values values: this.form.values