show page for pages (a start)
This commit is contained in:
parent
54e8c287ca
commit
6dbddce173
@ -1,11 +1,15 @@
|
|||||||
module Merged
|
module Merged
|
||||||
class PagesController < MergedController
|
class PagesController < MergedController
|
||||||
before_action :set_page, only: %i[ update destroy ]
|
before_action :set_page, only: %i[ update destroy show ]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@pages = Page.all
|
@pages = Page.all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
name = params[:name]
|
name = params[:name]
|
||||||
message = Page.check_name(name)
|
message = Page.check_name(name)
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
module Merged
|
module Merged
|
||||||
class Page < ViewBase
|
class Page < ViewBase
|
||||||
|
|
||||||
|
fields :name , :type , :options
|
||||||
|
|
||||||
fields :name , :tempate
|
alias :template :type
|
||||||
|
|
||||||
def sections
|
def sections
|
||||||
Section.where(page_id: id).order(index: :asc)
|
Section.where(page_id: id).order(index: :asc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def template_style
|
||||||
|
PageStyle.find_by_type( type )
|
||||||
|
end
|
||||||
|
|
||||||
def new_section(section_template)
|
def new_section(section_template)
|
||||||
section_template = "section_spacer" if section_template.blank?
|
section_template = "section_spacer" if section_template.blank?
|
||||||
section = Section.new_section(section_template, self.id , sections.length + 1)
|
section = Section.new_section(section_template, self.id , sections.length + 1)
|
||||||
|
@ -11,6 +11,10 @@ module Merged
|
|||||||
Card.where(section_id: id).order(index: :asc)
|
Card.where(section_id: id).order(index: :asc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def template_style
|
||||||
|
SectionStyle.find_by_template( template )
|
||||||
|
end
|
||||||
|
|
||||||
def set_template(new_template)
|
def set_template(new_template)
|
||||||
self.template = new_template
|
self.template = new_template
|
||||||
new_style = template_style
|
new_style = template_style
|
||||||
|
@ -10,10 +10,6 @@ module Merged
|
|||||||
|
|
||||||
fields :options , :updated_at , :updated_by
|
fields :options , :updated_at , :updated_by
|
||||||
|
|
||||||
def template_style
|
|
||||||
SectionStyle.find_by_template( template )
|
|
||||||
end
|
|
||||||
|
|
||||||
def has_option?(option)
|
def has_option?(option)
|
||||||
options.has_key?(option) and !options[option].blank?
|
options.has_key?(option) and !options[option].blank?
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
Actions
|
Actions
|
||||||
%tbody.divide-y.divide-gray-200
|
%tbody.divide-y.divide-gray-200
|
||||||
- @pages.each do |merged_page|
|
- @pages.each do |merged_page|
|
||||||
%tr
|
%tr{id: merged_page.name}
|
||||||
%td.whitespace-nowrap.px-4.py-2.text-gray-700
|
%td.whitespace-nowrap.px-4.py-2.text-gray-700
|
||||||
= link_to merged_page.name , page_sections_path(merged_page.id)
|
= link_to merged_page.name , page_sections_path(merged_page.id)
|
||||||
%td.whitespace-nowrap.px-4.py-2.text-gray-700
|
%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"}
|
%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)
|
= 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"}
|
%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
|
.grid.grid-cols-3.gap-2.m-8
|
||||||
.relative.block.border.border-gray-100
|
.relative.block.border.border-gray-100
|
||||||
|
36
app/views/merged/pages/show.haml
Normal file
36
app/views/merged/pages/show.haml
Normal 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")
|
@ -6,7 +6,7 @@ Merged::Engine.routes.draw do
|
|||||||
|
|
||||||
post 'form/sendit'
|
post 'form/sendit'
|
||||||
|
|
||||||
resources :pages , except: [:show , :new] , shallow: true do
|
resources :pages , except: [:edit , :new] , shallow: true do
|
||||||
resources :sections do
|
resources :sections do
|
||||||
get :select_image
|
get :select_image
|
||||||
get :set_image
|
get :set_image
|
||||||
|
@ -7,11 +7,17 @@ RSpec.feature "Pages", type: :feature do
|
|||||||
expect(page).to have_title("Dummy")
|
expect(page).to have_title("Dummy")
|
||||||
expect(page).to have_text("Pages")
|
expect(page).to have_text("Pages")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
describe "index page" do
|
it "has an index page" do
|
||||||
it "returns http success" do
|
|
||||||
visit "/merged/pages"
|
visit "/merged/pages"
|
||||||
click_on ("index")
|
click_on ("index")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "edit page works " do
|
||||||
|
visit "/merged/pages"
|
||||||
|
within("#index") do
|
||||||
|
click_on ("Edit")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module Merged
|
|||||||
let(:first) {Card.first}
|
let(:first) {Card.first}
|
||||||
|
|
||||||
it "has Card.all" do
|
it "has Card.all" do
|
||||||
expect(Card.all.length).to be 46
|
expect(Card.all.length).to be 20
|
||||||
end
|
end
|
||||||
it "has cards" do
|
it "has cards" do
|
||||||
expect(first.class).to be Card
|
expect(first.class).to be Card
|
||||||
@ -29,16 +29,16 @@ module Merged
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "deletes " do
|
it "deletes " do
|
||||||
card = Card.find(20)
|
id = first.id
|
||||||
expect(card).not_to be nil
|
first.delete
|
||||||
card.delete
|
expect{Card.find(id) }.to raise_error(ActiveHash::RecordNotFound)
|
||||||
expect{Card.find(20) }.to raise_error(ActiveHash::RecordNotFound)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "destroys " do
|
it "destroys " do
|
||||||
Card.find(20).destroy
|
id = first.id
|
||||||
|
first.delete
|
||||||
Card.reload
|
Card.reload
|
||||||
expect{Card.find(20) }.to raise_error(ActiveHash::RecordNotFound)
|
expect{Card.find(id) }.to raise_error(ActiveHash::RecordNotFound)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Merged
|
|||||||
let(:index) {Page.find_by_name('index')}
|
let(:index) {Page.find_by_name('index')}
|
||||||
|
|
||||||
it "has Pages.all" do
|
it "has Pages.all" do
|
||||||
expect(Page.all.length).to be 6
|
expect(Page.all.length).to be 2
|
||||||
end
|
end
|
||||||
it "has index page" do
|
it "has index page" do
|
||||||
expect(index.class).to be Page
|
expect(index.class).to be Page
|
||||||
@ -53,5 +53,9 @@ module Merged
|
|||||||
page = Page.new_page( name)
|
page = Page.new_page( name)
|
||||||
expect(page.name).to eq name
|
expect(page.name).to eq name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "has type" do
|
||||||
|
expect(index.type).to eq "page"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,12 +2,11 @@ require 'rails_helper'
|
|||||||
|
|
||||||
module Merged
|
module Merged
|
||||||
RSpec.describe Section, type: :model do
|
RSpec.describe Section, type: :model do
|
||||||
let(:first) {Section.find_by_id(1)}
|
let(:first) {Section.first}
|
||||||
let(:second) {Section.find_by_id(2)}
|
|
||||||
let(:last) {Section.last}
|
let(:last) {Section.last}
|
||||||
|
|
||||||
it "has Sections.all" do
|
it "has Sections.all" do
|
||||||
expect(Section.all.length).to be 40
|
expect(Section.all.length).to be 14
|
||||||
end
|
end
|
||||||
it "has index page" do
|
it "has index page" do
|
||||||
expect(last.class).to be Section
|
expect(last.class).to be Section
|
||||||
@ -22,8 +21,8 @@ module Merged
|
|||||||
expect(last.cards.class).to be ActiveHash::Relation
|
expect(last.cards.class).to be ActiveHash::Relation
|
||||||
end
|
end
|
||||||
it "has options" do
|
it "has options" do
|
||||||
expect(second.options.class).to be Hash
|
expect(last.options.class).to be Hash
|
||||||
expect(second.options.length).to be 6
|
expect(first.options.length).to be 4
|
||||||
end
|
end
|
||||||
it "has option_definitions" do
|
it "has option_definitions" do
|
||||||
expect(last.option_definitions.class).to be Array
|
expect(last.option_definitions.class).to be Array
|
||||||
|
Loading…
Reference in New Issue
Block a user