File

angular/projects/researchdatabox/export/src/app/export.component.ts

Extends

BaseComponent

Metadata

Index

Properties
Methods

Constructor

constructor(loggerService: LoggerService, recordService: RecordService, configService: ConfigService, translationService: TranslationService, document: Document)
Parameters :
Name Type Optional
loggerService LoggerService No
recordService RecordService No
configService ConfigService No
translationService TranslationService No
document Document No

Methods

download
download()
Returns : void
getExportFormatNames
getExportFormatNames()
Returns : {}
getRecordTypeNames
getRecordTypeNames()
Returns : {}
Protected Async initComponent
initComponent()
Inherited from BaseComponent
Defined in BaseComponent:57
Returns : Promise<void>
setExportFormat
setExportFormat(exportFormat: any, e: any)
Parameters :
Name Type Optional
exportFormat any No
e any No
Returns : void
setRecordType
setRecordType(recType: any, e: any)
Parameters :
Name Type Optional
recType any No
e any No
Returns : void
getInitSubject
getInitSubject()
Inherited from BaseComponent
Defined in BaseComponent:71

For those interested in the init from RXJS-land.

Note that it returns a BehaviorSubject instance, and will have an initial value of false, so process the return value as needed.

Returns : Subject<any>
isInitializing
isInitializing()
Inherited from BaseComponent
Defined in BaseComponent:95

Main flag to indicate the init status

Returns : boolean
ngOnInit
ngOnInit()
Inherited from BaseComponent
Defined in BaseComponent:50
Returns : void
Async waitForDeps
waitForDeps()
Inherited from BaseComponent
Defined in BaseComponent:78

Wait for dependencies to initialise

Returns : Promise<any>
Async waitForInit
waitForInit()
Inherited from BaseComponent
Defined in BaseComponent:89

For those interested in the init from the Promise-land

Returns : Promise<any>

Properties

criticalError
Type : any
datePickerOpts
Type : any
datePickerPlaceHolder
Type : string
Default value : ''
export_format
Type : literal type
Default value : null as any
exportFormatTypes
Type : any[]
Default value : null as any
hasClearButton
Type : boolean
Default value : false
labelModAfter
Type : string
Default value : ''
modAfter
Type : any
modBefore
Type : any
record_type
Type : string
Default value : null as any
recTypeNames
Type : string[]
Default value : null as any
timePickerOpts
Type : any
window
Type : any
Protected brandingAndPortalUrl
Type : string
Default value : ''
Inherited from BaseComponent
Defined in BaseComponent:42
Private filterFn
Default value : function(initStat: boolean) { return initStat; }
Inherited from BaseComponent
Defined in BaseComponent:40
Protected initDependencies
Type : Initable[]
Default value : []
Inherited from BaseComponent
Defined in BaseComponent:39
Protected initSubject
Type : BehaviorSubject<any>
Default value : new BehaviorSubject(false)
Inherited from BaseComponent
Defined in BaseComponent:38
Protected isReady
Type : boolean
Default value : false
Inherited from BaseComponent
Defined in BaseComponent:37
import { Component, Inject } from '@angular/core';
import { DOCUMENT } from "@angular/common"
import { ConfigService, LoggerService, TranslationService, RecordService, BaseComponent } from '@researchdatabox/portal-ng-common';
import { map as _map, get as _get } from 'lodash-es';
import { DateTime } from 'luxon';

@Component({
  selector: 'export',
  templateUrl: './export.component.html'
})
export class ExportComponent extends BaseComponent {
  datePickerPlaceHolder: string = '';
  criticalError: any;
  modBefore: any;
  modAfter: any;
  datePickerOpts: any;
  timePickerOpts: any;
  hasClearButton: boolean = false;
  recTypeNames: string[] = null as any;
  record_type: string = null as any;
  exportFormatTypes: any[] = null as any;
  export_format: { name: string, id: string, checked: string } = null as any;
  labelModAfter: string = '';
  window: any;
  constructor(
    @Inject(LoggerService) private loggerService: LoggerService,
    @Inject(RecordService) private recordService: RecordService,
    @Inject(ConfigService) private configService: ConfigService,
    @Inject(TranslationService) private translationService: TranslationService,
    @Inject(DOCUMENT) private document: Document
  ) {
    super();
    this.loggerService.debug(`Export waiting for deps to init...`); 
    this.window = this.document.defaultView;
    this.initDependencies = [this.translationService, this.recordService];
  }

  protected override async initComponent():Promise<void> {
    const sysConfig = await this.configService.getConfig();
    const appName = 'export';
    const defaultDatePickerOpts = { dateInputFormat: 'DD/MM/YYYY', containerClass: 'theme-dark-blue' };
    const defaultDatePickerPlaceHolder = 'dd/mm/yyyy';
    const defaultExportFormatTypes = [{name: 'CSV', id: 'csv', checked: 'true'},{name: 'JSON', id: 'json', checked: null}];
    this.datePickerOpts = ConfigService._getAppConfigProperty(sysConfig, appName, 'datePickerOpts', defaultDatePickerOpts);  
    this.datePickerPlaceHolder = ConfigService._getAppConfigProperty(sysConfig, appName, 'datePickerPlaceHolder', defaultDatePickerPlaceHolder);
    this.exportFormatTypes = ConfigService._getAppConfigProperty(sysConfig, appName, 'exportFormatTypes', defaultExportFormatTypes);
    this.export_format = this.exportFormatTypes[0].id; //set default export format
    this.labelModAfter = `${this.translationService.t('export-modified-after')}`;
    const typeConfs = await this.recordService.getAllTypes();
    this.recTypeNames = _map(typeConfs, (typeConf:any) => { return typeConf.name });
    this.record_type = this.recTypeNames[0];
    this.loggerService.debug(`Export initialised`); 
  }

  download() {
    let before = '';
    let after = '';
    if(this.modBefore) {
      this.modBefore.setHours(23,59,59,999);
      before = this.modBefore.toISOString();
    }
    if(this.modAfter) {
      this.modAfter.setHours(0,0,0,0);
      after = this.modAfter.toISOString();
    }
    
    
    const url = `${this.recordService.brandingAndPortalUrl}/export/record/download/${this.export_format}?before=${before}&after=${after}&recType=${this.record_type}`;
    this.window.open(url, '_blank');
  }

  getRecordTypeNames() {
    return this.recTypeNames;
  }

  getExportFormatNames() {
    return this.exportFormatTypes;
  }

  setRecordType(recType:any, e: any) {
    if (e) {
      e.preventDefault();
    }
    this.record_type = recType;
  }

  setExportFormat(exportFormat:any, e:any) {
    if (e) {
      e.preventDefault();
    }
    this.export_format = exportFormat;
  }
}
<!-- ngIf is needed so init completes and view has all the information it needs -->
<ng-container *ngIf="isReady"> 
  <div class="row">
    <div class="col-xs-1">
    </div>
    <div class="col-xs-10">
      <div class="form-horizontal">
        <div class="form-group">
          <label class="col-xs-2 control-label">{{ 'export-modified-after' | i18next }}</label>
          <span class="col-xs-2">
            <input type="text" id="after" 
            [bsConfig]="datePickerOpts"
            [placeholder] = "datePickerPlaceHolder"
            [(ngModel)] = "modAfter"
            bsDatepicker />
          </span>
        </div>
        <div class="form-group">
          <label class="col-xs-2 control-label">{{ 'export-modified-before' | i18next }}</label>
          <span class="col-xs-2">
            <input type="text" id="before" 
            [bsConfig]="datePickerOpts"
            [placeholder] = "datePickerPlaceHolder"
            [(ngModel)] = "modBefore"
            bsDatepicker />
          </span>
        </div>
        <div class="form-group">
          <label class="col-xs-2 control-label">{{ 'export-format' | i18next }} </label>
          <span class="col-xs-2">
            <div *ngFor="let recExportFormat of getExportFormatNames()"  >
              <input [checked]="recExportFormat.checked" (change)="setExportFormat(recExportFormat.id, $event)" id="format-{{recExportFormat.id}}" name="export-format-radio" type="radio" >
              <label for="format-{{recExportFormat.name}}" >&nbsp;{{ recExportFormat.name }}</label>
            </div>
          </span>
        </div>
        <div class="form-group">
          <div class="col-xs-2"></div>
          <div class="col-xs-2 padding-remove">
            <span class="btn-group">
              <button (click)="download()" class="btn btn-primary" type="button">
                {{ 'export-' + record_type  | i18next }}
              </button>
              <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
                <span class="visually-hidden">Toggle Dropdown</span>
              </button>
              <ul class="dropdown-menu">
                <li *ngFor="let recTypeName of getRecordTypeNames()">
                  <a class="dropdown-item" href="#" (click)="setRecordType(recTypeName, $event)">
                    {{ 'export-'+ recTypeName  | i18next }}
                  </a>
                </li>
              </ul>
            </span>
          </div>
        </div>
      </div>
    </div>
    <div class="col-xs-1">
    </div>
  </div>
</ng-container>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""