This commit is contained in:
BoHung Chiu 2021-10-12 21:26:26 +08:00
parent c344d04a97
commit d35c12f1fc
6 changed files with 60 additions and 7 deletions

View File

@ -8,18 +8,21 @@ class SurveysController < ApplicationController
current_user = OrbitHelper.current_user current_user = OrbitHelper.current_user
surveys = questionnairesurveys.collect do |a| surveys = questionnairesurveys.collect do |a|
answer_present = (current_user.nil? ? false : (a.survey_answers.where(:user => current_user.id).count > 0 ? true : false)) answer_present = (current_user.nil? ? false : (a.survey_answers.where(:user => current_user.id).count > 0 ? true : false))
show_link = OrbitHelper.url_to_show(a.to_param)
if !OrbitHelper.params[:page_no].blank? if !OrbitHelper.params[:page_no].blank?
title = ('<a href="'+ OrbitHelper.url_to_show(a.to_param) + "?method=show_data&page_no=#{OrbitHelper.params[:page_no]}" + '">' + a.title + '</a>').html_safe title = ('<a href="'+ show_link + "?method=show_data&page_no=#{OrbitHelper.params[:page_no]}" + '">' + a.title + '</a>').html_safe
else else
title = ('<a href="'+ OrbitHelper.url_to_show(a.to_param) + '?method=show_data">' + a.title + '</a>').html_safe title = ('<a href="'+ show_link + '?method=show_data">' + a.title + '</a>').html_safe
end
result = QuestionnaireSurvey.result(a)
if answer_present && a.needs_login
result += "<a href=\"#{show_link + "?method=my_record"}\" class=\"btn btn-primary\" title=\"#{t('survey.my_record')}\">#{t('survey.my_record')}</a>".html_safe
end end
{ {
"title" => title, "title" => title,
"time_range" => QuestionnaireSurvey.time_range(a), "time_range" => QuestionnaireSurvey.time_range(a),
"write" => QuestionnaireSurvey.write(a), "write" => QuestionnaireSurvey.write(a),
"result" => QuestionnaireSurvey.result(a), "result" => result,
"answer_present" => answer_present "answer_present" => answer_present
} }
end end

View File

@ -31,7 +31,7 @@ class SurveyAnswer
end end
end end
before_destroy do before_destroy do
answer_group = SurveyAnswerGroup.where(:user=>user).first answer_group = SurveyAnswerGroup.where(:user=>self.user,:questionnaire_survey_id=>self.questionnaire_survey_id).first
if answer_group if answer_group
answer_group.survey_answer_ids.delete(self.id) answer_group.survey_answer_ids.delete(self.id)
if answer_group.survey_answer_ids.count == 0 if answer_group.survey_answer_ids.count == 0

View File

@ -0,0 +1,20 @@
<table class="table table-hover table-striped survey-index">
<caption><h3>{{page-title}}</h3></caption>
<thead>
<tr>
<th class="col-md-5">{{th_title}}</th>
<th class="col-md-3">{{th_time_range}}</th>
<th class="col-md-1">{{th_write}}</th>
<th class="col-md-3">{{th_result}}</th>
</tr>
</thead>
<tbody data-level="0" data-list="surveys">
<tr>
<td>{{title}}</td>
<td>{{time_range}}</td>
<td>{{write}}</td>
<td>{{result}}</td>
</tr>
</tbody>
</table>
{{pagination_goes_here}}

12
modules/survey/info.json Normal file
View File

@ -0,0 +1,12 @@
{
"frontend": [
{
"filename" : "index",
"name" : {
"zh_tw" : "1. 列表",
"en" : "1. List"
},
"thumbnail" : "thumb.png"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -2,7 +2,25 @@ $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version: # Maintain your gem's version:
require "survey/version" require "survey/version"
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
if bundle_update_flag
app_path = File.expand_path(__dir__)
template_path = ENV['PWD'] + '/app/templates'
all_template = Dir.glob(template_path+'/*/')
puts 'copying module'
all_template.each do |folder|
if !folder.include?('mobile')
if folder.split('/')[-1] != 'mobile'
begin
system ('cp -r '+ app_path + '/modules/* ' + folder+'/modules/.')
puts "Updating survey to #{folder}"
rescue
puts "error updating survey in #{folder}"
end
end
end
end
end
# Describe your gem and declare its dependencies: # Describe your gem and declare its dependencies:
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "survey" s.name = "survey"