Skip to content

Commit

Permalink
added sets
Browse files Browse the repository at this point in the history
  • Loading branch information
braungoodson committed May 31, 2014
1 parent 1e161eb commit 6201a90
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 32 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Workout Logger [![Build Status](https://magnum.travis-ci.com/braungoodson/workout-logger.svg?token=JbnN2yM8JStKWMsVBT8a&branch=develop)](https://magnum.travis-ci.com/braungoodson/workout-logger)
======

$ mongod --dbpath ./data/db --directoryperdb &
...
$ npm install
...
$ npm start
Expand Down
8 changes: 8 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.input-group {
margin-bottom:15px;
}

.hydrate {
color:white;
}

.escape-buffer {
margin-bottom:0px;
}
34 changes: 28 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var app = angular.module('app',['ngRoute']);

app.config(['$routeProvider',Router]);
app.controller('WorkoutsCreateController',['$scope','$http','$location',WorkoutsCreateController]);
app.controller('SetsCreateController',['$scope','$location',SetsCreateController]);
app.controller('SetsCreateController',['$scope','$location','$http',SetsCreateController]);

function Router ($routeProvider) {
$routeProvider.when('/',{templateUrl:'views/index.html'});
Expand All @@ -22,14 +22,36 @@ function WorkoutsCreateController ($scope,$http,$location) {
}
}

function SetsCreateController ($scope,$location) {
function SetsCreateController ($scope,$location,$http) {
$scope.workout = {};
$scope.hydrate = false;
$scope.hydrateWorkout = false;
$scope.sets = [];
$scope.hydrateSets = false;
if ($location.hash()) {
$scope.hydrate = true;
$scope.hydrateWorkout = true;
$scope.workout = JSON.parse($location.hash());
$scope.workout.digest = function () {
var d = "";
d += " for ";
d += new Date($scope.workout.start).getMonth() + '/';
d += new Date($scope.workout.start).getDate() + '/';
d += new Date($scope.workout.start).getFullYear() + ' @ ';
d += new Date($scope.workout.start).getHours() > 12 ? new Date($scope.workout.start).getHours() - 12 : new Date($scope.workout.start).getHours();
d += new Date($scope.workout.start).getHours() > 12 ? 'PM-' : 'AM-';
d += new Date($scope.workout.end).getHours() > 12 ? new Date($scope.workout.end).getHours() - 12 : new Date($scope.workout.end).getHours();
d += new Date($scope.workout.end).getHours() > 12 ? 'PM' : 'AM';
return d;
}
}
$scope.onSubmit = function () {
$http.post('/sets',$scope.set).success(function(){}).error(function(){});
$scope.onSubmit = function (queue) {
$scope.set.wid = $scope.workout._id;
$http.post('/sets',$scope.set).success(function(data){
if (!$scope.hydrateSets) {
$scope.hydrateSets = true;
}
$scope.sets.push(data);
}).error(function(){
throw new Error(arguments);
});
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "./node_modules/karma/bin/karma start --single-run",
"test": "./node_modules/karma/bin/karma start --no-single-run",
"start": "node server.js",
"postinstall": "./node_modules/bower/bin/bower install && mkdir -p ./data/db"
},
Expand Down
23 changes: 18 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ var express = require('express'),
port = process.env.PORT || 30000,
staticRoot = __dirname;

console.log('configuring database');

dataClient.connect('mongodb://localhost:27017/workoutlogger',function(e,db){
function dataClient_connectHandler (e,db){
if (e) {
throw new Error(e);
} else {
console.log('connected to database');
dataClient.db = db;
dataClient.workouts = db.collection('workouts');
dataClient.sets = db.collection('sets');
configServer();
}
});
}

function configServer () {
console.log('configuring server');
Expand All @@ -36,4 +35,18 @@ function configServer () {
}
});
});
}
server.post('/sets',function(q,r){
var set = q.body;
dataClient.sets.insert(set,function(e,sets){
if (e) {
r.send({error:e});
throw new Error(e);
} else {
r.send(sets[0]);
}
})
});
}

console.log('configuring database');
dataClient.connect('mongodb://localhost:27017/workoutlogger',dataClient_connectHandler);
53 changes: 33 additions & 20 deletions views/sets/create.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
<div class="panel panel-default" ng-controller="SetsCreateController">
<div class="panel-heading">Create Set</div>
<div class="panel-body">
<form class="navbar-form navbar-left" role="search" ng-submit="onSubmit();">
<section ng-controller="SetsCreateController">
<div class="panel panel-default">
<div class="panel-heading">Create Set<span ng-show="hydrateWorkout" class="hydrate">{{workout.digest()}}</span></div>
<div class="panel-body">
<form class="navbar-form navbar-left escpae-buffer" role="search" ng-submit="onSubmit();" name="setForm">

<div class="input-group">
<span class="input-group-addon">Name</span>
<input type="text" class="form-control" placeholder="Flat Bench Press" ng-model="set.name" required>
</div>
<div class="input-group">
<span class="input-group-addon">Name</span>
<input type="text" class="form-control" placeholder="Flat Bench Press" ng-model="set.name" required>
</div>

<div class="input-group">
<input type="text" class="form-control" placeholder="225" ng-model="set.weight" required>
<span class="input-group-addon">lbs/kgs</span>
<span class="input-group-addon">X</span>
<input type="text" class="form-control" placeholder="12" ng-model="set.X" required>
</div>
<div class="input-group">
<input type="text" class="form-control" placeholder="225" ng-model="set.weight" required>
<span class="input-group-addon">lbs/kgs</span>
<span class="input-group-addon">X</span>
<input type="text" class="form-control" placeholder="12" ng-model="set.X" required>
</div>

<div class="input-group">
<input type="submit" class="btn btn-default" />
<span ng-show="hydrate"> {{workout}}</span>
</div>
<div class="input-group escape-buffer">
<input type="submit" class="btn btn-default" />
</div>

</form>
</form>
</div>
<table class="table" ng-show="hydrateSets">
<tr>
<th>Name</th>
<th>lbs/kg</th>
<th>X</th>
</tr>
<tr ng-repeat="s in sets">
<td>{{s.name}}</td>
<td>{{s.weight}}</td>
<td>{{s.X}}</td>
</tr>
</table>
</div>
</div>
</section>

0 comments on commit 6201a90

Please sign in to comment.