-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.js
153 lines (135 loc) · 5.24 KB
/
backend.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
var BACKEND = (function (my) {
my.feedData = function (count, sort, dir, filter, page) {
var db = [];
db.push(
{id: 1, name: "Amidate", quant: 49},
{id: 2, name: "Nafcillin", quant: 95},
{id: 3, name: "Achromycin V", quant: 73},
{id: 4, name: "ANTARA", quant: 93},
{id: 5, name: "Multi-Vitamin Fluoride Drops", quant: 61},
{id: 6, name: "Benzonatate", quant: 49},
{id: 7, name: "California Valley White Oak", quant: 6},
{id: 8, name: "Magnesium Sulfate in Dextrose", quant: 97},
{id: 9, name: "equaline pain relief pm", quant: 8},
{id: 10, name: "careone nicotine polacrilex", quant: 84},
{id: 11, name: "Hand Sanitizer", quant: 87},
{id: 12, name: "Clario Free Foaming Hand Sanitizer", quant: 66},
{id: 13, name: "ZOMIG", quant: 98},
{id: 14, name: "UP and UP", quant: 22},
{id: 15, name: "SULPHUR", quant: 43},
{id: 16, name: "extra strength", quant: 58},
{id: 17, name: "Doxycycline Hyclate", quant: 86},
{id: 18, name: "Carvedilol", quant: 79},
{id: 19, name: "BEEVENOM PACT", quant: 33},
{id: 20, name: "METFORMIN HYDROCHLORIDE", quant: 42},
{id: 21, name: "Extra Strength Acetaminophen PM", quant: 10},
{id: 22, name: "Motion Sickness", quant: 82},
{id: 23, name: "NICARdipine Hydrochloride", quant: 83},
{id: 24, name: "Atenolol", quant: 90},
{id: 25, name: "Isopropyl alcohol", quant: 70},
{id: 26, name: "sunmark ibuprofen ib", quant: 28},
{id: 27, name: "healthy accents sore throat", quant: 58},
{id: 28, name: "Topcare infants pain relief", quant: 73},
{id: 29, name: "Neosporin Lip Health", quant: 60},
{id: 30, name: "Dopamine HCl", quant: 81},
{id: 31, name: "ELF Tinted Moisturizer SPF 20", quant: 57},
{id: 32, name: "Clonazepam", quant: 58},
{id: 33, name: "Boy Butter", quant: 93},
{id: 34, name: "Loperamide Hydrochloride", quant: 9},
{id: 35, name: "Total Bromine", quant: 51});
if (filter == undefined) {
filter = "";
}
if (page > 1) {
var ceiling = page * count;
var floor = ceiling - count;
}
if (dir == "1") {
if (sort == 'name') {
var sorted = _.sortBy(db, function (obj) {
return obj[sort].toLowerCase();
});
var filtered = _.filter(sorted, function (obj) {
return ~obj.name.toLowerCase().indexOf(filter);
})
}
else {
var sorted = _.sortBy(db, function (obj) {
return obj[sort]
});
var filtered = _.filter(sorted, function (obj) {
return ~obj.name.toLowerCase().indexOf(filter);
})
}
if (page == 1) {
arr = _.first(filtered, count)
}
else {
arr = filtered.slice(floor, ceiling);
}
if (_.size(filtered) < 11) {
var pag = 0;
}
else {
var pag = Math.round(_.size(filtered) / count);
}
return {
pages: pag,
page: page,
count: count,
sort: sort,
dir: dir,
filter: filter,
results: arr
}
}
else {
if (sort == 'name') {
var sorted = _.sortBy(db, function (obj) {
return obj[sort].toLowerCase();
}).reverse();
var filtered = _.filter(sorted, function (obj) {
return ~obj.name.toLowerCase().indexOf(filter);
})
}
else {
var sorted = _.sortBy(db, function (obj) {
return obj[sort]
}).reverse();
var filtered = _.filter(sorted, function (obj) {
return ~obj.name.toLowerCase().indexOf(filter);
})
}
if (page == 1) {
arr = _.first(filtered, count)
}
else {
arr = filtered.slice(floor, ceiling);
}
if (_.size(filtered) < 11) {
var pag = 0;
}
else {
var pag = Math.round(_.size(filtered) / count);
}
return {
pages: pag,
page: page,
count: count,
sort: sort,
dir: dir,
filter: filter,
results: arr
}
}
},
my.get = function (count, sort, dir, filter, page) {
var deffered = $.Deferred();
setTimeout(
function () {
deffered.resolve(BACKEND.feedData(count, sort, dir, filter, page))
}, 1000, count, sort, dir, filter, page);
return (deffered.promise());
}
return my;
}(BACKEND || {}));