Broken
This commit is contained in:
parent
a1baa334ed
commit
cb51e66d11
|
@ -1,7 +1,7 @@
|
||||||
<ng-container *ngIf="recipe && materials && (!editionMode || mix)">
|
<ng-container *ngIf="controls && recipe && materials && (!editionMode || mix)">
|
||||||
<cre-action-bar>
|
<cre-action-bar>
|
||||||
<cre-action-group>
|
<cre-action-group>
|
||||||
<cre-primary-button routerLink="/color/edit/{{recipeId}}">Retour</cre-primary-button>
|
<cre-primary-button routerLink="/color/edit/{{recipe.id}}">Retour</cre-primary-button>
|
||||||
</cre-action-group>
|
</cre-action-group>
|
||||||
<cre-action-group>
|
<cre-action-group>
|
||||||
<cre-warn-button *ngIf="editionMode" (click)="deleteConfirmBox.show()">Supprimer</cre-warn-button>
|
<cre-warn-button *ngIf="editionMode" (click)="deleteConfirmBox.show()">Supprimer</cre-warn-button>
|
||||||
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
<cre-form-content>
|
<cre-form-content>
|
||||||
<cre-input [control]="controls.name" label="name" icon="form-textbox"></cre-input>
|
<cre-input [control]="controls.name" label="name" icon="form-textbox"></cre-input>
|
||||||
<cre-select [control]="controls.materialType" label="Type de produit"
|
<!-- <cre-select [control]="controls.materialType" label="Type de produit"-->
|
||||||
[entries]="materialTypeEntries$"></cre-select>
|
<!-- [entries]="materialTypeEntries$"></cre-select>-->
|
||||||
</cre-form-content>
|
</cre-form-content>
|
||||||
</cre-form>
|
</cre-form>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
@ -71,7 +71,7 @@
|
||||||
<!-- </mat-form-field>-->
|
<!-- </mat-form-field>-->
|
||||||
|
|
||||||
|
|
||||||
<cre-select [entries]="getAvailableMaterials(mixMaterial)"></cre-select>
|
<!-- <cre-select [entries]="getAvailableMaterials(mixMaterial)"></cre-select>-->
|
||||||
</td>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import {ActivatedRoute, Router} from '@angular/router'
|
||||||
import {ConfirmBoxComponent} from '../../../shared/components/confirm-box/confirm-box.component'
|
import {ConfirmBoxComponent} from '../../../shared/components/confirm-box/confirm-box.component'
|
||||||
import {AccountService} from '../../../accounts/services/account.service'
|
import {AccountService} from '../../../accounts/services/account.service'
|
||||||
import {ErrorService} from '../../../shared/service/error.service'
|
import {ErrorService} from '../../../shared/service/error.service'
|
||||||
import {map, tap} from 'rxjs/operators';
|
import {map} from 'rxjs/operators';
|
||||||
import {CreInputEntry} from '../../../shared/components/inputs/inputs';
|
import {CreInputEntry} from '../../../shared/components/inputs/inputs';
|
||||||
import {CreForm, ICreForm} from '../../../shared/components/forms/forms';
|
import {CreForm, ICreForm} from '../../../shared/components/forms/forms';
|
||||||
|
|
||||||
|
@ -30,19 +30,17 @@ import {CreForm, ICreForm} from '../../../shared/components/forms/forms';
|
||||||
styleUrls: ['./mix-editor.component.sass']
|
styleUrls: ['./mix-editor.component.sass']
|
||||||
})
|
})
|
||||||
export class MixEditorComponent extends ErrorHandlingComponent {
|
export class MixEditorComponent extends ErrorHandlingComponent {
|
||||||
@ViewChild('matTable') mixTable: MatTable<MixMaterial>
|
@ViewChild(MatTable, {static: true}) mixTable: MatTable<MixMaterial>
|
||||||
@ViewChild('deleteConfirmBox') deleteConfirmBox: ConfirmBoxComponent
|
@ViewChild('deleteConfirmBox') deleteConfirmBox: ConfirmBoxComponent
|
||||||
@ViewChild(CreForm) creForm: ICreForm
|
@ViewChild(CreForm) creForm: ICreForm
|
||||||
|
|
||||||
@Input() mixId: number | null
|
@Input() mixId: number | null
|
||||||
@Input() recipeId: number | null
|
@Input() recipe: Recipe
|
||||||
@Input() materials: Material[]
|
@Input() mix: Mix | null
|
||||||
|
@Input() materials: Material[] = []
|
||||||
|
|
||||||
@Output() save = new EventEmitter<any>()
|
@Output() save = new EventEmitter<any>()
|
||||||
|
|
||||||
recipe: Recipe
|
|
||||||
mix: Mix | null
|
|
||||||
|
|
||||||
editionMode = false
|
editionMode = false
|
||||||
units = UNIT_MILLILITER
|
units = UNIT_MILLILITER
|
||||||
hoveredMixMaterial: MixMaterial | null
|
hoveredMixMaterial: MixMaterial | null
|
||||||
|
@ -92,33 +90,14 @@ export class MixEditorComponent extends ErrorHandlingComponent {
|
||||||
this.editionMode = true
|
this.editionMode = true
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fetchRecipe()
|
if (this.editionMode) {
|
||||||
this.fetchMaterials()
|
this.mix = this.recipe.mixes.find(mix => mix.id === this.mixId)
|
||||||
}
|
this.mixMaterials = mixMaterialsAsMixMaterialsDto(this.mix)
|
||||||
|
} else {
|
||||||
|
this.addBlankMixMaterial()
|
||||||
|
}
|
||||||
|
|
||||||
private fetchRecipe() {
|
this.createControls()
|
||||||
this.subscribe(
|
|
||||||
this.recipeService.getById(this.recipeId),
|
|
||||||
recipe => {
|
|
||||||
this.recipe = recipe
|
|
||||||
|
|
||||||
if (this.editionMode) {
|
|
||||||
this.mix = this.recipe.mixes.find(mix => mix.id === this.mixId)
|
|
||||||
this.mixMaterials = mixMaterialsAsMixMaterialsDto(this.mix)
|
|
||||||
} else {
|
|
||||||
this.addBlankMixMaterial()
|
|
||||||
}
|
|
||||||
|
|
||||||
this.createControls()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fetchMaterials() {
|
|
||||||
this.subscribe(
|
|
||||||
this.materialService.all,
|
|
||||||
materials => this.materials = materials
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private createControls() {
|
private createControls() {
|
||||||
|
@ -167,7 +146,7 @@ export class MixEditorComponent extends ErrorHandlingComponent {
|
||||||
submit() {
|
submit() {
|
||||||
this.save.emit({
|
this.save.emit({
|
||||||
name: this.controls.name.value,
|
name: this.controls.name.value,
|
||||||
recipeId: this.recipeId,
|
recipeId: this.recipe.id,
|
||||||
materialTypeId: this.controls.materialType.value,
|
materialTypeId: this.controls.materialType.value,
|
||||||
mixMaterials: this.mixMaterials,
|
mixMaterials: this.mixMaterials,
|
||||||
units: this.units
|
units: this.units
|
||||||
|
@ -176,7 +155,7 @@ export class MixEditorComponent extends ErrorHandlingComponent {
|
||||||
|
|
||||||
delete() {
|
delete() {
|
||||||
this.deleting = true
|
this.deleting = true
|
||||||
this.subscribeAndNavigate(this.mixService.delete(this.mixId), `/color/edit/${this.recipeId}`)
|
this.subscribeAndNavigate(this.mixService.delete(this.mixId), `/color/edit/${this.recipe.id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
getAvailableMaterials(mixMaterial: MixMaterialDto): CreInputEntry[] {
|
getAvailableMaterials(mixMaterial: MixMaterialDto): CreInputEntry[] {
|
||||||
|
@ -187,8 +166,10 @@ export class MixEditorComponent extends ErrorHandlingComponent {
|
||||||
// map(materials => this.sortedMaterials(materials)),
|
// map(materials => this.sortedMaterials(materials)),
|
||||||
// map(materials => materials.map(material => new CreInputEntry(material.id, material.name)))
|
// map(materials => materials.map(material => new CreInputEntry(material.id, material.name)))
|
||||||
// )
|
// )
|
||||||
console.log(this.materials.map(material => new CreInputEntry(material.id, material.name)))
|
return this.materials
|
||||||
return []
|
.filter(m => mixMaterial.materialId === m.id || this.mixMaterials.filter(mm => mm.materialId === m.id).length === 0)
|
||||||
|
.sort(materialComparator)
|
||||||
|
.map(material => new CreInputEntry(material.id, material.name))
|
||||||
// return this.materials.map(material => new CreInputEntry(material.id, material.name))
|
// return this.materials.map(material => new CreInputEntry(material.id, material.name))
|
||||||
// return this.materials
|
// return this.materials
|
||||||
// .filter(m => mixMaterial.materialId === m.id || this.mixMaterials.filter(mm => mm.materialId === m.id).length === 0)
|
// .filter(m => mixMaterial.materialId === m.id || this.mixMaterials.filter(mm => mm.materialId === m.id).length === 0)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<cre-mix-editor
|
<cre-mix-editor
|
||||||
[recipeId]="recipeId"
|
*ngIf="recipe && materials"
|
||||||
|
[recipe]="recipe"
|
||||||
[materials]="materials"
|
[materials]="materials"
|
||||||
(save)="submit($event)">
|
(save)="submit($event)">
|
||||||
</cre-mix-editor>
|
</cre-mix-editor>
|
||||||
|
|
|
@ -5,6 +5,8 @@ import {ActivatedRoute, Router} from '@angular/router'
|
||||||
import {ErrorHandlingComponent} from '../../../../shared/components/subscribing.component'
|
import {ErrorHandlingComponent} from '../../../../shared/components/subscribing.component'
|
||||||
import {MixService} from '../../../services/mix.service'
|
import {MixService} from '../../../services/mix.service'
|
||||||
import {ErrorService} from '../../../../shared/service/error.service'
|
import {ErrorService} from '../../../../shared/service/error.service'
|
||||||
|
import {Recipe} from "../../../../shared/model/recipe.model";
|
||||||
|
import {RecipeService} from "../../../services/recipe.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'cre-mix-add',
|
selector: 'cre-mix-add',
|
||||||
|
@ -12,10 +14,13 @@ import {ErrorService} from '../../../../shared/service/error.service'
|
||||||
styleUrls: ['./mix-add.component.sass']
|
styleUrls: ['./mix-add.component.sass']
|
||||||
})
|
})
|
||||||
export class MixAddComponent extends ErrorHandlingComponent {
|
export class MixAddComponent extends ErrorHandlingComponent {
|
||||||
recipeId: number | null
|
materials: Material[] | null = [new Material(0, "Example", 1000, null, null)]
|
||||||
materials: Material[] | null
|
recipe: Recipe | null
|
||||||
|
|
||||||
|
private recipeId: number | null
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private recipeService: RecipeService,
|
||||||
private materialService: MaterialService,
|
private materialService: MaterialService,
|
||||||
private mixService: MixService,
|
private mixService: MixService,
|
||||||
errorService: ErrorService,
|
errorService: ErrorService,
|
||||||
|
@ -29,10 +34,21 @@ export class MixAddComponent extends ErrorHandlingComponent {
|
||||||
super.ngOnInit()
|
super.ngOnInit()
|
||||||
|
|
||||||
this.recipeId = this.urlUtils.parseIntUrlParam('recipeId')
|
this.recipeId = this.urlUtils.parseIntUrlParam('recipeId')
|
||||||
|
this.fetchRecipe()
|
||||||
|
// this.fetchMaterials()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fetchRecipe() {
|
||||||
|
this.subscribe(
|
||||||
|
this.recipeService.getById(this.recipeId),
|
||||||
|
recipe => this.recipe = recipe
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fetchMaterials() {
|
||||||
this.subscribe(
|
this.subscribe(
|
||||||
this.materialService.getAllForMixCreation(this.recipeId),
|
this.materialService.getAllForMixCreation(this.recipeId),
|
||||||
m => this.materials = m
|
materials => this.materials = materials
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<cre-mix-editor
|
<cre-mix-editor
|
||||||
[mixId]="mixId"
|
[mixId]="mixId"
|
||||||
[recipeId]="recipeId"
|
[recipe]="recipe"
|
||||||
[materials]="materials"
|
[materials]="materials"
|
||||||
(save)="submit($event)">
|
(save)="submit($event)">
|
||||||
</cre-mix-editor>
|
</cre-mix-editor>
|
||||||
|
|
|
@ -4,9 +4,10 @@ import {ErrorHandlingComponent} from '../../../../shared/components/subscribing.
|
||||||
import {Material} from '../../../../shared/model/material.model'
|
import {Material} from '../../../../shared/model/material.model'
|
||||||
import {MaterialService} from '../../../../material/service/material.service'
|
import {MaterialService} from '../../../../material/service/material.service'
|
||||||
import {MixService} from '../../../services/mix.service'
|
import {MixService} from '../../../services/mix.service'
|
||||||
import {ErrorHandlerComponent, ErrorService} from '../../../../shared/service/error.service'
|
import {ErrorService} from '../../../../shared/service/error.service'
|
||||||
import {MixMaterialDto} from '../../../../shared/model/recipe.model'
|
import {MixMaterialDto, Recipe} from '../../../../shared/model/recipe.model'
|
||||||
import {AlertService} from '../../../../shared/service/alert.service'
|
import {AlertService} from '../../../../shared/service/alert.service'
|
||||||
|
import {RecipeService} from "../../../services/recipe.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'cre-mix-edit',
|
selector: 'cre-mix-edit',
|
||||||
|
@ -15,10 +16,13 @@ import {AlertService} from '../../../../shared/service/alert.service'
|
||||||
})
|
})
|
||||||
export class MixEditComponent extends ErrorHandlingComponent {
|
export class MixEditComponent extends ErrorHandlingComponent {
|
||||||
mixId: number | null
|
mixId: number | null
|
||||||
recipeId: number | null
|
recipe: Recipe | null
|
||||||
materials: Material[] | null
|
materials: Material[] | null
|
||||||
|
|
||||||
|
private recipeId: number | null
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private recipeService: RecipeService,
|
||||||
private materialService: MaterialService,
|
private materialService: MaterialService,
|
||||||
private mixService: MixService,
|
private mixService: MixService,
|
||||||
private alertService: AlertService,
|
private alertService: AlertService,
|
||||||
|
@ -35,9 +39,21 @@ export class MixEditComponent extends ErrorHandlingComponent {
|
||||||
this.mixId = this.urlUtils.parseIntUrlParam('id')
|
this.mixId = this.urlUtils.parseIntUrlParam('id')
|
||||||
this.recipeId = this.urlUtils.parseIntUrlParam('recipeId')
|
this.recipeId = this.urlUtils.parseIntUrlParam('recipeId')
|
||||||
|
|
||||||
|
this.fetchRecipe()
|
||||||
|
this.fetchMaterials()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fetchRecipe() {
|
||||||
|
this.subscribe(
|
||||||
|
this.recipeService.getById(this.recipeId),
|
||||||
|
recipe => this.recipe = recipe
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fetchMaterials() {
|
||||||
this.subscribe(
|
this.subscribe(
|
||||||
this.materialService.getAllForMixUpdate(this.mixId),
|
this.materialService.getAllForMixUpdate(this.mixId),
|
||||||
m => this.materials = m
|
materials => this.materials = materials
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -399,8 +399,12 @@ export class CreSliderInputComponent {
|
||||||
selector: 'cre-select',
|
selector: 'cre-select',
|
||||||
templateUrl: 'select.html'
|
templateUrl: 'select.html'
|
||||||
})
|
})
|
||||||
export class CreSelectComponent extends _CreInputBase {
|
export class CreSelectComponent extends _CreInputBase implements AfterViewInit {
|
||||||
@Input() entries: Observable<CreInputEntry[]> | CreInputEntry[]
|
@Input() entries: CreInputEntry[] | Observable<CreInputEntry[]>
|
||||||
|
|
||||||
|
ngAfterViewInit(): void {
|
||||||
|
console.log(this.entries)
|
||||||
|
}
|
||||||
|
|
||||||
get entriesAreObservable(): boolean {
|
get entriesAreObservable(): boolean {
|
||||||
return isObservable(this.entries)
|
return isObservable(this.entries)
|
||||||
|
|
Loading…
Reference in New Issue