adjuster.component.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {Component, ViewRef} from '@angular/core';
  2. import {HsLayoutService} from 'hslayers-ng/components/layout/layout.service';
  3. import {HsPanelComponent} from 'hslayers-ng/components/layout/panels/panel-component.interface';
  4. import {AdjusterEventService} from './adjuster-event.service';
  5. import {AdjusterService} from './adjuster.service';
  6. @Component({
  7. selector: 'pra-adjuster',
  8. template: require('./adjuster.directive.html'),
  9. })
  10. export class AdjusterComponent implements HsPanelComponent {
  11. data: any;
  12. descriptionVisible: boolean;
  13. errorMsg: string;
  14. method: string;
  15. viewRef: ViewRef;
  16. constructor(
  17. private adjusterService: AdjusterService,
  18. private adjusterEventService: AdjusterEventService,
  19. private hsLayoutService: HsLayoutService
  20. ) {
  21. this.descriptionVisible = false;
  22. this.method = this.adjusterService.method;
  23. this.adjusterEventService.clustersLoaded.subscribe(({success, err}) => {
  24. if (!success) {
  25. this.errorMsg = err.message;
  26. }
  27. });
  28. }
  29. ngOnInit(): void {
  30. this.adjusterService.init();
  31. }
  32. isVisible(): boolean {
  33. return this.hsLayoutService.panelVisible('adjuster');
  34. }
  35. noDataSelected(): boolean {
  36. if (this.adjusterService.factors.length === 0) {
  37. return true;
  38. }
  39. let datasetsEffectivelyTurnedOn = [];
  40. for (const factor of this.adjusterService.factors) {
  41. if (factor.weight === 0) {
  42. continue;
  43. }
  44. datasetsEffectivelyTurnedOn = [
  45. ...datasetsEffectivelyTurnedOn,
  46. ...factor.datasets.filter((ds) => ds.included),
  47. ];
  48. }
  49. return datasetsEffectivelyTurnedOn.length === 0;
  50. }
  51. selectMethod(): void {
  52. this.adjusterService.method = this.method;
  53. this.adjusterEventService.methodChanged.next(this.method);
  54. }
  55. }