sibu 0.7.3 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -20
- data/README.md +38 -38
- data/Rakefile +36 -36
- data/app/assets/config/sibu_manifest.js +2 -2
- data/app/assets/fonts/sibu/Sibu.eot +0 -0
- data/app/assets/fonts/sibu/Sibu.svg +13 -13
- data/app/assets/fonts/sibu/Sibu.ttf +0 -0
- data/app/assets/fonts/sibu/Sibu.woff +0 -0
- data/app/assets/javascripts/cropper/cropper.js +3694 -3694
- data/app/assets/javascripts/quill/quill.js +11401 -11401
- data/app/assets/javascripts/sibu/common.js +6 -6
- data/app/assets/javascripts/sibu/sibu.js.erb +155 -177
- data/app/assets/javascripts/tabs/van11y-accessible-tab-panel-aria.js +466 -0
- data/app/assets/stylesheets/cropper/cropper.css +304 -304
- data/app/assets/stylesheets/quill/quill.snow.css +945 -945
- data/app/assets/stylesheets/sibu/defaults.scss +336 -284
- data/app/assets/stylesheets/sibu/icons.scss +40 -40
- data/app/assets/stylesheets/sibu/sibu.css +131 -136
- data/app/controllers/sibu/application_controller.rb +14 -14
- data/app/controllers/sibu/documents_controller.rb +35 -35
- data/app/controllers/sibu/images_controller.rb +78 -78
- data/app/controllers/sibu/pages_controller.rb +197 -197
- data/app/controllers/sibu/sites_controller.rb +81 -81
- data/app/helpers/sibu/application_helper.rb +11 -11
- data/app/helpers/sibu/documents_helper.rb +4 -4
- data/app/helpers/sibu/images_helper.rb +4 -4
- data/app/helpers/sibu/pages_helper.rb +194 -194
- data/app/helpers/sibu/sites_helper.rb +23 -23
- data/app/jobs/sibu/application_job.rb +4 -4
- data/app/mailers/sibu/application_mailer.rb +6 -6
- data/app/models/concerns/sibu/document_uploader.rb +8 -8
- data/app/models/concerns/sibu/image_uploader.rb +31 -31
- data/app/models/concerns/sibu/sections_concern.rb +134 -134
- data/app/models/concerns/sibu/style_uploader.rb +1 -1
- data/app/models/concerns/sibu/user_concern.rb +8 -8
- data/app/models/sibu/application_record.rb +5 -5
- data/app/models/sibu/document.rb +16 -16
- data/app/models/sibu/dynamic_style.rb +76 -76
- data/app/models/sibu/image.rb +19 -19
- data/app/models/sibu/page.rb +66 -66
- data/app/models/sibu/site.rb +97 -97
- data/app/models/sibu/site_template.rb +22 -17
- data/app/views/layouts/sibu/application.html.erb +23 -23
- data/app/views/layouts/sibu/edit_content.html.erb +262 -255
- data/app/views/layouts/sibu/site.html.erb +45 -45
- data/app/views/sibu/documents/_form.html.erb +14 -14
- data/app/views/sibu/documents/index.html.erb +37 -37
- data/app/views/sibu/documents/new.html.erb +12 -12
- data/app/views/sibu/images/_edit_form.html.erb +23 -23
- data/app/views/sibu/images/_form.html.erb +34 -34
- data/app/views/sibu/images/edit.js.erb +2 -2
- data/app/views/sibu/images/index.html.erb +13 -13
- data/app/views/sibu/images/new.html.erb +12 -12
- data/app/views/sibu/images/show.html.erb +2 -2
- data/app/views/sibu/pages/_code_edit_panel.html.erb +17 -17
- data/app/views/sibu/pages/_element_actions.html.erb +4 -4
- data/app/views/sibu/pages/_error_panel.html.erb +4 -4
- data/app/views/sibu/pages/_form.html.erb +62 -62
- data/app/views/sibu/pages/_group_edit_panel.html.erb +3 -3
- data/app/views/sibu/pages/_link_edit_panel.html.erb +50 -50
- data/app/views/sibu/pages/_map_edit_panel.html.erb +27 -27
- data/app/views/sibu/pages/_media_edit_panel.html.erb +46 -46
- data/app/views/sibu/pages/_new_section_panel.html.erb +43 -27
- data/app/views/sibu/pages/_paragraph_edit_panel.html.erb +18 -18
- data/app/views/sibu/pages/_text_edit_panel.html.erb +19 -19
- data/app/views/sibu/pages/child_element.js.erb +6 -6
- data/app/views/sibu/pages/clone_element.js.erb +6 -6
- data/app/views/sibu/pages/create_section.js.erb +6 -6
- data/app/views/sibu/pages/delete_element.js.erb +6 -6
- data/app/views/sibu/pages/delete_section.js.erb +6 -6
- data/app/views/sibu/pages/destroy.html.erb +2 -2
- data/app/views/sibu/pages/edit.html.erb +8 -8
- data/app/views/sibu/pages/edit_content.html.erb +3 -3
- data/app/views/sibu/pages/edit_element.js.erb +100 -100
- data/app/views/sibu/pages/edit_section.js.erb +7 -7
- data/app/views/sibu/pages/index.html.erb +40 -40
- data/app/views/sibu/pages/new.html.erb +8 -8
- data/app/views/sibu/pages/new_section.js.erb +19 -18
- data/app/views/sibu/pages/show.html.erb +3 -3
- data/app/views/sibu/pages/update.html.erb +2 -2
- data/app/views/sibu/pages/update_element.js.erb +5 -5
- data/app/views/sibu/pages/update_section.js.erb +5 -5
- data/app/views/sibu/sites/_form.html.erb +125 -125
- data/app/views/sibu/sites/destroy.html.erb +2 -2
- data/app/views/sibu/sites/edit.html.erb +9 -9
- data/app/views/sibu/sites/edit_styles.html.erb +8 -8
- data/app/views/sibu/sites/index.html.erb +41 -41
- data/app/views/sibu/sites/new.html.erb +18 -18
- data/app/views/sibu/sites/update.html.erb +2 -2
- data/config/initializers/constants.rb +2 -2
- data/config/initializers/shrine.rb +18 -18
- data/config/routes.rb +30 -30
- data/config/tinymce.yml +5 -5
- data/db/migrate/20180124095041_create_sibu_sites.rb +12 -12
- data/db/migrate/20180124095213_create_sibu_pages.rb +15 -15
- data/db/migrate/20180124145030_create_sibu_site_templates.rb +10 -10
- data/db/migrate/20180125231638_add_user_id_to_sites.rb +5 -5
- data/db/migrate/20180126114522_rename_url_to_path_in_pages.rb +5 -5
- data/db/migrate/20180126114628_add_domain_to_sites.rb +5 -5
- data/db/migrate/20180127211533_create_sibu_images.rb +11 -11
- data/db/migrate/20180208082317_rename_images_user_id_to_site_id.rb +5 -5
- data/db/migrate/20180208125024_rename_image_data_column.rb +5 -5
- data/db/migrate/20180210181644_add_defaults_to_site_templates.rb +6 -6
- data/db/migrate/20180214134653_add_fields_to_sites.rb +5 -5
- data/db/migrate/20180227151519_add_default_templates_to_site_templates.rb +5 -5
- data/db/migrate/20180301121902_add_style_data_to_sites.rb +5 -5
- data/db/migrate/20180301152101_add_default_styles_to_templates.rb +5 -5
- data/db/migrate/20180321144021_move_images_to_user_level.rb +7 -7
- data/db/migrate/20180321170310_add_version_to_sibu_sites.rb +7 -7
- data/db/migrate/20180405095448_create_sibu_documents.rb +10 -10
- data/db/migrate/20190110204854_add_custom_data_to_sibu_pages.rb +5 -5
- data/lib/sibu.rb +4 -4
- data/lib/sibu/engine.rb +19 -19
- data/lib/sibu/utils.rb +14 -14
- data/lib/sibu/version.rb +3 -3
- data/lib/tasks/sibu_tasks.rake +4 -4
- metadata +4 -3
@@ -1,78 +1,78 @@
|
|
1
|
-
require_dependency "sibu/application_controller"
|
2
|
-
|
3
|
-
module Sibu
|
4
|
-
class ImagesController < ApplicationController
|
5
|
-
before_action :set_image, only: [:edit, :update, :destroy]
|
6
|
-
before_action :set_edition_context, only: [:new, :create]
|
7
|
-
|
8
|
-
def index
|
9
|
-
@images = Sibu::Image.for_user(sibu_user)
|
10
|
-
end
|
11
|
-
|
12
|
-
def new
|
13
|
-
@image = Sibu::Image.new(user_id: send(Rails.application.config.sibu[:current_user]).id)
|
14
|
-
end
|
15
|
-
|
16
|
-
def create
|
17
|
-
@image = Sibu::Image.new(image_params)
|
18
|
-
if @image.save
|
19
|
-
if !@page_id.blank? && !@section_id.blank? && !@element_id.blank? && !@size.blank?
|
20
|
-
p = Sibu::Page.find(@page_id)
|
21
|
-
entity = @entity_type == 'site' ? p.site : p
|
22
|
-
ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
|
23
|
-
elt = entity.update_element(*ids, {"id" => @img_id, "src" => @image.file_url(@size.to_sym), "alt" => @image.alt})
|
24
|
-
if elt.nil?
|
25
|
-
msg = {alert: "Une erreur s'est produite lors de la mise à jour de l'image."}
|
26
|
-
else
|
27
|
-
msg = {notice: "L'image a bien été mise à jour."}
|
28
|
-
end
|
29
|
-
redirect_to site_page_edit_content_path(p.site_id, @page_id), msg
|
30
|
-
else
|
31
|
-
redirect_to images_url, notice: "L'image a bien été téléchargée."
|
32
|
-
end
|
33
|
-
else
|
34
|
-
flash.now[:alert] = "Une erreur s'est produite lors du téléchargement de l'image."
|
35
|
-
render :new
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def show
|
40
|
-
end
|
41
|
-
|
42
|
-
def edit
|
43
|
-
end
|
44
|
-
|
45
|
-
def update
|
46
|
-
if @image.update(image_params)
|
47
|
-
redirect_to images_url, notice: "L'image a bien été mise à jour."
|
48
|
-
else
|
49
|
-
flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement de l'image."
|
50
|
-
render :index
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def destroy
|
55
|
-
@image.destroy
|
56
|
-
redirect_to images_url, notice: "L'image a bien été supprimée."
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def set_image
|
62
|
-
@image = Sibu::Image.find(params[:id])
|
63
|
-
end
|
64
|
-
|
65
|
-
def set_edition_context
|
66
|
-
@page_id = params[:page_id]
|
67
|
-
@entity_type = params[:entity_type]
|
68
|
-
@section_id = params[:section_id]
|
69
|
-
@element_id = params[:element_id]
|
70
|
-
@img_id = params[:img_id]
|
71
|
-
@size = params[:size]
|
72
|
-
end
|
73
|
-
|
74
|
-
def image_params
|
75
|
-
params.require(:image).permit!
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
1
|
+
require_dependency "sibu/application_controller"
|
2
|
+
|
3
|
+
module Sibu
|
4
|
+
class ImagesController < ApplicationController
|
5
|
+
before_action :set_image, only: [:edit, :update, :destroy]
|
6
|
+
before_action :set_edition_context, only: [:new, :create]
|
7
|
+
|
8
|
+
def index
|
9
|
+
@images = Sibu::Image.for_user(sibu_user)
|
10
|
+
end
|
11
|
+
|
12
|
+
def new
|
13
|
+
@image = Sibu::Image.new(user_id: send(Rails.application.config.sibu[:current_user]).id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
@image = Sibu::Image.new(image_params)
|
18
|
+
if @image.save
|
19
|
+
if !@page_id.blank? && !@section_id.blank? && !@element_id.blank? && !@size.blank?
|
20
|
+
p = Sibu::Page.find(@page_id)
|
21
|
+
entity = @entity_type == 'site' ? p.site : p
|
22
|
+
ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
|
23
|
+
elt = entity.update_element(*ids, {"id" => @img_id, "src" => @image.file_url(@size.to_sym), "alt" => @image.alt})
|
24
|
+
if elt.nil?
|
25
|
+
msg = {alert: "Une erreur s'est produite lors de la mise à jour de l'image."}
|
26
|
+
else
|
27
|
+
msg = {notice: "L'image a bien été mise à jour."}
|
28
|
+
end
|
29
|
+
redirect_to site_page_edit_content_path(p.site_id, @page_id), msg
|
30
|
+
else
|
31
|
+
redirect_to images_url, notice: "L'image a bien été téléchargée."
|
32
|
+
end
|
33
|
+
else
|
34
|
+
flash.now[:alert] = "Une erreur s'est produite lors du téléchargement de l'image."
|
35
|
+
render :new
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def show
|
40
|
+
end
|
41
|
+
|
42
|
+
def edit
|
43
|
+
end
|
44
|
+
|
45
|
+
def update
|
46
|
+
if @image.update(image_params)
|
47
|
+
redirect_to images_url, notice: "L'image a bien été mise à jour."
|
48
|
+
else
|
49
|
+
flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement de l'image."
|
50
|
+
render :index
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def destroy
|
55
|
+
@image.destroy
|
56
|
+
redirect_to images_url, notice: "L'image a bien été supprimée."
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def set_image
|
62
|
+
@image = Sibu::Image.find(params[:id])
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_edition_context
|
66
|
+
@page_id = params[:page_id]
|
67
|
+
@entity_type = params[:entity_type]
|
68
|
+
@section_id = params[:section_id]
|
69
|
+
@element_id = params[:element_id]
|
70
|
+
@img_id = params[:img_id]
|
71
|
+
@size = params[:size]
|
72
|
+
end
|
73
|
+
|
74
|
+
def image_params
|
75
|
+
params.require(:image).permit!
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -1,197 +1,197 @@
|
|
1
|
-
require_dependency "sibu/application_controller"
|
2
|
-
|
3
|
-
module Sibu
|
4
|
-
class PagesController < ApplicationController
|
5
|
-
before_action :set_page, only: [:edit, :update, :destroy, :duplicate, :edit_element, :update_element, :clone_element,
|
6
|
-
:delete_element, :child_element, :new_section, :create_section, :edit_section,
|
7
|
-
:update_section, :delete_section]
|
8
|
-
before_action :set_site, only: [:index, :new]
|
9
|
-
before_action :set_edit_context, only: [:edit_element, :update_element, :clone_element, :delete_element,
|
10
|
-
:child_element, :new_section, :create_section, :edit_section,
|
11
|
-
:update_section, :delete_section]
|
12
|
-
before_action :set_online, only: [:show, :edit]
|
13
|
-
skip_before_action Rails.application.config.sibu[:auth_filter], only: [:show]
|
14
|
-
|
15
|
-
def index
|
16
|
-
@pages = @site.pages.order(:created_at)
|
17
|
-
end
|
18
|
-
|
19
|
-
def show
|
20
|
-
return_code = :ok
|
21
|
-
if params[:site_id].blank?
|
22
|
-
@page = Sibu::Page.lookup(request.host, params[:path])
|
23
|
-
if @page
|
24
|
-
@query_path = params[:path][@page.path.length + 1..-1] unless @page.path.blank?
|
25
|
-
@query_params = show_params.except(:controller, :action, :path).to_h
|
26
|
-
@site = @page.site
|
27
|
-
@links = @site.pages_path_by_id
|
28
|
-
view_template = 'show'
|
29
|
-
else
|
30
|
-
@site = Sibu::Site.where(domain: request.host).first
|
31
|
-
view_template = Rails.application.config.sibu[:not_found]
|
32
|
-
return_code = :not_found
|
33
|
-
end
|
34
|
-
else
|
35
|
-
@site = Sibu::Site.find(params[:site_id])
|
36
|
-
@page = Sibu::Page.find(params[:id])
|
37
|
-
@links = @site.pages_path_by_id
|
38
|
-
@query_path = params[:path]
|
39
|
-
@query_params = show_params.except(:controller, :action, :path).to_h
|
40
|
-
view_template = 'show'
|
41
|
-
end
|
42
|
-
|
43
|
-
render view_template, layout: 'sibu/site', status: return_code
|
44
|
-
end
|
45
|
-
|
46
|
-
def new
|
47
|
-
@page = Sibu::Page.new(site_id: @site.id)
|
48
|
-
end
|
49
|
-
|
50
|
-
def create
|
51
|
-
@page = Sibu::Page.new(page_params)
|
52
|
-
if @page.save_and_init
|
53
|
-
redirect_to site_pages_url(@page.site_id), notice: "La page a bien été créée."
|
54
|
-
else
|
55
|
-
flash.now[:alert] = "Une erreur s'est produite lors de la création de la page."
|
56
|
-
render :new
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def edit
|
61
|
-
end
|
62
|
-
|
63
|
-
def update
|
64
|
-
if @page.update(page_params)
|
65
|
-
redirect_to site_pages_url(@page.site_id), notice: "La page a bien été mise à jour."
|
66
|
-
else
|
67
|
-
flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement de la page."
|
68
|
-
render :edit
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def destroy
|
73
|
-
site_id = @page.site_id
|
74
|
-
if @page.destroy
|
75
|
-
redirect_to site_pages_url(site_id), notice: "La page a bien été supprimée."
|
76
|
-
else
|
77
|
-
flash.now[:alert] = "Une erreur s'est produite lors de la suppression de la page."
|
78
|
-
render :index
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def duplicate
|
83
|
-
new_page = @page.deep_copy
|
84
|
-
if new_page.save
|
85
|
-
redirect_to site_pages_url(@page.site_id), notice: "La page a bien été copiée."
|
86
|
-
else
|
87
|
-
flash.now[:alert] = "Une erreur s'est produite lors de la copie de la page."
|
88
|
-
render :index
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def edit_content
|
93
|
-
@page = Sibu::Page.find(params[:page_id])
|
94
|
-
@site = Sibu::Site.includes(:pages).find(@page.site_id) if @page
|
95
|
-
@links = @site.pages_path_by_id if @site
|
96
|
-
@edit_section = params[:edit_section]
|
97
|
-
render :edit_content, layout: 'sibu/edit_content'
|
98
|
-
end
|
99
|
-
|
100
|
-
def edit_element
|
101
|
-
@content_type = params[:content_type]
|
102
|
-
@links = @site.pages_path_by_id if @site
|
103
|
-
@element = @entity.element(*@section_id.split('|'), *@element_id.split('|'))
|
104
|
-
@repeat = params[:repeat]
|
105
|
-
@size = params[:size].blank? ? :medium : params[:size].to_sym
|
106
|
-
@children = params[:children]
|
107
|
-
end
|
108
|
-
|
109
|
-
def update_element
|
110
|
-
ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
|
111
|
-
@updated = @entity.update_element(*ids, element_params)
|
112
|
-
@refresh = params[:refresh]
|
113
|
-
end
|
114
|
-
|
115
|
-
def clone_element
|
116
|
-
@cloned = @entity.clone_element(*@section_id.split('|'), *@element_id.split('|'))
|
117
|
-
end
|
118
|
-
|
119
|
-
def delete_element
|
120
|
-
@deleted = @entity.delete_element(*@section_id.split('|'), *@element_id.split('|'))
|
121
|
-
end
|
122
|
-
|
123
|
-
def child_element
|
124
|
-
@added = @entity.child_element(*@section_id.split('|'), *@element_id.split('|'))
|
125
|
-
end
|
126
|
-
|
127
|
-
def new_section
|
128
|
-
page = Sibu::Page.find(params[:id])
|
129
|
-
@page = Page.new(id: page.id, sections: [])
|
130
|
-
@site = Sibu::Site.includes(:pages).find(page.site_id)
|
131
|
-
@after = params[:after]
|
132
|
-
@links = @site.pages_path_by_id
|
133
|
-
|
134
|
-
@site.site_template.
|
135
|
-
template_defaults = @site.site_template.templates ? (@site.site_template.templates[t["template"]] || {}) : {}
|
136
|
-
@page.sections << template_defaults.merge(t).to_h
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def create_section
|
141
|
-
@created = @entity.create_section(*@section_id.split('|'), params[:after], section_params)
|
142
|
-
end
|
143
|
-
|
144
|
-
def edit_section
|
145
|
-
@section = @entity.section(params[:section_id])
|
146
|
-
end
|
147
|
-
|
148
|
-
def update_section
|
149
|
-
# {"utf8"=>"✓", "section"=>{"color"=>"#AFCA0B", "filters"=>"school_camps"}, "section_id"=>"cs1536301729", "refresh"=>"true", "commit"=>"Valider", "site_id"=>"3", "id"=>"1392"}
|
150
|
-
@entity.section(params[:section_id]).merge!(section_params)
|
151
|
-
logger.debug @entity.section(params[:section_id])
|
152
|
-
@updated = @entity.save
|
153
|
-
end
|
154
|
-
|
155
|
-
def delete_section
|
156
|
-
@deleted = @entity.delete_section(*@section_id.split('|'))
|
157
|
-
end
|
158
|
-
|
159
|
-
private
|
160
|
-
|
161
|
-
def set_page
|
162
|
-
@page = Sibu::Page.find(params[:id])
|
163
|
-
@site = Sibu::Site.includes(:pages).find(@page.site_id) if @page
|
164
|
-
end
|
165
|
-
|
166
|
-
def set_site
|
167
|
-
@site = Sibu::Site.find(params[:site_id])
|
168
|
-
end
|
169
|
-
|
170
|
-
def set_edit_context
|
171
|
-
@entity_type = params[:entity]
|
172
|
-
@section_id = params[:section_id]
|
173
|
-
@element_id = params[:element_id]
|
174
|
-
@entity = @entity_type == 'site' ? @site : @page
|
175
|
-
end
|
176
|
-
|
177
|
-
def set_online
|
178
|
-
@online = request.host != conf[:host]
|
179
|
-
end
|
180
|
-
|
181
|
-
def page_params
|
182
|
-
params.require(:page).permit!
|
183
|
-
end
|
184
|
-
|
185
|
-
def element_params
|
186
|
-
params.require(:element).permit!
|
187
|
-
end
|
188
|
-
|
189
|
-
def section_params
|
190
|
-
params.require(:section).permit!
|
191
|
-
end
|
192
|
-
|
193
|
-
def show_params
|
194
|
-
params.permit!
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
1
|
+
require_dependency "sibu/application_controller"
|
2
|
+
|
3
|
+
module Sibu
|
4
|
+
class PagesController < ApplicationController
|
5
|
+
before_action :set_page, only: [:edit, :update, :destroy, :duplicate, :edit_element, :update_element, :clone_element,
|
6
|
+
:delete_element, :child_element, :new_section, :create_section, :edit_section,
|
7
|
+
:update_section, :delete_section]
|
8
|
+
before_action :set_site, only: [:index, :new]
|
9
|
+
before_action :set_edit_context, only: [:edit_element, :update_element, :clone_element, :delete_element,
|
10
|
+
:child_element, :new_section, :create_section, :edit_section,
|
11
|
+
:update_section, :delete_section]
|
12
|
+
before_action :set_online, only: [:show, :edit]
|
13
|
+
skip_before_action Rails.application.config.sibu[:auth_filter], only: [:show]
|
14
|
+
|
15
|
+
def index
|
16
|
+
@pages = @site.pages.order(:created_at)
|
17
|
+
end
|
18
|
+
|
19
|
+
def show
|
20
|
+
return_code = :ok
|
21
|
+
if params[:site_id].blank?
|
22
|
+
@page = Sibu::Page.lookup(request.host, params[:path])
|
23
|
+
if @page
|
24
|
+
@query_path = params[:path][@page.path.length + 1..-1] unless @page.path.blank?
|
25
|
+
@query_params = show_params.except(:controller, :action, :path).to_h
|
26
|
+
@site = @page.site
|
27
|
+
@links = @site.pages_path_by_id
|
28
|
+
view_template = 'show'
|
29
|
+
else
|
30
|
+
@site = Sibu::Site.where(domain: request.host).first
|
31
|
+
view_template = Rails.application.config.sibu[:not_found]
|
32
|
+
return_code = :not_found
|
33
|
+
end
|
34
|
+
else
|
35
|
+
@site = Sibu::Site.find(params[:site_id])
|
36
|
+
@page = Sibu::Page.find(params[:id])
|
37
|
+
@links = @site.pages_path_by_id
|
38
|
+
@query_path = params[:path]
|
39
|
+
@query_params = show_params.except(:controller, :action, :path).to_h
|
40
|
+
view_template = 'show'
|
41
|
+
end
|
42
|
+
|
43
|
+
render view_template, layout: 'sibu/site', status: return_code
|
44
|
+
end
|
45
|
+
|
46
|
+
def new
|
47
|
+
@page = Sibu::Page.new(site_id: @site.id)
|
48
|
+
end
|
49
|
+
|
50
|
+
def create
|
51
|
+
@page = Sibu::Page.new(page_params)
|
52
|
+
if @page.save_and_init
|
53
|
+
redirect_to site_pages_url(@page.site_id), notice: "La page a bien été créée."
|
54
|
+
else
|
55
|
+
flash.now[:alert] = "Une erreur s'est produite lors de la création de la page."
|
56
|
+
render :new
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def edit
|
61
|
+
end
|
62
|
+
|
63
|
+
def update
|
64
|
+
if @page.update(page_params)
|
65
|
+
redirect_to site_pages_url(@page.site_id), notice: "La page a bien été mise à jour."
|
66
|
+
else
|
67
|
+
flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement de la page."
|
68
|
+
render :edit
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def destroy
|
73
|
+
site_id = @page.site_id
|
74
|
+
if @page.destroy
|
75
|
+
redirect_to site_pages_url(site_id), notice: "La page a bien été supprimée."
|
76
|
+
else
|
77
|
+
flash.now[:alert] = "Une erreur s'est produite lors de la suppression de la page."
|
78
|
+
render :index
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def duplicate
|
83
|
+
new_page = @page.deep_copy
|
84
|
+
if new_page.save
|
85
|
+
redirect_to site_pages_url(@page.site_id), notice: "La page a bien été copiée."
|
86
|
+
else
|
87
|
+
flash.now[:alert] = "Une erreur s'est produite lors de la copie de la page."
|
88
|
+
render :index
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def edit_content
|
93
|
+
@page = Sibu::Page.find(params[:page_id])
|
94
|
+
@site = Sibu::Site.includes(:pages).find(@page.site_id) if @page
|
95
|
+
@links = @site.pages_path_by_id if @site
|
96
|
+
@edit_section = params[:edit_section]
|
97
|
+
render :edit_content, layout: 'sibu/edit_content'
|
98
|
+
end
|
99
|
+
|
100
|
+
def edit_element
|
101
|
+
@content_type = params[:content_type]
|
102
|
+
@links = @site.pages_path_by_id if @site
|
103
|
+
@element = @entity.element(*@section_id.split('|'), *@element_id.split('|'))
|
104
|
+
@repeat = params[:repeat]
|
105
|
+
@size = params[:size].blank? ? :medium : params[:size].to_sym
|
106
|
+
@children = params[:children]
|
107
|
+
end
|
108
|
+
|
109
|
+
def update_element
|
110
|
+
ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
|
111
|
+
@updated = @entity.update_element(*ids, element_params)
|
112
|
+
@refresh = params[:refresh]
|
113
|
+
end
|
114
|
+
|
115
|
+
def clone_element
|
116
|
+
@cloned = @entity.clone_element(*@section_id.split('|'), *@element_id.split('|'))
|
117
|
+
end
|
118
|
+
|
119
|
+
def delete_element
|
120
|
+
@deleted = @entity.delete_element(*@section_id.split('|'), *@element_id.split('|'))
|
121
|
+
end
|
122
|
+
|
123
|
+
def child_element
|
124
|
+
@added = @entity.child_element(*@section_id.split('|'), *@element_id.split('|'))
|
125
|
+
end
|
126
|
+
|
127
|
+
def new_section
|
128
|
+
page = Sibu::Page.find(params[:id])
|
129
|
+
@page = Page.new(id: page.id, sections: [])
|
130
|
+
@site = Sibu::Site.includes(:pages).find(page.site_id)
|
131
|
+
@after = params[:after]
|
132
|
+
@links = @site.pages_path_by_id
|
133
|
+
|
134
|
+
@site.site_template.available_sections.each do |t|
|
135
|
+
template_defaults = @site.site_template.templates ? (@site.site_template.templates[t["template"]] || {}) : {}
|
136
|
+
@page.sections << template_defaults.merge(t).to_h
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def create_section
|
141
|
+
@created = @entity.create_section(*@section_id.split('|'), params[:after], section_params)
|
142
|
+
end
|
143
|
+
|
144
|
+
def edit_section
|
145
|
+
@section = @entity.section(params[:section_id])
|
146
|
+
end
|
147
|
+
|
148
|
+
def update_section
|
149
|
+
# {"utf8"=>"✓", "section"=>{"color"=>"#AFCA0B", "filters"=>"school_camps"}, "section_id"=>"cs1536301729", "refresh"=>"true", "commit"=>"Valider", "site_id"=>"3", "id"=>"1392"}
|
150
|
+
@entity.section(params[:section_id]).merge!(section_params)
|
151
|
+
logger.debug @entity.section(params[:section_id])
|
152
|
+
@updated = @entity.save
|
153
|
+
end
|
154
|
+
|
155
|
+
def delete_section
|
156
|
+
@deleted = @entity.delete_section(*@section_id.split('|'))
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
def set_page
|
162
|
+
@page = Sibu::Page.find(params[:id])
|
163
|
+
@site = Sibu::Site.includes(:pages).find(@page.site_id) if @page
|
164
|
+
end
|
165
|
+
|
166
|
+
def set_site
|
167
|
+
@site = Sibu::Site.find(params[:site_id])
|
168
|
+
end
|
169
|
+
|
170
|
+
def set_edit_context
|
171
|
+
@entity_type = params[:entity]
|
172
|
+
@section_id = params[:section_id]
|
173
|
+
@element_id = params[:element_id]
|
174
|
+
@entity = @entity_type == 'site' ? @site : @page
|
175
|
+
end
|
176
|
+
|
177
|
+
def set_online
|
178
|
+
@online = request.host != conf[:host]
|
179
|
+
end
|
180
|
+
|
181
|
+
def page_params
|
182
|
+
params.require(:page).permit!
|
183
|
+
end
|
184
|
+
|
185
|
+
def element_params
|
186
|
+
params.require(:element).permit!
|
187
|
+
end
|
188
|
+
|
189
|
+
def section_params
|
190
|
+
params.require(:section).permit!
|
191
|
+
end
|
192
|
+
|
193
|
+
def show_params
|
194
|
+
params.permit!
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|