diff --git a/app/controllers/merged/cards_controller.rb b/app/controllers/merged/cards_controller.rb index 1320498..6699cda 100644 --- a/app/controllers/merged/cards_controller.rb +++ b/app/controllers/merged/cards_controller.rb @@ -31,7 +31,7 @@ module Merged end def destroy - @card.delete_and_reset_index + @card.delete_and_reset_index(current_member.email) redirect_to section_cards_url(@card.section.id) , notice: "#{@card.header} removed" end diff --git a/app/controllers/merged/pages_controller.rb b/app/controllers/merged/pages_controller.rb index e0d7134..f0f7ce2 100644 --- a/app/controllers/merged/pages_controller.rb +++ b/app/controllers/merged/pages_controller.rb @@ -53,7 +53,7 @@ module Merged end def destroy - @page.delete_save! + @page.delete_save!(current_member.email) redirect_to pages_url, notice: "Page #{@page.name} was removed." end diff --git a/app/controllers/merged/sections_controller.rb b/app/controllers/merged/sections_controller.rb index 52073c5..65d042a 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -27,7 +27,7 @@ module Merged end def destroy - @section.delete_and_reset_index + @section.delete_and_reset_index(current_member.email) redirect_to page_sections_url(@section.page.id) , notice: "Section #{@section.header} removed" end diff --git a/app/helpers/merged/merged_helper.rb b/app/helpers/merged/merged_helper.rb index 619c237..8ce1394 100644 --- a/app/helpers/merged/merged_helper.rb +++ b/app/helpers/merged/merged_helper.rb @@ -68,6 +68,38 @@ module Merged end end end + + def last_change_digit + last = ChangeSet.current.last + puts "digit in #{last}" + return 10 unless last + last = (Time.now - last).to_i + puts "digit minus #{last}" + return 10 if ( last >= 600 ) + digit = last / 60 + puts "digit ret #{digit}" + digit + end + + def last_change_class + digit = last_change_digit + return button_classes if digit > 9 + digit = 9 - digit + reds = { "1" => "bg-red-100","2" => "bg-red-200","3" => "bg-red-100", + "4" => "bg-red-400","5" => "bg-red-500","6" => "bg-red-600", + "7" => "bg-red-700","8" => "bg-red-600","9" => "bg-red-900"} + + clazz = reds[digit.to_s].to_s + clazz += " " + "text-white" if digit > 7 + button_classes + " " + clazz + end + + def last_change_text + digit = last_change_digit + return "no change" if digit > 9 + "#{digit} min. by #{ChangeSet.current.last_editor}" + end + def button_classes "mr-3 inline-block rounded-lg px-4 py-3 text-md font-medium border border-gray-400" end diff --git a/app/models/merged/active_base.rb b/app/models/merged/active_base.rb index b74ffca..94a737d 100644 --- a/app/models/merged/active_base.rb +++ b/app/models/merged/active_base.rb @@ -5,11 +5,11 @@ module Merged def edit_save( editor ) self.updated_at = Time.now self.updated_by = editor - edit_save! + edit_save!(editor) end - def edit_save! - ChangeSet.current.edit(self.class.name , self.change_name) + def edit_save!(editor) + ChangeSet.current.edit(self.class.name , self.change_name, editor) save!() self.class.save_all end @@ -17,17 +17,17 @@ module Merged def add_save( editor ) self.updated_at = Time.now self.updated_by = editor - add_save! + add_save!(editor) end - def add_save! - ChangeSet.current.add(self.class.name , self.change_name) + def add_save!(editor) + ChangeSet.current.add(self.class.name , self.change_name, editor) save!() self.class.save_all end - def delete_save! - ChangeSet.current.delete(self.class.name , self.change_name) + def delete_save!(editor) + ChangeSet.current.delete(self.class.name , self.change_name,editor) self.class.delete(self.id) self.class.save_all end diff --git a/app/models/merged/card.rb b/app/models/merged/card.rb index 4ba0573..d436bfc 100644 --- a/app/models/merged/card.rb +++ b/app/models/merged/card.rb @@ -38,8 +38,8 @@ module Merged CardStyle.find_by_template( self.template ) end - def delete_and_reset_index - delete_save! + def delete_and_reset_index(editor) + delete_save!(editor) section.reset_index Section.find(section_id).reset_index Card.save_all diff --git a/app/models/merged/change_set.rb b/app/models/merged/change_set.rb index 4af86b0..646411c 100644 --- a/app/models/merged/change_set.rb +++ b/app/models/merged/change_set.rb @@ -5,7 +5,7 @@ module Merged def self.current @@current ||= ChangeSet.new end - attr_reader :adds , :edits , :deletes + attr_reader :adds , :edits , :deletes , :last , :last_editor def initialize zero @@ -16,16 +16,26 @@ module Merged @adds = Set.new @edits = Set.new @deletes = Set.new + @last = nil + @last_editor = nil end - def add( type , text) + def touch(editor) + @last = Time.now + @last_editor = editor + end + + def add( type , text , editor) + touch(editor) @adds << [typed(type) , text ] end - def edit( type , text) + def edit( type , text, editor) + touch(editor) @edits << [typed(type) , text ] end - def delete( type , text) + def delete( type , text, editor) + touch(editor) @deletes << [typed(type) , text ] end diff --git a/app/models/merged/image.rb b/app/models/merged/image.rb index 2a33d72..d0be5eb 100644 --- a/app/models/merged/image.rb +++ b/app/models/merged/image.rb @@ -55,7 +55,7 @@ module Merged def destroy File.delete self.full_filename - delete_save! + delete_save!(current_member.email) end def asset_name diff --git a/app/models/merged/page.rb b/app/models/merged/page.rb index faae3d9..8e0639f 100644 --- a/app/models/merged/page.rb +++ b/app/models/merged/page.rb @@ -51,9 +51,9 @@ module Merged sections.each_with_index{|section, index| section.index = index + 1} end - def delete - sections.each {|section| section.delete } - delete_save! + def delete(editor) + sections.each {|section| section.delete(editor) } + delete_save!(editor) end def save(editor) diff --git a/app/models/merged/section.rb b/app/models/merged/section.rb index 626d786..b6dd922 100644 --- a/app/models/merged/section.rb +++ b/app/models/merged/section.rb @@ -37,15 +37,6 @@ module Merged ! card_template.blank? end - def remove_card(card) - from_index = card.index - @cards.delete_at(from_index) - @content["cards"].delete_at(from_index) - @cards.each_with_index do |card, index| - card.set_index(index) - end - end - def move_up swap_index_with(next_section) end @@ -71,13 +62,13 @@ module Merged cards.each_with_index{|card, index| card.index = index + 1} end - def delete - cards.each {|card| card.delete_save! } - delete_save!() + def delete(editor) + cards.each {|card| card.delete_save!(editor) } + delete_save!(editor) end - def delete_and_reset_index - delete + def delete_and_reset_index(editor) + delete(editor) Page.find(page_id).reset_index Section.save_all end diff --git a/app/views/layouts/_merged_header.haml b/app/views/layouts/_merged_header.haml index 1103ab0..ce3c504 100644 --- a/app/views/layouts/_merged_header.haml +++ b/app/views/layouts/_merged_header.haml @@ -17,3 +17,5 @@ %a.text-gray-500.transition{:class => "hover:text-gray-500/75", :href => merged.changes_index_path} Changes = yield :merged_menu + + %button.my-3{class: last_change_class}= last_change_text diff --git a/test/models/card_write_test.rb b/test/models/card_write_test.rb index 5eb6bb0..dff245a 100644 --- a/test/models/card_write_test.rb +++ b/test/models/card_write_test.rb @@ -8,20 +8,20 @@ module Merged def test_deletes id = first.id - first.delete_save! + first.delete_save!("random") assert_raises(ActiveHash::RecordNotFound) {Card.find(id) } end def test_delete_index section = first.section index = first.index - first.delete_and_reset_index + first.delete_and_reset_index("me") assert_equal index , section.cards.first.index end def test_adds card = Card.first.section.new_card - card.add_save! + card.add_save!("me me") assert_equal "NEW" , card.header end diff --git a/test/models/change_set_test.rb b/test/models/change_set_test.rb index 46f97c6..522a657 100644 --- a/test/models/change_set_test.rb +++ b/test/models/change_set_test.rb @@ -12,17 +12,17 @@ module Merged class ChangeSetTest < ActiveSupport::TestCase include Zero def test_has_add - change.add("Section" , "name") + change.add("Section" , "name" , "you") assert_equal "name", change.added("Section").first.last assert_equal :Section, change.added("Section").first.first end def test_has_edit - change.edit("Section" , "name") + change.edit("Section" , "name" , "me") assert_equal "name", change.edited("Section").first.last assert_equal :Section, change.edited("Section").first.first end def test_has_delete - change.delete("Section" , "name") + change.delete("Section" , "name", "him") assert_equal "name", change.deleted("Section").first.last assert_equal :Section, change.deleted("Section").first.first end @@ -69,19 +69,19 @@ module Merged def test_page_delete studios = Page.first - studios.delete_save! + studios.delete_save!("random") assert_equal "studios" , change.deleted("Page").first.last assert_nil change.edited("Page").first end def test_section_delete studios = Section.first - studios.delete_save!() + studios.delete_save!("me") assert_equal "studios:Studios" , change.deleted("Section").first.last assert_nil change.edited("Section").first end def test_card_delete studios = Card.first - studios.delete_save!() + studios.delete_save!("you") assert_equal "studios:Standard" , change.deleted("Card").first.last assert_nil change.edited("Card").first end diff --git a/test/models/page_write_test.rb b/test/models/page_write_test.rb index ba77ea8..6d3cbd6 100644 --- a/test/models/page_write_test.rb +++ b/test/models/page_write_test.rb @@ -28,18 +28,18 @@ module Merged def test_deletes id = index.id - index.delete + index.delete("you") assert_raises(ActiveHash::RecordNotFound){Page.find(id) } end def test_destroys id = index.id - index.delete + index.delete("you") Section.reload assert_raises(ActiveHash::RecordNotFound){Page.find(id) } end def test_destroys_sections id = index.sections.first.id - index.delete + index.delete("you") Section.reload assert_raises(ActiveHash::RecordNotFound){Page.find(id) } end diff --git a/test/models/section_write_test.rb b/test/models/section_write_test.rb index 4040a38..b1dd7da 100644 --- a/test/models/section_write_test.rb +++ b/test/models/section_write_test.rb @@ -19,14 +19,14 @@ module Merged def test_deletes last_id = last.id - last.delete + last.delete("you") assert_raises(ActiveHash::RecordNotFound){Section.find(last_id) } end def test_delete_index_section eleven = Section.find 11 page = eleven.page - eleven.delete + eleven.delete("you") assert_equal eleven.index + 1 , page.sections.second.index end @@ -34,19 +34,19 @@ module Merged eleven = Section.find 11 page = eleven.page index = eleven.index - eleven.delete_and_reset_index + eleven.delete_and_reset_index("you") assert_equal index , page.sections.second.index end def test_destroys last_id = last.id - last.delete + last.delete("you") Section.reload assert_raises(ActiveHash::RecordNotFound){Section.find(last_id) } end def test_destroys_cards card_id = last.cards.first.id - last.delete + last.delete("you") Section.reload assert_raises(ActiveHash::RecordNotFound){Card.find(card_id) } end