Ajout du support pour les bannières dans le frontend Angular.
This commit is contained in:
parent
4b5dec39d8
commit
19f77d1b5b
|
@ -27,6 +27,10 @@ const routes: Routes = [{
|
|||
path: 'material',
|
||||
loadChildren: () => import('./modules/material/material.module').then(m => m.MaterialModule)
|
||||
},
|
||||
{
|
||||
path: 'company',
|
||||
loadChildren: () => import('./modules/company/company.module').then(m => m.CompanyModule)
|
||||
},
|
||||
{
|
||||
path: '',
|
||||
pathMatch: 'full',
|
||||
|
|
|
@ -7,6 +7,7 @@ import {MatIconRegistry} from "@angular/material/icon";
|
|||
import {SharedModule} from "./modules/shared/shared.module";
|
||||
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
|
||||
import { InventoryPageComponent } from './pages/inventory-page/inventory-page.component';
|
||||
import { CompanyModule } from './modules/company/company.module';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
@ -16,7 +17,8 @@ import { InventoryPageComponent } from './pages/inventory-page/inventory-page.co
|
|||
imports: [
|
||||
AppRoutingModule,
|
||||
SharedModule,
|
||||
BrowserAnimationsModule
|
||||
BrowserAnimationsModule,
|
||||
CompanyModule
|
||||
],
|
||||
providers: [],
|
||||
bootstrap: [AppComponent]
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import {RouterModule, Routes} from "@angular/router";
|
||||
import {ListComponent} from "./pages/list/list.component";
|
||||
import {NgModule} from "@angular/core";
|
||||
import {AddComponent} from "./pages/add/add.component";
|
||||
import {EditComponent} from "./pages/edit/edit.component";
|
||||
|
||||
const routes: Routes = [{
|
||||
path: 'list',
|
||||
component: ListComponent
|
||||
}, {
|
||||
path: 'add',
|
||||
component: AddComponent
|
||||
}, {
|
||||
path: 'edit/:id',
|
||||
component: EditComponent
|
||||
}, {
|
||||
path: '',
|
||||
pathMatch: 'full',
|
||||
redirectTo: 'list'
|
||||
}]
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class CompanyRoutingModule {
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ListComponent } from './pages/list/list.component';
|
||||
import { AddComponent } from './pages/add/add.component';
|
||||
import { EditComponent } from './pages/edit/edit.component';
|
||||
import {CompanyRoutingModule} from "./company-routing.module";
|
||||
import {SharedModule} from "../shared/shared.module";
|
||||
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [ListComponent, AddComponent, EditComponent],
|
||||
imports: [
|
||||
CommonModule,
|
||||
CompanyRoutingModule,
|
||||
SharedModule
|
||||
]
|
||||
})
|
||||
export class CompanyModule { }
|
|
@ -0,0 +1,8 @@
|
|||
<cre-entity-add
|
||||
title="Création d'une bannière"
|
||||
backButtonLink="/inventory/company/list"
|
||||
[unknownError]="unknownError"
|
||||
[customError]="errorMessage"
|
||||
[formFields]="formFields"
|
||||
(submit)="submit($event)">
|
||||
</cre-entity-add>
|
|
@ -0,0 +1,52 @@
|
|||
import {Component} from '@angular/core';
|
||||
import {CompanyService} from "../../service/company.service";
|
||||
import {Validators} from "@angular/forms";
|
||||
import {SubscribingComponent} from "../../../shared/components/subscribing.component";
|
||||
import {FormField} from "../../../shared/components/entity-add/entity-add.component";
|
||||
import {Router} from "@angular/router";
|
||||
|
||||
@Component({
|
||||
selector: 'cre-add',
|
||||
templateUrl: './add.component.html',
|
||||
styleUrls: ['./add.component.sass']
|
||||
})
|
||||
export class AddComponent extends SubscribingComponent {
|
||||
formFields: FormField[] = [
|
||||
{
|
||||
name: 'name',
|
||||
label: 'Nom',
|
||||
icon: 'form-textbox',
|
||||
type: 'text',
|
||||
validator: Validators.required,
|
||||
errorMessages: [
|
||||
{conditionFn: errors => errors.required, message: 'Un nom est requis'}
|
||||
]
|
||||
}
|
||||
]
|
||||
unknownError = false
|
||||
errorMessage: string | null
|
||||
|
||||
constructor(
|
||||
private companyService: CompanyService,
|
||||
private router: Router
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
submit(values) {
|
||||
this.subscribe(
|
||||
this.companyService.save(values.name),
|
||||
{
|
||||
next: () => this.router.navigate(['/inventory/company/list']),
|
||||
error: err => {
|
||||
if (err.status == 409) {
|
||||
this.errorMessage = `Une bannière avec le nom '${values.name}' existe déjà`
|
||||
} else {
|
||||
this.unknownError = true
|
||||
}
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<cre-entity-edit
|
||||
*ngIf="company"
|
||||
title="Modifier la bannière {{company.name}}"
|
||||
deleteConfirmMessage="Voulez-vous vraiment supprimer la bannière {{company.name}}?"
|
||||
backButtonLink="/inventory/company/list"
|
||||
deletePermission="REMOVE_COMPANY"
|
||||
[entity]="company"
|
||||
[formFields]="formFields"
|
||||
[unknownError]="unknownError"
|
||||
[customError]="errorMessage"
|
||||
(submit)="submit($event)"
|
||||
(delete)="delete()">
|
||||
</cre-entity-edit>
|
|
@ -0,0 +1,88 @@
|
|||
import {Component} from '@angular/core';
|
||||
import {SubscribingComponent} from "../../../shared/components/subscribing.component";
|
||||
import {Company} from "../../../shared/model/company.model";
|
||||
import {FormField} from "../../../shared/components/entity-add/entity-add.component";
|
||||
import {Validators} from "@angular/forms";
|
||||
import {CompanyService} from "../../service/company.service";
|
||||
import {ActivatedRoute, Router} from "@angular/router";
|
||||
|
||||
@Component({
|
||||
selector: 'cre-edit',
|
||||
templateUrl: './edit.component.html',
|
||||
styleUrls: ['./edit.component.sass']
|
||||
})
|
||||
export class EditComponent extends SubscribingComponent {
|
||||
company: Company | null
|
||||
formFields: FormField[] = [
|
||||
{
|
||||
name: 'name',
|
||||
label: 'Nom',
|
||||
icon: 'form-textbox',
|
||||
type: 'text',
|
||||
validator: Validators.required,
|
||||
errorMessages: [
|
||||
{conditionFn: errors => errors.required, message: 'Un nom est requis'}
|
||||
]
|
||||
}
|
||||
]
|
||||
unknownError = false
|
||||
errorMessage: string | null
|
||||
|
||||
constructor(
|
||||
private companyService: CompanyService,
|
||||
private router: Router,
|
||||
private activatedRoute: ActivatedRoute
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit()
|
||||
|
||||
const id = parseInt(this.activatedRoute.snapshot.paramMap.get('id'))
|
||||
this.subscribe(
|
||||
this.companyService.getById(id),
|
||||
{
|
||||
next: company => this.company = company,
|
||||
error: err => {
|
||||
if (err.status == 404) {
|
||||
this.router.navigate(['/inventory/company/list'])
|
||||
} else {
|
||||
this.unknownError = true
|
||||
}
|
||||
}
|
||||
},
|
||||
1
|
||||
)
|
||||
}
|
||||
|
||||
submit(values) {
|
||||
this.subscribe(
|
||||
this.companyService.update(this.company.id, values.name),
|
||||
{
|
||||
next: () => this.router.navigate(['/inventory/company/list']),
|
||||
error: err => {
|
||||
if (err.status == 409) {
|
||||
this.errorMessage = `Une bannière avec le nom '${values.name}' existe déjà`
|
||||
} else {
|
||||
this.unknownError = true
|
||||
}
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.subscribe(
|
||||
this.companyService.delete(this.company.id),
|
||||
{
|
||||
next: () => this.router.navigate(['/inventory/company/list']),
|
||||
error: err => {
|
||||
this.unknownError = true
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<cre-entity-list
|
||||
[entities$]="companies$"
|
||||
[columns]="columns"
|
||||
[buttons]="buttons"
|
||||
addLink="/inventory/company/add">
|
||||
</cre-entity-list>
|
|
@ -0,0 +1,27 @@
|
|||
import {Component} from '@angular/core';
|
||||
import {SubscribingComponent} from "../../../shared/components/subscribing.component";
|
||||
import {CompanyService} from "../../service/company.service";
|
||||
import {EmployeePermission} from "../../../shared/model/employee";
|
||||
|
||||
@Component({
|
||||
selector: 'cre-list',
|
||||
templateUrl: './list.component.html',
|
||||
styleUrls: ['./list.component.sass']
|
||||
})
|
||||
export class ListComponent extends SubscribingComponent {
|
||||
companies$ = this.companyService.all
|
||||
columns = [
|
||||
{def: 'name', title: 'Nom', valueFn: c => c.name}
|
||||
]
|
||||
buttons = [{
|
||||
text: 'Modifier',
|
||||
linkFn: t => `/inventory/company/edit/${t.id}`,
|
||||
permission: EmployeePermission.EDIT_COMPANY
|
||||
}]
|
||||
|
||||
constructor(
|
||||
private companyService: CompanyService
|
||||
) {
|
||||
super()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {ApiService} from "../../shared/service/api.service";
|
||||
import {Observable} from "rxjs";
|
||||
import {Company} from "../../shared/model/company.model";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CompanyService {
|
||||
constructor(
|
||||
private api: ApiService
|
||||
) {
|
||||
}
|
||||
|
||||
get all(): Observable<Company[]> {
|
||||
return this.api.get<Company[]>('/company')
|
||||
}
|
||||
|
||||
getById(id: number): Observable<Company> {
|
||||
return this.api.get<Company>(`/company/${id}`)
|
||||
}
|
||||
|
||||
save(name: string): Observable<void> {
|
||||
return this.api.post<void>('/company', {name})
|
||||
}
|
||||
|
||||
update(id: number, name: string): Observable<void> {
|
||||
return this.api.put<void>('/company', {id, name})
|
||||
}
|
||||
|
||||
delete(id: number): Observable<void> {
|
||||
return this.api.delete<void>(`/company/${id}`)
|
||||
}
|
||||
}
|
|
@ -36,6 +36,8 @@ export class AddComponent extends SubscribingComponent {
|
|||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit()
|
||||
|
||||
this.group$ = this.groupService.all
|
||||
|
||||
this.idControl = new FormControl(null, Validators.compose([Validators.required, Validators.pattern(new RegExp('^[0-9]+$')), Validators.min(0)]))
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
export class Company {
|
||||
constructor(
|
||||
public id: number,
|
||||
public name: string
|
||||
) {
|
||||
}
|
||||
}
|
|
@ -23,12 +23,14 @@ export class EmployeeGroup {
|
|||
export enum EmployeePermission {
|
||||
VIEW_MATERIAL = 'VIEW_MATERIAL',
|
||||
VIEW_MATERIAL_TYPE = 'VIEW_MATERIAL_TYPE',
|
||||
VIEW_COMPANY = 'VIEW_COMPANY',
|
||||
VIEW = 'VIEW',
|
||||
VIEW_EMPLOYEE = 'VIEW_EMPLOYEE',
|
||||
VIEW_EMPLOYEE_GROUP = 'VIEW_EMPLOYEE_GROUP',
|
||||
|
||||
EDIT_MATERIAL = 'EDIT_MATERIAL',
|
||||
EDIT_MATERIAL_TYPE = 'EDIT_MATERIAL_TYPE',
|
||||
EDIT_COMPANY = 'EDIT_COMPANY',
|
||||
EDIT = 'EDIT',
|
||||
EDIT_EMPLOYEE = 'EDIT_EMPLOYEE',
|
||||
EDIT_EMPLOYEE_PASSWORD = 'EDIT_EMPLOYEE_PASSWORD',
|
||||
|
@ -36,6 +38,7 @@ export enum EmployeePermission {
|
|||
|
||||
REMOVE_MATERIAL = 'REMOVE_MATERIAL',
|
||||
REMOVE_MATERIAL_TYPE = 'REMOVE_MATERIAL_TYPE',
|
||||
REMOVE_COMPANY = 'REMOVE_COMPANY',
|
||||
REMOVE = 'REMOVE',
|
||||
REMOVE_EMPLOYEE = 'REMOVE_EMPLOYEE',
|
||||
REMOVE_EMPLOYEE_GROUP = 'REMOVE_EMPLOYEE_GROUP',
|
||||
|
@ -52,10 +55,11 @@ export const mapped_permissions = {
|
|||
description: 'Voir les types de produit',
|
||||
impliedPermissions: []
|
||||
},
|
||||
{permission: EmployeePermission.VIEW_COMPANY, description: 'Voir les bannières', impliedPermissions: []},
|
||||
{
|
||||
permission: EmployeePermission.VIEW,
|
||||
description: 'Voir',
|
||||
impliedPermissions: [EmployeePermission.VIEW_MATERIAL, EmployeePermission.VIEW_MATERIAL_TYPE]
|
||||
impliedPermissions: [EmployeePermission.VIEW_MATERIAL, EmployeePermission.VIEW_MATERIAL_TYPE, EmployeePermission.VIEW_COMPANY]
|
||||
},
|
||||
{permission: EmployeePermission.VIEW_EMPLOYEE, description: 'Voir les employés', impliedPermissions: []},
|
||||
{permission: EmployeePermission.VIEW_EMPLOYEE_GROUP, description: 'Voir les groupes', impliedPermissions: []},
|
||||
|
@ -71,10 +75,15 @@ export const mapped_permissions = {
|
|||
description: 'Modifier les types de produit',
|
||||
impliedPermissions: [EmployeePermission.VIEW_MATERIAL_TYPE]
|
||||
},
|
||||
{
|
||||
permission: EmployeePermission.EDIT_COMPANY,
|
||||
description: 'Modifier les bannières',
|
||||
impliedPermissions: [EmployeePermission.VIEW_COMPANY]
|
||||
},
|
||||
{
|
||||
permission: EmployeePermission.EDIT,
|
||||
description: 'Modifier',
|
||||
impliedPermissions: [EmployeePermission.EDIT_MATERIAL, EmployeePermission.EDIT_MATERIAL_TYPE, EmployeePermission.VIEW]
|
||||
impliedPermissions: [EmployeePermission.EDIT_MATERIAL, EmployeePermission.EDIT_MATERIAL_TYPE, EmployeePermission.EDIT_COMPANY, EmployeePermission.VIEW]
|
||||
},
|
||||
{
|
||||
permission: EmployeePermission.EDIT_EMPLOYEE,
|
||||
|
@ -103,10 +112,15 @@ export const mapped_permissions = {
|
|||
description: 'Supprimer des types de produit',
|
||||
impliedPermissions: [EmployeePermission.EDIT_MATERIAL_TYPE]
|
||||
},
|
||||
{
|
||||
permission: EmployeePermission.REMOVE_COMPANY,
|
||||
description: 'Supprimer des bannières',
|
||||
impliedPermissions: [EmployeePermission.EDIT_COMPANY]
|
||||
},
|
||||
{
|
||||
permission: EmployeePermission.REMOVE,
|
||||
description: 'Supprimer',
|
||||
impliedPermissions: [EmployeePermission.REMOVE_MATERIAL, EmployeePermission.REMOVE_MATERIAL_TYPE, EmployeePermission.EDIT]
|
||||
impliedPermissions: [EmployeePermission.REMOVE_MATERIAL, EmployeePermission.REMOVE_MATERIAL_TYPE, EmployeePermission.REMOVE_COMPANY, EmployeePermission.EDIT]
|
||||
},
|
||||
{
|
||||
permission: EmployeePermission.REMOVE_EMPLOYEE,
|
||||
|
|
|
@ -10,6 +10,7 @@ import {EmployeePermission} from "../../modules/shared/model/employee";
|
|||
export class InventoryPageComponent {
|
||||
links: NavLink[] = [
|
||||
{route: '/inventory/materialtype', title: 'Types de produit', permission: EmployeePermission.VIEW_MATERIAL_TYPE},
|
||||
{route: '/inventory/material', title: 'Produits', permission: EmployeePermission.VIEW_MATERIAL}
|
||||
{route: '/inventory/material', title: 'Produits', permission: EmployeePermission.VIEW_MATERIAL},
|
||||
{route: '/inventory/company', title: 'Bannières', permission: EmployeePermission.VIEW_COMPANY}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue