consumerportal
Version:
mydna Custimised for you
85 lines (68 loc) • 2.56 kB
text/typescript
/// <reference path="../../includes.ts" />
module app {
import IAuthenService = authenSrvc.IAuthenService;
import IUser = services.IUser;
class DietMealsController {
static $inject = [
'$scope',
'$routeParams',
'dietService',
'user'
];
details: any;
meals: any[];
menu: string = 'breakfast';
selected: any;
state: any;
public menuTabOpen: boolean = false;
public reportLabel: string;
public mealLabel: string;
public breakdown: any[];
public loaded: boolean = false;
public navigation: any[];
public menuTabs: any[];
constructor(
private $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.getMeals();
this.$scope.$on('dietMetricsChanged', () => {
this.getMeals();
});
$scope.$on('menuTabChanged', (ev: any, value: any) => {
this.setMenu(value.value);
});
}
getMeals() {
this.dietService.details(this.$routeParams.type).then((value: any) => {
this.details = value;
this.menuTabs = [];
this.details[this.details.goal].plan.Menus.forEach((menu: any) => {
this.menuTabs.push({value: menu.Reference, label: menu.Name})
});
this.setMenu(this.menu);
});
}
setMenu(value: string) {
this.menu = value;
this.selected = this.details[this.details.goal].plan.Menus.filter((m: any) => {
return m.Reference === value;
})[0];
this.selected.Meals.forEach((meal: any) => {
meal.Items = meal.Ingredients.split(' + ');
});
this.menuTabOpen = false;
this.mealLabel = this.menuTabs.filter((m: any) => {
return m.value === value;
})[0].label;
this.loaded = true;
}
}
angular
.module('app')
.controller('dietMealsCtrl', DietMealsController);
}