diff --git a/app/css/app.less b/app/css/app.less index 80fe8b3..8dd1990 100755 --- a/app/css/app.less +++ b/app/css/app.less @@ -37,7 +37,7 @@ .app{ background: white; - color: #48C9AF; + /*color: #48C9AF;*/ } .error-message { diff --git a/app/index.html b/app/index.html index 0b12650..3e277b2 100755 --- a/app/index.html +++ b/app/index.html @@ -38,7 +38,7 @@

Performance Tracker

- +
diff --git a/app/js/app.js b/app/js/app.js index d307490..2caa64d 100755 --- a/app/js/app.js +++ b/app/js/app.js @@ -22,6 +22,13 @@ define([ 'n3-line-chart' ]) .controller('loginController', loginController) + .run(function($http) { + var username = sessionStorage.getItem("username"); + var password = sessionStorage.getItem("password"); + if (username && password) { + $http.defaults.headers.common.Authorization = 'Basic ' + btoa(username + ':' + password); + } + }) .config(routes) .config(['$httpProvider', function($httpProvider) { diff --git a/app/js/clients/clientsService.js b/app/js/clients/clientsService.js index 2799143..d5d30b7 100644 --- a/app/js/clients/clientsService.js +++ b/app/js/clients/clientsService.js @@ -11,14 +11,14 @@ define([], function() { return $http.get(BASE_URL + 'listClientsForLoggedInUser/json-user/.json'); }; - this.getClient = function(id) { - return $http.get(BASE_URL + 'listUser/json-user/.json?RFMscriptParam=' + id); + this.getClient = function(clientId) { + return $http.get(BASE_URL + 'listUser/json-user/.json?RFMscriptParam=' + clientId); }; - this.getExercises = function(id, period) { + this.getExercises = function(clientId, period) { var whenExercises = $q.defer(); - service.getClient(id).then(function() { + service.getClient(clientId).then(function() { $http.get(BASE_URL + 'listExercisesForClient/json-exerciseList/.json?RFMscriptParam=' + period).then(function(exercises) { whenExercises.resolve(exercises); }, @@ -34,6 +34,11 @@ define([], function() { return $http.get(BASE_URL + 'listReportPeriodOptions/ReportingPeriods/.json'); }; + this.getReport = function(exerciseId) { + var url = BASE_URL + "listHistoryForClientForExercise/json-history/.json?RFMscriptParam=" + exerciseId; + return $http.get(url); + } + }; return ['$http','$q', clientsService]; diff --git a/app/js/clients/exercisesController.js b/app/js/clients/exercisesController.js index 125caad..5061536 100755 --- a/app/js/clients/exercisesController.js +++ b/app/js/clients/exercisesController.js @@ -9,8 +9,23 @@ define([], function() { clientsService.getReportingPeriods().then(function(periods) { $scope.periods = periods.data.data; $scope.period = $scope.periods[0]; - }) - + console.log($scope.period); + clientsService.getExercises($routeParams.clientId, $scope.period.PeriodValueDays).then( + + function(exercises) { + $scope.exercises = exercises.data.data; + $scope.exercises.forEach(function(exercise) { + exercise.id = exercise['pk Exercise ID']; + exercise.name = exercise['Exercise Name']; + }); + }, + + function(error) { + $scope.exercisesError = error.data.info["X-RESTfm-FM-Reason"]; + } + ); + }); + clientsService.getClient($routeParams.clientId).then(function(client) { $scope.client = client.data.data[0]; $scope.client.name = $scope.client['Client Name']; @@ -19,25 +34,130 @@ define([], function() { $scope.client.id = $scope.client['pkClientID']; }); - clientsService.getExercises($routeParams.clientId, $scope.period).then( - - function(exercises) { - $scope.exercises = exercises.data.data; - $scope.exercises.forEach(function(exercise) { - exercise.id = exercise['pk Exercise ID']; - exercise.name = exercise['Exercise Name']; - }); - }, - function(error) { - $scope.exercisesError = error.data.info["X-RESTfm-FM-Reason"]; - } - ); $scope.setPeriod = function(period) { $scope.period = period; console.log($scope.period); - } + }; + + $scope.getReport = function(exerciseId) { + $scope.selectedExercise = exerciseId; + clientsService.getReport(exerciseId).then(function(response) { + var report = response.data.data; + console.log(report); + var dates = []; + + var timestamps = []; + var goToFailures = []; + var performances = []; + var currentWeights = []; + var netChangeWeights = []; + var timeUnderLoads = []; + var rangeOfMotions = []; + var outOfSequences = []; + + report.forEach(function(data, index) { + data["Date"] = new Date(data["Date"]).getTime(); + data["dateIndex"] = index; + dates.push(data["dateIndex"]); + var timeParts = data["Total Time"].split(":"); + var time = 60 * parseInt(timeParts[1]) + parseInt(timeParts[2]); + data["Total Time"] = time; + data["Current Weight"] = parseInt(data["Current Weight"]); + + var timestamp = new Date(data["Timestamp"]); + var hours = timestamp.getHours(); + if (hours == 0){ + timestamp = "12 AM"; + } else if (hours > 12) { + timestamp = (hours - 12) + " PM"; + } else { + timestamps = hours + " AM" + } + timestamps.push(timestamp); + goToFailures.push("N/A"); + outOfSequences.push("N/A"); + performances.push(data["performanceView"]); + currentWeights.push(data["Current Weight"]); + netChangeWeights.push(data["netChangeWeight"]? data["netChangeWeight"] + "%" : ""); + + var timeUnderLoadMinutes = Math.floor(data["Total Time"]/60); + var timeUnderLoadSeconds = data["Total Time"] % 60; + timeUnderLoads.push(timeUnderLoadMinutes + "m " + timeUnderLoadSeconds + "s"); + rangeOfMotions.push(data["Current Range"]); + + }); + + $scope.data = report; + $scope.timestamps = timestamps; + $scope.goToFailures = goToFailures; + $scope.performances = performances; + $scope.outOfSequences = outOfSequences; + $scope.currentWeights = currentWeights; + $scope.netChangeWeights = netChangeWeights; + $scope.timeUnderLoads = timeUnderLoads; + $scope.rangeOfMotions = rangeOfMotions; + + $scope.options = { + series: [{ + y: "Current Weight", + label: "Current Weight", + color: "#1871A4", + axis: "y2", + type: "line", + thickness: "3px", + dotSize: 10, + id: "series_0" + }, { + y: "Total Time", + label: "Time Under Load", + color: "#BFBFBF", + type: "column", + axis: "y", + id: "series_1" + }], + axes: { + x: { + type: "linear", + key: "dateIndex", + labelFunction: function(index) { + if (dates.indexOf(index) == -1) { + return ""; + } + var msTime = $scope.data[index].Date + var date = new Date(msTime); + + var dateParts = date.toString().split(" "); + var formattedDate = dateParts[1] + dateParts[2]; + return formattedDate; + } + }, + y: { + type: "linear", + labelFunction: function(seconds) { + var seconds = parseInt(seconds); + var minutes = Math.floor(seconds / 60); + var remainingSeconds = seconds - 60 * minutes; + return minutes.toString() + ":" + remainingSeconds.toString(); + } + }, + y2: { + type: "linear", + labelFunction: function(weight) { + return weight + " lbs" + } + } + }, + lineMode: "linear", + tension: 0.7, + drawLegend: true, + drawDots: true, + columnsHGap: 5 + }; + }); + }; + }; return ['$scope', '$routeParams', 'clientsService', exercisesController]; diff --git a/app/js/clients/partials/exercises.html b/app/js/clients/partials/exercises.html index a383cb9..deb379a 100644 --- a/app/js/clients/partials/exercises.html +++ b/app/js/clients/partials/exercises.html @@ -1,7 +1,6 @@ -
+

Report for -

- -
-
+
+

()

+
+
+ + + + + + + + + + + + + +
Timestamp
Go to Failure
Performance
Out of Sequence
+
+ +
+ + + + + + + + + + + + + +
Current Weight
Net Change Weight
Time Under Load
Range of Motion
+
+
\ No newline at end of file diff --git a/app/js/clients/styles/exercises.less b/app/js/clients/styles/exercises.less index bf688b3..ce7ecc4 100644 --- a/app/js/clients/styles/exercises.less +++ b/app/js/clients/styles/exercises.less @@ -1,31 +1,111 @@ #exercises { margin:10px; -} - -.exerciseName { - float: left; - width: 100px; - height: 75px; - border:1px solid gray; - text-align: center; - padding:5px; - &:hover { - background: gray; - cursor: pointer; + table { + margin:10px 0; + } + + td:not(:first-child) { + text-align: center; + font-size: 9pt; + font-weight: bold; + } + + .topTable { + tr:first-child td:not(:first-child) { + border-top: 1px black solid; + background-color: #FCF99F; + } + tr:nth-child(2) td:not(:first-child){ + background-color: #B6E494; + } + tr:nth-child(3) td:not(:first-child){ + background-color: #9CE05A; + } + tr:nth-child(4) td:not(:first-child){ + background-color: #FDA18B; + } + td { + width: 65px; + white-space: nowrap; + } + td:first-child { + border:none; + font-size: 12pt; + } + + td:nth-child(2) { + border-left: 1px lightgray dashed; + } + td { + border: 1px black dashed; + } + td:last-child { + border-right: 1px lightgray dashed; + } + } + + .bottomTable { + tr:first-child td:not(:first-child) { + border-top: none; + background-color: white; + } + tr:nth-child(2) td:not(:first-child){ + background-color: #ADBB8C; + } + tr:nth-child(3) td:not(:first-child){ + background-color: white; + } + tr:nth-child(4) td:not(:first-child){ + background-color: #A0EEEA; + } + td { + width: 65px; + white-space: nowrap; + } + td:first-child { + border:none; + font-size: 12pt; + } + + /*td:nth-child(2) { + border-left: 1px lightgray dashed; + }*/ + td { + border: 1px lightgray solid; + } + td:last-child { + border-right: 1px lightgray dashed; + } } -} -.reportHeader { - text-align: center; - li { - text-align: left; + .exerciseName { + float: left; + width: 100px; + height: 60px; + border:1px solid gray; + text-align: center; + padding:5px; + + &:hover, &.active { + background: gray; + cursor: pointer; + } + + } + + .reportHeader { + text-align: center; + + li { + text-align: left; + } } -} -.exercisesError { - text-align: center; - color:black; + .exercisesError { + text-align: center; + color:black; + } } \ No newline at end of file diff --git a/app/js/loginController.js b/app/js/loginController.js index 96191d9..d094c0d 100755 --- a/app/js/loginController.js +++ b/app/js/loginController.js @@ -16,10 +16,16 @@ define([], function() { }); $scope.login = function(username, password) { + setSession(username, password); $http.defaults.headers.common.Authorization = 'Basic ' + btoa(username + ':' + password); $location.path('/clients'); }; + function setSession(username, password) { + sessionStorage.setItem("username", username); + sessionStorage.setItem("password", password); + } + function showErrorMessage(message) { $scope.errorMessage = message; diff --git a/app/js/main.js b/app/js/main.js index 9e289aa..8acff17 100644 --- a/app/js/main.js +++ b/app/js/main.js @@ -42,14 +42,13 @@ require([ ], function(angular, app, routes, mockBackend) { var isDevMode = false; - + $(function() { - if(isDevMode){ - angular.bootstrap($('#myApp'), ['myApp', mockBackend]); - } - else { - angular.bootstrap($('#myApp'), ['myApp']); - } + var appModules = ['myApp']; + if (isDevMode) { + appModules.push(mockBackend); + } + angular.bootstrap($('#myApp'), appModules); }); - + }); \ No newline at end of file diff --git a/app/js/mockBackend/exerciseReport.js b/app/js/mockBackend/exerciseReport.js new file mode 100644 index 0000000..1193830 --- /dev/null +++ b/app/js/mockBackend/exerciseReport.js @@ -0,0 +1,119 @@ +define([], function() { + return { + "data": [ + { + "Timestamp": "11\/26\/2012 15:29:19", + "oosView": "", + "Exercise Name": "Leg Press", + "fkClientID": "client506", + "Exercise ID": "exercise145", + "fk Studio ID": "studio13", + "netChangeWeight": "", + "Current Weight": "170", + "performanceView": "D", + "Date": "11\/26\/2012", + "fk Client Name": "Blaine Hart", + "Total Time": "00:02:26", + "Current Range": "", + "dayOfWeek": "Mon", + "hourOfDay": "3 PM" + }, { + "Timestamp": "12\/10\/2012 15:31:34", + "oosView": "", + "Exercise Name": "Leg Press", + "fkClientID": "client506", + "Exercise ID": "exercise145", + "fk Studio ID": "studio13", + "netChangeWeight": "", + "Current Weight": "170", + "performanceView": "D", + "Date": "12\/10\/2012", + "fk Client Name": "Blaine Hart", + "Total Time": "00:02:23", + "Current Range": "", + "dayOfWeek": "Mon", + "hourOfDay": "3 PM" + }, + { + "Timestamp": "09\/11\/2013 13:58:26", + "oosView": "", + "Exercise Name": "Leg Press", + "fkClientID": "client506", + "Exercise ID": "exercise145", + "fk Studio ID": "studio13", + "netChangeWeight": "-13", + "Current Weight": "150", + "performanceView": "D", + "Date": "09\/11\/2013", + "fk Client Name": "Blaine Hart", + "Total Time": "00:03:15", + "Current Range": "", + "dayOfWeek": "Wed", + "hourOfDay": "1 PM" + }, { + "Timestamp": "09\/16\/2013 14:29:29", + "oosView": "", + "Exercise Name": "Leg Press", + "fkClientID": "client506", + "Exercise ID": "exercise145", + "fk Studio ID": "studio13", + "netChangeWeight": "3", + "Current Weight": "155", + "performanceView": "D", + "Date": "09\/16\/2013", + "fk Client Name": "Blaine Hart", + "Total Time": "00:03:14", + "Current Range": "", + "dayOfWeek": "Mon", + "hourOfDay": "2 PM" + }, { + "Timestamp": "09\/18\/2013 14:24:09", + "oosView": "", + "Exercise Name": "Leg Press", + "fkClientID": "client506", + "Exercise ID": "exercise145", + "fk Studio ID": "studio13", + "netChangeWeight": "1", + "Current Weight": "157", + "performanceView": "D", + "Date": "09\/18\/2013", + "fk Client Name": "Blaine Hart", + "Total Time": "00:03:11", + "Current Range": "", + "dayOfWeek": "Wed", + "hourOfDay": "2 PM" + }, { + "Timestamp": "09\/23\/2013 14:32:03", + "oosView": "", + "Exercise Name": "Leg Press", + "fkClientID": "client506", + "Exercise ID": "exercise145", + "fk Studio ID": "studio13", + "netChangeWeight": "", + "Current Weight": "157", + "performanceView": "D", + "Date": "09\/23\/2013", + "fk Client Name": "Blaine Hart", + "Total Time": "00:03:10", + "Current Range": "", + "dayOfWeek": "Mon", + "hourOfDay": "2 PM" + }, { + "Timestamp": "09\/25\/2013 14:24:38", + "oosView": "", + "Exercise Name": "Leg Press", + "fkClientID": "client506", + "Exercise ID": "exercise145", + "fk Studio ID": "studio13", + "netChangeWeight": "5", + "Current Weight": "165", + "performanceView": "D", + "Date": "09\/25\/2013", + "fk Client Name": "Blaine Hart", + "Total Time": "00:03:07", + "Current Range": "", + "dayOfWeek": "Wed", + "hourOfDay": "2 PM" + }] + }; +}); \ No newline at end of file diff --git a/app/js/mockBackend/mockBackendRunner.js b/app/js/mockBackend/mockBackendRunner.js index a36d9df..5ee20a4 100644 --- a/app/js/mockBackend/mockBackendRunner.js +++ b/app/js/mockBackend/mockBackendRunner.js @@ -3,21 +3,27 @@ define([ 'app', 'mockBackend/clientList', 'mockBackend/clientExercises', + 'mockBackend/reportingPeriods', + 'mockBackend/exerciseReport', 'angularMocks' -], function(angular, app, clients, clientExercises) { +], function(angular, app, clients, clientExercises, reportingPeriods, exerciseReport) { var mockBackendRunner = function($httpBackend) { - var BASE_URL = 'http://pt.trackformance.com/RESTfm/PT_Demo/script/'; - var clientListURL = BASE_URL + 'listClientsForLoggedInUser/json-user/.json'; - var clientURL = BASE_URL + 'listUser/json-user/.json?' - +'RFMscriptParam=client39'; - var clientExercisesURL = BASE_URL + 'listExercisesForClient/json-exerciseList/.json?' - + 'RFMscriptParam=client39'; + + var clientListURL = /listClientsForLoggedInUser\/json-user/; + var clientURL = /listUser\/json-user/; + var clientExercisesURL = /listExercisesForClient\/json-exerciseList/; + var reportingPeriodsURL = /listReportPeriodOptions\/ReportingPeriods/; + var exerciseReportURL = /listHistoryForClientForExercise\/json-history/; + var templateUrl = /partials\//; + $httpBackend.whenGET(clientExercisesURL).respond(clientExercises); $httpBackend.whenGET(clientURL).respond(clients); $httpBackend.whenGET(clientListURL).respond(clients); - $httpBackend.whenGET(/partials\//).passThrough(); - + $httpBackend.whenGET(reportingPeriodsURL).respond(reportingPeriods); + $httpBackend.whenGET(exerciseReportURL).respond(exerciseReport); + + $httpBackend.whenGET(templateUrl).passThrough(); }; return ['$httpBackend', mockBackendRunner]; diff --git a/app/js/mockBackend/reportingPeriods.js b/app/js/mockBackend/reportingPeriods.js new file mode 100644 index 0000000..b61e902 --- /dev/null +++ b/app/js/mockBackend/reportingPeriods.js @@ -0,0 +1,11 @@ +define([], function() { + return { + "data": [{ + "PeriodName": "Lifetime", + "PeriodValueDays": "0" + }, { + "PeriodName": "Previous 3 Months", + "PeriodValueDays": "90" + }] + }; +}); \ No newline at end of file