From 8f8641114836143c0663eb09125794ba99979fe7 Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Mon, 20 Apr 2015 16:36:44 +0200 Subject: [PATCH] simplify grid construction move the html generation into a helper --- app/helpers/my_projects_overviews_helper.rb | 23 +++++++-- .../page_layout.html.erb | 51 ++++--------------- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/app/helpers/my_projects_overviews_helper.rb b/app/helpers/my_projects_overviews_helper.rb index 55967b6366..893ddc86a1 100644 --- a/app/helpers/my_projects_overviews_helper.rb +++ b/app/helpers/my_projects_overviews_helper.rb @@ -1,7 +1,7 @@ #-- copyright # OpenProject My Project Page Plugin # -# Copyright (C) 2011-2014 the OpenProject Foundation (OPF) +# Copyright (C) 2011-2015 the OpenProject Foundation (OPF) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License version 3. @@ -23,10 +23,10 @@ module MyProjectsOverviewsHelper TOP = %w(top) MIDDLE = %w(left right) - BOTTOM = %w(hidden) + HIDDEN = %w(hidden) def field_list - TOP + MIDDLE + BOTTOM + TOP + MIDDLE + HIDDEN end def visible_fields @@ -41,6 +41,18 @@ module MyProjectsOverviewsHelper raise NoMethodError end + def grid_field(name) + content_tag :div, id: "list-#{name}", class: %w(block-receiver) + [name] do + ActiveSupport::SafeBuffer.new(blocks[name].map do |block| + if block_available? block + render partial: 'block', locals: { block_name: block } + elsif block.respond_to? :to_ary + render partial: 'block_textilizable', locals: { block_name: block } + end + end.join) + end + end + def sortable_box(field) sortable_element "list-#{field}", tag: 'div', @@ -51,4 +63,9 @@ module MyProjectsOverviewsHelper constraint: false, url: { action: 'order_blocks', group: field } end + + def block_available?(block) + controller.class.available_blocks.keys.include? block + end + end diff --git a/app/views/my_projects_overviews/page_layout.html.erb b/app/views/my_projects_overviews/page_layout.html.erb index 1c0fb39853..c51b99a597 100644 --- a/app/views/my_projects_overviews/page_layout.html.erb +++ b/app/views/my_projects_overviews/page_layout.html.erb @@ -108,71 +108,42 @@ function addBlock() { //]]> -<% content_for :action_menu_specific do %> +<% content_for :toolbar do %>
  • - <%= form_tag({:action => "add_block"}, :id => "block-form") do %> - <%= select_tag 'block', + <%= styled_form_tag({:action => "add_block"}, :id => "block-form") do %> + <%= styled_select_tag 'block', ("" + options_for_select(block_options)).html_safe, :id => "block-select", :onChange => "addBlock();", - class: 'form--select -small' + class: 'form--select' %> <% end %>
  • -
  • <%= link_to l(:button_back), {:action => 'index'}, :class => 'icon icon-cancel' %>
  • +
  • <%= link_to l(:button_back), {:action => 'index'}, :class => 'button' %>
  • <% end %>

    <%=l(:label_overview)%>

    -<%= render :partial => 'layouts/action_menu_specific' %> +<%= render :partial => 'layouts/toolbar' %>

    <%=l(:label_visible_elements) %>

    <% top_fields.each do |f| %> -
    - <% blocks[f].each do |b| %> - <% if MyProjectsOverviewsController.available_blocks.keys.include? b %> - <%= render(:partial => 'block', :locals => { :block_name => b }) %> - <% elsif b.respond_to? :to_ary %> - <%= render(:partial => 'block_textilizable', - :locals => {:block_name => b.first, - :block_title => b[1], - :textile => b.last}) %> - <% end %> - <% end %> -
    + <%= grid_field f %> <% end %>
    <% middle_fields.each do |f| %> -
    - <% blocks[f].each do |b| %> - <% if MyProjectsOverviewsController.available_blocks.keys.include? b %> - <%= render(:partial => 'block', :locals => { :block_name => b }) %> - <% elsif b.respond_to? :to_ary %> - <%= render(:partial => 'block_textilizable', - :locals => {:block_name => b.first, - :block_title => b[1], - :textile => b.last}) %> - <% end %> - <% end %> -
    + <%= grid_field f %> <% end %>

    <%=l(:label_hidden_elements) %>

    -
    - <% blocks['hidden'].each do |b| %> - <% if MyProjectsOverviewsController.available_blocks.keys.include? b %> - <%= render(:partial => 'block', :locals => {:block_name => b}) %> - <% elsif b.respond_to? :to_ary %> - <%= render(:partial => 'block_textilizable', - :locals => {:block_name => b.first, - :block_title => b[1], - :textile => b.last}) %> - <% end %> +
    + <% hidden_fields.each do |f| %> + <%= grid_field f %> <% end %>