Support for rest dropdown fields (dynamic table)

This commit is contained in:
Denys Vuika 2016-10-24 12:59:38 +01:00 committed by Vito Albano
parent 36dd42b62d
commit 3b898959ee
5 changed files with 47 additions and 7 deletions

View File

@ -51,7 +51,7 @@
</div>
</div>
<div *ngIf="editMode">
<div *ngIf="editMode" class="mdl-shadow--2dp">
<div class="mdl-grid" *ngFor="let column of content.columns">
<div class="mdl-cell mdl-cell--6-col" [ngSwitch]="column.type">
<div *ngSwitchCase="'Dropdown'">

View File

@ -29,4 +29,8 @@ export abstract class CellEditorComponent {
@Input()
column: DynamicTableColumn;
protected handleError(error: any) {
console.error(error);
}
}

View File

@ -2,11 +2,11 @@
<label [attr.for]="column.id">{{column.name}}</label>
<div>
<select
[value]="table.getCellValue(row, column)"
[value]="value"
class="dropdown-editor__select"
(change)="onValueChanged(row, column, $event)">
<option></option>
<option *ngFor="let opt of column.options" [value]="opt.name">{{opt.name}}</option>
<option *ngFor="let opt of options" [value]="opt.name">{{opt.name}}</option>
</select>
</div>
</div>

View File

@ -15,9 +15,10 @@
* limitations under the License.
*/
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { CellEditorComponent } from './../cell.editor';
import { DynamicTableRow, DynamicTableColumn } from './../../../core/index';
import { DynamicTableRow, DynamicTableColumn, DynamicTableColumnOption } from './../../../core/index';
import { FormService } from './../../../../../services/form.service';
@Component({
moduleId: module.id,
@ -25,7 +26,36 @@ import { DynamicTableRow, DynamicTableColumn } from './../../../core/index';
templateUrl: './dropdown.editor.html',
styleUrls: ['./dropdown.editor.css']
})
export class DropdownEditorComponent extends CellEditorComponent {
export class DropdownEditorComponent extends CellEditorComponent implements OnInit {
value: any;
options: DynamicTableColumnOption[] = [];
constructor(private formService: FormService) {
super();
}
ngOnInit() {
this.value = this.table.getCellValue(this.row, this.column);
this.options = this.column.options || [];
let field = this.table.field;
if (field && field.restUrl) {
this.formService
.getRestFieldValuesColumn(
field.form.taskId,
field.id,
this.column.id
)
.subscribe(
(result: DynamicTableColumnOption[]) => {
this.column.options = result || [];
this.options = this.column.options;
},
err => this.handleError(err)
);
}
}
onValueChanged(row: DynamicTableRow, column: DynamicTableColumn, event: Event) {
let value: any = (<HTMLInputElement>event.srcElement).value;
@ -33,4 +63,5 @@ export class DropdownEditorComponent extends CellEditorComponent {
row.value[column.id] = value;
}
}

View File

@ -208,7 +208,12 @@ export class FormService {
getRestFieldValues(taskId: string, field: string): Observable<any> {
let alfrescoApi = this.apiService.getInstance();
return Observable.fromPromise(alfrescoApi.activiti.taskFormsApi.getRestFieldValues(taskId, field));
return Observable.fromPromise(alfrescoApi.activiti.taskApi.getRestFieldValues(taskId, field));
}
getRestFieldValuesColumn(taskId: string, field: string, column?: string): Observable<any> {
let alfrescoApi = this.apiService.getInstance();
return Observable.fromPromise(alfrescoApi.activiti.taskApi.getRestFieldValuesColumn(taskId, field, column));
}
// TODO: uses private webApp api