summaryrefslogtreecommitdiffstats
path: root/js/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'js/app/services')
-rw-r--r--js/app/services/bl/feedbl.coffee65
-rw-r--r--js/app/services/bl/folderbl.coffee56
-rw-r--r--js/app/services/bl/itembl.coffee38
-rw-r--r--js/app/services/models/itemmodel.coffee21
-rw-r--r--js/app/services/services.coffee32
-rw-r--r--js/app/services/statusflag.coffee31
6 files changed, 241 insertions, 2 deletions
diff --git a/js/app/services/bl/feedbl.coffee b/js/app/services/bl/feedbl.coffee
new file mode 100644
index 000000000..1c2e4af09
--- /dev/null
+++ b/js/app/services/bl/feedbl.coffee
@@ -0,0 +1,65 @@
+###
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+###
+
+
+angular.module('News').factory '_FeedBl', ->
+
+ class FeedBl
+
+ constructor: (@_feedModel, @_itemBl, @_persistence) ->
+
+
+ getUnreadCount: (feedId) ->
+ @_feedModel.getFeedUnreadCount(feedId)
+
+
+ getFeedsOfFolder: (folderId) ->
+ return @_feedModel.getAllOfFolder(folderId)
+
+
+ getFolderUnreadCount: (folderId) ->
+ @_feedModel.getFolderUnreadCount(folderId)
+
+
+ getUnreadCount: ->
+ return @_feedModel.getUnreadCount()
+
+
+ delete: (feedId) ->
+ @_feedModel.removeById(feedId)
+ @_persistence.deleteFeed(feedId)
+
+
+ markFeedRead: (feedId) ->
+ feed = @_feedModel.getById(feedId)
+ if angular.isDefined(feed)
+ feed.unreadCount = 0
+ @_itemBl.markAllRead(feedId)
+
+
+ markAllRead: ->
+ for feed in @_feedModel.getAll()
+ @markFeedRead(feed.id)
+
+
+
+ return FeedBl
diff --git a/js/app/services/bl/folderbl.coffee b/js/app/services/bl/folderbl.coffee
new file mode 100644
index 000000000..e869453f2
--- /dev/null
+++ b/js/app/services/bl/folderbl.coffee
@@ -0,0 +1,56 @@
+###
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+###
+
+
+angular.module('News').factory '_FolderBl', ->
+
+ class FolderBl
+
+ constructor: (@_folderModel, @_feedBl, @_persistence) ->
+
+
+ delete: (folderId) ->
+ @_folderModel.removeById(folderId)
+ @_persistence.deleteFolder(folderId)
+
+
+ hasFeeds: (folderId) ->
+ return @_feedBl.getFeedsOfFolder(folderId).length
+
+
+ markFolderRead: (folderId) ->
+ for feed in @_feedBl.getFeedsOfFolder(folderId)
+ @_feedBl.markFeedRead(feed.id)
+
+
+ toggleFolder: (folderId) ->
+ folder = @_folderModel.getById(folderId)
+
+ if angular.isDefined(folder)
+ folder.open = !folder.open
+ if folder.open
+ @_persistence.openFolder(folder.id)
+ else
+ @_persistence.collapseFolder(folder.id)
+
+
+ return FolderBl
diff --git a/js/app/services/bl/itembl.coffee b/js/app/services/bl/itembl.coffee
new file mode 100644
index 000000000..ee4d9049a
--- /dev/null
+++ b/js/app/services/bl/itembl.coffee
@@ -0,0 +1,38 @@
+###
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+###
+
+
+angular.module('News').factory '_ItemBl', ->
+
+ class ItemBl
+
+ constructor: (@_itemModel, @_persistence) ->
+
+
+ markAllRead: (feedId) ->
+ highestItemId = @_itemModel.getHighestId()
+ @_persistence.setFeedRead(feedId, highestItemId)
+ for item in @_itemModel.getAll()
+ item.setRead()
+
+
+ return ItemBl
diff --git a/js/app/services/models/itemmodel.coffee b/js/app/services/models/itemmodel.coffee
index 09c187443..61030b50e 100644
--- a/js/app/services/models/itemmodel.coffee
+++ b/js/app/services/models/itemmodel.coffee
@@ -21,8 +21,8 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
###
angular.module('News').factory '_ItemModel',
-['_Model', '_MaximumQuery', '_MinimumQuery',
-(_Model, _MaximumQuery, _MinimumQuery) ->
+['_Model', '_MaximumQuery', '_MinimumQuery', 'StatusFlag',
+(_Model, _MaximumQuery, _MinimumQuery, StatusFlag) ->
class ItemModel extends _Model
@@ -41,6 +41,8 @@ angular.module('News').factory '_ItemModel',
# in case we get updated items with the same two fields we
# also need to update the field
add: (data, clearCache=true) ->
+ @_bindMethods(data)
+
hash = data.feedId + '_' + data.guidHash
entry = @_guidFeedIdHash[hash]
@@ -52,6 +54,21 @@ angular.module('News').factory '_ItemModel',
super(data, clearCache)
+ _bindMethods: (data) ->
+ data.isRead = ->
+ return !((@status & StatusFlag.UNREAD) == StatusFlag.UNREAD)
+ data.setRead = ->
+ @status &= ~StatusFlag.UNREAD
+ data.setUnread = ->
+ @status |= StatusFlag.UNREAD
+ data.isStarred = ->
+ return (@status & StatusFlag.STARRED) == StatusFlag.STARRED
+ data.setStarred = ->
+ @status |= StatusFlag.STARRED
+ data.setUnstarred = ->
+ @status &= ~StatusFlag.STARRED
+
+
update: (data, clearCache=true) ->
hash = data.feedId + '_' + data.guidHash
entry = @_guidFeedIdHash[hash]
diff --git a/js/app/services/services.coffee b/js/app/services/services.coffee
index cf1389fa7..6e27ece9d 100644
--- a/js/app/services/services.coffee
+++ b/js/app/services/services.coffee
@@ -34,12 +34,44 @@ angular.module('News').factory 'Request',
return new _Request($http, Publisher, Router)
]
+
# loading helpers
angular.module('News').factory 'FeedLoading',
['_Loading', (_Loading) ->
return new _Loading()
]
+angular.module('News').factory 'AutoPageLoading',
+['_Loading', (_Loading) ->
+ return new _Loading()
+]
+
+angular.module('News').factory 'NewLoading',
+['_Loading', (_Loading) ->
+ return new _Loading()
+]
+
+
+# business layer
+angular.module('News').factory 'ItemBl',
+['_ItemBl', 'ItemModel', 'Persistence',
+(_ItemBl, ItemModel, Persistence) ->
+ return new _ItemBl(ItemModel, Persistence)
+]
+
+angular.module('News').factory 'FeedBl',
+['_FeedBl', 'FeedModel', 'ItemBl', 'Persistence',
+(_FeedBl, FeedModel, ItemBl, Persistence) ->
+ return new _FeedBl(FeedModel, ItemBl, Persistence)
+]
+
+angular.module('News').factory 'FolderBl',
+['_FolderBl', 'FolderModel', 'FeedBl', 'Persistence',
+(_FolderBl, FolderModel, FeedBl, Persistence) ->
+ return new _FolderBl(FolderModel, FeedBl, Persistence)
+]
+
+
# models
angular.module('News').factory 'ActiveFeed', ['_ActiveFeed', (_ActiveFeed) ->
return new _ActiveFeed()
diff --git a/js/app/services/statusflag.coffee b/js/app/services/statusflag.coffee
new file mode 100644
index 000000000..c280c7ced
--- /dev/null
+++ b/js/app/services/statusflag.coffee
@@ -0,0 +1,31 @@
+###
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+###
+
+
+angular.module('News').factory 'StatusFlag', ->
+
+ return {
+ UNREAD: 0x02
+ STARRED: 0x04
+ DELETED: 0x08
+ UPDATED: 0x16
+ } \ No newline at end of file