[#1872] Managers can enable feature flags from UI

This commit is contained in:
gregoirenovel 2018-04-26 14:40:03 +02:00 committed by Paul Chavard
parent eb99bdcb06
commit 47323ffbf1
3 changed files with 36 additions and 2 deletions

View file

@ -19,6 +19,20 @@ module Manager
redirect_to manager_administrateur_path(params[:id])
end
def enable_feature
administrateur = Administrateur.find(params[:id])
params[:features].each do |key, enable|
if enable
administrateur.enable_feature(key.to_sym)
else
administrateur.disable_feature(key.to_sym)
end
end
head :ok
end
private
def create_administrateur_params

View file

@ -1,7 +1,26 @@
%table
%table#features
- Flipflop.feature_set.features.each do |feature|
- if !feature.group || feature.group.key != :production
%tr
%td= feature.title
%td
= check_box_tag "Enabled", "enabled", field.data[feature.name], disabled: true
= check_box_tag "enable-feature", "enable", field.data[feature.name], data: { url: enable_feature_manager_administrateur_path(field.resource.id), key: feature.key }
:javascript
window.onload = function() {
$('#features input[type=checkbox]').on('change', function(evt) {
let url = $(evt.target).data('url');
let key = $(evt.target).data('key');
let features = {};
features[key] = $(evt.target).prop('checked');
$.ajax(url, {
method: 'put',
contentType: 'application/json',
dataType: 'json',
data: JSON.stringify({
features: features
})
});
});
};

View file

@ -8,6 +8,7 @@ Rails.application.routes.draw do
resources :administrateurs, only: [:index, :show, :new, :create] do
post 'reinvite', on: :member
put 'enable_feature', on: :member
end
resources :demandes, only: [:index]