spina 1.1.2 → 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of spina might be problematic. Click here for more details.

Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/fonts/spina/ics_spina.eot +0 -0
  3. data/app/assets/fonts/spina/ics_spina.svg +285 -267
  4. data/app/assets/fonts/spina/ics_spina.ttf +0 -0
  5. data/app/assets/fonts/spina/ics_spina.woff +0 -0
  6. data/app/assets/fonts/spina/ics_spina.woff2 +0 -0
  7. data/app/assets/icons/spina/bold.svg +1 -1
  8. data/app/assets/icons/spina/code.svg +1 -1
  9. data/app/assets/icons/spina/image.svg +1 -10
  10. data/app/assets/icons/spina/indent.svg +1 -0
  11. data/app/assets/icons/spina/italic.svg +1 -1
  12. data/app/assets/icons/spina/link.svg +1 -1
  13. data/app/assets/icons/spina/list-ol.svg +1 -0
  14. data/app/assets/icons/spina/list.svg +1 -0
  15. data/app/assets/icons/spina/outdent.svg +1 -0
  16. data/app/assets/icons/spina/preview/icons_spina-preview.html +0 -2
  17. data/app/assets/icons/spina/preview/ics_spina-preview.html +121 -3
  18. data/app/assets/icons/spina/quote-right.svg +1 -0
  19. data/app/assets/icons/spina/redo.svg +1 -0
  20. data/app/assets/icons/spina/strikethrough.svg +1 -0
  21. data/app/assets/icons/spina/undo.svg +1 -0
  22. data/app/assets/images/spina/favicon.png +0 -0
  23. data/app/assets/javascripts/spina/admin/application.js +1 -2
  24. data/app/assets/javascripts/spina/admin/controllers/attachment_picker_controller.js +15 -0
  25. data/app/assets/javascripts/spina/admin/controllers/image_form_controller.js +5 -4
  26. data/app/assets/javascripts/spina/admin/controllers/infinite_scroll_controller.js +20 -22
  27. data/app/assets/javascripts/spina/admin/controllers/media_picker_controller.js +171 -0
  28. data/app/assets/javascripts/spina/admin/controllers/modal_controller.js +18 -0
  29. data/app/assets/javascripts/spina/admin/controllers/repeater_form_controller.js +38 -0
  30. data/app/assets/javascripts/spina/admin/media_gallery.coffee +0 -3
  31. data/app/assets/javascripts/spina/admin/notifications.coffee +1 -1
  32. data/app/assets/javascripts/spina/admin/pages.coffee.erb +3 -20
  33. data/app/assets/javascripts/spina/admin/scaffold.coffee +1 -3
  34. data/app/assets/javascripts/spina/admin/trix.coffee.erb +14 -18
  35. data/app/assets/stylesheets/spina.sass +10 -8
  36. data/app/assets/stylesheets/spina/_buttons.sass +57 -31
  37. data/app/assets/stylesheets/spina/_configuration.sass.erb +1 -1
  38. data/app/assets/stylesheets/spina/_forms.sass +72 -77
  39. data/app/assets/stylesheets/spina/_gallery.sass +22 -4
  40. data/app/assets/stylesheets/spina/_ics_spina.scss +8 -0
  41. data/app/assets/stylesheets/spina/_media_picker.sass +133 -0
  42. data/app/assets/stylesheets/spina/_modal.sass +35 -2
  43. data/app/assets/stylesheets/spina/_notifications.sass +20 -14
  44. data/app/assets/stylesheets/spina/_pages.sass +131 -0
  45. data/app/assets/stylesheets/spina/_sortable_lists.sass +14 -8
  46. data/app/assets/stylesheets/spina/_tables.sass +7 -4
  47. data/app/assets/stylesheets/spina/_trix_custom.sass +29 -32
  48. data/app/controllers/concerns/spina/current_methods.rb +26 -0
  49. data/app/controllers/concerns/spina/frontend.rb +9 -0
  50. data/app/controllers/spina/admin/accounts_controller.rb +9 -13
  51. data/app/controllers/spina/admin/admin_controller.rb +5 -1
  52. data/app/controllers/spina/admin/attachments_controller.rb +0 -22
  53. data/app/controllers/spina/admin/images_controller.rb +1 -1
  54. data/app/controllers/spina/admin/media_picker_controller.rb +18 -19
  55. data/app/controllers/spina/admin/pages_controller.rb +3 -7
  56. data/app/controllers/spina/admin/resources_controller.rb +9 -4
  57. data/app/controllers/spina/application_controller.rb +6 -23
  58. data/app/controllers/spina/pages_controller.rb +11 -13
  59. data/app/controllers/spina/sitemaps_controller.rb +6 -6
  60. data/app/helpers/spina/admin/pages_helper.rb +22 -20
  61. data/app/helpers/spina/{files_helper.rb → attachments_helper.rb} +1 -1
  62. data/app/helpers/spina/images_helper.rb +9 -10
  63. data/app/helpers/spina/pages_helper.rb +23 -4
  64. data/app/models/concerns/spina/partable.rb +19 -7
  65. data/app/models/concerns/spina/translated_content.rb +19 -0
  66. data/app/models/spina/account.rb +3 -10
  67. data/app/models/spina/attachment.rb +0 -4
  68. data/app/models/spina/current.rb +1 -0
  69. data/app/models/spina/image.rb +0 -4
  70. data/app/models/spina/page.rb +31 -23
  71. data/app/models/spina/parts/attachment.rb +22 -0
  72. data/app/models/spina/parts/base.rb +12 -0
  73. data/app/models/spina/parts/image.rb +39 -0
  74. data/app/models/spina/parts/image_collection.rb +23 -0
  75. data/app/models/spina/parts/image_variant.rb +19 -0
  76. data/app/models/spina/parts/line.rb +7 -0
  77. data/app/models/spina/parts/multi_line.rb +7 -0
  78. data/app/models/spina/parts/option.rb +13 -0
  79. data/app/models/spina/parts/repeater.rb +10 -0
  80. data/app/models/spina/parts/repeater_content.rb +15 -0
  81. data/app/models/spina/parts/text.rb +7 -0
  82. data/app/models/spina/resource.rb +4 -12
  83. data/app/presenters/spina/content_presenter.rb +51 -0
  84. data/app/presenters/spina/menu_presenter.rb +2 -1
  85. data/app/views/layouts/spina/admin/admin.html.haml +3 -7
  86. data/app/views/layouts/spina/admin/pages.html.haml +5 -4
  87. data/app/views/layouts/spina/login.html.haml +0 -3
  88. data/app/views/spina/admin/accounts/_form.html.haml +13 -7
  89. data/app/views/spina/admin/accounts/analytics.html.haml +5 -3
  90. data/app/views/spina/admin/accounts/social.html.haml +13 -7
  91. data/app/views/spina/admin/accounts/style.html.haml +26 -21
  92. data/app/views/spina/admin/attachments/index.html.haml +1 -1
  93. data/app/views/spina/admin/images/_image.html.haml +1 -1
  94. data/app/views/spina/admin/images/index.html.haml +7 -5
  95. data/app/views/spina/admin/media_folders/_media_folder.html.haml +1 -1
  96. data/app/views/spina/admin/media_folders/show.html.haml +2 -2
  97. data/app/views/spina/admin/media_picker/_image.html.haml +3 -0
  98. data/app/views/spina/admin/media_picker/_media_picker.html.haml +32 -0
  99. data/app/views/spina/admin/media_picker/_media_picker_grid.html.haml +25 -0
  100. data/app/views/spina/admin/media_picker/_modal.html.haml +1 -1
  101. data/app/views/spina/admin/media_picker/infinite_scroll.js.erb +4 -4
  102. data/app/views/spina/admin/media_picker/select.js.erb +2 -0
  103. data/app/views/spina/admin/media_picker/show.html.haml +1 -0
  104. data/app/views/spina/admin/media_picker/show.js.erb +1 -1
  105. data/app/views/spina/admin/pages/_form.html.haml +9 -7
  106. data/app/views/spina/admin/pages/_form_advanced.html.haml +19 -17
  107. data/app/views/spina/admin/pages/_form_page_content.html.haml +14 -13
  108. data/app/views/spina/admin/pages/_form_page_seo.html.haml +15 -4
  109. data/app/views/spina/admin/pages/_page.html.haml +5 -3
  110. data/app/views/spina/admin/pages/_page_nested_list.html.haml +2 -3
  111. data/app/views/spina/admin/pages/index.html.haml +5 -4
  112. data/app/views/spina/admin/parts/attachments/_form.html.haml +6 -0
  113. data/app/views/spina/admin/parts/image_collections/_fields.html.haml +7 -0
  114. data/app/views/spina/admin/parts/image_collections/_form.html.haml +12 -0
  115. data/app/views/spina/admin/parts/images/_form.html.haml +18 -0
  116. data/app/views/spina/admin/parts/lines/_form.html.haml +2 -0
  117. data/app/views/spina/admin/parts/multi_lines/_form.html.haml +2 -0
  118. data/app/views/spina/admin/parts/options/_form.html.haml +3 -0
  119. data/app/views/spina/admin/parts/repeaters/_fields.html.haml +15 -0
  120. data/app/views/spina/admin/parts/repeaters/_form.html.haml +17 -0
  121. data/app/views/spina/admin/parts/texts/_form.html.haml +6 -0
  122. data/app/views/spina/admin/resources/edit.html.haml +28 -12
  123. data/app/views/spina/admin/resources/show.html.haml +6 -3
  124. data/app/views/spina/admin/shared/_notifications.html.haml +4 -4
  125. data/config/locales/TH.yml +10 -0
  126. data/config/locales/bg.yml +10 -0
  127. data/config/locales/de.yml +10 -0
  128. data/config/locales/en.yml +10 -0
  129. data/config/locales/es.yml +39 -29
  130. data/config/locales/fr.yml +10 -0
  131. data/config/locales/id.yml +10 -0
  132. data/config/locales/it.yml +10 -0
  133. data/config/locales/nl.yml +10 -0
  134. data/config/locales/pl.yml +24 -14
  135. data/config/locales/pt-BR.yml +10 -0
  136. data/config/locales/ro.yml +10 -0
  137. data/config/locales/ru.yml +10 -0
  138. data/config/locales/sv.yml +10 -0
  139. data/config/locales/tr.yml +10 -0
  140. data/config/locales/zh-CN.yml +10 -0
  141. data/config/routes.rb +13 -0
  142. data/db/migrate/11_create_spina_resources.rb +0 -2
  143. data/db/migrate/12_add_url_title_to_spina_page_translations.rb +5 -0
  144. data/db/migrate/13_add_json_attributes_to_spina_accounts.rb +5 -0
  145. data/db/migrate/14_add_json_attributes_to_spina_pages.rb +5 -0
  146. data/db/migrate/15_add_slug_to_spina_resources.rb +5 -0
  147. data/lib/generators/spina/templates/app/views/demo/pages/demo.html.haml +13 -21
  148. data/lib/generators/spina/templates/app/views/demo/pages/homepage.html.haml +1 -1
  149. data/lib/generators/spina/templates/config/initializers/mobility.rb +13 -4
  150. data/lib/generators/spina/templates/config/initializers/spina.rb +4 -0
  151. data/lib/generators/spina/templates/config/initializers/themes/default.rb +7 -7
  152. data/lib/generators/spina/templates/config/initializers/themes/demo.rb +32 -44
  153. data/lib/spina.rb +18 -3
  154. data/lib/spina/attr_json_spina_parts_model.rb +29 -0
  155. data/lib/spina/engine.rb +14 -6
  156. data/lib/spina/part.rb +19 -0
  157. data/lib/spina/theme.rb +1 -1
  158. data/lib/spina/version.rb +1 -1
  159. data/lib/tasks/spina_tasks.rake +1 -1
  160. data/vendor/assets/javascripts/spina/sortable.js +2 -2
  161. metadata +83 -53
  162. data/app/assets/javascripts/spina/admin/account.coffee +0 -16
  163. data/app/models/concerns/spina/image_collectable.rb +0 -23
  164. data/app/models/concerns/spina/optionable.rb +0 -12
  165. data/app/models/concerns/spina/part.rb +0 -38
  166. data/app/models/spina/attachment_collection.rb +0 -20
  167. data/app/models/spina/image_collection.rb +0 -23
  168. data/app/models/spina/image_collections_image.rb +0 -6
  169. data/app/models/spina/layout_part.rb +0 -22
  170. data/app/models/spina/line.rb +0 -10
  171. data/app/models/spina/option.rb +0 -17
  172. data/app/models/spina/page_part.rb +0 -22
  173. data/app/models/spina/structure.rb +0 -14
  174. data/app/models/spina/structure_item.rb +0 -22
  175. data/app/models/spina/structure_part.rb +0 -20
  176. data/app/models/spina/text.rb +0 -10
  177. data/app/views/dummy/show.html.haml +0 -1
  178. data/app/views/spina/admin/attachments/_attachment_collection.html.haml +0 -2
  179. data/app/views/spina/admin/attachments/_select.html.haml +0 -17
  180. data/app/views/spina/admin/attachments/_select_collection.html.haml +0 -18
  181. data/app/views/spina/admin/attachments/insert.js.erb +0 -5
  182. data/app/views/spina/admin/attachments/insert_collection.js.coffee +0 -7
  183. data/app/views/spina/admin/attachments/select.js.erb +0 -2
  184. data/app/views/spina/admin/attachments/select_collection.js.erb +0 -2
  185. data/app/views/spina/admin/image_collections/_image_collection.html.haml +0 -5
  186. data/app/views/spina/admin/layout_partables/lines/_form.html.haml +0 -2
  187. data/app/views/spina/admin/partables/attachment_collections/_form.html.haml +0 -14
  188. data/app/views/spina/admin/partables/attachments/_form.html.haml +0 -13
  189. data/app/views/spina/admin/partables/image_collections/_form.html.haml +0 -16
  190. data/app/views/spina/admin/partables/images/_form.html.haml +0 -21
  191. data/app/views/spina/admin/partables/lines/_form.html.haml +0 -5
  192. data/app/views/spina/admin/partables/options/_form.html.haml +0 -7
  193. data/app/views/spina/admin/partables/photo_collections/_form.html.haml +0 -4
  194. data/app/views/spina/admin/partables/photos/_form.html.haml +0 -4
  195. data/app/views/spina/admin/partables/structures/_form.html.haml +0 -21
  196. data/app/views/spina/admin/partables/texts/_form.html.haml +0 -8
  197. data/app/views/spina/admin/structure_items/_fields.html.haml +0 -15
  198. data/app/views/spina/admin/structure_partables/attachment_collections/_form.html.haml +0 -14
  199. data/app/views/spina/admin/structure_partables/attachments/_form.html.haml +0 -13
@@ -0,0 +1,26 @@
1
+ module Spina
2
+ module CurrentMethods
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ helper_method :current_theme
7
+ helper_method :current_spina_user
8
+ helper_method :current_account
9
+ end
10
+
11
+ private
12
+
13
+ def current_theme
14
+ @current_theme ||= Spina::Theme.find_by_name(current_account.theme)
15
+ end
16
+
17
+ def current_spina_user
18
+ @current_spina_user ||= Spina::User.where(id: session[:user_id]).first if session[:user_id]
19
+ end
20
+
21
+ def current_account
22
+ @current_account ||= Spina::Account.first
23
+ end
24
+
25
+ end
26
+ end
@@ -4,9 +4,12 @@ module Spina
4
4
 
5
5
  included do
6
6
  rescue_from ActiveRecord::RecordNotFound, with: :redirect_or_render_404
7
+
8
+ helper Spina::PagesHelper
7
9
 
8
10
  before_action :set_locale
9
11
  before_action :set_current_page
12
+ before_action :set_current_account
10
13
  end
11
14
 
12
15
  def show
@@ -27,6 +30,12 @@ module Spina
27
30
 
28
31
  def set_current_page
29
32
  Spina::Current.page = page
33
+ Spina::Current.page.view_context = view_context
34
+ end
35
+
36
+ def set_current_account
37
+ Spina::Current.account = Spina::Account.first
38
+ Spina::Current.account.view_context = view_context
30
39
  end
31
40
 
32
41
  def page_by_locale(locale)
@@ -1,6 +1,7 @@
1
1
  module Spina
2
2
  module Admin
3
3
  class AccountsController < AdminController
4
+ before_action :set_locale
4
5
 
5
6
  def edit
6
7
  add_breadcrumb I18n.t('spina.preferences.account'), spina.edit_admin_account_path
@@ -22,23 +23,18 @@ module Spina
22
23
  def style
23
24
  add_breadcrumb I18n.t('spina.preferences.style'), spina.style_admin_account_path
24
25
  @themes = ::Spina::Theme.all
25
- @layout_parts = current_theme.layout_parts.map { |layout_part| current_account.layout_part(layout_part) }
26
26
  end
27
27
 
28
28
  private
29
29
 
30
- def account_params
31
- params.require(:account).permit(:address, :city, :email, :name, :phone,
32
- :postal_code, :preferences, :google_analytics,
33
- :google_site_verification, :facebook, :twitter, :google_plus,
34
- :instagram, :youtube, :linkedin,
35
- :kvk_identifier, :theme, :vat_identifier, :robots_allowed,
36
- layout_parts_attributes:
37
- [:id, :layout_partable_type, :layout_partable_id,
38
- :name, :title, :position, :content, :page_id,
39
- layout_partable_attributes:
40
- [:content, :photo_tokens, :attachment_tokens, :id]])
41
- end
30
+ def account_params
31
+ params.require(:account).permit!
32
+ end
33
+
34
+ def set_locale
35
+ @locale = params[:locale] || I18n.default_locale
36
+ end
37
+
42
38
  end
43
39
  end
44
40
  end
@@ -1,6 +1,10 @@
1
1
  module Spina
2
2
  module Admin
3
- class AdminController < ::Spina::ApplicationController
3
+ class AdminController < ActionController::Base
4
+ include Spina::CurrentMethods
5
+
6
+ helper Spina::Engine.helpers
7
+
4
8
  before_action :set_admin_locale
5
9
  before_action :authorize_spina_user
6
10
 
@@ -24,28 +24,6 @@ module Spina
24
24
  redirect_to spina.admin_attachments_url
25
25
  end
26
26
 
27
- def select
28
- @selected_attachment_id = Attachment.find_by(id: params[:selected_attachment_id]).try(:id)
29
- @hidden_field_id = params[:hidden_field_id]
30
- @attachments = Attachment.sorted
31
- @attachment = Attachment.new
32
- end
33
-
34
- def insert
35
- @attachment = Attachment.find(params[:attachment_id])
36
- Rails.logger.info "HAHA HA HA #{@attachment.id}"
37
- end
38
-
39
- def select_collection
40
- @selected_attachment_ids = Attachment.where(id: params[:selected_attachment_ids]).ids
41
- @attachments = Attachment.sorted
42
- @attachment = Attachment.new
43
- end
44
-
45
- def insert_collection
46
- @attachments = Attachment.where(id: params[:attachment_ids])
47
- end
48
-
49
27
  private
50
28
 
51
29
  def set_breadcrumbs
@@ -8,7 +8,7 @@ module Spina
8
8
  def index
9
9
  add_breadcrumb I18n.t('spina.website.images'), admin_images_path
10
10
  @media_folders = MediaFolder.order(:name)
11
- @images = Image.sorted.where(media_folder_id: nil).with_attached_file.page(params[:page])
11
+ @images = Image.sorted.where(media_folder_id: nil).with_attached_file.page(params[:page]).per(25)
12
12
  end
13
13
 
14
14
  # There's no file validation yet in ActiveStorage
@@ -2,39 +2,38 @@ module Spina
2
2
  module Admin
3
3
  class MediaPickerController < AdminController
4
4
  before_action :set_media_folders
5
+ before_action :set_selected_images
5
6
 
6
7
  def show
7
- if @media_folder.present?
8
- @images = @media_folder.images.page(params[:page])
9
- else
10
- @images = Image.where(media_folder_id: nil).page(params[:page])
11
- end
8
+ @images = Image.where(media_folder: @media_folder).order(created_at: :desc).page(params[:page]).per(25)
9
+ @mode = params[:mode]
12
10
 
13
- if params[:selected_ids].present?
14
- ids = params[:selected_ids].map(&:to_i).join(', ')
15
- @images = @images.order(Arel.sql("CASE WHEN id IN(#{ids}) THEN 0 ELSE 1 END, created_at DESC"))
16
- else
17
- @images = @images.sorted
11
+ if selected_ids.any?
12
+ @images = @images.reorder(Arel.sql("CASE WHEN id IN(#{selected_ids.join(', ')}) THEN 0 ELSE 1 END, created_at DESC"))
18
13
  end
19
14
 
20
- render params[:page].present? ? :infinite_scroll : :show
21
- end
22
-
23
- def select
24
- if params[:multiple]
25
- @images = Image.where(id: params[:image_ids].split("-"))
26
- else
27
- @image = Image.find(params[:image_id])
15
+ respond_to do |format|
16
+ format.html { render layout: false }
17
+ format.js { render :infinite_scroll if params[:page].present? }
28
18
  end
29
19
  end
30
20
 
31
21
  private
32
22
 
33
23
  def set_media_folders
34
- @media_folders = MediaFolder.order(:name)
24
+ @media_folders = MediaFolder.order(:name).joins(:images).uniq
35
25
  @media_folder = MediaFolder.find(params[:media_folder_id]) if params[:media_folder_id].present?
36
26
  end
37
27
 
28
+ def set_selected_images
29
+ @selected_images = Image.where(id: selected_ids).sort_by{|image| selected_ids.index(image.id)}
30
+ end
31
+
32
+ def selected_ids
33
+ params[:selected_ids].present? ? params[:selected_ids].map(&:to_i) : []
34
+ end
35
+ helper_method :selected_ids
36
+
38
37
  end
39
38
  end
40
39
  end
@@ -8,18 +8,17 @@ module Spina
8
8
  def index
9
9
  add_breadcrumb I18n.t('spina.website.pages'), spina.admin_pages_path
10
10
  redirect_to admin_pages_path unless current_admin_path.starts_with?('/pages')
11
- @pages = Page.active.sorted.roots.regular_pages
11
+ @pages = Page.active.sorted.roots.regular_pages.includes(:translations)
12
12
  end
13
13
 
14
14
  def new
15
15
  @resource = Resource.find_by(id: params[:resource_id])
16
- @page = Page.new(resource: @resource, parent: Page.find_by(id: params[:parent_id]) || @resource&.parent_page)
16
+ @page = Page.new(resource: @resource, parent: Page.find_by(id: params[:parent_id]))
17
17
  add_index_breadcrumb
18
18
  if current_theme.new_page_templates.any? { |template| template[0] == params[:view_template] }
19
19
  @page.view_template = params[:view_template]
20
20
  end
21
21
  add_breadcrumb I18n.t('spina.pages.new')
22
- @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
23
22
  render layout: 'spina/admin/admin'
24
23
  end
25
24
 
@@ -30,7 +29,6 @@ module Spina
30
29
  @page.navigations << Spina::Navigation.where(auto_add_pages: true)
31
30
  redirect_to spina.edit_admin_page_url(@page), flash: {success: t('spina.pages.saved')}
32
31
  else
33
- @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
34
32
  render :new, layout: 'spina/admin/admin'
35
33
  end
36
34
  end
@@ -38,11 +36,10 @@ module Spina
38
36
  def edit
39
37
  add_index_breadcrumb
40
38
  add_breadcrumb @page.title
41
- @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
42
39
  render layout: 'spina/admin/admin'
43
40
  end
44
41
 
45
- def update
42
+ def update
46
43
  respond_to do |format|
47
44
  Mobility.locale = @locale
48
45
  if @page.update(page_params)
@@ -51,7 +48,6 @@ module Spina
51
48
  format.js
52
49
  else
53
50
  format.html do
54
- @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
55
51
  Mobility.locale = I18n.default_locale
56
52
  render :edit, layout: 'spina/admin/admin'
57
53
  end
@@ -1,7 +1,7 @@
1
1
  module Spina
2
2
  module Admin
3
3
  class ResourcesController < AdminController
4
-
4
+ before_action :set_locale
5
5
  before_action :set_resource, only: [:show, :edit, :update]
6
6
 
7
7
  def show
@@ -13,8 +13,8 @@ module Spina
13
13
  add_breadcrumb t('spina.edit')
14
14
  end
15
15
 
16
- def update
17
- if @resource.update(resource_params)
16
+ def update
17
+ if Mobility.with_locale(@locale) { @resource.update(resource_params) }
18
18
  redirect_to spina.admin_resource_path(@resource)
19
19
  else
20
20
  render :edit
@@ -24,12 +24,17 @@ module Spina
24
24
  private
25
25
 
26
26
  def resource_params
27
- params.require(:resource).permit(:label, :view_template, :order_by, :parent_page_id)
27
+ params.require(:resource).permit(:label, :slug, :view_template, :order_by, :parent_page_id)
28
28
  end
29
29
 
30
30
  def set_resource
31
31
  @resource = Resource.find(params[:id])
32
32
  end
33
+
34
+ def set_locale
35
+ @locale = params[:locale] || I18n.default_locale
36
+ end
37
+
33
38
  end
34
39
  end
35
40
  end
@@ -1,24 +1,7 @@
1
- module Spina
2
- class ApplicationController < ActionController::Base
3
-
4
- protect_from_forgery with: :exception
5
-
6
- private
7
-
8
- def current_theme
9
- @current_theme = ::Spina::Theme.find_by_name(current_account.theme)
10
- end
11
- helper_method :current_theme
12
-
13
- def current_spina_user
14
- @current_spina_user ||= ::Spina::User.where(id: session[:user_id]).first if session[:user_id]
15
- end
16
- helper_method :current_spina_user
17
-
18
- def current_account
19
- @current_account ||= ::Spina::Account.first
20
- end
21
- helper_method :current_account
22
-
23
- end
1
+ class Spina::ApplicationController < Spina.frontend_parent_controller.constantize
2
+ include Spina::CurrentMethods
3
+
4
+ helper Spina::Engine.helpers
5
+
6
+ protect_from_forgery with: :exception
24
7
  end
@@ -1,20 +1,18 @@
1
- module Spina
2
- class PagesController < Spina::ApplicationController
3
- include Spina::Frontend
1
+ class Spina::PagesController < Spina::ApplicationController
2
+ include Spina::Frontend
4
3
 
5
- before_action :current_spina_user_can_view_page?, except: [:robots]
4
+ before_action :current_spina_user_can_view_page?, except: [:robots]
6
5
 
7
- helper_method :page
6
+ helper_method :page
8
7
 
9
- def homepage
10
- render_with_template(page)
11
- end
8
+ def homepage
9
+ render_with_template(page)
10
+ end
12
11
 
13
- private
12
+ private
14
13
 
15
- def current_spina_user_can_view_page?
16
- raise ActiveRecord::RecordNotFound unless current_spina_user.present? || page.live?
17
- end
14
+ def current_spina_user_can_view_page?
15
+ raise ActiveRecord::RecordNotFound unless current_spina_user.present? || page.live?
16
+ end
18
17
 
19
- end
20
18
  end
@@ -1,8 +1,8 @@
1
- module Spina
2
- class SitemapsController < Spina::ApplicationController
3
- def show
4
- I18n.locale = I18n.default_locale
5
- @pages = Page.live.sorted
6
- end
1
+ class Spina::SitemapsController < Spina::ApplicationController
2
+
3
+ def show
4
+ I18n.locale = I18n.default_locale
5
+ @pages = Spina::Page.live.sorted
7
6
  end
7
+
8
8
  end
@@ -1,34 +1,36 @@
1
1
  module Spina
2
2
  module Admin
3
3
  module PagesHelper
4
- def link_to_add_structure_item_fields(f, &block)
5
- item = StructureItem.new
6
- fields = f.fields_for(:structure_items, item, child_index: item.object_id) do |builder|
7
- build_structure_parts(f.object.page_part.name, item)
8
- render("spina/admin/structure_items/fields", f: builder)
4
+
5
+ def link_to_add_repeater_fields(f)
6
+ repeater_content = Spina::Parts::RepeaterContent.new(name: f.object.name, title: f.object.title)
7
+ fields = f.fields_for(:content, [repeater_content], child_index: repeater_content.object_id) do |builder|
8
+ render("spina/admin/parts/repeaters/fields", f: builder)
9
9
  end
10
- link_to '#', class: "add_structure_item_fields button button-link", data: {id: item.object_id, fields: fields.gsub("\n", "")} do
10
+ link_to '#', class: "add_structure_item_fields button button-link", data: {id: repeater_content.object_id, fields: fields.gsub("\n", "")} do
11
11
  icon('plus')
12
12
  end
13
13
  end
14
14
 
15
- def build_structure_parts(name, item)
16
- structure = current_theme.structures.find { |structure| structure[:name] == name }
17
- return item.parts unless structure.present?
18
- structure[:structure_parts].map do |attributes|
19
- part = item.parts.where(name: attributes[:name]).first_or_initialize(attributes)
20
- part.partable = part.partable_type.constantize.new if part.partable.blank?
21
- part.options = attributes[:options]
22
- part
15
+ def data_attrs_for_image_collection(f)
16
+ image = Spina::Parts::Image.new
17
+ fields = f.fields_for(:images, [image], child_index: image.object_id) do |builder|
18
+ render("spina/admin/parts/image_collections/fields", f: builder)
23
19
  end
20
+ {fields: fields.gsub("\n", ""), id: image.object_id}
24
21
  end
25
22
 
26
- def partable_partial_namespace(partable)
27
- partable_type_partial_namespace(partable.model_name.to_s)
23
+ def build_parts(partable, parts)
24
+ I18n.with_locale(@locale) do
25
+ parts.map do |part|
26
+ part_attributes = current_theme.parts.find{|p|p[:name].to_s == part.to_s}
27
+ partable.part(part_attributes)
28
+ end
29
+ end
28
30
  end
29
31
 
30
- def partable_type_partial_namespace(partable_type)
31
- partable_type.tableize.sub(/\Aspina\//, '')
32
+ def parts_partial_namespace(part_type)
33
+ part_type.tableize.sub(/\Aspina\/parts\//, '')
32
34
  end
33
35
 
34
36
  def flatten_nested_hash(hash)
@@ -36,14 +38,14 @@ module Spina
36
38
  end
37
39
 
38
40
  def page_ancestry_options(page)
39
- pages = Spina::Page.active.regular_pages
41
+ pages = Spina::Page.active.regular_pages.includes(:translations)
40
42
  pages = pages.where.not(id: page.subtree.ids) unless page.new_record? || !page.methods.include?(:subtree)
41
43
 
42
44
  (flatten_nested_hash(pages.arrange(order: :position)).map do |page|
43
45
  next if page.depth >= Spina.config.max_page_depth - 1
44
46
  page_menu_title = page.depth.zero? ? page.menu_title : " #{page.menu_title}".indent(page.depth, '-')
45
47
  [page_menu_title, page.id]
46
- end << [page.parent&.menu_title, page&.parent_id].compact).uniq.compact
48
+ end << [page.parent&.menu_title, page&.parent_id].compact).map(&:presence).uniq.compact
47
49
  end
48
50
 
49
51
  def option_label(part, value)