|
@@ -12,12 +12,13 @@ import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
|
|
|
import {ManagementService} from '../../shared/api/endpoints/services/management.service';
|
|
import {ManagementService} from '../../shared/api/endpoints/services/management.service';
|
|
|
import {ToastService} from '../../shared/services/toast.service';
|
|
import {ToastService} from '../../shared/services/toast.service';
|
|
|
import {map} from 'rxjs/operators';
|
|
import {map} from 'rxjs/operators';
|
|
|
-import {HttpResponse} from '@angular/common/http';
|
|
|
|
|
|
|
+import {HttpClient, HttpResponse} from '@angular/common/http';
|
|
|
import {AuthService} from '../../auth/services/auth.service';
|
|
import {AuthService} from '../../auth/services/auth.service';
|
|
|
import {User} from '../../auth/models/user';
|
|
import {User} from '../../auth/models/user';
|
|
|
import {SensorType} from '../../shared/api/endpoints/models/sensor-type';
|
|
import {SensorType} from '../../shared/api/endpoints/models/sensor-type';
|
|
|
-import {Subscription} from 'rxjs';
|
|
|
|
|
|
|
+import {forkJoin, Subscription} from 'rxjs';
|
|
|
import {ActivatedRoute} from '@angular/router';
|
|
import {ActivatedRoute} from '@angular/router';
|
|
|
|
|
+import {Config} from '../../shared/api/endpoints/models/config';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'app-dashboard',
|
|
selector: 'app-dashboard',
|
|
@@ -30,6 +31,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
|
|
position: 'bottom';
|
|
position: 'bottom';
|
|
|
groups: Group[];
|
|
groups: Group[];
|
|
|
units: Array<{ drivers?: Drivers; generalInfo?: GeneralInfo; holder?: any; lastpos?: Lastpos; sensors?: Array<Sensor>; unit?: Unit }>;
|
|
units: Array<{ drivers?: Drivers; generalInfo?: GeneralInfo; holder?: any; lastpos?: Lastpos; sensors?: Array<Sensor>; unit?: Unit }>;
|
|
|
|
|
+ cstmUnits: Array<{ drivers?: Drivers; generalInfo?: GeneralInfo; holder?: any; lastpos?: Lastpos; sensors?: Array<Sensor>; unit?: Unit }>;
|
|
|
editedUnit: Unit;
|
|
editedUnit: Unit;
|
|
|
showEditUnitPopup = false;
|
|
showEditUnitPopup = false;
|
|
|
showInsertSensorPopup = false;
|
|
showInsertSensorPopup = false;
|
|
@@ -49,7 +51,8 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
|
|
// private managementService: ManagementService,
|
|
// private managementService: ManagementService,
|
|
|
private toastService: ToastService,
|
|
private toastService: ToastService,
|
|
|
private authService: AuthService,
|
|
private authService: AuthService,
|
|
|
- private route: ActivatedRoute
|
|
|
|
|
|
|
+ private route: ActivatedRoute,
|
|
|
|
|
+ private http: HttpClient
|
|
|
) {
|
|
) {
|
|
|
this.initData();
|
|
this.initData();
|
|
|
}
|
|
}
|
|
@@ -97,10 +100,70 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
|
|
* Get all units and theirs sensors from backend
|
|
* Get all units and theirs sensors from backend
|
|
|
*/
|
|
*/
|
|
|
getUnits() {
|
|
getUnits() {
|
|
|
|
|
+ forkJoin({
|
|
|
|
|
+ masterData: this.dataService.getData(),
|
|
|
|
|
+ config: this.http.get<Config>('assets/example.json')
|
|
|
|
|
+ }).subscribe({
|
|
|
|
|
+ next: ({ masterData, config }) => {
|
|
|
|
|
+ console.log(masterData);
|
|
|
|
|
+
|
|
|
|
|
+ // 1. Store and sort the raw master data
|
|
|
|
|
+ this.units = masterData;
|
|
|
|
|
+ this.units.forEach(u => u.sensors?.sort((a, b) => (a.sensorId ?? 0) - (b.sensorId ?? 0)));
|
|
|
|
|
+
|
|
|
|
|
+ // 2. Extract configuration selections
|
|
|
|
|
+ const { units: unitSelections, globalSensors } = config.preferences.selections;
|
|
|
|
|
+
|
|
|
|
|
+ // 3. Perform the filtering logic
|
|
|
|
|
+ this.cstmUnits = this.units.map(masterUnit => {
|
|
|
|
|
+
|
|
|
|
|
+ // Find specific config for this unit
|
|
|
|
|
+ const selection = unitSelections.find(u => u.unitId === masterUnit.unit?.unitId);
|
|
|
|
|
+
|
|
|
|
|
+ const filteredSensors = (masterUnit.sensors || []).filter(sensor => {
|
|
|
|
|
+ const sId = sensor.sensorId;
|
|
|
|
|
+ if (sId === undefined) return false;
|
|
|
|
|
+
|
|
|
|
|
+ const isGlobal = globalSensors.includes(sId);
|
|
|
|
|
+ let isLocallySelected = false;
|
|
|
|
|
+
|
|
|
|
|
+ if (selection) {
|
|
|
|
|
+ isLocallySelected = selection.sensors === 'ALL' ||
|
|
|
|
|
+ (Array.isArray(selection.sensors) && selection.sensors.includes(sId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return isGlobal || isLocallySelected;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Return the unit structure with the new filtered sensor array
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...masterUnit,
|
|
|
|
|
+ sensors: filteredSensors
|
|
|
|
|
+ };
|
|
|
|
|
+ })
|
|
|
|
|
+ // 4. Final step: Only keep units that have at least one valid sensor
|
|
|
|
|
+ .filter(u => u.sensors.length > 0);
|
|
|
|
|
+
|
|
|
|
|
+ console.log('Filtered cstmUnits:', this.cstmUnits);
|
|
|
|
|
+ },
|
|
|
|
|
+ error: (err) => {
|
|
|
|
|
+ this.toastService.showError(err.error?.message || 'Error loading data');
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
this.dataService.getData().subscribe(data => {
|
|
this.dataService.getData().subscribe(data => {
|
|
|
this.units = data;
|
|
this.units = data;
|
|
|
this.units.forEach(unit => unit.sensors.sort((a, b) => a.sensorId - b.sensorId));
|
|
this.units.forEach(unit => unit.sensors.sort((a, b) => a.sensorId - b.sensorId));
|
|
|
|
|
+
|
|
|
|
|
+ // according to the config file filter through units
|
|
|
|
|
+ this.cstmUnits = [this.units[0]];
|
|
|
|
|
+
|
|
|
|
|
+ console.log(this.units);
|
|
|
|
|
+ console.log(this.units[0].unit);
|
|
|
|
|
+ console.log(this.units[0].sensors);
|
|
|
}, err => this.toastService.showError(err.error.message));
|
|
}, err => this.toastService.showError(err.error.message));
|
|
|
|
|
+ */
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|