diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-18 11:49:26 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-18 11:49:26 +0100 |
commit | 8c5bf6f3173ce84c11cd1e0a77c30b71c3463d52 (patch) | |
tree | 77043acda22b45e6f0c1cd10a5246a30dbc6659c /js/app | |
parent | 2eec5da48cb0ac1833a92ab73eb5bff68e7c84f7 (diff) |
added rewritten js from appframwork-js branch
Diffstat (limited to 'js/app')
-rw-r--r-- | js/app/app.coffee | 44 | ||||
-rw-r--r-- | js/app/services/activefeed.coffee | 48 | ||||
-rw-r--r-- | js/app/services/feedtype.coffee | 31 | ||||
-rw-r--r-- | js/app/services/models/feedmodel.coffee | 40 | ||||
-rw-r--r-- | js/app/services/models/foldermodel.coffee | 28 | ||||
-rw-r--r-- | js/app/services/models/itemmodel.coffee | 28 | ||||
-rw-r--r-- | js/app/services/opmlparser.coffee | 78 | ||||
-rw-r--r-- | js/app/services/persistence.coffee | 298 | ||||
-rw-r--r-- | js/app/services/services.coffee | 89 | ||||
-rw-r--r-- | js/app/services/showall.coffee | 41 | ||||
-rw-r--r-- | js/app/services/starredcount.coffee | 41 |
11 files changed, 766 insertions, 0 deletions
diff --git a/js/app/app.coffee b/js/app/app.coffee new file mode 100644 index 000000000..82a839c8c --- /dev/null +++ b/js/app/app.coffee @@ -0,0 +1,44 @@ +### + +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/>. + +### + + +# app main +angular.module('News', ['OC', 'ui']).config ($provide) -> + $provide.value 'Config', config = + markReadTimeout: 500 + scrollTimeout: 500 + feedUpdateInterval: 6000000 + itemBatchSize: 20 + + +angular.module('News').run ['Persistence', (Persistence) -> + Persistence.init() +] + + +$(document).ready -> + # this is used to forces browser to reload content after refreshing + # and thus clearing the scroll cache + $(this).keyup (e) -> + if (e.which == 116) || (e.which == 82 && e.ctrlKey) + document.location.reload(true) + return false diff --git a/js/app/services/activefeed.coffee b/js/app/services/activefeed.coffee new file mode 100644 index 000000000..8af9f7573 --- /dev/null +++ b/js/app/services/activefeed.coffee @@ -0,0 +1,48 @@ +### + +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 '_ActiveFeed', -> + + class ActiveFeed + + constructor: -> + ### + Default value is all feeds + ### + @_id = 0 + @_type = 3 + + + handle: (data) -> + @_id = data.id + @_type = data.type + + + getType: -> + return @_type + + + getId: -> + return @_id + + + return ActiveFeed diff --git a/js/app/services/feedtype.coffee b/js/app/services/feedtype.coffee new file mode 100644 index 000000000..924c2f9aa --- /dev/null +++ b/js/app/services/feedtype.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 'FeedType', -> + + return feedType = + Feed: 0 + Folder: 1 + Starred: 2 + Subscriptions: 3 + Shared: 4
\ No newline at end of file diff --git a/js/app/services/models/feedmodel.coffee b/js/app/services/models/feedmodel.coffee new file mode 100644 index 000000000..25cc48d88 --- /dev/null +++ b/js/app/services/models/feedmodel.coffee @@ -0,0 +1,40 @@ +### + +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 '_FeedModel', ['_Model', (_Model) -> + + class FeedModel extends _Model + + constructor: (@_utils) -> + super() + + + add: (item) -> + if item.icon == 'url()' + item.icon = 'url(' + @_utils.imagePath('news', 'rss.svg') + ')' + super(item) + + + + return FeedModel +]
\ No newline at end of file diff --git a/js/app/services/models/foldermodel.coffee b/js/app/services/models/foldermodel.coffee new file mode 100644 index 000000000..208bd2f4b --- /dev/null +++ b/js/app/services/models/foldermodel.coffee @@ -0,0 +1,28 @@ +### + +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 '_FolderModel', ['_Model', (_Model) -> + + class FolderModel extends _Model + + return FolderModel +]
\ No newline at end of file diff --git a/js/app/services/models/itemmodel.coffee b/js/app/services/models/itemmodel.coffee new file mode 100644 index 000000000..d53f17f15 --- /dev/null +++ b/js/app/services/models/itemmodel.coffee @@ -0,0 +1,28 @@ +### + +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 '_ItemModel', ['_Model', (_Model) -> + + class ItemModel extends _Model + + return ItemModel +]
\ No newline at end of file diff --git a/js/app/services/opmlparser.coffee b/js/app/services/opmlparser.coffee new file mode 100644 index 000000000..5154e423c --- /dev/null +++ b/js/app/services/opmlparser.coffee @@ -0,0 +1,78 @@ +### + +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 '_OPMLParser', -> + + class Feed + + constructor: (@_name, @_url) -> + + getName: -> + return @_name + + getUrl: -> + return @_url + + isFolder: -> + return false + + + class Folder + + constructor: (@_name) -> + @_items = [] + + add: (feed) -> + @_items.push(feed) + + getItems: -> + return @_items + + getName: -> + return @_name + + isFolder: -> + return true + + + class OPMLParser + + parseXML: (xml) -> + $xml = $($.parseXML(xml)) + $root = $xml.find('body') + structure = new Folder('root') + @_recursivelyParse($root, structure) + return structure + + _recursivelyParse: ($xml, structure) -> + for outline in $xml.children('outline') + $outline = $(outline) + if angular.isDefined($outline.attr('type')) + feed = new Feed($outline.attr('text'), $outline.attr('xmlUrl')) + structure.add(feed) + else + folder = new Folder($outline.attr('text')) + structure.add(folder) + @_recursivelyParse($outline, folder) + + + return OPMLParser diff --git a/js/app/services/persistence.coffee b/js/app/services/persistence.coffee new file mode 100644 index 000000000..26e547cd6 --- /dev/null +++ b/js/app/services/persistence.coffee @@ -0,0 +1,298 @@ +### + +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 '_Persistence', -> + + class Persistence + + constructor: (@_request, @_loading, @_config, @_activeFeed, + @_$rootScope) -> + + + init: -> + ### + Loads the initial data from the server + ### + @_loading.increase() + + # items can only be loaded after the active feed is known + @getActiveFeed => + @getItems @_activeFeed.getType(), @_activeFeed.getId(), null, => + @_loading.decrease() + + @getAllFolders(@_triggerHideRead) + @getAllFeeds(@_triggerHideRead) + @userSettingsRead(@_triggerHideRead) + @getStarredItems(@_triggerHideRead) + + + ### + ITEM CONTROLLER + ### + getItems: (type, id, offset, onSuccess, updatedSince=null) -> + # TODO + if updatedSince != null + data = + updatedSince: updatedSince + type: type + id: id + else + data = + limit: @_config.itemBatchSize + offset: offset + id: id + type: type + + @_request.get 'news_items', {}, data, onSuccess + + + getItemById: (itemId) -> + url = + itemId: itemId + + @_request.get 'news_item', url + + + getStarredItems: (onSuccess) -> + @_request.get 'news_starred_items', {}, {}, onSuccess + + + starItem: (itemId) -> + ### + Stars an item + ### + url = + itemId: itemId + + @_request.post 'news_star_item', url + + + + unstarItem: (itemId) -> + ### + Unstars an item + ### + url = + itemId: itemId + + @_request.post 'news_unstar_item', url + + + readItem: (itemId) -> + ### + Sets an item as read + ### + url = + itemId: itemId + + @_request.post 'news_read_item', url + + + + unreadItem: (itemId) -> + ### + Sets an item as unread + ### + url = + itemId: itemId + + @_request.post 'news_unread_item', url + + + ### + FOLDER CONTROLLER + ### + getAllFolders: (callback) -> + callback or= angular.noop + @_request.get 'news_folders', {}, {}, callback + + + getFolderById: (folderId) -> + url = + folderId: folderId + @_request.get 'news_folder', url + + + openFolder: (folderId) -> + ### + Save if a folder was opened + ### + url = + folderId: folderId + + @_request.post 'news_open_folder', url + + + collapseFolder: (folderId) -> + ### + Save if a folder was collapsed + ### + url = + folderId: folderId + + @_request.post 'news_collapse_folder', url + + + createFolder: (folderName, parentFolderId=0, onSuccess=null, onError=null) -> + data = + folderName: folderName + parentFolderId: parentFolderId + onSuccess or= angular.noop + onError or= angular.noop + + @_request.post 'news_create_folder', {}, data, onSuccess, onError + + + deleteFolder: (folderId) -> + ### + Save if a folder was collapsed + ### + url = + folderId: folderId + + @_request.post 'news_delete_folder', url + + + renameFolder: (folderId, folderName) -> + ### + Save if a folder was collapsed + ### + url = + folderId: folderId + + data = + folderName: folderName + + @_request.post 'news_rename_folder', url, data + + + ### + FEED CONTROLLER + ### + getAllFeeds: (callback) -> + callback or= angular.noop + + @_request.get 'news_feeds', {}, {}, callback + + + getFeedById: (feedId) -> + url = + feedId: feedId + + @_request.get 'news_feed', url + + + getActiveFeed: (onSuccess) -> + @_request.get 'news_active_feed', {}, {}, onSuccess + + + createFeed: (url, parentFolderId, onSuccess, onError) -> + data = + parentFolderId: parentFolderId + url: url + + @_request.post 'news_create_feed', {}, data, onSuccess, onError + + + deleteFeed: (feedId) -> + url = + feedId: feedId + + @_request.post 'news_delete_feed', url + + + moveFeed: (feedId, folderId) -> + ### + moves a feed to a new folder + ### + url = + feedId: feedId + data = + folderId: folderId + + @_request.post 'news_move_feed', url, data + + + setFeedRead: (feedId, highestItemId) -> + ### + sets all items of a feed as read + ### + url = + feedId: feedId + data = + highestItemId: highestItemId + + @_request.post 'news_set_feed_read', url, data + + + updateFeed: (feedId) -> + ### + moves a feed to a new folder + ### + url = + feedId: feedId + + @_request.post 'news_update_feed', url + + + ### + EXPORT CONTROLLER + ### + exportOPML: -> + ### + Prompts for an OPML download + ### + @_request.get 'news_export_opml' + + + ### + USERSETTINGS CONTROLLER + ### + userSettingsRead: (callback=null) -> + ### + Gets the configs for read settings + ### + callback or= angular.noop + @_request.get 'news_user_settings_read', {}, {}, callback + + + userSettingsReadShow: -> + ### + Sets the reader mode to show all + ### + @_request.post 'news_user_settings_read_show' + + + userSettingsReadHide: -> + ### + Sets the reader mode to show only unread + ### + @_request.post 'news_user_settings_read_hide' + + + _trigerHideRead: -> + @_$rootScope.$broadcast('triggerHideRead') + + + return Persistence + diff --git a/js/app/services/services.coffee b/js/app/services/services.coffee new file mode 100644 index 000000000..31b33871c --- /dev/null +++ b/js/app/services/services.coffee @@ -0,0 +1,89 @@ +### + +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/>. + +### + + +# request related stuff +angular.module('News').factory 'Persistence', ['_Persistence', 'Request', +'Loading', 'Config', '$rootScope', 'ActiveFeed', +(_Persistence, Request, Loading, Config, ActiveFeed, $rootScope) -> + return new _Persistence(Request, Loading, Config, ActiveFeed, $rootScope) +] + +angular.module('News').factory 'Request', +['_Request', '$http', 'Publisher', 'Router', +(_Request, $http, Publisher, Router) -> + return new _Request($http, Publisher, Router) +] + + +# models +angular.module('News').factory 'ActiveFeed', ['_ActiveFeed', (_ActiveFeed) -> + return new _ActiveFeed() +] + +angular.module('News').factory 'ShowAll', ['_ShowAll', (_ShowAll) -> + return new _ShowAll() +] + +angular.module('News').factory 'StarredCount', ['_StarredCount', +(_StarredCount) -> + return new _StarredCount() +] + +angular.module('News').factory 'FeedModel', ['_FeedModel', 'Utils', +(_FeedModel, Utils) -> + return new _FeedModel(Utils) +] + +angular.module('News').factory 'FolderModel', ['_FolderModel', (_FolderModel) -> + return new _FolderModel() +] + +angular.module('News').factory 'ItemModel', ['_ItemModel', (_ItemModel) -> + return new _ItemModel() +] + + +angular.module('News').factory 'Publisher', +['_Publisher', 'ActiveFeed', 'ShowAll', 'StarredCount', 'ItemModel', +'FolderModel', 'FeedModel', +(_Publisher, ActiveFeed, ShowAll, StarredCount, ItemModel, +FolderModel, FeedModel) -> + + # register items at publisher to automatically add incoming items + publisher = new _Publisher() + publisher.subscribeObjectTo(ActiveFeed, 'activeFeed') + publisher.subscribeObjectTo(ShowAll, 'showAll') + publisher.subscribeObjectTo(StarredCount, 'starred') + publisher.subscribeObjectTo(FolderModel, 'folders') + publisher.subscribeObjectTo(FeedModel, 'feeds') + publisher.subscribeObjectTo(ItemModel, 'items') + + return publisher +] + + +# other classes +angular.module('News').factory 'OPMLParser', ['_OPMLParser', (_OPMLParser) -> + return new _OPMLParser() +] + diff --git a/js/app/services/showall.coffee b/js/app/services/showall.coffee new file mode 100644 index 000000000..25b093735 --- /dev/null +++ b/js/app/services/showall.coffee @@ -0,0 +1,41 @@ +### + +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 '_ShowAll', -> + + class ShowAll + + constructor: -> + @_showAll = false + + + handle: (data) -> + @_showAll = data + + + getShowAll: -> + return @_showAll + + + + return ShowAll diff --git a/js/app/services/starredcount.coffee b/js/app/services/starredcount.coffee new file mode 100644 index 000000000..aaa8fdaff --- /dev/null +++ b/js/app/services/starredcount.coffee @@ -0,0 +1,41 @@ +### + +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 '_StarredCount', -> + + class StarredCount + + constructor: -> + @_count = 0 + + + handle: (data) -> + @_count = data + + + getStarredCount: -> + return @_count + + + + return StarredCount |