Selaa lähdekoodia

download - export style

kunickyd 3 vuotta sitten
vanhempi
commit
2f4d81bb81

+ 1 - 0
src/app/shared/api/endpoints/models.ts

@@ -21,3 +21,4 @@ export { Observation } from './models/observation';
 export { Statistics } from './models/statistics';
 export { OldObservation } from './models/old-observation';
 export { SensorType } from './models/sensor-type';
+export { ExportStyle } from './models/export-style'

+ 5 - 0
src/app/shared/api/endpoints/models/export-style.ts

@@ -0,0 +1,5 @@
+export interface ExportStyle {
+    style_id: string,
+    style_name: string,
+    description?: string
+}

+ 45 - 1
src/app/shared/api/endpoints/services/observation.service.ts

@@ -11,6 +11,7 @@ import { Observable } from 'rxjs';
 import { map, filter } from 'rxjs/operators';
 
 import { OldObservation } from '../models/old-observation';
+import { ExportStyle } from '../models/export-style';
 
 
 /**
@@ -91,19 +92,62 @@ export class ObservationService extends BaseService {
     );
   }
 
+/**
+   * Get export styles.
+   *
+   *
+   *
+   * This method provides access to the full `HttpResponse`, allowing access to response headers.
+   * To access only the response body, use `getExportStyle()` instead.
+   *
+   * This method doesn't expect any request body.
+   */
+ getExportStyle$Response(): Observable<StrictHttpResponse<Array<ExportStyle>>> {
+
+  const rb = new RequestBuilder(this.rootUrl, ObservationService.RestObservationsPath + 'exportstyle', 'get');  
+
+  return this.http.request(rb.build({
+    responseType: 'json',
+    accept: 'application/json'
+  })).pipe(
+    filter((r: any) => r instanceof HttpResponse),
+    map((r: HttpResponse<any>) => {
+      return r as StrictHttpResponse<Array<ExportStyle>>;
+    })
+  );
+}  
+
+/**
+   * Get observation.
+   *
+   *
+   *
+   * This method provides access to only to the response body.
+   * To access the full response (for headers, for example), `getExportStyle$Response()` instead.
+   *
+   * This method doesn't expect any request body.
+   */
+ getExportStyle(): Observable<Array<ExportStyle>> {
+
+  return this.getExportStyle$Response().pipe(
+    map((r: StrictHttpResponse<Array<ExportStyle>>) => r.body as Array<ExportStyle>)
+  );
+}
+
 
   exportObservations(params: {
     //group_id: number,
     sensor_id: number,
     from?: Date;
     to?: Date;
+    exportStyleId: string;
   }): Observable<StrictHttpResponse<string>> {
     const rb = new RequestBuilder(this.rootUrl, ObservationService.RestObservationsPath + 'export', 'get');
     if (params) {
       rb.query('sensor_id', params.sensor_id);
       rb.query('from_time', formatDate(params.from, 'yyyy-MM-dd', 'en-US'));
       rb.query('to_time', formatDate(params.to, 'yyyy-MM-dd', 'en-US'));
-      rb.query('style', 'crosstab');
+      rb.query('style', params.exportStyleId);
       rb.query('nullable', false);
     }
 

+ 18 - 1
src/app/shared/nav-bar/components/data-download/data-download-popup.component.html

@@ -31,14 +31,31 @@
         <p-calendar [monthNavigator]="true" [yearNavigator]="true" yearRange="2000:2021" dateFormat="d. m. yy" inputId="navigators" formControlName="to"></p-calendar>
       </div>
 
+      <div class="input-group form-group">
+        <div class="input-group-prepend">
+          <span class="input-group-text"><i class="fas fa-palette"></i></span>
+        </div>
+        <select formControlName="exportStyleId" id="exportStyleId">                  
+          <option _ngcontent-cba-c50="" value="null" disabled="">Select export style</option>
+          <option *ngFor="let style of exportStyles" [value]="style.style_id" [title]="style.description">
+            {{ style.style_name }}
+          </option>
+          
+        </select>
+      </div>
+
       <p-listbox [options]="units" formControlName="selectedUnits" [metaKeySelection]="false" [checkbox]="true" [filter]="true" filterPlaceHolder="Search and select units"
                  optionLabel="description" optionValue="unitId"
                  emptyFilterMessage="No units for specified filter" [multiple]="true" [listStyle]="{'max-height':'250px'}" [style]="{'width':'100%'}">
       </p-listbox>
 
+
+      
+
     </div>
 
-  
+    
+
   </form>
 
   <div *ngIf="inProgress" class="download-progress">Export in progress<p-progressBar mode="indeterminate" [style]="{'height': '6px'}"></p-progressBar></div>

+ 8 - 1
src/app/shared/nav-bar/components/data-download/data-download-popup.component.ts

@@ -11,6 +11,7 @@ import { Unit } from '../../../api/endpoints/models/unit';
 import * as moment from 'moment-timezone';
 import { DashboardComponent } from '../../../../dashboard/components/dashboard.component';
 import { formatDate } from '@angular/common';
+import { ExportStyle } from 'src/app/shared/api/endpoints/models';
 
 @Component({
   selector: 'app-data-download-popup',
@@ -24,6 +25,7 @@ export class DataDownloadPopupComponent implements OnInit {
   dateFrom: Date = moment().hour(0).minutes(0).subtract(1, 'days').toDate();
   dateTo: Date = moment().toDate();
   selectedUnits: Unit[];
+  exportStyles: ExportStyle[];
 
   inProgress: Boolean = false;
   @Input() isVisible;
@@ -53,7 +55,8 @@ export class DataDownloadPopupComponent implements OnInit {
       from: [this.dateFrom, Validators.required],
       to: [this.dateTo, Validators.required],
       sensor_id: [null, Validators.required],
-      selectedUnits: new FormControl([])
+      selectedUnits: new FormControl([]),
+      exportStyleId: [null, Validators.required]
     });
 
     this.dataService.getData().subscribe(data => {
@@ -71,6 +74,10 @@ export class DataDownloadPopupComponent implements OnInit {
         });
       }
     }, err => this.toastService.showError(err.error.message));
+
+    this.observationService.getExportStyle().subscribe(
+      data => this.exportStyles = data
+    );
   }
 
   /**