Skip to content

Commit

Permalink
FIX: Ensure that entity creation works for tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
macite committed Dec 9, 2020
1 parent 1fa7eeb commit 072afde
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/app/common/entity-form/entity-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class EntityFormComponent<T extends Entity> implements OnInit {
response = service.update(this.selected);
} else if (!this.selected) {
// Nothing selected, which means we're creating something new
response = service.create(this.formDataToNewObject(service.serverKey));
response = service.create(this.formDataToNewObject(service.serverKey), this.otherOnCreate());
} else {
// Nothing has changed if the selected value, so we want to inform the user
alertService.add('danger', `${service.entityName} was not changed`, 6000);
Expand Down Expand Up @@ -179,6 +179,18 @@ export class EntityFormComponent<T extends Entity> implements OnInit {
return changes;
}

/**
* Returns the data that needs to be passed as the other parameter to the
* EntityService's create method when this control is used to create an Entity object.
*
* Override this in child classes to provide any other details needed to be passed
* to the entity constructor when an object is created. This is then passed along
* in the `create` call as the `other` value to the EntityService's create method.
*/
protected otherOnCreate(): any {
return undefined;
}

/**
* Copy changes in data related to the FromControls into
* the selected value. This is called in preperation to send
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ export class UnitTutorialsListComponent extends EntityFormComponent<Tutorial> {
this.unit.deleteStream(this.stream);
}

/**
* Ensure that the unit is passed to the Tutorial entity when create it called.
*/
protected otherOnCreate() : any {
return this.unit;
}

// Sorting function to sort data when sort
// event is triggered
sortTableData(sort: Sort) {
Expand Down

0 comments on commit 072afde

Please sign in to comment.