From 05d9e62dd2be435aad2cb562339daec6a7e48b21 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 10 Oct 2017 17:16:43 +0200 Subject: [PATCH] ability to disabled training --- .../controllers/admin/trainings.coffee.erb | 10 +++++ .../templates/admin/trainings/_form.html.erb | 41 ++++++++++++++----- app/controllers/api/trainings_controller.rb | 2 +- app/views/api/trainings/index.json.jbuilder | 2 +- app/views/api/trainings/show.json.jbuilder | 2 +- config/locales/app.shared.en.yml | 18 +++++--- config/locales/app.shared.fr.yml | 18 +++++--- config/locales/app.shared.pt.yml | 18 +++++--- ...20171010143708_add_disabled_to_training.rb | 5 +++ db/schema.rb | 3 +- 10 files changed, 89 insertions(+), 30 deletions(-) create mode 100644 db/migrate/20171010143708_add_disabled_to_training.rb diff --git a/app/assets/javascripts/controllers/admin/trainings.coffee.erb b/app/assets/javascripts/controllers/admin/trainings.coffee.erb index 6ae3e12ab..e7d5dc317 100644 --- a/app/assets/javascripts/controllers/admin/trainings.coffee.erb +++ b/app/assets/javascripts/controllers/admin/trainings.coffee.erb @@ -9,9 +9,11 @@ # Provides : # - $scope.submited(content) # - $scope.fileinputClass(v) +# - $scope.onDisableToggled # # Requires : # - $state (Ui-Router) [ 'app.admin.trainings' ] +# - $scope.training ## class TrainingsController constructor: ($scope, $state) -> @@ -43,6 +45,14 @@ class TrainingsController + ## + # Force the 'public_page' attribute to false when the current training is disabled + ## + $scope.onDisableToggled = -> + $scope.training.public_page = !$scope.training.disabled + + + ## # For use with 'ng-class', returns the CSS class name for the uploads previews. # The preview may show a placeholder or the content of the file depending on the upload state. diff --git a/app/assets/templates/admin/trainings/_form.html.erb b/app/assets/templates/admin/trainings/_form.html.erb index 91e09131b..3eb722328 100644 --- a/app/assets/templates/admin/trainings/_form.html.erb +++ b/app/assets/templates/admin/trainings/_form.html.erb @@ -15,21 +15,21 @@ {{alert.msg}}
- +
- {{ 'name_is_required' }} + {{ 'trainings_form.name_is_required' }}
- +
@@ -40,7 +40,7 @@
- {{ 'add_an_illustration' | translate }} + {{ 'trainings_form.add_an_illustration' | translate }} {{ 'change' }} - +
- {{ 'description_is_required' }} + {{ 'trainings_form.description_is_required' }}
- +
@@ -81,7 +81,7 @@
- +
+
+ +
+ + +
+
+
diff --git a/app/controllers/api/trainings_controller.rb b/app/controllers/api/trainings_controller.rb index 9e452b346..30b03a256 100644 --- a/app/controllers/api/trainings_controller.rb +++ b/app/controllers/api/trainings_controller.rb @@ -70,6 +70,6 @@ class API::TrainingsController < API::ApiController end def training_params - params.require(:training).permit(:id, :name, :description, :machine_ids, :plan_ids, :nb_total_places, :public_page, training_image_attributes: [:attachment], machine_ids: [], plan_ids: []) + params.require(:training).permit(:id, :name, :description, :machine_ids, :plan_ids, :nb_total_places, :public_page, :disabled, training_image_attributes: [:attachment], machine_ids: [], plan_ids: []) end end diff --git a/app/views/api/trainings/index.json.jbuilder b/app/views/api/trainings/index.json.jbuilder index 9e78e0f3b..77e7a8e8a 100644 --- a/app/views/api/trainings/index.json.jbuilder +++ b/app/views/api/trainings/index.json.jbuilder @@ -1,7 +1,7 @@ role = (current_user and current_user.is_admin?) ? 'admin' : 'user' json.array!(@trainings) do |training| - json.extract! training, :id, :name, :description, :machine_ids, :nb_total_places, :slug + json.extract! training, :id, :name, :description, :machine_ids, :nb_total_places, :slug, :disabled json.training_image training.training_image.attachment.large.url if training.training_image json.plan_ids training.plan_ids if role === 'admin' end diff --git a/app/views/api/trainings/show.json.jbuilder b/app/views/api/trainings/show.json.jbuilder index 5d69b4223..524b3c0e7 100644 --- a/app/views/api/trainings/show.json.jbuilder +++ b/app/views/api/trainings/show.json.jbuilder @@ -1,2 +1,2 @@ -json.extract! @training, :id, :name, :description, :machine_ids, :nb_total_places, :public_page +json.extract! @training, :id, :name, :description, :machine_ids, :nb_total_places, :public_page, :disabled json.training_image @training.training_image.attachment.large.url if @training.training_image diff --git a/config/locales/app.shared.en.yml b/config/locales/app.shared.en.yml index c6b66c36d..24a4258dd 100644 --- a/config/locales/app.shared.en.yml +++ b/config/locales/app.shared.en.yml @@ -235,11 +235,19 @@ en: trainings: # training edition form - add_a_new_training: "Add a new training" - validate_your_training: "Validate your training" - associated_machines: "Associated machines" - number_of_tickets: "Number of tickets" - public_page: "Show in training lists" + trainings_form: + name: "Name" + name_is_required: "Name is required." + illustration: "Illustration" + add_an_illustration: "Add an illustration" + description: "Description" + description_is_required: "Description is required." + add_a_new_training: "Add a new training" + validate_your_training: "Validate your training" + associated_machines: "Associated machines" + number_of_tickets: "Number of tickets" + public_page: "Show in training lists" + disable_training: "Disable the training" user_admin: # partial form to edit/create an user (admin view) diff --git a/config/locales/app.shared.fr.yml b/config/locales/app.shared.fr.yml index dfbed283d..a147f9fe0 100644 --- a/config/locales/app.shared.fr.yml +++ b/config/locales/app.shared.fr.yml @@ -235,11 +235,19 @@ fr: trainings: # formulaire d'édition d'une formation - add_a_new_training: "Ajouter une nouvelle formation" - validate_your_training: "Valider votre formation" - associated_machines: "Machines associées" - number_of_tickets: "Nombre de places" - public_page: "Afficher dans la liste de formation" + trainings_form: + name: "Nom" + name_is_required: "Le nom est requis." + illustration: "Visuel" + add_an_illustration: "Ajouter un visuel" + description: "Description" + description_is_required: "La description est requise." + add_a_new_training: "Ajouter une nouvelle formation" + validate_your_training: "Valider votre formation" + associated_machines: "Machines associées" + number_of_tickets: "Nombre de places" + public_page: "Afficher dans la liste de formation" + disable_training: "Désactiver la formation" user_admin: # formulaire partiel d'édition/création utilisateur (vue admin) diff --git a/config/locales/app.shared.pt.yml b/config/locales/app.shared.pt.yml index 74824afa0..40beef4e0 100755 --- a/config/locales/app.shared.pt.yml +++ b/config/locales/app.shared.pt.yml @@ -235,11 +235,19 @@ pt: trainings: # training edition form - add_a_new_training: "Adicionar um novo treinamento" - validate_your_training: "Validar seu treinamento" - associated_machines: "Máquinas associadas" - number_of_tickets: "Número de vagas" - public_page: "Mostrar na lista de treinamentos" + trainings_form: + name: "Nome" + name_is_required: "Nome é obrigatório." + illustration: "Ilustração" + add_an_illustration: "Adicionar ilustração" + description: "Descrição" + description_is_required: "Descrição é obrigatório." + add_a_new_training: "Adicionar um novo treinamento" + validate_your_training: "Validar seu treinamento" + associated_machines: "Máquinas associadas" + number_of_tickets: "Número de vagas" + public_page: "Mostrar na lista de treinamentos" + disable_training: "Disable the training" # TODO user_admin: # partial form to edit/create an user (admin view) diff --git a/db/migrate/20171010143708_add_disabled_to_training.rb b/db/migrate/20171010143708_add_disabled_to_training.rb new file mode 100644 index 000000000..3f5638447 --- /dev/null +++ b/db/migrate/20171010143708_add_disabled_to_training.rb @@ -0,0 +1,5 @@ +class AddDisabledToTraining < ActiveRecord::Migration + def change + add_column :trainings, :disabled, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 7cc7eb9f5..5fb38d7f5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171005141522) do +ActiveRecord::Schema.define(version: 20171010143708) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -703,6 +703,7 @@ ActiveRecord::Schema.define(version: 20171005141522) do t.string "slug", limit: 255 t.text "description" t.boolean "public_page", default: true + t.boolean "disabled" end add_index "trainings", ["slug"], name: "index_trainings_on_slug", unique: true, using: :btree