diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index 17215e8..18e58f6 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -90,34 +90,14 @@ end end - - #show and edit a phase of the template def admin_show - @phase = Phase.eager_load(:sections).find_by('phases.id = ?', params[:id]) + @phase = Phase.includes(:sections).order(:number).find(params[:id]) authorize @phase @current = Template.current(@phase.template.dmptemplate_id) @edit = (@phase.template.org == current_user.org) && (@phase.template == @current) - #@edit = params[:edit] == "true" ? true : false - #verify if there are any sections if not create one - @sections = @phase.sections - if !@sections.any?() || @sections.count == 0 - @section = @phase.sections.build - @section.phase = @phase - @section.title = '' - @section.number = 1 - @section.published = true - @section.modifiable = true - @section.save - @new_sec = true - end - #verify if section_id has been passed, if so then open that section - if params.has_key?(:section_id) - @open = true - @section_id = params[:section_id].to_i - end if params.has_key?(:question_id) @question_id = params[:question_id].to_i end @@ -131,9 +111,8 @@ partial_path: 'admin_show', phase: @phase, template: @phase.template, - current: @current, edit: @edit, - sections: @sections + current_section: params.has_key?(:section_id) ? params[:section_id].to_i : nil }) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8c8ca84..ee6590a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -23,7 +23,7 @@ # see http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-fullpath for details # --------------------------------------------------------------------------- def isActivePage(path) - return request.fullpath() == path + return request.fullpath.include?(path) end def fingerprinted_asset(name) diff --git a/app/views/phases/_admin_show.html.erb b/app/views/phases/_admin_show.html.erb index 8f800ec..da337a5 100644 --- a/app/views/phases/_admin_show.html.erb +++ b/app/views/phases/_admin_show.html.erb @@ -1,3 +1,4 @@ +<% # locals: { phase, template, edit, current_section } %>

<%= _('Phase details')%>

@@ -19,17 +20,26 @@
- <% sections.order('number ASC').each do |section| %> + <% phase.sections.each do |section| %>
-
" class="panel-collapse collapse" role="tabpanel" aria-labelledby="<%= "headingSection#{section.id}" %>"> +
" + class="panel-collapse collapse<%= " in" if section.id == current_section %>" + role="tabpanel" + aria-labelledby="<%= "headingSection#{section.id}" %>">
<% if edit && section.modifiable %> <%= render partial: 'sections/edit_section', locals: { section: section, edit: edit, phase: phase } %> @@ -45,12 +55,12 @@
- <%= link_to(_('Add Section'), '#', { class: "btn btn-default section_new_link", role: "button" }) %> + <%= link_to(_('Add Section'), "#section_new#{phase.id}", { class: "btn btn-default section_new_link", role: "button" }) %>
-
diff --git a/app/views/sections/_edit_section.html.erb b/app/views/sections/_edit_section.html.erb index b747dc3..e7cca30 100644 --- a/app/views/sections/_edit_section.html.erb +++ b/app/views/sections/_edit_section.html.erb @@ -33,11 +33,11 @@ confirm: _("You are about to delete '%{section_title}'. This will affect questions linked to this section. Are you sure?") % { :section_title => section.title }, method: :delete, class: 'btn btn-default', role:'button' %>
<% end %> - -
-

<%= _('Questions') %>

- <% questions = section.questions.order('number') %> - <% if questions.present? %> +
+
+

<%= _('Questions') %>

+ <% questions = section.questions.order('number') %> + <% if questions.present? %> <% questions.each do |question| %>
"> @@ -46,36 +46,19 @@
" style="display: none;"> <%= render partial: 'questions/edit_question', locals: {question: question} %>
- <% if questions.last.id == question.id %> -
- <% end %> + <%= raw("
") if questions.last.id == question.id %> <% end %> - <% end %> -
+ <% end %>
-
+
<%= link_to(_('Add Question'), '#', { class: 'btn btn-default question_new_link', role: "button" }) %>
- - -
-
-
- <%= link_to(_('Add Section'), '#', { class: "btn btn-default section_new_link", role: "button" }) %> -
-
-
- -
-
\ No newline at end of file diff --git a/test/functional/phases_controller_test.rb b/test/functional/phases_controller_test.rb index dc87a1b..68b839f 100644 --- a/test/functional/phases_controller_test.rb +++ b/test/functional/phases_controller_test.rb @@ -102,8 +102,6 @@ assert_response :success assert assigns(:phase) - #assert assigns(:edit) - assert assigns(:sections) end # GET /org/admin/templates/phases/:id/admin_preview (admin_preview_phase_path)