locomotivecms 4.0.0.alpha2 → 4.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/Rakefile +14 -6
  4. data/app/api/locomotive/api/forms/site_form.rb +8 -2
  5. data/app/api/locomotive/api/helpers/locales_helper.rb +4 -0
  6. data/app/api/locomotive/api/resources/content_entry_resource.rb +1 -1
  7. data/app/assets/javascripts/locomotive/editor.js +2859 -2561
  8. data/app/assets/javascripts/locomotive/views/content_entries/index_view.js.coffee +4 -1
  9. data/app/assets/javascripts/locomotive/views/current_site/edit_view.js.coffee +6 -0
  10. data/app/assets/javascripts/locomotive/views/shared/bulk_delete_view.js.coffee +27 -0
  11. data/app/assets/javascripts/locomotive/views/translations/index_view.js.coffee +6 -0
  12. data/app/assets/stylesheets/locomotive/application.scss +1 -0
  13. data/app/assets/stylesheets/locomotive/editor.css +119 -113
  14. data/app/assets/stylesheets/locomotive/new/_checkbox.scss +38 -0
  15. data/app/assets/stylesheets/locomotive/old/_activity_feed.scss +10 -0
  16. data/app/assets/stylesheets/locomotive/old/_list.scss +28 -0
  17. data/app/assets/stylesheets/locomotive/old/_main.scss +21 -4
  18. data/app/assets/stylesheets/locomotive/old/_search_bars.scss +2 -5
  19. data/app/assets/stylesheets/locomotive/old/_translations.scss +2 -2
  20. data/app/controllers/locomotive/content_entries_controller.rb +5 -5
  21. data/app/controllers/locomotive/current_site_controller.rb +8 -1
  22. data/app/controllers/locomotive/custom_fields/select_options_controller.rb +1 -1
  23. data/app/controllers/locomotive/editable_elements_controller.rb +1 -1
  24. data/app/controllers/locomotive/page_content_controller.rb +2 -2
  25. data/app/controllers/locomotive/pages_controller.rb +1 -1
  26. data/app/controllers/locomotive/search_for_resources_controller.rb +1 -1
  27. data/app/controllers/locomotive/translations_controller.rb +7 -1
  28. data/app/helpers/locomotive/base_helper.rb +6 -5
  29. data/app/helpers/locomotive/dashboard_helper.rb +18 -6
  30. data/app/helpers/locomotive/page_content_helper.rb +28 -5
  31. data/app/helpers/locomotive/pages_helper.rb +4 -0
  32. data/app/helpers/locomotive/shared/pages_helper.rb +8 -4
  33. data/app/models/locomotive/activity.rb +1 -0
  34. data/app/models/locomotive/concerns/content_entry/file_size.rb +5 -1
  35. data/app/models/locomotive/concerns/content_type/public_submission_title_template.rb +1 -1
  36. data/app/models/locomotive/concerns/page/sections.rb +11 -0
  37. data/app/models/locomotive/concerns/site/url_redirections.rb +11 -1
  38. data/app/policies/locomotive/membership_policy.rb +3 -7
  39. data/app/services/locomotive/content_entry_service.rb +21 -10
  40. data/app/services/locomotive/custom_field_service.rb +28 -4
  41. data/app/services/locomotive/editable_element_service.rb +2 -2
  42. data/app/services/locomotive/editor_service.rb +47 -31
  43. data/app/services/locomotive/page_service.rb +2 -2
  44. data/app/services/locomotive/translation_service.rb +7 -0
  45. data/app/views/locomotive/accounts/new.html.slim +1 -1
  46. data/app/views/locomotive/content_assets/_list.html.slim +5 -0
  47. data/app/views/locomotive/content_assets/_search_form.html.slim +1 -1
  48. data/app/views/locomotive/content_entries/_list.html.slim +3 -3
  49. data/app/views/locomotive/content_entries/edit.html.slim +2 -1
  50. data/app/views/locomotive/content_entries/index.html.slim +53 -40
  51. data/app/views/locomotive/content_entries/new.html.slim +1 -1
  52. data/app/views/locomotive/current_site/edit.html.slim +1 -1
  53. data/app/views/locomotive/current_site/form/_url_redirections.html.slim +4 -0
  54. data/app/views/locomotive/current_site_metafields/index.html.slim +1 -1
  55. data/app/views/locomotive/dashboard/_activity.html.slim +3 -0
  56. data/app/views/locomotive/layouts/application.html.slim +3 -2
  57. data/app/views/locomotive/layouts/editor.html.slim +2 -0
  58. data/app/views/locomotive/memberships/edit.html.slim +1 -1
  59. data/app/views/locomotive/memberships/new.html.slim +1 -1
  60. data/app/views/locomotive/page_content/edit.html.erb +1 -0
  61. data/app/views/locomotive/page_content/edit.json.jbuilder +3 -1
  62. data/app/views/locomotive/pages/_header.html.slim +1 -1
  63. data/app/views/locomotive/pages/form/_main.html.slim +1 -1
  64. data/app/views/locomotive/pages/new.html.slim +1 -1
  65. data/app/views/locomotive/public_submission_accounts/edit.html.slim +1 -1
  66. data/app/views/locomotive/translations/_form.html.slim +0 -3
  67. data/app/views/locomotive/translations/edit.html.slim +1 -1
  68. data/app/views/locomotive/translations/index.html.slim +34 -15
  69. data/config/locales/devise.fr.yml +3 -3
  70. data/config/locales/editor.en.yml +39 -13
  71. data/config/locales/editor.fr.yml +39 -13
  72. data/config/locales/en.yml +4 -0
  73. data/config/locales/flash.en.yml +4 -0
  74. data/config/locales/flash.fr.yml +4 -0
  75. data/config/locales/fr.yml +14 -0
  76. data/config/locales/mongoid.fr.yml +0 -2
  77. data/config/locales/simple_form.en.yml +4 -0
  78. data/config/locales/simple_form.fr.yml +6 -1
  79. data/config/routes.rb +7 -4
  80. data/config/webpack/development.js +26 -0
  81. data/config/webpack/production.js +7 -0
  82. data/config/webpack/test.js +6 -0
  83. data/lib/locomotive/engine.rb +1 -0
  84. data/lib/locomotive/steam/middlewares/page_editing.rb +20 -1
  85. data/lib/locomotive/steam/services/api_entry_submission_service.rb +6 -6
  86. data/lib/locomotive/version.rb +1 -1
  87. metadata +9 -32
@@ -3,6 +3,33 @@
3
3
  color: $paragraph_color;
4
4
  }
5
5
 
6
+ .list-groups {
7
+ margin-bottom: 10px;
8
+
9
+ .nav-tabs {
10
+ padding-left: 15px;
11
+ padding-right: 15px;
12
+ }
13
+ }
14
+
15
+ .list-header {
16
+
17
+ .col {
18
+ display: flex;
19
+ flex-direction: column;
20
+ padding-bottom: 1rem;
21
+
22
+ &:first-child {
23
+ align-items: flex-start;
24
+ }
25
+
26
+ &:last-child {
27
+ align-items: flex-end;
28
+ padding-top: 4px;
29
+ }
30
+ }
31
+ }
32
+
6
33
  .big-list {
7
34
  .item {
8
35
  position: relative;
@@ -74,6 +101,7 @@
74
101
  .actions {
75
102
  position: relative;
76
103
  margin-left: auto;
104
+ font-size: 0; /* remove empty space */
77
105
 
78
106
  i {
79
107
  font-size: 16px;
@@ -11,14 +11,31 @@
11
11
  color: $main_title_color;
12
12
  }
13
13
 
14
+ .text {
15
+ margin: 0.8rem 0 0 0;
16
+ color: rgba($main_title_color, 0.7);
17
+ }
18
+
14
19
  .actions {
15
20
  text-align: right;
16
- p {
17
- margin: 0;
18
- }
19
21
 
20
- a {
22
+ & > a, & > div {
21
23
  margin-left: 5px;
24
+ display: inline-block;
25
+ }
26
+
27
+ .btn > i {
28
+ margin-right: 0.5rem;
29
+ }
30
+
31
+ .btn.dropdown-toggle {
32
+ border-left: 1px solid $btn-primary-border;
33
+ }
34
+
35
+ .dropdown-menu {
36
+ i {
37
+ margin-right: 1rem;
38
+ }
22
39
  }
23
40
  }
24
41
  }
@@ -1,13 +1,9 @@
1
1
  .search-bar {
2
- text-align: right;
3
-
4
2
  form {
5
3
  display: inline-block;
6
4
 
7
5
  .form-group {
8
- position: relative;
9
- top: -6px;
10
- padding: 4px 6px;
6
+ padding: 0.5rem 0.9rem;
11
7
  margin-bottom: 0;
12
8
  border: 1px solid #dadada;
13
9
 
@@ -24,6 +20,7 @@
24
20
  .icon {
25
21
  display: inline-block;
26
22
  color: $nav-tabs-link-color;
23
+ margin-right: 0.8rem;
27
24
  }
28
25
  }
29
26
  }
@@ -1,8 +1,8 @@
1
1
  #translations-list {
2
2
 
3
3
  .item {
4
- &:first-child {
5
- border-top: none;
4
+ & > .status {
5
+ margin-right: 1.5rem;
6
6
  }
7
7
 
8
8
  &.zero-done .completion i { color: $brand-danger; }
@@ -72,10 +72,10 @@ module Locomotive
72
72
  respond_with @content_type, location: content_entries_path(current_site, @content_type.slug)
73
73
  end
74
74
 
75
- def destroy
76
- authorize @content_entry
77
- service.destroy(@content_entry)
78
- respond_with @content_entry, location: content_entries_path(current_site, @content_type.slug)
75
+ def bulk_destroy
76
+ authorize ContentEntry, :destroy?
77
+ service.bulk_destroy(params[:ids].split(','))
78
+ respond_with @content_type, location: content_entries_path(current_site, @content_type.slug, page: params[:page], q: params[:q])
79
79
  end
80
80
 
81
81
  private
@@ -89,7 +89,7 @@ module Locomotive
89
89
  end
90
90
 
91
91
  def service
92
- @service ||= Locomotive::ContentEntryService.new(load_content_type, current_locomotive_account)
92
+ @service ||= Locomotive::ContentEntryService.new(load_content_type, current_locomotive_account, current_content_locale)
93
93
  end
94
94
 
95
95
  def list_params
@@ -20,6 +20,7 @@ module Locomotive
20
20
  def update
21
21
  authorize @site
22
22
  service.update(@site, site_params)
23
+ logger.debug @site.errors.inspect
23
24
  respond_with @site, location: -> { edit_current_site_path(current_site) }
24
25
  end
25
26
 
@@ -63,7 +64,13 @@ module Locomotive
63
64
  end
64
65
 
65
66
  def site_params
66
- params.require(:site).permit(*policy(@site || Site).permitted_attributes)
67
+ params.require(:site).permit(*policy(@site || Site).permitted_attributes).tap do |_params|
68
+ if params[:site][:url_redirections_expert_mode] == '1'
69
+ _params[:url_redirections] = params[:site][:url_redirections_plain_text]
70
+ .split("\n")
71
+ .map { |line| line.split(/\s+/) }
72
+ end
73
+ end
67
74
  end
68
75
 
69
76
  def service
@@ -38,7 +38,7 @@ module Locomotive
38
38
  end
39
39
 
40
40
  def service
41
- @service ||= Locomotive::CustomFieldService.new(@custom_field)
41
+ @service ||= Locomotive::CustomFieldService.new(@custom_field, current_content_locale)
42
42
  end
43
43
 
44
44
  def options_params
@@ -65,7 +65,7 @@ module Locomotive
65
65
  end
66
66
 
67
67
  def persisting_service
68
- @persisting_service ||= Locomotive::EditableElementService.new(current_site, current_locomotive_account)
68
+ @persisting_service ||= Locomotive::EditableElementService.new(current_site, current_locomotive_account, current_content_locale)
69
69
  end
70
70
 
71
71
  def store_location_if_content_entry
@@ -12,7 +12,7 @@ module Locomotive
12
12
 
13
13
  respond_to :json, only: [:edit, :update]
14
14
 
15
- helper Locomotive::ContentEntriesHelper
15
+ helper Locomotive::ContentEntriesHelper, Locomotive::PagesHelper
16
16
 
17
17
  def edit
18
18
  authorize @page
@@ -56,7 +56,7 @@ module Locomotive
56
56
  end
57
57
 
58
58
  def persisting_service
59
- @persisting_service ||= Locomotive::EditorService.new(current_site, current_locomotive_account, @page)
59
+ @persisting_service ||= Locomotive::EditorService.new(current_site, current_locomotive_account, @page, current_content_locale)
60
60
  end
61
61
 
62
62
  def editable_elements_layout
@@ -58,7 +58,7 @@ module Locomotive
58
58
  end
59
59
 
60
60
  def service
61
- @service ||= Locomotive::PageService.new(current_site, current_locomotive_account)
61
+ @service ||= Locomotive::PageService.new(current_site, current_locomotive_account, current_content_locale)
62
62
  end
63
63
 
64
64
  def edit_content_path(page)
@@ -6,7 +6,7 @@ module Locomotive
6
6
  respond_to :json, only: [:index]
7
7
 
8
8
  def index
9
- resources = service.find_resources(params[:q])
9
+ resources = service.find_resources(params[:type], params[:q], params[:scope])
10
10
  respond_with resources
11
11
  end
12
12
 
@@ -24,6 +24,12 @@ module Locomotive
24
24
  respond_with @translation, location: translations_path(current_site, translation_nav_params)
25
25
  end
26
26
 
27
+ def bulk_destroy
28
+ authorize Translation, :destroy?
29
+ service.bulk_destroy(params[:ids].split(','))
30
+ respond_with current_site, location: translations_path(current_site, translation_nav_params)
31
+ end
32
+
27
33
  protected
28
34
 
29
35
  def load_translation
@@ -35,7 +41,7 @@ module Locomotive
35
41
  end
36
42
 
37
43
  def translation_nav_params
38
- params[:_location].permit(:filter_by, :q)
44
+ params.permit(:filter_by, :q, :page, :per_page)
39
45
  end
40
46
 
41
47
  def service
@@ -29,10 +29,11 @@ module Locomotive
29
29
  end
30
30
  end
31
31
 
32
- def help(text)
33
- if text.present?
34
- content_tag :p, text, class: 'text'
32
+ def help(text = nil)
33
+ if text.nil?
34
+ @content_for_help
35
35
  else
36
+ @content_for_help = content_tag(:p, text, class: 'text')
36
37
  ''
37
38
  end
38
39
  end
@@ -295,10 +296,10 @@ module Locomotive
295
296
  )
296
297
  end
297
298
 
298
- def decorated_steam_page(page)
299
+ def decorated_steam_page(page, locale = nil)
299
300
  Locomotive::Steam::Decorators::PageDecorator.new(
300
301
  page.to_steam,
301
- current_content_locale,
302
+ locale || current_content_locale,
302
303
  current_site.default_locale
303
304
  )
304
305
  end
@@ -5,7 +5,8 @@ module Locomotive
5
5
  if current_site.domains.blank?
6
6
  preview_url(current_site)
7
7
  else
8
- URI.join('http://' + current_site.domains.first).tap do |uri|
8
+ protocol = current_site.redirect_to_https? ? 'https' : 'http'
9
+ URI.join("#{protocol}://" + current_site.domains.first).tap do |uri|
9
10
  uri.port = request.port if request.port != 80 && request.port != 443
10
11
  end.to_s
11
12
  end
@@ -17,6 +18,7 @@ module Locomotive
17
18
  case activity.domain
18
19
  when 'site' then 'fa-cog'
19
20
  when 'page' then 'fa-file-alt'
21
+ when 'page_content' then 'fa-file-alt'
20
22
  when 'editable_element' then 'fa-file-alt'
21
23
  when 'content_entry' then activity.action == 'created_public' ? 'fa-comment' : 'fa-archive'
22
24
  when 'content_asset' then 'fa-image'
@@ -27,13 +29,15 @@ module Locomotive
27
29
 
28
30
  def render_activity_sentence(activity)
29
31
  params = activity.parameters
32
+ locale = activity.locale
30
33
 
31
34
  options = case activity.key
32
35
  when /\Apage\./ then activity_page_options(params)
33
- when /\Acontent_entry\./ then activity_content_entry_options(params)
36
+ when /\Acontent_entry\./ then activity_content_entry_options(params, locale)
37
+ when 'page_content.updated' then activity_page_content_options(params, locale)
34
38
  when 'editable_element.updated_bulk' then activity_bulk_editable_elements_options(params)
35
39
  when 'content_asset.created_bulk' then { count: activity_emphasize(params[:assets].size) }
36
- when 'content_asset.destroyed' then { name: activity_emphasize(params[:name]) }
40
+ when 'content_asset.destroyed' then { name: activity_emphasize(params[:name]) }
37
41
  when 'membership.created' then { name: activity_emphasize(params[:name]) }
38
42
  when 'site_metafields.updated' then { label: current_site_metafields_ui[:label].downcase }
39
43
  end
@@ -67,19 +71,27 @@ module Locomotive
67
71
  end
68
72
  end
69
73
 
74
+ def activity_page_content_options(params, locale)
75
+ path = edit_page_content_path(current_site, params[:_id], content_locale: locale)
76
+ { page: link_to(truncate(params[:title]), path).html_safe }
77
+ end
78
+
70
79
  def activity_bulk_editable_elements_options(params)
71
80
  pages = params[:pages].map do |page|
72
- link_to truncate(page[:title]), editable_elements_path(current_site, page[:_id])
81
+ link_to truncate(page[:title]), editable_elements_path(current_site, page[:_id])
73
82
  end.join(', ').html_safe
74
83
 
75
84
  { pages: pages }
76
85
  end
77
86
 
78
- def activity_content_entry_options(params)
87
+ def activity_content_entry_options(params, locale)
79
88
  entry = if params[:_id]
80
- link_to(params[:label], edit_content_entry_path(current_site, params[:content_type_slug], params[:_id]))
89
+ path = edit_content_entry_path(current_site, params[:content_type_slug], params[:_id], content_locale: locale)
90
+ link_to(params[:label], path)
81
91
  elsif params[:label]
82
92
  activity_emphasize(params[:label])
93
+ elsif params[:labels]
94
+ activity_emphasize(params[:labels].join(', '))
83
95
  else
84
96
  nil
85
97
  end
@@ -3,6 +3,29 @@ require 'digest'
3
3
  module Locomotive
4
4
  module PageContentHelper
5
5
 
6
+ def content_types_with_templates(site)
7
+ site.content_types.order_by(title: 1).map do |content_type|
8
+ pages = site.pages
9
+ .only(:_id, :site_id, :title, :target_klass_name, :sections_dropzone_content, :sections_content)
10
+ .where(target_klass_name: content_type.entries_class_name)
11
+ .map do |page|
12
+ {
13
+ id: page._id,
14
+ title: page.title,
15
+ sections: page.all_sections_content
16
+ }
17
+ end
18
+
19
+ next if pages.empty?
20
+
21
+ {
22
+ name: content_type.name,
23
+ slug: content_type.slug,
24
+ pages: pages
25
+ }
26
+ end.compact
27
+ end
28
+
6
29
  def sections_content(model, sections, definitions)
7
30
  source = model.respond_to?(:title) ? :page : :site
8
31
  content = model.sections_content || {}
@@ -16,14 +39,14 @@ module Locomotive
16
39
  if content[key].blank?
17
40
  definition = definitions.find { |definition| definition['type'] == type } || {}
18
41
 
19
- content[key] = definition['default'] || { 'settings' => {}, 'blocks' => [], 'type' => type }
42
+ content[key] = definition['default'] || { 'settings' => {}, 'blocks' => [] }
20
43
  else
21
- content[key]['type'] = type
22
44
  content[key]['settings'] ||= {}
23
45
  content[key]['blocks'] ||= []
24
46
  end
25
47
 
26
- content[key]['id'] = attributes[:id] # FIXME: attributes[:id] => section domId
48
+ content[key]['id'] = attributes[:id] # FIXME: attributes[:id] => section domId
49
+ content[key]['type'] = type # make sure there is always the type attribute
27
50
 
28
51
  # reset block id
29
52
  content[key]['blocks'] = (content[key]['blocks'] || []).each_with_index.map do |block, index|
@@ -36,7 +59,7 @@ module Locomotive
36
59
  end
37
60
 
38
61
  def sections_dropzone_content(page)
39
- (page.sections_dropzone_content || {}).each_with_index.map do |section, index|
62
+ (page.sections_dropzone_content || []).each_with_index.map do |section, index|
40
63
  section['id'] = "dropzone-#{index}"
41
64
 
42
65
  # FIXME: sections content deployed with Wagon might have no blocks (nil)
@@ -57,7 +80,7 @@ module Locomotive
57
80
  ids[attributes[:uuid]] = attributes
58
81
  end
59
82
 
60
- (page.sections_dropzone_content || {}).each_with_index do |section, index|
83
+ (page.sections_dropzone_content || []).each_with_index do |section, index|
61
84
  id = "dropzone-#{index}"
62
85
  uuid = Digest::MD5.hexdigest(id)
63
86
 
@@ -25,6 +25,10 @@ module Locomotive
25
25
  list
26
26
  end
27
27
 
28
+ def display_slug?(page)
29
+ !page.index? && !page.not_found? && (!page.templatized? || page.templatized_from_parent?)
30
+ end
31
+
28
32
  def display_page_layouts?
29
33
  ((@page.persisted? && @page.allow_layout? && @page.use_layout?) || !@page.persisted?) &&
30
34
  !current_site.pages.layouts.empty?
@@ -10,9 +10,9 @@ module Locomotive
10
10
  truncate(path, length: 50)
11
11
  end
12
12
 
13
- def preview_page_path(page, locale: nil, mounted_on: false)
13
+ def preview_page_path(page, locale: nil, mounted_on: false, prefix_default_locale: nil)
14
14
  locale = locale || current_content_locale.to_s
15
- _page = decorated_steam_page(page)
15
+ _page = decorated_steam_page(page, locale)
16
16
 
17
17
  if page.content_entry
18
18
  _page.content_entry = decorated_steam_content_entry(page.content_entry)
@@ -20,12 +20,16 @@ module Locomotive
20
20
 
21
21
  steam_url_builder.mounted_on = mounted_on ? preview_path(current_site) : nil
22
22
 
23
- steam_url_builder.url_for(_page, locale)
23
+ steam_url_builder.url_for(_page, locale, prefix_default_locale)
24
24
  end
25
25
 
26
26
  def localized_preview_page_paths(page, mounted_on: false)
27
27
  current_site.locales.inject({}) do |memo, locale|
28
- memo[locale] = preview_page_path(page, locale: locale, mounted_on: mounted_on)
28
+ memo[locale] = preview_page_path(page,
29
+ locale: locale,
30
+ mounted_on: mounted_on,
31
+ prefix_default_locale: true
32
+ )
29
33
  memo
30
34
  end
31
35
  end
@@ -6,6 +6,7 @@ module Locomotive
6
6
  ## fields ##
7
7
  field :key
8
8
  field :parameters, type: Hash
9
+ field :locale
9
10
 
10
11
  ## associations ##
11
12
  belongs_to :site, class_name: 'Locomotive::Site', validate: false, autosave: false