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 def new
@section = Section.find(params[:section_id]) @section = Section.find(params[:section_id])
new_card = @section.new_card new_card = @section.new_card
new_card.save new_card.save(current_member.email)
redirect_to section_cards_url(@section.id) , notice: "Card created" redirect_to section_cards_url(@section.id) , notice: "Card created"
end end

View File

@ -6,5 +6,19 @@ module Merged
return true if name.include?("merged/") return true if name.include?("merged/")
false false
end 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
end end

View File

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

View File

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

View File

@ -3,7 +3,7 @@
.text-xl.text-gray-900 .text-xl.text-gray-900
Cards for Section #{@section.index} - Cards for Section #{@section.index} -
= link_to @section.header , merged.section_path( @section.id) , class: "underline" = 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" = render "layouts/merged_header"

View File

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