make changeset instance and start on change page

This commit is contained in:
Torsten 2022-12-26 17:06:12 +02:00
parent c1288786b6
commit 367c05b086
6 changed files with 65 additions and 48 deletions

View File

@ -25,7 +25,7 @@ module Merged
def new
@section = Section.find(params[:section_id])
new_card = @section.new_card
new_card.save
new_card.save(current_member.email)
redirect_to section_cards_url(@section.id) , notice: "Card created"
end

View File

@ -6,5 +6,19 @@ module Merged
return true if name.include?("merged/")
false
end
def changeset( type , element)
case type
when :add
ChangeSet.current.added( element )
when :edit
ChangeSet.current.edited( element )
when :delete
ChangeSet.current.deleted( element )
else
raise "unrecognized type #{type}"
end
end
end
end

View File

@ -2,20 +2,20 @@ module Merged
class ActiveBase < ActiveYaml::Base
def save
ChangeSet.edit(self.class.name , self.change_name)
ChangeSet.current.edit(self.class.name , self.change_name)
super
self.class.save_all
end
def add_save
ChangeSet.add(self.class.name , self.change_name)
ChangeSet.current.add(self.class.name , self.change_name)
super.save()
self.class.save_all
end
def delete
ChangeSet.delete(self.class.name , self.change_name)
ChangeSet.current.delete(self.class.name , self.change_name)
self.class.delete(self.id)
end

View File

@ -1,36 +1,43 @@
module Merged
module ChangeSet
@@adds = []
@@edits = []
@@deletes = []
class ChangeSet
mattr_accessor :adds , :edits , :deletes
def self.add( type , text)
@@adds << [typed(type) , text ]
def self.current
@@current ||= ChangeSet.new
end
attr_reader :adds , :edits , :deletes
def initialize
@adds = []
@edits = []
@deletes = []
end
def self.edit( type , text)
@@edits << [typed(type) , text ]
end
def self.delete( type , text)
@@deletes << [typed(type) , text ]
def add( type , text)
@adds << [typed(type) , text ]
end
def self.added( type )
def edit( type , text)
@edits << [typed(type) , text ]
end
def delete( type , text)
@deletes << [typed(type) , text ]
end
def added( type )
type = type.to_sym
@@adds.select { |a| a.first == type }
@adds.select { |a| a.first == type }
end
def self.edited( type )
def edited( type )
type = type.to_sym
@@edits.select { |a| a.first == type }
@edits.select { |a| a.first == type }
end
def self.deleted( type )
def deleted( type )
type = type.to_sym
@@deletes.select { |a| a.first == type }
@deletes.select { |a| a.first == type }
end
def self.typed(class_name)
def typed(class_name)
class_name.split("::").last.to_sym
end
end

View File

@ -3,7 +3,7 @@
.text-xl.text-gray-900
Cards for Section #{@section.index} -
= link_to @section.header , merged.section_path( @section.id) , class: "underline"
= link_to( "New Card" , merged.new_section_card_path(@section.id) , class: "p-2 border border-gray-200 font-bold rounded-lg hover:bg-sky-100")
= link_to( "New Card" , merged.new_section_card_path(@section.id) , class: "p-2 border border-gray-200 bg-cyan-100 font-bold rounded-lg hover:bg-sky-100")
= render "layouts/merged_header"

View File

@ -7,30 +7,26 @@
= render "layouts/merged_header"
.grid.grid-cols-4.gap-2.m-8
.relative.block.border.border-gray-100
Changed Files
-@status.changed.each do |name , file|
-next unless cms_part?(name)
%p
= name
.relative.block.border.border-gray-100
Deletions
-@status.deleted.each do |name , file|
-next unless cms_part?(name)
%p= name
.relative.block.border.border-gray-100
Additions
-@status.added.each do |name , file|
-next unless cms_part?(name)
%p= name
.relative.block.border.border-gray-100
New
-@status.untracked.each do |name , file|
-next unless cms_part?(name)
%p
= name
.overflow-hidden.overflow-x-auto.rounded-lg.border.border-gray-200.m-20
%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
Change
-[:Page , :Section , :Card , :Image].each do |element|
%th.whitespace-nowrap.px-4.py-2.text-left.font-medium.text-gray-900
.flex.items-center.gap-2
=element
%tbody.divide-y.divide-gray-200
-[:add , :edit , :delete].each do |type|
%tr
%td.whitespace-nowrap.px-4.py-2.text-gray-700
= type.to_s.capitalize
-[:Page , :Section , :Card , :Image].each do |element|
%td.whitespace-nowrap.px-4.py-2.text-gray-700
- changeset(type , element).each do |name|
%span=name.last
.flex.flex-col.bg-white
.flex.items-center.justify-center.flex-1