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
def update
@page.add_redirect
@page.name = params[:name]
@page.save
redirect_to page_path(@page) , notice: "Page renamed"
end
def create
name = params[:name]
message = Page.check_name(name)

View File

@ -1,10 +1,16 @@
module Merged
class Page < ViewBase
fields :name , :type , :options
fields :name , :type , :options, :redirects
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
Section.where(page_id: id).order(index: :asc)
end
@ -55,6 +61,9 @@ module Merged
end
def save
olds = self.redirects.to_s.split(" ")
olds.delete( self.name.to_s )
self.redirects = olds.join(" ")
updated_at = Time.now
super
Page.save_all

View File

@ -23,13 +23,16 @@
%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")
.mt-4= submit_button("Update")
(renaming not implemented)
-unless @page.redirects.blank?
.mt-4
Page redirects from
= @page.redirects
.basis-80.grow
%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
- @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?
%p No options
-else

View File

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

View File

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