Set loaded schema resources as properties of the work package

pull/4159/head
Alex Dik 9 years ago
parent 1df7fe6661
commit 08efd59277
  1. 16
      frontend/app/components/api/api-v3/hal/work-package-resource.service.ts
  2. 1
      frontend/app/components/wp-edit/wp-edit-form.directive.ts
  3. 3
      frontend/app/typings/open-project.typings.ts

@ -26,14 +26,26 @@
// See doc/COPYRIGHT.rdoc for more details.
//++
function wpResource(HalResource: typeof op.HalResource, apiV3) {
function wpResource(HalResource: typeof op.HalResource) {
class WorkPackageResource extends HalResource {
getForm() {
return this.$links.update(this);
}
getSchema() {
return this.getForm().then(form => form.$embedded.schema);
return this.getForm().then(form => {
const schema = form.$embedded.schema;
angular.forEach(schema, (field, name) => {
if (this[name] && field.writable && field.$isHal
&& Array.isArray(field.allowedValues)) {
this[name] = _.where(field.allowedValues, {name: this[name].name})[0];
}
});
return schema;
});
}
save() {

@ -30,7 +30,6 @@ export class WorkPackageEditFormController {
public workPackage;
public loadSchema() {
//TODO: See `api-work-packages.config.ts`. The schema, if set, should be returned by `getSchema`
return this.workPackage.getSchema();
}

@ -207,6 +207,8 @@ declare namespace op {
public $links;
public $embedded;
public $isHal;
public name:string;
constructor(protected $source:restangular.IElement);
@ -223,6 +225,7 @@ declare namespace op {
interface FieldSchema {
type:string;
writable:boolean;
allowedValues;
}
interface WorkPackageLinks {

Loading…
Cancel
Save