summaryrefslogtreecommitdiffstats
path: root/js/service/Resource.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/service/Resource.js')
-rw-r--r--js/service/Resource.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/js/service/Resource.js b/js/service/Resource.js
index 7683099da..072abca18 100644
--- a/js/service/Resource.js
+++ b/js/service/Resource.js
@@ -12,6 +12,7 @@ app.factory('Resource', () => {
class Resource {
+
constructor (http, BASE_URL, id='id') {
this.id = id;
this.values = [];
@@ -20,12 +21,14 @@ app.factory('Resource', () => {
this.BASE_URL = BASE_URL;
}
+
receive (objs) {
for (let obj of objs) {
this.add(obj);
}
}
+
add (obj) {
let existing = this.hashMap[obj[this.id]];
@@ -40,14 +43,17 @@ app.factory('Resource', () => {
}
}
+
size () {
return this.values.length;
}
+
get (id) {
return this.hashMap[id];
}
+
delete (id) {
// find index of object that should be deleted
let deleteAtIndex = this.values.findIndex(e => e[this.id] === id);
@@ -61,6 +67,7 @@ app.factory('Resource', () => {
}
}
+
clear () {
this.hashMap = {};
@@ -72,10 +79,12 @@ app.factory('Resource', () => {
}
}
+
getAll () {
return this.values;
}
+
}
return Resource;