-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
83 lines (71 loc) · 2.72 KB
/
app.js
File metadata and controls
83 lines (71 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(function () {
"use strict";
angular.module("NarrowItDownApp", [])
.controller("NarrowItDownController", NarrowItDownController)
.service("MenuSearchService", MenuSearchService)
.directive("foundItems", FoundItemsDirective)
.constant('ApiBasePath', "https://davids-restaurant.herokuapp.com");
function FoundItemsDirective() {
return {
templateUrl: "templates/foundItems.html",
scope: {
items: '<',
message: '@message',
onRemove: '&'
},
controller: FoundItemsDirectiveController,
controllerAs: 'list',
bindToController: true
};
}
function FoundItemsDirectiveController() {
const list = this;
list.nothingInList = function () {
return list.items.length === 0
};
}
NarrowItDownController.$inject = ['MenuSearchService'];
function NarrowItDownController(MenuSearchService) {
const ctrl = this;
ctrl.found=[];
ctrl.searchTerm = "";
ctrl.search = function () {
ctrl.found = [];
ctrl.warning = "";
if (ctrl.searchTerm !=="" ) {
MenuSearchService.getMatchedMenuItems(ctrl.searchTerm)
.then(function (items) {
ctrl.found = items;
if (items.length === 0) {
ctrl.warning = "Nothing found";
}
}
);
}
};
ctrl.removeItem = function (itemIndex) {
// remove item form list
ctrl.found.splice(itemIndex,1);
};
}
MenuSearchService.$inject = ['$http', 'ApiBasePath'];
function MenuSearchService($http, ApiBasePath) {
const service = this;
service.getMatchedMenuItems = function (searchTerm) {
return $http({
method: "GET",
url: (ApiBasePath + "/menu_items.json"),
})
.then(function (result) {
// return processed items
return result.data.menu_items.filter(
function (x) {
return (x.description.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1 );
}
);
}
)
};
}
}
)();