From db6e918ee5a92429738f2e87afb1af8f024d5053 Mon Sep 17 00:00:00 2001 From: François Schmidts Date: Sun, 31 Jan 2016 22:32:10 +0100 Subject: enhancement: ordering categories and hidding empty 'no category' category --- src/web/js/actions/MenuActions.js | 1 + src/web/js/components/Menu.react.js | 8 +++++++- src/web/js/stores/MenuStore.js | 3 ++- src/web/views/views.py | 8 ++++++-- 4 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/web/js/actions/MenuActions.js b/src/web/js/actions/MenuActions.js index 027a3d37..d3a0d25d 100644 --- a/src/web/js/actions/MenuActions.js +++ b/src/web/js/actions/MenuActions.js @@ -11,6 +11,7 @@ var MenuActions = { 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, diff --git a/src/web/js/components/Menu.react.js b/src/web/js/components/Menu.react.js index b68a84eb..76304f9a 100644 --- a/src/web/js/components/Menu.react.js +++ b/src/web/js/components/Menu.react.js @@ -89,6 +89,10 @@ var CategoryGroup = React.createClass({ return {unfolded: true}; }, render: function() { + // hidden the no category if empty + if(!this.props.cat_id && !this.props.feeds.length) { + return ); var categories = []; - for(var cat_id in this.state.categories) { + for(var index in this.state.categories_order) { + var cat_id = this.state.categories_order[index]; var feeds = []; var unread = 0; this.state.categories[cat_id].feeds.map(function(feed_id) { @@ -237,6 +242,7 @@ var Menu = React.createClass({ this.setState({filter: datas.filter, feeds: datas.feeds, categories: datas.categories, + categories_order: datas.categories_order, active_type: datas.active_type, active_id: datas.active_id}); }, diff --git a/src/web/js/stores/MenuStore.js b/src/web/js/stores/MenuStore.js index a68b24de..d3c44355 100644 --- a/src/web/js/stores/MenuStore.js +++ b/src/web/js/stores/MenuStore.js @@ -6,7 +6,7 @@ var assign = require('object-assign'); var MenuStore = assign({}, EventEmitter.prototype, { - _datas: {filter: 'all', feeds: {}, categories: {}, + _datas: {filter: 'all', feeds: {}, categories: {}, categories_order: [], active_type: null, active_id: null, is_admin: false, crawling_method: 'classic', all_unread_count: 0, max_error: 0, error_threshold: 0}, @@ -46,6 +46,7 @@ MenuStore.dispatchToken = JarrDispatcher.register(function(action) { case ActionTypes.RELOAD_MENU: MenuStore._datas['feeds'] = action.feeds; MenuStore._datas['categories'] = action.categories; + MenuStore._datas['categories_order'] = action.categories_order; MenuStore._datas['is_admin'] = action.is_admin; MenuStore._datas['max_error'] = action.max_error; MenuStore._datas['error_threshold'] = action.error_threshold; diff --git a/src/web/views/views.py b/src/web/views/views.py index 0ae37a8d..223f96e9 100644 --- a/src/web/views/views.py +++ b/src/web/views/views.py @@ -243,8 +243,11 @@ def home(): @app.route('/menu') @login_required def get_menu(): - categories = {c.id: c.dump() for c in CategoryController(g.user.id).read()} - categories[0] = {'name': 'No category', 'id': 0} + categories_order = [0] + categories = {0: {'name': 'No category', 'id': 0}} + for cat in CategoryController(g.user.id).read().order_by('name'): + categories_order.append(cat.id) + categories[cat.id] = cat.dump() unread = ArticleController(g.user.id).count_by_feed(readed=False) for cat_id in categories: categories[cat_id]['unread'] = 0 @@ -262,6 +265,7 @@ def get_menu(): categories[feed['category_id']]['unread'] += feed['unread'] categories[feed['category_id']]['feeds'].append(feed_id) return jsonify(**{'feeds': feeds, 'categories': categories, + 'categories_order': categories_order, 'crawling_method': conf.CRAWLING_METHOD, 'max_error': conf.DEFAULT_MAX_ERROR, 'error_threshold': conf.ERROR_THRESHOLD, -- cgit