enjoy_cms 0.3.3 → 0.3.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a343ff214ab5a895ad91cf3eb897a3692420bef
4
- data.tar.gz: e0d4ebd8b92e5182325c8dc2c0373c8517f8dfc3
3
+ metadata.gz: e1cde68353de729109469314593280868f16f916
4
+ data.tar.gz: 8d710c2d7de38ddf701c9069f8b03ef7481a794b
5
5
  SHA512:
6
- metadata.gz: 9f444d9a1b1e6c99a0de9d94e6d826ceaa73d48ab658a22dc8b17d2e23a9895a690353fa6c8a36e958433c22f294177d3ad31198f7943b34588fe341e829dd8e
7
- data.tar.gz: f53e6b513f7a9004ddda3fcbda789827ed922f67b1da1cc39e1083daf282986d69dbad1a92c5ebd2abdf00dce77ee73771d3c7e5621dc4a83667fc04bc6c9073
6
+ metadata.gz: dbcd938f54fdc7fa3d5e58c74fcdaa0f2082a8b8defcd3999adb845f6146ff12b03ac2dec980514a04f06b17f56a729b449ffd98f3f4397178eae632fcc5f6a6
7
+ data.tar.gz: 1c9120a4a121b5cbdd346f4e801e6695438a7e4ad7e2af9604cf236686e36581cebcf4e34b5b9f128179aea86ac477ce0a94edbc5454328cc8f9471dd7f5b7fa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enjoy_cms (0.3.3)
4
+ enjoy_cms (0.3.4)
5
5
  ack_rails_admin_jcrop
6
6
  addressable
7
7
  ckeditor
@@ -16,7 +16,7 @@ module Enjoy::NavMenu
16
16
  }
17
17
  end
18
18
  end
19
- cr = item.clean_regexp
19
+ # cr = item.clean_regexp
20
20
  navigation_item(primary, item, block)
21
21
  end
22
22
 
@@ -52,7 +52,23 @@ module Enjoy::NavMenu
52
52
  end
53
53
 
54
54
  def nav_get_url(item)
55
- item.redirect.blank? ? item.fullpath : item.redirect
55
+ _connectable = item.connectable
56
+ if _connectable and _connectable.enabled
57
+ begin
58
+ _routes_namespace = _connectable.respond_to?(:routes_namespace) ? _connectable.routes_namespace : :main_app
59
+ send(_routes_namespace.to_sym).url_for(_connectable)
60
+ rescue Exception => exception
61
+ Rails.logger.error exception.message
62
+ Rails.logger.error exception.backtrace.join("\n")
63
+ puts exception.message
64
+ puts exception.backtrace.join("\n")
65
+ capture_exception(exception) if respond_to?(:capture_exception)
66
+
67
+ item.redirect.blank? ? item.fullpath : item.redirect
68
+ end
69
+ else
70
+ item.redirect.blank? ? item.fullpath : item.redirect
71
+ end
56
72
  end
57
73
  def nav_get_menu_items(type)
58
74
  menu = menu_class.find(type.to_s)
@@ -0,0 +1,36 @@
1
+ module Enjoy::Connectable
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def enjoy_connectable_field (name = :connected_pages, opts = {})
6
+ class_name = opts.delete(:class_name)
7
+ class_name ||= "Enjoy::Page"
8
+ routes_namespace = opts.delete(:routes_namespace)
9
+ routes_namespace ||= :main_app
10
+ autocreate_page = opts.delete(:autocreate_page)
11
+ autocreate_page = true if autocreate_page.nil?
12
+
13
+ has_many name, as: :connectable, class_name: "Enjoy::Page"
14
+ class_eval <<-EVAL
15
+ def routes_namespace
16
+ :#{routes_namespace}
17
+ end
18
+ EVAL
19
+
20
+ if autocreate_page
21
+ attr_accessor :enjoy_connectable_autocreate_page
22
+ _name_attr = Enjoy.config.localize ? "name_translations" : "name"
23
+ class_eval <<-EVAL
24
+ after_create do
25
+ if self.enjoy_connectable_autocreate_page
26
+ _p = #{class_name}.new
27
+ _p.#{_name_attr} = self.#{_name_attr}
28
+ _p.connectable = self
29
+ _p.save
30
+ end
31
+ end
32
+ EVAL
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,7 +1,7 @@
1
1
  = render 'shared/obj', obj: @seo_page
2
2
 
3
3
  #enjoy_cms_contact_form
4
- = simple_form_for @contact_message, url: enjoy_cms.contacts_path do |f|
4
+ = simple_form_for @contact_message, url: contacts_path do |f|
5
5
  = f.input :name
6
6
  = f.input :email
7
7
  = f.input :phone
@@ -1,7 +1,7 @@
1
1
  = render 'shared/obj', obj: @seo_page
2
2
 
3
3
  #enjoy_cms_contact_form
4
- = simple_form_for @contact_message, url: enjoy_cms.contacts_path do |f|
4
+ = simple_form_for @contact_message, url: contacts_path do |f|
5
5
  = f.input :name
6
6
  = f.input :email
7
7
  = f.input :phone
@@ -1,6 +1,6 @@
1
1
  .enjoy-search-results
2
2
  h1 Результаты поиска
3
- = form_tag enjoy.search_path, method: :get, class: 'nav_search' do
3
+ = form_tag search_path, method: :get, class: 'nav_search' do
4
4
  = text_field_tag 'query', params[:query], placeholder: "Поиск"
5
5
  = submit_tag 'Найти'
6
6
  ol
@@ -1,7 +1,7 @@
1
1
  - if params[:associations].nil?
2
2
  = render 'rails_admin/main/enum_check_boxes', field: field, form: form
3
3
  - else
4
- :ruby
4
+ ruby:
5
5
  related_id = params[:associations] && params[:associations][field.name.to_s]
6
6
  config = field.associated_model_config
7
7
  source_abstract_model = RailsAdmin.config(form.object.class).abstract_model
@@ -0,0 +1,56 @@
1
+ ruby:
2
+ related_id = params[:associations] && params[:associations][field.name.to_s]
3
+ config = field.associated_model_config
4
+ source_abstract_model = RailsAdmin.config(form.object.class).abstract_model
5
+
6
+ if form.object.new_record? && related_id.present? && related_id != 'new'
7
+ selected = [config.abstract_model.get(related_id)]
8
+ else
9
+ selected = form.object.send(field.name)
10
+ end
11
+ selected_ids = selected.map{|s| s.send(field.associated_primary_key)}
12
+
13
+ current_action = params[:action].in?(['create', 'new']) ? 'create' : 'update'
14
+
15
+ xhr = !field.associated_collection_cache_all
16
+
17
+ collection = if xhr
18
+ selected.map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }
19
+ else
20
+ i = 0
21
+ controller.list_entries(config, :index, field.associated_collection_scope, false).map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }.sort_by {|a| [selected_ids.index(a[1]) || selected_ids.size, i+=1] }
22
+ end
23
+
24
+ js_data = {
25
+ xhr: xhr,
26
+ :'edit-url' => (authorized?(:edit, config.abstract_model) ? edit_path(model_name: config.abstract_model.to_param, id: '__ID__') : ''),
27
+ remote_source: index_path(config.abstract_model, source_object_id: form.object.id, source_abstract_model: source_abstract_model.to_param, associated_collection: field.name, current_action: current_action, compact: true),
28
+ sortable: !!field.orderable,
29
+ removable: !!field.removable,
30
+ cacheAll: !!field.associated_collection_cache_all,
31
+ regional: {
32
+ chooseAll: t("admin.misc.chose_all"),
33
+ chosen: t("admin.misc.chosen", name: config.label_plural),
34
+ clearAll: t("admin.misc.clear_all"),
35
+ search: t("admin.misc.search"),
36
+ up: t("admin.misc.up"),
37
+ down: t("admin.misc.down")
38
+ }
39
+ }
40
+
41
+ input{name="#{form.dom_name(field)}" type="hidden" value=""}
42
+
43
+ - if field.bindings[:object].new_record? and field.bindings[:object].respond_to?(field.autocreate_page_attr)
44
+ p
45
+ span{style='float: left'}= form.check_box field.autocreate_page_attr, checked: true, class: "form-control"
46
+ div{style='margin-left: 35px; line-height: 40px;'} Автоматически создать пункт меню
47
+
48
+ - selected_ids = (hdv = field.form_default_value).nil? ? selected_ids : hdv
49
+ = form.select field.method_name, collection, { selected: selected_ids, object: form.object }, field.html_attributes.reverse_merge({data: { filteringmultiselect: true, options: js_data.to_json }, multiple: true})
50
+ - if authorized?(:new, config.abstract_model) && field.inline_add
51
+ - path_hash = { model_name: config.abstract_model.to_param, modal: true }
52
+ - path_hash.merge!({ associations: { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of
53
+ = link_to "<i class=\"icon-plus icon-white\"></i> ".html_safe + wording_for(:link, :new, config.abstract_model), '#', data: { link: new_path(path_hash) }, class: "create btn btn-info", style: 'margin-left:10px'
54
+
55
+
56
+
@@ -1,4 +1,4 @@
1
- :ruby
1
+ ruby:
2
2
  values = form.object.class.send(field.method_name).values.map { |v|
3
3
  [t("enumerize.#{form.object.class.name.downcase}.#{field.method_name}.#{v}", default: t("enumerize.defaults.#{field.method_name}.#{v}")), v]
4
4
  }
@@ -1,4 +1,4 @@
1
- :ruby
1
+ ruby:
2
2
  values = form.object.class.send(field.method_name).values.map { |v|
3
3
  [t("enumerize.#{form.object.class.name.downcase}.#{field.method_name}.#{v}", default: t("enumerize.defaults.#{field.method_name}.#{v}")), v]
4
4
  }
@@ -13,6 +13,7 @@ module Enjoy
13
13
  sort_reverse true
14
14
  end
15
15
  field :name
16
+ field :connected_pages, :enjoy_connectable
16
17
  unless Enjoy.config.news_image_styles.nil?
17
18
  field :image, :jcrop do
18
19
  jcrop_options :image_jcrop_options
@@ -10,6 +10,7 @@ module Enjoy
10
10
  field :enabled, :toggle
11
11
  field :menus, :menu
12
12
  field :name
13
+ field :connectable
13
14
  field :fullpath do
14
15
  pretty_value do
15
16
  bindings[:view].content_tag(:a, bindings[:object].fullpath, href: bindings[:object].fullpath)
@@ -21,6 +22,9 @@ module Enjoy
21
22
 
22
23
  edit do
23
24
  field :name
25
+ field :connectable do
26
+ read_only true
27
+ end
24
28
 
25
29
  group :content do
26
30
  active false
@@ -49,7 +53,7 @@ module Enjoy
49
53
  end
50
54
 
51
55
  Enjoy::RailsAdminGroupPatch::enjoy_cms_group(self, fields)
52
-
56
+
53
57
  group :seo do
54
58
  active false
55
59
  field :seo do
@@ -11,6 +11,24 @@ module Enjoy
11
11
  include RailsAdminComments::Commentable
12
12
  end
13
13
 
14
+ belongs_to :connectable, polymorphic: true
15
+ scope :connected, -> {
16
+ where(:connectable_id.ne => nil)
17
+ }
18
+ scope :unconnected, -> (except_this = nil) {
19
+ if except_this
20
+ where({"$or" =>[
21
+ {:connectable_id => nil},
22
+ {"$and" => [
23
+ {connectable_type: except_this.class.to_param},
24
+ {connectable_id: except_this._id}
25
+ ]}
26
+ ]})
27
+ else
28
+ where(:connectable_id => nil)
29
+ end
30
+ }
31
+
14
32
  field :name, type: String, localize: Enjoy.config.localize, default: ""
15
33
 
16
34
  field :regexp, type: String, default: ""
@@ -7,6 +7,7 @@ module Enjoy
7
7
  include Enjoy::Seoable
8
8
  include Enjoy::Enableable
9
9
  include Enjoy::SitemapDataField
10
+ include Enjoy::Connectable
10
11
 
11
12
  include Enjoy.orm_specific('News')
12
13
 
@@ -15,6 +16,7 @@ module Enjoy
15
16
  # end
16
17
 
17
18
  included do
19
+ enjoy_connectable_field :connected_pages, routes_namespace: :enjoy_cms
18
20
 
19
21
  unless Enjoy.config.news_image_styles.nil?
20
22
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/, if: :image?
@@ -0,0 +1,33 @@
1
+ require 'rails_admin/config/fields/types/has_many_association'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Fields
6
+ module Types
7
+ class EnjoyConnectable < RailsAdmin::Config::Fields::Types::HasManyAssociation
8
+ RailsAdmin::Config::Fields::Types::register(self)
9
+ include RailsAdmin::Engine.routes.url_helpers
10
+
11
+ register_instance_option :partial do
12
+ :enjoy_connectable
13
+ end
14
+
15
+ register_instance_option :autocreate_page_attr do
16
+ :enjoy_connectable_autocreate_page
17
+ end
18
+
19
+ register_instance_option :allowed_methods do
20
+ [method_name, autocreate_page_attr]
21
+ end
22
+
23
+ register_instance_option :associated_collection_scope do
24
+ me = bindings[:object]
25
+ Proc.new do |scope|
26
+ scope.unconnected(me).enabled.sorted
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,5 @@
1
+ require 'rails_admin/config/fields/types/text'
2
+
1
3
  module RailsAdmin
2
4
  module Config
3
5
  module Fields
@@ -1,3 +1,5 @@
1
+ require 'rails_admin/config/fields/types/ck_editor'
2
+
1
3
  module RailsAdmin
2
4
  module Config
3
5
  module Fields
@@ -34,7 +36,7 @@ module RailsAdmin
34
36
  register_instance_option :export_value do
35
37
  pretty_value
36
38
  end
37
-
39
+
38
40
 
39
41
  register_instance_option :boolean_view_helper do
40
42
  :check_box
@@ -1,3 +1,5 @@
1
+ require 'rails_admin/config/fields/base'
2
+
1
3
  module RailsAdmin
2
4
  module Config
3
5
  module Fields
data/lib/enjoy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Enjoy
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
data/lib/enjoy_cms.rb CHANGED
@@ -15,10 +15,18 @@ require 'glebtv-simple_captcha'
15
15
  require 'validates_email_format_of'
16
16
  require 'smart_excerpt'
17
17
  require 'filename_to_slug'
18
+
18
19
  require 'rails_admin'
20
+
21
+ require 'enjoy/rails_admin_ext/enjoy_connectable'
22
+ require 'enjoy/rails_admin_ext/enjoy_hash'
23
+ require 'enjoy/rails_admin_ext/enjoy_html'
24
+ require 'enjoy/rails_admin_ext/group_patch'
25
+ require 'enjoy/rails_admin_ext/menu'
26
+
19
27
  require 'rails_admin_nested_set'
20
28
  require 'rails_admin_toggleable'
21
- # require 'rails_admin_settings'
29
+ require 'rails_admin_settings'
22
30
  require 'rails_admin_sort_embedded'
23
31
 
24
32
  require 'x-real-ip'
@@ -35,10 +43,6 @@ require 'ack_rails_admin_jcrop'
35
43
  require 'enjoy/configuration'
36
44
  require 'enjoy/elastic_search'
37
45
  require 'enjoy/model'
38
- require 'enjoy/rails_admin_menu'
39
- require 'enjoy/rails_admin_enjoy_html'
40
- require 'enjoy/rails_admin_enjoy_hash'
41
- require 'enjoy/rails_admin_group_patch'
42
46
  require 'enjoy/engine'
43
47
  require 'enjoy/controller'
44
48
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enjoy_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kiseliev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-03 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -434,6 +434,7 @@ files:
434
434
  - app/helpers/enjoy/powered_helper.rb
435
435
  - app/mailers/enjoy/contact_mailer.rb
436
436
  - app/models/concerns/enjoy/boolean_field.rb
437
+ - app/models/concerns/enjoy/connectable.rb
437
438
  - app/models/concerns/enjoy/decorators/contact_message.rb
438
439
  - app/models/concerns/enjoy/decorators/embedded_element.rb
439
440
  - app/models/concerns/enjoy/decorators/embedded_gallery_image.rb
@@ -493,6 +494,7 @@ files:
493
494
  - app/views/errors/error_500.html.slim
494
495
  - app/views/layouts/application.html.slim
495
496
  - app/views/rails_admin/main/_check_boxes.html.slim
497
+ - app/views/rails_admin/main/_enjoy_connectable.html.slim
496
498
  - app/views/rails_admin/main/_enjoy_hash.html.slim
497
499
  - app/views/rails_admin/main/_enjoy_html.html.slim
498
500
  - app/views/rails_admin/main/_enum_check_boxes.html.slim
@@ -574,10 +576,11 @@ files:
574
576
  - lib/enjoy/models/page_blockset.rb
575
577
  - lib/enjoy/models/seo.rb
576
578
  - lib/enjoy/models/sitemap_data.rb
577
- - lib/enjoy/rails_admin_enjoy_hash.rb
578
- - lib/enjoy/rails_admin_enjoy_html.rb
579
- - lib/enjoy/rails_admin_group_patch.rb
580
- - lib/enjoy/rails_admin_menu.rb
579
+ - lib/enjoy/rails_admin_ext/enjoy_connectable.rb
580
+ - lib/enjoy/rails_admin_ext/enjoy_hash.rb
581
+ - lib/enjoy/rails_admin_ext/enjoy_html.rb
582
+ - lib/enjoy/rails_admin_ext/group_patch.rb
583
+ - lib/enjoy/rails_admin_ext/menu.rb
581
584
  - lib/enjoy/simple_form_patch.rb
582
585
  - lib/enjoy/tasks.rb
583
586
  - lib/enjoy/version.rb