-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
294e394
commit 537a1ee
Showing
53 changed files
with
1,843 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
class Guide::Agents::Nodes::GuideController < ApplicationController | ||
include Cms::NodeFilter::View | ||
helper Guide::ListHelper | ||
|
||
before_action :set_answers | ||
|
||
private | ||
|
||
def set_answers | ||
@answers = params[:condition].to_s | ||
@answers = @answers.split("-").map { |transitions| transitions.split(",") } | ||
|
||
if params[:question].present? | ||
question = ::Guide::Question.find(params[:question]) | ||
question_type = question.question_type | ||
|
||
if params[:answers].present? | ||
if question_type == "choices" | ||
params[:answers].each do |no, transitions| | ||
@answers[no.to_i] = transitions | ||
end | ||
elsif question_type == "yes_no" | ||
params[:answers].each do |no, transitions| | ||
if params[:submit] == I18n.t("guide.links.applicable") | ||
transitions = [transitions[0]] | ||
elsif params[:submit] == I18n.t("guide.links.not_applicable") | ||
transitions = [transitions[1]] | ||
else | ||
transitions = [] | ||
end | ||
@answers[no.to_i] = transitions | ||
end | ||
else | ||
params[:answers].each do |no, transitions| | ||
@answers[no.to_i] = [] | ||
end | ||
end | ||
end | ||
end | ||
|
||
condition = @answers.map { |transitios| transitios.join(",") } | ||
@condition = condition.join("-") | ||
|
||
condition.pop | ||
@before_condition = condition.join("-") | ||
|
||
@no = @answers.size | ||
end | ||
|
||
public | ||
|
||
def index | ||
@diagram = ::Guide::QuestionDiagram.new @cur_node | ||
@diagram.input_answers(@answers) | ||
end | ||
|
||
def dialog | ||
@diagram = ::Guide::QuestionDiagram.new @cur_node | ||
@question = @diagram.input_answers(@answers).first | ||
|
||
@longest_length = @diagram.longest_length | ||
@evaluated_length = @diagram.evaluated_length | ||
|
||
if @question.nil? | ||
redirect_to "#{@cur_node.url}result/#{@condition}" | ||
return | ||
else | ||
render :dialog | ||
end | ||
end | ||
|
||
def result | ||
@cur_node.name = "【結果】#{@cur_node.name}" | ||
|
||
@diagram = ::Guide::QuestionDiagram.new @cur_node | ||
@diagram.input_answers(@answers) | ||
@procedures = @diagram.procedures | ||
@other_procedures = @cur_node.procedures | ||
end | ||
|
||
def answer | ||
@cur_node.name = "【結果】#{@cur_node.name}" | ||
|
||
@diagram = ::Guide::QuestionDiagram.new @cur_node | ||
@diagram.input_answers(@answers) | ||
@procedures = @diagram.procedures | ||
end | ||
|
||
def procedure | ||
@cur_node.name = "【結果】#{@cur_node.name}" | ||
|
||
@diagram = ::Guide::QuestionDiagram.new @cur_node | ||
@procedures = @diagram.all_procedures | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Guide::Apis::ProceduresController < ApplicationController | ||
include Cms::ApiFilter | ||
|
||
model Guide::Procedure | ||
|
||
def index | ||
@multi = params[:single].blank? | ||
@node = Cms::Node.find(params[:nid]) | ||
@id = params[:id].to_i | ||
|
||
@items = @model.site(@cur_site). | ||
node(@node). | ||
ne(id: @id). | ||
allow(:read, @cur_user, site: @cur_site). | ||
search(params[:s]). | ||
page(params[:page]).per(50) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Guide::Apis::QuestionsController < ApplicationController | ||
include Cms::ApiFilter | ||
|
||
model Guide::Question | ||
|
||
def index | ||
@multi = params[:single].blank? | ||
@node = Cms::Node.find(params[:nid]) | ||
@id = params[:id].to_i | ||
|
||
@items = @model.site(@cur_site). | ||
node(@node). | ||
ne(id: @id). | ||
where(referenced_question_ids: []). | ||
allow(:read, @cur_user, site: @cur_site). | ||
search(params[:s]). | ||
page(params[:page]).per(50) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Guide::DiagramController < ApplicationController | ||
include Cms::BaseFilter | ||
|
||
navi_view "cms/node/main/navi" | ||
|
||
def index | ||
@item = Guide::QuestionDiagram.new(@cur_node) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Guide::GuidesController < ApplicationController | ||
include Cms::BaseFilter | ||
|
||
def index | ||
redirect_to guide_questions_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Guide::ProceduresController < ApplicationController | ||
include Cms::BaseFilter | ||
include Cms::CrudFilter | ||
|
||
model Guide::Procedure | ||
navi_view "cms/node/main/navi" | ||
|
||
private | ||
|
||
def set_crumbs | ||
@crumbs << [t("guide.procedure"), action: :index] | ||
end | ||
|
||
def fix_params | ||
{ cur_site: @cur_site, cur_node: @cur_node } | ||
end | ||
|
||
public | ||
|
||
def index | ||
@items = @model.site(@cur_site). | ||
node(@cur_node). | ||
search(params[:s]). | ||
allow(:read, @cur_user, site: @cur_site) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Guide::QuestionsController < ApplicationController | ||
include Cms::BaseFilter | ||
include Cms::CrudFilter | ||
|
||
model Guide::Question | ||
navi_view "cms/node/main/navi" | ||
|
||
private | ||
|
||
def set_crumbs | ||
@crumbs << [t("guide.question"), action: :index] | ||
end | ||
|
||
def fix_params | ||
{ cur_site: @cur_site, cur_node: @cur_node } | ||
end | ||
|
||
public | ||
|
||
def index | ||
@items = @model.site(@cur_site). | ||
node(@cur_node). | ||
search(params[:s]). | ||
allow(:read, @cur_user, site: @cur_site) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module Guide::ListHelper | ||
def default_procedure_loop_html | ||
ih = [] | ||
ih << '<dl class="procedure item-#{id}">' | ||
ih << ' <dt>#{link}</dt>' | ||
ih << ' <dd>#{html}</dd>' | ||
ih << '</dl>' | ||
ih.join("\n").freeze | ||
end | ||
|
||
def default_procedure_loop_liquid | ||
ih = [] | ||
ih << '{% for item in procedures %}' | ||
ih << '<dl class="procedure item-{{ item.id }}">' | ||
ih << ' <dt>' | ||
ih << ' {% if item.link_url %}' | ||
ih << ' <a href="{{ item.link_url }}">{{ item.name }}</a>' | ||
ih << ' {% else %}' | ||
ih << ' {{ item.name }}' | ||
ih << ' {% endif %}' | ||
ih << ' </dt>' | ||
ih << ' <dd>{{ item.procedure_location }}</dd>' | ||
ih << '</dl>' | ||
ih << '{% endfor %}' | ||
ih.join("\n").freeze | ||
end | ||
|
||
def render_procedure_list(items) | ||
@cur_node.cur_date = @cur_date | ||
if @cur_node.loop_format_shirasagi? | ||
render_list_with_shirasagi(items) | ||
else | ||
source = @cur_node.loop_liquid.presence || default_procedure_loop_liquid | ||
assigns = { "procedures" => items.to_a } | ||
render_list_with_liquid(source, assigns) | ||
end | ||
end | ||
|
||
private | ||
|
||
def render_list_with_shirasagi(items) | ||
h = [] | ||
|
||
if @cur_node.loop_setting.present? | ||
loop_html = @cur_node.loop_setting.html | ||
elsif @cur_node.loop_html.present? | ||
loop_html = @cur_node.loop_html | ||
else | ||
loop_html = default_procedure_loop_html | ||
end | ||
|
||
items.each do |item| | ||
ih = @cur_node.render_loop_html(item, html: loop_html) | ||
h << ih | ||
end | ||
|
||
h.join("\n").html_safe | ||
end | ||
|
||
def render_list_with_liquid(source, assigns) | ||
template = ::Cms.parse_liquid(source, liquid_registers) | ||
assigns["node"] = @cur_node | ||
template.render(assigns).html_safe | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require "csv" | ||
|
||
class Guide::Procedure::ImportJob < Cms::ApplicationJob | ||
def put_log(message) | ||
Rails.logger.info(message) | ||
end | ||
|
||
def perform(ss_file_id) | ||
file = ::SS::File.find(ss_file_id) | ||
|
||
put_log("import start " + ::File.basename(file.name)) | ||
import_csv(file) | ||
|
||
file.destroy | ||
end | ||
|
||
def model | ||
Guide::Procedure | ||
end | ||
|
||
def import_csv(file) | ||
table = CSV.read(file.path, headers: true, encoding: 'SJIS:UTF-8') | ||
table.each_with_index do |row, i| | ||
begin | ||
item = update_row(row, i + 2) | ||
put_log("update #{i + 1}: #{item.name}") if item.present? | ||
rescue => e | ||
put_log("error #{i + 1}: #{e}") | ||
end | ||
end | ||
end | ||
|
||
def update_row(row, index) | ||
item = model.find_or_initialize_by(site_id: site.id, name: row[model.t(:name)]) | ||
set_attributes(row, item) | ||
|
||
item.save ? item : raise(item.errors.full_messages.join(", ")) | ||
end | ||
|
||
def value(row, key) | ||
row[model.t(key)].try(:strip) | ||
end | ||
|
||
def ary_value(row, key) | ||
row[model.t(key)].to_s.split(/\n/).map(&:strip) | ||
end | ||
|
||
def set_question_ids(values) | ||
values.collect do |value| | ||
column = Guide::Question.find_or_initialize_by(site_id: site.id, question: value) | ||
column.name ||= value | ||
column.save! | ||
column.id | ||
end | ||
end | ||
|
||
def set_attributes(row, item) | ||
item.site_id = site.id | ||
item.name = value(row, :name) | ||
item.link_url = value(row, :link_url) | ||
item.html = value(row, :html) | ||
item.procedure_location = value(row, :procedure_location) | ||
item.belongings = value(row, :belongings) | ||
item.procedure_applicant = value(row, :procedure_applicant) | ||
item.remarks = value(row, :remarks) | ||
item.order = value(row, :order) | ||
item.question_ids = set_question_ids(ary_value(row, :question_ids)) | ||
end | ||
end |
Oops, something went wrong.