UNPKG

consumerportal

Version:

mydna Custimised for you

108 lines (89 loc) 4.99 kB
/// <reference path="../../includes.ts" /> module app { import IUser = services.IUser; import ISportsDetails = services.ISportsDetails; class SportsDashboardController { static $inject = [ '$scope', '$timeout', 'sportsService', 'user' ]; public details: ISportsDetails; public loaded: boolean = false; public powerEndurance: any = {}; public allRounder: boolean; public stamina: any = {}; public injury: any = {}; public recovery: any = {}; public selected: any; public navigation: any[] = this.sportsService.navigation(); constructor( $scope: angular.IScope, $timeout: any, private sportsService: services.ISportsService, public user: IUser ) { $scope.$on('selectDay', (ev: any, day: number) => { //window.location.hash = "#/sports/training"; }); sportsService.details().then((value: ISportsDetails) => { this.details = value; this.loaded = true; let power: string[] = [ `Your muscles are well-equipped to work at full power and grow in size`, `With the right training, you can be suited to both power and endurance sports`, `Your muscles are best suited to slow and steady exercise` ]; let stamina: string[] = [ `You aerobic fitness is naturally low. You might have to work harder than others to improve your stamina.`, `Your aerobic fitness is not naturally high, but you can increase it with targetted training.`, `Your aerobic fitness is naturally high and can be easily improved with training.` ]; let injury: string[] = [ `Your generics protect you somewhat from soft tissue injury, but you should still take care when exercising.`, `You have a normal risk of soft tissue injury and should exercise with care.`, `You have a greater risk of soft tissue injury and should exercise with particular care.` ]; let recovery: string[] = [ `You have a high chance of experiencing muscle soreness after exercise and may need longer recovery times between training sessions.`, `You may experience muscle soreness after intense exercise and you many need to adapt recovery time between training sessions accordingly.`, `Muscle soreness after intense exercise is not expected to be a major issue for you and you should be able to exercise on most days.` ]; let powerResult: number = value.Profile.Power < 40 ? 2 : value.Profile.Power <= 50 ? 1 : 0; let needle: number[] = [10, 50, 90]; let levels: string[] = ['bad', 'okay', 'good']; this.powerEndurance = { value: 0, result: '' }; this.stamina = { value: 0, result: '' }; this.injury = { value: 0, result: '' }; this.recovery = { value: 0, result: '' }; $timeout(() => { this.powerEndurance = { value: value.Profile.Power, result: power[powerResult] }; this.allRounder = value.PowerEndurance === 'all-rounder'; $('.adjust-left').attr('style', 'left: calc(' + this.powerEndurance.value + '% - 75px); left: -webkit-calc(' + this.powerEndurance.value + '% - 75px)'); $('.adjust-arrow').attr('style', 'left: ' + this.powerEndurance.value + '%'); $('.adjust-power').attr('style', 'width: ' + this.powerEndurance.value + '%'); $('.adjust-endurance').attr('style', 'width: ' + (100 - this.powerEndurance.value) + '%'); }, 500); $timeout(() => { let s: number = value.Profile.Stamina; this.stamina = { value: needle[s], result: stamina[s], level: levels[s] }; }, 1000); $timeout(() => { let i: number = value.Profile.Injury; this.injury = { value: needle[i], result: injury[i], level: levels[2-i] }; }, 1500); $timeout(() => { let r: number = value.Profile.Recovery; this.recovery = { value: needle[r], result: recovery[r], level: levels[r] }; }, 2000); }); } } angular.module('app').controller('sportsDashboardCtrl', SportsDashboardController); }