From 367c05b086cc37d9760f9240ed090b0b1e20d921 Mon Sep 17 00:00:00 2001 From: Torsten Date: Mon, 26 Dec 2022 17:06:12 +0200 Subject: [PATCH] make changeset instance and start on change page --- app/controllers/merged/cards_controller.rb | 2 +- app/helpers/merged/changes_helper.rb | 14 +++++++ app/models/merged/active_base.rb | 6 +-- app/models/merged/change_set.rb | 45 +++++++++++++--------- app/views/merged/cards/index.haml | 2 +- app/views/merged/changes/index.haml | 44 ++++++++++----------- 6 files changed, 65 insertions(+), 48 deletions(-) diff --git a/app/controllers/merged/cards_controller.rb b/app/controllers/merged/cards_controller.rb index 4719bbd..c02f0e4 100644 --- a/app/controllers/merged/cards_controller.rb +++ b/app/controllers/merged/cards_controller.rb @@ -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 diff --git a/app/helpers/merged/changes_helper.rb b/app/helpers/merged/changes_helper.rb index 000e26b..caacb2e 100644 --- a/app/helpers/merged/changes_helper.rb +++ b/app/helpers/merged/changes_helper.rb @@ -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 diff --git a/app/models/merged/active_base.rb b/app/models/merged/active_base.rb index b95dc94..9eae27c 100644 --- a/app/models/merged/active_base.rb +++ b/app/models/merged/active_base.rb @@ -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 diff --git a/app/models/merged/change_set.rb b/app/models/merged/change_set.rb index 0cddf0d..d12e73b 100644 --- a/app/models/merged/change_set.rb +++ b/app/models/merged/change_set.rb @@ -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 diff --git a/app/views/merged/cards/index.haml b/app/views/merged/cards/index.haml index 4f1fb14..568332e 100644 --- a/app/views/merged/cards/index.haml +++ b/app/views/merged/cards/index.haml @@ -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" diff --git a/app/views/merged/changes/index.haml b/app/views/merged/changes/index.haml index 0ed468e..ae1d487 100644 --- a/app/views/merged/changes/index.haml +++ b/app/views/merged/changes/index.haml @@ -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