home_page 0.0.5 → 0.0.6

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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/home_page/application.js +8 -1
  3. data/app/assets/javascripts/home_page/base.js.coffee.erb +44 -0
  4. data/app/assets/javascripts/home_page/lib/jquery.multisortable.js +254 -0
  5. data/app/assets/javascripts/home_page/page_module_collections/index.js.coffee +14 -0
  6. data/app/assets/javascripts/home_page/shared/sortable_list.js.coffee +44 -0
  7. data/app/assets/stylesheets/home_page/application.css +4 -0
  8. data/app/assets/stylesheets/home_page/bootswatch.css.less +4 -0
  9. data/app/assets/stylesheets/vendors/keen/dashboards.css +59 -0
  10. data/app/controllers/home_page/application_controller.rb +24 -0
  11. data/app/controllers/page_module_collections_controller.rb +96 -0
  12. data/app/controllers/page_module_collections_modules_controller.rb +43 -0
  13. data/app/controllers/page_modules_controller.rb +121 -0
  14. data/app/controllers/settings_controller.rb +30 -0
  15. data/app/controllers/users_controller.rb +7 -3
  16. data/app/helpers/home_page/application_helper.rb +22 -0
  17. data/app/helpers/home_page/form_helper.rb +23 -0
  18. data/app/helpers/home_page/show_helper.rb +67 -0
  19. data/app/models/page_module.rb +78 -0
  20. data/app/models/page_module_collection.rb +24 -0
  21. data/app/models/page_module_collection_module.rb +8 -0
  22. data/app/models/setting.rb +26 -0
  23. data/app/views/apis/volontariat/_settings.html.erb +5 -0
  24. data/app/views/layouts/application.html.erb +2 -1
  25. data/app/views/layouts/fluid/without_rows.html.erb +17 -0
  26. data/app/views/layouts/shared/_foot.html.erb +9 -1
  27. data/app/views/layouts/shared/_modal.html.erb +16 -0
  28. data/app/views/page_module_collections/_collection.html.erb +18 -0
  29. data/app/views/page_module_collections/_form.html.erb +29 -0
  30. data/app/views/page_module_collections/_page_module.html.erb +27 -0
  31. data/app/views/page_module_collections/_page_module_collection.html.erb +41 -0
  32. data/app/views/page_module_collections/destroy.js.erb +9 -0
  33. data/app/views/page_module_collections/edit.html.erb +3 -0
  34. data/app/views/page_module_collections/index.html.erb +67 -0
  35. data/app/views/page_module_collections/new.html.erb +3 -0
  36. data/app/views/page_module_collections/show.html.erb +44 -0
  37. data/app/views/page_module_collections/update.js.erb +11 -0
  38. data/app/views/page_module_collections_modules/_fields.html.erb +10 -0
  39. data/app/views/page_module_collections_modules/create.js.erb +8 -0
  40. data/app/views/page_module_collections_modules/destroy.js.erb +9 -0
  41. data/app/views/page_module_collections_modules/new.html.erb +27 -0
  42. data/app/views/page_modules/_actions.html.erb +26 -0
  43. data/app/views/page_modules/_collection.html.erb +19 -0
  44. data/app/views/page_modules/_fields.html.erb +52 -0
  45. data/app/views/page_modules/_form.html.erb +25 -0
  46. data/app/views/page_modules/_page_module.html.erb +14 -0
  47. data/app/views/page_modules/_tab.html.erb +39 -0
  48. data/app/views/page_modules/destroy.js.erb +9 -0
  49. data/app/views/page_modules/edit.html.erb +3 -0
  50. data/app/views/page_modules/new.html.erb +3 -0
  51. data/app/views/page_modules/update.js.erb +11 -0
  52. data/app/views/settings/_apis.html.erb +20 -0
  53. data/app/views/settings/index.html.erb +13 -0
  54. data/app/views/settings/plugins/home_page/_panel.html.erb +42 -0
  55. data/app/views/settings/plugins/home_page/tabs/_apis.html.erb +24 -0
  56. data/app/views/shared/_javascript_response.js.erb +50 -0
  57. data/app/views/shared/layouts/_modal.html.erb +14 -0
  58. data/app/views/users/index.html.erb +5 -1
  59. data/app/views/users/show.html.erb +5 -0
  60. data/config/initializers/default_settings.rb +8 -0
  61. data/config/locales/general/en.yml +33 -2
  62. data/config/locales/resources/page_module/en.yml +34 -0
  63. data/config/locales/resources/page_module_collection/en.yml +21 -0
  64. data/config/locales/resources/setting/en.yml +26 -0
  65. data/config/routes.rb +18 -1
  66. data/db/migrate/20150307193102_create_friendly_id_slugs.rb +3 -3
  67. data/db/migrate/20150313154924_create_settings.rb +17 -0
  68. data/db/migrate/20150315082328_create_page_modules_and_page_module_collections.rb +43 -0
  69. data/lib/home_page.rb +9 -0
  70. data/lib/home_page/api_provider_host.rb +54 -0
  71. data/lib/home_page/engine.rb +1 -0
  72. data/lib/home_page/navigation.rb +62 -21
  73. data/lib/home_page/pagination_metadata.rb +1 -2
  74. data/lib/home_page/simple_navigation_renderer/breadcrumbs_without_method_links.rb +6 -2
  75. data/lib/home_page/version.rb +1 -1
  76. metadata +242 -50
  77. data/README.rdoc +0 -3
  78. data/config/initializers/volontariat.rb +0 -3
@@ -27,6 +27,30 @@ class HomePage::ApplicationController < ActionController::Base
27
27
 
28
28
  private
29
29
 
30
+ def render_or_redirect_by_request_type
31
+ if request.xhr? || request.env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
32
+ render_javascript_response
33
+ elsif @template.present?
34
+ render @template
35
+ elsif @path.present?
36
+ redirect_to @path
37
+ end
38
+ end
39
+
40
+ def render_javascript_response
41
+ @method ||= :get
42
+ @data ||= {}
43
+ @template_namespace ||= controller_name
44
+ @template ||= action_name unless @path.present?
45
+ @template_format ||= 'html'
46
+ @target ||= "#modal"
47
+ @target_needs_modal_layout = @target_needs_modal_layout.nil? ? true : @target_needs_modal_layout
48
+ @modal_title ||= I18n.t("#{controller_name}.#{action_name}.title")
49
+ @close_modal ||= false
50
+
51
+ render partial: 'shared/javascript_response.js', layout: false
52
+ end
53
+
30
54
  def custom_view_path
31
55
  prepend_view_path 'app/views/custom'
32
56
  end
@@ -0,0 +1,96 @@
1
+ class PageModuleCollectionsController < ApplicationController
2
+ respond_to :html, :js
3
+
4
+ before_filter :authenticate_user!
5
+ before_filter :show_breadcrumbs, except: :index
6
+
7
+ def index
8
+ slug_stub = if params[:slug_stub].blank?
9
+ @page_module_collection_slug_stubs = PageModuleCollection.pluck(:slug_stub).uniq.sort
10
+ @page_module_collection_slug_stubs.first
11
+ else
12
+ params[:slug_stub]
13
+ end
14
+
15
+ @page_module_collections = PageModuleCollection.where(slug_stub: slug_stub).paginate(page: params[:page], per_page: 10)
16
+
17
+ if params[:slug_stub].blank?
18
+ @page_module_slug_stubs = PageModule.pluck(:slug_stub).uniq.sort
19
+ @page_modules = PageModule.where(slug_stub: @page_module_slug_stubs.first).paginate(page: params[:module_page], per_page: 10)
20
+ end
21
+
22
+ render partial: 'page_module_collections/collection', layout: false if params[:slug_stub].present?
23
+ end
24
+
25
+ def new
26
+ @page_module_collection = PageModuleCollection.new(params[:page_module_collection])
27
+ end
28
+
29
+ def create
30
+ @page_module_collection = PageModuleCollection.create(params[:page_module_collection])
31
+
32
+ if @page_module_collection.persisted?
33
+ @path = page_module_collections_path
34
+
35
+ if request.xhr?
36
+ @target = '#page'
37
+ @close_modal = true
38
+ end
39
+ else
40
+ @template = :new
41
+ @target = '.modal-content' if request.xhr?
42
+ end
43
+
44
+ @target_needs_modal_layout = false if request.xhr?
45
+
46
+ render_or_redirect_by_request_type
47
+ end
48
+
49
+ def show
50
+ @page_module_collection = PageModuleCollection.friendly.find(params[:id])
51
+ @page_modules = @page_module_collection.modules.select(
52
+ 'page_modules.*, page_module_collections_modules.id AS collection_module_id, page_module_collections_modules.position'
53
+ ).order('page_module_collections_modules.position ASC')
54
+ end
55
+
56
+ def edit
57
+ @page_module_collection = PageModuleCollection.friendly.find(params[:id])
58
+ end
59
+
60
+ def update
61
+ @page_module_collection = PageModuleCollection.friendly.find(params[:id])
62
+
63
+ if @page_module_collection.update_attributes(params[:page_module_collection])
64
+ flash[:notice] = t('general.form.successfully_updated')
65
+
66
+ if request.xhr?
67
+ @template_format = 'js'
68
+ else
69
+ @path = edit_page_module_collection_path(@page_module_collection)
70
+ end
71
+ else
72
+ @template = :edit
73
+ @target = '.modal-content' if request.xhr?
74
+ end
75
+
76
+ @target_needs_modal_layout = false if request.xhr?
77
+
78
+ render_or_redirect_by_request_type
79
+ end
80
+
81
+ def destroy
82
+ @page_module_collection = PageModuleCollection.friendly.find(params[:id]).destroy
83
+
84
+ if @page_module_collection.persisted?
85
+ flash[:alert] = I18n.t('general.form.destroy_failed')
86
+ else
87
+ flash[:notice] = I18n.t('general.form.destroyed')
88
+ end
89
+
90
+ redirect_to page_module_collections_path unless request.xhr?
91
+ end
92
+
93
+ def resource
94
+ @page_module_collection
95
+ end
96
+ end
@@ -0,0 +1,43 @@
1
+ class PageModuleCollectionsModulesController < ApplicationController
2
+ respond_to :html, :js
3
+
4
+ before_filter :authenticate_user!
5
+
6
+ def create
7
+ @page_module_collection = PageModuleCollection.find(params[:page_module_collection_module][:collection_id])
8
+
9
+ if params[:page_module_collection_module][:module_id].to_i == 0
10
+ @template_namespace = 'page_modules'
11
+ @template = 'new'
12
+ @page_module = PageModule.new(params[:page_module])
13
+ @page_module.collection_id = @page_module_collection.id
14
+ @target_needs_modal_layout = false
15
+ @target = '.modal-content'
16
+
17
+ render_or_redirect_by_request_type
18
+ else
19
+ @page_module = PageModule.find params[:page_module_collection_module][:module_id]
20
+ @page_module_collection.modules << @page_module
21
+ page_module_collection_module = PageModuleCollectionModule.where(collection_id: @page_module_collection.id).order('position DESC').first
22
+ @collection_module_id = page_module_collection_module.id
23
+ @position = page_module_collection_module.position
24
+ @template_format = 'js'
25
+ end
26
+ end
27
+
28
+ def destroy
29
+ @page_module_collection_module = PageModuleCollectionModule.find(params[:id]).destroy
30
+
31
+ if @page_module_collection_module.persisted?
32
+ flash[:alert] = I18n.t('general.form.destroy_failed')
33
+ else
34
+ flash[:notice] = I18n.t('general.form.destroyed')
35
+ end
36
+
37
+ redirect_to page_module_collection_path(@page_module_collection_module.collection) unless request.xhr?
38
+ end
39
+
40
+ def resource
41
+ @page_module || @page_module_collection_module
42
+ end
43
+ end
@@ -0,0 +1,121 @@
1
+ class PageModulesController < ApplicationController
2
+ respond_to :html, :js
3
+
4
+ before_filter :authenticate_user!
5
+
6
+ def index
7
+ slug_stub = if params[:slug_stub].blank?
8
+ @page_module_slug_stubs = PageModule.pluck(:slug_stub).uniq.sort
9
+ @page_module_slug_stubs.first
10
+ else
11
+ params[:slug_stub]
12
+ end
13
+
14
+ @page_modules = PageModule.where(slug_stub: slug_stub).paginate(page: params[:page], per_page: 10)
15
+
16
+ if params[:slug_stub].present?
17
+ render partial: 'page_modules/collection', layout: false
18
+ else
19
+ render partial: 'page_modules/tab', layout: false
20
+ end
21
+ end
22
+
23
+ def new
24
+ if params[:page_module_collection_id].present?
25
+ @page_module_collection = PageModuleCollection.friendly.find(params[:page_module_collection_id])
26
+ @page_module_collection_module = PageModuleCollectionModule.new(params[:page_module_collection_module])
27
+ @page_module_collection_module.collection_id = @page_module_collection.id
28
+ @page_modules = PageModule
29
+ module_ids = @page_module_collection.modules.map(&:id)
30
+ @page_modules = @page_modules.where('id NOT IN(?)', module_ids) if module_ids.any?
31
+ @page_modules = @page_modules.order('title ASC').map{|p| [p.title, p.id]}
32
+
33
+ render template: 'page_module_collections_modules/new'
34
+ else
35
+ @page_module = PageModule.new(params[:page_module])
36
+ end
37
+ end
38
+
39
+ def create
40
+ @page_module = PageModule.create(params[:page_module])
41
+ @page_module.collection_id = params[:page_module][:collection_id]
42
+
43
+ if @page_module.persisted?
44
+ if @page_module.collection_id.present?
45
+ @path = page_module_collections_modules_path
46
+ @method = 'post'
47
+ @data = { page_module_collection_module: { collection_id: @page_module.collection_id, module_id: @page_module.id } }
48
+ @template_format = 'js'
49
+ else
50
+ @path = page_modules_path
51
+
52
+ if request.xhr?
53
+ @target = '#page_modules_tab'
54
+ @close_modal = true
55
+ end
56
+ end
57
+ else
58
+ @template = :new
59
+
60
+ if request.xhr?
61
+ @target = '.modal-content'
62
+ @target_needs_modal_layout = false
63
+ end
64
+ end
65
+
66
+ render_or_redirect_by_request_type
67
+ end
68
+
69
+ def edit
70
+ @page_module = PageModule.friendly.find(params[:id])
71
+ end
72
+
73
+ def update
74
+ @page_module = PageModule.friendly.find(params[:id])
75
+
76
+ if @page_module.update_attributes(params[:page_module])
77
+ flash[:notice] = t('general.form.successfully_updated')
78
+
79
+ if request.xhr?
80
+ @template_format = 'js'
81
+ else
82
+ @path = edit_page_module_path(@page_module)
83
+ end
84
+ else
85
+ @template = :edit
86
+ @target = '.modal-content' if request.xhr?
87
+ end
88
+
89
+ render_or_redirect_by_request_type
90
+ end
91
+
92
+ def move
93
+ page_module_collection = PageModuleCollection.friendly.find(params[:page_module_collection_id])
94
+ page_module_collection_modules = page_module_collection.page_module_collection_modules.
95
+ where('page_module_collections_modules.id IN(?)', params[:positions].values).index_by(&:id)
96
+
97
+ params[:positions].keys.map(&:to_i).sort.each do |position|
98
+ id = params[:positions][position.to_s]
99
+ page_module_collection_modules[id.to_i].reload
100
+ page_module_collection_modules[id.to_i].insert_at(position.to_i)
101
+ end
102
+
103
+ render nothing: true
104
+ end
105
+
106
+ def destroy
107
+ @page_module = PageModule.friendly.find(params[:id]).destroy
108
+
109
+ if @page_module.persisted?
110
+ flash[:alert] = I18n.t('general.form.destroy_failed')
111
+ else
112
+ flash[:notice] = I18n.t('general.form.destroyed')
113
+ end
114
+
115
+ redirect_to page_modules_path unless request.xhr?
116
+ end
117
+
118
+ def resource
119
+ @page_module_collection_module || @page_module
120
+ end
121
+ end
@@ -0,0 +1,30 @@
1
+ class SettingsController < ApplicationController
2
+ respond_to :html
3
+
4
+ before_filter :authenticate_user!
5
+
6
+ def index
7
+ @settings = Setting.unscoped.index_by(&:var)
8
+ end
9
+
10
+ def show
11
+ render json: Setting[params[:id2] || params[:id]].to_json
12
+ end
13
+
14
+ def updates
15
+ @settings = Setting.unscoped.index_by(&:var)
16
+
17
+ params[:setting].each do |var, value|
18
+ next if @settings[var].nil? && (value.nil? || value.strip == '')
19
+
20
+ if @settings[var] && value.strip == ''
21
+ Setting.destroy var
22
+ else
23
+ value = Setting.new(var: var, value: value).cast_value
24
+ Setting[var] = value
25
+ end
26
+ end
27
+
28
+ redirect_to settings_path, notice: t('settings.updates.done')
29
+ end
30
+ end
@@ -1,12 +1,16 @@
1
1
  class UsersController < ApplicationController
2
- before_filter :find_resource, only: [:edit, :update, :destroy]
2
+ before_filter :find_resource, only: [:show, :edit, :update, :destroy]
3
3
 
4
4
  respond_to :html
5
5
 
6
6
  before_filter :authenticate_user!
7
+ before_filter :show_breadcrumbs, except: :index
7
8
 
8
9
  def index
9
- @users = User.order('name ASC')
10
+ @users = User.order('name ASC').paginate(page: params[:page], per_page: 10)
11
+ end
12
+
13
+ def show
10
14
  end
11
15
 
12
16
  def edit
@@ -14,7 +18,7 @@ class UsersController < ApplicationController
14
18
 
15
19
  def update
16
20
  if params[:user][:password].present? ? @user.update_attributes(params[:user]) : @user.update_without_password(params[:user])
17
- redirect_to edit_user_path(current_user), notice: t('general.form.successfully_updated')
21
+ redirect_to edit_user_path(@user), notice: t('general.form.successfully_updated')
18
22
  else
19
23
  render :edit
20
24
  end
@@ -2,6 +2,21 @@ module HomePage
2
2
  module ApplicationHelper
3
3
  include AutoHtml
4
4
 
5
+ def self.root_model_class_name_helper(resource)
6
+ if resource.class.superclass.name == 'ActiveRecord::Base'
7
+ resource.class.name
8
+ elsif resource.class.superclass.name == 'Object'
9
+ # classes like mongo db models without a specific superclass
10
+ resource.class.name
11
+ else
12
+ resource.class.superclass.name
13
+ end
14
+ end
15
+
16
+ def root_model_class_name(resource)
17
+ ::HomePage::ApplicationHelper.root_model_class_name_helper(resource)
18
+ end
19
+
5
20
  # Taken from https://github.com/seyhunak/twitter-bootstrap-rails
6
21
  # Modified to support html in flash message
7
22
  def bootstrap_flash_raw
@@ -56,5 +71,12 @@ module HomePage
56
71
 
57
72
  doc.to_s
58
73
  end
74
+
75
+ def attribute_translation(attribute, current_resource = nil)
76
+ current_resource = current_resource || resource
77
+ t("activerecord.attributes.#{root_model_class_name(current_resource).underscore}.#{attribute}",
78
+ default: t("attributes.#{attribute}")
79
+ )
80
+ end
59
81
  end
60
82
  end
@@ -0,0 +1,23 @@
1
+ module HomePage
2
+ module FormHelper
3
+ def setting_input(f, var, options = {})
4
+ required = options.delete(:required) || false
5
+ label = options.delete(:label)
6
+
7
+ default = Setting.defaults[var]
8
+ hint_value = default.is_a?(Array) || default.is_a?(Hash) ? default.to_json : default.inspect
9
+ value = @settings[var].try(:value)
10
+ value = if value.nil?
11
+ value
12
+ else
13
+ default.is_a?(Array) || default.is_a?(Hash) ? value.to_json : value
14
+ end
15
+
16
+ f.input(
17
+ var, label: label || t("settings.vars.#{var}"), input_html: { id: var.gsub(/\./, '_'), value: value },
18
+ hint: Setting.defaults[var].nil? ? nil : t('settings.index.default_value', value: hint_value),
19
+ required: required
20
+ )
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,67 @@
1
+ module HomePage
2
+ module ShowHelper
3
+ def show_attributes(*attributes)
4
+ result = ''
5
+
6
+ attributes.each {|attribute| result += show_attribute attribute}
7
+
8
+ raw result
9
+ end
10
+
11
+ def show_attribute(attribute, options = {})
12
+ title = options[:title] || attribute_translation(attribute)
13
+ value = options[:value] || resource.send(attribute)
14
+
15
+ value.blank? ? '' : content_tag(:dt, title) + content_tag(:dd, value)
16
+ end
17
+
18
+ def show_associations(*associations)
19
+ result = ''
20
+
21
+ associations.each {|association| result += show_association association}
22
+
23
+ raw result
24
+ end
25
+
26
+ def show_association(association)
27
+ if association.to_s == association.to_s.pluralize
28
+ return show_attribute(
29
+ association,
30
+ title: t("#{association}.index.title"),
31
+ value: raw(resource.send(association).map{|a| link_to a.name, a}.join(', '))
32
+ )
33
+ end
34
+
35
+ title = if general_attribute?(:parent)
36
+ t("attributes.#{association}")
37
+ else
38
+ if resource.send(association)
39
+ t("activerecord.models.#{root_model_class_name(resource.send(association)).underscore}")
40
+ else
41
+ t("activerecord.models.#{association}")
42
+ end
43
+ end
44
+
45
+ if resource.send(association)
46
+ show_attribute(
47
+ association,
48
+ title: title,
49
+ value: link_to(resource.send(association).try(:name), resource.send(association))
50
+ )
51
+ else
52
+ ''
53
+ end
54
+ end
55
+
56
+ def show_actions(options = {})
57
+ result = content_tag :dt, raw('&nbsp')
58
+ result += content_tag :dd, render(
59
+ partial: 'shared/resource/actions', locals: {
60
+ type: root_model_class_name(resource).tableize, resource: resource, namespace: options[:namespace]
61
+ }
62
+ )
63
+
64
+ raw result
65
+ end
66
+ end
67
+ end