page redirect with redirect capturing

This commit is contained in:
Torsten 2022-12-19 21:42:03 +02:00
parent f61ce40e71
commit ca029d274c
5 changed files with 29 additions and 3 deletions

View File

@ -10,6 +10,13 @@ module Merged
end end
def update
@page.add_redirect
@page.name = params[:name]
@page.save
redirect_to page_path(@page) , notice: "Page renamed"
end
def create def create
name = params[:name] name = params[:name]
message = Page.check_name(name) message = Page.check_name(name)

View File

@ -1,10 +1,16 @@
module Merged module Merged
class Page < ViewBase class Page < ViewBase
fields :name , :type , :options fields :name , :type , :options, :redirects
alias :template :type alias :template :type
def add_redirect
olds = self.redirects.to_s.split(" ")
olds << self.name unless olds.include?(self.name)
self.redirects = olds.join(" ")
end
def sections def sections
Section.where(page_id: id).order(index: :asc) Section.where(page_id: id).order(index: :asc)
end end
@ -55,6 +61,9 @@ module Merged
end end
def save def save
olds = self.redirects.to_s.split(" ")
olds.delete( self.name.to_s )
self.redirects = olds.join(" ")
updated_at = Time.now updated_at = Time.now
super super
Page.save_all Page.save_all

View File

@ -23,13 +23,16 @@
%h4.text-lg.font-bold Name %h4.text-lg.font-bold Name
= text_field_tag( :name , @page.name, class: "w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm") = text_field_tag( :name , @page.name, class: "w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm")
.mt-4= submit_button("Update") .mt-4= submit_button("Update")
(renaming not implemented) -unless @page.redirects.blank?
.mt-4
Page redirects from
= @page.redirects
.basis-80.grow .basis-80.grow
%h3.mt-4.text-lg.font-bold Options %h3.mt-4.text-lg.font-bold Options
= form_tag( page_url(@page.id) , {method: :patch , class: "mx-auto mt-8 mb-0 max-w space-y-4" } ) do = form_tag( page_url(@page.id) , {method: :patch , class: "mx-auto mt-8 mb-0 max-w space-y-4" } ) do
- @page.option_definitions.each do |option| - @page.option_definitions.each do |option|
=render "option_form_#{option.type}" , section: @page , option: option =render "/merged/sections/option_form_#{option.type}" , section: @page , option: option
-if @page.option_definitions.empty? -if @page.option_definitions.empty?
%p No options %p No options
-else -else

View File

@ -93,3 +93,8 @@
:values: left center right :values: left center right
:default: left :default: left
:id: 17 :id: 17
- :name: meta
:description: Meta tag for page
:values:
:default:
:id: 18

View File

@ -2,3 +2,5 @@
- type: page - type: page
description: A general page, may contain anykind of section. description: A general page, may contain anykind of section.
No restrictions of any kind. No options either. No restrictions of any kind. No options either.
options:
- meta