Compare commits

..
Author SHA1 Message Date
Manson Wang 0d4e58e2f1 Fix annoucement front_end displaying two promoter 2013-11-20 14:03:48 +08:00
Spen 385e77f189 add archive frontend table class 2013-11-19 10:33:43 +08:00
Spen d1fd2b6984 fix app sub manager and ask verification code 2013-11-07 18:06:16 +08:00
Spen 8f25dc2871 fix ntu ga survey export 2013-11-04 10:00:54 +08:00
thomaschen 82988a2029 Fix front-end tag cloud search under category filters 2013-11-01 16:22:08 +08:00
thomaschen e5fccb33bf Fix tag cloud search under category filters 2013-11-01 15:38:49 +08:00
thomaschen d832f4c4b1 can read the spreadsheet each row.(need to think of a method to parse each row to figure)
Conflicts:

	Gemfile
	vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb
2013-10-25 18:36:32 +08:00
thomaschen 59af75e50a fix error 2013-10-25 18:21:17 +08:00
Bernie Chiu 67cd34ab27 Add oneline and multiline import 2013-10-25 18:21:17 +08:00
thomaschen 4a736cc92c error fix 2013-10-25 18:21:17 +08:00
Bernie Chiu 9b96f2eeb0 Merge
Conflicts:

	vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb
2013-10-25 18:21:07 +08:00
Bernie Chiu 74b89f1fac Allow update answers on radio groups
Conflicts:

	vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb
2013-10-25 18:09:55 +08:00
thomaschen 62e9acdbb8 fix error 2013-10-25 18:05:37 +08:00
thomaschen 4a897b68cf merge 2013-10-25 18:05:37 +08:00
Bernie Chiu d3fc6e5956 Add import on radiogroups on file change 2013-10-25 18:05:37 +08:00
Bernie Chiu 71acee200c Fix encoding issue and add import on title change 2013-10-25 18:05:37 +08:00
thomaschen 63156c7a95 remove unuse variable and comment 2013-10-25 18:05:37 +08:00
thomaschen 5156701094 import 'check' and 'select' question success 2013-10-25 18:05:37 +08:00
thomaschen 1266cd1384 fix import-csv column error 2013-10-25 18:05:37 +08:00
thomaschen f3f4dc842c import radio question success
Conflicts:

	Gemfile
	vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb
2013-10-25 17:56:49 +08:00
Spen 13144f62fb add ntu_ga survey init sorting 2013-10-18 18:17:05 +08:00
Bernie Chiu 6d951f8d9c Add correct department links 2013-10-18 16:20:13 +08:00
15 changed files with 225 additions and 49 deletions

No files matched your search

+3
View File
@@ -29,6 +29,9 @@ gem 'mongoid-tree', :require => 'mongoid/tree'
gem "mongo_session_store-rails3", '3.0.6'
gem 'nokogiri'
# import csv
gem 'roo'
gem 'fb_graph'
gem 'rack-gridfs'
gem 'radius'
+7 -2
View File
@@ -15,8 +15,13 @@ class ObjectAuth < PrototypeAuth
end
def check_user_has_can_access_app
sub_managing_users = auth_obj.module_app.sub_managing_users rescue []
module_app = auth_obj.module_app
if auth_obj["_type"] == "PageContext"
module_app = ModuleApp.where(:key=>'page_content').first
sub_managing_users = module_app.sub_managing_users rescue []
else
sub_managing_users = auth_obj.module_app.sub_managing_users rescue []
module_app = auth_obj.module_app
end
self.auth_users.each do |auth_user|
if !sub_managing_users.include? auth_user && !auth_user.admin?
module_app.assign_sub_manager(auth_user,User.current)
+10
View File
@@ -55,6 +55,16 @@ class PrototypeAuth
if (self.send item).include? obj.id
(self.send item).delete obj.id
self.save!
if auth_obj["_type"] == "PageContext"
module_app = ModuleApp.where(:key=>'page_content').first
else
module_app = auth_obj.module_app
end
module_app.remove_sub_manager(obj)
module_app.save
else
false #should put error message for user not existed in list
end
@@ -44,15 +44,8 @@
<% end %>
</div>
<% unless @bulletin.user_ids.blank? %>
<div class="promoter">
<div>
<p><%= t(:promoter) %>:</p>
<span><%= @bulletin.get_users.map{|u| "<span>#{u.name}</span>"}.join(', ').html_safe %></span>
</div>
</div>
<% end %>
<%= share_links(@bulletin, 'announcement') %>
<%= render partial: 'admin/member_selects/promoter_front', locals: {users: @bulletin.get_users} %>
<% unless @bulletin.user_ids.blank? %>
<%= render partial: 'admin/member_selects/promoter_front', locals: {users: @bulletin.get_users} %>
<% end %>
@@ -31,18 +31,29 @@ class Panel::Archive::FrontEnd::ArchiveFilesController < OrbitWidgetController
@archive_file_categorys = ArchiveFileCategory.all
# @archive_files = ArchiveFile.where( :is_hidden => false ).desc(:is_top).page(params[:page]).per(@page_num)
# if !params[:category_id].blank? && !params[:tag_id].blank?
# @archive_files = @archive_files.default_sort(params[:sort]).can_display.where(:archive_file_category_id.in => params[:category_id], :tagged_ids.in => params[:tag_id]).desc( :is_top ).page( params[:page_main] ).per(@page_num)
# @current_category = ArchiveFileCategory.from_id(params[:category_id]) rescue nil
# elsif !params[:category_id].blank?
# @archive_files = ArchiveFile.default_sort(params[:sort]).can_display.where(:archive_file_category_id.in => params[:category_id]).desc( :is_top ).page( params[:page_main] ).per(@page_num)
# @current_category = ArchiveFileCategory.from_id(params[:category_id]) rescue nil
# elsif !params[:tag_id].blank?
# @archive_files = ArchiveFile.default_sort(params[:sort]).can_display.where(:tagged_ids.in => params[:tag_id]).desc( :is_top ).page( params[:page_main] ).per(@page_num)
# else
# @archive_files = ArchiveFile.default_sort(params[:sort]).can_display.desc( :is_top ).page( params[:page_main] ).per(@page_num)
# end
if !params[:category_id].blank? && !params[:tag_id].blank?
@archive_files = @archive_files.default_sort(params[:sort]).can_display.where(:archive_file_category_id.in => params[:category_id], :tagged_ids.in => params[:tag_id]).desc( :is_top ).page( params[:page_main] ).per(@page_num)
@current_category = ArchiveFileCategory.from_id(params[:category_id]) rescue nil
elsif !params[:category_id].blank?
@archive_files = ArchiveFile.default_sort(params[:sort]).can_display.where(:archive_file_category_id.in => params[:category_id]).desc( :is_top ).page( params[:page_main] ).per(@page_num)
@current_category = ArchiveFileCategory.from_id(params[:category_id]) rescue nil
@archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.where(:tagged_ids.in => params[:tag_id]).any_in(:archive_file_category_id => params[:category_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num)
@current_category = ArchiveFileCategory.any_in(:_id => params[:category_id]).excludes('disable' => true)
elsif !params[:category_id].blank?
@archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.any_in(:archive_file_category_id => params[:category_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num)
@current_category = ArchiveFileCategory.any_in(:_id => params[:category_id]).excludes('disable' => true)
elsif !params[:tag_id].blank?
@archive_files = ArchiveFile.default_sort(params[:sort]).can_display.where(:tagged_ids.in => params[:tag_id]).desc( :is_top ).page( params[:page_main] ).per(@page_num)
@archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.any_in(:tagged_ids => params[:tag_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num)
else
@archive_files = ArchiveFile.default_sort(params[:sort]).can_display.desc( :is_top ).page( params[:page_main] ).per(@page_num)
@archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top).page( params[:page_main] ).per(@page_num)
end
@@ -27,8 +27,10 @@ class Panel::Archive::Widget::ArchiveFilesController < OrbitWidgetController
@category_id = @part.category
date_now = Time.now
if !params[:category_id].blank?
if !params[:category_id].blank? && !params[:tag_id].blank?
@archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.where(:tagged_ids.in => params[:tag_id]).any_in(:archive_file_category_id => params[:category_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num)
@archive_file_categorys = ArchiveFileCategory.any_in(:_id => params[:category_id]).excludes('disable' => true)
elsif !params[:category_id].blank?
@archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.any_in(:archive_file_category_id => params[:category_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num)
@archive_file_categorys = ArchiveFileCategory.any_in(:_id => params[:category_id]).excludes('disable' => true)
elsif !params[:tag_id].blank?
@@ -8,15 +8,15 @@
<tr>
<th class="column-ctrl col-title"><%= sortable(:title, t("archive.Title"))%></th>
<th class="column-ctrl col-file"><%= t("archive.Files")%></th>
<th class="column-ctrl col-file"><%= t(:promoter)%></th>
<th class="column-ctrl col-promoter"><%= t(:promoter)%></th>
</tr>
</thead>
<tbody>
<% @archive_files.each_with_index do |post,i| %>
<tr <% if ( (i + 1) % 2 ) == 0 %> class="even" <% end %>>
<td><div class="o-archives-title"><%= post.title %></div></td>
<td>
<td class="col-title"><div class="o-archives-title"><%= post.title %></div></td>
<td class="col-file">
<div class="o-archives-list-item">
<% if !post.archive_file_multiples.blank? %>
<ol>
@@ -32,7 +32,7 @@
<% end %>
</div>
</td>
<td>
<td class="col-promoter">
<% unless post.get_users.blank? %>
<div class="promoter-block">
<ul>
@@ -1,6 +1,9 @@
<script type="text/javascript">
var local_host = "<%= request.host %>";
if (local_host[0] == "g" && local_host[1] == "a") {
local_host = "www." + local_host;
}
function hide_current_host_name(localhost) {
$('input[type=checkbox]').each(function() {
@@ -80,21 +83,22 @@ $(document).ready(function() {
<tr>
<td colspan="5" class="dept_options">
<div class="dept_options">
<%= check_box("school", "depts", {:multiple => true}, 'ntu_ga_test_p.tp.rulingcom.com', nil) %><%= label_tag("ntu_ga_test_p.tp.rulingcom.com", "測試站總務處 (ntu_ga_test_p)") %>
<%= check_box("school", "depts", {:multiple => true}, 'ntu_ga_test.tp.rulingcom.com', nil) %><%= label_tag("ntu_ga_test.tp.rulingcom.com", "測試站總務處經管組 (ntu_ga_test)") %>
<!-- Example <%= check_box("school", "depts", {:multiple => true}, 'ntu_ga_test_p.tp.rulingcom.com', nil) %><%= label_tag("ntu_ga_test_p.tp.rulingcom.com", "測試站總務處 (ntu_ga_test_p)") %>
<%= check_box("school", "depts", {:multiple => true}, 'ntu_ga_test.tp.rulingcom.com', nil) %><%= label_tag("ntu_ga_test.tp.rulingcom.com", "測試站總務處經管組 (ntu_ga_test)") %> -->
<!-- <%= check_box("school", "depts", {:multiple => true}, (request.host + ":3000"), nil) %><%= label_tag((request.host + ":3000"), "測試站3000") %>
<%= check_box("school", "depts", {:multiple => true}, (request.host + ":4000"), nil) %><%= label_tag((request.host + ":4000"), "測試站4000") %> -->
<%= check_box("school", "depts", {:multiple => true}, "", nil) %><%= label_tag(:dep1, "總務長室暨總務處秘書室") %>
<%= check_box("school", "depts", {:multiple => true}, "文書組", nil) %><%= label_tag(:dep2, "文書組") %>
<%= check_box("school", "depts", {:multiple => true}, "事務組", nil) %><%= label_tag(:dep3, "事務組") %>
<%= check_box("school", "depts", {:multiple => true}, "保管組", nil) %><%= label_tag(:dep4, "保管組") %>
<%= check_box("school", "depts", {:multiple => true}, "營繕組", nil) %><%= label_tag(:dep5, "營繕組") %>
<%= check_box("school", "depts", {:multiple => true}, "出納組", nil) %><%= label_tag(:dep6, "出納組") %>
<%= check_box("school", "depts", {:multiple => true}, "採購組", nil) %><%= label_tag(:dep7, "採購組") %>
<%= check_box("school", "depts", {:multiple => true}, "經營管理組", nil) %><%= label_tag(:dep8, "經營管理組") %>
<%= check_box("school", "depts", {:multiple => true}, "駐警隊", nil) %><%= label_tag(:dep9, "駐警隊") %>
<%= check_box("school", "depts", {:multiple => true}, "社科院總務分處", nil) %><%= label_tag(:dep10, "社科院總務分處") %>
<%= check_box("school", "depts", {:multiple => true}, "醫學院總務分處", nil) %><%= label_tag(:dep11, "醫學院總務分處") %>
<%= check_box("school", "depts", {:multiple => true}, "www.ga.ntu.edu.tw", nil) %><%= label_tag("www.ga.ntu.edu.tw", "總務處") %>
<%= check_box("school", "depts", {:multiple => true}, "sec.ga.ntu.edu.tw", nil) %><%= label_tag("sec.ga.ntu.edu.tw", "總務長室暨總務處秘書室") %>
<%= check_box("school", "depts", {:multiple => true}, "doc.ga.ntu.edu.tw", nil) %><%= label_tag("doc.ga.ntu.edu.tw", "文書組") %>
<%= check_box("school", "depts", {:multiple => true}, "general.ga.ntu.edu.tw", nil) %><%= label_tag("general.ga.ntu.edu.tw", "事務組") %>
<%= check_box("school", "depts", {:multiple => true}, "property.ga.ntu.edu.tw", nil) %><%= label_tag("property.ga.ntu.edu.tw", "保管組") %>
<%= check_box("school", "depts", {:multiple => true}, "construction.ga.ntu.edu.tw", nil) %><%= label_tag("construction.ga.ntu.edu.tw", "營繕組") %>
<%= check_box("school", "depts", {:multiple => true}, "cashier.ga.ntu.edu.tw", nil) %><%= label_tag("cashier.ga.ntu.edu.tw", "出納組") %>
<%= check_box("school", "depts", {:multiple => true}, "procurement.ga.ntu.edu.tw", nil) %><%= label_tag("procurement.ga.ntu.edu.tw", "採購組") %>
<%= check_box("school", "depts", {:multiple => true}, "fss.ga.ntu.edu.tw", nil) %><%= label_tag("fss.ga.ntu.edu.tw", "經營管理組") %>
<%= check_box("school", "depts", {:multiple => true}, "police.ga.ntu.edu.tw", nil) %><%= label_tag("police.ga.ntu.edu.tw", "駐警隊") %>
<%= check_box("school", "depts", {:multiple => true}, "social.ga.ntu.edu.tw", nil) %><%= label_tag("social.ga.ntu.edu.tw", "社科院總務分處") %>
<%= check_box("school", "depts", {:multiple => true}, "medicine.ga.ntu.edu.tw", nil) %><%= label_tag("medicine.ga.ntu.edu.tw", "醫學院總務分處") %>
</div>
</td>
</tr>
@@ -85,7 +85,9 @@ $(document).ready(function(){
</div>
</div>
<div class="control-group">
<%= f.label t('ask.validate_code'), class: 'control-label required' %>
<div class="controls">
<label><%= t('ask.validate_code_note') %></label>
<%= gotcha_error %>
<%= gotcha%>
</div>
+2
View File
@@ -18,6 +18,8 @@ en:
admin: Administrator
new_question: New question
pending: Pending
validate_code: Verification code
validate_code_note: Please answer the following verification questions.
mongoid:
attributes:
ask_question:
@@ -23,6 +23,8 @@ zh_tw:
admin: 管理者
new_question: 新的發問
pending: 待處理
validate_code: 驗證碼
validate_code_note: 請回答下列驗證問句。
mongoid:
attributes:
ask_question:
@@ -2,7 +2,7 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll
before_filter :force_order_for_visitor,:only=>[:index]
before_filter :force_order_for_user,:except => [:index]
before_filter :for_app_manager,:except => [:index]
# before_filter :for_app_manager,:except => [:index]
before_filter :for_app_sub_manager,:except => [:index]
#before_filter :is_admin?
@@ -4,7 +4,7 @@
<%= page_context.page.title %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<%if is_manager? || is_admin? || page_context.authed_users(:edit).include?(current_user)%>
<%if is_manager? || is_admin? || page_context.authed_users("Edit").include?(current_user)%>
<li><%= link_to t(:edit), edit_panel_page_content_back_end_page_context_path(page_context, page: params[:page], sort: params[:sort], direction: params[:direction], sort_options: params[:sort_options]) %></li>
<%if (is_manager? || is_admin?) %>
<li><%=show_page_context_edit_auth_link page_context%></li>
@@ -1,4 +1,8 @@
require 'csv'
require 'iconv'
require 'roo'
# encoding: UTF-8
class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
@@ -90,13 +94,147 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
end
def import
@survey = ::Survey.find(params[:id])
@chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data
@file = params[:file]
case File.extname(@file.original_filename)
when ".csv" then @spreadsheet = Roo::CSV.new(@file.path, csv_options: {encoding: Encoding::Big5})
# when ".xls" then Excel.new(file.path, nil, :ignore)
# when ".xlsx" then Excelx.new(file.path, nil, :ignore)
else raise "Unknown file type: #{file.original_filename}"
end
# Modify titles if changed
titles = @spreadsheet.row(1) - [" "]
@survey_questions.each_with_index do |question, index|
question.update_attributes(title: titles[index])
end
@survey_answers.destroy
# Start and end of speadsheet
@end_row = @spreadsheet.count
@max_row_start = 0
@survey_questions.each do |question|
case question.type
when ::SurveyQuestion::Radio, ::SurveyQuestion::Select, ::SurveyQuestion::Check
if question.survey_question_options.count > @max_row_start
@max_row_start = question.survey_question_options.count
end
when ::SurveyQuestion::Radiogroup
if question.survey_question_options.count * question.survey_question_radiogroups.count > @max_row_start
@max_row_start = question.survey_question_options.count * question.survey_question_radiogroups.count
end
end
end
@start_row = @max_row_start + 2
# Modify multiline options if changed
(@start_row..@end_row).each do |row|
@answer_model = @survey.survey_answers.new
@survey_questions.each_with_index do |question, index|
case question.type
when ::SurveyQuestion::Oneline, ::SurveyQuestion::Multiline
@answer_model[question.id.to_s] = @spreadsheet.row(row)[index * 2]
when ::SurveyQuestion::Radio, ::SurveyQuestion::Select
if !@spreadsheet.row(row)[index*2].nil? && @spreadsheet.row(row)[index*2] != " "
@answer_model[question.id.to_s] = @spreadsheet.row(row)[index*2]
end
when ::SurveyQuestion::Check
if !@spreadsheet.row(row)[index*2].nil? && @spreadsheet.row(row)[index*2] != " "
@answer_model[question.id.to_s] = @spreadsheet.row(row)[index*2].split("\"").select.each_with_index { |str, i| i.odd? }
end
when ::SurveyQuestion::Radiogroup
radio_groups = []
spreadsheet_radiogroups_lines =
question.survey_question_options.count * question.survey_question_radiogroups.count + 2
# Grab each radiogroups line for update
(2...spreadsheet_radiogroups_lines).each do |line|
radio_groups << @spreadsheet.row(line)[index * 2]
end
# Grab answers info
answers = []
if not @spreadsheet.row(row)[index * 2].blank?
answers << eval(@spreadsheet.row(row)[index * 2])
end
# Save the answers
answers.each do |answer|
options = Hash[question.survey_question_options.collect { |o| [ o.id.to_s, o.name ] }]
# @answer_model = @survey.survey_answers.new
@answer_model[question.id.to_s] = {}
answer.each do |option, value|
@answer_model[question.id.to_s][options.invert[option]] = value
end
# @answer_model.save!
end
# Parse the needed info in the array
radio_titles = []
radio_options = []
radio_groups.each do |group|
option_with_radio = group.split(' - ')
radio_titles << option_with_radio[0]
radio_options << option_with_radio[1]
end
# Update the spreadsheet info to the DB
groups_of_options = []
groups_of_radios = []
radio_titles.each_slice(question.survey_question_radiogroups.count) do |options|
groups_of_options << options
end
radio_options.each_slice(question.survey_question_radiogroups.count) do |options|
groups_of_radios << options
end
# Update option names
question.survey_question_options.each_with_index do |option, index|
groups_of_options[index].each do |modified_option|
if option.name_translations["zh_tw"] != modified_option
option.update_attributes(name: modified_option)
break
end
end
end
# Update radio names
question.survey_question_radiogroups.each_with_index do |option, index|
groups_of_radios.each do |radios|
if radios[index] != option.name_translations["zh_tw"]
option.update_attributes(name: radios[index])
break
end
end
end
end
end
@answer_model.save!
end #end row
redirect_to panel_survey_back_end_surveys_url, :notice => :success
end
def export
@survey = ::Survey.find(params[:id])
@chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data
csv = CSV.generate do |csv|
head = 'EF BB BF'.split(' ').map{|a|a.hex.chr}.join()
csv = CSV.generate(csv = head) do |csv|
row = []
@survey_questions.each do |question|
row << question.title
@@ -141,7 +279,7 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
@survey_questions.each do |question|
if question.type == ::SurveyQuestion::Radiogroup
options = Hash[question.survey_question_options.collect{|o| [ o.id.to_s, o.name ] }]
row << Hash[answer[question.id.to_s].map {|o, g| [options[o], g]}]
row << Hash[answer[question.id.to_s].map {|o, g| [options[o], g]}] if !answer[question.id.to_s].blank?
else
row << answer[question.id.to_s]
end
@@ -153,11 +291,16 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
end
respond_to do |format|
format.csv do
response.headers["Content-Type"] = "text/csv; charset=big5"
render :text => csv.encode('Big5')
end
format.html
format.csv { send_data csv }
end
# respond_to do |format|
# format.csv do
# response.headers["Content-Type"] = "text/csv; charset=big5"
# render :text => csv.encode('Big5')
# end
# end
end
def set_answers
@@ -44,5 +44,4 @@ class SurveyQuestion
def get_jump_tos
Hash[survey_question_options.select{ |o| !o.jump_to.blank? }.collect{ |o| [o.id.to_s, o.jump_to] }]
end
end