summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-27 18:07:48 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-27 18:07:48 +0100
commitd97e2b1f0e26b113f870a09c5cc3ab384f1c1d94 (patch)
tree99061e8fda3265dec807b0fc1a67e65520f9b3e7 /js
parentd1d775da219e79e134c55d978ebc96c728d77958 (diff)
fixed bug that didnt add feeds when they were deleted once
Diffstat (limited to 'js')
-rw-r--r--js/app/services/models/feedmodel.coffee42
-rw-r--r--js/app/services/models/itemmodel.coffee43
-rw-r--r--js/public/app.js102
-rw-r--r--js/tests/services/models/feedmodelSpec.coffee16
-rw-r--r--js/tests/services/models/itemmodelSpec.coffee14
5 files changed, 162 insertions, 55 deletions
diff --git a/js/app/services/models/feedmodel.coffee b/js/app/services/models/feedmodel.coffee
index 4a186e659..96f187e75 100644
--- a/js/app/services/models/feedmodel.coffee
+++ b/js/app/services/models/feedmodel.coffee
@@ -37,7 +37,7 @@ angular.module('News').factory '_FeedModel',
super()
- add: (item) ->
+ add: (item, clearCache=true) ->
if item.faviconLink == null
item.faviconLink = 'url(' +
@_utils.imagePath('news', 'rss.svg') + ')'
@@ -46,20 +46,36 @@ angular.module('News').factory '_FeedModel',
# the same url
entry = @_urlHash[item.urlHash]
if angular.isDefined(entry)
- # first update id that could have changed
- delete @_dataMap[entry.id]
- @_dataMap[item.id] = entry
-
- # now copy over the elements data attrs
- for key, value of item
- if key == 'urlHash'
- continue
- else
- entry[key] = value
-
+ @update(item, clearCache)
else
@_urlHash[item.urlHash] = item
- super(item)
+ super(item, clearCache)
+
+
+ update: (item, clearCache=true) ->
+ entry = @_urlHash[item.urlHash]
+
+ # first update id that could have changed
+ delete @_dataMap[entry.id]
+ @_dataMap[item.id] = entry
+
+ # now copy over the elements data attrs
+ for key, value of item
+ if key == 'urlHash'
+ continue
+ else
+ entry[key] = value
+
+
+
+ removeById: (id) ->
+ item = @getById(id)
+ delete @_urlHash[item.urlHash]
+ super(id)
+
+
+ getByUrlHash: (urlHash) ->
+ return @_urlHash[urlHash]
getUnreadCount: ->
diff --git a/js/app/services/models/itemmodel.coffee b/js/app/services/models/itemmodel.coffee
index 3101c52f1..09c187443 100644
--- a/js/app/services/models/itemmodel.coffee
+++ b/js/app/services/models/itemmodel.coffee
@@ -46,23 +46,42 @@ angular.module('News').factory '_ItemModel',
# update entry if exists with same feedid and guidhash
if angular.isDefined(entry)
-
- # first update id that could have changed
- delete @_dataMap[entry.id]
- @_dataMap[data.id] = entry
-
- # now copy over the elements data attrs
- for key, value of data
- if key == 'feedId' or key == 'guidHash'
- continue
- else
- entry[key] = value
-
+ @update(data, clearCache)
else
@_guidFeedIdHash[hash] = data
super(data, clearCache)
+ update: (data, clearCache=true) ->
+ hash = data.feedId + '_' + data.guidHash
+ entry = @_guidFeedIdHash[hash]
+
+ # first update id that could have changed
+ delete @_dataMap[entry.id]
+ @_dataMap[data.id] = entry
+
+ # now copy over the elements data attrs
+ for key, value of data
+ if key == 'feedId' or key == 'guidHash'
+ continue
+ else
+ entry[key] = value
+
+ super(entry, clearCache)
+
+
+ getByGuidHashAndFeedId: (guidHash, feedId) ->
+ hash = feedId + '_' + guidHash
+ return @_guidFeedIdHash[hash]
+
+
+ removeById: (id) ->
+ item = @getById(id)
+ hash = item.feedId + '_' + item.guidHash
+ delete @_guidFeedIdHash[hash]
+ super(id)
+
+
getHighestId: ->
query = new _MaximumQuery('id')
highestId = @get(query)
diff --git a/js/public/app.js b/js/public/app.js
index edf48f309..8105c27dd 100644
--- a/js/public/app.js
+++ b/js/public/app.js
@@ -691,31 +691,54 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
return FeedModel.__super__.clear.call(this);
};
- FeedModel.prototype.add = function(item) {
- var entry, key, value, _results;
+ FeedModel.prototype.add = function(item, clearCache) {
+ var entry;
+ if (clearCache == null) {
+ clearCache = true;
+ }
if (item.faviconLink === null) {
item.faviconLink = 'url(' + this._utils.imagePath('news', 'rss.svg') + ')';
}
entry = this._urlHash[item.urlHash];
if (angular.isDefined(entry)) {
- delete this._dataMap[entry.id];
- this._dataMap[item.id] = entry;
- _results = [];
- for (key in item) {
- value = item[key];
- if (key === 'urlHash') {
- continue;
- } else {
- _results.push(entry[key] = value);
- }
- }
- return _results;
+ return this.update(item, clearCache);
} else {
this._urlHash[item.urlHash] = item;
- return FeedModel.__super__.add.call(this, item);
+ return FeedModel.__super__.add.call(this, item, clearCache);
}
};
+ FeedModel.prototype.update = function(item, clearCache) {
+ var entry, key, value, _results;
+ if (clearCache == null) {
+ clearCache = true;
+ }
+ entry = this._urlHash[item.urlHash];
+ delete this._dataMap[entry.id];
+ this._dataMap[item.id] = entry;
+ _results = [];
+ for (key in item) {
+ value = item[key];
+ if (key === 'urlHash') {
+ continue;
+ } else {
+ _results.push(entry[key] = value);
+ }
+ }
+ return _results;
+ };
+
+ FeedModel.prototype.removeById = function(id) {
+ var item;
+ item = this.getById(id);
+ delete this._urlHash[item.urlHash];
+ return FeedModel.__super__.removeById.call(this, id);
+ };
+
+ FeedModel.prototype.getByUrlHash = function(urlHash) {
+ return this._urlHash[urlHash];
+ };
+
FeedModel.prototype.getUnreadCount = function() {
var count, feed, _i, _len, _ref;
count = 0;
@@ -865,31 +888,54 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
};
ItemModel.prototype.add = function(data, clearCache) {
- var entry, hash, key, value, _results;
+ var entry, hash;
if (clearCache == null) {
clearCache = true;
}
hash = data.feedId + '_' + data.guidHash;
entry = this._guidFeedIdHash[hash];
if (angular.isDefined(entry)) {
- delete this._dataMap[entry.id];
- this._dataMap[data.id] = entry;
- _results = [];
- for (key in data) {
- value = data[key];
- if (key === 'feedId' || key === 'guidHash') {
- continue;
- } else {
- _results.push(entry[key] = value);
- }
- }
- return _results;
+ return this.update(data, clearCache);
} else {
this._guidFeedIdHash[hash] = data;
return ItemModel.__super__.add.call(this, data, clearCache);
}
};
+ ItemModel.prototype.update = function(data, clearCache) {
+ var entry, hash, key, value;
+ if (clearCache == null) {
+ clearCache = true;
+ }
+ hash = data.feedId + '_' + data.guidHash;
+ entry = this._guidFeedIdHash[hash];
+ delete this._dataMap[entry.id];
+ this._dataMap[data.id] = entry;
+ for (key in data) {
+ value = data[key];
+ if (key === 'feedId' || key === 'guidHash') {
+ continue;
+ } else {
+ entry[key] = value;
+ }
+ }
+ return ItemModel.__super__.update.call(this, entry, clearCache);
+ };
+
+ ItemModel.prototype.getByGuidHashAndFeedId = function(guidHash, feedId) {
+ var hash;
+ hash = feedId + '_' + guidHash;
+ return this._guidFeedIdHash[hash];
+ };
+
+ ItemModel.prototype.removeById = function(id) {
+ var hash, item;
+ item = this.getById(id);
+ hash = item.feedId + '_' + item.guidHash;
+ delete this._guidFeedIdHash[hash];
+ return ItemModel.__super__.removeById.call(this, id);
+ };
+
ItemModel.prototype.getHighestId = function() {
var highestId, query;
query = new _MaximumQuery('id');
diff --git a/js/tests/services/models/feedmodelSpec.coffee b/js/tests/services/models/feedmodelSpec.coffee
index 2ae72eec2..08ddabc86 100644
--- a/js/tests/services/models/feedmodelSpec.coffee
+++ b/js/tests/services/models/feedmodelSpec.coffee
@@ -62,4 +62,18 @@ describe '_FeedModel', ->
model.add({id: 3, faviconLink: 'hey', urlHash: 'hi4'})
expect(model.size()).toBe(1)
expect(model.getById(2)).toBe(undefined)
- expect(model.getById(3).faviconLink).toBe('hey') \ No newline at end of file
+ expect(model.getById(3).faviconLink).toBe('hey')
+
+
+ it 'should also remove the feed from the urlHash cache when its removed', =>
+ utils =
+ imagePath: jasmine.createSpy('utils')
+ model = new @_FeedModel(utils)
+
+ item = {id: 2, faviconLink: null, urlHash: 'hi'}
+ model.add(item)
+
+ expect(model.getByUrlHash('hi')).toBe(item)
+
+ model.removeById(2)
+ expect(model.getByUrlHash('hi')).toBe(undefined) \ No newline at end of file
diff --git a/js/tests/services/models/itemmodelSpec.coffee b/js/tests/services/models/itemmodelSpec.coffee
index 7d929b223..364c07b80 100644
--- a/js/tests/services/models/itemmodelSpec.coffee
+++ b/js/tests/services/models/itemmodelSpec.coffee
@@ -56,4 +56,16 @@ describe '_ItemModel', ->
expect(model.getById(3).feedId).toBe(item4.feedId)
expect(model.getById(3).id).toBe(item4.id)
expect(model.getById(5)).toBe(undefined)
- expect(model.size()).toBe(2) \ No newline at end of file
+ expect(model.size()).toBe(2)
+
+
+ it 'should also remove the feed from the urlHash cache when its removed', =>
+ model = new @_ItemModel()
+ item = {id: 4, guidHash: 'abc', feedId: 3}
+ model.add(item)
+
+ expect(model.getById(4)).toBe(item)
+ expect(model.getByGuidHashAndFeedId('abc', 3)).toBe(item)
+
+ model.removeById(4)
+ expect(model.getByGuidHashAndFeedId('abc', 3)).toBe(undefined) \ No newline at end of file