Skip to content

Commit

Permalink
use sitesgroups and sites components
Browse files Browse the repository at this point in the history
  • Loading branch information
bastyen committed Dec 13, 2024
1 parent a5ea6c7 commit bc0af3d
Show file tree
Hide file tree
Showing 22 changed files with 430 additions and 168 deletions.
1 change: 1 addition & 0 deletions frontend/app/class/monitoring-object-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ export class MonitoringObjectBase {
}

navigateToDetail(id = null, toEdit = false) {
// monitorings/object/mak_oiseaux/sites_group
this._objService.navigate('object', this.moduleCode, this.objectType, id || this.id, {
parents_path: this.parentsPath,
edit: toEdit,
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/modules/modules.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h3>Liste des protocoles</h3>
style="min-width: 250px; max-width: 250px"
*ngFor="let module of modules"
>
<a [routerLink]="['object', module.module_code, 'module', module.id_module]">
<a [routerLink]="['object', module.module_code, 'sites_group']">
<div class="card module-card" title="code&nbsp;: {{ module.module_code }}">
<img
class="card-img-top"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,10 @@ export class MonitoringDatatableGComponent implements OnInit {
this.activetabIndex = tab.index;
// Réinitialisation des données selectés
this.activetabType = this.dataTableArray[tab.index].objectType;
this.dataTableObj[this.activetabType].rows.length > 0
? (this.columns = this._dataTableService.colsTable(
this.dataTableObj[this.activetabType].columns,
this.dataTableObj[this.activetabType].rows[0]
))
this.columns = this.dataTableObj[this.activetabType].rows.length > 0 ?
this._dataTableService.colsTable(this.dataTableObj[this.activetabType].columns)
: null;

this.rows = this.dataTableObj[this.activetabType].rows;
this.page = this.dataTableObj[this.activetabType].page;
this.objectsStatusChange.emit(this.reInitStatut());
Expand Down Expand Up @@ -326,9 +324,8 @@ export class MonitoringDatatableGComponent implements OnInit {

this.activetabType = this.dataTableArray[this.activetabIndex].objectType;
const dataTable = this.dataTableObj[this.activetabType];
if (dataTable.rows.length > 0) {
this.columns = this._dataTableService.colsTable(dataTable.columns, dataTable.rows[0]);
}
this.columns = dataTable.rows.length > 0 ? this._dataTableService.colsTable(dataTable.columns) : null;

this.rows = dataTable.rows;
this.page = dataTable.page;
this.initPermissionAction();
Expand All @@ -339,6 +336,7 @@ export class MonitoringDatatableGComponent implements OnInit {
if (this.rows && this.rows.length > 0) {
this.activetabType = this.dataTableArray[this.activetabIndex].objectType;
const dataTable = this.dataTableObj[this.activetabType];

this.rows = dataTable.rows;
this.page = dataTable.page;
this.initPermissionAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
</pnx-map>
</div>
<div id="monitoring-elem-container" class="cadre scroll">
<pnx-monitoring-breadcrumbs></pnx-monitoring-breadcrumbs>
<div *ngIf="moduleCode !== 'generic'; else staticBreadcrumb">
<pnx-monitoring-breadcrumbs *ngIf="obj && obj.bIsInitialized" [obj]="obj"
[(bEdit)]="bEdit">
</pnx-monitoring-breadcrumbs>
</div>

<ng-template #staticBreadcrumb>
<pnx-monitoring-breadcrumbs></pnx-monitoring-breadcrumbs>
</ng-template>

<!-- <button (click)="displayMap = !displayMap">HIDE MAP</button> -->
<router-outlet (activate)="onActivate($event)"></router-outlet>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ConfigJsonService } from '../../services/config-json.service';
import { ObjectService } from '../../services/object.service';
import { CommonService } from '@geonature_common/service/common.service';
import { FormGroup } from '@angular/forms';
import { Router, NavigationStart, ActivatedRoute } from '@angular/router';

@Component({
selector: 'monitoring-map-list.component',
Expand All @@ -23,12 +24,19 @@ export class MonitoringMapListComponent {
displayMap: boolean = true;
siteSiteGroup: SiteSiteGroup | null = null;
apiService: ApiGeomService;

moduleCode: string;

constructor(
private _formService: FormService,
private _commonService: CommonService
private _commonService: CommonService,
private _router: Router,
private _Activatedroute: ActivatedRoute,
) {}

ngOnInit() {
this.moduleCode = this._Activatedroute.snapshot.params.moduleCode;
}

ngAfterViewInit() {
const container = document.getElementById('object');
const height = this._commonService.calcCardContentHeight();
Expand All @@ -38,7 +46,16 @@ export class MonitoringMapListComponent {
});
}

onActivate(component) {
onActivate() {
this._router.events.subscribe((route) => {
if (route instanceof NavigationStart) {
this._formService.changeFormMapObj({
frmGp: null,
bEdit: false,
obj: null,
});
}
});
this._formService.currentFormMap
.pipe(distinctUntilChanged((prev, curr) => prev.obj === curr.obj))
.subscribe((formMapObj) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { Observable, of } from 'rxjs';
import { mergeMap, concatMap, tap } from 'rxjs/operators';

import { endPoints } from '../../enum/endpoints';
import { ISite, ISiteType } from '../../interfaces/geom';
import { IobjObs, ObjDataType, SiteSiteGroup } from '../../interfaces/objObs';
import { ISite, ISitesGroup, ISiteType } from '../../interfaces/geom';
import { IobjObs, ObjDataType } from '../../interfaces/objObs';
import { SitesGroupService, SitesService } from '../../services/api-geom.service';
import { FormService } from '../../services/form.service';
import { ObjectService } from '../../services/object.service';
import { JsonData } from '../../types/jsondata';
import { IPaginated } from '../../interfaces/page';
import { IBreadCrumb } from '../../interfaces/object';
import { breadCrumbElementBase } from '../breadcrumbs/breadcrumbs.component';
import { breadCrumbBase } from '../../class/breadCrumb';
import { GeoJSONService } from '../../services/geojson.service';
import { AuthService, User } from '@geonature/components/auth/auth.service';

Expand All @@ -40,12 +40,14 @@ export class MonitoringSitesCreateComponent implements OnInit {
urlRelative: string;

breadCrumbList: IBreadCrumb[] = [];
breadCrumbElemnt: IBreadCrumb = { label: 'Groupe de site', description: '' };
breadCrumbElementBase: IBreadCrumb = breadCrumbElementBase;
breadCrumbElementBase: IBreadCrumb = breadCrumbBase.baseBreadCrumbSites.value;

obj: MonitoringObject;
bEdit: boolean = true;
currentUser: User;
moduleCode: string;
sitesGroup: ISitesGroup;

constructor(
private _auth: AuthService,
private _formService: FormService,
Expand All @@ -60,15 +62,16 @@ export class MonitoringSitesCreateComponent implements OnInit {
) {}

ngOnInit() {
const idSitesGroup = this._route.snapshot.data.createSite.id_sites_group;
this.moduleCode = this._route.snapshot.data.createSite.moduleCode;
this.bEdit = true;
this.objForm = this._formBuilder.group({});

const elements = document.getElementsByClassName('monitoring-map-container');
if (elements.length >= 1) {
elements[0].remove();
}

this.obj = new MonitoringObject('generic', 'site', null, this._monitoringObjServiceMonitoring);
this.obj = new MonitoringObject(this.moduleCode, 'site', null, this._monitoringObjServiceMonitoring);
this.currentUser = this._auth.getCurrentUser();

this._route.paramMap
Expand All @@ -78,15 +81,20 @@ export class MonitoringSitesCreateComponent implements OnInit {
}),
mergeMap(() => {
return this.obj.get(0);
})
}),
mergeMap(() => {
return this._sitesGroupService.getById(idSitesGroup);
}),
)
.subscribe((params) => {
.subscribe((sitesGroup) => {
this.sitesGroup = sitesGroup;
this.obj.initTemplate();
this._formService.changeFormMapObj({
frmGp: this.objForm,
bEdit: true,
obj: this.obj,
});
this.updateBreadCrumb();
this.obj.bIsInitialized = true;
});
}
Expand All @@ -96,7 +104,7 @@ export class MonitoringSitesCreateComponent implements OnInit {
}

initConfig(): Observable<any> {
return this._configService.init().pipe(
return this._configService.init(this.moduleCode).pipe(
concatMap(() => {
if (this.obj.objectType == 'site' && this.obj.id != null) {
return this._monitoringObjServiceMonitoring
Expand All @@ -119,18 +127,24 @@ export class MonitoringSitesCreateComponent implements OnInit {
);
}

updateBreadCrumb(sitesGroup) {
this.breadCrumbElemnt.description = sitesGroup.sites_group_name;
this.breadCrumbElemnt.label = 'Groupe de site';
this.breadCrumbElemnt['id'] = sitesGroup.id_sites_group;
this.breadCrumbElemnt['objectType'] =
this._sitesGroupService.objectObs.objectType || 'sites_group';
this.breadCrumbElemnt['url'] = [
this.breadCrumbElementBase.url,
this.breadCrumbElemnt.id?.toString(),
].join('/');

this.breadCrumbList = [this.breadCrumbElementBase, this.breadCrumbElemnt];
updateBreadCrumb() {
const breadcrumb : IBreadCrumb[] = []

if (this.moduleCode !== "generic") {
const module = this._configService.config()[this.moduleCode].module;
breadcrumb.push({ description: module.module_label, label: "", url: `object/${module.module_code}/sites_group` })
if (this.sitesGroup) {
breadcrumb.push({ description: `Groupe de site : ${this.sitesGroup.sites_group_name}`, label: "", url: `object/${module.module_code}/sites_group/${this.sitesGroup.id_sites_group}`});
}
}

this.breadCrumbElementBase = { ...this.breadCrumbElementBase, url: `object/${this.moduleCode}/site` };

this.breadCrumbList = [
...breadcrumb,
this.breadCrumbElementBase,
];

this._objService.changeBreadCrumb(this.breadCrumbList, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
[currentUser]="currentUser"
>
</pnx-monitoring-form>
<pnx-monitoring-properties-g
*ngIf="!bEdit"
[(bEdit)]="bEdit"
[newParentType]="objParent"
[selectedObj]="objResolvedProperties"
[selectedObjRaw]="objSelected"
[permission]="currentPermission"
></pnx-monitoring-properties-g>
<pnx-monitoring-properties
*ngIf="obj && !bEdit && obj.bIsInitialized"
id="nav-properties"
[obj]="obj"
[(bEdit)]="bEdit"
[currentUser]="currentUser">
</pnx-monitoring-properties>
<pnx-monitoring-datatable-g
*ngIf="!bEdit"
[dataTableArray]="dataTableArray"
Expand All @@ -46,5 +45,5 @@
[optionList]="modules"
(onDeployed)="getModules()"
(onSaved)="addNewVisit($event)"
></option-list-btn
></pnx-monitoring-datatable-g>
></option-list-btn>
</pnx-monitoring-datatable-g>
Loading

0 comments on commit bc0af3d

Please sign in to comment.