calculator.component.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {Component, ViewRef} from '@angular/core';
  2. import {
  3. HsLanguageService,
  4. HsLayoutService,
  5. // eslint-disable-next-line import/named
  6. HsPanelComponent,
  7. } from 'hslayers-ng';
  8. import {CalculatorService, Index} from './calculator.service';
  9. import {FieldService} from './field.service';
  10. @Component({
  11. selector: 'calculator-panel',
  12. templateUrl: './calculator.component.html',
  13. styleUrls: ['./calculator.component.scss'],
  14. })
  15. export class CalculatorComponent implements HsPanelComponent {
  16. data: {
  17. selectedProduct: Index;
  18. selectedFieldsProperties: {[x: string]: any}[];
  19. };
  20. name: 'calculator';
  21. viewRef: ViewRef;
  22. constructor(
  23. public calcService: CalculatorService,
  24. private fieldService: FieldService,
  25. public hsLanguageService: HsLanguageService,
  26. public hsLayoutService: HsLayoutService
  27. ) {
  28. this.fieldService.fieldSelects.subscribe(({features}) => {
  29. this.data.selectedFieldsProperties = [];
  30. for (const feature of features) {
  31. this.data.selectedFieldsProperties.push(feature.getProperties());
  32. }
  33. });
  34. }
  35. isVisible(): boolean {
  36. return this.hsLayoutService.panelVisible('calculator');
  37. }
  38. noFieldSelected(): boolean {
  39. return this.fieldService.noFieldSelected();
  40. }
  41. noProductSelected(): boolean {
  42. return this.data.selectedProduct === undefined;
  43. }
  44. noDates(): boolean {
  45. return this.calcService.noDates();
  46. }
  47. noDateSelected(): boolean {
  48. return this.calcService.selectedDate === undefined;
  49. }
  50. getDates() {
  51. this.calcService.getDates({product: this.data.selectedProduct});
  52. }
  53. getZones() {
  54. this.calcService.getZones({
  55. product: this.data.selectedProduct,
  56. });
  57. }
  58. updateRangeSlider(value: string) {
  59. this.calcService.dateCalendarSelects.next({date: value});
  60. }
  61. }