faalis 2.0.8 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +15 -9
  5. data/app/assets/javascripts/faalis/dashboard/application.js.erb +4 -3
  6. data/app/assets/javascripts/faalis/dashboard/init.js.coffee +1 -1
  7. data/{spec/dummy/public/favicon.ico → app/assets/javascripts/faalis/dashboard/lib/amd.js.coffee.erb} +0 -0
  8. data/app/assets/stylesheets/faalis/dashboard/share.scss +5 -0
  9. data/app/controllers/faalis/assets_controller.rb +6 -0
  10. data/app/controllers/faalis/dashboard/user_messages_controller.rb +27 -0
  11. data/app/models/application_record.rb +3 -0
  12. data/app/models/faalis/group.rb +4 -3
  13. data/app/models/faalis/permission.rb +2 -2
  14. data/app/models/faalis/user.rb +1 -7
  15. data/app/models/faalis/user_message.rb +6 -0
  16. data/app/policies/faalis/user_message_policy.rb +9 -0
  17. data/app/policies/faalis/user_policy.rb +1 -1
  18. data/app/views/faalis/dashboard/resource/edit.html.slim +1 -1
  19. data/app/views/faalis/dashboard/resource/show.html.slim +1 -2
  20. data/app/views/faalis/dashboard/shared/_header.html.erb +2 -2
  21. data/app/views/faalis/dashboard/user_messages/_form.html.slim +0 -0
  22. data/app/views/faalis/dashboard/user_messages/create.js.erb +0 -0
  23. data/app/views/faalis/dashboard/user_messages/destroy.js.erb +0 -0
  24. data/app/views/faalis/dashboard/user_messages/new.html.slim +72 -0
  25. data/app/views/layouts/faalis/dashboard.html.erb +2 -1
  26. data/config/locales/faalis.en.yml +2 -1
  27. data/config/routes.rb +6 -21
  28. data/db/migrate/20160310105736_create_faalis_user_messages.rb +16 -0
  29. data/lib/faalis.rb +1 -1
  30. data/lib/faalis/configuration.rb +79 -52
  31. data/lib/faalis/dashboard/dsl.rb +1 -0
  32. data/lib/faalis/dashboard/models/sidebar.rb +42 -16
  33. data/lib/faalis/dashboard/sections/resource.rb +152 -130
  34. data/lib/faalis/dashboard/sections/resource_create.rb +1 -3
  35. data/lib/faalis/engine.rb +7 -5
  36. data/lib/faalis/orm.rb +5 -5
  37. data/lib/faalis/version.rb +1 -1
  38. data/{spec → test}/dummy/README.rdoc +0 -0
  39. data/{spec → test}/dummy/Rakefile +0 -0
  40. data/{spec → test}/dummy/app/assets/javascripts/application.js +0 -0
  41. data/{spec → test}/dummy/app/assets/javascripts/dashboard/application.js +0 -0
  42. data/{spec → test}/dummy/app/assets/stylesheets/application.css +0 -0
  43. data/{spec → test}/dummy/app/assets/stylesheets/dashboard/ltr/application.css +0 -0
  44. data/{spec → test}/dummy/app/assets/stylesheets/dashboard/rtl/application.css +0 -0
  45. data/{spec → test}/dummy/app/assets/stylesheets/ltr/application.css +0 -0
  46. data/{spec → test}/dummy/app/assets/stylesheets/rtl/application.css +0 -0
  47. data/{spec → test}/dummy/app/controllers/api_controller.rb +0 -0
  48. data/{spec → test}/dummy/app/controllers/application_controller.rb +0 -0
  49. data/{spec → test}/dummy/app/controllers/dashboard/application_controller.rb +0 -0
  50. data/{spec → test}/dummy/app/helpers/application_helper.rb +0 -0
  51. data/{spec → test}/dummy/app/policies/application_policy.rb +0 -0
  52. data/{spec → test}/dummy/app/views/layouts/application.html.erb +0 -0
  53. data/{spec → test}/dummy/bin/bundle +0 -0
  54. data/{spec → test}/dummy/bin/rails +0 -0
  55. data/{spec → test}/dummy/bin/rake +0 -0
  56. data/{spec → test}/dummy/config.ru +0 -0
  57. data/{spec → test}/dummy/config/application.rb +0 -0
  58. data/{spec → test}/dummy/config/boot.rb +0 -0
  59. data/{spec → test}/dummy/config/database.yml +0 -0
  60. data/{spec → test}/dummy/config/environment.rb +0 -0
  61. data/{spec → test}/dummy/config/environments/development.rb +0 -0
  62. data/{spec → test}/dummy/config/environments/production.rb +0 -0
  63. data/{spec → test}/dummy/config/environments/test.rb +2 -0
  64. data/{spec → test}/dummy/config/initializers/backtrace_silencers.rb +0 -0
  65. data/{spec → test}/dummy/config/initializers/devise.rb +0 -0
  66. data/{spec → test}/dummy/config/initializers/faalis.rb +0 -0
  67. data/{spec → test}/dummy/config/initializers/faalis_assets.rb +0 -0
  68. data/{spec → test}/dummy/config/initializers/filter_parameter_logging.rb +0 -0
  69. data/{spec → test}/dummy/config/initializers/formstatic.rb +0 -0
  70. data/{spec → test}/dummy/config/initializers/formtastic.rb +0 -0
  71. data/{spec → test}/dummy/config/initializers/inflections.rb +0 -0
  72. data/{spec → test}/dummy/config/initializers/kaminari_config.rb +0 -0
  73. data/{spec → test}/dummy/config/initializers/mime_types.rb +0 -0
  74. data/{spec → test}/dummy/config/initializers/secret_token.rb +0 -0
  75. data/{spec → test}/dummy/config/initializers/session_store.rb +0 -0
  76. data/{spec → test}/dummy/config/initializers/wrap_parameters.rb +0 -0
  77. data/{spec → test}/dummy/config/locales/en.yml +0 -0
  78. data/{spec → test}/dummy/config/routes.rb +0 -0
  79. data/test/dummy/db/test.sqlite3 +0 -0
  80. data/{spec → test}/dummy/lib/templates/slim/scaffold/_form.html.slim +0 -0
  81. data/test/dummy/log/test.log +0 -0
  82. data/{spec → test}/dummy/public/404.html +0 -0
  83. data/{spec → test}/dummy/public/422.html +0 -0
  84. data/{spec → test}/dummy/public/500.html +0 -0
  85. data/test/dummy/public/favicon.ico +0 -0
  86. data/test/fabricators/faalis/groups.rb +27 -0
  87. data/test/fabricators/faalis/permissions.rb +14 -0
  88. data/test/fabricators/faalis/users.rb +17 -0
  89. data/test/generators/install_generator_test.rb +84 -0
  90. data/test/integration/faalis/authentication_test.rb +36 -0
  91. data/test/integration/faalis/dashboard_test.rb +64 -0
  92. data/test/test_helper.rb +72 -0
  93. metadata +291 -150
  94. metadata.gz.sig +1 -0
  95. data/app/controllers/faalis/api/v1/conversations_controller.rb +0 -120
  96. data/app/controllers/faalis/api/v1/groups_controller.rb +0 -71
  97. data/app/controllers/faalis/api/v1/logs_controller.rb +0 -12
  98. data/app/controllers/faalis/api/v1/permissions_controller.rb +0 -61
  99. data/app/controllers/faalis/api/v1/profiles_controller.rb +0 -42
  100. data/app/controllers/faalis/api/v1/users_controller.rb +0 -75
  101. data/lib/faalis_application.rb +0 -446
  102. data/lib/faalis_plugin.rb +0 -477
  103. data/spec/factories/faalis/groups.rb +0 -31
  104. data/spec/factories/faalis/permissions.rb +0 -16
  105. data/spec/factories/faalis/users.rb +0 -23
  106. data/spec/features/dashboard_spec.rb +0 -36
  107. data/spec/features/record_not_found_spec.rb +0 -24
  108. data/spec/features/sign_in_spec.rb +0 -37
  109. data/spec/generators/install_spec.rb +0 -58
  110. data/spec/models/faalis/group_spec.rb +0 -32
  111. data/spec/models/faalis/permission_spec.rb +0 -15
  112. data/spec/models/faalis/user_spec.rb +0 -100
  113. data/spec/policies/faalis/admin_only_policy_spec.rb +0 -39
  114. data/spec/policies/faalis/application_policy_spec.rb +0 -49
  115. data/spec/spec_helper.rb +0 -89
  116. data/spec/support/factory_girl.rb +0 -3
@@ -1,56 +1,83 @@
1
- module Faalis::Configuration
2
-
3
- # Configure logger
4
- mattr_accessor :logger
5
- @@logger = Logger.new(STDOUT)
6
-
7
- # Dashboard url prefix
8
- mattr_accessor :dashboard_namespace
9
- @@dashboard_namespace = :dashboard
10
-
11
- # ==> ORM configuration
12
- # Load and configure the ORM. Supports :active_record (default) and
13
- # :mongoid (bson_ext recommended) by default. Other ORMs may be
14
- # available as additional gems.
15
- # ORM name to use. either 'active_record' or 'mongoid'
16
- mattr_accessor :orm
17
-
18
- def orm=(orm_name)
19
- @@orm = orm_name
20
- require "devise/orm/#{orm_name}"
21
- end
1
+ module Faalis
2
+ module Configuration
3
+
4
+ @@modules_to_load = {}
22
5
 
23
- # We have to move this method somewhere else
24
- def collect_i18n_missing_keys=(value)
25
- if value
26
- ::I18n.exception_handler = Faalis::I18n::MissingKeyHandler.new
6
+ # Configure logger
7
+ mattr_accessor :logger do
8
+ Logger.new(STDOUT)
9
+ end
10
+
11
+ # Dashboard url prefix
12
+ mattr_accessor :dashboard_namespace do
13
+ :dashboard
14
+ end
15
+
16
+ # ==> ORM configuration
17
+ # Load and configure the ORM. Supports :active_record (default) and
18
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
19
+ # available as additional gems.
20
+ # ORM name to use. either 'active_record' or 'mongoid'
21
+ mattr_accessor :orm
22
+
23
+ def orm=(orm_name)
24
+ @@orm = orm_name
25
+ require "devise/orm/#{orm_name}"
26
+ end
27
+
28
+ # We have to move this method somewhere else
29
+ def collect_i18n_missing_keys=(value)
30
+ if value
31
+ ::I18n.exception_handler = Faalis::I18n::MissingKeyHandler.new
32
+ end
33
+ end
34
+
35
+ # Site Title
36
+ attr_accessor :site_title do
37
+ 'Faalis'
38
+ end
39
+
40
+ mattr_accessor :slug
41
+
42
+ # Dashboard default javascript manifest
43
+ mattr_accessor :dashboard_js_manifest do
44
+ 'dashboard/application.js'
27
45
  end
28
- end
29
46
 
30
- # Site Title
31
- attr_accessor :site_title
32
- @site_title = 'Faalis'
33
-
34
- mattr_accessor :slug
35
-
36
- # Dashboard default javascript manifest
37
- mattr_accessor :dashboard_js_manifest
38
- @@dashboard_js_manifest = 'dashboard/application.js'
39
-
40
- # Devise options
41
- # Include default devise modules. Others available are:
42
- # :token_authenticatable, :confirmable,
43
- # :lockable, :timeoutable and :omniauthable
44
- mattr_accessor :devise_options
45
- @@devise_options = [:database_authenticatable,
46
- :registerable,
47
- :recoverable,
48
- :rememberable,
49
- :trackable,
50
- :lockable,
51
- :timeoutable,
52
- :validatable]
53
-
54
- mattr_accessor :devise_for
55
- @@devise_for = {}
47
+ # Devise options
48
+ # Include default devise modules. Others available are:
49
+ # :token_authenticatable, :confirmable,
50
+ # :lockable, :timeoutable and :omniauthable
51
+ mattr_accessor :devise_options do
52
+ [:database_authenticatable, :registerable,
53
+ :recoverable, :rememberable, :trackable,
54
+ :lockable, :timeoutable, :validatable]
55
+ end
56
+
57
+ mattr_accessor :devise_for do
58
+ {}
59
+ end
60
+
61
+ mattr_accessor :amd_dir do
62
+ 'amd'
63
+ end
64
+
65
+ mattr_accessor :amd do
66
+ true
67
+ end
68
+
69
+ @@modules_to_load[:amd] = ['amd']
70
+
71
+ def load_dependencies_based_on_configuration
72
+
73
+ @@modules_to_load.each do |k, v|
74
+ v.map { |mod| require mod } if send(k)
75
+ end
76
+ end
77
+
78
+ def enabled?(configuration)
79
+ puts "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", configuration, @@modules_to_load.include?(configuration)
80
+ @@modules_to_load.include? configuration
81
+ end
82
+ end
56
83
  end
@@ -8,6 +8,7 @@ require_dependency 'faalis/dashboard/sections/sidebar'
8
8
 
9
9
  module Faalis::Dashboard
10
10
  module DSL
11
+
11
12
  extend ActiveSupport::Concern
12
13
 
13
14
  include Faalis::Dashboard::Sections::Resource
@@ -1,7 +1,7 @@
1
1
  module Faalis::Dashboard::Models
2
2
  class Item
3
3
 
4
- attr_reader :title, :url, :icon, :model
4
+ attr_reader :title, :url, :icon, :model, :members_only
5
5
  def initialize(title, options)
6
6
  @title = title
7
7
  @model = nil
@@ -28,11 +28,11 @@ module Faalis::Dashboard::Models
28
28
  end
29
29
 
30
30
  private
31
- def extract_options(options)
32
- options.each do |key, value|
33
- instance_variable_set("@#{key}", value)
34
- end
31
+ def extract_options(options)
32
+ options.each do |key, value|
33
+ instance_variable_set("@#{key}", value)
35
34
  end
35
+ end
36
36
  end
37
37
 
38
38
  class Menu < Item
@@ -45,6 +45,15 @@ module Faalis::Dashboard::Models
45
45
  @children << child
46
46
  end
47
47
 
48
+ def initialize(title, options)
49
+ children = options.delete :children
50
+ if children
51
+ @children = children.map do |child|
52
+ Item.new(child.delete(:title), child)
53
+ end
54
+ end
55
+ super
56
+ end
48
57
  end
49
58
 
50
59
  class RootMenu < Array
@@ -91,23 +100,40 @@ module Faalis::Dashboard::Models
91
100
 
92
101
  def faalis_entries
93
102
  menu(t('faalis.dashboard.user_management'),
94
- icon: 'fa fa-users',
95
- model: 'Faalis::User') do
103
+ icon: 'fa fa-users',
104
+ model: 'Faalis::User') do
96
105
  item(I18n.t('faalis.dashboard.users'),
97
- model: 'Faalis::User',
98
- url: Faalis::Engine.routes.url_helpers.dashboard_auth_users_path)
106
+ model: 'Faalis::User',
107
+ url: Faalis::Engine.routes.url_helpers.dashboard_auth_users_path)
99
108
 
100
109
  item(I18n.t('faalis.dashboard.groups'),
101
- model: 'Faalis::Group',
102
- url: Faalis::Engine.routes.url_helpers.dashboard_auth_groups_path)
110
+ model: 'Faalis::Group',
111
+ url: Faalis::Engine.routes.url_helpers.dashboard_auth_groups_path)
112
+
113
+ end
114
+
115
+ menu(t('faalis.dashboard.user_messages'),
116
+ icon: 'fa fa-envelope-o',
117
+ model: 'Faalis::UserMessage') do
118
+
119
+ item(I18n.t('faalis.dashboard.user_messages.inbox'),
120
+ model: 'Faalis::UserMessage',
121
+ url: Faalis::Engine.routes.url_helpers.dashboard_user_messages_path)
122
+ item(I18n.t('faalis.dashboard.user_messages.sent'),
123
+ model: 'Faalis::UserMessage',
124
+ url: Faalis::Engine.routes.url_helpers.dashboard_user_messages_path)
125
+ item(I18n.t('faalis.dashboard.user_messages.draft'),
126
+ model: 'Faalis::UserMessage',
127
+ url: Faalis::Engine.routes.url_helpers.dashboard_user_messages_path)
128
+
103
129
  end
104
130
  end
105
131
 
106
132
  private
107
- def extract_options(options)
108
- @icon = options.delete(:icon)
109
- @id = options.delete(:id)
110
- @class = options.delete(:class)
111
- end
133
+ def extract_options(options)
134
+ @icon = options.delete(:icon)
135
+ @id = options.delete(:id)
136
+ @class = options.delete(:class)
137
+ end
112
138
  end
113
139
  end
@@ -13,176 +13,175 @@ module Faalis::Dashboard::Sections
13
13
 
14
14
  protected
15
15
 
16
- def _resources
17
- instance_variable_get("@{plural_name")
18
- end
16
+ def _resources
17
+ instance_variable_get("@{plural_name")
18
+ end
19
19
 
20
- def plural_name
21
- controller_name.underscore
22
- end
20
+ def plural_name
21
+ controller_name.underscore
22
+ end
23
23
 
24
- def model_name
25
- controller_path.gsub('dashboard/', '').classify
26
- end
24
+ def model_name
25
+ "::#{controller_path.gsub('dashboard/', '').classify}"
26
+ end
27
27
 
28
- def model
29
- "::#{model_name}".constantize
30
- rescue
31
- msg = "Can't find model '::#{model_name}'. Please override \
32
- 'model' method in your dashboard controller."
33
- fail NameError, msg
34
- end
28
+ def model
29
+ model_name.constantize
30
+ rescue
31
+ msg = "Can't find model '#{model_name}'. Please override 'model' method in your dashboard controller."
32
+ fail NameError, msg
33
+ end
35
34
 
36
- def namespace
37
- pieces = controller_path.gsub('dashboard/', '').split('/')
38
- return '' if pieces.length == 1
35
+ def namespace
36
+ pieces = controller_path.gsub('dashboard/', '').split('/')
37
+ return '' if pieces.length == 1
39
38
 
40
- pieces.pop
41
- pieces.join('/')
42
- end
39
+ pieces.pop
40
+ pieces.join('/')
41
+ end
43
42
 
44
- def _route_engine
45
- if namespace.empty?
46
- Rails.application
43
+ def _route_engine
44
+ if namespace.empty?
45
+ Rails.application
46
+ else
47
+ engine = "#{namespace.split('/')[0]}::Engine".classify
48
+ if Object.const_defined? engine
49
+ engine.constantize
47
50
  else
48
- engine = "#{namespace.split('/')[0]}::Engine".classify
49
- if Object.const_defined? engine
50
- engine.constantize
51
- else
52
- logger.info 'You are using locale modules please define route_engine in your controller'
53
- Rails.application
54
- end
51
+ logger.info 'You are using locale modules please define route_engine in your controller'
52
+ Rails.application
55
53
  end
56
54
  end
55
+ end
57
56
 
58
- # Return the array of action buttons in given `property_object`.
59
- # `property_object` is an instance of once of DSL classes.
60
- def action_buttons(property_object)
61
- @_action_buttons = property_object.action_buttons || []
62
- end
57
+ # Return the array of action buttons in given `property_object`.
58
+ # `property_object` is an instance of once of DSL classes.
59
+ def action_buttons(property_object)
60
+ @_action_buttons = property_object.action_buttons || []
61
+ end
63
62
 
64
- def _engine
65
- nil
66
- end
63
+ def _engine
64
+ nil
65
+ end
67
66
 
68
67
  private
69
68
 
70
- def _route_name
71
- nil
72
- end
73
-
74
- def attachment_fields
75
- if model.respond_to? :attachment_definitions
76
- return model.attachment_definitions.keys
77
- end
69
+ def _route_name
70
+ nil
71
+ end
78
72
 
79
- []
73
+ def attachment_fields
74
+ if model.respond_to? :attachment_definitions
75
+ return model.attachment_definitions.keys
80
76
  end
81
77
 
82
- def has_attachment?
83
- !attachment_fields.empty?
84
- end
78
+ []
79
+ end
85
80
 
86
- def guess_index_route(scope = 'dashboard')
87
- scope_ = "#{scope}_"
88
- scope_ = "#{scope_}#{namespace}_" if !namespace.blank? && _engine.nil?
81
+ def has_attachment?
82
+ !attachment_fields.empty?
83
+ end
89
84
 
90
- name = controller_name
91
- if name.singularize == name.pluralize
92
- "#{scope_}#{name}_index_path"
93
- else
94
- "#{scope_}#{name}_path"
95
- end
85
+ def guess_index_route(scope = 'dashboard')
86
+ scope_ = "#{scope}_"
87
+ scope_ = "#{scope_}#{namespace}_" if !namespace.blank? && _engine.nil?
88
+
89
+ name = controller_name
90
+ if name.singularize == name.pluralize
91
+ "#{scope_}#{name}_index_path"
92
+ else
93
+ "#{scope_}#{name}_path"
96
94
  end
95
+ end
97
96
 
98
- def guess_show_route(scope = 'dashboard')
99
- scope_ = "#{scope}_"
100
- scope_ = "#{scope_}#{namespace}_" if !namespace.blank? && _engine.nil?
97
+ def guess_show_route(scope = 'dashboard')
98
+ scope_ = "#{scope}_"
99
+ scope_ = "#{scope_}#{namespace}_" if !namespace.blank? && _engine.nil?
101
100
 
102
- resource_name = controller_name.singularize.underscore
103
- "#{scope_}#{resource_name}_path".gsub('/', '_')
104
- end
101
+ resource_name = controller_name.singularize.underscore
102
+ "#{scope_}#{resource_name}_path".gsub('/', '_')
103
+ end
105
104
 
106
- def guess_edit_route(scope = 'dashboard')
107
- scope_ = "#{scope}_"
108
- scope_ = "#{scope_}#{namespace}_" if !namespace.blank? && _engine.nil?
105
+ def guess_edit_route(scope = 'dashboard')
106
+ scope_ = "#{scope}_"
107
+ scope_ = "#{scope_}#{namespace}_" if !namespace.blank? && _engine.nil?
109
108
 
110
- resource_name = controller_name.singularize.underscore
111
- "edit_#{scope_}#{resource_name}_path".gsub('/', '_')
112
- end
109
+ resource_name = controller_name.singularize.underscore
110
+ "edit_#{scope_}#{resource_name}_path".gsub('/', '_')
111
+ end
113
112
 
114
- def guess_new_route(scope = 'dashboard')
115
- scope_ = "#{scope}_"
116
- scope_ = "#{scope_}#{namespace}_" if !namespace.blank? && _engine.nil?
113
+ def guess_new_route(scope = 'dashboard')
114
+ scope_ = "#{scope}_"
115
+ scope_ = "#{scope_}#{namespace}_" if !namespace.blank? && _engine.nil?
117
116
 
118
- resource_name = controller_name.singularize.underscore
119
- "new_#{scope_}#{resource_name}_path".gsub('/', '_')
120
- end
117
+ resource_name = controller_name.singularize.underscore
118
+ "new_#{scope_}#{resource_name}_path".gsub('/', '_')
119
+ end
121
120
 
122
- def guess_edit_route(scope = 'dashboard')
123
- scope_ = "#{scope}_"
124
- scope_ = "#{scope_}#{namespace}_" if !namespace.blank? && _engine.nil?
121
+ def guess_edit_route(scope = 'dashboard')
122
+ scope_ = "#{scope}_"
123
+ scope_ = "#{scope_}#{namespace}_" if !namespace.blank? && _engine.nil?
125
124
 
126
- resource_name = controller_name.singularize.underscore
127
- "edit_#{scope_}#{resource_name}_path".gsub('/', '_')
128
- end
125
+ resource_name = controller_name.singularize.underscore
126
+ "edit_#{scope_}#{resource_name}_path".gsub('/', '_')
127
+ end
129
128
 
130
- def setup_named_routes
131
- @engine = _engine || _route_engine
132
- @index_route = guess_index_route
133
- @new_route = guess_new_route
134
- @show_route = guess_show_route
135
- @edit_route = guess_edit_route
136
- end
129
+ def setup_named_routes
130
+ @engine = _engine || _route_engine
131
+ @index_route = guess_index_route
132
+ @new_route = guess_new_route
133
+ @show_route = guess_show_route
134
+ @edit_route = guess_edit_route
135
+ end
137
136
 
138
- def successful_response(section, msg = nil)
139
- @_msg = msg
137
+ def successful_response(section, msg = nil)
138
+ @_msg = msg
140
139
 
141
- respond_to do |f|
142
- if _override_views.include? section.to_sym
143
- f.js
144
- f.html
145
- else
146
- flash[:success] = msg
147
- # Engine to fetch the route from
148
- engine = _engine || Rails.application
149
- path = engine.routes.url_helpers.send(@index_route)
150
- # TODO: We really need to put setup routed on top of this method
151
- f.js { render "faalis/dashboard/resource/#{section}" }
152
- f.html { redirect_to path }
153
- end
140
+ respond_to do |f|
141
+ if _override_views.include? section.to_sym
142
+ f.js
143
+ f.html
144
+ else
145
+ flash[:success] = msg
146
+ # Engine to fetch the route from
147
+ engine = _engine || Rails.application
148
+ path = engine.routes.url_helpers.send(@index_route)
149
+ # TODO: We really need to put setup routed on top of this method
150
+ f.js { render "faalis/dashboard/resource/#{section}" }
151
+ f.html { redirect_to path }
154
152
  end
155
153
  end
154
+ end
156
155
 
157
- def errorful_resopnse(section, msg = nil, &block)
158
- @_msg = msg
156
+ def errorful_resopnse(section, msg = nil, &block)
157
+ @_msg = msg
158
+
159
+ respond_to do |f|
160
+ if _override_views.include? section.to_sym
161
+ f.js { render :errors }
162
+ f.html { render :errors }
163
+ else
164
+ flash[:error] = msg
159
165
 
160
- respond_to do |f|
161
- if _override_views.include? section.to_sym
162
- f.js { render :errors }
163
- f.html { render :errors }
166
+ # Engine to fetch the route from
167
+ engine = _engine || Rails.application
168
+ path = engine.routes.url_helpers.send(@index_route)
169
+ # TODO: We really need to put setup routed on top of this method
170
+
171
+ f.js { render 'faalis/shared/errors' }
172
+ if block_given?
173
+ f.html(&block)
164
174
  else
165
- flash[:error] = msg
166
-
167
- # Engine to fetch the route from
168
- engine = _engine || Rails.application
169
- path = engine.routes.url_helpers.send(@index_route)
170
- # TODO: We really need to put setup routed on top of this method
171
-
172
- f.js { render 'faalis/shared/errors' }
173
- if block_given?
174
- f.html(&block)
175
- else
176
- f.html { redirect_to path }
177
- end
175
+ f.html { redirect_to path }
178
176
  end
179
177
  end
180
178
  end
179
+ end
181
180
 
182
- # TODO: Move this method to a suitable place
183
- def symbolify_keys(hash)
184
- hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
185
- end
181
+ # TODO: Move this method to a suitable place
182
+ def symbolify_keys(hash)
183
+ hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
184
+ end
186
185
 
187
186
  # The actual DSL for resource ages
188
187
  module ClassMethods
@@ -214,6 +213,29 @@ module Faalis::Dashboard::Sections
214
213
  name.constantize
215
214
  end
216
215
  end
216
+
217
+ # Specify the model name of controller. This method overrides the
218
+ # `model_class` **class method** and `model_name` instance method.
219
+ def model_name(name)
220
+ define_singleton_method :model_class do
221
+ name.constantize
222
+ end
223
+
224
+ define_method :model_name do
225
+ name
226
+ end
227
+ end
228
+
229
+ # Returns the actual model class by looking at `controller_name` and
230
+ # and `controller_path`. If user uses the `model_name` **class method**
231
+ # (the `model_name` DSL) then this method will override by the
232
+ # `model_name` defination of `model_class`
233
+ def model_class
234
+ name = controller_name
235
+ path = controller_path.gsub(name, '').gsub(/dashboard\//, '')
236
+
237
+ "#{path}#{name}".classify.constantize
238
+ end
217
239
  end
218
240
 
219
241
  end