locomotivecms 3.0.0.pre.alpha → 3.0.0.pre.alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/app/api/locomotive/api/entities/site_entity.rb +4 -0
  3. data/app/api/locomotive/api/forms/site_form.rb +1 -1
  4. data/app/api/locomotive/api/resources/site_resource.rb +2 -0
  5. data/app/assets/javascripts/locomotive/utils/notify.js.coffee +13 -0
  6. data/app/assets/javascripts/locomotive/views/application_view.js.coffee +1 -1
  7. data/app/assets/javascripts/locomotive/views/content_assets/dropzone_view.js.coffee +1 -1
  8. data/app/assets/javascripts/locomotive/views/content_assets/edit_image_view.js.coffee +4 -2
  9. data/app/assets/javascripts/locomotive/views/pages/_form_view.js.coffee +14 -4
  10. data/app/assets/javascripts/locomotive/views/pages/edit_view.js.coffee +1 -1
  11. data/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee +2 -4
  12. data/app/assets/stylesheets/locomotive/components/_misc.scss +2 -1
  13. data/app/assets/stylesheets/locomotive/components/misc/_notify.scss +27 -0
  14. data/app/assets/stylesheets/locomotive/components/sidebar/_pages_tree.scss +1 -1
  15. data/app/controllers/locomotive/pages_controller.rb +6 -8
  16. data/app/helpers/locomotive/base_helper.rb +2 -3
  17. data/app/helpers/locomotive/custom_fields_helper.rb +2 -2
  18. data/app/helpers/locomotive/pages_helper.rb +17 -16
  19. data/app/helpers/locomotive/shared/pages_helper.rb +2 -2
  20. data/app/models/locomotive/concerns/page/layout.rb +4 -0
  21. data/app/models/locomotive/page.rb +2 -3
  22. data/app/models/locomotive/site.rb +0 -4
  23. data/app/services/locomotive/content_entry_service.rb +1 -0
  24. data/app/services/locomotive/page_service.rb +23 -51
  25. data/app/services/locomotive/page_tree_service.rb +64 -0
  26. data/app/views/locomotive/accounts/new.html.haml +2 -1
  27. data/app/views/locomotive/current_site/form/_main.html.haml +1 -1
  28. data/app/views/locomotive/custom_fields/select_options/edit.html.haml +1 -1
  29. data/app/views/locomotive/memberships/new.html.haml +1 -1
  30. data/app/views/locomotive/my_account/form/_actions.html.haml +1 -6
  31. data/app/views/locomotive/my_account/form/_main.html.haml +1 -1
  32. data/app/views/locomotive/pages/form/_main.html.haml +17 -3
  33. data/app/views/locomotive/pages/form/_tabs.html.haml +3 -5
  34. data/app/views/locomotive/pages/new.html.haml +8 -11
  35. data/app/views/locomotive/shared/_sidebar.html.haml +3 -0
  36. data/app/views/locomotive/shared/_sidebar_without_site.html.haml +2 -0
  37. data/app/views/locomotive/shared/header/_account_menu.html.haml +1 -1
  38. data/app/views/locomotive/shared/sidebar/_link.html.haml +1 -1
  39. data/app/views/locomotive/shared/sidebar/_my_account.html.haml +1 -1
  40. data/app/views/locomotive/shared/sidebar/_page.html.haml +6 -1
  41. data/app/views/locomotive/shared/sidebar/_pages.html.haml +1 -1
  42. data/app/views/locomotive/sites/new.html.haml +1 -1
  43. data/config/locales/admin_ui.en.yml +6 -16
  44. data/lib/locomotive/simple_form.rb +2 -2
  45. data/lib/locomotive/version.rb +4 -1
  46. data/spec/models/locomotive/concerns/page/layout_spec.rb +26 -0
  47. data/vendor/assets/javascripts/locomotive/bootstrap-notify.js +2 -0
  48. data/vendor/assets/javascripts/locomotive/resizeImage.js +0 -2
  49. metadata +10 -9
  50. data/app/views/locomotive/pages/_form.html.haml +0 -66
  51. data/app/views/locomotive/pages/_page.html.haml +0 -44
  52. data/vendor/assets/javascripts/locomotive/bootstrap-growl.js +0 -312
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13af7d4674ae2e9a78c3f0c28ba9b0c6eab430b5
4
- data.tar.gz: cbc17a9c176e8a2df21dc8f7c7545eb3ae3e4192
3
+ metadata.gz: 10adf1633c36bc535a1fee5de2d222f04b412144
4
+ data.tar.gz: 941c8279d7f786e77f16a659745c9d3c74166172
5
5
  SHA512:
6
- metadata.gz: 9c5c7319dda26005c0b70f6179cbd1ddd2402083feea05428c498c8c0255e9da5bb51a0b124cc032ff647cad11f465260ae721269b0c50a95c0f4e5b7da90ae2
7
- data.tar.gz: 371622004666f61268c538b2eef46b89355c5fc08d945adc21900784533442c21c2bbc89ed1c41096aa0da0085ffd9a44544cf0d7a1a0b3ec31dcc3fad4babfd
6
+ metadata.gz: b1023a316c88d96e7eb64e5b77c88027e1071f9b536fdd59d8db139a85f86160c44b8245f70829bd1fa8a91241dcc9bf4b6d87d10d9ad17298a99b11277367e3
7
+ data.tar.gz: bfd4756b7844f6013e639960b21a4ce8461a32b2c9af5cb6332d8a40abdf93eb294435975523a5d78173c491a7b9d120948e21f58b74fec81261235e7d58ec4d
@@ -15,6 +15,10 @@ module Locomotive
15
15
  site.timezone_name
16
16
  end
17
17
 
18
+ expose :picture_url do |site, _|
19
+ site.picture.url
20
+ end
21
+
18
22
  end
19
23
 
20
24
  end
@@ -4,7 +4,7 @@ module Locomotive
4
4
 
5
5
  class SiteForm < BaseForm
6
6
 
7
- attrs :name, :handle, :robots_txt, :locales, :domains, :timezone
7
+ attrs :name, :handle, :robots_txt, :locales, :domains, :timezone, :picture
8
8
 
9
9
  attrs :seo_title, :meta_keywords, :meta_description, localized: true
10
10
 
@@ -64,6 +64,7 @@ module Locomotive
64
64
  optional :locales, type: Array
65
65
  optional :domains, type: Array
66
66
  optional :timezone
67
+ optional :picture
67
68
  end
68
69
  end
69
70
  post do
@@ -88,6 +89,7 @@ module Locomotive
88
89
  optional :locales, type: Array
89
90
  optional :domains, type: Array
90
91
  optional :timezone
92
+ optional :picture
91
93
  end
92
94
  end
93
95
  put ':id' do
@@ -0,0 +1,13 @@
1
+ Locomotive.notify = (message, type) ->
2
+ icon = if type == 'danger'
3
+ 'exclamation-triangle'
4
+ else if type == 'success'
5
+ 'check'
6
+ else
7
+ 'exclamation-circle'
8
+
9
+ $.notify { message: message, icon: "fa fa-#{icon}" },
10
+ type: type
11
+ placement:
12
+ from: 'bottom'
13
+ align: 'right'
@@ -32,7 +32,7 @@ class Locomotive.Views.ApplicationView extends Backbone.View
32
32
 
33
33
  render_flash_messages: (messages) ->
34
34
  _.each messages, (couple) ->
35
- $.growl couple[1], { type: couple[0] }
35
+ Locomotive.notify couple[1], couple[0]
36
36
 
37
37
  automatic_max_height: ->
38
38
  $(window).on 'resize', => @set_max_height()
@@ -38,7 +38,7 @@ class Locomotive.Views.ContentAssets.DropzoneView extends Backbone.View
38
38
  form_data = new FormData()
39
39
 
40
40
  _.each event.target.files || event.originalEvent.dataTransfer.files, (file, i) ->
41
- form_data.append("content_assets[#{i}][source]", file)
41
+ form_data.append("content_assets[][source]", file)
42
42
 
43
43
  @upload_files(form_data)
44
44
 
@@ -21,7 +21,8 @@ class Locomotive.Views.ContentAssets.EditImageView extends Backbone.View
21
21
  @create_resize_popover()
22
22
 
23
23
  create_cropper: ->
24
- @$cropper = @$('.image-container > img')
24
+ @$cropper = @$('.image-container > img')
25
+ @cropper_enabled = false
25
26
 
26
27
  @set_cropper_height()
27
28
  @$cropper.cropper
@@ -84,6 +85,7 @@ class Locomotive.Views.ContentAssets.EditImageView extends Backbone.View
84
85
  .then (image) =>
85
86
  @width = width
86
87
  @height = height
88
+ @cropper_enabled = true
87
89
  @$cropper.cropper('replace', image.src)
88
90
  @set_cropper_height()
89
91
  $btn.button('reset')
@@ -99,7 +101,7 @@ class Locomotive.Views.ContentAssets.EditImageView extends Backbone.View
99
101
  return unless @cropper_enabled
100
102
 
101
103
  $link = $(event.target).closest('.apply-btn')
102
- image_url = @$cropper.cropper('getDataURL')
104
+ image_url = @$cropper.cropper('getDataURL') || @$cropper.attr('src')
103
105
  blob = window.dataURLtoBlob(image_url)
104
106
 
105
107
  form_data = new FormData()
@@ -1,10 +1,20 @@
1
- # #= require ../shared/form_view
1
+ #= require ../shared/form_view
2
2
 
3
- # Locomotive.Views.Pages ||= {}
3
+ Locomotive.Views.Pages ||= {}
4
+
5
+ class Locomotive.Views.Pages.FormView extends Locomotive.Views.Shared.FormView
6
+
7
+ el: '#content'
8
+
9
+ initialize: ->
10
+ @attach_events_on_redirect_attribute()
11
+
12
+ attach_events_on_redirect_attribute: ->
13
+ @$('#page_redirect').on 'switchChange.bootstrapSwitch', (event, state) ->
14
+ $inputs = $('.locomotive_page_redirect_url, .locomotive_page_redirect_type')
15
+ $inputs.toggleClass('hide')
4
16
 
5
- # class Locomotive.Views.Pages.FormView extends Locomotive.Views.Shared.FormView
6
17
 
7
- # el: '#content'
8
18
 
9
19
  # events:
10
20
  # 'change #page_parent_id': 'change_page_url'
@@ -2,7 +2,7 @@
2
2
 
3
3
  Locomotive.Views.Pages ||= {}
4
4
 
5
- class Locomotive.Views.Pages.EditView extends Locomotive.Views.Shared.FormView
5
+ class Locomotive.Views.Pages.EditView extends Locomotive.Views.Pages.FormView
6
6
 
7
7
  el: '.main'
8
8
 
@@ -70,10 +70,8 @@ class Locomotive.Views.Pages.ListView extends Backbone.View
70
70
  error: @.on_failed_sort
71
71
 
72
72
  on_successful_sort: (data, status, xhr) ->
73
- $.growl decodeURIComponent($.parseJSON(xhr.getResponseHeader('X-Message'))),
74
- type: 'success'
73
+ Locomotive.notify decodeURIComponent($.parseJSON(xhr.getResponseHeader('X-Message'))), 'success'
75
74
 
76
75
  on_failed_sort: (data, status, xhr) ->
77
- $.growl decodeURIComponent($.parseJSON(xhr.getResponseHeader('X-Message'))),
78
- type: 'error'
76
+ Locomotive.notify decodeURIComponent($.parseJSON(xhr.getResponseHeader('X-Message'))), 'error'
79
77
 
@@ -1 +1,2 @@
1
- @import "misc/nav";
1
+ @import "misc/nav";
2
+ @import "misc/notify";
@@ -0,0 +1,27 @@
1
+ [data-notify="container"] {
2
+ border: none;
3
+
4
+ [data-notify="icon"] {
5
+ font-size: 18px;
6
+ margin-right: 9px;
7
+ color: #fff;
8
+ }
9
+
10
+ [data-notify="message"] {
11
+ color: #fff;
12
+ }
13
+ }
14
+
15
+ [data-notify="container"].alert-success {
16
+ background-color: $brand-success;
17
+ }
18
+
19
+ [data-notify="container"].alert-danger {
20
+ background-color: $brand-danger;
21
+ }
22
+
23
+ [data-notify="container"].alert-info {
24
+ [data-notify="icon"], [data-notify="message"] {
25
+ color: $state-info-text;
26
+ }
27
+ }
@@ -74,7 +74,7 @@ $pt_warning_color: #F89406;
74
74
  &.folded .folded, &.unfolded .unfolded { display: inline; }
75
75
  }
76
76
 
77
- &.new-content {
77
+ &.new-entry, &.list-entries, &.new-page {
78
78
  a {
79
79
  margin-left: 1px;
80
80
  color: $pt_new_link_color;
@@ -11,12 +11,6 @@ module Locomotive
11
11
 
12
12
  respond_to :json, only: [:sort]
13
13
 
14
- def index
15
- authorize Page
16
- @pages = current_site.all_pages_in_once
17
- respond_with(@pages)
18
- end
19
-
20
14
  def new
21
15
  authorize Page
22
16
  @page = current_site.pages.build
@@ -25,7 +19,7 @@ module Locomotive
25
19
 
26
20
  def create
27
21
  authorize Page
28
- @page = current_site.pages.create(page_params)
22
+ @page = service.create(page_params)
29
23
  respond_with @page, location: -> { edit_page_path(current_site, @page) }
30
24
  end
31
25
 
@@ -36,7 +30,7 @@ module Locomotive
36
30
 
37
31
  def update
38
32
  authorize @page
39
- @page.update_attributes(page_params)
33
+ service.update(@page, page_params)
40
34
  respond_with @page, location: edit_page_path(current_site, @page)
41
35
  end
42
36
 
@@ -62,5 +56,9 @@ module Locomotive
62
56
  params.require(:page).permit(:title, :parent_id, :listed, :published)
63
57
  end
64
58
 
59
+ def service
60
+ @service ||= Locomotive::PageService.new(current_site)
61
+ end
62
+
65
63
  end
66
64
  end
@@ -125,9 +125,8 @@ module Locomotive
125
125
 
126
126
  def flash_key_to_bootstrap_alert(key)
127
127
  case key.to_sym
128
- when :notice then :success
129
- when :alert then :info
130
- when :error then :warning
128
+ when :notice then :success
129
+ when :alert, :error then :danger
131
130
  else
132
131
  :info
133
132
  end
@@ -50,8 +50,8 @@ module Locomotive
50
50
  name: field.name,
51
51
  label: label_for_custom_field(form.object, field),
52
52
  hint: field.hint,
53
- wrapper_html: {
54
- class: "#{'highlighted' if highlighted}"
53
+ input_html: {
54
+ class: "#{'input-lg' if highlighted}"
55
55
  }
56
56
  }
57
57
  end
@@ -25,17 +25,17 @@ module Locomotive
25
25
  list
26
26
  end
27
27
 
28
- # def display_page_layouts?
29
- # ((@page.persisted? && @page.allow_layout?) || !@page.persisted?) &&
30
- # !current_site.pages.layouts.empty?
31
- # end
28
+ def display_page_layouts?
29
+ ((@page.persisted? && @page.allow_layout?) || !@page.persisted?) &&
30
+ !current_site.pages.layouts.empty?
31
+ end
32
32
 
33
- # def options_for_page_layouts
34
- # layouts = current_site.pages.layouts.map do |_layout|
35
- # [_layout.title, _layout._id]
36
- # end
37
- # [[t('.no_layout'), nil]] + layouts
38
- # end
33
+ def options_for_page_layouts
34
+ layouts = current_site.pages.layouts.map do |_layout|
35
+ [_layout.title, _layout._id]
36
+ end
37
+ [[t(:no_layout, scope: 'locomotive.pages.form'), nil]] + layouts
38
+ end
39
39
 
40
40
  # def options_for_page_response_type
41
41
  # [
@@ -46,12 +46,13 @@ module Locomotive
46
46
  # ]
47
47
  # end
48
48
 
49
- # def options_for_page_redirect_type
50
- # [
51
- # [t('.redirect_type.permanent'), 301],
52
- # [t('.redirect_type.temporary'), 302]
53
- # ]
54
- # end
49
+ def options_for_page_redirect_type
50
+ puts t('.redirect_type.permanent').inspect
51
+ [
52
+ [t('.redirect_type.permanent'), 301],
53
+ [t('.redirect_type.temporary'), 302]
54
+ ]
55
+ end
55
56
 
56
57
  # def page_response_type_to_string(page)
57
58
  # options_for_page_response_type.detect { |t| t.last == page.response_type }.try(:first) || '&mdash;'
@@ -10,7 +10,7 @@ module Locomotive
10
10
  end
11
11
 
12
12
  def build_page_tree
13
- @page_tree ||= Locomotive::PageService.new(current_site).build_tree
13
+ @page_tree ||= Locomotive::PageTreeService.new(current_site).build_tree
14
14
  end
15
15
 
16
16
  class Node < Struct.new(:page, :children, :controller)
@@ -20,7 +20,7 @@ module Locomotive
20
20
  def_delegators :page, :_id, :title, :index_or_not_found?, :published?, :templatized?, :translated?, :redirect?, :response_type
21
21
 
22
22
  def fold_state
23
- controller.send(:cookies)["node-#{_id}"] != 'folded' ? 'unfolded' : 'folded'
23
+ controller.send(:cookies)["node-#{_id}"] != 'unfolded' ? 'folded' : 'unfolded'
24
24
  end
25
25
 
26
26
  def nodes
@@ -23,6 +23,10 @@ module Locomotive
23
23
 
24
24
  end
25
25
 
26
+ def is_layout_or_related?
27
+ !(self.fullpath =~ /^layouts($|\/)/).nil?
28
+ end
29
+
26
30
  private
27
31
 
28
32
  def set_default_raw_template_if_layout
@@ -3,19 +3,18 @@ module Locomotive
3
3
 
4
4
  include Locomotive::Mongoid::Document
5
5
 
6
- MINIMAL_ATTRIBUTES = %w(_id title slug fullpath position depth published templatized target_klass_name redirect listed response_type parent_id parent_ids site_id created_at updated_at raw_template)
6
+ MINIMAL_ATTRIBUTES = %w(_id title slug fullpath position depth published templatized target_klass_name redirect listed response_type parent_id parent_ids site_id created_at updated_at raw_template is_layout)
7
7
 
8
8
  ## concerns ##
9
9
  include Concerns::Page::Tree
10
10
  include Concerns::Page::EditableElements
11
11
  include Concerns::Page::Layout
12
- # include Concerns::Page::Parse
13
- # include Concerns::Page::Render
14
12
  include Concerns::Page::Templatized
15
13
  include Concerns::Page::Redirect
16
14
  include Concerns::Page::Listed
17
15
  include Concerns::Shared::Slug
18
16
  include Concerns::Shared::Seo
17
+ include Concerns::Shared::Userstamp
19
18
 
20
19
  ## fields ##
21
20
  field :title, localize: true
@@ -43,10 +43,6 @@ module Locomotive
43
43
 
44
44
  ## methods ##
45
45
 
46
- def all_pages_in_once
47
- PageService.new(self).build_tree
48
- end
49
-
50
46
  # Get all the pages in the right order: depth and position, both ASC.
51
47
  #
52
48
  # @param [ Hash ] conditions Extra conditions passed to the Mongoid criteria
@@ -56,6 +56,7 @@ module Locomotive
56
56
  # @return [ Object ] An instance of the content entry.
57
57
  #
58
58
  def public_create(attributes)
59
+ raise 'TODO'
59
60
  content_type.entries.build.tap do |entry|
60
61
  entry.from_presenter(attributes)
61
62
  entry.save
@@ -1,63 +1,35 @@
1
1
  module Locomotive
2
2
 
3
- class PageService < Struct.new(:site)
3
+ class PageService < Struct.new(:site, :account)
4
4
 
5
- # Returns the tree of pages from the site with the most minimal amount of queries.
6
- # This method should only be used for read-only purpose since
7
- # the mongodb returns the minimal set of required attributes to build
8
- # the tree.
5
+ # Create a page from the attributes passed in parameter.
6
+ # It sets the created_by column with the current account.
9
7
  #
10
- # @return [ Array ] The first array of pages (index + page not found + pages with depth == 1)
8
+ # @param [ Hash ] attributes The attributes of new page.
11
9
  #
12
- def build_tree
13
- pages, page_not_found = pages_with_minimun_attributes, nil
14
-
15
- [].tap do |tree|
16
- while page = pages.shift
17
- if page.not_found?
18
- # move the "page not found" (404) at the end of the array
19
- page_not_found = page
20
- elsif page.index?
21
- # make the index page without children
22
- tree << [page, nil]
23
- else
24
- tree << _build_tree(page, pages)
25
- end
26
- end
27
-
28
- tree << [page_not_found, nil]
10
+ # @return [ Object ] An instance of the page.
11
+ #
12
+ def create(attributes)
13
+ site.pages.build(attributes).tap do |page|
14
+ page.created_by = account if account
15
+ page.save
29
16
  end
30
17
  end
31
18
 
32
- protected
33
-
34
- #:nodoc:
35
- def pages_with_minimun_attributes
36
- site.pages.unscoped.
37
- minimal_attributes.
38
- order_by_depth_and_position.
39
- to_a
40
- end
41
-
42
- #:nodoc:
43
- def _build_tree(current_page, pages)
44
- i, children = 0, []
45
-
46
- while !pages.empty?
47
- page = pages[i]
48
-
49
- break if page.nil? # end of the array
50
-
51
- if page.parent_id == current_page.id
52
- page = pages.delete_at(i)
53
-
54
- children << _build_tree(page, pages)
55
- else
56
- i += 1
57
- end
19
+ # Update a page from the attributes passed in parameter.
20
+ # It sets the updated_by column with the current account.
21
+ #
22
+ # @param [ Object ] entry The page to update.
23
+ # @param [ Hash ] attributes The attributes of new page.
24
+ #
25
+ # @return [ Object ] The instance of the page.
26
+ #
27
+ def update(page, attributes)
28
+ page.tap do
29
+ page.attributes = attributes
30
+ page.updated_by = account
31
+ page.save
58
32
  end
59
-
60
- [current_page, children]
61
33
  end
62
34
 
63
35
  end