Bladeren bron

Moving to new server

A-Konig 1 week geleden
bovenliggende
commit
436eb14aad

+ 1 - 0
src/app/dashboard/components/custom-dashboard/custom-dashboard.component.html

@@ -0,0 +1 @@
+<p>Currently under construction!</p>

+ 0 - 0
src/app/dashboard/components/custom-dashboard/custom-dashboard.component.scss


+ 95 - 0
src/app/dashboard/components/custom-dashboard/custom-dashboard.component.ts

@@ -0,0 +1,95 @@
+import {Component, Input, OnChanges, SimpleChanges} from '@angular/core';
+import {User} from '../../../auth/models/user';
+import {Drivers} from '../../../shared/api/endpoints/models/drivers';
+import {GeneralInfo} from '../../../shared/api/endpoints/models/general-info';
+import {Lastpos} from '../../../shared/api/endpoints/models/lastpos';
+import {Sensor} from '../../../shared/api/endpoints/models/sensor';
+import {Unit} from '../../../shared/api/endpoints/models/unit';
+import {DataService} from '../../../shared/api/endpoints/services/data.service';
+import {SensorsService} from '../../../shared/api/endpoints/services/sensors.service';
+import {ConfirmationService, MessageService} from 'primeng/api';
+import {ManagementService} from '../../../shared/api/endpoints/services/management.service';
+import {ToastService} from '../../../shared/services/toast.service';
+import {AuthService} from '../../../auth/services/auth.service';
+import {Config} from '../../../shared/api/endpoints/models/config';
+import {HttpClient} from '@angular/common/http';
+
+@Component({
+  selector: 'app-custom-dashboard',
+  templateUrl: './custom-dashboard.component.html',
+  styleUrls: ['./custom-dashboard.component.scss']
+})
+export class CustomDashboardComponent implements OnChanges {
+  @Input('user') loggedUser: User;
+  @Input('units') 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 }>;
+
+  constructor(
+      private dataService: DataService,
+      private sensorService: SensorsService,
+      private confirmationService: ConfirmationService,
+      private messageService: MessageService,
+      private managementService: ManagementService,
+      private toastService: ToastService,
+      private authService: AuthService,
+      private http: HttpClient
+  ) {
+  }
+
+  ngOnChanges(changes: SimpleChanges): void {
+    if (changes.units && changes.units.currentValue) {
+      console.log('New units data arrived in child.');
+      // Once data is here, process
+      this.createGraphs();
+    }
+  }
+
+  /**
+   * Get all units and theirs sensors from backend
+   */
+  createGraphs() {
+    this.http.get<Config>('assets/example.json').subscribe(config => {
+
+      // 1. Store and sort the raw master data
+      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);
+    }, err => this.toastService.showError(err.error.message));
+  }
+
+  }

+ 3 - 3
src/app/dashboard/components/dashboard.component.html

@@ -2,7 +2,7 @@
 
 <div class="container dashboard">
   <p-tabView [(activeIndex)]="selectedTabIndex">
-    <p-tabPanel header="Dashboard">
+    <p-tabPanel header="Units">
       <unit-list [user]="loggedUser" [units]="units"></unit-list>
     </p-tabPanel>
     <p-tabPanel header="Map">
@@ -10,8 +10,8 @@
         <app-map [units]="units"></app-map>
       </ng-template>
     </p-tabPanel>
-    <p-tabPanel header="Custom dashboard">
-        <unit-list [user]="loggedUser" [units]="cstmUnits"></unit-list>
+    <p-tabPanel header="Dashboard">
+        <app-custom-dashboard [user]="loggedUser" [units]="units"></app-custom-dashboard>
     </p-tabPanel>
   </p-tabView>
 </div>

+ 2 - 64
src/app/dashboard/components/dashboard.component.ts

@@ -31,7 +31,6 @@ export class DashboardComponent implements OnInit, OnDestroy {
   position: 'bottom';
   groups: Group[];
   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;
   showEditUnitPopup = false;
   showInsertSensorPopup = false;
@@ -51,13 +50,12 @@ export class DashboardComponent implements OnInit, OnDestroy {
     // private managementService: ManagementService,
     private toastService: ToastService,
     private authService: AuthService,
-    private route: ActivatedRoute,
-    private http: HttpClient
+    private route: ActivatedRoute
   ) {
-    this.initData();
   }
 
   ngOnInit(): void {
+    this.initData();
     const tab = this.route.snapshot.queryParamMap.get('tab');
     if (tab === 'map') {
       this.selectedTabIndex = 1;   // show Map view
@@ -100,70 +98,10 @@ export class DashboardComponent implements OnInit, OnDestroy {
    * Get all units and theirs sensors from backend
    */
   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.units = data;
       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));
-     */
   }
 
   /**

+ 2 - 2
src/app/dashboard/components/sensors/sensors.component.html

@@ -4,8 +4,8 @@
       <h5>{{ sensor.sensorName }}</h5>
     </div>
   </div>
-  <div class="col-sm-5 col-md-4 col-lg-3 dashboard-sensor-heading">
-    <button pButton type="button" label="View graph" class="p-button-primary" [id]="sensor.sensorName" [routerLink]="['/dashboard/unit', unit.unitId, 'sensor', sensor.sensorId]" [queryParams]="{unitName: unit.description}" title="Sensor" icon="pi pi-chart-line"></button>
+  <div class="col-sm-5 col-md-4 col-lg-3 dashboard-sensor-heading buttonDiv">
+    <button pButton type="button" label="View graph" class="p-button-primary p-button-lg" [id]="sensor.sensorName" [routerLink]="['/dashboard/unit', unit.unitId, 'sensor', sensor.sensorId]" [queryParams]="{unitName: unit.description}" title="Sensor" icon="pi pi-chart-line"></button>
     <ng-container *ngIf="loggedUser?.userInfo?.rightsId == 0 || loggedUser?.userInfo?.rightsId == 1">
       <div class="dashboard-button-separator"></div>
       <p-button [id]="'manipulation_sensor_'+sensor.sensorId" icon="pi pi-cog" styleClass="p-button-warning" (click)="showItems($event, sensor); menu.toggle($event)"></p-button>

+ 13 - 0
src/app/dashboard/components/sensors/sensors.component.scss

@@ -0,0 +1,13 @@
+.buttonDiv {
+  display: flex;
+  flex-direction: row;
+  flex-wrap: nowrap;
+  align-items: center;
+  justify-content: flex-end;
+}
+
+/* Force the buttons to maintain their size */
+.buttonDiv button,
+.buttonDiv p-button {
+  flex-shrink: 0;
+}

+ 13 - 2
src/app/dashboard/components/unit-list/unit-list.component.ts

@@ -1,4 +1,4 @@
-import { Component, Input, OnDestroy, OnInit } from '@angular/core';
+import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core';
 import { Group } from '../../../shared/api/endpoints/models/group';
 import { Drivers } from '../../../shared/api/endpoints/models/drivers';
 import { GeneralInfo } from '../../../shared/api/endpoints/models/general-info';
@@ -23,7 +23,7 @@ import { Subscription } from 'rxjs';
   templateUrl: './unit-list.component.html',
   styleUrls: ['./unit-list.component.scss']
 })
-export class UnitListComponent implements OnInit, OnDestroy {
+export class UnitListComponent implements OnInit, OnDestroy, OnChanges {
 
   @Input('user') loggedUser: User;
   @Input('units') units:
@@ -54,6 +54,17 @@ export class UnitListComponent implements OnInit, OnDestroy {
     this.initData();
   }
 
+  ngOnChanges(changes: SimpleChanges): void {
+    // If the 'units' input changes and has a value
+    if (changes.units && changes.units.currentValue) {
+      // console.log('New units data arrived in child:', this.units);
+      // Once data is here, stop the loading progress bar
+      if (this.units.length >= 0) {
+        this.inProgress = false;
+      }
+    }
+  }
+
   ngOnInit(): void {
   }
 

+ 2 - 1
src/app/dashboard/dashboard.module.ts

@@ -20,10 +20,11 @@ import { UnitListComponent } from './components/unit-list/unit-list.component';
 import { MapComponent } from './components/map/map.component';
 import { ProgressBarModule } from 'primeng/progressbar';
 import { TabViewModule } from 'primeng/tabview';
+import { CustomDashboardComponent } from './components/custom-dashboard/custom-dashboard.component';
 
 @NgModule({
   declarations: [DashboardComponent, SensorsComponent, UnitPopupComponent, SensorPopupComponent, SensorInsertPopupComponent,
-    PositionInsertPopupComponent, UnitListComponent, MapComponent],
+    PositionInsertPopupComponent, UnitListComponent, MapComponent, CustomDashboardComponent],
   imports: [
     CommonModule,
     NavBarModule,

+ 4 - 4
src/app/sensor/components/sensor.component.html

@@ -69,13 +69,13 @@
       <div class="y-range">
           <div>
               <form class="column-group">
-                  <label for="yFrom">Min y:</label><br>
-                  <input type="number" class="simple-number-input" id="yFrom" name="yFrom" [(ngModel)]="yFrom" placeholder="Min y"/>
-              </form>
-              <form class="column-group">
                   <label for="yTo">Max y:</label><br>
                   <input type="number" class="simple-number-input" id="yTo" name="yTo" [(ngModel)]="yTo" placeholder="Max y"/>
               </form>
+              <form class="column-group">
+                  <label for="yFrom">Min y:</label><br>
+                  <input type="number" class="simple-number-input" id="yFrom" name="yFrom" [(ngModel)]="yFrom" placeholder="Min y"/>
+              </form>
           </div>
 
           <button pButton type="button" label="Change y" class="p-button-primary" icon="pi pi-chart-line" (click)="changeGraphY()"></button>

+ 4 - 4
src/app/shared/graph-loading/graphloader.ts

@@ -101,8 +101,8 @@ export class GraphLoader {
       config
     };
 
-    console.log('COPY THIS INTO VEGA EDITOR:');
-    console.log(JSON.stringify(fullSpecForExport, null, 2));
+    // console.log('COPY THIS INTO VEGA EDITOR:');
+    // console.log(JSON.stringify(fullSpecForExport, null, 2));
 
     // --------------------------------
 
@@ -115,8 +115,8 @@ export class GraphLoader {
 
   static ResizeGraph(graphView, newWidth: number) {
     graphView.width(newWidth).height(300).runAsync();
-    console.log('Requested width : ', newWidth);
-    console.log('Got width: ', graphView.width());
+    // console.log('Requested width : ', newWidth);
+    // console.log('Got width: ', graphView.width());
 
     // check if Vega "stole" pixels. If it did, force it again.
     /*

+ 34 - 32
src/app/unit/components/unit.component.html

@@ -14,41 +14,43 @@
         {{unitDescription}}
       </div>
     </div>
-    <div class="graph-range-dates">
-      <div class="input-group calendar-group">
-          <label for="from">From:</label>
+    <div>
+        <div class="graph-range-dates">
+            <div class="input-group column-group">
+              <label for="from">From:</label>
 
-          <p-calendar
-                  id="from"
-                  [style]="{'width':'100%'}"
-                  [inputStyle]="{'width':'100%'}"
-                  [(ngModel)]="from"
-                  [showIcon]=true
-                  [showTime]=true
-                  (onSelect)="onDateChanged()"
-                  [maxDate]="today"
-                  showButtonBar=true>
-          </p-calendar>
-      </div>
+              <p-calendar
+                    id="from"
+                      [style]="{'width':'100%'}"
+                      [inputStyle]="{'width':'100%'}"
+                      [(ngModel)]="from"
+                      [showIcon]=true
+                      [showTime]=true
+                    (onSelect)="onDateChanged()"
+                      [maxDate]="today"
+                      showButtonBar=true>
+              </p-calendar>
+            </div>
 
-      <div class="input-group calendar-group">
-          <label for="to">To:</label>
+            <div class="input-group column-group">
+                  <label for="to">To:</label>
 
-          <p-calendar
-                  id="to"
-                  [style]="{'width':'100%'}"
-                  [inputStyle]="{'width':'100%'}"
-                  [(ngModel)]="to"
-                  [showIcon]=true
-                  [showTime]=true
-                  (onSelect)="onDateChanged()"
-                  [maxDate]="today"
-                  showButtonBar=true>
-          </p-calendar>
-      </div>
-      <div>
-        <button pButton type="button" *ngIf="dateChanged" label="Load data" class="p-button-primary" icon="pi pi-chart-line" (click)="showGraph()"></button>
-      </div>
+                  <p-calendar
+                    id="to"
+                      [style]="{'width':'100%'}"
+                      [inputStyle]="{'width':'100%'}"
+                      [(ngModel)]="to"
+                      [showIcon]=true
+                      [showTime]=true
+                      (onSelect)="onDateChanged()"
+                      [maxDate]="today"
+                      showButtonBar=true>
+                  </p-calendar>
+            </div>
+            <div>
+                <button pButton type="button" *ngIf="dateChanged" label="Load data" class="p-button-primary" icon="pi pi-chart-line" (click)="showGraph()"></button>
+            </div>
+        </div>
     </div>
     <div *ngIf="showIntervalError" class="alert alert-danger interval-alert" role="alert">
       Select a valid interval - interval should be smaller than <b>6 months</b> and the "from" date has to <b>precede</b> the "to" date!

+ 1 - 1
src/app/unit/components/unit.component.ts

@@ -86,7 +86,7 @@ export class UnitComponent implements OnInit, OnDestroy {
 
   private onResize() {
     const itemCount = Object.keys(this.graphViews).length;
-    console.log('Number of entries:', itemCount);
+    // console.log('Number of entries:', itemCount);
 
     Object.entries(this.graphViews).forEach(([key, view]) => {
       if (view) {

+ 1 - 1
src/environments/environment.prod.ts

@@ -2,6 +2,6 @@ export const environment = {
   production: true,
   baseHref: '/',
   useMock: false,
-  sensLogBaseUrl: 'https://sensor.lesprojekt.cz/senslog15',
+  sensLogBaseUrl: 'https://senslog.lesprojekt.cz/senslog15',
   hslayersAssetsPath: 'https://unpkg.com/hslayers-ng-app@6.1.0/assets'
 };

+ 1 - 1
src/environments/environment.ts

@@ -1,5 +1,5 @@
 export const environment = {
   production: false,
-  sensLogBaseUrl: 'https://sensor.lesprojekt.cz/senslog15',
+  sensLogBaseUrl: 'https://senslog.lesprojekt.cz/senslog15',
   hslayersAssetsPath: './hslayers-ng/assets'
 };

+ 1 - 1
src/index.html

@@ -12,7 +12,7 @@
   <app-root></app-root>
   <footer>
     <p>
-      Copyright 2021&nbsp;&copy;&nbsp;
+      Copyright 2026&nbsp;&copy;&nbsp;
       <a href="https://www.zcu.cz" target="_blank">ZČU</a>,&nbsp;
       <a href="https://www.lesprojekt.cz" target="_blank">LESPROJEKT</a>,&nbsp;
       <a href="https://www.ccss.cz" target="_blank">CCSS</a>