Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions todo-src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,29 @@ <h1 class="text-center">My little to do app!</h1>
</div><!-- /input-group -->

<h2>stuff i gotta do asap</h2>

<!--Delete all completed tasks button-->
<div>
<button class="btn btn-info" type="button" ng-click="deleteCompleted()">
Delete Completed Tasks
</button>
</div>
<ul class="list-group">
<!-- http://www.w3schools.com/css/css_float.asp -->
<li class="list-group-item clearfix" ng-repeat="do in todos">
<li class="list-group-item clearfix" ng-repeat="do in todos" ng-class="{disabled: do.done}">

<span>{{do}}</span>
<button class="btn btn-danger pull-right" type="button" ng-click="deleteItem(do)">
<span class="glyphicon glyphicon-trash " aria-hidden="true"></span>
</button>
<span>{{do.name}}</span>
<span class="pull-right">

<!-- complete/uncomplete buttons -->
<button class="btn btn-success" ng-show="!do.done" ng-click="completeItem($index)">Done <span class="glyphicon glyphicon-ok"></span></button>
<button class="btn btn-success" ng-show="do.done" ng-click="uncompleteItem($index)">Undone <span class="glyphicon glyphicon-repeat"></span></button>

<button class="btn btn-danger" type="button" ng-click="deleteItem($index)">
<span class="glyphicon glyphicon-trash " aria-hidden="true"></span>
</button>


</span>

</li>
</ul>
Expand Down
26 changes: 22 additions & 4 deletions todo-src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,40 @@
var myApp = angular.module('app', []);

myApp.controller('MainCtrl', function ($scope){
$scope.todos = ["Learn Angular", "Learn node"];
$scope.todos = [{name: "Learn Angular", done:false}, {name: "Learn node", done:false}];
$scope.newItem = "";

$scope.addItem = function(){
console.log("in add");
if ($scope.newItem !== ""){
$scope.todos.push($scope.newItem);
var addItem = {name:$scope.newItem, done:false};
$scope.todos.push(addItem);
$scope.newItem = "";

}
}

$scope.deleteItem = function(item){
$scope.deleteItem = function(index){
console.log("in delete");
var index = $scope.todos.indexOf(item);
$scope.todos.splice(index, 1);
}

$scope.completeItem = function(index){
console.log("completed item");
$scope.todos[index].done = true;
}

$scope.uncompleteItem = function(index) {
console.log("uncompleted item");
$scope.todos[index].done = false;
}
//iterates through todos from back to front, deleting
//all entries that are tagged as finished
$scope.deleteCompleted = function() {
for (var i = $scope.todos.length - 1; i >= 0; i--) {
if($scope.todos[i].done) $scope.deleteItem(i);
};
}


});
Expand Down
2 changes: 1 addition & 1 deletion todo-src/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Styles go here */
body {
background: green;
}
}