Timers are now saved by cookies (limit 1). This should probably get changed to use IndexedDB later.

This commit is contained in:
William Brawner 2015-11-21 23:32:08 -06:00
parent 7ccbec3822
commit 7ff49cbde0
3 changed files with 189 additions and 178 deletions

View file

@ -9,7 +9,7 @@ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockq
}
body {
font-family: Helvetica;
font-family: Helvetica, Arial, sans-serif;
margin: -20px 0 0;
padding: 0;
height: 100vh;

View file

@ -34,16 +34,16 @@
<label>Timer Name:</label>
<input type="text" ng-model="timer.name">
<label>Warm Up:</label>
<input type="number" ng-model="warmUpTime">
<input type="number" ng-model="timer.warmUpTime">
<label>Low Intensity:</label>
<input type="number" ng-model="lowIntensityTime">
<input type="number" ng-model="timer.lowIntensityTime">
<label>High Intensity:</label>
<input type="number" ng-model="highIntensityTime">
<input type="number" ng-model="timer.highIntensityTime">
<label>Cool Down:</label>
<input type="number" ng-model="coolDownTime">
<input type="number" ng-model="timer.coolDownTime">
<label>Rounds:</label>
<input type="number" ng-model="timer.cycles">
<a class="form-button" id="save" ng-click="settingsOpen = false; closeSettings = true; time = warmUpTime; resetTimer()" href="#"> Save Changes</a>
<a class="form-button" id="save" ng-click="settingsOpen = false; closeSettings = true; time = warmUpTime; resetTimer(); saveTimer()" href="#"> Save Changes</a>
</form>
</div>
</body>

View file

@ -3,8 +3,7 @@
// }
(function() {
var app = angular.module('interval-timer', []);
var app = angular.module('interval-timer', [ 'ngCookies' ]);
// var db;
// var request = window.indexedDB.open("myTimers", 1);
// request.onerror = function(event) {
@ -23,55 +22,60 @@
// db = event.target.result;
// };
// var transaction = db.transaction(["timers"], "readwrite");
var timer = {
var defaultTimer = {
"name" : "Tabata",
"warm_up": 300,
"high_intensity" : 20,
"low_intensity" : 10,
"cool_down" : 300,
"warmUpTime": 300,
"highIntensityTime" : 20,
"lowIntensityTime" : 10,
"coolDownTime" : 300,
"cycles" : 8,
"repeat": 6
};
var countDown;
app.controller('timerCtrl', ['$scope', function($scope){
app.controller('timerCtrl', ['$scope', '$cookies', function($scope, $cookies) {
$scope.defaults = defaultTimer;
function getSavedTimer() {
var savedTimer = $cookies.getObject("timer");
console.log(typeof savedTimer == "object");
if (typeof savedTimer == "object") {
return savedTimer;
} else {
return $scope.defaults;
}
};
$scope.timer = getSavedTimer();
console.log($scope.timer);
$scope.lowIntensityBeep = new Audio('audio/beep-09.mp3');
$scope.highIntensityBeep = new Audio('audio/button-42(1).mp3');
$scope.coolDownBeep = new Audio('audio/beep-10.mp3');
$scope.round = 1;
$scope.cycle = 1;
$scope.timer = timer;
$scope.warmUpTime = timer.warm_up;
$scope.lowIntensityTime = timer.low_intensity;
$scope.highIntensityTime = timer.high_intensity;
$scope.coolDownTime = timer.cool_down;
$scope.warmUp = true;
$scope.time = $scope.warmUpTime;
$scope.round = 1;
$scope.time = $scope.timer.warmUpTime;
$scope.settingsOpen = false;
$scope.closeSettings = false;
$scope.setWarmUp = function() {
clearInterval($scope.countdown);
$scope.warmUp = true;
$scope.time = $scope.warmUpTime;
$scope.time = $scope.timer.warmUpTime;
$scope.startTimer();
}
$scope.setCoolDown = function() {
clearInterval($scope.countdown);
$scope.coolDown = true;
$scope.time = $scope.coolDownTime;
$scope.time = $scope.timer.coolDownTime;
$scope.coolDownBeep.play();
$scope.startTimer();
}
$scope.setLowIntensity = function() {
clearInterval($scope.countdown);
$scope.lowIntensity = true;
$scope.time = $scope.lowIntensityTime;
$scope.time = $scope.timer.lowIntensityTime;
$scope.lowIntensityBeep.play();
$scope.startTimer();
}
$scope.setHighIntensity = function() {
clearInterval($scope.countdown);
$scope.highIntensity = true;
$scope.time = $scope.highIntensityTime;
$scope.time = $scope.timer.highIntensityTime;
$scope.highIntensityBeep.play();
$scope.startTimer();
}
@ -174,7 +178,14 @@
$scope.highIntensity = false;
$scope.coolDown = false;
$scope.warmUp = true;
$scope.time = $scope.warmUpTime;
$scope.time = $scope.timer.warmUpTime;
};
$scope.saveTimer = function() {
console.log("Saved timer:");
console.log($scope.timer);
$cookies.putObject("timer", $scope.timer);
console.log("timer saved");
console.log($cookies.getObject("timer"));
};
}]);
})();