import { Component } from '@angular/core';

import { MapPage } from '../map/map';
import { SettingsPage } from '../settings/settings';
import { StatsPage } from '../stats/stats';
import { TripsPage } from '../trips/trips';
import { Trip } from '../../app/trip';

@Component({
  templateUrl: 'tabs.html'
})
export class TabsPage {
  mapRoot: any = MapPage;
  settingsRoot: any = SettingsPage;
  statsRoot: any = StatsPage;
  tripsRoot: any = TripsPage;
  unsubmittedTripsCount: number;

  constructor() {
  }

  ionViewWillEnter() {
    this.updateTripsBadge();
  }

  public updateTripsBadge() {
    Trip.objects.count('submitted = 0')
      .then((count) => this.unsubmittedTripsCount = (count > 0) ? count : null);
  }
}

import { Component } from '@angular/core';

import { MapPage } from '../map/map';
import { SettingsPage } from '../settings/settings';
import { StatsPage } from '../stats/stats';
import { TripsPage } from '../trips/trips';
import { Trip } from '../../app/trip';
import { Geo } from '../../app/geo';

@Component({
  templateUrl: 'tabs.html'
})
export class TabsPage {
  mapRoot: any = MapPage;
  settingsRoot: any = SettingsPage;
  statsRoot: any = StatsPage;
  tripsRoot: any = TripsPage;
  unsubmittedTripsCount: number;

  constructor(private geo: Geo) {
    geo.motion.subscribe(this.onMotion.bind(this));
  }

  ionViewWillEnter() {
    this.updateTripsBadge();
  }

  onMotion(moving) {
    if (!moving) this.updateTripsBadge();
  }

  public updateTripsBadge() {
    Trip.objects.count('submitted = 0')
      .then((count) => this.unsubmittedTripsCount = (count > 0) ? count : null);
  }
}

Update the trips badge when a trip ends.
Update the trips badge when a trip ends.
