From ba022b525934144718d8137c2a2685d8d90b1660 Mon Sep 17 00:00:00 2001 From: Torsten Date: Mon, 26 Dec 2022 20:29:43 +0200 Subject: [PATCH] lastish from the api changes (coverage not 100) and change reset --- app/controllers/merged/cards_controller.rb | 6 ++-- app/controllers/merged/changes_controller.rb | 35 ++++++++++++++----- app/controllers/merged/pages_controller.rb | 26 +++++++------- app/controllers/merged/sections_controller.rb | 14 ++++---- app/views/merged/changes/index.haml | 12 +++++-- app/views/merged/sections/index.haml | 2 +- config/routes.rb | 1 + test/integration/pages_test.rb | 12 +++++++ 8 files changed, 74 insertions(+), 34 deletions(-) diff --git a/app/controllers/merged/cards_controller.rb b/app/controllers/merged/cards_controller.rb index c02f0e4..b085aec 100644 --- a/app/controllers/merged/cards_controller.rb +++ b/app/controllers/merged/cards_controller.rb @@ -18,19 +18,19 @@ module Merged else @card.move_down end - @card.save(current_member) + @card.edit_save(current_member) redirect_to section_cards_url(@card.section.id),notice: "#{@card.header} moved" end def new @section = Section.find(params[:section_id]) new_card = @section.new_card - new_card.save(current_member.email) + new_card.add_save(current_member.email) redirect_to section_cards_url(@section.id) , notice: "Card created" end def destroy - @card.destroy + @card.delete_save! redirect_to section_cards_url(@card.section.id) , notice: "#{@card.header} removed" end diff --git a/app/controllers/merged/changes_controller.rb b/app/controllers/merged/changes_controller.rb index 898c02f..0ff6f1c 100644 --- a/app/controllers/merged/changes_controller.rb +++ b/app/controllers/merged/changes_controller.rb @@ -9,15 +9,34 @@ module Merged end def commit - raise "must have message" if params[:message].blank? - git = Git.open(Rails.root) - git.add("merged") - git.add( Image.root ) - begin - git.commit(params[:message]) - rescue + if params[:message].blank? + message = "must have message" + redirect_to changes_index_url , alert: message + else + git = Git.open(Rails.root) + git.add("merged") + git.add( Image.root ) + begin + g.config('user.email', current_member.email) + git.commit(params[:message]) + redirect_to changes_index_url , notice: "Changes commited" + rescue + redirect_to changes_index_url , notice: "Error occurred" + end end - redirect_to changes_index_url end + + def reset + git = Git.open(Rails.root) + begin + git.checkout_file("HEAD" , "merged") + ChangeSet.current.zero + message = "Changes reset" + rescue + message = "Unknown error occured" + end + redirect_to changes_index_url , notice: message + end + end end diff --git a/app/controllers/merged/pages_controller.rb b/app/controllers/merged/pages_controller.rb index 1272a96..edf1081 100644 --- a/app/controllers/merged/pages_controller.rb +++ b/app/controllers/merged/pages_controller.rb @@ -12,28 +12,30 @@ module Merged end def update - @page.add_redirect - @page.name = params[:name] - @page.save(current_member.email) - redirect_to page_url(@page) , notice: "Page renamed" + if( !params[:name].blank? && (params[:name] != @page.name)) + @page.add_redirect + @page.name = params[:name] + @page.edit_save(current_member.email) + message = "Page renamed" + end + redirect_to page_url(@page) , notice: message end def create name = params[:name] - message = "Must enter name" if name.blank? - if( ! message.nil?) - @page = Page.new_page(name) - @page.save(current_member.email) - redirect_to new_page_section_url(@page.id) , notice: "Page was successfully created." - else + if( name.blank? ) @pages = Page.all - flash.now.alert = message + flash.now.alert = "Must enter name" render :index + else + @page = Page.new_page(name) + @page.add_save(current_member.email) + redirect_to new_page_section_url(@page.id) , notice: "Page was successfully created." end end def destroy - @page.destroy() + @page.delete() 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 3872af3..bca211e 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -19,7 +19,7 @@ module Merged page = Page.find(params[:page_id]) template = params[:template] new_section = page.new_section(template) - new_section.save(current_member.email) + new_section.add_save(current_member.email) if(template.blank?) # new redirect_to section_select_template_url(new_section.id), notice: "New section created" else # copy @@ -28,13 +28,13 @@ module Merged end def destroy - @section.destroy() + @section.delete redirect_to page_sections_url(@section.page.id) , notice: "Section #{@section.header} removed" end def set_image @section.image_id = params[:image_id].to_i - @section.save + @section.edit_save(current_member.email) redirect_to section_url(@section.id) , notice: "Image selected: #{@section.image.name}" end @@ -42,7 +42,7 @@ module Merged template = params[:template] raise "no template given" if template.blank? @section.set_template( template ) - @section.save + @section.edit_save(current_member.email) redirect_to section_url(@section.id) end @@ -50,7 +50,7 @@ module Merged card_template = params[:card_template] raise "no card template given" if card_template.blank? @section.card_template = card_template - @section.save + @section.edit_save(current_member.email) redirect_to section_url(@section.id) end @@ -60,7 +60,7 @@ module Merged else @section.move_down end - @section.save + @section.edit_save(current_member.email) redirect_to page_sections_url(@section.page.id) end @@ -74,7 +74,7 @@ module Merged @section.option_definitions.each do |option| @section.set_option(option.name, options[option.name]) end if options - @section.save(current_member.email) + @section.edit_save(current_member.email) redirect_to :section , notice: "Update ok" end diff --git a/app/views/merged/changes/index.haml b/app/views/merged/changes/index.haml index ae1d487..90a20f3 100644 --- a/app/views/merged/changes/index.haml +++ b/app/views/merged/changes/index.haml @@ -28,9 +28,9 @@ - changeset(type , element).each do |name| %span=name.last -.flex.flex-col.bg-white - .flex.items-center.justify-center.flex-1 - .max-w-xl.px-4.py-8.mx-auto.text-center +.grid.grid-cols-3.bg-white + .items-center.justify-center.col-span-2 + .max-w-xl.px-4.py-8.mx-auto.text-center.commit_changes = form_tag( merged.changes_commit_path() , {method: :post } ) do %h1.text-2xl.font-bold.tracking-tight.text-gray-900.sm:text-4xl Commit changes @@ -39,3 +39,9 @@ %h4.text-lg.font-bold Message (short summary of changes) = text_field_tag( :message , "", class: "block w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm") =submit_button( "Commit") + + .max-w-xl.px-4.py-8.mx-auto.text-center.reset_changes + = form_tag( merged.changes_reset_path() , {method: :post } ) do + %h1.text-2xl.font-bold.tracking-tight.text-gray-900.sm:text-4xl + Reset changes + =submit_button( "Reset" ,true) diff --git a/app/views/merged/sections/index.haml b/app/views/merged/sections/index.haml index d48d892..3cfe6fd 100644 --- a/app/views/merged/sections/index.haml +++ b/app/views/merged/sections/index.haml @@ -63,7 +63,7 @@ .relative.block %p = green_button( "New Section" , merged.new_page_section_path(@page.id) ) - .relative.block + .relative.block.delete_page %p = form_tag( merged.page_path(@page.id) , {method: :delete } ) do =submit_button( "Delete Page" , true) diff --git a/config/routes.rb b/config/routes.rb index 0d8709e..5badfb4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,7 @@ Merged::Engine.routes.draw do get 'changes/index' post 'changes/commit' + post 'changes/reset' get "styles/index" post 'form/sendit' diff --git a/test/integration/pages_test.rb b/test/integration/pages_test.rb index 116e340..4caad90 100644 --- a/test/integration/pages_test.rb +++ b/test/integration/pages_test.rb @@ -36,6 +36,7 @@ class PagesWrite < ActionDispatch::IntegrationTest within(".new_page") do click_on ("New Page") end + assert_equal "/merged/pages" , current_path end def test_new_works_with_name visit "/merged/pages" @@ -43,6 +44,17 @@ class PagesWrite < ActionDispatch::IntegrationTest fill_in 'Name', with: 'New Page' click_on ("New Page") end + assert_equal "/merged/sections/41/select_template" , current_path + end + + def test_delete_works + id = Merged::Page.first.id + visit merged.page_sections_path(id) + within(".delete_page") do + click_on ("Delete Page") + end + assert_equal "/merged/pages" , current_path + assert_raise(ActiveHash::RecordNotFound) {visit merged.page_path(id)} end end