diff --git a/app/controllers/admin/asks_controller.rb b/app/controllers/admin/asks_controller.rb index 7ccf9cf..3f15796 100644 --- a/app/controllers/admin/asks_controller.rb +++ b/app/controllers/admin/asks_controller.rb @@ -9,70 +9,48 @@ class Admin::AsksController < OrbitAdminController @app_title = "ask" end - # 重新定義排序 - def sort - unless params[:sort].blank? - case params[:sort] - when "status" - @sort = {:status=>params[:order]} - when "category" - @sort = {:category_id=>params[:order]} - when "start_date" - @sort = {:postdate=>params[:order]} - when "end_date" - @sort = {:deadline=>params[:order]} - when "last_modified" - @sort = {:update_user_id=>params[:order]} - when "banner" - @sort = {'banner_id'=>params[:order]} - when "banner_name" - @sort = {:title=>params[:order]} - when "effect" - @sort = {:ad_fx=>params[:order]} - when "transition_interval" - @sort = {:timeout=>params[:order]} - when "transition_speed" - @sort = {:speed=>params[:order]} - when "size" - @sort = {:height=>params[:order]} - when "link" - @sort = {:out_link=>params[:order]} - else - s = Sanitize.clean(params[:sort]).to_sym - @sort = {s=>params[:order]} - end - else - @sort = {:created_at=>'desc'} - end - @sort - end - - # 重新定義分類搜尋 - def filter_fields(categories) + def filter_fields(categories, tags) { - :status=>[{:title=>"待處理",:id=>"is_hot"},{:title=>"已處理",:id=>"is_top"},{:title=>"轉介其他單位",:id=>"is_hidden"}], - :category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}} + :situation=>[{:title=>"is_waiting",:id=>"is_waiting"},{:title=>"is_processed",:id=>"is_processed"},{:title=>"is_referral",:id=>"is_referral"}], + :category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}}, + :identity=>tags.map{|tag| {:title=>(tag.name.blank? ? " " : tag.name), :id=>tag.id}} } end # 抓取網址的狀態參數 def filter2(type) case type - when "status" - params[:filters][:status].blank? ? [] : params[:filters][:status] rescue [] + when "situation" + params[:filters][:situation].blank? ? [] : params[:filters][:situation] rescue [] + when "identity" + params[:filters][:identity].blank? ? [] : params[:filters][:identity] rescue [] end end def index + @tags = @module_app.tags @categories = @module_app.categories - @filter_fields = filter_fields(@categories) + @filter_fields = filter_fields(@categories, @tags) # 列表欄位 - @table_fields = [:status, :category, :title, 'ask.name', 'ask.created_at'] + @table_fields = [:situation, :category, :title, 'ask.name', 'ask.created_at'] # 列表排序 - if filter2("status").blank? - @askquestions = AskQuestion.order_by(sort) .with_categories(filters("category")) + # debugger + if filter2("situation").blank? and filter2("identity").blank? + @askquestions = AskQuestion.order_by(sort) + .with_categories(filters("category")) + elsif filter2("situation").blank? + @askquestions = AskQuestion.order_by(sort) + .with_categories(filters("category")) + .any_in(:identity => filter2("identity")) + elsif filter2("identity").blank? + @askquestions = AskQuestion.order_by(sort) + .with_categories(filters("category")) + .any_in(:situation => filter2("situation")) else - @askquestions = AskQuestion.order_by(sort) .with_categories(filters("category")) .where(:status.in => filter2("status")) + @askquestions = AskQuestion.order_by(sort) + .with_categories(filters("category")) + .any_in(:identity => filter2("identity")) + .any_in(:situation => filter2("situation")) end # 分頁 @@ -82,6 +60,10 @@ class Admin::AsksController < OrbitAdminController end end + def search_tag(tag) + Tag.find(tag).name_translations{} + end + def edit @ask_question = AskQuestion.find(params[:id]) @url = admin_ask_path(@ask_question) @@ -149,16 +131,18 @@ class Admin::AsksController < OrbitAdminController AskQuestion.human_attribute_name(:reply), AskQuestion.human_attribute_name(:comment)] @ask_questions.each do |ask_question| - csv << [ ask_question.category.title, - ask_question.name, - ask_question[:identity], - ask_question.mail, - ask_question.phone, - ask_question.fax, - ask_question.title, - ask_question.content, - ask_question.reply, - ask_question.comment ] + Tag.where({:id => ask_question[:identity]}).each do |tag| + csv << [ ask_question.category.title, + ask_question.name, + tag.name, + ask_question.mail, + ask_question.phone, + ask_question.fax, + ask_question.title, + ask_question.content, + ask_question.reply, + ask_question.comment ] + end end end send_data csv.encode('Big5'), type: 'text/csv', filename: "Questions-#{date_start}-#{date_end}.csv" diff --git a/app/controllers/asks_controller.rb b/app/controllers/asks_controller.rb index 839d4e2..7ec9ed3 100644 --- a/app/controllers/asks_controller.rb +++ b/app/controllers/asks_controller.rb @@ -7,10 +7,12 @@ class AsksController < ApplicationController def index module_app = ModuleApp.where(:key => "ask").first categories = module_app.categories + tags = module_app.tags ask_question = AskQuestion.new { "ask_question" => ask_question, "categories" => categories, + "tags" => tags, "module_app" => module_app } end diff --git a/app/models/ask_question.rb b/app/models/ask_question.rb index 12c5827..bc5b44b 100644 --- a/app/models/ask_question.rb +++ b/app/models/ask_question.rb @@ -1,8 +1,9 @@ class AskQuestion include Mongoid::Document include Mongoid::Timestamps - include ActiveModel::Validations + # include ActiveModel::Validations include OrbitCategory::Categorizable + include OrbitTag::Taggable # 欄位 field :name, type: String @@ -15,11 +16,11 @@ class AskQuestion field :reply, type: String field :comment, type: String - field :status, type: String, default: "is_hot" #預設待處理 + field :situation, type: String, default: "is_waiting" #預設待處理 field :send_email, type: Boolean, default: false field :email_id - validates_presence_of :name, :identity, :mail, :title, :content + # validates_presence_of :name, :identity, :mail, :title, :content def email mail = Email.find(self.email_id) rescue nil diff --git a/app/views/admin/asks/_filter.html.erb b/app/views/admin/asks/_filter.html.erb deleted file mode 100644 index 808eb5a..0000000 --- a/app/views/admin/asks/_filter.html.erb +++ /dev/null @@ -1,186 +0,0 @@ -<% content_for :right_nav do %> - <% if !search_dom_id.nil?%> -
-
- -
- -
- <% end %> - - -
- <% fields.keys.each do |field| %> -
-
- <% fields[field].each do |val| %> - <%= link_to (val[:title].blank? ? "" : t(val[:title])), "#", :onclick => "filter.addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}", :id => "filter_#{val[:id]}" %> - <% end %> -
- -
- <% end %> -
-<% end %> - diff --git a/app/views/admin/asks/_form.html.erb b/app/views/admin/asks/_form.html.erb index d7eb83e..25008a0 100644 --- a/app/views/admin/asks/_form.html.erb +++ b/app/views/admin/asks/_form.html.erb @@ -11,7 +11,11 @@ - + @@ -20,7 +24,7 @@ - + @@ -35,10 +39,10 @@
<%= f.text_field :comment, style: 'width: 500px' %> - diff --git a/app/views/admin/asks/_index.html.erb b/app/views/admin/asks/_index.html.erb index a22b03e..bbb4841 100644 --- a/app/views/admin/asks/_index.html.erb +++ b/app/views/admin/asks/_index.html.erb @@ -10,12 +10,12 @@ <% @askquestions.each do |b| %> diff --git a/app/views/admin/asks/email.html.erb b/app/views/admin/asks/email.html.erb index f16b23e..3684920 100644 --- a/app/views/admin/asks/email.html.erb +++ b/app/views/admin/asks/email.html.erb @@ -5,7 +5,7 @@

- <%= @data['reply'] %> + <%= @data['reply'].gsub(/[(\n)(\r)]/, "\n" => "
", "\r" => "" ).html_safe %>


此為系統自動發信,請勿直接回覆

diff --git a/app/views/asks/email.html.erb b/app/views/asks/email.html.erb index 63bfb07..f29e4ed 100644 --- a/app/views/asks/email.html.erb +++ b/app/views/asks/email.html.erb @@ -7,28 +7,32 @@

<%= @data['title'] %>

<%= AskQuestion.human_attribute_name(:name) %>:<%= @ask_question.name %><%= AskQuestion.human_attribute_name(:identity) %>:<%= @ask_question[:identity] %><%= AskQuestion.human_attribute_name(:identity) %>: + <% Tag.where({:id => @ask_question[:identity]}).each do |tag| %> + <%= tag.name %> + <% end %> + <%= AskQuestion.human_attribute_name(:mail) %>:<%= @ask_question.mail %> <%= AskQuestion.human_attribute_name(:phone) %>:<%= @ask_question.phone %> <%= AskQuestion.human_attribute_name(:fax) %>:<%= @ask_question.fax %><%= AskQuestion.human_attribute_name(:title) %>:<%= @ask_question.title %>
<%= AskQuestion.human_attribute_name(:content) %>:
<%= @ask_question.content %>
<%= AskQuestion.human_attribute_name(:content) %>:
<%= @ask_question.content.gsub(/[(\n)(\r)]/, "\n" => "
", "\r" => "" ).html_safe %>
<%= f.label :status %> <%= f.select :status, [ - ['待處理', 'is_hot'], - ['已處理', 'is_top'], - ['轉介其他單位', 'is_hidden'] + <%= f.label t('situation') %> <%= f.select :situation, [ + [t('is_waiting'), 'is_waiting'], + [t('is_processed'), 'is_processed'], + [t('is_referral'), 'is_referral'] ] %>
- <% if b.status == 'is_hot' %> - <%= t('待處理') %> - <% elsif b.status == 'is_top' %> - <%= t('已處理') %> - <% elsif b.status == 'is_hidden' %> - <%= t('轉介其他單位') %> + <% if b.situation == 'is_waiting' %> + <%= t('is_waiting') %> + <% elsif b.situation == 'is_processed' %> + <%= t('is_processed') %> + <% elsif b.situation == 'is_referral' %> + <%= t('is_referral') %> <% end %> <%= b.category.title %>
- + - - + + - + - + - + - - + +
<%= AskQuestion.human_attribute_name(:name) %>:<%= AskQuestion.human_attribute_name(:name) %>: <%= @data['name'] %>
<%= AskQuestion.human_attribute_name(:identity) %>:<%= @data['identity'] %><%= AskQuestion.human_attribute_name(:identity) %>: + <% Tag.where({:id => @data['identity']}).each do |tag| %> + <%= tag.name %> + <% end %> +
<%= AskQuestion.human_attribute_name(:mail) %>:<%= AskQuestion.human_attribute_name(:mail) %>: <%= @data['mail'] %>
<%= AskQuestion.human_attribute_name(:phone) %>:<%= AskQuestion.human_attribute_name(:phone) %>: <%= @data['phone'] %>
<%= AskQuestion.human_attribute_name(:fax) %>:<%= AskQuestion.human_attribute_name(:fax) %>: <%= @data['fax'] %>
<%= AskQuestion.human_attribute_name(:content) %>:<%= @data['content'] %><%= AskQuestion.human_attribute_name(:content) %>:<%= @data['content'].gsub(/[(\n)(\r)]/, "\n" => "
", "\r" => "" ).html_safe %>

此為系統自動發信,請勿直接回覆

diff --git a/app/views/asks/index.html.erb b/app/views/asks/index.html.erb index 6e7a8f3..8d70228 100644 --- a/app/views/asks/index.html.erb +++ b/app/views/asks/index.html.erb @@ -1,6 +1,7 @@ <% data = action_data @ask_question = data["ask_question"] @categories = data["categories"] + @tags = data["tags"] @module_app = data["module_app"] %> @@ -23,14 +24,10 @@ -
+
<%= f.label :identity, class: 'control-label required' %>
- <%= f.select :identity, options_for_select( [t('ask.teacher'), - t('ask.stuff'), - t('ask.student'), - t('ask.schoolfellow'), - t('ask.others')].map{|i| [i, i]} ) %> + <%= select_tag "ask_question[identity]", options_for_select(@tags.collect{|t| [ t.name, t.id ]}) if !@tags.nil? %>
diff --git a/ask.gemspec b/ask.gemspec index 75f6722..edc13f9 100644 --- a/ask.gemspec +++ b/ask.gemspec @@ -17,5 +17,5 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] s.test_files = Dir["test/**/*"] - s.add_dependency "gotcha" + # s.add_dependency ~> "gotcha" end diff --git a/config/locales/en.yml b/config/locales/en.yml index cdd0b56..b343ca1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,8 +1,12 @@ en: + situation: Situation + is_waiting: Pending + is_processed: Processed + is_referral: Rreferral ask: ask: Ask all_articles: All - export: Export + exports: Export reply: Reply reply_success: Reply success to: To @@ -15,10 +19,11 @@ en: schoolfellow: Schoolfellow others: Others acknowledgements: Thank You - admin: Administrator + admins: Administrator new_question: New question - pending: Pending + mongoid: attributes: ask_question: - ask_category_id: Ask Category \ No newline at end of file + ask_category_id: Ask Category + identity: Identity \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index bee83b6..80b7c6b 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -1,4 +1,11 @@ zh_tw: + + situation: 狀況 + identity: 身份 + is_waiting: 待處理 + is_processed: 已處理 + is_referral: 轉介其他單位 + module_name: ask: 發問 recaptcha: @@ -27,7 +34,6 @@ zh_tw: acknowledgements: 感謝詞 admins: 管理者 new_question: 新的發問 - pending: 待處理 mongoid: attributes: diff --git a/lib/ask/engine.rb b/lib/ask/engine.rb index 9d5c7bb..78622da 100644 --- a/lib/ask/engine.rb +++ b/lib/ask/engine.rb @@ -6,7 +6,7 @@ module Ask base_url File.expand_path File.dirname(__FILE__) # widget_methods ["widget","widget1"] # widget_settings [{"data_count"=>10}] - #taggable "AskQuestion" + taggable "AskQuestion" categorizable authorizable frontend_enabled @@ -45,6 +45,13 @@ module Ask :priority=>5, :active_for_action=>{'admin/asks'=>'exports'}, :available_for => 'managers' + context_link 'tags', + :link_path=>"admin_module_app_tags_path" , + :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'ask').id}", + :priority=>4, + :active_for_action=>{'admin/ask'=>'tags'}, + :active_for_tag => 'Ask', + :available_for => 'managers' # context_link 'new_', # :link_path=>"new_admin_ask_path" , # :priority=>2,