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. // See doc/COPYRIGHT.rdoc for more details.
//++ //++
function wpResource(HalResource: typeof op.HalResource, apiV3) { function wpResource(HalResource: typeof op.HalResource) {
class WorkPackageResource extends HalResource { class WorkPackageResource extends HalResource {
getForm() { getForm() {
return this.$links.update(this); return this.$links.update(this);
} }
getSchema() { 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() { save() {

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

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

Loading…
Cancel
Save