Commit 4436d02c authored by Mark Harding's avatar Mark Harding
Browse files

(wip): fixes various looping issues and removes combineLatest logic

parent 5760aeab
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -113,8 +113,6 @@ export class AnalyticsChartComponent implements OnInit, OnDestroy {
  // ---------------------------------------------------

  visualisation: Visualisation;
  vm$: Observable<UserState> = this.analyticsService.vm$;
  vm: UserState;

  isDark: boolean = false;
  subscription: Subscription;
@@ -218,7 +216,6 @@ export class AnalyticsChartComponent implements OnInit, OnDestroy {
  ) {}

  ngOnInit() {
    this.subscription = this.vm$.subscribe(viewModel => (this.vm = viewModel));
    this.themeService.isDark$.subscribe(isDark => (this.isDark = isDark));

    this.graphDiv = document.getElementById('graphDiv');
@@ -377,9 +374,7 @@ export class AnalyticsChartComponent implements OnInit, OnDestroy {
      { interval: 'day', tickFormat: '%m/%d' },
      { interval: 'month', tickFormat: '%d/%y' },
    ];
    const selectedInterval = this.vm.timespans.find(
      t => t.id === this.vm.timespan
    ).interval;
    const selectedInterval = 'monthly';
    return timespanTickFormats.find(t => t.interval === selectedInterval)
      .tickFormat;
  }
@@ -396,8 +391,9 @@ export class AnalyticsChartComponent implements OnInit, OnDestroy {

  updateGraph() {
    // TODO: add latest shapes and marker settings to the updates
    const dataUpdate = this.setData();
    const layoutUpdate = this.setLayout();
    // THIS IS CAUSING A LOOP (MH)
    //const dataUpdate = this.setData();
    //const layoutUpdate = this.setLayout();

    // Plotly.update('graphDiv', dataUpdate, layoutUpdate);
  }
@@ -465,7 +461,6 @@ export class AnalyticsChartComponent implements OnInit, OnDestroy {
  }

  ngOnDestroy() {
    this.subscription.unsubscribe();
    this.themeSubscription.unsubscribe();
  }
}
+2 −2
Original line number Diff line number Diff line
<div class="filtersContainer" *ngIf="vm$ | async as vm">
  <ng-container *ngFor="let filter of vm.filters">
<div class="filtersContainer">
  <ng-container *ngFor="let filter of (filters$ | async)">
    <m-analytics__filter class="filter" [filter]="filter"></m-analytics__filter>
  </ng-container>
</div>
+3 −4
Original line number Diff line number Diff line
@@ -27,17 +27,16 @@ import {
})
export class AnalyticsFiltersComponent implements OnInit, OnDestroy {
  subscription: Subscription;
  vm$: Observable<UserState> = this.analyticsService.vm$;
  vm: UserState;

  filters$ = this.analyticsService.filters$;

  constructor(private analyticsService: AnalyticsDashboardService) {}

  ngOnInit() {
    // TODO: remove subscription because everything is happening in html
    // TODO: might even be fine to just get rid of this component and put it in dashboard.ts
    this.subscription = this.vm$.subscribe(viewModel => (this.vm = viewModel));
  }

  ngOnDestroy() {
    this.subscription.unsubscribe();
  }
}
+5 −4
Original line number Diff line number Diff line
@@ -39,14 +39,15 @@ export class AnalyticsMetricsComponent implements OnInit, OnDestroy {
  subscription: Subscription;

  //TODO: (maybe) interface ViewMetric implements Metric {}
  vm$: Observable<UserState> = this.analyticsService.vm$;
  metrics$;

  constructor(private analyticsService: AnalyticsDashboardService) {}

  ngOnInit() {
    this.metrics$ = this.vm$.pipe(map(vm => {
      const metrics = vm.metrics.map(metric => ({...metric})); // Clone to avoid updating
    this.metrics$ = this.analyticsService.metrics$
      .pipe(
        map(_metrics => {
      const metrics = _metrics.map(metric => ({...metric})); // Clone to avoid updating

      for (let metric of metrics) {
        const delta =
@@ -72,7 +73,7 @@ export class AnalyticsMetricsComponent implements OnInit, OnDestroy {
  }

  updateMetric(metric) {
    this.analyticsService.updateMetric(metric);
    this.analyticsService.updateMetric(metric.id);
  }

  ngOnDestroy() {
+3 −3
Original line number Diff line number Diff line
<div class="page" *ngIf="vm$ | async as vm" [ngClass]="{ isMobile: isMobile }">
<div class="page" [ngClass]="{ isMobile: isMobile }">
  <section class="sidebar">
    <h3>Analytics</h3>
    <div *ngIf="isMobile">{{ vm.category }}</div>
    <div *ngIf="isMobile">{{ category$ | async }}</div>
    <div class="catContainer">
      <i class="material-icons">menu</i>
      <div class="cat" *ngFor="let cat of cats">
        <span [ngClass]="{ selected: cat.id === vm.category }">{{
        <span [ngClass]="{ selected: cat.id === (category$ | async) }">{{
          cat?.label
        }}</span>
      </div>
Loading