track last edit
This commit is contained in:
parent
178c0ba9d2
commit
b9c6b12131
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -55,7 +55,7 @@ module Merged
|
||||
|
||||
def destroy
|
||||
File.delete self.full_filename
|
||||
delete_save!
|
||||
delete_save!(current_member.email)
|
||||
end
|
||||
|
||||
def asset_name
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user