From 3375a736fff39dfe0dd9fc9c7750dd3ed4207608 Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Thu, 20 Apr 2017 09:49:26 +0300 Subject: [PATCH] Finished --- app/app.js | 1 + app/details.ctrl.js | 12 +++++++++++- app/details.html | 3 +++ app/list.ctrl.js | 30 +++++++++++++++++++++++++++++- app/list.html | 9 +++++++++ app/routes.js | 2 +- data/db.json | 12 ++++++------ index.html | 15 ++++++++++++--- 8 files changed, 72 insertions(+), 12 deletions(-) diff --git a/app/app.js b/app/app.js index 5169565..97e83a3 100644 --- a/app/app.js +++ b/app/app.js @@ -1,6 +1,7 @@ (function () { 'use strict'; + var app = angular.module('app', ['ngRoute']); })(); diff --git a/app/details.ctrl.js b/app/details.ctrl.js index f77a545..194a524 100644 --- a/app/details.ctrl.js +++ b/app/details.ctrl.js @@ -3,8 +3,18 @@ angular.module('app').controller('DetailsCtrl', Ctrl); - function Ctrl() { + function Ctrl($http, $routeParams, $location) { + var vm = this; + vm.item = {}; + vm.back = back; + $http.get('api/tasks/'+$routeParams.id).then(function (resp) { + vm.item = resp.data; + }); + + function back() { + $location.path('/list'); + } } })(); diff --git a/app/details.html b/app/details.html index e69de29..8731a93 100644 --- a/app/details.html +++ b/app/details.html @@ -0,0 +1,3 @@ +Title: {{ vm.item.title }}
+Time: {{ vm.item.added | date: "HH:mm"}} + diff --git a/app/list.ctrl.js b/app/list.ctrl.js index 18d73d3..4b8f84f 100644 --- a/app/list.ctrl.js +++ b/app/list.ctrl.js @@ -3,8 +3,36 @@ angular.module('app').controller('ListCtrl', Ctrl); - function Ctrl() { + function Ctrl($http, modalService) { + var vm = this; + vm.items = [{ title: "hello", done: false }]; + vm.newItem = ''; + vm.addNew = addNew; + vm.removeItem = removeItem; + + pullItems(); + function pullItems() { + $http.get('api/tasks').then(function(resp) { + vm.items = resp.data; + }); + }; + + function removeItem(id) { + modalService.confirm() + .then(function() { + return $http.delete('api/tasks/'+id); + }).then(pullItems); + } + + function addNew () { + var item = {title:this.newItem, done:false}; + + $http.post('api/tasks', item).then(pullItems); + + //this.items.push(item); + vm.newItem = ''; + } } })(); diff --git a/app/list.html b/app/list.html index e69de29..2ed236c 100644 --- a/app/list.html +++ b/app/list.html @@ -0,0 +1,9 @@ +
+ + {{ item.title }} + + + +
+ + diff --git a/app/routes.js b/app/routes.js index 55514c4..b5569ef 100644 --- a/app/routes.js +++ b/app/routes.js @@ -17,4 +17,4 @@ } -})(); \ No newline at end of file +})(); diff --git a/data/db.json b/data/db.json index ba09ed9..7afd90c 100644 --- a/data/db.json +++ b/data/db.json @@ -1,14 +1,14 @@ { "tasks": [ { - "title": "Call Jill", - "added": "2017-03-13T09:46:46.127Z", - "_id": 1 + "title": "sadfasdf", + "done": false, + "_id": 5 }, { - "title": "Write to John", - "added": "2017-03-13T10:09:38.867Z", - "_id": 4 + "title": "asdf", + "done": false, + "_id": 6 } ] } \ No newline at end of file diff --git a/index.html b/index.html index d11db3a..637b1e9 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,5 @@ - + Ng1 @@ -9,13 +9,22 @@ - +
- + + + + + +