show page for pages (a start)

This commit is contained in:
Torsten 2022-12-16 16:50:56 +02:00
parent 54e8c287ca
commit 6dbddce173
11 changed files with 79 additions and 25 deletions

View File

@ -1,11 +1,15 @@
module Merged
class PagesController < MergedController
before_action :set_page, only: %i[ update destroy ]
before_action :set_page, only: %i[ update destroy show ]
def index
@pages = Page.all
end
def show
end
def create
name = params[:name]
message = Page.check_name(name)

View File

@ -1,13 +1,18 @@
module Merged
class Page < ViewBase
fields :name , :type , :options
fields :name , :tempate
alias :template :type
def sections
Section.where(page_id: id).order(index: :asc)
end
def template_style
PageStyle.find_by_type( type )
end
def new_section(section_template)
section_template = "section_spacer" if section_template.blank?
section = Section.new_section(section_template, self.id , sections.length + 1)

View File

@ -11,6 +11,10 @@ module Merged
Card.where(section_id: id).order(index: :asc)
end
def template_style
SectionStyle.find_by_template( template )
end
def set_template(new_template)
self.template = new_template
new_style = template_style

View File

@ -10,10 +10,6 @@ module Merged
fields :options , :updated_at , :updated_by
def template_style
SectionStyle.find_by_template( template )
end
def has_option?(option)
options.has_key?(option) and !options[option].blank?
end

View File

@ -24,7 +24,7 @@
Actions
%tbody.divide-y.divide-gray-200
- @pages.each do |merged_page|
%tr
%tr{id: merged_page.name}
%td.whitespace-nowrap.px-4.py-2.text-gray-700
= link_to merged_page.name , page_sections_path(merged_page.id)
%td.whitespace-nowrap.px-4.py-2.text-gray-700
@ -37,7 +37,7 @@
%strong.rounded.bg-green-100.px-3.text-xs.font-medium.text-green-700{:class => "py-1.5"}
= link_to 'Sections', page_sections_path(merged_page.id)
%strong.rounded.bg-amber-100.px-3.text-xs.font-medium.text-amber-700{:class => "py-1.5"}
= link_to 'Edit', edit_page_path(merged_page.id)
= link_to 'Edit', page_path(merged_page.id)
.grid.grid-cols-3.gap-2.m-8
.relative.block.border.border-gray-100

View File

@ -0,0 +1,36 @@
- content_for( :merged_menu ) do
.text-xl.font-bold.text-gray-900
Page
.text-xl.font-bold.text-gray-900
=@page.name
%strong.rounded.bg-green-100.px-3.text-xs.font-medium.text-green-700{:class => "py-1.5"}
= link_to 'Sections', page_sections_path(@page.id)
.text-xl= distance_of_time_in_words_to_now(@page.updated_at)
= render "layouts/merged_header"
.flex.gap-4.justify-center.m-20
.flex.flex-col
-@page.sections.each do |section |
.flex.pb-2.px-2{class: (section.index%2)==1 ? 'bg-cyan-50' : 'bg-red-50'}
=link_to( section_path(section.id)) do
.mt-4.text-lg.font-bold Section #{section.index} : #{section.header}
- if section.has_cards?
%h3.mt-4.text-lg.font-bold #{section.cards.length} Cards
.basis-80
= form_tag( page_url(@page.id) , {method: :patch , class: "mx-auto mt-8 mb-0 max-w space-y-4" } ) do
%label.block
%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)
.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
-if @page.option_definitions.empty?
%p No options
-else
.mt-4= submit_button("Update")

View File

@ -6,7 +6,7 @@ Merged::Engine.routes.draw do
post 'form/sendit'
resources :pages , except: [:show , :new] , shallow: true do
resources :pages , except: [:edit , :new] , shallow: true do
resources :sections do
get :select_image
get :set_image

View File

@ -7,11 +7,17 @@ RSpec.feature "Pages", type: :feature do
expect(page).to have_title("Dummy")
expect(page).to have_text("Pages")
end
end
describe "index page" do
it "returns http success" do
it "has an index page" do
visit "/merged/pages"
click_on ("index")
end
it "edit page works " do
visit "/merged/pages"
within("#index") do
click_on ("Edit")
end
end
end
end

View File

@ -6,7 +6,7 @@ module Merged
let(:first) {Card.first}
it "has Card.all" do
expect(Card.all.length).to be 46
expect(Card.all.length).to be 20
end
it "has cards" do
expect(first.class).to be Card
@ -29,16 +29,16 @@ module Merged
end
it "deletes " do
card = Card.find(20)
expect(card).not_to be nil
card.delete
expect{Card.find(20) }.to raise_error(ActiveHash::RecordNotFound)
id = first.id
first.delete
expect{Card.find(id) }.to raise_error(ActiveHash::RecordNotFound)
end
it "destroys " do
Card.find(20).destroy
id = first.id
first.delete
Card.reload
expect{Card.find(20) }.to raise_error(ActiveHash::RecordNotFound)
expect{Card.find(id) }.to raise_error(ActiveHash::RecordNotFound)
end
end

View File

@ -5,7 +5,7 @@ module Merged
let(:index) {Page.find_by_name('index')}
it "has Pages.all" do
expect(Page.all.length).to be 6
expect(Page.all.length).to be 2
end
it "has index page" do
expect(index.class).to be Page
@ -53,5 +53,9 @@ module Merged
page = Page.new_page( name)
expect(page.name).to eq name
end
it "has type" do
expect(index.type).to eq "page"
end
end
end

View File

@ -2,12 +2,11 @@ require 'rails_helper'
module Merged
RSpec.describe Section, type: :model do
let(:first) {Section.find_by_id(1)}
let(:second) {Section.find_by_id(2)}
let(:first) {Section.first}
let(:last) {Section.last}
it "has Sections.all" do
expect(Section.all.length).to be 40
expect(Section.all.length).to be 14
end
it "has index page" do
expect(last.class).to be Section
@ -22,8 +21,8 @@ module Merged
expect(last.cards.class).to be ActiveHash::Relation
end
it "has options" do
expect(second.options.class).to be Hash
expect(second.options.length).to be 6
expect(last.options.class).to be Hash
expect(first.options.length).to be 4
end
it "has option_definitions" do
expect(last.option_definitions.class).to be Array