diff --git a/src/main/frontend/src/app/app-routing.module.ts b/src/main/frontend/src/app/app-routing.module.ts
index f647f8f..0f119ac 100644
--- a/src/main/frontend/src/app/app-routing.module.ts
+++ b/src/main/frontend/src/app/app-routing.module.ts
@@ -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',
diff --git a/src/main/frontend/src/app/app.module.ts b/src/main/frontend/src/app/app.module.ts
index 81ec36f..7c914a4 100644
--- a/src/main/frontend/src/app/app.module.ts
+++ b/src/main/frontend/src/app/app.module.ts
@@ -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]
diff --git a/src/main/frontend/src/app/modules/company/company-routing.module.ts b/src/main/frontend/src/app/modules/company/company-routing.module.ts
new file mode 100644
index 0000000..8884872
--- /dev/null
+++ b/src/main/frontend/src/app/modules/company/company-routing.module.ts
@@ -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 {
+}
diff --git a/src/main/frontend/src/app/modules/company/company.module.ts b/src/main/frontend/src/app/modules/company/company.module.ts
new file mode 100644
index 0000000..4d86746
--- /dev/null
+++ b/src/main/frontend/src/app/modules/company/company.module.ts
@@ -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 { }
diff --git a/src/main/frontend/src/app/modules/company/pages/add/add.component.html b/src/main/frontend/src/app/modules/company/pages/add/add.component.html
new file mode 100644
index 0000000..32402ee
--- /dev/null
+++ b/src/main/frontend/src/app/modules/company/pages/add/add.component.html
@@ -0,0 +1,8 @@
+
+
diff --git a/src/main/frontend/src/app/modules/company/pages/add/add.component.sass b/src/main/frontend/src/app/modules/company/pages/add/add.component.sass
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/frontend/src/app/modules/company/pages/add/add.component.ts b/src/main/frontend/src/app/modules/company/pages/add/add.component.ts
new file mode 100644
index 0000000..1566cc5
--- /dev/null
+++ b/src/main/frontend/src/app/modules/company/pages/add/add.component.ts
@@ -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)
+ }
+ }
+ )
+ }
+}
diff --git a/src/main/frontend/src/app/modules/company/pages/edit/edit.component.html b/src/main/frontend/src/app/modules/company/pages/edit/edit.component.html
new file mode 100644
index 0000000..5312c74
--- /dev/null
+++ b/src/main/frontend/src/app/modules/company/pages/edit/edit.component.html
@@ -0,0 +1,13 @@
+
+
diff --git a/src/main/frontend/src/app/modules/company/pages/edit/edit.component.sass b/src/main/frontend/src/app/modules/company/pages/edit/edit.component.sass
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/frontend/src/app/modules/company/pages/edit/edit.component.ts b/src/main/frontend/src/app/modules/company/pages/edit/edit.component.ts
new file mode 100644
index 0000000..2ff244c
--- /dev/null
+++ b/src/main/frontend/src/app/modules/company/pages/edit/edit.component.ts
@@ -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)
+ }
+ }
+ )
+ }
+}
diff --git a/src/main/frontend/src/app/modules/company/pages/list/list.component.html b/src/main/frontend/src/app/modules/company/pages/list/list.component.html
new file mode 100644
index 0000000..54eaea6
--- /dev/null
+++ b/src/main/frontend/src/app/modules/company/pages/list/list.component.html
@@ -0,0 +1,6 @@
+
+
diff --git a/src/main/frontend/src/app/modules/company/pages/list/list.component.sass b/src/main/frontend/src/app/modules/company/pages/list/list.component.sass
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/frontend/src/app/modules/company/pages/list/list.component.ts b/src/main/frontend/src/app/modules/company/pages/list/list.component.ts
new file mode 100644
index 0000000..d77a958
--- /dev/null
+++ b/src/main/frontend/src/app/modules/company/pages/list/list.component.ts
@@ -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()
+ }
+}
diff --git a/src/main/frontend/src/app/modules/company/service/company.service.ts b/src/main/frontend/src/app/modules/company/service/company.service.ts
new file mode 100644
index 0000000..238eaef
--- /dev/null
+++ b/src/main/frontend/src/app/modules/company/service/company.service.ts
@@ -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 {
+ return this.api.get('/company')
+ }
+
+ getById(id: number): Observable {
+ return this.api.get(`/company/${id}`)
+ }
+
+ save(name: string): Observable {
+ return this.api.post('/company', {name})
+ }
+
+ update(id: number, name: string): Observable {
+ return this.api.put('/company', {id, name})
+ }
+
+ delete(id: number): Observable {
+ return this.api.delete(`/company/${id}`)
+ }
+}
diff --git a/src/main/frontend/src/app/modules/employees/pages/add/add.component.ts b/src/main/frontend/src/app/modules/employees/pages/add/add.component.ts
index bb04f4b..dd757b9 100644
--- a/src/main/frontend/src/app/modules/employees/pages/add/add.component.ts
+++ b/src/main/frontend/src/app/modules/employees/pages/add/add.component.ts
@@ -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)]))
diff --git a/src/main/frontend/src/app/modules/shared/model/company.model.ts b/src/main/frontend/src/app/modules/shared/model/company.model.ts
new file mode 100644
index 0000000..ef2f3a2
--- /dev/null
+++ b/src/main/frontend/src/app/modules/shared/model/company.model.ts
@@ -0,0 +1,7 @@
+export class Company {
+ constructor(
+ public id: number,
+ public name: string
+ ) {
+ }
+}
diff --git a/src/main/frontend/src/app/modules/shared/model/employee.ts b/src/main/frontend/src/app/modules/shared/model/employee.ts
index 4da4ecc..121ccd5 100644
--- a/src/main/frontend/src/app/modules/shared/model/employee.ts
+++ b/src/main/frontend/src/app/modules/shared/model/employee.ts
@@ -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,
diff --git a/src/main/frontend/src/app/pages/inventory-page/inventory-page.component.ts b/src/main/frontend/src/app/pages/inventory-page/inventory-page.component.ts
index 5da005a..5769b6f 100644
--- a/src/main/frontend/src/app/pages/inventory-page/inventory-page.component.ts
+++ b/src/main/frontend/src/app/pages/inventory-page/inventory-page.component.ts
@@ -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}
]
}