diff --git a/app/app.js b/app/app.js new file mode 100644 index 0000000..9f012f3 --- /dev/null +++ b/app/app.js @@ -0,0 +1,6 @@ +(function () { + 'use strict'; + + angular.module('app', ['ngRoute']); +})(); + diff --git a/app/details.ctrl.js b/app/details.ctrl.js new file mode 100644 index 0000000..18b9602 --- /dev/null +++ b/app/details.ctrl.js @@ -0,0 +1,27 @@ +(function () { + 'use strict'; + + angular.module('app').controller('DetailsCtrl', Ctrl); + + function Ctrl($http, $routeParams, $location) { + var vm = this; + + vm.task = {}; + vm.back = back; + + init(); + + function init() { + $http.get('api/tasks/' + $routeParams.id).then(function (result) { + vm.task = result.data; + }); + } + + function back() { + $location.path('/list'); + } + + } + +})(); + diff --git a/app/details.html b/app/details.html new file mode 100644 index 0000000..9416c17 --- /dev/null +++ b/app/details.html @@ -0,0 +1,4 @@ +Title: {{ vm.task.title }}
+Added: {{ vm.task.added | date : 'HH:mm' }} +

+ diff --git a/app/list.ctrl.js b/app/list.ctrl.js new file mode 100644 index 0000000..0ad8f8c --- /dev/null +++ b/app/list.ctrl.js @@ -0,0 +1,41 @@ +(function () { + 'use strict'; + + angular.module('app').controller('ListCtrl', Ctrl); + + function Ctrl($http, modalService) { + var vm = this; + vm.tasks = []; + vm.newTitle = ''; + + vm.addTask = addTask; + vm.removeTask = removeTask; + + init(); + + function init() { + $http.get('api/tasks').then(function (result) { + vm.tasks = result.data; + }); + } + + function addTask() { + var newTask = { + title: vm.newTitle, + added: new Date() + }; + + $http.post('api/tasks', newTask).then(init); + + vm.newTitle = ''; + } + + function removeTask(id) { + modalService.confirm() + .then(function () { + return $http.delete('api/tasks/' + id); + }).then(init); + } + } +})(); + diff --git a/app/list.html b/app/list.html new file mode 100644 index 0000000..b6f7a05 --- /dev/null +++ b/app/list.html @@ -0,0 +1,9 @@ +
+ {{ task.title }} + X +

+ + + + + diff --git a/app/modal.html b/app/modal.html new file mode 100644 index 0000000..ea619af --- /dev/null +++ b/app/modal.html @@ -0,0 +1,13 @@ +
+
+ + Oled kindel? + +

+ + Jah | + Ei + +
+
+ diff --git a/app/modal.srv.js b/app/modal.srv.js new file mode 100644 index 0000000..728883d --- /dev/null +++ b/app/modal.srv.js @@ -0,0 +1,53 @@ +(function () { + 'use strict'; + + angular.module('app').service('modalService', Srv); + + Srv.$inject = ['$q', '$document', '$http', '$compile', '$rootScope']; + + function Srv($q, $document, $http, $compile, $rootScope) { + + this.confirm = confirm; + + var modal; + var scope; + + function confirm() { + if (modal) { + return showModal(); + } + + return $http.get('app/modal.html').then(function (result) { + createModalElement(result.data); + return showModal(); + }); + } + + function showModal() { + var deferred = $q.defer(); + + scope.ok = function () { + modal.addClass('hide'); + deferred.resolve(); + }; + + scope.cancel = function () { + modal.addClass('hide'); + deferred.reject(); + }; + + modal.removeClass('hide'); + + return deferred.promise; + } + + function createModalElement(html) { + var body = angular.element($document[0].body); + var containerElement = angular.element(html); + scope = $rootScope.$new(); + modal = $compile(containerElement[0])(scope); + body.append(modal); + } + } + +})(); diff --git a/app/routes.js b/app/routes.js new file mode 100644 index 0000000..55514c4 --- /dev/null +++ b/app/routes.js @@ -0,0 +1,20 @@ +(function () { + 'use strict'; + + angular.module('app').config(RouteConfig); + + function RouteConfig($routeProvider) { + + $routeProvider.when('/list', { + templateUrl : 'app/list.html', + controller : 'ListCtrl', + controllerAs : 'vm' + }).when('/details/:id', { + templateUrl : 'app/details.html', + controller : 'DetailsCtrl', + controllerAs : 'vm' + }).otherwise('/list'); + + } + +})(); \ No newline at end of file diff --git a/data/db.json b/data/db.json index 50ffbb9..ba09ed9 100644 --- a/data/db.json +++ b/data/db.json @@ -1,3 +1,14 @@ { - "tasks": [] -} + "tasks": [ + { + "title": "Call Jill", + "added": "2017-03-13T09:46:46.127Z", + "_id": 1 + }, + { + "title": "Write to John", + "added": "2017-03-13T10:09:38.867Z", + "_id": 4 + } + ] +} \ No newline at end of file diff --git a/index.html b/index.html index bb8b71a..44a4268 100644 --- a/index.html +++ b/index.html @@ -8,13 +8,20 @@ -Hello! +
+ + + + + +