fae-rails 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -2
  3. data/app/assets/config/fae/manifest.js +2 -0
  4. data/app/assets/javascripts/fae/_contrast.js +50 -0
  5. data/app/assets/javascripts/fae/_deploy.js +198 -0
  6. data/app/assets/javascripts/fae/_modals.js +94 -0
  7. data/app/assets/javascripts/fae/application.js +7 -1
  8. data/app/assets/javascripts/fae/form/_ajax.js +17 -5
  9. data/app/assets/javascripts/fae/form/_filtering.js +34 -0
  10. data/app/assets/javascripts/fae/form/_form.js +5 -2
  11. data/app/assets/javascripts/fae/form/_form_manager.js +295 -0
  12. data/app/assets/javascripts/fae/form/_slugger.js.erb +2 -2
  13. data/app/assets/javascripts/fae/form/_validator.js +224 -55
  14. data/app/assets/javascripts/fae/form/drag_drop.js +109 -0
  15. data/app/assets/javascripts/fae/form/inputs/_select.js +10 -4
  16. data/app/assets/javascripts/fae/form/inputs/_text.js +23 -9
  17. data/app/assets/javascripts/fae/vendor/simplemde/codemirror-4.inline-attachment.js +95 -0
  18. data/app/assets/javascripts/fae/vendor/simplemde/inline-attachment.js +405 -0
  19. data/app/assets/stylesheets/fae/application.css +1 -0
  20. data/app/assets/stylesheets/fae/base.scss +7 -3
  21. data/app/assets/stylesheets/fae/globals/_tags.scss +1 -1
  22. data/app/assets/stylesheets/fae/globals/imports/_variables.scss +1 -0
  23. data/app/assets/stylesheets/fae/globals/layout/_base.scss +9 -4
  24. data/app/assets/stylesheets/fae/globals/layout/_content-header.scss +14 -4
  25. data/app/assets/stylesheets/fae/globals/legacy/_pre-1.3.scss +1 -1
  26. data/app/assets/stylesheets/fae/globals/navigation/_footer.scss +1 -1
  27. data/app/assets/stylesheets/fae/globals/navigation/_header.scss +3 -3
  28. data/app/assets/stylesheets/fae/globals/navigation/_multi-col-subnav.scss +50 -0
  29. data/app/assets/stylesheets/fae/globals/navigation/_sidenav.scss +2 -2
  30. data/app/assets/stylesheets/fae/globals/navigation/_utility.scss +1 -1
  31. data/app/assets/stylesheets/fae/modules/_buttons.scss +11 -0
  32. data/app/assets/stylesheets/fae/modules/_deploy.scss +25 -0
  33. data/app/assets/stylesheets/fae/modules/_errors-bar.scss +19 -0
  34. data/app/assets/stylesheets/fae/modules/_modal.scss +25 -0
  35. data/app/assets/stylesheets/fae/modules/_toggles.scss +39 -23
  36. data/app/assets/stylesheets/fae/modules/forms/_asset-actions.scss +1 -1
  37. data/app/assets/stylesheets/fae/modules/forms/_base.scss +14 -1
  38. data/app/assets/stylesheets/fae/modules/forms/_checkbox.scss +1 -1
  39. data/app/assets/stylesheets/fae/modules/forms/_date.scss +20 -4
  40. data/app/assets/stylesheets/fae/modules/forms/_form-manager.scss +82 -0
  41. data/app/assets/stylesheets/fae/modules/forms/_hints.scss +1 -1
  42. data/app/assets/stylesheets/fae/modules/forms/_label.scss +1 -1
  43. data/app/assets/stylesheets/fae/modules/forms/_radio.scss +1 -1
  44. data/app/assets/stylesheets/fae/modules/forms/_select.scss +9 -8
  45. data/app/assets/stylesheets/fae/modules/forms/_simple-mde.scss +72 -1
  46. data/app/assets/stylesheets/fae/modules/forms/_textarea.scss +1 -1
  47. data/app/assets/stylesheets/fae/modules/tables/_base.scss +1 -1
  48. data/app/assets/stylesheets/fae/modules/tables/_filters.scss +4 -0
  49. data/app/assets/stylesheets/fae/modules/tables/_pagination.scss +2 -2
  50. data/app/assets/stylesheets/fae/pages/_error.scss +1 -1
  51. data/app/assets/stylesheets/fae/pages/_login.scss +5 -1
  52. data/app/assets/stylesheets/fae/simplemde_override.scss +32 -0
  53. data/app/controllers/fae/application_controller.rb +9 -2
  54. data/app/controllers/fae/base_controller.rb +6 -2
  55. data/app/controllers/fae/deploy_controller.rb +24 -0
  56. data/app/controllers/fae/deploy_hooks_controller.rb +71 -0
  57. data/app/controllers/fae/form_managers_controller.rb +19 -0
  58. data/app/controllers/fae/options_controller.rb +1 -0
  59. data/app/controllers/fae/setup_controller.rb +2 -2
  60. data/app/controllers/fae/static_pages_controller.rb +6 -1
  61. data/app/controllers/fae/users_controller.rb +11 -1
  62. data/app/controllers/fae/utilities_controller.rb +18 -6
  63. data/app/helpers/fae/application_helper.rb +36 -2
  64. data/app/helpers/fae/form_helper.rb +26 -2
  65. data/app/helpers/fae/view_helper.rb +26 -9
  66. data/app/models/concerns/fae/base_model_concern.rb +17 -0
  67. data/app/models/concerns/fae/seo_set_concern.rb +1 -0
  68. data/app/models/fae/change.rb +20 -6
  69. data/app/models/fae/deploy_hook.rb +12 -0
  70. data/app/models/fae/form_manager.rb +24 -0
  71. data/app/models/fae/option.rb +1 -0
  72. data/app/models/fae/seo_set.rb +14 -0
  73. data/app/models/fae/user.rb +2 -2
  74. data/app/services/fae/netlify_api.rb +213 -0
  75. data/app/uploaders/fae/file_uploader.rb +1 -1
  76. data/app/uploaders/fae/image_uploader.rb +2 -2
  77. data/app/views/devise/unlocks/new.html.slim +5 -9
  78. data/app/views/fae/application/_content_form.html.slim +16 -11
  79. data/app/views/fae/application/_file_uploader.html.slim +7 -2
  80. data/app/views/fae/application/_global_search_results.html.slim +1 -1
  81. data/app/views/fae/application/_header.slim +4 -1
  82. data/app/views/fae/application/_mobilenav.slim +3 -0
  83. data/app/views/fae/application/_seo_set_form.html.slim +12 -0
  84. data/app/views/fae/deploy/index.html.slim +40 -0
  85. data/app/views/fae/deploy_hooks/_form.html.slim +18 -0
  86. data/app/views/fae/deploy_hooks/_table.html.slim +28 -0
  87. data/app/views/fae/deploy_hooks/edit.html.slim +3 -0
  88. data/app/views/fae/deploy_hooks/new.html.slim +3 -0
  89. data/app/views/fae/images/_image_uploader.html.slim +12 -3
  90. data/app/views/fae/options/_form.html.slim +6 -2
  91. data/app/views/fae/pages/activity_log.html.slim +7 -3
  92. data/app/views/fae/pages/home.html.slim +3 -4
  93. data/app/views/fae/shared/_errors.slim +0 -3
  94. data/app/views/fae/shared/_form_header.html.slim +20 -12
  95. data/app/views/fae/shared/_nested_table.html.slim +5 -2
  96. data/app/views/fae/shared/_recent_changes.html.slim +1 -1
  97. data/app/views/fae/shared/_shared_nested_table.html.slim +9 -3
  98. data/app/views/layouts/fae/application.html.slim +2 -1
  99. data/config/deploy.rb +3 -1
  100. data/config/initializers/carrierwave.rb +41 -2
  101. data/config/initializers/devise.rb +6 -6
  102. data/config/initializers/fae_judge.rb +4 -2
  103. data/config/locales/fae.en.yml +49 -4
  104. data/config/locales/fae.zh-CN.yml +2 -2
  105. data/config/puma.rb +82 -0
  106. data/config/routes.rb +9 -1
  107. data/db/migrate/20140809222030_add_user_table.rb +1 -1
  108. data/db/migrate/20190925153222_create_fae_form_managers.rb +11 -0
  109. data/db/migrate/20220118192729_create_fae_publish_hooks.rb +10 -0
  110. data/db/migrate/20220128133730_rename_publish_hooks.rb +5 -0
  111. data/db/migrate/20220202153607_add_position_to_deploy_hooks.rb +6 -0
  112. data/db/migrate/20221118161833_create_fae_seo_sets.rb +13 -0
  113. data/lib/fae/concerns/models/base.rb +2 -0
  114. data/lib/fae/engine.rb +3 -3
  115. data/lib/fae/options.rb +18 -18
  116. data/lib/fae/version.rb +1 -1
  117. data/lib/generators/fae/base_generator.rb +28 -5
  118. data/lib/generators/fae/controller_generator.rb +0 -1
  119. data/lib/generators/fae/install_generator.rb +1 -1
  120. data/lib/generators/fae/model_generator.rb +1 -2
  121. data/lib/generators/fae/nested_index_scaffold_generator.rb +1 -2
  122. data/lib/generators/fae/nested_scaffold_generator.rb +23 -2
  123. data/lib/generators/fae/page_generator.rb +1 -2
  124. data/lib/generators/fae/scaffold_generator.rb +1 -1
  125. data/lib/generators/fae/templates/assets/fae.js +1 -1
  126. data/lib/generators/fae/templates/controllers/nested_scaffold_controller.rb +13 -1
  127. data/lib/generators/fae/templates/controllers/scaffold_controller.rb +7 -0
  128. data/lib/generators/fae/templates/initializers/fae.rb +16 -1
  129. data/lib/generators/fae/templates/views/_form.html.slim +12 -1
  130. data/lib/generators/fae/templates/views/_form_index_nested.html.slim +15 -1
  131. data/lib/generators/fae/templates/views/_form_nested.html.slim +22 -2
  132. data/lib/generators/fae/templates/views/static_page_form.html.slim +13 -1
  133. metadata +53 -24
  134. data/config/deploy/dev.rb +0 -19
  135. data/config/deploy/prod.rb +0 -19
  136. data/config/deploy/stage.rb +0 -19
  137. /data/app/assets/javascripts/fae/vendor/{simplemde.min.js → simplemde/simplemde.min.js} +0 -0
@@ -23,7 +23,78 @@
23
23
  &.mde-focus {
24
24
  .CodeMirror-wrap,
25
25
  .editor-toolbar {
26
- border-color: $c-notice-content;
26
+ border-color: $c-focus-border;
27
27
  }
28
28
  }
29
29
  }
30
+
31
+ .editor-preview,
32
+ .editor-preview-side {
33
+ h1 {
34
+ font-size: 26px;
35
+ }
36
+
37
+ h2 {
38
+ font-size: 24px;
39
+ }
40
+
41
+ h3 {
42
+ font-size: 22px;
43
+ }
44
+
45
+ h4 {
46
+ font-size: 20px;
47
+ }
48
+
49
+ h5 {
50
+ font-size: 18px;
51
+ }
52
+
53
+ h6 {
54
+ font-size: 16px;
55
+ }
56
+
57
+ h1,
58
+ h2,
59
+ h3,
60
+ h4,
61
+ h5,
62
+ h6 {
63
+ font-weight: bold;
64
+ }
65
+
66
+ h1,
67
+ h2,
68
+ h3,
69
+ h4,
70
+ h5,
71
+ h6,
72
+ p,
73
+ ul,
74
+ ol {
75
+ background: none;
76
+ border: 0;
77
+ color: black;
78
+ letter-spacing: 0;
79
+ margin: inherit;
80
+ padding: inherit;
81
+ text-transform: inherit;
82
+ }
83
+
84
+ ul {
85
+ list-style: disc;
86
+ }
87
+
88
+ ol {
89
+ list-style: decimal;
90
+ }
91
+
92
+ ul,
93
+ ol {
94
+ padding-left: 30px;
95
+ }
96
+
97
+ em {
98
+ font-style: italic;
99
+ }
100
+ }
@@ -11,6 +11,6 @@ textarea {
11
11
  border-radius: 2px;
12
12
 
13
13
  &:focus {
14
- border-color: $c-notice-content;
14
+ border-color: $c-focus-border;
15
15
  }
16
16
  }
@@ -22,7 +22,7 @@ tbody {
22
22
  &:hover {
23
23
  td {
24
24
  &:first-child {
25
- border-left-color: $c-custom-highlight;
25
+ border-left-color: var(--highlight-color);
26
26
  }
27
27
  }
28
28
  }
@@ -58,4 +58,8 @@
58
58
  .table-filter-group {
59
59
  display: inline-block;
60
60
  margin: 0 30px 20px 0;
61
+
62
+ &.no-right-margin {
63
+ margin-right: 0;
64
+ }
61
65
  }
@@ -19,7 +19,7 @@
19
19
 
20
20
  &:hover {
21
21
  color: $c-white;
22
- background: $c-custom-highlight;
22
+ background: var(--highlight-color);
23
23
  }
24
24
  }
25
25
 
@@ -29,6 +29,6 @@
29
29
 
30
30
  .current {
31
31
  color: $c-white;
32
- background: $c-custom-highlight;
32
+ background: var(--highlight-color);
33
33
  }
34
34
  }
@@ -8,7 +8,7 @@
8
8
  min-width: 235px;
9
9
  height: 330px;
10
10
  padding: 35px;
11
- border-top: 8px solid $c-custom-highlight;
11
+ border-top: 8px solid var(--highlight-color);
12
12
  border-radius: 4px;
13
13
  background: white;
14
14
  color: $c-mid-dark-grey;
@@ -15,7 +15,7 @@
15
15
  }
16
16
 
17
17
  .login-area {
18
- border-top: 10px solid $c-custom-highlight;
18
+ border-top: 10px solid var(--highlight-color);
19
19
  margin: auto;
20
20
  border-radius: 5px;
21
21
  box-shadow: 0 0 5px 0 $c-grey;
@@ -33,6 +33,10 @@
33
33
  width: 50%;
34
34
  margin: auto;
35
35
 
36
+ h2 {
37
+ margin: 0 0 28px;
38
+ }
39
+
36
40
  @include bp(login_container) {
37
41
  display: inline-block;
38
42
  vertical-align: middle;
@@ -0,0 +1,32 @@
1
+ .editor-preview,
2
+ .editor-preview-side {
3
+ h1 { font-size: 26px; }
4
+ h2 { font-size: 24px; }
5
+ h3 { font-size: 22px; }
6
+ h4 { font-size: 20px; }
7
+ h5 { font-size: 18px; }
8
+ h6 { font-size: 16px; }
9
+
10
+ h1, h2, h3, h4, h5, h6 {
11
+ font-weight: bold;
12
+ }
13
+
14
+ h1, h2, h3, h4, h5, h6, p, ul, ol {
15
+ background: none;
16
+ border: 0;
17
+ color: black;
18
+ letter-spacing: 0;
19
+ margin: inherit;
20
+ padding: inherit;
21
+ text-transform: inherit;
22
+ }
23
+
24
+ ul { list-style: disc; }
25
+ ol { list-style: decimal; }
26
+
27
+ ul, ol {
28
+ padding-left: 30px;
29
+ }
30
+
31
+ em { font-style: italic; }
32
+ }
@@ -17,9 +17,16 @@ module Fae
17
17
  before_action :detect_cancellation
18
18
  before_action :set_change_user
19
19
  before_action :set_locale
20
+ before_action :setup_form_manager
20
21
 
21
22
  private
22
23
 
24
+ def setup_form_manager
25
+ if Fae.use_form_manager
26
+ @form_manager = FormManager.for_model(params, @item)
27
+ end
28
+ end
29
+
23
30
  # defines the locale used to translate the Fae interface
24
31
  def set_locale
25
32
  if I18n.available_locales.include?(language_from_browser)
@@ -53,7 +60,7 @@ module Fae
53
60
  end
54
61
 
55
62
  def show_404
56
- render template: 'fae/pages/error404.html.slim', layout: 'fae/error.html.slim', status: :not_found
63
+ render 'fae/pages/error404', layout: 'fae/error', status: :not_found
57
64
  end
58
65
 
59
66
  def set_option
@@ -118,7 +125,7 @@ module Fae
118
125
 
119
126
  def load_and_filter_models
120
127
  # load of all models since Rails caches activerecord queries.
121
- Rails.application.eager_load!
128
+ Zeitwerk::Loader.eager_load_all
122
129
  ActiveRecord::Base.descendants.map.reject { |m| m.name['Fae::'] || !m.instance_methods.include?(:fae_display_field) || Fae.dashboard_exclusions.include?(m.name) || !authorize_model(m) }
123
130
  end
124
131
 
@@ -16,7 +16,7 @@ module Fae
16
16
  end
17
17
  respond_to do |format|
18
18
  format.html
19
- format.csv { send_data @items.to_csv, filename: @items.name.parameterize + "." + Time.now.to_s(:filename) + '.csv' }
19
+ format.csv { send_data @items.to_csv, filename: @items.name.parameterize + "." + Time.now.to_fs(:filename) + '.csv' }
20
20
  end
21
21
  end
22
22
 
@@ -35,7 +35,11 @@ module Fae
35
35
  @item = @klass.new(item_params)
36
36
 
37
37
  if @item.save
38
- redirect_to @index_path, notice: t('fae.save_notice')
38
+ if @item.try(:fae_redirect_to_form_on_create)
39
+ redirect_to send("edit_admin_#{@klass_singular}_path", @item.id), notice: t('fae.save_notice')
40
+ else
41
+ redirect_to @index_path, notice: t('fae.save_notice')
42
+ end
39
43
  else
40
44
  build_assets
41
45
  flash[:alert] = t('fae.save_error')
@@ -0,0 +1,24 @@
1
+ module Fae
2
+ class DeployController < ApplicationController
3
+ before_action :admin_only
4
+
5
+ include Fae::ApplicationHelper
6
+
7
+ def index
8
+ raise 'Fae.netlify configs are missing.' unless netlify_enabled?
9
+ @deploy_hooks = DeployHook.all
10
+ end
11
+
12
+ def deploys_list
13
+ render json: Fae::NetlifyApi.new().get_deploys
14
+ end
15
+
16
+ def deploy_site
17
+ if Fae::NetlifyApi.new().run_deploy(params['deploy_hook_type'], current_user)
18
+ return render json: { success: true }
19
+ end
20
+ render json: {success: false}
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,71 @@
1
+ module Fae
2
+ class DeployHooksController < ApplicationController
3
+
4
+ before_action :super_admin_only
5
+ before_action :set_deploy_hook, only: [:show, :edit, :update, :destroy]
6
+ layout false
7
+
8
+ def index
9
+ @deploy_hooks = DeployHook.all
10
+ end
11
+
12
+ def new
13
+ @deploy_hook = DeployHook.new
14
+ end
15
+
16
+ def edit
17
+ end
18
+
19
+ def create
20
+ @deploy_hook = DeployHook.new(deploy_hook_params)
21
+
22
+ if @deploy_hook.save
23
+ flash[:notice] = t('fae.save_notice')
24
+ @deploy_hooks = DeployHook.all
25
+ render partial: table_template_path
26
+ else
27
+ render action: 'new'
28
+ end
29
+ end
30
+
31
+ def update
32
+ if @deploy_hook.update(deploy_hook_params)
33
+ flash[:notice] = t('fae.save_notice')
34
+ @deploy_hooks = DeployHook.all
35
+ render partial: table_template_path
36
+ else
37
+ render action: 'edit'
38
+ end
39
+ end
40
+
41
+ def destroy
42
+ if @deploy_hook.destroy
43
+ flash[:notice] = t('fae.delete_notice')
44
+ else
45
+ flash[:alert] = t('fae.delete_error')
46
+ end
47
+ @deploy_hooks = DeployHook.all
48
+ render partial: table_template_path
49
+ end
50
+
51
+ private
52
+
53
+ def set_deploy_hook
54
+ @deploy_hook = DeployHook.find(params[:id])
55
+ end
56
+
57
+ def deploy_hook_params
58
+ params.require(:deploy_hook).permit!
59
+ end
60
+
61
+ def set_index_path
62
+ # @index_path determines form's cancel btn path
63
+ @index_path = deploy_hooks_path
64
+ end
65
+
66
+ def table_template_path
67
+ "fae/deploy_hooks/table"
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,19 @@
1
+ module Fae
2
+ class FormManagersController < ApplicationController
3
+
4
+ def update
5
+ if params[:form_manager].present?
6
+ fields_serialized = params[:form_manager][:fields].to_json
7
+ conditions = {
8
+ form_manager_model_name: params[:form_manager][:form_manager_model_name],
9
+ }
10
+ if params[:form_manager][:form_manager_model_name] == 'Fae::StaticPage'
11
+ conditions[:form_manager_model_id] = params[:form_manager][:form_manager_model_id]
12
+ end
13
+ FormManager.where(conditions).first_or_initialize.update_attribute(:fields, fields_serialized)
14
+ end
15
+ render body: nil
16
+ end
17
+
18
+ end
19
+ end
@@ -7,6 +7,7 @@ module Fae
7
7
  @option = Option.first || Option.instance
8
8
  @option.build_logo if @option.logo.blank?
9
9
  @option.build_favicon if @option.favicon.blank?
10
+ @deploy_hooks = DeployHook.all
10
11
  end
11
12
 
12
13
  # PATCH/PUT /options/1
@@ -34,11 +34,11 @@ module Fae
34
34
  private
35
35
 
36
36
  def show_404
37
- render template: 'fae/pages/error404.html.slim', layout: 'fae/error.html.slim', status: :not_found
37
+ render 'fae/pages/error404', layout: 'fae/error', status: :not_found
38
38
  end
39
39
 
40
40
  def show_401
41
- render template: 'fae/pages/error404.html.slim', layout: 'fae/error.html.slim', status: :unauthorized
41
+ render 'fae/pages/error404', layout: 'fae/error', status: :unauthorized
42
42
  end
43
43
 
44
44
  def user_params
@@ -20,7 +20,8 @@ module Fae
20
20
  redirect_to @index_path, notice: t('fae.save_notice')
21
21
  else
22
22
  build_assocs
23
- render template: "#{fae.root_path.gsub('/', '')}/content_blocks/#{params[:slug]}", error: t('fae.save_error')
23
+ flash[:alert] = t('fae.save_error')
24
+ render template: "#{fae.root_path.gsub('/', '')}/content_blocks/#{params[:slug]}"
24
25
  end
25
26
  end
26
27
 
@@ -29,6 +30,9 @@ module Fae
29
30
  # Use callbacks to share common setup or constraints between actions.
30
31
  def set_item
31
32
  @item = "#{params[:slug]}_page".classify.constantize.instance
33
+ if Fae.use_form_manager
34
+ @form_manager = FormManager.for_model(params, @item)
35
+ end
32
36
  end
33
37
 
34
38
  # set up variables so that fae partial forms work
@@ -50,5 +54,6 @@ module Fae
50
54
  @item.send(:"create_#{assoc.name}", attached_as: assoc.name.to_s) if assoc.macro == :has_one && @item.send(:"#{assoc.name}").blank?
51
55
  end
52
56
  end
57
+
53
58
  end
54
59
  end
@@ -23,6 +23,8 @@ module Fae
23
23
  end
24
24
 
25
25
  def create
26
+ authorize_role
27
+
26
28
  @user = Fae::User.new(user_params)
27
29
 
28
30
  if @user.save
@@ -33,11 +35,13 @@ module Fae
33
35
  end
34
36
 
35
37
  def update
38
+ authorize_role
39
+
36
40
  params[:user].delete(:password) if params[:user][:password].blank?
37
41
  params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
38
42
 
39
43
  if @user.update(user_params)
40
- path = current_user.super_admin? ? users_path : fae.root_path
44
+ path = current_user.super_admin_or_admin? ? users_path : fae.root_path
41
45
  redirect_to path, notice: t('fae.save_notice')
42
46
  else
43
47
  render action: 'edit', error: t('fae.save_error')
@@ -75,5 +79,11 @@ module Fae
75
79
  # @index_path determines form's cancel btn path
76
80
  @index_path = users_path
77
81
  end
82
+
83
+ def authorize_role
84
+ return if params[:user][:role_id].blank?
85
+ return if @role_collection.map(&:id).include?(params[:user][:role_id].to_i)
86
+ params[:user].delete(:role_id)
87
+ end
78
88
  end
79
89
  end
@@ -2,8 +2,9 @@ module Fae
2
2
  class UtilitiesController < ApplicationController
3
3
 
4
4
  def toggle
5
- klass = params[:object].gsub('__', '/').classify.constantize
6
- if can_toggle(klass)
5
+ klass = params[:object].gsub('__', '/').classify
6
+ if can_toggle(klass, params[:attr])
7
+ klass = klass.constantize
7
8
  klass.find(params[:id]).toggle(params[:attr]).save(validate: false)
8
9
  render body: nil
9
10
  else
@@ -42,10 +43,21 @@ module Fae
42
43
 
43
44
  private
44
45
 
45
- def can_toggle(klass)
46
- # restrict models that non-admins aren't allowed to update
47
- restricted_classes = %w(Fae::User Fae::Role Fae::Option)
48
- return false if restricted_classes.include?(klass.name.to_s) && !current_user.super_admin_or_admin?
46
+ def can_toggle(klass, attribute)
47
+ # check if class exists and convert
48
+ return false unless Object.const_defined?(klass)
49
+ klass = klass.constantize
50
+
51
+ # allow admins to toggle Fae::User#active
52
+ return true if klass == Fae::User && attribute == 'active' && current_user.super_admin_or_admin?
53
+
54
+ # restrict models that only super admins can toggle
55
+ restricted_classes = %w(Fae::User Fae::Role Fae::Option Fae::Change)
56
+ return false if restricted_classes.include?(klass.name.to_s) && !current_user.super_admin?
57
+
58
+ # restrict to only other boolean fields
59
+ return false unless klass.columns_hash[attribute].type == :boolean
60
+
49
61
  true
50
62
  end
51
63
 
@@ -22,12 +22,16 @@ module Fae
22
22
  new_klass
23
23
  end
24
24
 
25
+ def deployments_active_class
26
+ '-parent-current -open' if params[:controller].split('/').last == 'deploy'
27
+ end
28
+
25
29
  def col_name_or_image(item, attribute)
26
30
  value = item.send(attribute)
27
31
  return if value.blank?
28
32
  # if item is an image
29
33
  if value.class.name == 'Fae::Image'
30
- image_tag(value.asset.thumb.url) if value.asset.thumb.url.present?
34
+ image_tag(nested_table_thumb_url(value), class: 'addedit-form-thumb') if nested_table_thumb_url(value).present?
31
35
  # if item's attribute is an association
32
36
  elsif item.class.reflections.include?(attribute)
33
37
  value.try(:fae_display_field)
@@ -72,7 +76,9 @@ module Fae
72
76
  begin
73
77
  return link_to text, fae.edit_content_block_path(change.changeable.slug) if change.changeable_type == 'Fae::StaticPage'
74
78
  parent = change.changeable.respond_to?(:fae_parent) ? change.changeable.fae_parent : nil
75
- edit_path = edit_polymorphic_path([main_app, fae_scope, parent, change.changeable])
79
+ edit_path = edit_polymorphic_path(
80
+ [main_app, fae_scope.to_sym, parent, change.changeable]
81
+ )
76
82
  return link_to text, edit_path
77
83
  rescue
78
84
  return text
@@ -80,6 +86,15 @@ module Fae
80
86
  end
81
87
  end
82
88
 
89
+ def netlify_enabled?
90
+ Fae.netlify.present? &&
91
+ Fae.netlify[:api_user].present? &&
92
+ Fae.netlify[:api_token].present? &&
93
+ Fae.netlify[:site].present? &&
94
+ Fae.netlify[:site_id].present? &&
95
+ Fae.netlify[:api_base].present?
96
+ end
97
+
83
98
  private
84
99
 
85
100
  def nav_path_current?(path)
@@ -110,5 +125,24 @@ module Fae
110
125
  "#{item.class.name.underscore.gsub('/', '_').pluralize}_#{item.id}"
111
126
  end
112
127
 
128
+ def multi_column_nav_ul_class(item_count)
129
+ num = item_count.length
130
+ if num > 30
131
+ 'multicol-nav four'
132
+ elsif num > 20
133
+ 'multicol-nav three'
134
+ elsif num > 10
135
+ 'multicol-nav'
136
+ end
137
+ end
138
+
139
+ def nested_table_thumb_url(image)
140
+ return unless image.asset.file
141
+ if image.asset.file.extension.downcase == 'svg'
142
+ image.asset.url
143
+ else
144
+ image.asset.thumb.url
145
+ end
146
+ end
113
147
  end
114
148
  end
@@ -11,6 +11,8 @@ module Fae
11
11
  add_input_class(options, 'js-markdown-editor') if options[:markdown].present?
12
12
  add_input_class(options, 'js-html-editor') if options[:html].present?
13
13
 
14
+ set_form_manager_container_attr(f, options, attribute) unless options[:show_form_manager] == false
15
+
14
16
  set_maxlength(f, attribute, options)
15
17
 
16
18
  f.input attribute, options
@@ -22,6 +24,8 @@ module Fae
22
24
  list_order f, attribute, options
23
25
  set_prompt f, attribute, options if !options[:include_blank].is_a?(String)
24
26
 
27
+ set_form_manager_container_attr(f, options, attribute) unless options[:show_form_manager] == false
28
+
25
29
  f.association attribute, options
26
30
  end
27
31
 
@@ -46,7 +50,8 @@ module Fae
46
50
 
47
51
  def fae_checkbox(f, attribute, options={})
48
52
  options[:type] ||= 'stacked'
49
- options.update(as: :check_boxes, wrapper_class: "checkbox-wrapper js-checkbox-wrapper #{options[:wrapper_class]} -#{options[:type]}", no_label_div: true)
53
+ options[:input_type] ||= :check_boxes
54
+ options.update(as: options[:input_type], wrapper_class: "input checkbox-wrapper js-checkbox-wrapper #{options[:wrapper_class]} -#{options[:type]}", no_label_div: true)
50
55
  association_or_input f, attribute, options
51
56
  end
52
57
 
@@ -125,7 +130,7 @@ module Fae
125
130
  label = options[:label] || label_translation(attribute) || attribute_name
126
131
  if options[:markdown_supported].present? || options[:helper_text].present?
127
132
  label += content_tag :h6, class: 'helper_text' do
128
- concat(options[:helper_text]) if options[:helper_text].present?
133
+ concat(content_tag(:span, options[:helper_text], class: 'helper_text_text')) if options[:helper_text].present?
129
134
  concat(content_tag(:span, 'Markdown Supported', class: 'markdown-support')) if options[:markdown_supported].present?
130
135
  end
131
136
  end
@@ -188,6 +193,25 @@ module Fae
188
193
  end
189
194
  end
190
195
 
196
+ def add_wrapper_class(options, class_name)
197
+ if options.key?(:wrapper_html)
198
+ options[:wrapper_html].merge!({class: "#{options[:wrapper_html][:class]} #{class_name}"})
199
+ else
200
+ options[:wrapper_html] = { class: class_name }
201
+ end
202
+ end
203
+
204
+ def set_form_manager_container_attr(f, options, attribute)
205
+ form_manager_id = f.object.class.name
206
+ form_manager_id = f.object.attached_as if f.object.try(:attached_as)
207
+ form_manager_id += "_#{attribute}"
208
+ if options.key?(:wrapper_html)
209
+ options[:wrapper_html]['data-form-manager-id'] = form_manager_id
210
+ else
211
+ options[:wrapper_html] = { 'data-form-manager-id' => form_manager_id }
212
+ end
213
+ end
214
+
191
215
  # sets collection to class.for_fae_index if not defined
192
216
  def list_order(f, attribute, options)
193
217
  if is_association?(f, attribute) && !options[:collection]