diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 2b1c62859f..538ea29f3d 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -31,6 +31,7 @@ @use "pages/case_contacts"; @use "pages/court_dates"; @use "pages/emancipation"; +@use "pages/feature_flags"; @use "pages/login"; @use "pages/password"; @use "pages/patch_notes"; diff --git a/app/assets/stylesheets/pages/feature_flags.scss b/app/assets/stylesheets/pages/feature_flags.scss new file mode 100644 index 0000000000..cc0fd1fef4 --- /dev/null +++ b/app/assets/stylesheets/pages/feature_flags.scss @@ -0,0 +1,9 @@ +#feature-flags { + padding-top: 1em; + h1 { + padding-bottom: 1em; + } + .flag-name { + padding-right: 2em; + } +} \ No newline at end of file diff --git a/app/controllers/all_casa_admins/feature_flags_controller.rb b/app/controllers/all_casa_admins/feature_flags_controller.rb new file mode 100644 index 0000000000..c1d75f76ed --- /dev/null +++ b/app/controllers/all_casa_admins/feature_flags_controller.rb @@ -0,0 +1,10 @@ +class AllCasaAdmins::FeatureFlagsController < AllCasaAdminsController + def index + @feature_flags = FeatureFlag.all.order(name: "asc") + end + + def update + @feature_flag = FeatureFlag.find(params[:id]) + @feature_flag.update(enabled: !@feature_flag.enabled) + end +end diff --git a/app/javascript/all_casa_admin.js b/app/javascript/all_casa_admin.js index 6324ded939..97d90c31ef 100644 --- a/app/javascript/all_casa_admin.js +++ b/app/javascript/all_casa_admin.js @@ -1,4 +1,5 @@ require('./src/all_casa_admin/tables') require('./src/all_casa_admin/patch_notes') +require('./src/all_casa_admin/feature_flags') require('./src/session_timeout_poller.js') require('./src/display_app_metric.js') diff --git a/app/javascript/src/all_casa_admin/feature_flags.js b/app/javascript/src/all_casa_admin/feature_flags.js new file mode 100644 index 0000000000..e72d0419e9 --- /dev/null +++ b/app/javascript/src/all_casa_admin/feature_flags.js @@ -0,0 +1,30 @@ +$(function () { + const checkboxes = $('.form-check-input.toggle-switch') + + checkboxes.on('change', function (e) { + e.preventDefault() + const featureFlagId = $(this).data('feature-flag-id') + const uniqueCheckbox = $('#feature-checkbox-' + featureFlagId) + const csrfToken = $('meta[name=csrf-token]').attr('content') + const isChecked = this.checked + toggleSwitch(uniqueCheckbox, csrfToken, featureFlagId, isChecked) + }) + + function toggleSwitch (uniqueCheckbox, csrfToken, featureFlagId, checked) { + $.ajax({ + url: `/all_casa_admins/feature_flags/${featureFlagId}`, + method: 'PATCH', + contentType: 'application/json', + headers: { + 'X-CSRF-Token': csrfToken + }, + success: function () { + if (checked) { + uniqueCheckbox.prop('checked', true) + } else { + uniqueCheckbox.prop('checked', false) + } + } + }) + } +}) diff --git a/app/models/feature_flag.rb b/app/models/feature_flag.rb index cb7ed4391a..5b996ba80a 100644 --- a/app/models/feature_flag.rb +++ b/app/models/feature_flag.rb @@ -1,4 +1,5 @@ class FeatureFlag < ApplicationRecord + validates :name, presence: true, uniqueness: true end # == Schema Information diff --git a/app/views/all_casa_admins/feature_flags/index.html.erb b/app/views/all_casa_admins/feature_flags/index.html.erb new file mode 100644 index 0000000000..8e19f73c20 --- /dev/null +++ b/app/views/all_casa_admins/feature_flags/index.html.erb @@ -0,0 +1,18 @@ +
+

Feature Flags

+ + + <% @feature_flags.each do |feature_flag| %> + + + + + <% end %> + +
<%= feature_flag.name %> +
+ checked <% end %>> + +
+
+
diff --git a/app/views/layouts/_all_casa_admin_sidebar.html.erb b/app/views/layouts/_all_casa_admin_sidebar.html.erb index 32e29dca71..e029362731 100644 --- a/app/views/layouts/_all_casa_admin_sidebar.html.erb +++ b/app/views/layouts/_all_casa_admin_sidebar.html.erb @@ -22,6 +22,12 @@ Edit Profile <% end %> +