Fix mix editor did not get the materials from the correct location in update mode

This commit is contained in:
FyloZ 2021-12-20 19:20:01 -05:00
parent 82cb974d27
commit f04a3c7ba3
Signed by: william
GPG Key ID: 835378AE9AF4AE97
1 changed files with 17 additions and 5 deletions

View File

@ -27,7 +27,7 @@ abstract class _BaseMixPage extends SubscribingComponent {
protected mixService: MixService,
private recipeService: RecipeService,
private materialTypeService: MaterialTypeService,
private materialService: MaterialService,
protected materialService: MaterialService,
errorService: ErrorService,
router: Router,
activatedRoute: ActivatedRoute
@ -50,13 +50,15 @@ abstract class _BaseMixPage extends SubscribingComponent {
set recipe(recipe: Recipe) {
this._recipe = recipe
this.materials$ = this.materialService.getAllForMixCreation(recipe.id)
this.materials$ = this.fetchMaterials(recipe.id)
}
get recipe(): Recipe {
return this._recipe
}
protected abstract fetchMaterials(recipeId: number): Observable<Material[]>
abstract submit(dto: MixSaveDto)
}
@ -65,6 +67,10 @@ abstract class _BaseMixPage extends SubscribingComponent {
templateUrl: 'add.html'
})
export class MixAdd extends _BaseMixPage {
protected fetchMaterials(recipeId: number): Observable<Material[]> {
return this.materialService.getAllForMixCreation(recipeId)
}
submit(dto: MixSaveDto) {
this.subscribeAndNavigate(
this.mixService.saveDto(dto),
@ -80,21 +86,27 @@ export class MixAdd extends _BaseMixPage {
export class MixEdit extends _BaseMixPage {
mix: Mix
private mixId: number
ngOnInit() {
super.ngOnInit()
this.mixId = this.urlUtils.parseIntUrlParam('id')
this.fetchMix()
}
private fetchMix() {
const mixId = this.urlUtils.parseIntUrlParam('id')
this.subscribe(
this.mixService.getById(mixId),
this.mixService.getById(this.mixId),
mix => this.mix = mix
)
}
protected fetchMaterials(recipeId: number): Observable<Material[]> {
return this.materialService.getAllForMixUpdate(this.mixId)
}
submit(dto: MixSaveDto) {
this.subscribeAndNavigate(
this.mixService.updateDto({...dto, id: this.mix.id}),