diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb index 333aaa2..53caee4 100644 --- a/app/controllers/surveys_controller.rb +++ b/app/controllers/surveys_controller.rb @@ -8,18 +8,21 @@ class SurveysController < ApplicationController current_user = OrbitHelper.current_user surveys = questionnairesurveys.collect do |a| 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? - title = ('' + a.title + '').html_safe + title = ('' + a.title + '').html_safe else - title = ('' + a.title + '').html_safe + title = ('' + a.title + '').html_safe + end + result = QuestionnaireSurvey.result(a) + if answer_present && a.needs_login + result += "#{t('survey.my_record')}".html_safe end - { "title" => title, "time_range" => QuestionnaireSurvey.time_range(a), "write" => QuestionnaireSurvey.write(a), - "result" => QuestionnaireSurvey.result(a), + "result" => result, "answer_present" => answer_present } end diff --git a/app/models/survey_answer.rb b/app/models/survey_answer.rb index 1e55407..73f00e1 100644 --- a/app/models/survey_answer.rb +++ b/app/models/survey_answer.rb @@ -31,7 +31,7 @@ class SurveyAnswer end end 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 answer_group.survey_answer_ids.delete(self.id) if answer_group.survey_answer_ids.count == 0 diff --git a/modules/survey/index.html.erb b/modules/survey/index.html.erb new file mode 100644 index 0000000..3ff4fa3 --- /dev/null +++ b/modules/survey/index.html.erb @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + +

{{page-title}}

{{th_title}}{{th_time_range}}{{th_write}}{{th_result}}
{{title}}{{time_range}}{{write}}{{result}}
+{{pagination_goes_here}} \ No newline at end of file diff --git a/modules/survey/info.json b/modules/survey/info.json new file mode 100644 index 0000000..cda3d13 --- /dev/null +++ b/modules/survey/info.json @@ -0,0 +1,12 @@ +{ + "frontend": [ + { + "filename" : "index", + "name" : { + "zh_tw" : "1. 列表", + "en" : "1. List" + }, + "thumbnail" : "thumb.png" + } + ] +} \ No newline at end of file diff --git a/modules/survey/thumbs/thumb.png b/modules/survey/thumbs/thumb.png new file mode 100644 index 0000000..266af56 Binary files /dev/null and b/modules/survey/thumbs/thumb.png differ diff --git a/survey.gemspec b/survey.gemspec index c7fd310..f8eb351 100644 --- a/survey.gemspec +++ b/survey.gemspec @@ -2,7 +2,25 @@ $:.push File.expand_path("../lib", __FILE__) # Maintain your gem's 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: Gem::Specification.new do |s| s.name = "survey"