From 809290c656902da721fd773fef55f90f9d649c13 Mon Sep 17 00:00:00 2001 From: jpl Date: Wed, 1 Feb 2017 18:42:07 +0100 Subject: Refs #2485: adding pageHeader helper, to keep views simple --- app/helpers/application_helper.rb | 2 +- app/helpers/newapplication_helper.rb | 155 +++++++++++++++++++++++++++++++++++ app/helpers/newfront_helper.rb | 118 -------------------------- app/views/workbenches/show.html.slim | 28 ++----- 4 files changed, 164 insertions(+), 139 deletions(-) create mode 100644 app/helpers/newapplication_helper.rb delete mode 100644 app/helpers/newfront_helper.rb (limited to 'app') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8e476a958..5edb8c3bf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,6 @@ module ApplicationHelper - include NewfrontHelper + include NewapplicationHelper def font_awesome_classic_tag(name) name = "fa-file-text-o" if name == "fa-file-csv-o" diff --git a/app/helpers/newapplication_helper.rb b/app/helpers/newapplication_helper.rb new file mode 100644 index 000000000..2e5a716a6 --- /dev/null +++ b/app/helpers/newapplication_helper.rb @@ -0,0 +1,155 @@ +module NewapplicationHelper + + # Table Builder + def table_builder collection, columns, actions, cls = nil + return unless collection.present? + + head = content_tag :thead do + content_tag :tr do + hcont = [] + columns.map do |k, v| + # hcont << content_tag(:th, k.to_s.titleize) + hcont << content_tag(:th, sortable_columns(collection, k)) + end + hcont << content_tag(:th, 'Actions', class: 'text-center') if actions.any? + + hcont.join.html_safe + end + end + + body = content_tag :tbody do + collection.collect do |item| + content_tag :tr do + bcont = [] + columns.map do |k, attribute| + value = + if Proc === attribute + attribute.call(item) + else + item.try(attribute) + end + bcont << content_tag(:td, value) + end + bcont << content_tag(:td, links_builder(item, actions), class: 'text-center') if actions.any? + + bcont.join.html_safe + end + end.join.html_safe + end + + content_tag :table, head + body, class: cls + end + + def links_builder(item, actions) + trigger = content_tag :div, class: 'btn btn-primary dropdown-toggle', data: { toggle: 'dropdown' } do + a = content_tag :span, '', class: 'fa fa-bars' + b = content_tag :span, '', class: 'caret' + a + b + end + + menu = content_tag :ul, class: 'dropdown-menu' do + actions.collect do |action| + polymorph_url = [] + + unless [:show, :delete].include? action + polymorph_url << action + end + + unless item.class.to_s == 'Calendar' + if current_referential + polymorph_url << current_referential + polymorph_url << item.line if item.respond_to? :line + elsif item.respond_to? :referential + polymorph_url << item.referential + elsif item.respond_to? :line_referential + polymorph_url << item.line_referential + end + end + + polymorph_url << item + + if action == :delete + if policy(item).present? + if policy(item).destroy? + content_tag :li, link_to(t("table.#{action}"), polymorph_url, method: :delete, data: { confirm: 'Etes-vous sûr(e) de vouloir effectuer cette action ?' }) + end + else + content_tag :li, link_to(t("table.#{action}"), polymorph_url, method: :delete, data: { confirm: 'Etes-vous sûr(e) de vouloir effectuer cette action ?' }) + end + + elsif action == :edit + if policy(item).present? + if policy(item).update? + content_tag :li, link_to(t("table.#{action}"), polymorph_url) + end + else + content_tag :li, link_to(t("table.#{action}"), polymorph_url) + end + else + content_tag :li, link_to(t("table.#{action}"), polymorph_url) + end + end.join.html_safe + end + + content_tag :div, trigger + menu, class: 'btn-group btn-group-xs' + + end + + def sortable_columns collection, key + direction = (key == params[:sort] && params[:direction] == 'desc') ? 'asc' : 'desc' + + icon = 'sort-desc' if direction == 'asc' + icon = 'sort-asc' if direction == 'desc' + + link_to({sort: key, direction: direction}) do + pic = content_tag :span, '', class: "fa fa-#{icon}", style: 'margin-left:5px' + (key.to_s.titleize + pic).html_safe + end + end + + # Replacement message + def replacement_msg text + content_tag :div, '', class: 'alert alert-warning' do + icon = content_tag :span, '', class: 'fa fa-lg fa-info-circle', style: 'margin-right:7px;' + icon + text + end + end + + # PageHeader builder + def pageheader pageicon, pagetitle, desc, meta, mainaction = nil, &block + + firstRow = content_tag :div, '', class: 'row' do + # Left part with pageicon & pagetitle & desc + left = content_tag :div, '', class: 'col-lg-9 col-md-8 col-sm-8 col-xs-7' do + picon = content_tag :div, '', class: 'page-icon' do + content_tag :span, '', class: "fa fa-lg fa-#{pageicon}" + end + ptitle = content_tag :div, '', class: 'page-title' do + info = content_tag :span, '', class: 'small fa fa-info-circle', title: desc + + content_tag :h1, pagetitle.concat(info).html_safe + end + + picon + ptitle + end + # Right part with meta & mainaction + right = content_tag :div, '', class: 'col-lg-3 col-md-4 col-sm-4 col-xs-5 text-right' do + content_tag :div, '', class: 'page-action' do + a = content_tag :div, meta.html_safe, class: 'small' + b = mainaction.try(:html_safe) + + a + b + end + end + + left + right + end + + content_tag :div, '', class: 'page_header' do + content_tag :div, '', class: 'container-fluid' do + firstRow + capture(&block) + end + end + end + +end diff --git a/app/helpers/newfront_helper.rb b/app/helpers/newfront_helper.rb deleted file mode 100644 index 7bedbeea9..000000000 --- a/app/helpers/newfront_helper.rb +++ /dev/null @@ -1,118 +0,0 @@ -module NewfrontHelper - - # Table Builder - def table_builder collection, columns, actions, cls = nil - return unless collection.present? - - head = content_tag :thead do - content_tag :tr do - hcont = [] - columns.map do |k, v| - # hcont << content_tag(:th, k.to_s.titleize) - hcont << content_tag(:th, sortable_columns(collection, k)) - end - hcont << content_tag(:th, 'Actions', class: 'text-center') if actions.any? - - hcont.join.html_safe - end - end - - body = content_tag :tbody do - collection.collect do |item| - content_tag :tr do - bcont = [] - columns.map do |k, attribute| - value = - if Proc === attribute - attribute.call(item) - else - item.try(attribute) - end - bcont << content_tag(:td, value) - end - bcont << content_tag(:td, links_builder(item, actions), class: 'text-center') if actions.any? - - bcont.join.html_safe - end - end.join.html_safe - end - - content_tag :table, head + body, class: cls - end - - def links_builder(item, actions) - trigger = content_tag :div, class: 'btn btn-primary dropdown-toggle', data: { toggle: 'dropdown' } do - a = content_tag :span, '', class: 'fa fa-bars' - b = content_tag :span, '', class: 'caret' - a + b - end - - menu = content_tag :ul, class: 'dropdown-menu' do - actions.collect do |action| - polymorph_url = [] - - unless [:show, :delete].include? action - polymorph_url << action - end - - unless item.class.to_s == 'Calendar' - if current_referential - polymorph_url << current_referential - polymorph_url << item.line if item.respond_to? :line - elsif item.respond_to? :referential - polymorph_url << item.referential - elsif item.respond_to? :line_referential - polymorph_url << item.line_referential - end - end - - polymorph_url << item - - if action == :delete - if policy(item).present? - if policy(item).destroy? - content_tag :li, link_to(t("table.#{action}"), polymorph_url, method: :delete, data: { confirm: 'Etes-vous sûr(e) de vouloir effectuer cette action ?' }) - end - else - content_tag :li, link_to(t("table.#{action}"), polymorph_url, method: :delete, data: { confirm: 'Etes-vous sûr(e) de vouloir effectuer cette action ?' }) - end - - elsif action == :edit - if policy(item).present? - if policy(item).update? - content_tag :li, link_to(t("table.#{action}"), polymorph_url) - end - else - content_tag :li, link_to(t("table.#{action}"), polymorph_url) - end - else - content_tag :li, link_to(t("table.#{action}"), polymorph_url) - end - end.join.html_safe - end - - content_tag :div, trigger + menu, class: 'btn-group btn-group-xs' - - end - - def sortable_columns collection, key - direction = (key == params[:sort] && params[:direction] == 'desc') ? 'asc' : 'desc' - - icon = 'sort-desc' if direction == 'asc' - icon = 'sort-asc' if direction == 'desc' - - link_to({sort: key, direction: direction}) do - pic = content_tag :span, '', class: "fa fa-#{icon}", style: 'margin-left:5px' - (key.to_s.titleize + pic).html_safe - end - end - - # Replacement message - def replacement_msg text - content_tag :div, '', class: 'alert alert-warning' do - icon = content_tag :span, '', class: 'fa fa-lg fa-info-circle', style: 'margin-right:7px;' - icon + text - end - end - -end diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index 9aa7f054d..193344572 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -1,24 +1,12 @@ -.page_header - .container-fluid - .row - .col-lg-9.col-md-8.col-sm-8.col-xs-7 - .page-icon - span.fa.fa-map-marker - .page-title - h1 - |Jeux de données - span.small.fa.fa-info-circle title='Description' - - .col-lg-3.col-md-4.col-sm-4.col-xs-5.text-right - .page-action - .small - = "Dernière mise à jour " - br - = "le #{l @workbench.updated_at, format: '%d/%m/%Y'} par Prenom NOM" += pageheader 'map-marker', + 'Jeux de données', + 'Lorem ipsum dolor sit amet', + 'Dernière mise à jour
le 22/12/2016' do - .row - .col-lg-12.col-md-12.col-sm-12.col-xs-12.text-right - = link_to t('referentials.actions.new'), new_referential_path(workbench_id: @workbench), class: 'btn btn-default btn-primary' + / Below is secundary actions & optional contents (filters, ...) + .row + .col-lg-12.col-md-12.col-sm-12.col-xs-12.text-right + = link_to t('referentials.actions.new'), new_referential_path(workbench_id: @workbench), class: 'btn btn-default btn-primary' .page_content .container-fluid -- cgit v1.2.3