diff --git a/src/main/frontend/src/app/app.component.html b/src/main/frontend/src/app/app.component.html index a362220..4dd83bd 100644 --- a/src/main/frontend/src/app/app.component.html +++ b/src/main/frontend/src/app/app.component.html @@ -1,5 +1,6 @@
+
diff --git a/src/main/frontend/src/app/modules/accounts/pages/login/login.component.html b/src/main/frontend/src/app/modules/accounts/pages/login/login.component.html index 8917593..c02ca51 100644 --- a/src/main/frontend/src/app/modules/accounts/pages/login/login.component.html +++ b/src/main/frontend/src/app/modules/accounts/pages/login/login.component.html @@ -1,4 +1,3 @@ -
diff --git a/src/main/frontend/src/app/modules/colors/colors.module.ts b/src/main/frontend/src/app/modules/colors/colors.module.ts index d8aa665..fec9c19 100644 --- a/src/main/frontend/src/app/modules/colors/colors.module.ts +++ b/src/main/frontend/src/app/modules/colors/colors.module.ts @@ -16,10 +16,12 @@ import {MixEditorComponent} from './components/mix-editor/mix-editor.component'; import {UnitSelectorComponent} from './components/unit-selector/unit-selector.component'; import {MixAddComponent} from './pages/mix/mix-add/mix-add.component'; 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'; @NgModule({ - declarations: [ListComponent, AddComponent, EditComponent, ExploreComponent, RecipeInfoComponent, MixTableComponent, StepListComponent, StepTableComponent, MixEditorComponent, UnitSelectorComponent, MixAddComponent, MixEditComponent], + declarations: [ListComponent, AddComponent, EditComponent, ExploreComponent, RecipeInfoComponent, MixTableComponent, StepListComponent, StepTableComponent, MixEditorComponent, UnitSelectorComponent, MixAddComponent, MixEditComponent, ImagesEditorComponent, MixesCardComponent], imports: [ ColorsRoutingModule, SharedModule, diff --git a/src/main/frontend/src/app/modules/colors/components/images-editor/images-editor.component.html b/src/main/frontend/src/app/modules/colors/components/images-editor/images-editor.component.html new file mode 100644 index 0000000..4408b14 --- /dev/null +++ b/src/main/frontend/src/app/modules/colors/components/images-editor/images-editor.component.html @@ -0,0 +1,26 @@ + + + Images + + +
+
+
+ +
+ + +
+
+
+
+
+ + + + +
diff --git a/src/main/frontend/src/app/modules/colors/components/images-editor/images-editor.component.sass b/src/main/frontend/src/app/modules/colors/components/images-editor/images-editor.component.sass new file mode 100644 index 0000000..5b1267b --- /dev/null +++ b/src/main/frontend/src/app/modules/colors/components/images-editor/images-editor.component.sass @@ -0,0 +1,9 @@ +mat-card + background-color: rgba(255, 255, 255, 0.5) + max-width: 90vw !important + + .image-wrapper + padding: 16px + border-radius: 4px + box-shadow: 0 2px 1px -1px rgba(0, 0, 0, 0.2), 0 1px 1px 0 rgba(0, 0, 0, 0.14), 0 1px 3px 0 rgba(0, 0, 0, 0.12) + background-color: white diff --git a/src/main/frontend/src/app/modules/colors/components/images-editor/images-editor.component.ts b/src/main/frontend/src/app/modules/colors/components/images-editor/images-editor.component.ts new file mode 100644 index 0000000..eab25c5 --- /dev/null +++ b/src/main/frontend/src/app/modules/colors/components/images-editor/images-editor.component.ts @@ -0,0 +1,57 @@ +import {Component, Input} from '@angular/core'; +import {Recipe} from "../../../shared/model/recipe.model"; +import {SubscribingComponent} from "../../../shared/components/subscribing.component"; +import {ActivatedRoute, Router} from "@angular/router"; +import {Observable} from "rxjs"; +import {RecipeImageService} from "../../services/recipe-image.service"; +import {environment} from "../../../../../environments/environment"; + +@Component({ + selector: 'cre-images-editor', + templateUrl: './images-editor.component.html', + styleUrls: ['./images-editor.component.sass'] +}) +export class ImagesEditorComponent extends SubscribingComponent { + @Input() recipe: Recipe + @Input() editionMode = false + + imageIds$: Observable + backendUrl = environment.apiUrl + + constructor( + private recipeImageService: RecipeImageService, + router: Router, + activatedRoute: ActivatedRoute + ) { + super(activatedRoute, router) + } + + ngOnInit() { + super.ngOnInit() + + this.loadImagesIds() + } + + submit(event) { + const image = event.target.files[0] + this.subscribe( + this.recipeImageService.save(image, this.recipe.id), + {next: () => this.loadImagesIds()} + ) + } + + openImage(imageId: number) { + window.open(`${environment.apiUrl}/recipe/${this.recipe.id}/image/${imageId}`, '_blank') + } + + delete(imageId: number) { + this.subscribe( + this.recipeImageService.delete(imageId, this.recipe.id), + {next: () => this.loadImagesIds()} + ) + } + + private loadImagesIds() { + this.imageIds$ = this.recipeImageService.getAllIdsForRecipe(this.recipe.id) + } +} diff --git a/src/main/frontend/src/app/modules/colors/components/mix-table/mix-table.component.html b/src/main/frontend/src/app/modules/colors/components/mix-table/mix-table.component.html index 7ab681e..ed4576b 100644 --- a/src/main/frontend/src/app/modules/colors/components/mix-table/mix-table.component.html +++ b/src/main/frontend/src/app/modules/colors/components/mix-table/mix-table.component.html @@ -4,7 +4,7 @@
- +
Casier @@ -18,7 +18,7 @@
- +
@@ -92,8 +92,8 @@ - + [class.low-quantity]="!editionMode && isInLowQuantity(mixMaterial.id)"> + diff --git a/src/main/frontend/src/app/modules/colors/components/mix-table/mix-table.component.ts b/src/main/frontend/src/app/modules/colors/components/mix-table/mix-table.component.ts index 90a72b4..ca766b9 100644 --- a/src/main/frontend/src/app/modules/colors/components/mix-table/mix-table.component.ts +++ b/src/main/frontend/src/app/modules/colors/components/mix-table/mix-table.component.ts @@ -22,7 +22,7 @@ export class MixTableComponent extends SubscribingComponent { @Input() recipe: Recipe @Input() units$: Subject @Input() deductErrorBody - @Input() editing: boolean + @Input() editionMode: boolean @Input() printingError = 2 @Output() locationChange = new EventEmitter<{ id: number, location: string }>() @Output() quantityChange = new EventEmitter<{ id: number, materialId: number, quantity: number }>() @@ -46,7 +46,7 @@ export class MixTableComponent extends SubscribingComponent { ngOnInit() { super.ngOnInit(); - if (this.editing) { + if (this.editionMode) { this.mixColumns = this.COLUMNS_STATIC } @@ -142,7 +142,7 @@ export class MixTableComponent extends SubscribingComponent { } private convertQuantities(newUnit: string) { - this.computedQuantities.forEach(q => convertMixMaterialQuantity(q, this.units, newUnit)) + this.computedQuantities.forEach(q => q.quantity = convertMixMaterialQuantity(q, this.units, newUnit)) this.units = newUnit } diff --git a/src/main/frontend/src/app/modules/colors/components/step-list/step-list.component.html b/src/main/frontend/src/app/modules/colors/components/step-list/step-list.component.html index 0951d5d..ff972e2 100644 --- a/src/main/frontend/src/app/modules/colors/components/step-list/step-list.component.html +++ b/src/main/frontend/src/app/modules/colors/components/step-list/step-list.component.html @@ -1,4 +1,4 @@ - + Étapes diff --git a/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.html b/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.html index 7d0ab6b..3baa01f 100644 --- a/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.html +++ b/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.html @@ -35,34 +35,21 @@ [formFields]="formFields" [unknownError]="unknownError" [customError]="errorMessage" - [disableButtons]="true"> + [disableButtons]="true" + [noTopMargin]="true">
- - - Mélanges - - - - - - - - - - - +
-
+
+ +
+ +
diff --git a/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.sass b/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.sass index a474d96..2533b3c 100644 --- a/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.sass +++ b/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.sass @@ -1,17 +1,2 @@ .recipe-wrapper > div margin: 0 3rem 3rem - - mat-card - margin-top: 3rem - -.recipe-mixes-wrapper mat-card - min-width: 20rem - -mat-card - mat-card-content - margin-bottom: 0 - padding-top: 16px !important - padding-bottom: 0 !important - - mat-card-actions - margin-top: 0 diff --git a/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.ts b/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.ts index 59f8923..a493da4 100644 --- a/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.ts +++ b/src/main/frontend/src/app/modules/colors/pages/edit/edit.component.ts @@ -1,14 +1,15 @@ -import {Component} from '@angular/core'; +import {Component, ViewChild} from '@angular/core'; import {SubscribingComponent} from "../../../shared/components/subscribing.component"; import {Recipe} from "../../../shared/model/recipe.model"; import {RecipeService} from "../../services/recipe.service"; import {ActivatedRoute, Router} from "@angular/router"; -import {FormBuilder, Validators} from "@angular/forms"; +import {Validators} from "@angular/forms"; import {Subject} from "rxjs"; import {UNIT_GALLON, UNIT_LITER, UNIT_MILLILITER} from "../../../shared/units"; import {AccountService} from "../../../accounts/services/account.service"; import {EmployeePermission} from "../../../shared/model/employee"; import {EntityEditComponent} from "../../../shared/components/entity-edit/entity-edit.component"; +import {ImagesEditorComponent} from "../../components/images-editor/images-editor.component"; @Component({ selector: 'cre-edit', @@ -18,6 +19,8 @@ import {EntityEditComponent} from "../../../shared/components/entity-edit/entity export class EditComponent extends SubscribingComponent { readonly unitConstants = {UNIT_MILLILITER, UNIT_LITER, UNIT_GALLON} + @ViewChild('imagesEditor') imagesEditor: ImagesEditorComponent + recipe: Recipe | null formFields = [ { diff --git a/src/main/frontend/src/app/modules/colors/pages/explore/explore.component.html b/src/main/frontend/src/app/modules/colors/pages/explore/explore.component.html index 9fbb0f0..76cd1bb 100644 --- a/src/main/frontend/src/app/modules/colors/pages/explore/explore.component.html +++ b/src/main/frontend/src/app/modules/colors/pages/explore/explore.component.html @@ -42,31 +42,28 @@
-
+
- - - - + +
-
- -
- Images + +
+ +
diff --git a/src/main/frontend/src/app/modules/colors/pages/explore/explore.component.sass b/src/main/frontend/src/app/modules/colors/pages/explore/explore.component.sass index 24c7079..1775c49 100644 --- a/src/main/frontend/src/app/modules/colors/pages/explore/explore.component.sass +++ b/src/main/frontend/src/app/modules/colors/pages/explore/explore.component.sass @@ -1,21 +1,2 @@ -.recipe-content - display: flex - flex-direction: column - align-items: center - - div - margin-bottom: 1rem - -.recipe-images - margin-top: 5rem - padding: 2rem - background-color: grey - -@media screen and (min-width: 1920px) - .action-bar - padding-bottom: 5rem - - .recipe-content - flex-direction: row - justify-content: space-around - align-items: start +.recipe-content > div + margin: 0 3rem 3rem diff --git a/src/main/frontend/src/app/modules/colors/services/recipe-image.service.ts b/src/main/frontend/src/app/modules/colors/services/recipe-image.service.ts new file mode 100644 index 0000000..000462a --- /dev/null +++ b/src/main/frontend/src/app/modules/colors/services/recipe-image.service.ts @@ -0,0 +1,32 @@ +import {Injectable} from '@angular/core'; +import {ApiService} from "../../shared/service/api.service"; +import {Observable} from "rxjs"; + +@Injectable({ + providedIn: 'root' +}) +export class RecipeImageService { + constructor( + private api: ApiService + ) { + } + + getAllIdsForRecipe(recipeId: number): Observable { + return this.api.get(`/recipe/${recipeId}/image`) + } + + save(image: File, recipeId: number): Observable { + const body = new FormData() + body.append('image', image) + return this.api.post(`/recipe/${recipeId}/image`, body, true) + } + + deleteAll(imageIds: number[], recipeId: number) { + imageIds.forEach(id => this.delete(id, recipeId)) + } + + delete(imageId: number, recipeId: number): Observable { + return this.api.delete(`/recipe/${recipeId}/image/${imageId}`) + } +} + diff --git a/src/main/frontend/src/app/modules/employees/services/employee.service.ts b/src/main/frontend/src/app/modules/employees/services/employee.service.ts index f0c9765..57660fb 100644 --- a/src/main/frontend/src/app/modules/employees/services/employee.service.ts +++ b/src/main/frontend/src/app/modules/employees/services/employee.service.ts @@ -31,7 +31,7 @@ export class EmployeeService { } updatePassword(id: number, password: string): Observable { - return this.api.put(`/employee/${id}/password`, password, true, {headers: {contentType: 'text/plain'}}) + return this.api.put(`/employee/${id}/password`, password, true, {contentType: 'text/plain'}) } delete(id: number): Observable { diff --git a/src/main/frontend/src/app/modules/material/pages/edit/edit.component.html b/src/main/frontend/src/app/modules/material/pages/edit/edit.component.html index 894cbd8..e52a94a 100644 --- a/src/main/frontend/src/app/modules/material/pages/edit/edit.component.html +++ b/src/main/frontend/src/app/modules/material/pages/edit/edit.component.html @@ -26,12 +26,11 @@ (click)="openSimdutUrl()"> Voir la fiche signalitique -
- - - {{field.label}} - - -
+ + diff --git a/src/main/frontend/src/app/modules/material/pages/edit/edit.component.sass b/src/main/frontend/src/app/modules/material/pages/edit/edit.component.sass index 56ef602..29212c3 100644 --- a/src/main/frontend/src/app/modules/material/pages/edit/edit.component.sass +++ b/src/main/frontend/src/app/modules/material/pages/edit/edit.component.sass @@ -1,14 +1,3 @@ .simdut-file button height: 43px - - .edit-simdut-file-input - width: 250px - - mat-form-field - z-index: 10 - margin-top: 10px - opacity: 0 - - button - position: absolute diff --git a/src/main/frontend/src/app/modules/material/pages/edit/edit.component.ts b/src/main/frontend/src/app/modules/material/pages/edit/edit.component.ts index f8d1369..a194cda 100644 --- a/src/main/frontend/src/app/modules/material/pages/edit/edit.component.ts +++ b/src/main/frontend/src/app/modules/material/pages/edit/edit.component.ts @@ -1,6 +1,6 @@ import {Component, ViewChild} from '@angular/core'; import {FormField} from "../../../shared/components/entity-add/entity-add.component"; -import {FormBuilder, Validators} from "@angular/forms"; +import {Validators} from "@angular/forms"; import {map} from "rxjs/operators"; import {MaterialTypeService} from "../../../material-type/service/material-type.service"; import {MaterialService} from "../../service/material.service"; diff --git a/src/main/frontend/src/app/modules/shared/components/entity-edit/entity-edit.component.html b/src/main/frontend/src/app/modules/shared/components/entity-edit/entity-edit.component.html index 7a47a11..f4a31d3 100644 --- a/src/main/frontend/src/app/modules/shared/components/entity-edit/entity-edit.component.html +++ b/src/main/frontend/src/app/modules/shared/components/entity-edit/entity-edit.component.html @@ -1,4 +1,4 @@ - + {{title}} diff --git a/src/main/frontend/src/app/modules/shared/components/entity-edit/entity-edit.component.ts b/src/main/frontend/src/app/modules/shared/components/entity-edit/entity-edit.component.ts index 2473c99..93de76e 100644 --- a/src/main/frontend/src/app/modules/shared/components/entity-edit/entity-edit.component.ts +++ b/src/main/frontend/src/app/modules/shared/components/entity-edit/entity-edit.component.ts @@ -21,6 +21,7 @@ export class EntityEditComponent extends SubscribingComponent { @Input() unknownError = false @Input() customError: string | null @Input() disableButtons: boolean + @Input() noTopMargin = false @Output() submit = new EventEmitter() @Output() delete = new EventEmitter() diff --git a/src/main/frontend/src/app/modules/shared/file-button/file-button.component.html b/src/main/frontend/src/app/modules/shared/file-button/file-button.component.html new file mode 100644 index 0000000..1539365 --- /dev/null +++ b/src/main/frontend/src/app/modules/shared/file-button/file-button.component.html @@ -0,0 +1,11 @@ +
+ + + {{label}} + + + +
diff --git a/src/main/frontend/src/app/modules/shared/file-button/file-button.component.sass b/src/main/frontend/src/app/modules/shared/file-button/file-button.component.sass new file mode 100644 index 0000000..83cdff0 --- /dev/null +++ b/src/main/frontend/src/app/modules/shared/file-button/file-button.component.sass @@ -0,0 +1,13 @@ +.file-button-wrapper + width: 16rem + + button + width: 16rem + + mat-form-field + width: 16rem + z-index: 10 + opacity: 0 + + button + position: absolute diff --git a/src/main/frontend/src/app/modules/shared/file-button/file-button.component.ts b/src/main/frontend/src/app/modules/shared/file-button/file-button.component.ts new file mode 100644 index 0000000..18eb036 --- /dev/null +++ b/src/main/frontend/src/app/modules/shared/file-button/file-button.component.ts @@ -0,0 +1,18 @@ +import {Component, Input, ViewChild} from '@angular/core'; +import {FormControl} from "@angular/forms"; +import {ThemePalette} from "@angular/material/core"; +import {MaterialFileInputModule} from "ngx-material-file-input"; + +@Component({ + selector: 'cre-file-button', + templateUrl: './file-button.component.html', + styleUrls: ['./file-button.component.sass'] +}) +export class FileButtonComponent { + @ViewChild('fileInput') fileInput: MaterialFileInputModule + + @Input() label: string + @Input() color: ThemePalette + @Input() accept: string + @Input() control: FormControl | null +} diff --git a/src/main/frontend/src/app/modules/shared/service/api.service.ts b/src/main/frontend/src/app/modules/shared/service/api.service.ts index ef987a5..eec4707 100644 --- a/src/main/frontend/src/app/modules/shared/service/api.service.ts +++ b/src/main/frontend/src/app/modules/shared/service/api.service.ts @@ -5,6 +5,7 @@ import {environment} from "../../../../environments/environment"; import {AppState} from "../app-state"; import {Router} from "@angular/router"; import {map, share, takeUntil} from "rxjs/operators"; +import {valueOr} from "../utils/optional.utils"; @Injectable({ providedIn: 'root' @@ -61,7 +62,11 @@ export class ApiService implements OnDestroy { } private executeHttpRequest(requestFn: (httpOptions) => Observable, needAuthentication = true, requestOptions: ApiRequestOptions = new ApiRequestOptions()): Observable { - const httpOptions = {withCredentials: false, observe: 'response'} + const httpOptions = { + withCredentials: false, + headers: {contentType: valueOr(requestOptions.contentType, 'application/json')}, + observe: 'response' + } if (needAuthentication) { if (this.checkAuthenticated()) { if (httpOptions) { @@ -83,6 +88,7 @@ export class ApiService implements OnDestroy { const errorCheckSubscription = result$.subscribe({ next: () => this.appState.isServerOnline = true, error: err => { + console.error(err) errorCheckSubscription.unsubscribe() this.appState.isServerOnline = !(err.status === 0 && err.statusText === "Unknown Error"); } @@ -102,7 +108,8 @@ export class ApiService implements OnDestroy { export class ApiRequestOptions { constructor( - public takeFullResponse = false + public takeFullResponse?, + public contentType? ) { } } diff --git a/src/main/frontend/src/app/modules/shared/shared.module.ts b/src/main/frontend/src/app/modules/shared/shared.module.ts index c7cbff4..62c3d95 100644 --- a/src/main/frontend/src/app/modules/shared/shared.module.ts +++ b/src/main/frontend/src/app/modules/shared/shared.module.ts @@ -26,35 +26,37 @@ import {EntityEditComponent} from './components/entity-edit/entity-edit.componen import {MatSelectModule} from "@angular/material/select"; import {MatOptionModule} from "@angular/material/core"; import {MaterialFileInputModule} from "ngx-material-file-input"; +import { FileButtonComponent } from './file-button/file-button.component'; @NgModule({ - declarations: [HeaderComponent, EmployeeInfoComponent, LabeledIconComponent, ConfirmBoxComponent, PermissionsListComponent, PermissionsFieldComponent, NavComponent, EntityListComponent, EntityAddComponent, EntityEditComponent], - exports: [ - CommonModule, - HttpClientModule, - HeaderComponent, - MatCardModule, - MatButtonModule, - MatFormFieldModule, - MatInputModule, - MatIconModule, - MatTableModule, - MatCheckboxModule, - MatListModule, - MatSelectModule, - MatOptionModule, - MaterialFileInputModule, - ReactiveFormsModule, - LabeledIconComponent, - ConfirmBoxComponent, - PermissionsListComponent, - PermissionsFieldComponent, - NavComponent, - EntityListComponent, - EntityAddComponent, - EntityEditComponent - ], + declarations: [HeaderComponent, EmployeeInfoComponent, LabeledIconComponent, ConfirmBoxComponent, PermissionsListComponent, PermissionsFieldComponent, NavComponent, EntityListComponent, EntityAddComponent, EntityEditComponent, FileButtonComponent], + exports: [ + CommonModule, + HttpClientModule, + HeaderComponent, + MatCardModule, + MatButtonModule, + MatFormFieldModule, + MatInputModule, + MatIconModule, + MatTableModule, + MatCheckboxModule, + MatListModule, + MatSelectModule, + MatOptionModule, + MaterialFileInputModule, + ReactiveFormsModule, + LabeledIconComponent, + ConfirmBoxComponent, + PermissionsListComponent, + PermissionsFieldComponent, + NavComponent, + EntityListComponent, + EntityAddComponent, + EntityEditComponent, + FileButtonComponent + ], imports: [ MatTabsModule, MatIconModule, diff --git a/src/main/frontend/src/app/modules/shared/utils/optional.utils.ts b/src/main/frontend/src/app/modules/shared/utils/optional.utils.ts new file mode 100644 index 0000000..ef66afa --- /dev/null +++ b/src/main/frontend/src/app/modules/shared/utils/optional.utils.ts @@ -0,0 +1,4 @@ +/** Returns [value] if it is not null or [or]. */ +export function valueOr(value: T, or: T): T { + return value ? value : or +}