From 2d235f93cd29dc568102d4b4cdbb50ae7478f238 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Sat, 1 May 2021 20:44:34 -0400 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20g=C3=A9n=C3=A9ration=20de=20k?= =?UTF-8?q?its=20de=20retouche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app-routing.module.ts | 14 ++++- src/app/app.module.ts | 6 +- src/app/modules/colors/colors.module.ts | 60 +++++++++---------- .../employee-menu.component.html | 6 +- .../employee-info/employee-menu.component.ts | 28 +++++++-- .../components/header/header.component.ts | 15 +++-- src/app/modules/shared/model/employee.ts | 4 +- .../shared/service/touchupkit.service.ts | 11 ++++ src/app/pages/others/misc.component.html | 2 + src/app/pages/others/misc.component.sass | 0 src/app/pages/others/misc.component.ts | 15 +++++ 11 files changed, 112 insertions(+), 49 deletions(-) create mode 100644 src/app/modules/shared/service/touchupkit.service.ts create mode 100644 src/app/pages/others/misc.component.html create mode 100644 src/app/pages/others/misc.component.sass create mode 100644 src/app/pages/others/misc.component.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 7a4fe40..be757b7 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -2,6 +2,8 @@ import {NgModule} from '@angular/core' import {Routes, RouterModule} from '@angular/router' import {CatalogComponent} from './pages/catalog/catalog.component' import {AdministrationComponent} from './pages/administration/administration.component' +import {MiscComponent} from './pages/others/misc.component' +import {TouchupkitComponent} from './pages/others/touchupkit/touchupkit.component' const routes: Routes = [{ @@ -44,8 +46,16 @@ const routes: Routes = [{ } ] }, { - path: 'material', - loadChildren: () => import('./modules/material/material.module').then(m => m.MaterialModule) + path: 'misc', + component: MiscComponent, + children: [{ + path: 'touchupkit', + component: TouchupkitComponent + }, { + path: '', + pathMatch: 'full', + redirectTo: 'touchupkit' + }] }] @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 09374d6..9de024d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -9,12 +9,16 @@ import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; import {CatalogComponent} from './pages/catalog/catalog.component'; import {CompanyModule} from './modules/company/company.module'; import { AdministrationComponent } from './pages/administration/administration.component'; +import { MiscComponent } from './pages/others/misc.component'; +import { TouchupkitComponent } from './pages/others/touchupkit/touchupkit.component'; @NgModule({ declarations: [ AppComponent, CatalogComponent, - AdministrationComponent + AdministrationComponent, + MiscComponent, + TouchupkitComponent ], imports: [ AppRoutingModule, diff --git a/src/app/modules/colors/colors.module.ts b/src/app/modules/colors/colors.module.ts index 6832ed8..c994650 100644 --- a/src/app/modules/colors/colors.module.ts +++ b/src/app/modules/colors/colors.module.ts @@ -1,38 +1,38 @@ -import {NgModule} from '@angular/core'; +import {NgModule} from '@angular/core' -import {ColorsRoutingModule} from './colors-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"; -import {ExploreComponent} from './pages/explore/explore.component'; -import {RecipeInfoComponent} from './components/recipe-info/recipe-info.component'; -import {MixTableComponent} from './components/mix-table/mix-table.component'; -import {StepListComponent} from './components/step-list/step-list.component'; -import {StepTableComponent} from './components/step-table/step-table.component'; -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'; +import {ColorsRoutingModule} from './colors-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' +import {ExploreComponent} from './pages/explore/explore.component' +import {RecipeInfoComponent} from './components/recipe-info/recipe-info.component' +import {MixTableComponent} from './components/mix-table/mix-table.component' +import {StepListComponent} from './components/step-list/step-list.component' +import {StepTableComponent} from './components/step-table/step-table.component' +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' import {MatSortModule} from '@angular/material/sort' @NgModule({ - declarations: [ListComponent, AddComponent, EditComponent, ExploreComponent, RecipeInfoComponent, MixTableComponent, StepListComponent, StepTableComponent, MixEditorComponent, UnitSelectorComponent, MixAddComponent, MixEditComponent, ImagesEditorComponent, MixesCardComponent], - exports: [ - UnitSelectorComponent - ], - imports: [ - ColorsRoutingModule, - SharedModule, - MatExpansionModule, - FormsModule, - MatSortModule - ] + declarations: [ListComponent, AddComponent, EditComponent, ExploreComponent, RecipeInfoComponent, MixTableComponent, StepListComponent, StepTableComponent, MixEditorComponent, UnitSelectorComponent, MixAddComponent, MixEditComponent, ImagesEditorComponent, MixesCardComponent], + exports: [ + UnitSelectorComponent + ], + imports: [ + ColorsRoutingModule, + SharedModule, + MatExpansionModule, + FormsModule, + MatSortModule + ] }) export class ColorsModule { } diff --git a/src/app/modules/shared/components/employee-info/employee-menu.component.html b/src/app/modules/shared/components/employee-info/employee-menu.component.html index ee806f0..4830558 100644 --- a/src/app/modules/shared/components/employee-info/employee-menu.component.html +++ b/src/app/modules/shared/components/employee-info/employee-menu.component.html @@ -22,7 +22,7 @@ @@ -31,14 +31,14 @@ *ngIf="!authenticated && employeeInGroup" mat-list-item class="employee-menu-item-login" - routerLink="/account/login"> + (click)="openLogin()"> Connexion diff --git a/src/app/modules/shared/components/employee-info/employee-menu.component.ts b/src/app/modules/shared/components/employee-info/employee-menu.component.ts index 9224304..70263c3 100644 --- a/src/app/modules/shared/components/employee-info/employee-menu.component.ts +++ b/src/app/modules/shared/components/employee-info/employee-menu.component.ts @@ -1,8 +1,10 @@ -import {Component, OnDestroy, OnInit} from '@angular/core'; -import {AppState} from "../../app-state"; -import {Employee} from "../../model/employee"; -import {Subject} from "rxjs"; -import {takeUntil} from "rxjs/operators"; +import {Component, OnDestroy, OnInit} from '@angular/core' +import {AppState} from '../../app-state' +import {Employee} from '../../model/employee' +import {Subject} from 'rxjs' +import {takeUntil} from 'rxjs/operators' +import {UrlUtils} from '../../utils/url.utils' +import {ActivatedRoute, Router} from '@angular/router' @Component({ selector: 'cre-employee-menu', @@ -16,10 +18,14 @@ export class EmployeeMenuComponent implements OnInit, OnDestroy { menuEnabled = false private destroy$ = new Subject() + private urlUtils: UrlUtils constructor( - public appState: AppState + private appState: AppState, + private router: Router, + private activatedRoute: ActivatedRoute ) { + this.urlUtils = new UrlUtils(activatedRoute, router) } ngOnInit(): void { @@ -36,6 +42,16 @@ export class EmployeeMenuComponent implements OnInit, OnDestroy { this.destroy$.complete() } + openLogin() { + this.urlUtils.navigateTo('/account/login') + this.menuEnabled = false + } + + openLogout() { + this.urlUtils.navigateTo('/account/logout') + this.menuEnabled = false + } + private authenticationState(authenticated: boolean, employee: Employee) { this.authenticated = authenticated this.employee = employee diff --git a/src/app/modules/shared/components/header/header.component.ts b/src/app/modules/shared/components/header/header.component.ts index 04fd7ba..9a27af8 100644 --- a/src/app/modules/shared/components/header/header.component.ts +++ b/src/app/modules/shared/components/header/header.component.ts @@ -15,7 +15,8 @@ export class HeaderComponent extends SubscribingComponent { links: HeaderLink[] = [ {route: '/color', title: 'Couleurs', requiredPermission: EmployeePermission.VIEW_RECIPES}, {route: '/catalog', title: 'Catalogue', requiredPermission: EmployeePermission.VIEW_CATALOG}, - {route: '/admin', title: 'Administration', requiredPermission: EmployeePermission.VIEW_USERS} + {route: '/misc', title: 'Autres', enabled: true}, + {route: '/admin', title: 'Administration', requiredPermission: EmployeePermission.VIEW_USERS}, ] _activeLink = this.links[0].route @@ -46,10 +47,10 @@ export class HeaderComponent extends SubscribingComponent { ) // Auth status - this.updateEnabledLinks(this.appState.authenticatedEmployee) + this.updateEnabledLinks() this.subscribe( this.appState.authenticatedUser$, - authentication => this.updateEnabledLinks(authentication.authenticatedUser) + () => this.updateEnabledLinks() ) } @@ -70,10 +71,14 @@ export class HeaderComponent extends SubscribingComponent { return this._activeLink } - private updateEnabledLinks(employee: Employee) { + private updateEnabledLinks() { this.links.forEach(l => { if (l.requiredPermission) { - l.enabled = employee && employee.permissions.indexOf(l.requiredPermission) >= 0 + l.enabled = this.accountService.hasPermission(l.requiredPermission) + } + + if (l.route === '/misc') { + l.enabled = this.accountService.hasPermission(EmployeePermission.GENERATE_TOUCH_UP_KIT) } }) } diff --git a/src/app/modules/shared/model/employee.ts b/src/app/modules/shared/model/employee.ts index 050c3b7..b0ecdcb 100644 --- a/src/app/modules/shared/model/employee.ts +++ b/src/app/modules/shared/model/employee.ts @@ -25,8 +25,6 @@ export enum EmployeePermission { VIEW_USERS = 'VIEW_USERS', VIEW_CATALOG = 'VIEW_CATALOG', - PRINT_MIXES = 'PRINT_MIXES', - EDIT_RECIPES_PUBLIC_DATA = 'EDIT_RECIPES_PUBLIC_DATA', EDIT_RECIPES = 'EDIT_RECIPES', EDIT_MATERIALS = 'EDIT_MATERIALS', @@ -42,8 +40,10 @@ export enum EmployeePermission { REMOVE_USERS = 'REMOVE_USERS', REMOVE_CATALOG = 'REMOVE_CATALOG', + PRINT_MIXES = 'PRINT_MIXES', ADD_TO_INVENTORY = 'ADD_TO_INVENTORY', DEDUCT_FROM_INVENTORY = 'DEDUCT_FROM_INVENTORY', + GENERATE_TOUCH_UP_KIT = 'GENERATE_TOUCH_UP_KIT', ADMIN = 'ADMIN' } diff --git a/src/app/modules/shared/service/touchupkit.service.ts b/src/app/modules/shared/service/touchupkit.service.ts new file mode 100644 index 0000000..5b6a2d0 --- /dev/null +++ b/src/app/modules/shared/service/touchupkit.service.ts @@ -0,0 +1,11 @@ +import {Injectable} from '@angular/core' +import {environment} from '../../../../environments/environment' + +@Injectable({ + providedIn: 'root' +}) +export class TouchupkitService { + generateJobPdfDocument(job: string) { + window.open(`${environment.apiUrl}/touchup?job=${job}`, '_blank') + } +} diff --git a/src/app/pages/others/misc.component.html b/src/app/pages/others/misc.component.html new file mode 100644 index 0000000..2c65c9d --- /dev/null +++ b/src/app/pages/others/misc.component.html @@ -0,0 +1,2 @@ + + diff --git a/src/app/pages/others/misc.component.sass b/src/app/pages/others/misc.component.sass new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/others/misc.component.ts b/src/app/pages/others/misc.component.ts new file mode 100644 index 0000000..d6f99ea --- /dev/null +++ b/src/app/pages/others/misc.component.ts @@ -0,0 +1,15 @@ +import {Component} from '@angular/core' +import {SubMenuComponent} from '../../modules/shared/components/sub-menu/sub-menu.component' +import {NavLink} from '../../modules/shared/components/nav/nav.component' +import {EmployeePermission} from '../../modules/shared/model/employee' + +@Component({ + selector: 'cre-others', + templateUrl: './misc.component.html', + styleUrls: ['./misc.component.sass'] +}) +export class MiscComponent extends SubMenuComponent{ + links: NavLink[] = [ + {route: '/misc/touchupkit', title: 'Kits de retouche', permission: EmployeePermission.GENERATE_TOUCH_UP_KIT} + ] +}