calculator.component.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { Component, OnInit, ViewRef} from '@angular/core';
  2. import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
  3. import {
  4. HsLanguageService,
  5. HsLayoutService,
  6. // eslint-disable-next-line import/named
  7. HsPanelComponent,
  8. } from 'hslayers-ng';
  9. import {CalculatorService, Index} from './calculator.service';
  10. import {FieldService} from './field.service';
  11. @Component({
  12. selector: 'calculator-panel',
  13. templateUrl: './calculator.component.html',
  14. styleUrls: ['./calculator.component.scss'],
  15. })
  16. export class CalculatorComponent implements HsPanelComponent, OnInit {
  17. data: {
  18. selectedProduct: Index;
  19. selectedFieldsProperties: {[x: string]: any}[];
  20. };
  21. lpisWfsVisible: boolean;
  22. name: 'calculator';
  23. viewRef: ViewRef;
  24. constructor(
  25. public calcService: CalculatorService,
  26. private fieldService: FieldService,
  27. public hsLanguageService: HsLanguageService,
  28. public hsLayoutService: HsLayoutService
  29. ) {
  30. this.fieldService.fieldSelects.subscribe(({features}) => {
  31. this.data.selectedFieldsProperties = [];
  32. for (const feature of features) {
  33. this.data.selectedFieldsProperties.push(feature.getProperties());
  34. }
  35. });
  36. this.calcService.viewChanges.subscribe((view) => {
  37. if (view.getZoom() > this.calcService.MIN_LPIS_VISIBLE_ZOOM) {
  38. this.lpisWfsVisible = true;
  39. return;
  40. }
  41. this.lpisWfsVisible = false;
  42. });
  43. }
  44. ngOnInit() {
  45. this.data.selectedProduct = null;
  46. }
  47. isVisible(): boolean {
  48. return this.hsLayoutService.panelVisible('calculator');
  49. }
  50. noFieldSelected(): boolean {
  51. return this.fieldService.noFieldSelected();
  52. }
  53. noProductSelected(): boolean {
  54. return this.data.selectedProduct === null;
  55. }
  56. noDates(): boolean {
  57. return this.calcService.noDates();
  58. }
  59. noDateSelected(): boolean {
  60. return this.calcService.selectedDate === undefined;
  61. }
  62. getDates() {
  63. this.calcService.getDates({product: this.data.selectedProduct});
  64. }
  65. getZones() {
  66. this.calcService.getZones({
  67. product: this.data.selectedProduct,
  68. });
  69. }
  70. /**
  71. * Used when product is changed, so the selected date can be reset
  72. */
  73. resetDate() {
  74. this.calcService.selectedDate = undefined;
  75. this.calcService.availableDates = undefined;
  76. }
  77. updateRangeSlider(value: string) {
  78. this.calcService.dateCalendarSelects.next({date: value});
  79. }
  80. updateSelectedDate(value: NgbDateStruct) {
  81. this.calcService.selectedDate = value.year + '-' + value.month + '-' + value.day;
  82. }
  83. isWeekend(date: NgbDateStruct) {
  84. return date.day > 5;
  85. }
  86. hasTask(date: NgbDateStruct) {
  87. return date.year == 2022 && date.month == 6 && date.day == 16;
  88. }
  89. }