|
@@ -31,7 +31,6 @@ 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;
|
|
@@ -51,13 +50,12 @@ 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 http: HttpClient
|
|
|
|
|
|
|
+ private route: ActivatedRoute
|
|
|
) {
|
|
) {
|
|
|
- this.initData();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
ngOnInit(): void {
|
|
|
|
|
+ this.initData();
|
|
|
const tab = this.route.snapshot.queryParamMap.get('tab');
|
|
const tab = this.route.snapshot.queryParamMap.get('tab');
|
|
|
if (tab === 'map') {
|
|
if (tab === 'map') {
|
|
|
this.selectedTabIndex = 1; // show Map view
|
|
this.selectedTabIndex = 1; // show Map view
|
|
@@ -100,70 +98,10 @@ 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));
|
|
|
- */
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|