1
0
mirror of https://github.com/chylex/Nextcloud-News.git synced 2025-01-11 09:42:46 +01:00

implement read all

This commit is contained in:
Bernhard Posselt 2014-05-22 02:53:56 +02:00
parent 6b46f7b265
commit 7030132583
3 changed files with 62 additions and 10 deletions
js
build
service
tests/unit/service

View File

@ -296,10 +296,6 @@ var $__build_47_app__ = function () {
data: { isRead: isRead }
});
},
keepUnread: function (itemId) {
this.get(itemId).keepUnread = true;
return this.read(itemId, false);
},
readFeed: function (feedId) {
var read = arguments[1] !== void 0 ? arguments[1] : true;
for (var $__3 = this.values.filter(function (i) {
@ -315,6 +311,23 @@ var $__build_47_app__ = function () {
}
}
return this.http.post(this.BASE_URL + '/feeds/' + feedId + '/read');
},
readAll: function () {
for (var $__3 = this.values[$traceurRuntime.toProperty(Symbol.iterator)](), $__4; !($__4 = $__3.next()).done;) {
try {
throw undefined;
} catch (item) {
item = $__4.value;
{
item.unread = false;
}
}
}
return this.http.post(this.BASE_URL + '/items/read');
},
keepUnread: function (itemId) {
this.get(itemId).keepUnread = true;
return this.read(itemId, false);
}
}, {}, Resource);
return new ItemResource($http, BASE_URL);

View File

@ -79,12 +79,6 @@ app.factory('ItemResource', (Resource, $http, BASE_URL) => {
}
keepUnread (itemId) {
this.get(itemId).keepUnread = true;
return this.read(itemId, false);
}
readFeed (feedId, read=true) {
for (let item of this.values.filter(i => i.feedId === feedId)) {
item.unread = !read;
@ -93,6 +87,20 @@ app.factory('ItemResource', (Resource, $http, BASE_URL) => {
}
readAll () {
for (let item of this.values) {
item.unread = false;
}
return this.http.post(`${this.BASE_URL}/items/read`);
}
keepUnread (itemId) {
this.get(itemId).keepUnread = true;
return this.read(itemId, false);
}
}
return new ItemResource($http, BASE_URL);

View File

@ -155,6 +155,37 @@ describe('ItemResource', () => {
}));
it ('should mark all as read', inject((ItemResource) => {
http.expectPOST('base/items/read').respond(200, {});
ItemResource.receive([
{
id: 3,
feedId: 4,
unread: true
},
{
id: 4,
feedId: 3,
unread: true
},
{
id: 5,
feedId: 4,
unread: true
}
], 'items');
ItemResource.readAll(4);
http.flush();
expect(ItemResource.get(3).unread).toBe(false);
expect(ItemResource.get(4).unread).toBe(false);
expect(ItemResource.get(5).unread).toBe(false);
}));
afterEach(() => {
http.verifyNoOutstandingExpectation();
http.verifyNoOutstandingRequest();