sunrise-cms 1.1.0 → 1.1.1

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.
@@ -4,15 +4,15 @@ module Sunrise
4
4
  class ManagerController < Sunrise::ApplicationController
5
5
  include Sunrise::Utils::SearchWrapper
6
6
 
7
- before_action :build_record, only: [:new, :create]
8
- before_action :find_record, only: [:show, :edit, :update, :destroy]
7
+ before_action :build_record, only: %i[new create]
8
+ before_action :find_record, only: %i[show edit update destroy]
9
9
  before_action :authorize_resource
10
10
 
11
11
  helper :all
12
12
  helper_method :abstract_model, :apply_scope, :scoped_index_path
13
13
 
14
14
  respond_to(*Sunrise::Config.navigational_formats)
15
- respond_to :xml, :csv, :xlsx, only: [:export]
15
+ respond_to :xml, :csv, :xlsx, only: %i[export]
16
16
 
17
17
  def index
18
18
  @records = abstract_model.apply_scopes(params)
@@ -69,6 +69,19 @@ module Sunrise
69
69
  end
70
70
  end
71
71
 
72
+ def import
73
+ return render plain: 'Unacceptable', status: 422 unless import_possible?
74
+
75
+ @files = import_process_uploaded_files
76
+
77
+ respond_to do |format|
78
+ format.html { redirect_to scoped_index_path }
79
+ format.json do
80
+ render json: { files: @files }
81
+ end
82
+ end
83
+ end
84
+
72
85
  def sort
73
86
  abstract_model.update_sort(params)
74
87
 
@@ -89,6 +102,32 @@ module Sunrise
89
102
 
90
103
  protected
91
104
 
105
+ def import_process_uploaded_files
106
+ raw_files = params['files']
107
+ return [] if raw_files.blank?
108
+
109
+ raw_files.each_with_object([]) do |file, obj|
110
+ results = abstract_model.model.public_send(:sunrise_import, file)
111
+ results = render_imported_results(results, file)
112
+
113
+ obj << { name: file.original_filename, records: results }
114
+ end
115
+ end
116
+
117
+ def render_imported_results(results, file)
118
+ return results unless import_custom_render?
119
+
120
+ abstract_model.model.send(:sunrise_import_results_renderer, results, file)
121
+ end
122
+
123
+ def import_possible?
124
+ abstract_model.model.methods.include?(:sunrise_import)
125
+ end
126
+
127
+ def import_custom_render?
128
+ abstract_model.model.methods.include?(:sunrise_import_results_renderer)
129
+ end
130
+
92
131
  def find_model
93
132
  @abstract_model = Utils.get_model(params[:model_name], params)
94
133
  if @abstract_model.nil?
@@ -6,9 +6,10 @@
6
6
  <meta name="robots" content="NONE,NOARCHIVE" />
7
7
  <%= csrf_meta_tag %>
8
8
  <title><%= t('manage.page_title') %></title>
9
-
10
- <%= stylesheet_link_tag "sunrise/application" %>
11
- <%= javascript_include_tag "sunrise/application" %>
9
+
10
+ <%= stylesheet_link_tag 'sunrise/application' %>
11
+ <%= javascript_include_tag 'sunrise/application' %>
12
+ <%#= javascript_include_tag ::Ckeditor.cdn_url %>
12
13
  </head>
13
14
  <body>
14
15
  <div class="outer">
@@ -16,16 +17,16 @@
16
17
  <%= render :partial => "sunrise/shared/panel" %>
17
18
  <%= manage_render_header %>
18
19
  </div>
19
-
20
+
20
21
  <%= yield %>
21
22
  </div>
22
-
23
+
23
24
  <div class="footer">
24
25
  <div class="fwrapper">
25
26
  <%= image_tag("sunrise/created.png", :title => "fodojo.com") %>
26
27
  </div>
27
28
  </div>
28
-
29
+
29
30
  <div id="dark-shadow" class="dark-bg" style="display:none;"></div>
30
31
  </body>
31
32
  </html>
@@ -1,5 +1,12 @@
1
1
  <div class="but-holder">
2
2
  <div class="act-but">
3
- <%= link_to image_tag('sunrise/empty.gif'), export_path(:format => :csv), :class => 'but-container opt', :title => 'Export' %>
3
+ <%= link_to 'CSV', export_path(format: :csv), class: 'but-container export', title: 'Export' %>
4
4
  </div>
5
- </div>
5
+ </div>
6
+ <% if defined?(Mime::XLSX) %>
7
+ <div class="but-holder">
8
+ <div class="act-but">
9
+ <%= link_to 'XLS', export_path(format: :xlsx), class: 'but-container export', title: 'Export (XLS)' %>
10
+ </div>
11
+ </div>
12
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <% if abstract_model.config.available_import %>
2
+ <div class="but-holder">
3
+ <div class="act-but">
4
+ <%=
5
+ link_to(
6
+ image_tag('sunrise/empty.gif'),
7
+ export_path(format: :csv),
8
+ class: 'but-container import',
9
+ id: 'import-button',
10
+ title: 'Import',
11
+ data: {
12
+ title: 'Import',
13
+ url: import_path
14
+ }
15
+ )
16
+ %>
17
+
18
+ <script type="text/javascript">
19
+ $(document).ready(function(){
20
+ $('#import-button').import_dialog();
21
+ });
22
+ </script>
23
+ </div>
24
+ </div>
25
+ <% end %>
@@ -1,13 +1,13 @@
1
1
  <div class="but-holder">
2
2
  <div class="act-but">
3
3
  <%= link_to image_tag('sunrise/empty.gif'), export_path(:format => :json), :class => 'but-container sort', :title => t('manage.buttons.sort'), :id => 'sort-button', :"data-save_title" => t('manage.buttons.save'), :"data-cancel_title" => t('manage.buttons.cancel'), :"data-url" => sort_path(:format => :json) %>
4
-
4
+
5
5
  <script type="text/javascript">
6
6
  $(document).ready(function(){
7
7
  $('#sort-button').sort_dialog();
8
8
  });
9
9
  </script>
10
-
10
+
11
11
  <script id="sort-template" type="text/x-jquery-tmpl">
12
12
  <div class="sort-item" data-record-id="${id}">
13
13
  <div class="sort-inner">
@@ -17,4 +17,4 @@
17
17
  </div>
18
18
  </script>
19
19
  </div>
20
- </div>
20
+ </div>
@@ -9,7 +9,7 @@
9
9
  <script type='text/javascript'>
10
10
  $(document).ready(function(){
11
11
  window['sunrise'].storeQuery();
12
-
12
+
13
13
  $("#sortable ul").sortable({
14
14
  placeholder: "tree-state-shadow",
15
15
  handle: "a.dnd_link",
data/config/routes.rb CHANGED
@@ -13,6 +13,7 @@ Sunrise::Engine.routes.draw do
13
13
  scope ':model_name' do
14
14
  get '/', action: :index, as: :index
15
15
  get '/export.:format', action: :export, as: :export
16
+ post '/import', action: :import, as: :import
16
17
  post '/sort', action: :sort, as: :sort
17
18
  get '/new', action: :new, as: :new
18
19
  post '/new', action: :create, as: :create
@@ -50,14 +50,14 @@ module Sunrise
50
50
  delegate :label, to: 'self.class.config'
51
51
  delegate :param_key, :singular, :plural, :route_key, to: :model_name
52
52
 
53
- define_model_callbacks :sort, :mass_destroy, only: [:before, :after]
53
+ define_model_callbacks :sort, :mass_destroy, only: %i[before after]
54
54
 
55
55
  def initialize(params = {})
56
56
  @model_name = model.model_name
57
57
  @current_list = config.default_index_view
58
58
  @available_index_views = config.available_index_views
59
59
  @sort_column = config.sort_column
60
- @request_params = params.symbolize_keys
60
+ @request_params = params.try(:symbolize_keys) || params
61
61
  self.current_list = params[:view]
62
62
  end
63
63
 
@@ -183,7 +183,7 @@ module Sunrise
183
183
  if model.respond_to?(:sunrise_search) && params[:search].present?
184
184
  scope = model.sunrise_search(params[:search])
185
185
  end
186
- scope ||= model.where(nil)
186
+ scope ||= model.all
187
187
 
188
188
  scope = scope.merge(association_scope) unless parent_record.nil?
189
189
  scope = scope.merge(sort_scope(params[:sort])) if params[:sort].present?
@@ -38,6 +38,10 @@ module Sunrise
38
38
  Config.available_index_views
39
39
  end
40
40
 
41
+ register_instance_option(:available_import) do
42
+ Config.available_import
43
+ end
44
+
41
45
  register_instance_option(:sort_column) do
42
46
  Config.sort_column
43
47
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'rails'
4
4
  require 'sunrise'
5
+ require 'select2-rails'
6
+ require 'jquery-ui-rails'
5
7
 
6
8
  module Sunrise
7
9
  class Engine < ::Rails::Engine
@@ -10,6 +12,10 @@ module Sunrise
10
12
 
11
13
  config.i18n.load_path += Dir[Sunrise.root_path.join('config/locales/**', '*.{rb,yml}')]
12
14
 
15
+ config.assets.precompile += %w[
16
+ sunrise/*
17
+ ]
18
+
13
19
  initializer 'sunrise.setup' do
14
20
  I18n::Backend::Simple.include I18n::Backend::Pluralization
15
21
  I18n::Backend::Simple.include I18n::Backend::Transliterator
@@ -1,16 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cancan_namespace'
4
-
5
3
  module Sunrise
6
4
  module Models
7
5
  class Ability
8
- include CanCanNamespace::Ability
6
+ include CanCan::Ability
9
7
 
10
8
  attr_accessor :context, :user
11
9
 
12
10
  def initialize(user, context = nil)
13
- alias_action :delete, to: :destroy
11
+ # alias_action :delete, to: :destroy
14
12
 
15
13
  @user = (user || ::User.new) # guest user (not logged in)
16
14
  @context = context
@@ -24,13 +22,15 @@ module Sunrise
24
22
 
25
23
  def admin
26
24
  can :manage, :all
27
- can :manage, :all, context: :sunrise
25
+ # can :manage, :all, context: :sunrise
28
26
 
29
27
  # User cannot destroy self account
30
- cannot :destroy, ::User, id: @user.id, context: :sunrise
28
+ # cannot :destroy, ::User, id: @user.id, context: :sunrise
29
+ cannot :destroy, ::User, id: @user.id
31
30
 
32
31
  # User cannot destroy root structure
33
- cannot :destroy, ::Structure, structure_type_id: ::StructureType.main.id, context: :sunrise
32
+ # cannot :destroy, ::Structure, structure_type_id: ::StructureType.main.id, context: :sunrise
33
+ cannot :destroy, ::Structure, structure_type_id: ::StructureType.main.id
34
34
  end
35
35
  end
36
36
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sunrise
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'.freeze
5
5
  end
data/sunrise-cms.gemspec CHANGED
@@ -13,7 +13,6 @@ Gem::Specification.new do |s|
13
13
  s.description = 'Sunrise is a Open Source CMS'
14
14
  s.authors = ['Igor Galeta', 'Pavlo Galeta']
15
15
  s.email = 'galeta.igor@gmail.com'
16
- s.rubyforge_project = 'sunrise-cms'
17
16
  s.homepage = 'https://github.com/galetahub/sunrise'
18
17
  s.license = 'MIT'
19
18
 
@@ -32,7 +31,7 @@ Gem::Specification.new do |s|
32
31
 
33
32
  s.add_dependency('babosa')
34
33
  s.add_dependency('cancan')
35
- s.add_dependency('cancan_namespace')
34
+
36
35
  s.add_dependency('carrierwave')
37
36
  s.add_dependency('galetahub-enum_field')
38
37
  s.add_dependency('jquery-ui-rails', '>= 5.0.0')
@@ -43,7 +42,6 @@ Gem::Specification.new do |s|
43
42
  s.add_dependency('public_activity', '>= 1.0.0')
44
43
  s.add_dependency('rails-settings-cached', '>= 0.4.0')
45
44
  s.add_dependency('rails-uploader')
46
- s.add_dependency('select2-rails')
47
45
 
48
46
  s.add_development_dependency('capybara')
49
47
  s.add_development_dependency('database_cleaner')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunrise-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Galeta
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-06 00:00:00.000000000 Z
12
+ date: 2021-04-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kaminari
@@ -81,20 +81,6 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: cancan_namespace
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- type: :runtime
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
98
84
  - !ruby/object:Gem::Dependency
99
85
  name: carrierwave
100
86
  requirement: !ruby/object:Gem::Requirement
@@ -235,20 +221,6 @@ dependencies:
235
221
  - - ">="
236
222
  - !ruby/object:Gem::Version
237
223
  version: '0'
238
- - !ruby/object:Gem::Dependency
239
- name: select2-rails
240
- requirement: !ruby/object:Gem::Requirement
241
- requirements:
242
- - - ">="
243
- - !ruby/object:Gem::Version
244
- version: '0'
245
- type: :runtime
246
- prerelease: false
247
- version_requirements: !ruby/object:Gem::Requirement
248
- requirements:
249
- - - ">="
250
- - !ruby/object:Gem::Version
251
- version: '0'
252
224
  - !ruby/object:Gem::Dependency
253
225
  name: capybara
254
226
  requirement: !ruby/object:Gem::Requirement
@@ -362,6 +334,8 @@ files:
362
334
  - app/assets/images/sunrise/icons/commented.svg
363
335
  - app/assets/images/sunrise/icons/create.svg
364
336
  - app/assets/images/sunrise/icons/destroy.svg
337
+ - app/assets/images/sunrise/icons/export.svg
338
+ - app/assets/images/sunrise/icons/import.svg
365
339
  - app/assets/images/sunrise/icons/update.svg
366
340
  - app/assets/images/sunrise/note_pointer.png
367
341
  - app/assets/images/sunrise/page_arr_hover.png
@@ -446,6 +420,7 @@ files:
446
420
  - app/views/sunrise/manager/buttons/_delete.html.erb
447
421
  - app/views/sunrise/manager/buttons/_edit.html.erb
448
422
  - app/views/sunrise/manager/buttons/_export.html.erb
423
+ - app/views/sunrise/manager/buttons/_import.html.erb
449
424
  - app/views/sunrise/manager/buttons/_new.html.erb
450
425
  - app/views/sunrise/manager/buttons/_sort.html.erb
451
426
  - app/views/sunrise/manager/edit.html.erb
@@ -608,7 +583,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
608
583
  - !ruby/object:Gem::Version
609
584
  version: '0'
610
585
  requirements: []
611
- rubyforge_project: sunrise-cms
586
+ rubyforge_project:
612
587
  rubygems_version: 2.7.6.2
613
588
  signing_key:
614
589
  specification_version: 4