From b907c9a48ff1caa51117e49e4372c3d550c4150f Mon Sep 17 00:00:00 2001 From: Grigory Date: Wed, 21 Feb 2024 23:25:04 +0300 Subject: [PATCH] Small changes --- .../stylesheets/custom_table/table.scss | 124 ++++++++---------- .../custom_table/application_helper.rb | 2 +- app/helpers/custom_table/fieldset_helper.rb | 5 + app/views/custom_table/_field.haml | 6 +- app/views/custom_table/_table.html.haml | 4 +- 5 files changed, 65 insertions(+), 76 deletions(-) diff --git a/app/assets/stylesheets/custom_table/table.scss b/app/assets/stylesheets/custom_table/table.scss index e2c2230..7ddbd00 100644 --- a/app/assets/stylesheets/custom_table/table.scss +++ b/app/assets/stylesheets/custom_table/table.scss @@ -1,28 +1,5 @@ -.search-fields-filter { - // .form-group { - // margin-bottom: 0; - // } - // .dates .form-group { - // width: 50%; - // margin-left: 0; - // margin-right: 0; - // float:left; - // } - // input.boolean { - // margin-top: -5px; - // margin-bottom: 0; - // margin-left: -15px; - // margin-right: 5px; - // } - // label.boolean { - // margin-top: 5px; - // margin-bottom: 0; - // white-space: nowrap; - // } -} - -table { +table.custom-table { td.actions { white-space: nowrap; @@ -35,49 +12,32 @@ table { td.selected { border: 2px solid rgb(26, 179, 26) !important; } -} -.table-sum { - position: fixed; - right: 0; - bottom: 0; - width: 150px; - background: white; - border: 2px solid black; - padding: 2px; - text-align: right; - margin-right: 5px; - z-index: 1000; -} + tr { + .action { + visibility: hidden; + &.btn-sm { + padding: 2px 4px !important; + } + } + .d-action-none { + display: none; + } -.widget table.search-fields td { - max-width: 120px; - overflow: hidden; -} -table tr, li.list-group-item { - .action { - visibility: hidden; - } - .d-action-none { - display: none; - } -} -table tr, li.list-group-item { - // .btn-sm { - // padding: 0rem 0.25rem; - // } -} -table tr:hover, li.list-group-item:hover { - .action { - visibility: visible; - } - .d-action-none { - display: inherit; + &:hover { + .action { + visibility: visible; + } + .d-action-none { + display: inherit; + } + } + } -} -table { + + tr.sticky, thead.sticky { position: sticky; background: white; @@ -91,19 +51,39 @@ table { .text-sm { font-size: 11px; } -} -.tree-opener { - cursor: pointer; - .opened { - display: none; - } - &.opened { + .tree-opener { + cursor: pointer; .opened { - display: inline; - } - .closed { display: none; } + &.opened { + .opened { + display: inline; + } + .closed { + display: none; + } + } } + + .table-sum { + position: fixed; + right: 0; + bottom: 0; + width: 150px; + background: white; + border: 2px solid black; + padding: 2px; + text-align: right; + margin-right: 5px; + z-index: 1000; + } + +} + + +.widget table.custom-table td { + max-width: 120px; + overflow: hidden; } diff --git a/app/helpers/custom_table/application_helper.rb b/app/helpers/custom_table/application_helper.rb index 991a058..ebd06ae 100644 --- a/app/helpers/custom_table/application_helper.rb +++ b/app/helpers/custom_table/application_helper.rb @@ -14,7 +14,7 @@ def custom_table_form_for(record, options = {}, &block) options[:method] = :get options[:html] ||= {} - options[:html][:class] = "row row-cols-md-auto g-3 align-items-center search-fields-filter" + options[:html][:class] = "row row-cols-md-auto g-3 align-items-center custom-table-filter" options[:wrapper] = options[:wrapper] || :inline_form options[:wrapper_mappings] = { diff --git a/app/helpers/custom_table/fieldset_helper.rb b/app/helpers/custom_table/fieldset_helper.rb index c5b05a1..fbcbdb7 100644 --- a/app/helpers/custom_table/fieldset_helper.rb +++ b/app/helpers/custom_table/fieldset_helper.rb @@ -35,6 +35,11 @@ def field column, **params, &block params[:column] = column params[:object] = @object + hint_key = "simple_form.hints.#{@object.model_name.singular}.#{column}" + if I18n.exists?(hint_key) + params[:hint] = I18n.t(hint_key) + end + @template.render "custom_table/#{params[:template]}", **params do if params[:editable] && has_editable? params[:editable_params] = {} if params[:editable_params].nil? diff --git a/app/views/custom_table/_field.haml b/app/views/custom_table/_field.haml index b06e980..9f4f8c9 100644 --- a/app/views/custom_table/_field.haml +++ b/app/views/custom_table/_field.haml @@ -1,4 +1,8 @@ %div.d-flex.justify-content-between.custom-table-field - %b= label + %b + - if local_assigns[:hint] + %abbr{title: hint}= label + - else + = label %span.text-end.d-inline{id: "#{column}_#{object.model_name.singular}_#{object.id}"}= yield -# %dt{class: adaptive ? "col-lg-2 col-md-5" : "col-5"}= label diff --git a/app/views/custom_table/_table.html.haml b/app/views/custom_table/_table.html.haml index fc19ed2..c34353e 100644 --- a/app/views/custom_table/_table.html.haml +++ b/app/views/custom_table/_table.html.haml @@ -23,7 +23,7 @@ - if local_assigns[:batch_actions] = self.send(local_assigns[:batch_actions]) - %table{class: ["search-fields", "table", "table-hover", "table-sm", model_class.model_name.plural], data: {controller: "table toggle"}} + %table{class: ["search-fields", "custom-table", "table", "table-hover", "table-sm", model_class.model_name.plural], data: {controller: "table toggle"}} %thead.sticky - if local_assigns[:quick_filter] %tr @@ -111,7 +111,7 @@ - group_fields_totals = {} - items.each do |item| - - custom_table_fields_totals(fields: fields, item: item, totals: totals, variant: variant, fields_totals: group_fields_totals) + - custom_table_fields_totals(fields: fields, item: item, totals: local_assigns[:totals], variant: variant, fields_totals: group_fields_totals) %tr - shown = false - fields.each do |field, defs|