sunrise-cms 0.6.0 → 0.6.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.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.6.1
2
+ * New callbacks after_sort, before_sort, after_mass_destroy, before_mass_destroy in Abstract model.
3
+ * Translate sort buttons
4
+ * New nginx config (using try_files)
5
+
1
6
  == 0.6.0
2
7
  * Raname attributes kind and position to structure_type_id and position_type_id
3
8
  * Integrate "public_activity" gem
data/README.md CHANGED
@@ -39,6 +39,8 @@ class SunriseProduct < Sunrise::AbstractModel
39
39
  self.resource_name = "Product"
40
40
 
41
41
  association :structure
42
+
43
+ after_sort :clear_cache
42
44
 
43
45
  list :thumbs do
44
46
  scope { Product.includes(:picture) }
@@ -79,6 +81,12 @@ class SunriseProduct < Sunrise::AbstractModel
79
81
  field :picture, :as => :uploader
80
82
  end
81
83
  end
84
+
85
+ protected
86
+
87
+ def clear_cache
88
+ Rails.cache.clear
89
+ end
82
90
  end
83
91
  ```
84
92
 
@@ -9,7 +9,7 @@ module Sunrise
9
9
  cur_page = (params[:page] || 1).to_i
10
10
  offset = (cur_page - 1) * per_page
11
11
 
12
- @events = PublicActivity::Activity.includes(:owner, :trackable, :recipient)
12
+ @events = Sunrise.activities
13
13
  @events = @events.limit(per_page).offset(offset)
14
14
 
15
15
  respond_with(@events) do |format|
@@ -80,7 +80,7 @@ module Sunrise
80
80
  end
81
81
 
82
82
  def mass_destroy
83
- abstract_model.model.destroy_all(:id => params[:ids]) unless params[:ids].blank?
83
+ abstract_model.destroy_all(params)
84
84
 
85
85
  respond_to do |format|
86
86
  format.html { redirect_to redirect_after_update }
@@ -1,6 +1,6 @@
1
1
  <div class="but-holder">
2
2
  <div class="act-but">
3
- <%= link_to image_tag('sunrise/empty.gif'), export_path(:format => :json), :class => 'but-container sort', :title => 'Sort', :id => 'sort-button', :"data-save_title" => 'Save', :"data-cancel_title" => 'Cancel', :"data-url" => sort_path(:format => :json) %>
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(){
@@ -164,6 +164,9 @@ en:
164
164
  exit: "Exit"
165
165
  add_nested_field: "+Add"
166
166
  next_50: "Show more 50"
167
+ sort: "Sort"
168
+ save: "Save"
169
+ cancel: "Cancel"
167
170
 
168
171
  user:
169
172
  actions: "action"
@@ -164,6 +164,9 @@ ru:
164
164
  exit: "Выход"
165
165
  add_nested_field: "+Еще"
166
166
  next_50: "Показать еще 50"
167
+ sort: "Сортировать"
168
+ save: "Сохранить"
169
+ cancel: "Отмена"
167
170
 
168
171
  user:
169
172
  actions: "действия"
@@ -164,6 +164,9 @@ uk:
164
164
  exit: "Вихід"
165
165
  add_nested_field: "+Ще"
166
166
  next_50: "Показати ще 50"
167
+ sort: "Сортувати"
168
+ save: "Зберегти"
169
+ cancel: "Скасувати"
167
170
 
168
171
  user:
169
172
  actions: "дії"
@@ -22,7 +22,7 @@ module Sunrise
22
22
 
23
23
  def copy_configurations
24
24
  copy_file('config/seeds.rb', 'db/seeds.rb')
25
- copy_file('config/sunrise.rb', 'config/initializers/sunrise.rb')
25
+ copy_file("config/#{orm}/sunrise.rb", 'config/initializers/sunrise.rb')
26
26
 
27
27
  template('config/database.yml', 'config/database.yml.sample')
28
28
  template('config/logrotate-config', 'config/logrotate-config.sample')
@@ -1,5 +1,5 @@
1
- # require 'meta_manager/orm/active_record'
2
- # require 'page_parts/orm/active_record'
1
+ require 'meta_manager/orm/active_record'
2
+ require 'page_parts/orm/active_record'
3
3
 
4
4
  # Use this hook to configure sunrise
5
5
  Sunrise.setup do |config|
@@ -41,11 +41,11 @@ Sunrise.setup do |config|
41
41
  # config.navigational_formats = [:html, :json]
42
42
  end
43
43
 
44
- #PublicActivity::Config.set do
45
- # orm :mongoid
46
- #end
44
+ PublicActivity::Config.set do
45
+ orm :active_record
46
+ end
47
47
 
48
48
  #if Settings.table_exists?
49
49
  # Settings.defaults[:some_setting] = "value"
50
50
  # Settings.defaults[:some_setting2] = "value2"
51
- #end
51
+ #end
@@ -0,0 +1,51 @@
1
+ require 'meta_manager/orm/mongoid'
2
+ require 'page_parts/orm/mongoid'
3
+
4
+ # Use this hook to configure sunrise
5
+ Sunrise.setup do |config|
6
+ # Paginate records per page (default: 25)
7
+ # config.default_items_per_page = 25
8
+
9
+ # Display audits events on dashboard (default: 50)
10
+ # config.activities_per_page = 50
11
+
12
+ # By default show latest first (default: :desc)
13
+ # config.default_sort_mode = :desc
14
+
15
+ # The display for a model instance (i.e. a single database record).
16
+ # config.label_methods = [:title, :name]
17
+
18
+ # Defailt list template view (default: "thumbs")
19
+ # config.default_list_view = "thumbs"
20
+
21
+ # Avariable lists views (default: [:list, :thumbs, :table])
22
+ # config.available_list_view = [:list, :thumbs, :table]
23
+
24
+ # Defailt list template view (default: "sort_order")
25
+ # config.sort_column = "sort_order"
26
+
27
+ # Find template before rendering (default: true)
28
+ # config.scoped_views = true
29
+
30
+ # Set available locales in app (default: [])
31
+ # config.available_locales = []
32
+
33
+ # Set transliteration for babosa gem
34
+ # more info here: https://github.com/norman/babosa (default: :russian)
35
+ # config.transliteration = :russian
36
+
37
+ # Set list toolbar buttons (default: [:delete, :edit, :new, :sort, :export])
38
+ # config.default_toolbar_buttons = [:delete, :edit, :new, :sort, :export]
39
+
40
+ # Lists the formats that should be treated as navigational (default: [:html, :json])
41
+ # config.navigational_formats = [:html, :json]
42
+ end
43
+
44
+ PublicActivity::Config.set do
45
+ orm :mongoid
46
+ end
47
+
48
+ #if Settings.table_exists?
49
+ # Settings.defaults[:some_setting] = "value"
50
+ # Settings.defaults[:some_setting2] = "value2"
51
+ #end
@@ -1,7 +1,7 @@
1
1
  # <%= app_name %>
2
2
  #
3
3
  upstream <%= app_name %>_backend {
4
- server unix:/var/www/<%= app_name %>/tmp/sockets/unicorn.sock;
4
+ server unix:/var/www/<%= app_name %>/tmp/sockets/unicorn.sock fail_timeout=0;
5
5
  }
6
6
 
7
7
  server {
@@ -14,31 +14,10 @@ server {
14
14
 
15
15
  root /var/www/<%= app_name %>/public;
16
16
 
17
- if (-f $request_filename) {
18
- break;
19
- }
20
-
21
- if (-f /cache$request_filename) {
22
- rewrite (.*) /cache$1 break;
23
- break;
24
- }
25
-
26
- if (-f /cache$request_filename.html) {
27
- rewrite (.*) /cache$1.html break;
28
- break;
29
- }
17
+ try_files $uri $uri.html $uri/index.html /cache$uri/index.html /cache$uri.html /cache$uri @app;
30
18
 
31
- if (-f $document_root/cache$request_uri.html) {
32
- rewrite (.*) /cache$1.html break;
33
- }
34
-
35
- if (-f $document_root/cache$request_uri/index.html) {
36
- rewrite (.*) /cache$1/index.html break;
37
- }
38
-
39
- # This directive prohibits direct access to the cache directory from outside
40
19
  location ^~ /cache {
41
- internal;
20
+ return 404;
42
21
  }
43
22
 
44
23
  location ~ /\.[^\/]+ {
@@ -64,19 +43,12 @@ server {
64
43
  proxy_busy_buffers_size 64k;
65
44
  proxy_temp_file_write_size 64k;
66
45
 
67
- if (!-f $request_filename) {
68
- proxy_pass http://<%= app_name %>_backend;
69
- break;
70
- }
46
+ proxy_pass http://<%= app_name %>_backend;
71
47
  }
72
48
 
73
49
  location ~ ^/(assets|uploads|images|javascripts|stylesheets)/ {
74
50
  expires 1y;
75
51
  add_header Cache-Control public;
76
-
77
- # Some browsers still send conditional-GET requests if there's a
78
- # Last-Modified header or an ETag header even if they haven't
79
- # reached the expiry date sent in the Expires header.
80
52
  add_header Last-Modified "";
81
53
  add_header ETag "";
82
54
  break;
@@ -89,11 +61,7 @@ server {
89
61
 
90
62
  error_page 503 @503;
91
63
  location @503 {
92
- # Serve static assets if found.
93
- if (-f $request_filename) {
94
- break;
95
- }
96
-
64
+ root /var/www/designinterior/public;
97
65
  rewrite ^(.*)$ /system/maintenance.html break;
98
66
  }
99
67
  }
@@ -9,13 +9,13 @@ class Structure
9
9
  # Columns
10
10
  field :title, :type => String
11
11
  field :slug, :type => String
12
- field :kind, :type => Integer, :default => 0
13
- field :position, :type => Integer, :default => 0
12
+ field :structure_type_id, :type => Integer, :default => 0
13
+ field :position_type_id, :type => Integer, :default => 0
14
14
  field :is_visible, :type => Boolean, :default => true
15
15
  field :redirect_url, :type => String
16
16
 
17
- index({:kind => 1})
18
- index({:position => 1})
17
+ index({:structure_type_id => 1})
18
+ index({:position_type_id => 1})
19
19
  index({:parent_id => 1})
20
20
 
21
21
  tracked owner: ->(controller, model) { controller.try(:current_user) }
@@ -3,7 +3,8 @@ require 'ostruct'
3
3
 
4
4
  module Sunrise
5
5
  class AbstractModel
6
-
6
+ extend ::ActiveModel::Callbacks
7
+
7
8
  class << self
8
9
 
9
10
  # Gets the resource_name
@@ -49,6 +50,8 @@ module Sunrise
49
50
  delegate :config, :model, :to => 'self.class'
50
51
  delegate :label, :to => 'self.class.config'
51
52
  delegate :param_key, :singular, :plural, :route_key, :to => :model_name
53
+
54
+ define_model_callbacks :sort, :mass_destroy, :only => [:before, :after]
52
55
 
53
56
  def initialize(params = {})
54
57
  @model_name = model.model_name
@@ -117,10 +120,20 @@ module Sunrise
117
120
  end
118
121
 
119
122
  def update_sort(params)
120
- if !params[:ids].blank?
121
- update_sort_column(params[:ids])
122
- elsif !params[:tree].blank?
123
- update_sort_tree(params[:tree])
123
+ run_callbacks :sort do
124
+ if !params[:ids].blank?
125
+ update_sort_column(params[:ids])
126
+ elsif !params[:tree].blank?
127
+ update_sort_tree(params[:tree])
128
+ end
129
+ end
130
+ end
131
+
132
+ def destroy_all(params)
133
+ return if params[:ids].blank?
134
+
135
+ run_callbacks :mass_destroy do
136
+ model.where(:id => params[:ids]).destroy_all
124
137
  end
125
138
  end
126
139
 
@@ -139,14 +152,10 @@ module Sunrise
139
152
 
140
153
  def update_sort_column(ids)
141
154
  return nil if ids.empty?
142
-
143
- sql_case = ''
155
+
144
156
  ids.each do |key, value|
145
- sql_case += "WHEN #{key} THEN #{value} "
157
+ model.where(:id => key).update_all(["#{@sort_column} = ?", value])
146
158
  end
147
- sql_case += 'END'
148
-
149
- model.update_all("#{@sort_column} = CASE id #{sql_case}", ["id IN (?)", ids.keys.map(&:to_i)])
150
159
  end
151
160
 
152
161
  # Initialize new model, sets parent record and call build_defaults method
@@ -1,3 +1,3 @@
1
1
  module Sunrise
2
- VERSION = "0.6.0".freeze
2
+ VERSION = "0.6.1".freeze
3
3
  end
data/lib/sunrise.rb CHANGED
@@ -47,12 +47,20 @@ module Sunrise
47
47
  LOCALIZE_STANDALONE_DAY_NAMES_MATCH = /^%A/
48
48
 
49
49
  def self.root_path
50
- @root_path ||= Pathname.new( File.dirname(File.expand_path('../', __FILE__)) )
50
+ @root_path ||= Pathname.new(File.dirname(File.expand_path('../', __FILE__)))
51
51
  end
52
52
 
53
53
  def self.setup
54
54
  yield Config
55
55
  end
56
+
57
+ def self.activities
58
+ if defined?(Mongoid::Document)
59
+ PublicActivity::Activity.desc(:created_at)
60
+ else
61
+ PublicActivity::Activity.order("created_at DESC")
62
+ end
63
+ end
56
64
  end
57
65
 
58
66
  require 'sunrise/engine'