12-user-info-jwt #6
|
@ -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}),
|
||||
|
|
Loading…
Reference in New Issue