From c35635c596b9b260ca8238d3fc49229a482897f5 Mon Sep 17 00:00:00 2001 From: William Nolin Date: Tue, 14 Sep 2021 09:28:28 -0400 Subject: [PATCH] #14 Add messages when adding recipe --- src/app/app-routing.module.ts | 2 +- .../colors/pages/add/add.component.html | 6 - .../colors/pages/add/add.component.sass | 0 .../modules/colors/pages/add/add.component.ts | 123 ------------------ .../modules/colors/services/recipe.service.ts | 89 ------------- .../company/service/company.service.ts | 6 +- src/app/modules/material/material.module.ts | 4 +- src/app/modules/recipes/add.html | 1 + src/app/modules/{colors => recipes}/bpac.js | 0 .../images-editor.component.html | 0 .../images-editor.component.sass | 0 .../images-editor/images-editor.component.ts | 0 .../mix-editor/mix-editor.component.html | 0 .../mix-editor/mix-editor.component.sass | 0 .../mix-editor/mix-editor.component.ts | 0 .../mix-table/mix-table.component.html | 0 .../mix-table/mix-table.component.sass | 0 .../mix-table/mix-table.component.ts | 0 .../mixes-card/mixes-card.component.html | 0 .../mixes-card/mixes-card.component.sass | 0 .../mixes-card/mixes-card.component.ts | 0 .../recipe-info/recipe-info.component.html | 0 .../recipe-info/recipe-info.component.sass | 0 .../recipe-info/recipe-info.component.ts | 0 .../step-list/step-list.component.html | 0 .../step-list/step-list.component.sass | 0 .../step-list/step-list.component.ts | 0 .../step-table/step-table.component.html | 0 .../step-table/step-table.component.sass | 0 .../step-table/step-table.component.ts | 0 .../unit-selector.component.html | 0 .../unit-selector.component.sass | 0 .../unit-selector/unit-selector.component.ts | 0 src/app/modules/recipes/form.html | 24 ++++ .../pages/edit/edit.component.html | 0 .../pages/edit/edit.component.sass | 0 .../pages/edit/edit.component.ts | 0 .../pages/explore/explore.component.html | 0 .../pages/explore/explore.component.sass | 0 .../pages/explore/explore.component.ts | 0 .../pages/list/list.component.html | 0 .../pages/list/list.component.sass | 0 .../pages/list/list.component.ts | 2 +- .../pages/mix/mix-add/mix-add.component.html | 0 .../pages/mix/mix-add/mix-add.component.sass | 0 .../pages/mix/mix-add/mix-add.component.ts | 0 .../mix/mix-edit/mix-edit.component.html | 0 .../mix/mix-edit/mix-edit.component.sass | 0 .../pages/mix/mix-edit/mix-edit.component.ts | 0 .../{colors => recipes}/ptouchPrint.js | 0 .../recipes-routing.module.ts} | 6 +- .../recipes.module.ts} | 32 ++++- src/app/modules/recipes/recipes.ts | 119 +++++++++++++++++ .../services/mix.service.ts | 0 .../services/recipe-image.service.ts | 0 .../recipes/services/recipe.service.ts | 89 +++++++++++++ .../shared/components/alerts/alerts.ts | 5 +- .../shared/components/forms/forms.sass | 4 + .../modules/shared/components/forms/forms.ts | 2 +- .../components/inputs/autocomplete.html | 2 +- .../components/inputs/chips-combo-box.html | 2 +- .../shared/components/inputs/combo-box.html | 13 +- .../shared/components/inputs/input.html | 2 + .../shared/components/inputs/inputs.module.ts | 10 +- .../shared/components/inputs/inputs.ts | 107 +++++++++++++-- .../shared/components/inputs/slider.html | 13 ++ src/app/modules/shared/model/recipe.model.ts | 30 ++--- .../modules/touch-up-kit/components/finish.ts | 2 +- .../modules/touch-up-kit/components/form.html | 4 +- .../modules/touch-up-kit/components/form.ts | 2 +- .../modules/touch-up-kit/pages/touchupkit.ts | 2 +- 71 files changed, 419 insertions(+), 284 deletions(-) delete mode 100644 src/app/modules/colors/pages/add/add.component.html delete mode 100644 src/app/modules/colors/pages/add/add.component.sass delete mode 100644 src/app/modules/colors/pages/add/add.component.ts delete mode 100644 src/app/modules/colors/services/recipe.service.ts create mode 100644 src/app/modules/recipes/add.html rename src/app/modules/{colors => recipes}/bpac.js (100%) rename src/app/modules/{colors => recipes}/components/images-editor/images-editor.component.html (100%) rename src/app/modules/{colors => recipes}/components/images-editor/images-editor.component.sass (100%) rename src/app/modules/{colors => recipes}/components/images-editor/images-editor.component.ts (100%) rename src/app/modules/{colors => recipes}/components/mix-editor/mix-editor.component.html (100%) rename src/app/modules/{colors => recipes}/components/mix-editor/mix-editor.component.sass (100%) rename src/app/modules/{colors => recipes}/components/mix-editor/mix-editor.component.ts (100%) rename src/app/modules/{colors => recipes}/components/mix-table/mix-table.component.html (100%) rename src/app/modules/{colors => recipes}/components/mix-table/mix-table.component.sass (100%) rename src/app/modules/{colors => recipes}/components/mix-table/mix-table.component.ts (100%) rename src/app/modules/{colors => recipes}/components/mixes-card/mixes-card.component.html (100%) rename src/app/modules/{colors => recipes}/components/mixes-card/mixes-card.component.sass (100%) rename src/app/modules/{colors => recipes}/components/mixes-card/mixes-card.component.ts (100%) rename src/app/modules/{colors => recipes}/components/recipe-info/recipe-info.component.html (100%) rename src/app/modules/{colors => recipes}/components/recipe-info/recipe-info.component.sass (100%) rename src/app/modules/{colors => recipes}/components/recipe-info/recipe-info.component.ts (100%) rename src/app/modules/{colors => recipes}/components/step-list/step-list.component.html (100%) rename src/app/modules/{colors => recipes}/components/step-list/step-list.component.sass (100%) rename src/app/modules/{colors => recipes}/components/step-list/step-list.component.ts (100%) rename src/app/modules/{colors => recipes}/components/step-table/step-table.component.html (100%) rename src/app/modules/{colors => recipes}/components/step-table/step-table.component.sass (100%) rename src/app/modules/{colors => recipes}/components/step-table/step-table.component.ts (100%) rename src/app/modules/{colors => recipes}/components/unit-selector/unit-selector.component.html (100%) rename src/app/modules/{colors => recipes}/components/unit-selector/unit-selector.component.sass (100%) rename src/app/modules/{colors => recipes}/components/unit-selector/unit-selector.component.ts (100%) create mode 100644 src/app/modules/recipes/form.html rename src/app/modules/{colors => recipes}/pages/edit/edit.component.html (100%) rename src/app/modules/{colors => recipes}/pages/edit/edit.component.sass (100%) rename src/app/modules/{colors => recipes}/pages/edit/edit.component.ts (100%) rename src/app/modules/{colors => recipes}/pages/explore/explore.component.html (100%) rename src/app/modules/{colors => recipes}/pages/explore/explore.component.sass (100%) rename src/app/modules/{colors => recipes}/pages/explore/explore.component.ts (100%) rename src/app/modules/{colors => recipes}/pages/list/list.component.html (100%) rename src/app/modules/{colors => recipes}/pages/list/list.component.sass (100%) rename src/app/modules/{colors => recipes}/pages/list/list.component.ts (99%) rename src/app/modules/{colors => recipes}/pages/mix/mix-add/mix-add.component.html (100%) rename src/app/modules/{colors => recipes}/pages/mix/mix-add/mix-add.component.sass (100%) rename src/app/modules/{colors => recipes}/pages/mix/mix-add/mix-add.component.ts (100%) rename src/app/modules/{colors => recipes}/pages/mix/mix-edit/mix-edit.component.html (100%) rename src/app/modules/{colors => recipes}/pages/mix/mix-edit/mix-edit.component.sass (100%) rename src/app/modules/{colors => recipes}/pages/mix/mix-edit/mix-edit.component.ts (100%) rename src/app/modules/{colors => recipes}/ptouchPrint.js (100%) rename src/app/modules/{colors/colors-routing.module.ts => recipes/recipes-routing.module.ts} (88%) rename src/app/modules/{colors/colors.module.ts => recipes/recipes.module.ts} (65%) create mode 100644 src/app/modules/recipes/recipes.ts rename src/app/modules/{colors => recipes}/services/mix.service.ts (100%) rename src/app/modules/{colors => recipes}/services/recipe-image.service.ts (100%) create mode 100644 src/app/modules/recipes/services/recipe.service.ts create mode 100644 src/app/modules/shared/components/inputs/slider.html diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index a0ef43d..3d9f34f 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -7,7 +7,7 @@ import {CreConfigEditor} from './modules/configuration/config-editor' const routes: Routes = [{ path: 'color', - loadChildren: () => import('./modules/colors/colors.module').then(m => m.ColorsModule) + loadChildren: () => import('./modules/recipes/recipes.module').then(m => m.RecipesModule) }, { path: 'account', loadChildren: () => import('./modules/accounts/accounts.module').then(m => m.AccountsModule) diff --git a/src/app/modules/colors/pages/add/add.component.html b/src/app/modules/colors/pages/add/add.component.html deleted file mode 100644 index f95fa2b..0000000 --- a/src/app/modules/colors/pages/add/add.component.html +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/src/app/modules/colors/pages/add/add.component.sass b/src/app/modules/colors/pages/add/add.component.sass deleted file mode 100644 index e69de29..0000000 diff --git a/src/app/modules/colors/pages/add/add.component.ts b/src/app/modules/colors/pages/add/add.component.ts deleted file mode 100644 index e5bcf7e..0000000 --- a/src/app/modules/colors/pages/add/add.component.ts +++ /dev/null @@ -1,123 +0,0 @@ -import {Component} from '@angular/core' -import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' -import {RecipeService} from '../../services/recipe.service' -import {FormField} from '../../../shared/components/entity-add/entity-add.component' -import {Validators} from '@angular/forms' -import {CompanyService} from '../../../company/service/company.service' -import {map} from 'rxjs/operators' -import {ActivatedRoute, Router} from '@angular/router' -import {ErrorService} from '../../../shared/service/error.service' -import {AppState} from '../../../shared/app-state' - -@Component({ - selector: 'cre-add', - templateUrl: './add.component.html', - styleUrls: ['./add.component.sass'] -}) -export class AddComponent extends ErrorHandlingComponent { - formFields: FormField[] = [ - { - name: 'name', - label: 'Nom', - icon: 'form-textbox', - type: 'text', - required: true, - errorMessages: [ - {conditionFn: errors => errors.required, message: 'Un nom est requis'} - ] - }, - { - name: 'description', - label: 'Description', - icon: 'text', - type: 'text', - required: true, - errorMessages: [ - {conditionFn: errors => errors.required, message: 'Une description est requise'} - ] - }, - { - name: 'color', - label: 'Couleur', - icon: 'palette', - type: 'color', - defaultValue: "#ffffff", - required: true, - errorMessages: [ - {conditionFn: errors => errors.required, message: 'Une couleur est requise'} - ] - }, - { - name: 'gloss', - label: 'Lustre', - type: 'slider', - min: 0, - max: 100, - defaultValue: 0, - required: true, - errorMessages: [ - {conditionFn: errors => errors.required, message: 'Le lustre de la couleur est requis'} - ] - }, - { - name: 'sample', - label: 'Échantillon', - icon: 'pound', - type: 'number', - validator: Validators.min(0), - errorMessages: [ - {conditionFn: errors => errors.required, message: 'Un numéro d\'échantillon est requis'}, - {conditionFn: errors => errors.min, message: 'Le numéro d\'échantillon doit être supérieur ou égal à 0'} - ] - }, - { - name: 'approbationDate', - label: 'Date d\'approbation', - icon: 'calendar', - type: 'date' - }, - { - name: 'remark', - label: 'Remarque', - icon: 'text', - type: 'text' - }, - { - name: 'company', - label: 'Bannière', - icon: 'domain', - type: 'select', - required: true, - errorMessages: [ - {conditionFn: errors => errors.required, message: 'Une bannière est requise'} - ], - options$: this.companyService.all.pipe(map(companies => companies.map(c => { - return {value: c.id, label: c.name} - }))) - } - ] - - errorHandlers = [{ - filter: error => error.type === `exists-recipe-company-name`, - messageProducer: error => `Une couleur avec le nom ${error.name} existe déjà pour la bannière ${error.company}` - }] - - constructor( - private recipeService: RecipeService, - private companyService: CompanyService, - private appState: AppState, - errorService: ErrorService, - router: Router, - activatedRoute: ActivatedRoute - ) { - super(errorService, activatedRoute, router) - this.appState.title = "Nouvelle couleur" - } - - submit(values) { - this.subscribe( - this.recipeService.save(values.name, values.description, values.color, values.gloss, values.sample, values.approbationDate, values.remark, values.company), - recipe => this.urlUtils.navigateTo(`/color/edit/${recipe.id}`) - ) - } -} diff --git a/src/app/modules/colors/services/recipe.service.ts b/src/app/modules/colors/services/recipe.service.ts deleted file mode 100644 index d110d1a..0000000 --- a/src/app/modules/colors/services/recipe.service.ts +++ /dev/null @@ -1,89 +0,0 @@ -import {Injectable} from '@angular/core' -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' -}) -export class RecipeService { - constructor( - private api: ApiService - ) { - } - - get all(): Observable { - return this.api.get('/recipe') - } - - getAllByName(name: string): Observable { - return this.api.get(`/recipe?name=${name}`) - } - - get allByCompany(): Observable> { - return this.all.pipe(map(recipes => { - const map = new Map() - recipes.forEach(r => { - if (!map.has(r.company.id)) { - map.set(r.company.id, []) - } - map.get(r.company.id).push(r) - }) - return map - })) - } - - getById(id: number): Observable { - return this.api.get(`/recipe/${id}`) - } - - save(name: string, description: string, color: string, gloss: number, sample: number, approbationDate: string, remark: string, companyId: number): Observable { - const body = {name, description, color, gloss, sample, remark, companyId} - if (approbationDate) { - // @ts-ignore - body.approbationDate = approbationDate - } - return this.api.post('/recipe', body) - } - - update(id: number, name: string, description: string, color: string, gloss: number, sample: number, approbationDate: string, remark: string, steps: Map) { - const body = {id, name, description, color, gloss, sample, remark, steps: []} - if (approbationDate) { - // @ts-ignore - body.approbationDate = approbationDate - } - - steps.forEach((groupSteps, groupId) => { - const mappedGroupSteps = groupSteps.map(s => { - return {message: s.message, position: s.position} - }) - body.steps.push({groupId, steps: mappedGroupSteps}) - }) - - return this.api.put('/recipe', body) - } - - updateExplorerModifications(id: number, notes: Map, mixesLocationChange: Map): Observable { - const body = { - recipeId: id, - notes: [], - mixesLocation: [] - } - - notes.forEach((content, groupId) => { - body.notes.push({groupId, content}) - }) - - mixesLocationChange.forEach((location, mixId) => { - body.mixesLocation.push({mixId, location}) - }) - - return this.api.put('/recipe/public', body) - } - - delete(id: number): Observable { - return this.api.delete(`/recipe/${id}`) - } -} diff --git a/src/app/modules/company/service/company.service.ts b/src/app/modules/company/service/company.service.ts index 238eaef..90f3a78 100644 --- a/src/app/modules/company/service/company.service.ts +++ b/src/app/modules/company/service/company.service.ts @@ -1,7 +1,7 @@ import {Injectable} from '@angular/core'; -import {ApiService} from "../../shared/service/api.service"; -import {Observable} from "rxjs"; -import {Company} from "../../shared/model/company.model"; +import {ApiService} from '../../shared/service/api.service'; +import {Observable} from 'rxjs'; +import {Company} from '../../shared/model/company.model'; @Injectable({ providedIn: 'root' diff --git a/src/app/modules/material/material.module.ts b/src/app/modules/material/material.module.ts index 6ccb444..2b934b2 100644 --- a/src/app/modules/material/material.module.ts +++ b/src/app/modules/material/material.module.ts @@ -6,7 +6,7 @@ import {InventoryComponent} from './pages/inventory/inventory.component'; import {SharedModule} from "../shared/shared.module"; import {AddComponent} from './pages/add/add.component'; import {EditComponent} from './pages/edit/edit.component'; -import {ColorsModule} from '../colors/colors.module' +import {RecipesModule} from '../recipes/recipes.module' import {MatSortModule} from '@angular/material/sort' import {FormsModule} from '@angular/forms' @@ -17,7 +17,7 @@ import {FormsModule} from '@angular/forms' CommonModule, MaterialRoutingModule, SharedModule, - ColorsModule, + RecipesModule, MatSortModule, FormsModule ] diff --git a/src/app/modules/recipes/add.html b/src/app/modules/recipes/add.html new file mode 100644 index 0000000..185e14a --- /dev/null +++ b/src/app/modules/recipes/add.html @@ -0,0 +1 @@ + diff --git a/src/app/modules/colors/bpac.js b/src/app/modules/recipes/bpac.js similarity index 100% rename from src/app/modules/colors/bpac.js rename to src/app/modules/recipes/bpac.js diff --git a/src/app/modules/colors/components/images-editor/images-editor.component.html b/src/app/modules/recipes/components/images-editor/images-editor.component.html similarity index 100% rename from src/app/modules/colors/components/images-editor/images-editor.component.html rename to src/app/modules/recipes/components/images-editor/images-editor.component.html diff --git a/src/app/modules/colors/components/images-editor/images-editor.component.sass b/src/app/modules/recipes/components/images-editor/images-editor.component.sass similarity index 100% rename from src/app/modules/colors/components/images-editor/images-editor.component.sass rename to src/app/modules/recipes/components/images-editor/images-editor.component.sass diff --git a/src/app/modules/colors/components/images-editor/images-editor.component.ts b/src/app/modules/recipes/components/images-editor/images-editor.component.ts similarity index 100% rename from src/app/modules/colors/components/images-editor/images-editor.component.ts rename to src/app/modules/recipes/components/images-editor/images-editor.component.ts diff --git a/src/app/modules/colors/components/mix-editor/mix-editor.component.html b/src/app/modules/recipes/components/mix-editor/mix-editor.component.html similarity index 100% rename from src/app/modules/colors/components/mix-editor/mix-editor.component.html rename to src/app/modules/recipes/components/mix-editor/mix-editor.component.html diff --git a/src/app/modules/colors/components/mix-editor/mix-editor.component.sass b/src/app/modules/recipes/components/mix-editor/mix-editor.component.sass similarity index 100% rename from src/app/modules/colors/components/mix-editor/mix-editor.component.sass rename to src/app/modules/recipes/components/mix-editor/mix-editor.component.sass diff --git a/src/app/modules/colors/components/mix-editor/mix-editor.component.ts b/src/app/modules/recipes/components/mix-editor/mix-editor.component.ts similarity index 100% rename from src/app/modules/colors/components/mix-editor/mix-editor.component.ts rename to src/app/modules/recipes/components/mix-editor/mix-editor.component.ts diff --git a/src/app/modules/colors/components/mix-table/mix-table.component.html b/src/app/modules/recipes/components/mix-table/mix-table.component.html similarity index 100% rename from src/app/modules/colors/components/mix-table/mix-table.component.html rename to src/app/modules/recipes/components/mix-table/mix-table.component.html diff --git a/src/app/modules/colors/components/mix-table/mix-table.component.sass b/src/app/modules/recipes/components/mix-table/mix-table.component.sass similarity index 100% rename from src/app/modules/colors/components/mix-table/mix-table.component.sass rename to src/app/modules/recipes/components/mix-table/mix-table.component.sass diff --git a/src/app/modules/colors/components/mix-table/mix-table.component.ts b/src/app/modules/recipes/components/mix-table/mix-table.component.ts similarity index 100% rename from src/app/modules/colors/components/mix-table/mix-table.component.ts rename to src/app/modules/recipes/components/mix-table/mix-table.component.ts diff --git a/src/app/modules/colors/components/mixes-card/mixes-card.component.html b/src/app/modules/recipes/components/mixes-card/mixes-card.component.html similarity index 100% rename from src/app/modules/colors/components/mixes-card/mixes-card.component.html rename to src/app/modules/recipes/components/mixes-card/mixes-card.component.html diff --git a/src/app/modules/colors/components/mixes-card/mixes-card.component.sass b/src/app/modules/recipes/components/mixes-card/mixes-card.component.sass similarity index 100% rename from src/app/modules/colors/components/mixes-card/mixes-card.component.sass rename to src/app/modules/recipes/components/mixes-card/mixes-card.component.sass diff --git a/src/app/modules/colors/components/mixes-card/mixes-card.component.ts b/src/app/modules/recipes/components/mixes-card/mixes-card.component.ts similarity index 100% rename from src/app/modules/colors/components/mixes-card/mixes-card.component.ts rename to src/app/modules/recipes/components/mixes-card/mixes-card.component.ts diff --git a/src/app/modules/colors/components/recipe-info/recipe-info.component.html b/src/app/modules/recipes/components/recipe-info/recipe-info.component.html similarity index 100% rename from src/app/modules/colors/components/recipe-info/recipe-info.component.html rename to src/app/modules/recipes/components/recipe-info/recipe-info.component.html diff --git a/src/app/modules/colors/components/recipe-info/recipe-info.component.sass b/src/app/modules/recipes/components/recipe-info/recipe-info.component.sass similarity index 100% rename from src/app/modules/colors/components/recipe-info/recipe-info.component.sass rename to src/app/modules/recipes/components/recipe-info/recipe-info.component.sass diff --git a/src/app/modules/colors/components/recipe-info/recipe-info.component.ts b/src/app/modules/recipes/components/recipe-info/recipe-info.component.ts similarity index 100% rename from src/app/modules/colors/components/recipe-info/recipe-info.component.ts rename to src/app/modules/recipes/components/recipe-info/recipe-info.component.ts diff --git a/src/app/modules/colors/components/step-list/step-list.component.html b/src/app/modules/recipes/components/step-list/step-list.component.html similarity index 100% rename from src/app/modules/colors/components/step-list/step-list.component.html rename to src/app/modules/recipes/components/step-list/step-list.component.html diff --git a/src/app/modules/colors/components/step-list/step-list.component.sass b/src/app/modules/recipes/components/step-list/step-list.component.sass similarity index 100% rename from src/app/modules/colors/components/step-list/step-list.component.sass rename to src/app/modules/recipes/components/step-list/step-list.component.sass diff --git a/src/app/modules/colors/components/step-list/step-list.component.ts b/src/app/modules/recipes/components/step-list/step-list.component.ts similarity index 100% rename from src/app/modules/colors/components/step-list/step-list.component.ts rename to src/app/modules/recipes/components/step-list/step-list.component.ts diff --git a/src/app/modules/colors/components/step-table/step-table.component.html b/src/app/modules/recipes/components/step-table/step-table.component.html similarity index 100% rename from src/app/modules/colors/components/step-table/step-table.component.html rename to src/app/modules/recipes/components/step-table/step-table.component.html diff --git a/src/app/modules/colors/components/step-table/step-table.component.sass b/src/app/modules/recipes/components/step-table/step-table.component.sass similarity index 100% rename from src/app/modules/colors/components/step-table/step-table.component.sass rename to src/app/modules/recipes/components/step-table/step-table.component.sass diff --git a/src/app/modules/colors/components/step-table/step-table.component.ts b/src/app/modules/recipes/components/step-table/step-table.component.ts similarity index 100% rename from src/app/modules/colors/components/step-table/step-table.component.ts rename to src/app/modules/recipes/components/step-table/step-table.component.ts diff --git a/src/app/modules/colors/components/unit-selector/unit-selector.component.html b/src/app/modules/recipes/components/unit-selector/unit-selector.component.html similarity index 100% rename from src/app/modules/colors/components/unit-selector/unit-selector.component.html rename to src/app/modules/recipes/components/unit-selector/unit-selector.component.html diff --git a/src/app/modules/colors/components/unit-selector/unit-selector.component.sass b/src/app/modules/recipes/components/unit-selector/unit-selector.component.sass similarity index 100% rename from src/app/modules/colors/components/unit-selector/unit-selector.component.sass rename to src/app/modules/recipes/components/unit-selector/unit-selector.component.sass diff --git a/src/app/modules/colors/components/unit-selector/unit-selector.component.ts b/src/app/modules/recipes/components/unit-selector/unit-selector.component.ts similarity index 100% rename from src/app/modules/colors/components/unit-selector/unit-selector.component.ts rename to src/app/modules/recipes/components/unit-selector/unit-selector.component.ts diff --git a/src/app/modules/recipes/form.html b/src/app/modules/recipes/form.html new file mode 100644 index 0000000..a00dcf1 --- /dev/null +++ b/src/app/modules/recipes/form.html @@ -0,0 +1,24 @@ +
+ +

Il n'y a actuellement aucune bannière enregistrée dans le système.

+

Vous pouvez en créer une ici.

+
+
+ + + Ajouter une recette + + + + + + + + + + + + Retour + Enregistrer + + diff --git a/src/app/modules/colors/pages/edit/edit.component.html b/src/app/modules/recipes/pages/edit/edit.component.html similarity index 100% rename from src/app/modules/colors/pages/edit/edit.component.html rename to src/app/modules/recipes/pages/edit/edit.component.html diff --git a/src/app/modules/colors/pages/edit/edit.component.sass b/src/app/modules/recipes/pages/edit/edit.component.sass similarity index 100% rename from src/app/modules/colors/pages/edit/edit.component.sass rename to src/app/modules/recipes/pages/edit/edit.component.sass diff --git a/src/app/modules/colors/pages/edit/edit.component.ts b/src/app/modules/recipes/pages/edit/edit.component.ts similarity index 100% rename from src/app/modules/colors/pages/edit/edit.component.ts rename to src/app/modules/recipes/pages/edit/edit.component.ts diff --git a/src/app/modules/colors/pages/explore/explore.component.html b/src/app/modules/recipes/pages/explore/explore.component.html similarity index 100% rename from src/app/modules/colors/pages/explore/explore.component.html rename to src/app/modules/recipes/pages/explore/explore.component.html diff --git a/src/app/modules/colors/pages/explore/explore.component.sass b/src/app/modules/recipes/pages/explore/explore.component.sass similarity index 100% rename from src/app/modules/colors/pages/explore/explore.component.sass rename to src/app/modules/recipes/pages/explore/explore.component.sass diff --git a/src/app/modules/colors/pages/explore/explore.component.ts b/src/app/modules/recipes/pages/explore/explore.component.ts similarity index 100% rename from src/app/modules/colors/pages/explore/explore.component.ts rename to src/app/modules/recipes/pages/explore/explore.component.ts diff --git a/src/app/modules/colors/pages/list/list.component.html b/src/app/modules/recipes/pages/list/list.component.html similarity index 100% rename from src/app/modules/colors/pages/list/list.component.html rename to src/app/modules/recipes/pages/list/list.component.html diff --git a/src/app/modules/colors/pages/list/list.component.sass b/src/app/modules/recipes/pages/list/list.component.sass similarity index 100% rename from src/app/modules/colors/pages/list/list.component.sass rename to src/app/modules/recipes/pages/list/list.component.sass diff --git a/src/app/modules/colors/pages/list/list.component.ts b/src/app/modules/recipes/pages/list/list.component.ts similarity index 99% rename from src/app/modules/colors/pages/list/list.component.ts rename to src/app/modules/recipes/pages/list/list.component.ts index 1f82f76..53077a6 100644 --- a/src/app/modules/colors/pages/list/list.component.ts +++ b/src/app/modules/recipes/pages/list/list.component.ts @@ -53,7 +53,7 @@ export class ListComponent extends ErrorHandlingComponent { } ) - //this.fetchCompanies() + this.fetchCompanies() this.fetchRecipes() } diff --git a/src/app/modules/colors/pages/mix/mix-add/mix-add.component.html b/src/app/modules/recipes/pages/mix/mix-add/mix-add.component.html similarity index 100% rename from src/app/modules/colors/pages/mix/mix-add/mix-add.component.html rename to src/app/modules/recipes/pages/mix/mix-add/mix-add.component.html diff --git a/src/app/modules/colors/pages/mix/mix-add/mix-add.component.sass b/src/app/modules/recipes/pages/mix/mix-add/mix-add.component.sass similarity index 100% rename from src/app/modules/colors/pages/mix/mix-add/mix-add.component.sass rename to src/app/modules/recipes/pages/mix/mix-add/mix-add.component.sass diff --git a/src/app/modules/colors/pages/mix/mix-add/mix-add.component.ts b/src/app/modules/recipes/pages/mix/mix-add/mix-add.component.ts similarity index 100% rename from src/app/modules/colors/pages/mix/mix-add/mix-add.component.ts rename to src/app/modules/recipes/pages/mix/mix-add/mix-add.component.ts diff --git a/src/app/modules/colors/pages/mix/mix-edit/mix-edit.component.html b/src/app/modules/recipes/pages/mix/mix-edit/mix-edit.component.html similarity index 100% rename from src/app/modules/colors/pages/mix/mix-edit/mix-edit.component.html rename to src/app/modules/recipes/pages/mix/mix-edit/mix-edit.component.html diff --git a/src/app/modules/colors/pages/mix/mix-edit/mix-edit.component.sass b/src/app/modules/recipes/pages/mix/mix-edit/mix-edit.component.sass similarity index 100% rename from src/app/modules/colors/pages/mix/mix-edit/mix-edit.component.sass rename to src/app/modules/recipes/pages/mix/mix-edit/mix-edit.component.sass diff --git a/src/app/modules/colors/pages/mix/mix-edit/mix-edit.component.ts b/src/app/modules/recipes/pages/mix/mix-edit/mix-edit.component.ts similarity index 100% rename from src/app/modules/colors/pages/mix/mix-edit/mix-edit.component.ts rename to src/app/modules/recipes/pages/mix/mix-edit/mix-edit.component.ts diff --git a/src/app/modules/colors/ptouchPrint.js b/src/app/modules/recipes/ptouchPrint.js similarity index 100% rename from src/app/modules/colors/ptouchPrint.js rename to src/app/modules/recipes/ptouchPrint.js diff --git a/src/app/modules/colors/colors-routing.module.ts b/src/app/modules/recipes/recipes-routing.module.ts similarity index 88% rename from src/app/modules/colors/colors-routing.module.ts rename to src/app/modules/recipes/recipes-routing.module.ts index 879d0a1..a29258a 100644 --- a/src/app/modules/colors/colors-routing.module.ts +++ b/src/app/modules/recipes/recipes-routing.module.ts @@ -1,18 +1,18 @@ import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {ListComponent} from "./pages/list/list.component"; -import {AddComponent} from "./pages/add/add.component"; import {EditComponent} from "./pages/edit/edit.component"; import {ExploreComponent} from "./pages/explore/explore.component"; import {MixEditComponent} from "./pages/mix/mix-edit/mix-edit.component"; import {MixAddComponent} from "./pages/mix/mix-add/mix-add.component"; +import {RecipeAdd} from './recipes'; const routes: Routes = [{ path: 'list', component: ListComponent }, { path: 'add', - component: AddComponent + component: RecipeAdd }, { path: 'edit/:id', component: EditComponent @@ -35,5 +35,5 @@ const routes: Routes = [{ imports: [RouterModule.forChild(routes)], exports: [RouterModule] }) -export class ColorsRoutingModule { +export class RecipesRoutingModule { } diff --git a/src/app/modules/colors/colors.module.ts b/src/app/modules/recipes/recipes.module.ts similarity index 65% rename from src/app/modules/colors/colors.module.ts rename to src/app/modules/recipes/recipes.module.ts index c994650..3170cd2 100644 --- a/src/app/modules/colors/colors.module.ts +++ b/src/app/modules/recipes/recipes.module.ts @@ -1,9 +1,8 @@ import {NgModule} from '@angular/core' -import {ColorsRoutingModule} from './colors-routing.module' +import {RecipesRoutingModule} from './recipes-routing.module' import {SharedModule} from '../shared/shared.module' import {ListComponent} from './pages/list/list.component' -import {AddComponent} from './pages/add/add.component' import {EditComponent} from './pages/edit/edit.component' import {MatExpansionModule} from '@angular/material/expansion' import {FormsModule} from '@angular/forms' @@ -19,20 +18,41 @@ import {MixEditComponent} from './pages/mix/mix-edit/mix-edit.component' import {ImagesEditorComponent} from './components/images-editor/images-editor.component' import {MixesCardComponent} from './components/mixes-card/mixes-card.component' import {MatSortModule} from '@angular/material/sort' +import {CreInputsModule} from '../shared/components/inputs/inputs.module'; +import {CreButtonsModule} from '../shared/components/buttons/buttons.module'; +import {RecipeAdd, RecipeForm} from './recipes'; @NgModule({ - declarations: [ListComponent, AddComponent, EditComponent, ExploreComponent, RecipeInfoComponent, MixTableComponent, StepListComponent, StepTableComponent, MixEditorComponent, UnitSelectorComponent, MixAddComponent, MixEditComponent, ImagesEditorComponent, MixesCardComponent], + declarations: [ + ListComponent, + EditComponent, + ExploreComponent, + RecipeInfoComponent, + MixTableComponent, + StepListComponent, + StepTableComponent, + MixEditorComponent, + UnitSelectorComponent, + MixAddComponent, + MixEditComponent, + ImagesEditorComponent, + MixesCardComponent, + RecipeForm, + RecipeAdd + ], exports: [ UnitSelectorComponent ], imports: [ - ColorsRoutingModule, + RecipesRoutingModule, SharedModule, MatExpansionModule, FormsModule, - MatSortModule + MatSortModule, + CreInputsModule, + CreButtonsModule ] }) -export class ColorsModule { +export class RecipesModule { } diff --git a/src/app/modules/recipes/recipes.ts b/src/app/modules/recipes/recipes.ts new file mode 100644 index 0000000..b6b6e75 --- /dev/null +++ b/src/app/modules/recipes/recipes.ts @@ -0,0 +1,119 @@ +import {ErrorHandlingComponent, SubscribingComponent} from '../shared/components/subscribing.component'; +import {Observable} from 'rxjs'; +import {ComboBoxEntry} from '../shared/components/inputs/inputs'; +import {map, tap} from 'rxjs/operators'; +import {RecipeService} from './services/recipe.service'; +import {CompanyService} from '../company/service/company.service'; +import {AppState} from '../shared/app-state'; +import {ErrorService} from '../shared/service/error.service'; +import {ActivatedRoute, Router} from '@angular/router'; +import {FormControl, Validators} from '@angular/forms'; +import {Component, EventEmitter, Input, Output} from '@angular/core'; +import {Recipe} from '../shared/model/recipe.model'; +import {AccountService} from '../accounts/services/account.service'; +import {Permission} from '../shared/model/user'; + +@Component({ + selector: 'cre-recipe-add', + templateUrl: 'add.html' +}) +export class RecipeAdd extends ErrorHandlingComponent { + controls: any + companyEntries$: Observable = this.companyService.all.pipe( + map(companies => companies.map(c => new ComboBoxEntry(c.id, c.name))), + ) + + errorHandlers = [{ + filter: error => error.type === `exists-recipe-company-name`, + messageProducer: error => `Une couleur avec le nom ${error.name} existe déjà pour la bannière ${error.company}` + }] + + constructor( + private recipeService: RecipeService, + private companyService: CompanyService, + private appState: AppState, + errorService: ErrorService, + router: Router, + activatedRoute: ActivatedRoute + ) { + super(errorService, activatedRoute, router) + this.appState.title = 'Nouvelle couleur' + } + + submit(recipe: Recipe) { + this.subscribe( + this.recipeService.save(recipe), + recipe => this.urlUtils.navigateTo(`/color/edit/${recipe.id}`) + ) + } +} + +@Component({ + selector: 'recipe-form', + templateUrl: 'form.html' +}) +export class RecipeForm extends SubscribingComponent { + @Input() recipe: Recipe | null + + @Output() submitForm = new EventEmitter(); + + controls: any + companyEntries$: Observable + hasCompanies = true + + constructor( + private companyService: CompanyService, + private accountService: AccountService, + errorService: ErrorService, + activatedRoute: ActivatedRoute, + router: Router, + ) { + super(errorService, activatedRoute, router) + } + + ngOnInit() { + super.ngOnInit(); + + this.fetchCompanies() + + this.controls = { + name: new FormControl(null, Validators.required), + description: new FormControl(null, Validators.required), + color: new FormControl('#ffffff', Validators.required), + gloss: new FormControl(0, Validators.compose([Validators.required, Validators.min(0), Validators.max(100)])), + sample: new FormControl(null, Validators.compose([Validators.required, Validators.min(0)])), + approbationDate: new FormControl(null), + remark: new FormControl(null), + company: new FormControl(null, Validators.required) + } + } + + 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))), + ) + } + + submit() { + this.submitForm.emit({ + id: this.recipe?.id, + name: this.controls.name.value, + description: this.controls.description.value, + color: this.controls.color.value, + gloss: this.controls.gloss.value, + sample: this.controls.sample.value, + approbationDate: this.controls.approbationDate.value, + remark: this.controls.remark.value, + company: this.controls.company.value, + mixes: this.recipe?.mixes, + approbationExpired: this.recipe?.approbationExpired, + groupsInformation: this.recipe?.groupsInformation, + imagesUrls: this.recipe?.imagesUrls + }) + } + + get hasCompanyEditPermission(): boolean { + return this.accountService.hasPermission(Permission.EDIT_COMPANIES) + } +} diff --git a/src/app/modules/colors/services/mix.service.ts b/src/app/modules/recipes/services/mix.service.ts similarity index 100% rename from src/app/modules/colors/services/mix.service.ts rename to src/app/modules/recipes/services/mix.service.ts diff --git a/src/app/modules/colors/services/recipe-image.service.ts b/src/app/modules/recipes/services/recipe-image.service.ts similarity index 100% rename from src/app/modules/colors/services/recipe-image.service.ts rename to src/app/modules/recipes/services/recipe-image.service.ts diff --git a/src/app/modules/recipes/services/recipe.service.ts b/src/app/modules/recipes/services/recipe.service.ts new file mode 100644 index 0000000..b3d2670 --- /dev/null +++ b/src/app/modules/recipes/services/recipe.service.ts @@ -0,0 +1,89 @@ +import {Injectable} from '@angular/core' +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' +}) +export class RecipeService { + constructor( + private api: ApiService + ) { + } + + get all(): Observable { + return this.api.get('/recipe') + } + + getAllByName(name: string): Observable { + return this.api.get(`/recipe?name=${name}`) + } + + get allByCompany(): Observable> { + return this.all.pipe(map(recipes => { + const map = new Map() + recipes.forEach(r => { + if (!map.has(r.company.id)) { + map.set(r.company.id, []) + } + map.get(r.company.id).push(r) + }) + return map + })) + } + + getById(id: number): Observable { + return this.api.get(`/recipe/${id}`) + } + + save(recipe: Recipe): Observable { + const body = { + ...recipe, + companyId: recipe.company + } + + return this.api.post('/recipe', body) + } + + update(id: number, name: string, description: string, color: string, gloss: number, sample: number, approbationDate: string, remark: string, steps: Map) { + const body = {id, name, description, color, gloss, sample, remark, steps: []} + if (approbationDate) { + // @ts-ignore + body.approbationDate = approbationDate + } + + steps.forEach((groupSteps, groupId) => { + const mappedGroupSteps = groupSteps.map(s => { + return {message: s.message, position: s.position} + }) + body.steps.push({groupId, steps: mappedGroupSteps}) + }) + + return this.api.put('/recipe', body) + } + + updateExplorerModifications(id: number, notes: Map, mixesLocationChange: Map): Observable { + const body = { + recipeId: id, + notes: [], + mixesLocation: [] + } + + notes.forEach((content, groupId) => { + body.notes.push({groupId, content}) + }) + + mixesLocationChange.forEach((location, mixId) => { + body.mixesLocation.push({mixId, location}) + }) + + return this.api.put('/recipe/public', body) + } + + delete(id: number): Observable { + return this.api.delete(`/recipe/${id}`) + } +} diff --git a/src/app/modules/shared/components/alerts/alerts.ts b/src/app/modules/shared/components/alerts/alerts.ts index e150819..e31da46 100644 --- a/src/app/modules/shared/components/alerts/alerts.ts +++ b/src/app/modules/shared/components/alerts/alerts.ts @@ -1,8 +1,9 @@ -import {Component} from '@angular/core'; +import {Component, ViewEncapsulation} from '@angular/core'; @Component({ selector: 'cre-warning-alert', - templateUrl: 'alerts.html' + templateUrl: 'alerts.html', + encapsulation: ViewEncapsulation.None }) export class WarningAlert { diff --git a/src/app/modules/shared/components/forms/forms.sass b/src/app/modules/shared/components/forms/forms.sass index fffedc8..1a3fb08 100644 --- a/src/app/modules/shared/components/forms/forms.sass +++ b/src/app/modules/shared/components/forms/forms.sass @@ -1,8 +1,12 @@ cre-form display: block + width: max-content + min-width: 50rem + margin-top: 3rem mat-card width: inherit + min-width: inherit cre-form-actions display: flex diff --git a/src/app/modules/shared/components/forms/forms.ts b/src/app/modules/shared/components/forms/forms.ts index 5770d23..98a556c 100644 --- a/src/app/modules/shared/components/forms/forms.ts +++ b/src/app/modules/shared/components/forms/forms.ts @@ -42,7 +42,7 @@ export class CreFormComponent implements OnInit { } get hasActions(): boolean { - return this.formActions === true + return !!this.formActions } get invalid(): boolean { diff --git a/src/app/modules/shared/components/inputs/autocomplete.html b/src/app/modules/shared/components/inputs/autocomplete.html index bc21b24..760d6f4 100644 --- a/src/app/modules/shared/components/inputs/autocomplete.html +++ b/src/app/modules/shared/components/inputs/autocomplete.html @@ -24,7 +24,7 @@ [ngTemplateOutletContext]="{errors: control.errors}"> - + {{option}} diff --git a/src/app/modules/shared/components/inputs/chips-combo-box.html b/src/app/modules/shared/components/inputs/chips-combo-box.html index 443ff0c..f454ad3 100644 --- a/src/app/modules/shared/components/inputs/chips-combo-box.html +++ b/src/app/modules/shared/components/inputs/chips-combo-box.html @@ -30,7 +30,7 @@ - + {{option.display ? option.display : option.value}} diff --git a/src/app/modules/shared/components/inputs/combo-box.html b/src/app/modules/shared/components/inputs/combo-box.html index 5170f8c..7df0d9f 100644 --- a/src/app/modules/shared/components/inputs/combo-box.html +++ b/src/app/modules/shared/components/inputs/combo-box.html @@ -4,19 +4,20 @@ matInput type="text" [required]="required" - [formControl]="control" + [formControl]="internalControl" [matAutocomplete]="auto"> - - Ce champ est requis + + Cette valeur est invalide + Ce champ est requis + [ngTemplateOutletContext]="{errors: internalControl.errors}"> - - {{option.value}} + + {{entry.display || entry.value}} diff --git a/src/app/modules/shared/components/inputs/input.html b/src/app/modules/shared/components/inputs/input.html index 2bf813e..7b5f60f 100644 --- a/src/app/modules/shared/components/inputs/input.html +++ b/src/app/modules/shared/components/inputs/input.html @@ -5,6 +5,7 @@ @@ -13,6 +14,7 @@ diff --git a/src/app/modules/shared/components/inputs/inputs.module.ts b/src/app/modules/shared/components/inputs/inputs.module.ts index 1797478..aeddff9 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 + CreInputComponent, CrePeriodInputComponent, CreSliderInputComponent } from './inputs' import {MatInputModule} from '@angular/material/input' import {MatIconModule} from '@angular/material/icon' @@ -17,6 +17,7 @@ import {MatChipsModule} from '@angular/material/chips' import {CreButtonsModule} from '../buttons/buttons.module' import {MatCheckboxModule} from '@angular/material/checkbox' import {MatSelectModule} from '@angular/material/select' +import {MatSliderModule} from '@angular/material/slider'; @NgModule({ declarations: [ @@ -27,7 +28,8 @@ import {MatSelectModule} from '@angular/material/select' CreChipComboBoxComponent, CreFileInputComponent, CreCheckboxInputComponent, - CrePeriodInputComponent + CrePeriodInputComponent, + CreSliderInputComponent ], imports: [ MatInputModule, @@ -42,6 +44,7 @@ import {MatSelectModule} from '@angular/material/select' CreButtonsModule, MatCheckboxModule, MatSelectModule, + MatSliderModule, ], exports: [ CreInputComponent, @@ -51,7 +54,8 @@ import {MatSelectModule} from '@angular/material/select' CreAutocompleteInputComponent, CreFileInputComponent, CreCheckboxInputComponent, - CrePeriodInputComponent + CrePeriodInputComponent, + CreSliderInputComponent ] }) export class CreInputsModule { diff --git a/src/app/modules/shared/components/inputs/inputs.ts b/src/app/modules/shared/components/inputs/inputs.ts index dc7204e..e080f72 100644 --- a/src/app/modules/shared/components/inputs/inputs.ts +++ b/src/app/modules/shared/components/inputs/inputs.ts @@ -22,7 +22,7 @@ import {MatAutocomplete, MatAutocompleteSelectedEvent} from '@angular/material/a @Directive() abstract class _CreInputBase { - @Input() control: AbstractControl | null + @Input() control: FormControl | null @Input() label: string @Input() value @Input() disabled = false @@ -55,9 +55,12 @@ export class CreInputComponent extends _CreInputBase implements AfterViewInit { element.type = this.type element.step = this.step.toString() element.placeholder = this.placeholder - element.required = this.required element.autocomplete = this.autocomplete ? 'on' : 'off' } + + get isFieldRequired(): boolean { + return this.control ? this.control.validator && this.control.validator({} as AbstractControl)?.required : this.required + } } @Component({ @@ -70,7 +73,7 @@ export class CreAutocompleteInputComponent { @Input() label: string @Input() icon: string @Input() required = true - @Input() options: Observable + @Input() entries: Observable @Input() value @Output() valueChange = new EventEmitter() @@ -132,14 +135,70 @@ export class CreChipInputComponent implements OnInit { templateUrl: 'combo-box.html', encapsulation: ViewEncapsulation.None }) -export class CreComboBoxComponent { +export class CreComboBoxComponent implements OnInit { @Input() control: AbstractControl @Input() label: string @Input() icon: string @Input() required = true - @Input() options: Observable + @Input() entries: Observable @ContentChild(TemplateRef) errors: TemplateRef + + internalControl: FormControl + validValue = false + + private _destroy$ = new Subject(); + private _entries: ComboBoxEntry[] + + ngOnInit() { + this.entries.pipe(takeUntil(this._destroy$)) + .subscribe({ + next: entries => { + this._entries = entries + + this.internalControl.setValue(this.findEntryByKey(this.control.value)?.value) + } + }) + + this.internalControl = new FormControl(null, Validators.compose([this.control.validator, this.valueValidator()])) + this.internalControl.valueChanges.pipe(takeUntil(this._destroy$)) + .subscribe({ + next: value => { + if (this.internalControl.valid) { + this.control.setValue(this.findEntryByValue(value).key) + } else { + this.control.setValue(null) + } + } + }) + } + + private findEntryByKey(key: any): ComboBoxEntry | null { + const found = this._entries.filter(e => e.key === key) + if (found.length <= 0) { + return null + } + return found[0] + } + + private findEntryByValue(value: any): ComboBoxEntry | null { + const found = this._entries.filter(e => e.value === value) + if (found.length <= 0) { + return null + } + return found[0] + } + + private existsEntryByValue(value: any): boolean { + return this._entries && this._entries.filter(o => o.value === value).length > 0 + } + + private valueValidator(): ValidatorFn { + return (control: AbstractControl): ValidationErrors | null => { + const valid = this.existsEntryByValue(control.value) + return valid ? null : {invalidValue: {value: control.value}} + } + } } @Component({ @@ -148,25 +207,27 @@ export class CreComboBoxComponent { encapsulation: ViewEncapsulation.None }) export class CreChipComboBoxComponent extends CreChipInputComponent implements OnDestroy { - @Input() options: Observable + @Input() entries: Observable @ContentChild(TemplateRef) errors: TemplateRef @ViewChild('chipInput') chipInput: ElementRef @ViewChild('auto') matAutocomplete: MatAutocomplete - filteredOptions: Observable + filteredEntries: Observable - private _options: ComboBoxEntry[] + private _entries: ComboBoxEntry[] private _destroy$ = new Subject() ngOnInit() { super.ngOnInit() - this.options.pipe(takeUntil(this._destroy$)) - .subscribe({next: options => this._options = options}) + this.entries.pipe(takeUntil(this._destroy$)) + .subscribe({ + next: entries => this._entries = entries + }) - this.filteredOptions = this.inputControl.valueChanges.pipe( - map((query: string | null) => query ? this._filter(query) : this._options.slice()) + this.filteredEntries = this.inputControl.valueChanges.pipe( + map((query: string | null) => query ? this._filter(query) : this._entries.slice()) ) } @@ -187,11 +248,11 @@ export class CreChipComboBoxComponent extends CreChipInputComponent implements O private _filter(query: string): ComboBoxEntry[] { const filterValue = query.toString().toLowerCase() - return this._options.filter(option => option.value.toString().toLowerCase().indexOf(filterValue) === 0) + return this._entries.filter(e => e.value.toString().toLowerCase().indexOf(filterValue) === 0) } private findValueByKey(key: any): any { - return this._options.filter(o => o.key === key)[0].value + return this._entries.filter(e => e.key === key)[0].value } } @@ -294,6 +355,24 @@ export class CrePeriodInputComponent implements OnInit { } } +@Component({ + selector: 'cre-slider-input', + templateUrl: 'slider.html' +}) +export class CreSliderInputComponent { + @Input() control: FormControl + @Input() label: string + @Input() min: number + @Input() max: number + @Input() step = 1 + @Input() percents = false + @Input() thumbLabel = true + + formatValueForDisplay(value: number): string { + return this.percents ? `${value}%` : value.toString() + } +} + export class ComboBoxEntry { constructor( public key: any, diff --git a/src/app/modules/shared/components/inputs/slider.html b/src/app/modules/shared/components/inputs/slider.html new file mode 100644 index 0000000..1873422 --- /dev/null +++ b/src/app/modules/shared/components/inputs/slider.html @@ -0,0 +1,13 @@ +
+

{{label}}

+ + +
diff --git a/src/app/modules/shared/model/recipe.model.ts b/src/app/modules/shared/model/recipe.model.ts index 2fb9e52..3b096e0 100644 --- a/src/app/modules/shared/model/recipe.model.ts +++ b/src/app/modules/shared/model/recipe.model.ts @@ -1,25 +1,21 @@ import {Material} from './material.model' -import {LocalDate} from 'js-joda' import {Company} from './company.model' import {Group} from './user' export class Recipe { - constructor( - public id: number, - public name: string, - public description: string, - public color: string, - public gloss: number, - public sample: number, - public approbationDate: string, - public approbationExpired: boolean, - public remark: string, - public company: Company, - public mixes: Mix[], - public groupsInformation: RecipeGroupInformation[], - public imagesUrls: string[] - ) { - } + public id: number + public name: string + public description: string + public color: string + public gloss: number + public sample: number + public approbationDate: string + public remark: string + public company: Company + public mixes: Mix[] + public approbationExpired: boolean + public groupsInformation: RecipeGroupInformation[] + public imagesUrls: string[] } export class RecipeGroupInformation { diff --git a/src/app/modules/touch-up-kit/components/finish.ts b/src/app/modules/touch-up-kit/components/finish.ts index d91f01b..09b2fd7 100644 --- a/src/app/modules/touch-up-kit/components/finish.ts +++ b/src/app/modules/touch-up-kit/components/finish.ts @@ -1,6 +1,6 @@ import {Component, Input} from '@angular/core' import {SubscribingComponent} from '../../shared/components/subscribing.component' -import {RecipeService} from '../../colors/services/recipe.service' +import {RecipeService} from '../../recipes/services/recipe.service' import {ErrorService} from '../../shared/service/error.service' import {ActivatedRoute, Router} from '@angular/router' import {Recipe} from '../../shared/model/recipe.model' diff --git a/src/app/modules/touch-up-kit/components/form.html b/src/app/modules/touch-up-kit/components/form.html index 999b820..a6dd9eb 100644 --- a/src/app/modules/touch-up-kit/components/form.html +++ b/src/app/modules/touch-up-kit/components/form.html @@ -5,7 +5,7 @@ @@ -18,7 +18,7 @@ diff --git a/src/app/modules/touch-up-kit/components/form.ts b/src/app/modules/touch-up-kit/components/form.ts index 0a77b7f..b9b5e51 100644 --- a/src/app/modules/touch-up-kit/components/form.ts +++ b/src/app/modules/touch-up-kit/components/form.ts @@ -3,7 +3,7 @@ import {chipListRequired, ComboBoxEntry, CreChipComboBoxComponent} from '../../s import {CreFormComponent} from '../../shared/components/forms/forms' import {TouchUpKitProductEditor} from './product-editor' import {FormControl, Validators} from '@angular/forms' -import {RecipeService} from '../../colors/services/recipe.service' +import {RecipeService} from '../../recipes/services/recipe.service' import {CompanyService} from '../../company/service/company.service' import {ErrorService} from '../../shared/service/error.service' import {ActivatedRoute, Router} from '@angular/router' diff --git a/src/app/modules/touch-up-kit/pages/touchupkit.ts b/src/app/modules/touch-up-kit/pages/touchupkit.ts index 57b3ed5..b9db2e4 100644 --- a/src/app/modules/touch-up-kit/pages/touchupkit.ts +++ b/src/app/modules/touch-up-kit/pages/touchupkit.ts @@ -7,7 +7,7 @@ import {AccountService} from '../../accounts/services/account.service' import {ErrorService} from '../../shared/service/error.service' import {ActivatedRoute, Router} from '@angular/router' import {Permission} from '../../shared/model/user' -import {RecipeService} from '../../colors/services/recipe.service' +import {RecipeService} from '../../recipes/services/recipe.service' import {AppState} from '../../shared/app-state' import {map} from 'rxjs/operators' import {LocalDate, Period} from 'js-joda'