UNPKG

consumerportal

Version:

mydna Custimised for you

83 lines (66 loc) 2.52 kB
/// <reference path="../../includes.ts" /> module app { import IUser = services.IUser; class DietServingsController { details: any; state: any; public servings: any[]; public loaded: boolean = false; public type: string = 'vegetables'; public selected: any; public navigation: any[]; public reportLabel: string; public icons: any = { vegetables: 'dietVegetable', fruit: 'dietFruit', grains: 'dietGrain', meatandmeatalternatives: 'dietMeat', dairyanddairyalternatives: 'dietDairy', healthyfat: 'dietFat' }; public types: any[] = [ {value: 'vegetables', label: 'Vegetables'}, {value: 'fruit', label: 'Fruit'}, {value: 'grains', label: 'Grains'}, {value: 'meatandmeatalternatives', label: 'Meat'}, {value: 'dairyanddairyalternatives', label: 'Dairy'}, {value: 'healthyfat', label: 'Healthy Fat'}, ]; static $inject = [ '$scope', '$routeParams', 'dietService', 'user' ]; constructor( $scope: angular.IScope, private $routeParams: angular.route.IRouteParamsService, private dietService: services.IDietService, public user: IUser ) { this.navigation = this.dietService.navigation($routeParams.type); this.reportLabel = this.dietService.getWeightOverride($routeParams.type); this.getServings(); $scope.$on('dietMetricsChanged', (ev:any) => { this.getServings(); }); $scope.$on('typeTabChanged', (ev: any, value: any) => { this.setType(value.value); }); } getServings() { this.dietService.details(this.$routeParams.type).then((value: any) => { this.details = value; this.setType(this.type); this.loaded = true; }) } setType(value: string) { this.type = value; this.selected = this.details[this.details.goal].servings.filter((s: any) => { return s.Reference == this.type; })[0]; } } angular.module('app').controller('dietServingsCtrl', DietServingsController); }