From cbaf858b1c7676639eb23bfe59f04e89ae1cb14f Mon Sep 17 00:00:00 2001 From: Torsten Date: Mon, 26 Dec 2022 20:58:34 +0200 Subject: [PATCH] consistent updated display --- app/models/merged/page.rb | 12 ++-------- app/models/merged/section.rb | 4 ++++ app/models/merged/view_base.rb | 12 ++++++++++ app/views/merged/cards/index.haml | 6 +++++ app/views/merged/pages/index.haml | 33 ++++++---------------------- app/views/merged/sections/index.haml | 23 +++++++++++++------ app/views/merged/sections/show.haml | 6 +++++ 7 files changed, 53 insertions(+), 43 deletions(-) diff --git a/app/models/merged/page.rb b/app/models/merged/page.rb index 6f8e739..c29e271 100644 --- a/app/models/merged/page.rb +++ b/app/models/merged/page.rb @@ -19,16 +19,8 @@ module Merged Section.where(page_id: id).order(index: :asc) end - def section_update - last = Time.now - last_section = nil - sections.each do |section| - if( section.updated_at < last ) - last = section.updated_at - last_section = section - end - end - last_section + def sections_update + last_update_for( sections ) end def template_style diff --git a/app/models/merged/section.rb b/app/models/merged/section.rb index 9e5c4ed..1e0161e 100644 --- a/app/models/merged/section.rb +++ b/app/models/merged/section.rb @@ -15,6 +15,10 @@ module Merged Card.where(section_id: id).order(index: :asc) end + def cards_update + last_update_for( cards ) + end + def template_style SectionStyle.find_by_template( template ) end diff --git a/app/models/merged/view_base.rb b/app/models/merged/view_base.rb index 7ba3bb3..525a1c8 100644 --- a/app/models/merged/view_base.rb +++ b/app/models/merged/view_base.rb @@ -12,6 +12,18 @@ module Merged fields :options , :updated_at , :updated_by + def last_update_for(elements) + last = Time.now + last_section = nil + elements.each do |section| + if( section.updated_at < last ) + last = section.updated_at + last_section = section + end + end + last_section + end + def edit_save( editor ) self.updated_at = Time.now self.updated_by = editor diff --git a/app/views/merged/cards/index.haml b/app/views/merged/cards/index.haml index 568332e..9cc4b77 100644 --- a/app/views/merged/cards/index.haml +++ b/app/views/merged/cards/index.haml @@ -24,6 +24,12 @@ %h3.mt-4.text-lg.font-bold Image = yellow_button("Change Image" , merged.images_path(card_id: card.id) ) = red_button("Remove image", merged.card_set_image_path( card.id , image: "") ) + .basis-full.mt-3 + Updated at: + = distance_of_time_in_words_to_now(card.updated_at) + .basis-full.mb-3 + Updated by: + = card.updated_by .basis-96 %h3.mt-4.text-lg.font-bold Image diff --git a/app/views/merged/pages/index.haml b/app/views/merged/pages/index.haml index f30d317..b63b9bd 100644 --- a/app/views/merged/pages/index.haml +++ b/app/views/merged/pages/index.haml @@ -7,30 +7,11 @@ %table.min-w-full.divide-y.divide-gray-200.text-sm %thead.bg-gray-100 %tr - %th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900 - .flex.items-center.gap-2 - Index - %th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900 - .flex.items-center.gap-2 - Name - %th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900 - .flex.items-center.gap-2 - Sections - %th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900 - .flex.items-center.gap-2 - Updated - %th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900 - .flex.items-center.gap-2 - Edited by - %th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900 - .flex.items-center.gap-2 - Sections at - %th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900 - .flex.items-center.gap-2 - Sections by - %th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900 - .flex.items-center.gap-2 - Actions + -["Index", "Name","Sections" ,"Updated" ,"Edited by" , + "Sections at", "Sections by","Actions"].each do |header| + %th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900 + .flex.items-center.gap-2 + = header %tbody.divide-y.divide-gray-200 - @pages.each do |page| %tr{id: page.name} @@ -44,9 +25,9 @@ = distance_of_time_in_words_to_now(page.updated_at) %td.whitespace-nowrap.px-4.py-2.text-gray-700 =page.updated_by - - s = page.section_update + - s = page.sections_update %td.whitespace-nowrap.px-4.py-2.text-gray-700 - =s.updated_at.to_date + =distance_of_time_in_words_to_now(s.updated_at) %td.whitespace-nowrap.px-4.py-2.text-gray-700 =s.updated_by %td.whitespace-nowrap.px-4.py-2 diff --git a/app/views/merged/sections/index.haml b/app/views/merged/sections/index.haml index 3cfe6fd..9d4f5dc 100644 --- a/app/views/merged/sections/index.haml +++ b/app/views/merged/sections/index.haml @@ -9,7 +9,7 @@ -@page.sections.each do |section | .flex.gap-10.p-4{class: (section.index%2)==1 ? 'bg-cyan-50' : 'bg-red-50' , id: "section_#{section.id}"} - .basis-60 + .basis-72 %h3.mt-4.text-lg.font-bold Section #{section.index} : #{section.header} .flex.flex-wrap = yellow_button("Edit" , merged.section_path(section.id) ) @@ -24,13 +24,22 @@ %path{:d => "M15.75 17.25L12 21m0 0l-3.75-3.75M12 21V3", "stroke-linecap" => "round", "stroke-linejoin" => "round"} .basis-full.mt-3 Updated at: - = section.updated_at.to_date + = distance_of_time_in_words_to_now(section.updated_at) .basis-full.mb-3 Updated by: = section.updated_by + - if section.has_cards? + - card = section.cards_update + .basis-full + Cards updated at: + = distance_of_time_in_words_to_now(card.updated_at) + .basis-full.mb-3 + Cards updated by: + = card.updated_by .basis-full.mb-3 = form_tag( merged.section_path(section.id) , {method: :delete } ) do =submit_button( "Delete" , true) + .basis-72 %h3.mt-4.text-lg.font-bold Template = link_to(merged.section_select_template_path(section.id)) do @@ -53,12 +62,12 @@ = image_for( section , "h-40") -else %p No image - .basis-52.grow + .basis-96 %h3.mt-4.text-lg.font-bold Options - - section.options.each do|name , value| - %p - = name - = value + .grid.grid-cols-2.gap-3.mx-10 + - section.options.each do|name , value| + .font-bold.mt-1= name.camelcase + .font-xl= value .grid.grid-cols-2.gap-2.m-8 .relative.block %p diff --git a/app/views/merged/sections/show.haml b/app/views/merged/sections/show.haml index 6751e35..9b4f3a0 100644 --- a/app/views/merged/sections/show.haml +++ b/app/views/merged/sections/show.haml @@ -12,6 +12,12 @@ = section_preview(@section , class: "w-full object-contain my-4") = yellow_button( "Change Template" , merged.section_select_template_path(@section.id)) = green_button( "New Section" , merged.new_page_section_path(@section.page.id , template: @section.template) ) + .basis-full.mt-3 + Updated at: + = distance_of_time_in_words_to_now(@section.updated_at) + .basis-full.mb-3 + Updated by: + = @section.updated_by .basis-96 %h3.mt-4.text-lg.font-bold Image