Fix/invalid date entry (#4398)

Allows to correct errors made when data of an invalid format is inserted to one of the WP inline edit fields, e.g. when 'aaaaa' is inserted for 'start date'.

Before the fix, the promise calling 'POST work_packages/:id/form' was assigned to the work package resource. But in case of an error, the result of the promise is an error and not a form. As we do rely on the links present in the form, we need to ensure that we always have a form where we expect it.

The PR also fixes a couple of errors in the js console when invalid information is added which are caused by the API not specifying the invalid column. While the PR increases the robustness of the front end, it does not improve the API.
pull/4411/head
ulferts 9 years ago committed by Oliver Günther
parent 34cc6ba6f5
commit e7ff5eb374
  1. 10
      frontend/app/components/api/api-v3/hal-resources/error-resource.service.ts
  2. 33
      frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts
  3. 2
      frontend/app/components/wp-edit/wp-edit-form.directive.ts

@ -61,7 +61,15 @@ export class ErrorResource extends HalResource {
} }
public getInvolvedColumns():string[] { public getInvolvedColumns():string[] {
var columns = this.details ? [{details: this.details}] : this.errors; var columns = [];
if (this.details) {
columns = [{ details: this.details }]
}
else if (this.errors) {
columns = this.errors;
}
return columns.map(field => field.details.attribute); return columns.map(field => field.details.attribute);
} }
} }

@ -103,6 +103,27 @@ class WorkPackageResource extends HalResource {
return this.form; return this.form;
} }
public updateForm(payload) {
// Always resolve form to the latest form
// This way, we won't have to actively reset it.
// But store the existing form in case of an error.
// Because if we get an error, the object returned is not a form
// and thus lacks the links the implementation depends upon.
var oldForm = this.form
this.form = this.$links.update(payload);
var deferred = $q.defer();
this.form
.then(deferred.resolve)
.catch(error => {
this.form = oldForm;
deferred.reject(error);
});
return deferred.promise;
}
public getSchema() { public getSchema() {
return this.getForm().then(form => { return this.getForm().then(form => {
const schema = form.$embedded.schema; const schema = form.$embedded.schema;
@ -120,19 +141,9 @@ class WorkPackageResource extends HalResource {
} }
public save() { public save() {
const plain = this.$plain();
delete plain.createdAt;
delete plain.updatedAt;
var deferred = $q.defer(); var deferred = $q.defer();
// Always resolve form to the latest form this.updateForm(this.$source)
// This way, we won't have to actively reset it.
this.form = this.$links.update(this.$source);
this.form
.catch(deferred.reject)
.then(form => { .then(form => {
// Override the current schema with // Override the current schema with

@ -102,6 +102,8 @@ export class WorkPackageEditFormController {
} }
private handleErrorenousColumns(columns:string[]) { private handleErrorenousColumns(columns:string[]) {
if (columns.length === 0) { return; }
var selected = this.QueryService.getSelectedColumnNames(); var selected = this.QueryService.getSelectedColumnNames();
var active = _.find(this.fields, (f:any) => f.active); var active = _.find(this.fields, (f:any) => f.active);
columns.reverse().map(name => { columns.reverse().map(name => {

Loading…
Cancel
Save