diff --git a/src/app/modules/recipes/components/images-editor/images-editor.component.html b/src/app/modules/recipes/components/images-editor/images-editor.component.html index 97e9424..abd0574 100644 --- a/src/app/modules/recipes/components/images-editor/images-editor.component.html +++ b/src/app/modules/recipes/components/images-editor/images-editor.component.html @@ -4,7 +4,7 @@
-

Aucune image n'est associée à cette couleur

+

Aucune image n'est associée à cette couleur

diff --git a/src/app/modules/recipes/components/step-list/step-list.component.html b/src/app/modules/recipes/components/step-list/step-list.component.html index c53850d..daa579e 100644 --- a/src/app/modules/recipes/components/step-list/step-list.component.html +++ b/src/app/modules/recipes/components/step-list/step-list.component.html @@ -3,7 +3,7 @@ Étapes - + {{step.position}}.{{step.message}} diff --git a/src/app/modules/recipes/pages/explore/explore.component.html b/src/app/modules/recipes/pages/explore/explore.component.html index 93b3b3e..8d8f714 100644 --- a/src/app/modules/recipes/pages/explore/explore.component.html +++ b/src/app/modules/recipes/pages/explore/explore.component.html @@ -1,60 +1,26 @@
-
-
-
- - - -
- -
+ + + + Retour - - Groupe - - - {{group.name}} - - - -
-
+ + + + + + + + Version Excel + + Enregistrer + + + -
- - - Note - - -

{{selectedGroupNote}}

-
- -
+
() selectedGroupId: number | null @@ -33,6 +40,12 @@ export class ExploreComponent extends ErrorHandlingComponent { deductedMixId: number | null + groupControl: FormControl + noteControl: FormControl + groupEntries$ = this.groupService.all.pipe(map(groups => { + return groups.map(group => new CreInputEntry(group.id, group.name)) + })) + errorHandlers: ErrorHandler[] = [{ filter: error => error.type === 'notfound-recipe-id', consumer: error => this.urlUtils.navigateTo('/color/list') @@ -42,6 +55,9 @@ export class ExploreComponent extends ErrorHandlingComponent { messageProducer: () => 'Certains produit ne sont pas en quantité suffisante dans l\'inventaire' }] + private _recipe: Recipe | null + private _notePlaceholder = !this.canEditRecipesPublicData ? 'N/A' : '' + constructor( private recipeService: RecipeService, private inventoryService: InventoryService, @@ -62,18 +78,30 @@ export class ExploreComponent extends ErrorHandlingComponent { this.selectedGroupId = this.loggedInUserGroupId - const id = parseInt(this.activatedRoute.snapshot.paramMap.get('id')) + this.fetchRecipe() + + this.groupControl = new FormControl(this.selectedGroupId) + this.subscribe( + this.groupControl.valueChanges, + groupId => { + this.selectedGroupId = groupId + this.noteControl.setValue(this.selectedGroupNote, {emitEvent: false}) + } + ) + + this.noteControl = new FormControl({value: this._notePlaceholder, disabled: !this.canEditRecipesPublicData}) + this.subscribe( + this.noteControl.valueChanges, + _ => this.hasModifications = true + ) + } + + fetchRecipe() { + const recipeId = parseInt(this.activatedRoute.snapshot.paramMap.get('id')) this.subscribeEntityById( this.recipeService, - id, - r => { - this.recipe = r - this.appState.title = r.name - - if (recipeMixCount(this.recipe) <= 0 || recipeStepCount(this.recipe) <= 0) { - this.alertService.pushWarning('Cette recette n\'est pas complète') - } - } + recipeId, + recipe => this.recipe = recipe ) } @@ -128,11 +156,24 @@ export class ExploreComponent extends ErrorHandlingComponent { subscribeDeductMix(observable: Observable) { this.subscribe( observable, - () => this.alertService.pushSuccess('Les quantités quantités ont été déduites de l\'inventaire'), + () => this.alertService.pushSuccess('Les quantités ont été déduites de l\'inventaire'), true ) } + get recipe(): Recipe { + return this._recipe + } + + set recipe(recipe: Recipe) { + this._recipe = recipe + this.appState.title = recipe.name + + if (recipeMixCount(recipe) <= 0 || recipeStepCount(recipe) <= 0) { + this.alertService.pushWarning('Cette recette n\'est pas complète') + } + } + get loggedInUserGroupId(): number { return this.appState.authenticatedUser.group?.id } @@ -141,11 +182,7 @@ export class ExploreComponent extends ErrorHandlingComponent { if (!this.groupsNote.has(this.selectedGroupId)) { this.groupsNote.set(this.selectedGroupId, recipeNoteForGroupId(this.recipe, this.selectedGroupId)) } - return this.groupsNote.get(this.selectedGroupId) - } - - set selectedGroupNote(value: string) { - this.groupsNote.set(this.selectedGroupId, value) + return this.groupsNote.get(this.selectedGroupId) ?? this._notePlaceholder } get canEditRecipesPublicData(): boolean { @@ -160,7 +197,9 @@ export class ExploreComponent extends ErrorHandlingComponent { }) this.groupsNote.forEach((content, groupId) => { - updatedNotes.set(groupId, content) + if (content) { + updatedNotes.set(groupId, content) + } }) return updatedNotes diff --git a/src/app/modules/recipes/recipes.ts b/src/app/modules/recipes/recipes.ts index 19c0c3d..1be6565 100644 --- a/src/app/modules/recipes/recipes.ts +++ b/src/app/modules/recipes/recipes.ts @@ -1,6 +1,6 @@ import {ErrorHandlingComponent, SubscribingComponent} from '../shared/components/subscribing.component'; import {Observable, Subject} from 'rxjs'; -import {ComboBoxEntry} from '../shared/components/inputs/inputs'; +import {CreInputEntry} from '../shared/components/inputs/inputs'; import {map, tap} from 'rxjs/operators'; import {RecipeService} from './services/recipe.service'; import {CompanyService} from '../company/service/company.service'; @@ -29,7 +29,7 @@ export class RecipeForm extends SubscribingComponent { @Output() submitForm = new EventEmitter(); controls: any - companyEntries$: Observable + companyEntries$: Observable hasCompanies = true constructor( @@ -62,7 +62,7 @@ export class RecipeForm extends SubscribingComponent { private fetchCompanies() { this.companyEntries$ = this.companyService.all.pipe( tap(companies => this.hasCompanies = companies.length > 0), - map(companies => companies.map(c => new ComboBoxEntry(c.id, c.name))), + map(companies => companies.map(c => new CreInputEntry(c.id, c.name))), ) } diff --git a/src/app/modules/recipes/services/recipe.service.ts b/src/app/modules/recipes/services/recipe.service.ts index 4a99612..4554569 100644 --- a/src/app/modules/recipes/services/recipe.service.ts +++ b/src/app/modules/recipes/services/recipe.service.ts @@ -3,7 +3,6 @@ import {ApiService} from '../../shared/service/api.service' import {Observable} from 'rxjs' import {Recipe, RecipeStep} from '../../shared/model/recipe.model' import {map} from 'rxjs/operators' -import {Company} from '../../shared/model/company.model'; @Injectable({ providedIn: 'root' diff --git a/src/app/modules/shared/components/action-bar/action-group.html b/src/app/modules/shared/components/action-bar/action-group.html index dfdbcc7..01b5f5d 100644 --- a/src/app/modules/shared/components/action-bar/action-group.html +++ b/src/app/modules/shared/components/action-bar/action-group.html @@ -1,3 +1,6 @@ -
- +
+
+ +
+
diff --git a/src/app/modules/shared/components/inputs/inputs.module.ts b/src/app/modules/shared/components/inputs/inputs.module.ts index aeddff9..e45c685 100644 --- a/src/app/modules/shared/components/inputs/inputs.module.ts +++ b/src/app/modules/shared/components/inputs/inputs.module.ts @@ -4,7 +4,7 @@ import { CreChipComboBoxComponent, CreChipInputComponent, CreComboBoxComponent, CreFileInputComponent, - CreInputComponent, CrePeriodInputComponent, CreSliderInputComponent + CreInputComponent, CrePeriodInputComponent, CreSelectComponent, CreSliderInputComponent, CreTextareaComponent } from './inputs' import {MatInputModule} from '@angular/material/input' import {MatIconModule} from '@angular/material/icon' @@ -29,7 +29,9 @@ import {MatSliderModule} from '@angular/material/slider'; CreFileInputComponent, CreCheckboxInputComponent, CrePeriodInputComponent, - CreSliderInputComponent + CreSliderInputComponent, + CreTextareaComponent, + CreSelectComponent ], imports: [ MatInputModule, @@ -55,7 +57,9 @@ import {MatSliderModule} from '@angular/material/slider'; CreFileInputComponent, CreCheckboxInputComponent, CrePeriodInputComponent, - CreSliderInputComponent + CreSliderInputComponent, + CreTextareaComponent, + CreSelectComponent ] }) export class CreInputsModule { diff --git a/src/app/modules/shared/components/inputs/inputs.ts b/src/app/modules/shared/components/inputs/inputs.ts index 58c494a..fb038e9 100644 --- a/src/app/modules/shared/components/inputs/inputs.ts +++ b/src/app/modules/shared/components/inputs/inputs.ts @@ -63,6 +63,19 @@ export class CreInputComponent extends _CreInputBase implements AfterViewInit { } } +@Component({ + selector: 'cre-textarea', + templateUrl: 'textarea.html', + encapsulation: ViewEncapsulation.None +}) +export class CreTextareaComponent { + @Input() label: string + @Input() control: FormControl + @Input() cols = 40 + @Input() rows = 3 + @Input() placeholder: string | null +} + @Component({ selector: 'cre-autocomplete-input', templateUrl: 'autocomplete.html', @@ -140,7 +153,7 @@ export class CreComboBoxComponent implements OnInit { @Input() label: string @Input() icon: string @Input() required = true - @Input() entries: Observable + @Input() entries: Observable @ContentChild(TemplateRef) errors: TemplateRef @@ -148,7 +161,7 @@ export class CreComboBoxComponent implements OnInit { validValue = false private _destroy$ = new Subject(); - private _entries: ComboBoxEntry[] + private _entries: CreInputEntry[] ngOnInit() { this.entries.pipe(takeUntil(this._destroy$)) @@ -160,7 +173,7 @@ export class CreComboBoxComponent implements OnInit { this.internalControl.setValue(this.findEntryByKey(this.control.value)?.value) } - if (this.internalControl.disabled) { + if (this.control.disabled) { this.internalControl.disable() } } @@ -168,7 +181,7 @@ export class CreComboBoxComponent implements OnInit { this.internalControl = new FormControl({ value: null, - disabled: true + disabled: false }, Validators.compose([this.control.validator, this.valueValidator()])) this.internalControl.valueChanges.pipe(takeUntil(this._destroy$)) .subscribe({ @@ -182,7 +195,7 @@ export class CreComboBoxComponent implements OnInit { }) } - private findEntryByKey(key: any): ComboBoxEntry | null { + private findEntryByKey(key: any): CreInputEntry | null { const found = this._entries.filter(e => e.key === key) if (found.length <= 0) { return null @@ -190,7 +203,7 @@ export class CreComboBoxComponent implements OnInit { return found[0] } - private findEntryByValue(value: any): ComboBoxEntry | null { + private findEntryByValue(value: any): CreInputEntry | null { const found = this._entries.filter(e => e.value === value) if (found.length <= 0) { return null @@ -216,15 +229,15 @@ export class CreComboBoxComponent implements OnInit { encapsulation: ViewEncapsulation.None }) export class CreChipComboBoxComponent extends CreChipInputComponent implements OnDestroy { - @Input() entries: Observable + @Input() entries: Observable @ContentChild(TemplateRef) errors: TemplateRef @ViewChild('chipInput') chipInput: ElementRef @ViewChild('auto') matAutocomplete: MatAutocomplete - filteredEntries: Observable + filteredEntries: Observable - private _entries: ComboBoxEntry[] + private _entries: CreInputEntry[] private _destroy$ = new Subject() ngOnInit() { @@ -255,7 +268,7 @@ export class CreChipComboBoxComponent extends CreChipInputComponent implements O return this.selectedValues.length <= 0 } - private _filter(query: string): ComboBoxEntry[] { + private _filter(query: string): CreInputEntry[] { const filterValue = query.toString().toLowerCase() return this._entries.filter(e => e.value.toString().toLowerCase().indexOf(filterValue) === 0) } @@ -382,7 +395,15 @@ export class CreSliderInputComponent { } } -export class ComboBoxEntry { +@Component({ + selector: 'cre-select', + templateUrl: 'select.html' +}) +export class CreSelectComponent extends _CreInputBase { + @Input() entries: Observable +} + +export class CreInputEntry { constructor( public key: any, public value: any, diff --git a/src/app/modules/shared/components/inputs/select.html b/src/app/modules/shared/components/inputs/select.html new file mode 100644 index 0000000..6fd806b --- /dev/null +++ b/src/app/modules/shared/components/inputs/select.html @@ -0,0 +1,8 @@ + + {{label}} + + + {{entry.display || entry.value}} + + + diff --git a/src/app/modules/shared/components/inputs/textarea.html b/src/app/modules/shared/components/inputs/textarea.html new file mode 100644 index 0000000..18653c0 --- /dev/null +++ b/src/app/modules/shared/components/inputs/textarea.html @@ -0,0 +1,9 @@ + + {{label}} + + diff --git a/src/app/modules/touch-up-kit/components/form.ts b/src/app/modules/touch-up-kit/components/form.ts index b9b5e51..09c7248 100644 --- a/src/app/modules/touch-up-kit/components/form.ts +++ b/src/app/modules/touch-up-kit/components/form.ts @@ -1,5 +1,5 @@ import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core' -import {chipListRequired, ComboBoxEntry, CreChipComboBoxComponent} from '../../shared/components/inputs/inputs' +import {chipListRequired, CreInputEntry, CreChipComboBoxComponent} from '../../shared/components/inputs/inputs' import {CreFormComponent} from '../../shared/components/forms/forms' import {TouchUpKitProductEditor} from './product-editor' import {FormControl, Validators} from '@angular/forms' @@ -25,7 +25,7 @@ export class TouchUpKitForm extends SubscribingComponent { controls: any finish$ = this.recipeService.all.pipe( - map(recipes => recipes.map(recipe => new ComboBoxEntry(recipe.id, recipe.name, `${recipe.name} - ${recipe.company.name}`))) + map(recipes => recipes.map(recipe => new CreInputEntry(recipe.id, recipe.name, `${recipe.name} - ${recipe.company.name}`))) ) companies$ = this.companyService.all.pipe( map(companies => companies.map(company => company.name))