Commit b28eda9a authored by PECQUOT's avatar PECQUOT

[enh] sampling equipments as a module

parent 5867a5d6
......@@ -36,7 +36,7 @@
<mat-table [dataSource]="dataSource" matSort matSortActive="id" matSortDirection="asc"
matSortDisableClear [trackBy]="trackByFn" [resizable]="resizable">
matSortDisableClear [trackBy]="trackByFn" >
<ng-container matColumnDef="select">
<mat-header-cell class="hidden-xs hidden-sm" *matHeaderCellDef>
......@@ -62,7 +62,7 @@
<!-- Label column -->
<ng-container matColumnDef="label">
<mat-header-cell *matHeaderCellDef mat-sort-header [resizableColumn]="true" [resizableColumnDef]="'label'" >
<mat-header-cell *matHeaderCellDef mat-sort-header >
<span translate>REFERENTIAL.LABEL</span>
</mat-header-cell>
<mat-cell *matCellDef="let row">
......@@ -76,7 +76,7 @@
<!-- Name column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef [resizableColumn]="true" [resizableColumnDef]="'name'">
<mat-header-cell *matHeaderCellDef >
<span translate>REFERENTIAL.NAME</span>
</mat-header-cell>
<mat-cell *matCellDef="let row" [class.mat-form-field-disabled]="!row.editing">
......
......@@ -5,7 +5,6 @@ import {SharedRoutingModule} from "sumaris-lib";
import {ReferentialMenu} from "@app/referential/menu/referential.menu";
import {ReferentialGenericTable} from "@app/referential/table/referential.generic.table";
import {ComponentDirtyGuard} from "@app/shared/table/component-dirty.guard";
import {SamplingEquipmentTable} from "@app/referential/table/sampling-equipment.table";
const routes: Routes = [
{
......@@ -17,8 +16,9 @@ const routes: Routes = [
children: [
{
path: 'SamplingEquipment',
component: SamplingEquipmentTable,
canDeactivate: [ComponentDirtyGuard],
// component: SamplingEquipmentTable,
// canDeactivate: [ComponentDirtyGuard],
loadChildren: () => import('./sampling-equipment/sampling-equipment.module').then(m => m.SamplingEquipmentModule)
},
{
path: ':entity',
......
......@@ -9,8 +9,6 @@ import {QuadrigeCoreModule} from "../core/quadrige.core.module";
import {QuadrigeSharedModule} from "../shared/quadrige.shared.module";
import {ReferentialMenu} from "@app/referential/menu/referential.menu";
import {ReferentialGenericTable} from "@app/referential/table/referential.generic.table";
import {SamplingEquipmentTable} from "@app/referential/table/sampling-equipment.table";
@NgModule({
imports: [
......@@ -28,7 +26,6 @@ import {SamplingEquipmentTable} from "@app/referential/table/sampling-equipment.
ReferentialForm,
ReferentialMemoryTable,
ReferentialGenericTable,
SamplingEquipmentTable
],
exports: [
QuadrigeCoreModule,
......
import {NgModule} from "@angular/core";
import {TranslateModule} from "@ngx-translate/core";
import {RouterModule, Routes} from "@angular/router";
import {SamplingEquipmentTable} from "@app/referential/sampling-equipment/sampling-equipment.table";
import {ComponentDirtyGuard} from "@app/shared/table/component-dirty.guard";
import {QuadrigeSharedModule} from "@app/shared/quadrige.shared.module";
import {QuadrigeCoreModule} from "@app/core/quadrige.core.module";
const routes: Routes = [
{
path: '',
pathMatch: 'full',
component: SamplingEquipmentTable,
// canActivate: [AuthGuardService], useful ?
canDeactivate: [ComponentDirtyGuard],
data: {
profile: 'ADMIN'
}
}
];
@NgModule({
imports: [
QuadrigeCoreModule,
TranslateModule,
RouterModule.forChild(routes)
],
declarations: [
SamplingEquipmentTable
],
exports: [
SamplingEquipmentTable
]
})
export class SamplingEquipmentModule { }
......@@ -4,8 +4,24 @@ import {BaseReferentialService} from "@app/referential/services/base-referential
import gql from "graphql-tag";
import {referentialFragments} from "@app/referential/services/referential.fragments";
import {ReferentialQueries} from "@app/referential/services/referential.queries";
import {SamplingEquipment, SamplingEquipmentFilter} from "@app/referential/model/sampling-equipment.model";
import {SamplingEquipment, SamplingEquipmentFilter} from "@app/referential/sampling-equipment/sampling-equipment.model";
const fragments = {
samplingEquipment: gql`fragment SamplingEquipmentFragment on SamplingEquipmentVO {
id
name
description
comments
size
unit {
...ReferentialFragment
}
updateDate
creationDate
statusId
__typename
}`
};
const queries: ReferentialQueries = {
......@@ -16,7 +32,7 @@ const queries: ReferentialQueries = {
...SamplingEquipmentFragment
}
}
${referentialFragments.samplingEquipment}
${fragments.samplingEquipment}
${referentialFragments.referential}
`;
},
......@@ -29,7 +45,7 @@ const queries: ReferentialQueries = {
}
count:samplingEquipmentsCount(filter: $filter)
}
${referentialFragments.samplingEquipment}
${fragments.samplingEquipment}
${referentialFragments.referential}
`;
},
......@@ -41,7 +57,7 @@ const queries: ReferentialQueries = {
...SamplingEquipmentFragment
}
}
${referentialFragments.samplingEquipment}
${fragments.samplingEquipment}
${referentialFragments.referential}
`;
},
......
<app-toolbar [title]="title$|async|translate" color="primary">
<app-toolbar [title]="'REFERENTIAL.ENTITY.SAMPLING_EQUIPMENT'|translate" color="primary">
</app-toolbar>
<ion-content class="ion-no-padding">
......
import {ChangeDetectionStrategy, Component, Inject, Injector} from "@angular/core";
import {EntitiesTableDataSource, EnvironmentService, RESERVED_END_COLUMNS, RESERVED_START_COLUMNS} from "sumaris-lib";
import {ReferentialTable} from "@app/referential/table/referential.table";
import {SamplingEquipment, SamplingEquipmentFilter} from "@app/referential/model/sampling-equipment.model";
import {SamplingEquipment, SamplingEquipmentFilter} from "@app/referential/sampling-equipment/sampling-equipment.model";
import {ActivatedRoute} from "@angular/router";
import {SamplingEquipmentService} from "@app/referential/services/sampling-equipment.service";
import {SamplingEquipmentValidator} from "@app/referential/validator/sampling-equipment.validator";
import {SamplingEquipmentService} from "@app/referential/sampling-equipment/sampling-equipment.service";
import {SamplingEquipmentValidator} from "@app/referential/sampling-equipment/sampling-equipment.validator";
import {CdkDragDrop, moveItemInArray} from "@angular/cdk/drag-drop";
import {ReferentialGenericService} from "@app/referential/services/referential-generic.service";
......
import {Injectable} from "@angular/core";
import {AbstractControlOptions, FormBuilder, FormGroup, Validators} from "@angular/forms";
import {AppValidatorService, Referential, SharedValidators, toNumber} from "sumaris-lib";
import {SamplingEquipment} from "@app/referential/model/sampling-equipment.model";
import {AppValidatorService, SharedValidators, toNumber} from "sumaris-lib";
import {SamplingEquipment} from "@app/referential/sampling-equipment/sampling-equipment.model";
@Injectable({providedIn: 'root'})
export class SamplingEquipmentValidator
......
......@@ -43,19 +43,5 @@ export const referentialFragments = {
__typename
}
__typename
}`,
samplingEquipment: gql`fragment SamplingEquipmentFragment on SamplingEquipmentVO {
id
name
description
comments
size
unit {
...ReferentialFragment
}
updateDate
creationDate
statusId
__typename
}`
};
......@@ -119,7 +119,7 @@
<ion-label color="danger" class="error" [innerHTML]="error|translate"></ion-label>
</ion-item>
<mat-table #table [dataSource]="dataSource" class="trips-table" matSort matSortActive="id" matSortDirection="asc" [resizable]="true"
<mat-table #table [dataSource]="dataSource" class="trips-table" matSort matSortActive="id" matSortDirection="asc"
matSortDisableClear [trackBy]="trackByFn">
<ng-container matColumnDef="select">
......@@ -136,7 +136,7 @@
<!-- Id/code column -->
<ng-container matColumnDef="id">
<mat-header-cell class="hidden-xs hidden-sm" *matHeaderCellDef mat-sort-header [resizableColumn]="true" [resizableColumnDef]="'id'">
<mat-header-cell class="hidden-xs hidden-sm" *matHeaderCellDef mat-sort-header>
<app-loading-spinner [loading]="loadingSubject|async">
<ion-label translate>{{idLabel$|async}}</ion-label>
</app-loading-spinner>
......@@ -156,7 +156,7 @@
<!-- Name column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header [resizableColumn]="true" [resizableColumnDef]="'name'">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<span translate>REFERENTIAL.NAME</span>
</mat-header-cell>
<mat-cell *matCellDef="let row" [class.mat-form-field-disabled]="!row.editing">
......@@ -171,7 +171,7 @@
<!-- Label column -->
<ng-container matColumnDef="label">
<mat-header-cell *matHeaderCellDef mat-sort-header [resizableColumn]="true" [resizableColumnDef]="'label'">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<span translate>REFERENTIAL.LABEL</span>
</mat-header-cell>
<mat-cell *matCellDef="let row">
......@@ -185,7 +185,7 @@
<!-- Description column -->
<ng-container matColumnDef="description">
<mat-header-cell *matHeaderCellDef mat-sort-header [resizableColumn]="true" [resizableColumnDef]="'description'">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<span translate>REFERENTIAL.DESCRIPTION</span>
</mat-header-cell>
<mat-cell *matCellDef="let row">
......@@ -199,7 +199,7 @@
<!-- Comment column -->
<ng-container matColumnDef="comments">
<mat-header-cell *matHeaderCellDef class="hidden-xs hidden-sm" [resizableColumn]="false" [resizableColumnDef]="'comment'">
<mat-header-cell *matHeaderCellDef class="hidden-xs hidden-sm">
<span translate>REFERENTIAL.COMMENTS</span>
</mat-header-cell>
<mat-cell *matCellDef="let row" class="hidden-xs hidden-sm" >
......@@ -213,7 +213,7 @@
<!-- Status column -->
<ng-container matColumnDef="status">
<mat-header-cell *matHeaderCellDef mat-sort-header [resizableColumn]="false" [resizableColumnDef]="'status'">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<span translate>REFERENTIAL.STATUS</span>
</mat-header-cell>
<mat-cell *matCellDef="let row" [class.mat-form-field-disabled]="!row.editing">
......
......@@ -89,6 +89,10 @@ export abstract class ReferentialTable<E extends Referential<E> = Referential,
return this.save();
}
doCancel() {
this.onRefresh.emit();
}
save(): Promise<boolean> {
return super.save();
}
......
......@@ -10,12 +10,14 @@ export interface CanLeave {
isValid(): boolean;
doSave(): Promise<boolean>;
doCancel();
}
@Injectable()
export class ComponentDirtyGuard implements CanDeactivate<CanLeave> {
private debug = true;
private debug = false;
constructor(
protected translate: TranslateService,
......@@ -110,6 +112,9 @@ export class ComponentDirtyGuard implements CanDeactivate<CanLeave> {
if (this.debug) console.info(`[ReferentialGuard] save failed, cancel deactivate`);
return false;
}
} else {
if (this.debug) console.info(`[ReferentialGuard] do cancel`);
component.doCancel();
}
// Allow deactivate
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment