summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-18 22:49:30 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-18 22:49:30 +0200
commit2459002dcc070dcb66b2a44c237b87e8a1b8e968 (patch)
tree5a668fa1aead7269a1979e8706405d8dbf3226f3 /js
parente2e9a79aa3acb0d3a02d81ddbfbdcacc676db2d2 (diff)
add models
Diffstat (limited to 'js')
-rw-r--r--js/build/app.js50
-rw-r--r--js/service/feed.js20
-rw-r--r--js/service/folder.js20
-rw-r--r--js/service/item.js20
-rw-r--r--js/service/model.js11
-rw-r--r--js/service/publisher.js9
-rw-r--r--js/tests/unit/service/ModelSpec.js26
-rw-r--r--js/tests/unit/service/PublisherSpec.js15
8 files changed, 171 insertions, 0 deletions
diff --git a/js/build/app.js b/js/build/app.js
index 206114cd4..8c5835c06 100644
--- a/js/build/app.js
+++ b/js/build/app.js
@@ -54,6 +54,39 @@ app.run([
});
}
]);
+app.factory('Feed', [
+ 'Model',
+ function (Model) {
+ 'use strict';
+ var Feed = function () {
+ Model.call(this, 'url');
+ };
+ Feed.prototype = Object.create(Model.prototype);
+ return new Feed();
+ }
+]);
+app.factory('Folder', [
+ 'Model',
+ function (Model) {
+ 'use strict';
+ var Folder = function () {
+ Model.call(this, 'name');
+ };
+ Folder.prototype = Object.create(Model.prototype);
+ return new Folder();
+ }
+]);
+app.factory('Item', [
+ 'Model',
+ function (Model) {
+ 'use strict';
+ var Item = function () {
+ Model.call(this, 'id');
+ };
+ Item.prototype = Object.create(Model.prototype);
+ return new Item();
+ }
+]);
app.service('Loading', function () {
'use strict';
this.loading = {
@@ -117,6 +150,15 @@ app.factory('Model', function () {
if (this.hashMap[id] !== undefined) {
delete this.hashMap[id];
}
+ },
+ clear: function () {
+ this.hashMap = {};
+ // http://stackoverflow.com/questions/1232040/how-to-empty-an-array-in-javascript
+ // this is the fastes way to empty an array when you want to keep the
+ // reference around
+ while (this.values.length > 0) {
+ this.values.pop();
+ }
}
};
return Model;
@@ -133,6 +175,14 @@ app.service('Publisher', function () {
}
};
};
+ this.publishAll = function (values) {
+ var key;
+ for (key in values) {
+ if (values.hasOwnProperty(key)) {
+ this.publish(values[key]).onChannel(key);
+ }
+ }
+ };
this.publish = function (value) {
return {
onChannel: function (channel) {
diff --git a/js/service/feed.js b/js/service/feed.js
new file mode 100644
index 000000000..9223ca6e7
--- /dev/null
+++ b/js/service/feed.js
@@ -0,0 +1,20 @@
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Bernhard Posselt 2014
+ */
+app.factory('Feed', function (Model) {
+ 'use strict';
+
+ var Feed = function () {
+ Model.call(this, 'url');
+ };
+
+ Feed.prototype = Object.create(Model.prototype);
+
+ return new Feed();
+}); \ No newline at end of file
diff --git a/js/service/folder.js b/js/service/folder.js
new file mode 100644
index 000000000..101b8ec66
--- /dev/null
+++ b/js/service/folder.js
@@ -0,0 +1,20 @@
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Bernhard Posselt 2014
+ */
+app.factory('Folder', function (Model) {
+ 'use strict';
+
+ var Folder = function () {
+ Model.call(this, 'name');
+ };
+
+ Folder.prototype = Object.create(Model.prototype);
+
+ return new Folder();
+}); \ No newline at end of file
diff --git a/js/service/item.js b/js/service/item.js
new file mode 100644
index 000000000..0dd9b8677
--- /dev/null
+++ b/js/service/item.js
@@ -0,0 +1,20 @@
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Bernhard Posselt 2014
+ */
+app.factory('Item', function (Model) {
+ 'use strict';
+
+ var Item = function () {
+ Model.call(this, 'id');
+ };
+
+ Item.prototype = Object.create(Model.prototype);
+
+ return new Item();
+}); \ No newline at end of file
diff --git a/js/service/model.js b/js/service/model.js
index a28608329..dddede788 100644
--- a/js/service/model.js
+++ b/js/service/model.js
@@ -70,6 +70,17 @@ app.factory('Model', function () {
if (this.hashMap[id] !== undefined) {
delete this.hashMap[id];
}
+ },
+
+ clear: function () {
+ this.hashMap = {};
+
+ // http://stackoverflow.com/questions/1232040/how-to-empty-an-array-in-javascript
+ // this is the fastes way to empty an array when you want to keep the
+ // reference around
+ while (this.values.length > 0) {
+ this.values.pop();
+ }
}
};
diff --git a/js/service/publisher.js b/js/service/publisher.js
index 185e60047..d7e9bb0e7 100644
--- a/js/service/publisher.js
+++ b/js/service/publisher.js
@@ -22,6 +22,15 @@ app.service('Publisher', function () {
};
};
+ this.publishAll = function (values) {
+ var key;
+ for (key in values) {
+ if (values.hasOwnProperty(key)) {
+ this.publish(values[key]).onChannel(key);
+ }
+ }
+ };
+
this.publish = function (value) {
return {
onChannel: function (channel) {
diff --git a/js/tests/unit/service/ModelSpec.js b/js/tests/unit/service/ModelSpec.js
index d8aba1520..57b0f422c 100644
--- a/js/tests/unit/service/ModelSpec.js
+++ b/js/tests/unit/service/ModelSpec.js
@@ -100,4 +100,30 @@ describe('Model', function () {
expect(childModel.size()).toBe(1);
});
+
+ it('should clear all models', function () {
+ var object1,
+ object2;
+
+ object1 = {
+ id: 3,
+ name: 'test',
+ test: 'ho'
+ };
+
+ object2 = {
+ id: 4,
+ name: 'test2'
+ };
+
+ childModel.add(object1);
+ childModel.add(object2);
+
+ childModel.clear();
+
+ expect(childModel.get(3)).not.toBeDefined();
+ expect(childModel.get(4)).not.toBeDefined();
+ expect(childModel.size()).toBe(0);
+ });
+
}); \ No newline at end of file
diff --git a/js/tests/unit/service/PublisherSpec.js b/js/tests/unit/service/PublisherSpec.js
index 8a019f0db..59628356f 100644
--- a/js/tests/unit/service/PublisherSpec.js
+++ b/js/tests/unit/service/PublisherSpec.js
@@ -23,4 +23,19 @@ describe('Publisher', function () {
}));
+ it('should should publish on all possible channels', inject(function (Publisher) {
+
+ var obj = {
+ receive: jasmine.createSpy('receive')
+ };
+ Publisher.subscribe(obj).toChannel('test');
+
+ Publisher.publishAll({
+ test: 'tom'
+ });
+
+ expect(obj.receive).toHaveBeenCalledWith('tom');
+
+ }));
+
}); \ No newline at end of file