diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2016-02-03 07:11:37 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2016-02-03 07:11:37 +0100 |
commit | da929a367c3f1fe5f3546be82e47111c2fa84ad3 (patch) | |
tree | 89380f41b802256d8fdbf724e7d9e63b48209b4a /src/web/js/actions | |
parent | Merge pull request #30 from jaesivsm/master (diff) | |
parent | writing a bit of doc, moving crawler together (diff) | |
download | newspipe-da929a367c3f1fe5f3546be82e47111c2fa84ad3.tar.gz newspipe-da929a367c3f1fe5f3546be82e47111c2fa84ad3.tar.bz2 newspipe-da929a367c3f1fe5f3546be82e47111c2fa84ad3.zip |
Merge pull request #31 from jaesivsm/master
redoing UI
Diffstat (limited to 'src/web/js/actions')
-rw-r--r-- | src/web/js/actions/MenuActions.js | 37 | ||||
-rw-r--r-- | src/web/js/actions/MiddlePanelActions.js | 155 | ||||
-rw-r--r-- | src/web/js/actions/RightPanelActions.js | 38 |
3 files changed, 230 insertions, 0 deletions
diff --git a/src/web/js/actions/MenuActions.js b/src/web/js/actions/MenuActions.js new file mode 100644 index 00000000..b9154581 --- /dev/null +++ b/src/web/js/actions/MenuActions.js @@ -0,0 +1,37 @@ +var JarrDispatcher = require('../dispatcher/JarrDispatcher'); +var ActionTypes = require('../constants/JarrConstants'); +var jquery = require('jquery'); + + +var MenuActions = { + // PARENT FILTERS + reload: function() { + jquery.getJSON('/menu', function(payload) { + JarrDispatcher.dispatch({ + type: ActionTypes.RELOAD_MENU, + feeds: payload.feeds, + categories: payload.categories, + categories_order: payload.categories_order, + is_admin: payload.is_admin, + max_error: payload.max_error, + error_threshold: payload.error_threshold, + crawling_method: payload.crawling_method, + all_unread_count: payload.all_unread_count, + }); + }); + }, + setFilter: function(filter) { + JarrDispatcher.dispatch({ + type: ActionTypes.MENU_FILTER, + filter: filter, + }); + }, + toggleAllFolding: function(all_folded) { + JarrDispatcher.dispatch({ + type: ActionTypes.TOGGLE_MENU_FOLD, + all_folded: all_folded, + }); + }, +}; + +module.exports = MenuActions; diff --git a/src/web/js/actions/MiddlePanelActions.js b/src/web/js/actions/MiddlePanelActions.js new file mode 100644 index 00000000..f805b7b1 --- /dev/null +++ b/src/web/js/actions/MiddlePanelActions.js @@ -0,0 +1,155 @@ +var JarrDispatcher = require('../dispatcher/JarrDispatcher'); +var ActionTypes = require('../constants/JarrConstants'); +var jquery = require('jquery'); +var MiddlePanelStore = require('../stores/MiddlePanelStore'); + +var _last_fetched_with = {}; +var shouldFetch = function(filters) { + return true; // FIXME disabling intelligent fetch for now, no caching better that bad one +// if(filters.filter != null // undefined means unchanged +// && (_last_fetched_with.filter != 'all' +// || _last_fetched_with.filter != filters.filter)) { +// return true; +// } +// if(_last_fetched_with.filter_type != null) { +// if(_last_fetched_with.filter_type != filters.filter_type) { +// return true; +// } +// if(_last_fetched_with.filter_id != filters.filter_id) { +// return true; +// } +// } +// return false; +} +var reloadIfNecessaryAndDispatch = function(dispath_payload) { + if(shouldFetch(dispath_payload)) { + var filters = MiddlePanelStore.getRequestFilter( + dispath_payload.display_search); + MiddlePanelStore.filter_whitelist.map(function(key) { + if(key in dispath_payload) { + filters[key] = dispath_payload[key]; + } + if(filters[key] == null) { + delete filters[key]; + } + }); + if('display_search' in filters) { + delete filters['display_search']; + } + jquery.getJSON('/middle_panel', filters, + function(payload) { + dispath_payload.articles = payload.articles; + dispath_payload.filters = filters; + JarrDispatcher.dispatch(dispath_payload); + _last_fetched_with = MiddlePanelStore.getRequestFilter(); + }); + } else { + JarrDispatcher.dispatch(dispath_payload); + } +} + + +var MiddlePanelActions = { + reload: function() { + reloadIfNecessaryAndDispatch({ + type: ActionTypes.RELOAD_MIDDLE_PANEL, + }); + }, + search: function(search) { + reloadIfNecessaryAndDispatch({ + type: ActionTypes.RELOAD_MIDDLE_PANEL, + display_search: true, + query: search.query, + search_title: search.title, + search_content: search.content, + }); + }, + search_off: function() { + reloadIfNecessaryAndDispatch({ + type: ActionTypes.RELOAD_MIDDLE_PANEL, + display_search: false, + }); + }, + removeParentFilter: function() { + reloadIfNecessaryAndDispatch({ + type: ActionTypes.PARENT_FILTER, + filter_type: null, + filter_id: null, + }); + }, + setCategoryFilter: function(category_id) { + reloadIfNecessaryAndDispatch({ + type: ActionTypes.PARENT_FILTER, + filter_type: 'category_id', + filter_id: category_id, + }); + }, + setFeedFilter: function(feed_id) { + reloadIfNecessaryAndDispatch({ + type: ActionTypes.PARENT_FILTER, + filter_type: 'feed_id', + filter_id: feed_id, + }); + }, + setFilter: function(filter) { + reloadIfNecessaryAndDispatch({ + type: ActionTypes.MIDDLE_PANEL_FILTER, + filter: filter, + }); + }, + changeRead: function(category_id, feed_id, article_id, new_value){ + jquery.ajax({type: 'PUT', + contentType: 'application/json', + data: JSON.stringify({readed: new_value}), + url: "api/v2.0/article/" + article_id, + success: function () { + JarrDispatcher.dispatch({ + type: ActionTypes.CHANGE_ATTR, + attribute: 'read', + value_bool: new_value, + value_num: new_value ? -1 : 1, + articles: [{article_id: article_id, + category_id: category_id, + feed_id: feed_id}], + }); + }, + }); + }, + changeLike: function(category_id, feed_id, article_id, new_value){ + jquery.ajax({type: 'PUT', + contentType: 'application/json', + data: JSON.stringify({like: new_value}), + url: "api/v2.0/article/" + article_id, + success: function () { + JarrDispatcher.dispatch({ + type: ActionTypes.CHANGE_ATTR, + attribute: 'liked', + value_bool: new_value, + value_num: new_value ? -1 : 1, + articles: [{article_id: article_id, + category_id: category_id, + feed_id: feed_id}], + }); + }, + }); + }, + markAllAsRead: function() { + var filters = MiddlePanelStore.getRequestFilter(); + jquery.ajax({type: 'PUT', + contentType: 'application/json', + data: JSON.stringify(filters), + url: "/mark_all_as_read", + success: function (payload) { + JarrDispatcher.dispatch({ + type: ActionTypes.CHANGE_ATTR, + attribute: 'read', + value_num: -1, + value_bool: true, + articles: payload.articles, + }); + }, + }); + }, +}; + +module.exports = MiddlePanelActions; diff --git a/src/web/js/actions/RightPanelActions.js b/src/web/js/actions/RightPanelActions.js new file mode 100644 index 00000000..47adad79 --- /dev/null +++ b/src/web/js/actions/RightPanelActions.js @@ -0,0 +1,38 @@ +var jquery = require('jquery'); +var JarrDispatcher = require('../dispatcher/JarrDispatcher'); +var ActionTypes = require('../constants/JarrConstants'); +var MenuActions = require('../actions/MenuActions'); + +var RightPanelActions = { + loadArticle: function(article_id, was_read_before) { + jquery.getJSON('/getart/' + article_id, + function(payload) { + JarrDispatcher.dispatch({ + type: ActionTypes.LOAD_ARTICLE, + article: payload, + was_read_before: was_read_before, + }); + } + ); + }, + _apiReq: function(meth, id, obj_type, data, success_callback) { + var args = {type: meth, contentType: 'application/json', + url: "api/v2.0/" + obj_type + "/" + id} + if(data) {args.data = JSON.stringify(data);} + if(success_callback) {args.success = success_callback;} + jquery.ajax(args); + }, + putObj: function(id, obj_type, fields) { + this._apiReq('PUT', id, obj_type, fields, MenuActions.reload); + }, + delObj: function(id, obj_type, fields) { + this._apiReq('DELETE', id, obj_type, null, MenuActions.reload); + }, + resetErrors: function(feed_id) { + this._apiReq('PUT', feed_id, 'feed', {error_count: 0, last_error: ''}, + MenuActions.reload); + + }, +}; + +module.exports = RightPanelActions; |