Commit 61f43153 authored by PECQUOT's avatar PECQUOT

[enh] add unit in sampling-equipment.table.html (not finished)

parent cf1c3a54
/* eslint-disable no-throw-literal */
import {Inject, Injectable} from "@angular/core";
import {BaseEntityService, EntitiesService, EntityUtils, EnvironmentService, GraphqlService, LoadResult, PlatformService, Referential, ReferentialUtils} from "sumaris-lib";
import {BaseEntityService, EntitiesService, EntityUtils, EnvironmentService, GraphqlService, LoadResult, PlatformService, Referential, ReferentialUtils, SuggestService} from "sumaris-lib";
import {ReferentialQueries} from "@app/referential/services/referential.queries";
import gql from "graphql-tag";
import {referentialFragments} from "@app/referential/services/referential.fragments";
......@@ -74,7 +74,7 @@ const loadReferentialTypesQuery: any = gql`
@Injectable({providedIn: 'root'})
export class ReferentialGenericService extends BaseEntityService<Referential>
implements EntitiesService<Referential, ReferentialFilter> {
implements EntitiesService<Referential, ReferentialFilter>, SuggestService<Referential, ReferentialFilter> {
constructor(
protected graphql: GraphqlService,
......@@ -207,6 +207,16 @@ implements EntitiesService<Referential, ReferentialFilter> {
}
async suggest(value: any, filter?: ReferentialFilter, sortBy?: keyof Referential, sortDirection?: SortDirection): Promise<Referential[]> {
if (ReferentialUtils.isNotEmpty(value)) return [value];
value = (typeof value === "string" && value !== '*') && value || undefined;
const res = await this.loadAll(0, !value ? 30 : 10, sortBy, sortDirection,
{ ...filter, searchText: value},
{ withTotal: false /* total not need */ }
);
return res.data;
}
async saveAll(entities: Referential[], options?: any): Promise<Referential[]> {
if (!entities) return entities;
......
......@@ -12,7 +12,6 @@ import {BehaviorSubject} from "rxjs";
import {debounceTime, filter} from "rxjs/operators";
import {CanLeave} from "@app/shared/table/component-dirty.guard";
import {CommentModal} from "@app/shared/comment/comment.modal";
import {ReferentialGenericService} from "@app/referential/services/referential-generic.service";
@Directive()
......
......@@ -217,26 +217,15 @@
</ng-container>
<!-- Unit column -->
<!-- <ng-container matColumnDef="unit">-->
<!-- <th mat-header-cell *matHeaderCellDef [resizableColumn]="true" [resizableColumnDef]="'unit'" resizable>-->
<!-- <span mat-sort-header cdkDrag><ion-label translate>REFERENTIAL.SAMPLING_EQUIPMENT.UNIT</ion-label></span>-->
<!-- </th>-->
<!-- <td mat-cell *matCellDef="let row" [class.mat-form-field-disabled]="!row.editing">-->
<!-- <mat-form-field floatLabel="never">-->
<!-- <ion-icon matPrefix *ngIf="row.validator.controls.unitId.value >= 0" [name]="statusById[row.validator.controls.unitId.value]?.icon"></ion-icon>-->
<!-- <mat-select [formControl]="row.validator.controls.unitId" [placeholder]="'REFERENTIAL.SAMPLING_EQUIPMENT.UNIT'|translate">-->
<!-- <mat-select-trigger>-->
<!-- <span *ngIf="row.validator.controls.unitId.value >= 0">-->
<!-- {{ unitsById[row.validator.controls.unitId.value]?.label | translate}}</span>-->
<!-- </mat-select-trigger>-->
<!-- <mat-option *ngFor="let item of unitsList" [value]="item.id">-->
<!-- <ion-icon [name]="item.icon"></ion-icon>-->
<!-- {{ item.label |translate }}-->
<!-- </mat-option>-->
<!-- </mat-select>-->
<!-- </mat-form-field>-->
<!-- </td>-->
<!-- </ng-container>-->
<ng-container matColumnDef="unit">
<th mat-header-cell *matHeaderCellDef [resizableColumn]="true" [resizableColumnDef]="'unit'" resizable>
<span mat-sort-header cdkDrag><ion-label translate>REFERENTIAL.SAMPLING_EQUIPMENT.UNIT</ion-label></span>
</th>
<td mat-cell *matCellDef="let row" [class.mat-form-field-disabled]="!row.editing">
</td>
</ng-container>
<!-- Comment column -->
<ng-container matColumnDef="comments">
......
......@@ -6,6 +6,7 @@ import {ActivatedRoute} from "@angular/router";
import {SamplingEquipmentService} from "@app/referential/services/sampling-equipment.service";
import {SamplingEquipmentValidator} from "@app/referential/validator/sampling-equipment.validator";
import {CdkDragDrop, moveItemInArray} from "@angular/cdk/drag-drop";
import {ReferentialGenericService} from "@app/referential/services/referential-generic.service";
@Component({
selector: 'app-sampling-equipment-table',
......@@ -17,8 +18,9 @@ export class SamplingEquipmentTable extends ReferentialTable<SamplingEquipment,
constructor(
protected injector: Injector,
protected referentialService: SamplingEquipmentService,
protected samplingEquipmentService: SamplingEquipmentService,
protected validatorService: SamplingEquipmentValidator,
protected referentialService: ReferentialGenericService,
@Inject(EnvironmentService) protected environment
) {
super(injector, injector.get(ActivatedRoute),
......@@ -28,14 +30,14 @@ export class SamplingEquipmentTable extends ReferentialTable<SamplingEquipment,
'name',
'description',
'size',
// 'unit',
'unit',
'comments',
'status',
'creationDate',
'updateDate',
])
.concat(RESERVED_END_COLUMNS),
new EntitiesTableDataSource<SamplingEquipment, SamplingEquipmentFilter>(SamplingEquipment, referentialService, environment, validatorService, {
new EntitiesTableDataSource<SamplingEquipment, SamplingEquipmentFilter>(SamplingEquipment, samplingEquipmentService, environment, validatorService, {
prependNewElements: false,
suppressErrors: environment.production,
dataServiceOptions: {
......@@ -52,6 +54,18 @@ export class SamplingEquipmentTable extends ReferentialTable<SamplingEquipment,
});
}
ngOnInit() {
super.ngOnInit();
// Unit combo
this.registerAutocompleteField('unit', {
service: this.referentialService,
filter: {
entityName: 'Unit'
}
});
}
ngAfterViewInit() {
super.ngAfterViewInit();
......
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