diff --git a/demo-shell-ng2/app.config-dev.json b/demo-shell-ng2/app.config-dev.json
index 4fd4c1ce04..fa12f1e59d 100644
--- a/demo-shell-ng2/app.config-dev.json
+++ b/demo-shell-ng2/app.config-dev.json
@@ -3,5 +3,21 @@
"bpmHost": "http://{hostname}:{port}/bpm",
"application": {
"name": "Alfresco"
+ },
+ "activiti": {
+ "rest": {
+ "fields": [
+ {
+ "processId": "0",
+ "taskId": "7501",
+ "fieldId": "label10",
+ "values": [
+ { "id": "f1", "name": "Field 1" },
+ { "id": "f2", "name": "Field 2" },
+ { "id": "f3", "name": "Field 3" }
+ ]
+ }
+ ]
+ }
}
}
diff --git a/demo-shell-ng2/app/app.component.html b/demo-shell-ng2/app/app.component.html
index 47978f9fda..92e00fa06f 100644
--- a/demo-shell-ng2/app/app.component.html
+++ b/demo-shell-ng2/app/app.component.html
@@ -21,6 +21,7 @@
DocumentList
Process Services
Form
+ Form List
Login
Settings
diff --git a/demo-shell-ng2/app/app.module.ts b/demo-shell-ng2/app/app.module.ts
index fbef11c1c8..0b1b8f684f 100644
--- a/demo-shell-ng2/app/app.module.ts
+++ b/demo-shell-ng2/app/app.module.ts
@@ -44,6 +44,8 @@ import { ChartsModule } from 'ng2-charts';
import { CreateFolderDialog } from './dialogs/create-folder.dialog';
import { DebugAppConfigService } from './services/debug-app-config.service';
+import { FormListDemoComponent } from './components/form/form-list-demo.component';
+
import {
HomeComponent,
DataTableDemoComponent,
@@ -115,7 +117,8 @@ if (process.env.ENV === 'production') {
FormNodeViewer,
CreateFolderDialog,
SettingsComponent,
- FormDemoComponent
+ FormDemoComponent,
+ FormListDemoComponent
],
providers: [
{ provide: AppConfigService, useClass: DebugAppConfigService }
diff --git a/demo-shell-ng2/app/app.routes.ts b/demo-shell-ng2/app/app.routes.ts
index b8dc4a14b9..60b93a14da 100644
--- a/demo-shell-ng2/app/app.routes.ts
+++ b/demo-shell-ng2/app/app.routes.ts
@@ -39,6 +39,7 @@ import {
} from './components/index';
import { UploadButtonComponent } from 'ng2-alfresco-upload';
+import { FormListDemoComponent } from './components/form/form-list-demo.component';
export const appRoutes: Routes = [
{ path: 'login', component: LoginDemoComponent },
@@ -132,7 +133,8 @@ export const appRoutes: Routes = [
},
{ path: 'about', component: AboutComponent },
{ path: 'settings', component: SettingsComponent },
- { path: 'form', component: FormDemoComponent }
+ { path: 'form', component: FormDemoComponent },
+ { path: 'form-list', component: FormListDemoComponent }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
diff --git a/demo-shell-ng2/app/components/form/form-demo.component.css b/demo-shell-ng2/app/components/form/form-demo.component.css
index ee6f7a61fb..3608df8b91 100644
--- a/demo-shell-ng2/app/components/form/form-demo.component.css
+++ b/demo-shell-ng2/app/components/form/form-demo.component.css
@@ -1,8 +1,3 @@
.form-container {
padding: 10px;
}
-
-.store-form-container{
- width: 80%;
- height: 80%;
-}
diff --git a/demo-shell-ng2/app/components/form/form-demo.component.html b/demo-shell-ng2/app/components/form/form-demo.component.html
index 250aaec488..56b48c27f2 100644
--- a/demo-shell-ng2/app/components/form/form-demo.component.html
+++ b/demo-shell-ng2/app/components/form/form-demo.component.html
@@ -1,9 +1,4 @@
-
-
-
+
-
-
diff --git a/demo-shell-ng2/app/components/form/form-demo.component.ts b/demo-shell-ng2/app/components/form/form-demo.component.ts
index e142c75426..73794196b2 100644
--- a/demo-shell-ng2/app/components/form/form-demo.component.ts
+++ b/demo-shell-ng2/app/components/form/form-demo.component.ts
@@ -15,34 +15,25 @@
* limitations under the License.
*/
-import { Component, OnInit, ViewChild } from '@angular/core';
+import { Component, Inject, OnInit } from '@angular/core';
import { FormModel, FormService } from 'ng2-activiti-form';
+import { InMemoryFormService } from '../../services/in-memory-form.service';
import { DemoForm } from './demo-form';
-import { ActivitiForm } from 'ng2-activiti-form';
-
-declare var componentHandler;
@Component({
selector: 'form-demo',
templateUrl: 'form-demo.component.html',
- styleUrls: [
- 'form-demo.component.css'
+ styleUrls: [ 'form-demo.component.css' ],
+ providers: [
+ { provide: FormService, useClass: InMemoryFormService }
]
})
export class FormDemoComponent implements OnInit {
- @ViewChild(ActivitiForm)
- activitiForm: ActivitiForm;
-
- formList: any [] = [];
-
form: FormModel;
- formId: string;
- storedData: any = {};
- restoredData: any = {};
-
- constructor(private formService: FormService) {
+ constructor(@Inject(FormService) private formService: InMemoryFormService) {
+ // Prevent default outcome actions
formService.executeOutcome.subscribe(e => {
e.preventDefault();
console.log(e.outcome);
@@ -50,56 +41,8 @@ export class FormDemoComponent implements OnInit {
}
ngOnInit() {
- this.formList.push({ name: 'Demo Form Definition', lastUpdatedByFullName: 'Demo Name User', lastUpdated: '2017-06-23T13:20:30.754+0000', isFake: true });
- }
-
- ngAfterViewInit() {
- // workaround for MDL issues with dynamic components
- if (componentHandler) {
- componentHandler.upgradeAllRegistered();
- }
- }
-
- onRowDblClick(event: CustomEvent) {
- let rowForm = event.detail.value.obj;
-
- if (rowForm.isFake) {
- let formDefinitionJSON: any = DemoForm.getDefinition();
- let form = this.formService.parseForm(formDefinitionJSON);
- this.form = form;
- } else {
- this.formService.getFormDefinitionById(rowForm.id).subscribe((definition) => {
- let form = this.formService.parseForm(definition);
- this.form = form;
- });
- }
- console.log(rowForm);
- }
-
- isEmptyForm() {
- return this.form === null || this.form === undefined;
- }
-
- store() {
- this.clone(this.activitiForm.form.values, this.storedData);
- console.log('DATA SAVED');
- console.log(this.storedData);
- console.log('DATA SAVED');
- this.restoredData = null;
- }
-
- clone(objToCopyFrom, objToCopyTo) {
- for (let attribute in objToCopyFrom) {
- if (objToCopyFrom.hasOwnProperty(attribute)) {
- objToCopyTo[attribute] = objToCopyFrom[attribute];
- }
- }
- return objToCopyTo;
- }
-
- restore() {
- this.restoredData = this.storedData;
- this.storedData = {};
+ let formDefinitionJSON: any = DemoForm.getDefinition();
+ this.form = this.formService.parseForm(formDefinitionJSON);
}
}
diff --git a/demo-shell-ng2/app/components/form/form-list-demo.component.ts b/demo-shell-ng2/app/components/form/form-list-demo.component.ts
new file mode 100644
index 0000000000..0f10814c38
--- /dev/null
+++ b/demo-shell-ng2/app/components/form/form-list-demo.component.ts
@@ -0,0 +1,112 @@
+/*!
+ * @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 { Component, ViewChild } from '@angular/core';
+import { FormModel, FormService } from 'ng2-activiti-form';
+import { ActivitiForm } from 'ng2-activiti-form';
+
+declare var componentHandler;
+
+@Component({
+ selector: 'form-list-demo',
+ template: `
+
+
+
+
+
+ `,
+ styles: [`
+ .form-container {
+ padding: 10px;
+ }
+
+ .store-form-container{
+ width: 80%;
+ height: 80%;
+ }
+ `]
+})
+export class FormListDemoComponent {
+
+ @ViewChild(ActivitiForm)
+ activitiForm: ActivitiForm;
+
+ formList: any [] = [];
+
+ form: FormModel;
+ formId: string;
+
+ storedData: any = {};
+ restoredData: any = {};
+
+ constructor(private formService: FormService) {
+ // Prevent default outcome actions
+ formService.executeOutcome.subscribe(e => {
+ e.preventDefault();
+ console.log(e.outcome);
+ });
+ }
+
+ ngAfterViewInit() {
+ // workaround for MDL issues with dynamic components
+ if (componentHandler) {
+ componentHandler.upgradeAllRegistered();
+ }
+ }
+
+ onRowDblClick(event: CustomEvent) {
+ let rowForm = event.detail.value.obj;
+
+ this.formService.getFormDefinitionById(rowForm.id).subscribe((definition) => {
+ let form = this.formService.parseForm(definition);
+ this.form = form;
+ });
+
+ console.log(rowForm);
+ }
+
+ isEmptyForm() {
+ return this.form === null || this.form === undefined;
+ }
+
+ store() {
+ this.clone(this.activitiForm.form.values, this.storedData);
+ console.log('DATA SAVED');
+ console.log(this.storedData);
+ console.log('DATA SAVED');
+ this.restoredData = null;
+ }
+
+ clone(objToCopyFrom, objToCopyTo) {
+ for (let attribute in objToCopyFrom) {
+ if (objToCopyFrom.hasOwnProperty(attribute)) {
+ objToCopyTo[attribute] = objToCopyFrom[attribute];
+ }
+ }
+ return objToCopyTo;
+ }
+
+ restore() {
+ this.restoredData = this.storedData;
+ this.storedData = {};
+ }
+
+}
diff --git a/demo-shell-ng2/app/services/in-memory-form.service.ts b/demo-shell-ng2/app/services/in-memory-form.service.ts
new file mode 100644
index 0000000000..e8adeeaa6a
--- /dev/null
+++ b/demo-shell-ng2/app/services/in-memory-form.service.ts
@@ -0,0 +1,83 @@
+/*!
+ * @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 { Injectable } from '@angular/core';
+import { Observable } from 'rxjs/Rx';
+import { AlfrescoApiService, LogService } from 'ng2-alfresco-core';
+import { FormService, EcmModelService, FormFieldOption } from 'ng2-activiti-form';
+import { AppConfigService } from 'ng2-alfresco-core';
+
+interface ActivitiData {
+ rest: {
+ fields: Array<{
+ processId?: string,
+ taskId?: string,
+ fieldId?: string,
+ values?: Array<{
+ id: string,
+ name: string
+ }>
+ }>
+ };
+}
+
+@Injectable()
+export class InMemoryFormService extends FormService {
+
+ private data: ActivitiData;
+
+ constructor(appConfig: AppConfigService,
+ ecmModelService: EcmModelService,
+ apiService: AlfrescoApiService,
+ logService: LogService) {
+ super(ecmModelService, apiService, logService);
+ this.data = appConfig.get
('activiti');
+ }
+
+ /** @override */
+ getRestFieldValues(taskId: string, fieldId: string): Observable {
+ // Uncomment this to use original call
+ // return super.getRestFieldValues(taskId, fieldId);
+
+ console.log(`getRestFieldValues: ${taskId} => ${fieldId}`);
+ return new Observable(observer => {
+ let field = this.data.rest.fields.find(
+ f => f.taskId === taskId && f.fieldId === fieldId
+ );
+ let values: FormFieldOption[] = field.values || [];
+ console.log(values);
+ observer.next(values);
+ });
+ }
+
+ /** @override */
+ getRestFieldValuesByProcessId(processDefinitionId: string, fieldId: string): Observable {
+ // Uncomment this to use original call
+ // return super.getRestFieldValuesByProcessId(processDefinitionId, fieldId);
+
+ console.log(`getRestFieldValuesByProcessId: ${processDefinitionId} => ${fieldId}`);
+ return new Observable(observer => {
+ let field = this.data.rest.fields.find(
+ f => f.processId === processDefinitionId && f.fieldId === fieldId
+ );
+ let values: FormFieldOption[] = field.values || [];
+ console.log(values);
+ observer.next(values);
+ });
+ }
+
+}
diff --git a/ng2-components/ng2-activiti-form/src/services/form.service.ts b/ng2-components/ng2-activiti-form/src/services/form.service.ts
index c88b69fd4d..a29cbeb296 100644
--- a/ng2-components/ng2-activiti-form/src/services/form.service.ts
+++ b/ng2-components/ng2-activiti-form/src/services/form.service.ts
@@ -100,15 +100,27 @@ export class FormService {
stencilSet: 0
};
- return Observable.fromPromise(this.apiService.getInstance().activiti.modelsApi.createModel(dataModel));
+ return Observable.fromPromise(
+ this.apiService.getInstance().activiti.modelsApi.createModel(dataModel)
+ );
+ }
+
+ saveForm(formId: string, formModel: FormDefinitionModel): Observable {
+ return Observable.fromPromise(
+ this.apiService.getInstance().activiti.editorApi.saveForm(formId, formModel)
+ );
}
/**
+ * @deprecated in 1.7.0, use saveForm API instead
* Add Fileds to A form
* @returns {Observable}
*/
addFieldsToAForm(formId: string, formModel: FormDefinitionModel): Observable {
- return Observable.fromPromise(this.apiService.getInstance().activiti.editorApi.saveForm(formId, formModel));
+ console.log('addFieldsToAForm is deprecated in 1.7.0, use saveForm API instead');
+ return Observable.fromPromise(
+ this.apiService.getInstance().activiti.editorApi.saveForm(formId, formModel)
+ );
}
/**
@@ -121,12 +133,12 @@ export class FormService {
};
return Observable.fromPromise(
- this.apiService.getInstance().activiti.modelsApi.getModels(opts))
- .map(function (forms: any) {
- return forms.data.find(formdata => formdata.name === name);
- })
- .catch(err => this.handleError(err)
- );
+ this.apiService.getInstance().activiti.modelsApi.getModels(opts)
+ )
+ .map(function (forms: any) {
+ return forms.data.find(formdata => formdata.name === name);
+ })
+ .catch(err => this.handleError(err));
}
/**
@@ -139,10 +151,8 @@ export class FormService {
};
return Observable.fromPromise(
- this.apiService.getInstance().activiti.modelsApi.getModels(opts))
- .map((response: any) => response.data || [])
- .catch(err => this.handleError(err));
-
+ this.apiService.getInstance().activiti.modelsApi.getModels(opts)
+ );
}
/**