Skip to content

Commit

Permalink
added solved mark to board; it works! gotta write more tests to prove it
Browse files Browse the repository at this point in the history
  • Loading branch information
buzzdecafe committed Nov 8, 2013
1 parent eb877c8 commit dfba854
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
6 changes: 0 additions & 6 deletions app/js/controllers/boardCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ angular.module('kinghunt.controllers').

$scope.setStatus = function(status) {
$scope.status = status;
// side effects:
if (status.progress === "SOLVED") {
bookSvc.markSolved($scope.currentId, true);
} else if (status.progress === "FAILED") {
bookSvc.markSolved($scope.currentId, false);
}
};

$scope.pieces = ['q', 'r', 'b', 'n'];
Expand Down
8 changes: 4 additions & 4 deletions app/js/directives/solvedMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ angular.module('kinghunt.directives').
return {
restrict: 'C',
replace: true,
template: '<button class="pull-right btn btn-default"><span class="glyphicon {{ solved[problem.id] | toProblemClass }}"></span></button>',
template: '<button class="pull-right btn btn-default"><span class="glyphicon {{ problemSolved | toProblemClass }}"></span></button>',
link: function(scope, element, attrs) {
// update model
scope.problemSolved = bookSvc.isSolved(scope.problem.id);
element.on('click', function(e) {
var id = scope.problem.id;
var icon = element.find("span.glyphicon");
var solvedProblem = icon.is(".solved");
bookSvc.markSolved(id, !solvedProblem);
scope.problemSolved = !element.find("span.glyphicon").is(".solved");
bookSvc.markSolved(id, scope.problemSolved);
scope.$apply();
});
}
Expand Down
26 changes: 22 additions & 4 deletions app/js/services/bookSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,40 @@ angular.module('kinghunt.services').

getNext: function(id) {
var problems = book.problems;
var i, flen;
var i, j, flen;
for (i = 0, flen = problems.length; i < flen; i++) {
if (problems[i].id === id) {
return (problems[i + 1]) ? problems[i + 1] : null;
if (skipSolved) {
for (j = i + 1; j < problems.length; j++) {
if (!solved[problems[j].id]) {
return problems[j];
}
}
} else {
return (problems[i + 1]) ? problems[i + 1] : null;
}
}
}
return null;
},

getPrev: function(id) {
var problems = book.problems;
var i, flen;
var i, j, flen;
for (i = 0, flen = problems.length; i < flen; i++) {
if (problems[i].id === id) {
return (problems[i - 1]) ? problems[i - 1] : null;
if (skipSolved) {
for (j = i - 1; j > -1; j--) {
if (!solved[problems[j].id]) {
return problems[j];
}
}
} else {
return (problems[i - 1]) ? problems[i - 1] : null;
}
}
}
return null;
},

getSolved: function() {
Expand Down
1 change: 1 addition & 0 deletions app/partials/board.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="info">
<button class="solvedMark"></button>
<h4 id="goal">{{ problem.fen | whoseTurn }} to play and {{ goal | translateStipulation }}</h4>
<div class="author">{{ problem.author }}</div>
<div class="solveStatus"></div>
Expand Down

0 comments on commit dfba854

Please sign in to comment.