From 834cbe3a1124d2c93c448529c3c50949d0aae7f7 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 23 Apr 2012 16:12:07 +0800 Subject: [PATCH 1/6] Fix side_bar for tags Modules needs to use the fullpath for active or visible in tags --- app/helpers/application_helper.rb | 5 +++-- app/views/layouts/_side_bar.html.erb | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e45fa4d6..ea8c5a5b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -75,11 +75,12 @@ module ApplicationHelper end def active_for_controllers(*controller_names) - controller_names.include?(controller.controller_name) ? 'active' : nil + (controller_names.include?(controller.controller_name) || controller_names.include?(request.fullpath)) ? 'active' : nil end def visible_for_controllers(*controller_names) - controller_names.include?(controller.controller_name) ? '' : 'hide' + puts controller_names + (controller_names.include?(controller.controller_name) || controller_names.include?(request.fullpath)) ? '' : 'hide' end def active_for_action(controller_name, action_name) diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 84d89ac4..4acaa0c1 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -2,13 +2,13 @@ <%= link_to content_tag(:i, nil, :class => 'icons-purchase') + t('admin.purchase'), admin_purchases_path %> <% end -%> -<%= content_tag :li, :class => active_for_controllers('bulletins', 'tags', 'bulletin_categorys', 'fact_checks') do -%> +<%= content_tag :li, :class => active_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'fact_checks') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-announcement') + t('admin.announcement'), panel_announcement_back_end_bulletins_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('bulletins', 'tags', 'bulletin_categorys', 'fact_checks')) do -%> + <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'fact_checks')) do -%> <%= content_tag :li, link_to(t('announcement.all_articles'), panel_announcement_back_end_bulletins_path), :class => active_for_action('bulletins', 'index') %> <%= content_tag :li, link_to(t('announcement.add_new'), new_panel_announcement_back_end_bulletin_path), :class => active_for_action('bulletins', 'new') %> <%= content_tag :li, link_to(t('announcement.categories'), panel_announcement_back_end_bulletin_categorys_path), :class => active_for_action('bulletin_categorys', 'index') %> - <%= content_tag :li, link_to(t('announcement.tags'), panel_announcement_back_end_tags_path), :class => active_for_action('panel/bulletin/back_end/tags', 'index') %> + <%= content_tag :li, link_to(t('announcement.tags'), panel_announcement_back_end_tags_path), :class => active_for_action('/panel/announcement/back_end/tags', 'index') %> <%= content_tag :li, link_to(t('announcement.bulletin.fact_check_setting'), panel_announcement_back_end_fact_checks_setting_path), :class => active_for_action('fact_checks', 'setting') if (is_manager? rescue nil) %> <% end -%> @@ -38,13 +38,13 @@ <% end %> <% end %> -<%= content_tag :li, :class => active_for_controllers('web_links', 'tags', 'web_link_categorys') do -%> +<%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.link'), panel_web_resource_back_end_web_links_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('web_links', 'tags', 'web_link_categorys')) do -%> + <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys')) do -%> <%= content_tag :li, link_to(t('admin.announcement.all_articles'), panel_web_resource_back_end_web_links_path), :class => active_for_action('web_link', 'index') %> <%= content_tag :li, link_to(t('admin.announcement.add_new'), new_panel_web_resource_back_end_web_link_path), :class => active_for_action('web_link', 'new') %> <%= content_tag :li, link_to(t('admin.announcement.categories'), panel_web_resource_back_end_web_link_categorys_path), :class => active_for_action('web_link_categorys', 'index') %> - <%= content_tag :li, link_to(t('admin.announcement.tags'), panel_web_resource_back_end_tags_path), :class => active_for_action('panel/web_resource/back_end/tags', 'index') %> + <%= content_tag :li, link_to(t('admin.announcement.tags'), panel_web_resource_back_end_tags_path), :class => active_for_action('/panel/web_resource/back_end/tags', 'index') %> <% end -%> <% end -%> From b502bedd0fb4df1e25ee3de6ebf7b4b6ab1f539b Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Tue, 24 Apr 2012 00:46:34 +0800 Subject: [PATCH 2/6] Fix filter and sort for status in announcement --- .../back_end/bulletins_controller.rb | 23 +++++++---- .../announcement/app/models/bulletin.rb | 40 +++++++++++-------- .../back_end/bulletins/_bulletin.html.erb | 12 +++++- .../bulletins/_filter_status.html.erb | 10 +++-- .../back_end/bulletins/_form.html.erb | 2 +- 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index e66c51a4..ef60c330 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -243,12 +243,14 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # end respond_to do |format| - if @bulletin.update_attributes(params[:bulletin]) && @bulletin.save + if @bulletin.update_attributes(params[:bulletin]) # format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) } format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) } format.js { render 'toggle_enable' } format.xml { head :ok } else + get_tags + get_categorys format.html { render :action => "edit" } format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } end @@ -335,7 +337,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! bulletins = sorted.collect {|a| a[1] } when 'status' - bulletins = bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]) + bulletins = bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]).order_by(:is_pending, params[:direction]).order_by(:is_checked, params[:direction]).order_by(:is_rejected, params[:direction]) when 'update_user_id' user_ids = bulletins.distinct(:update_user_id) users = User.find(user_ids) rescue nil @@ -357,7 +359,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController sorted_titles = sorted.collect {|a| a[1] } a = params[:direction].eql?('asc') ? (sorted_titles + a) : (a + sorted_titles) bulletins = a.flatten - end + end if @filter @filter.each do |key, value| case key @@ -365,16 +367,23 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController a = Array.new bulletins.each do |bulletin| value.each do |v| - a << bulletin if bulletin[v] + case v + when 'pending' + a << bulletin if bulletin.is_checked.nil? + when 'rejected' + a << bulletin if bulletin.is_checked.eql?(false) + else + a << bulletin if bulletin[v] + end end end - bulletins = a + bulletins = a.uniq when 'categories' a = Array.new bulletins.each do |bulletin| a << bulletin if value.include?(bulletin.bulletin_category.id.to_s) end - bulletins = a + bulletins = a.uniq when 'tags' a = Array.new bulletins.each do |bulletin| @@ -382,7 +391,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController a << bulletin if value.include?(tag.id.to_s) end end - bulletins = a + bulletins = a.uniq end if value.size > 0 end end diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index 4808b3a9..55d1ec84 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -19,7 +19,10 @@ class Bulletin field :is_top, :type => Boolean, :default => false field :is_hot, :type => Boolean, :default => false field :is_hidden, :type => Boolean, :default => false - field :is_checked, :type => Boolean, :default => nil + field :is_checked, :type => Boolean, :default => false + field :is_pending, :type => Boolean, :default => true + field :is_rejected, :type => Boolean, :default => false + field :not_checked_reason @@ -42,7 +45,7 @@ class Bulletin validates_presence_of :title - before_save :set_key + before_save :set_key, :update_status after_save :save_bulletin_links after_save :save_bulletin_files @@ -79,17 +82,6 @@ class Bulletin end - def status - case self.is_checked - when nil - I18n.t('announcement.bulletin.fact_check_pending') - when true - I18n.t('announcement.bulletin.fact_check_pass') - when false - I18n.t('announcement.bulletin.fact_check_not_pass') - end - end - def is_expired? Date.today > self.deadline ? true : false rescue false #some dates might sat as nil so rescue false @@ -110,9 +102,13 @@ class Bulletin def is_checked? self.is_checked end - - def is_check_rejected? - self.is_checked == false + + def is_pending? + self.is_pending + end + + def is_rejected? + self.is_rejected end @@ -169,6 +165,18 @@ class Bulletin text.key = 'text' end end + + def update_status + if !self.is_pending && !self.is_checked + self.is_pending = false + self.is_rejected = true + self.is_checked = false + elsif self.is_checked + self.is_pending = false + self.is_rejected = false + self.is_checked = true + end + end end \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb index ca80512e..7db70593 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb @@ -10,14 +10,22 @@ <% if bulletin.is_hidden? %> <%= t(:hidden) %> <% end %> - <%= bulletin.status %> + <% if bulletin.is_pending? %> + <%= t(:pending) %> + <% end %> + <% if bulletin.is_checked? %> + <%= t(:checked) %> + <% end %> + <% if bulletin.is_rejected? %> + <%= t(:rejected) %> + <% end %> <%= bulletin.bulletin_category.i18n_variable[I18n.locale] %> <%= link_to bulletin.title[I18n.locale], panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''%>