diff --git a/app/assets/javascripts/archive.js b/app/assets/javascripts/archive.js new file mode 100644 index 000000000..7497960e5 --- /dev/null +++ b/app/assets/javascripts/archive.js @@ -0,0 +1,14 @@ +$(document).on('page:load', buttons_archived); +$(document).ready(buttons_archived); + +function buttons_archived(){ + $("button#archive").on('click', function(){ + $("button#archive").hide(); + $("#confirm").show(); + }); + + $("#confirm #cancel").on('click', function(){ + $("button#archive").show(); + $("#confirm").hide(); + }); +} \ No newline at end of file diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 7e3678c01..6adc0ee53 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -22,7 +22,7 @@ @import "bootstrap"; body { - background-color:rgb(255,255,255) + background-color: rgb(255, 255, 255) } .logo { @@ -34,7 +34,7 @@ body { .alert.alert-success, .alert.alert-danger { - margin-top:-20px + margin-top: -20px } .navbar { @@ -54,6 +54,7 @@ body { position: relative; overflow: hidden; } + .btn-file input[type=file] { position: absolute; top: 0; @@ -75,12 +76,13 @@ body { } .center { - text-align:center; + text-align: center; } textarea#description { width: 100%; } + input#nom_projet { width: 100%; } @@ -89,9 +91,9 @@ input#nom_projet { max-width: 27px; } -div.pagination{ - padding-top:20px; - display:block; +div.pagination { + padding-top: 20px; + display: block; text-align: center; } @@ -103,4 +105,43 @@ div.pagination{ width: 100%; margin-top: 0px; +} + +.archived { + float: right; + margin-top: 10px; + + .confirm { + display: none; + } +} + +.btn-nav { + background-color: transparent; + margin-top: 6px; + height: 36px; +} + +.btn-nav:hover { + background-color: #eeeeee; + border-color: #eeeeee #eeeeee #ddd; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; +} + +.btn-nav.text-info:hover{ + color: #23527c; +} + +.btn-nav.text-success:hover{ + color: #3c763d; +} + +.btn-nav.text-danger:hover{ + color: #a94442; +} + + +#confirm { + display:none; } \ No newline at end of file diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 19572d173..13923211d 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -28,7 +28,7 @@ class Admin::ProceduresController < AdminController end flash.notice = 'Procédure enregistrée' - redirect_to admin_procedure_types_de_champ_path(procedure_id: @procedure.id) + redirect_to admin_procedure_types_de_champ_path(procedure_id: @procedure.id) end def update @@ -43,6 +43,18 @@ class Admin::ProceduresController < AdminController redirect_to admin_procedures_path end + def archive + @procedure = current_administrateur.procedures.find(params[:procedure_id]) + @procedure.update_attributes({archived: true}) + + flash.notice = 'Procédure archivée' + redirect_to admin_procedures_path + + rescue ActiveRecord::RecordNotFound + flash.alert = 'Procédure inéxistante' + redirect_to admin_procedures_path + end + private def create_procedure_params diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index 09d90621d..c41af3283 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -5,8 +5,18 @@ = link_to('Champs', admin_procedure_types_de_champ_path(@procedure)) %li = link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) - - + %li{style:'float:right'} + = form_tag "/admin/procedures/#{@procedure.id}/archive", action: :archive, method: :put, procedure_id: @procedure.id do + %button#archive.btn.btn-nav.text-info{type: :button} + %i.fa.fa-eraser + Archiver + #confirm + %button#valid.btn.btn-nav.text-success{type: :submit} + %i.fa.fa-check + Valider + %button#cancel.btn.btn-nav.text-danger{type: :button} + %i.fa.fa-remove + Annuler %h2.text-info =@procedure.libelle diff --git a/config/routes.rb b/config/routes.rb index adb47396b..cc3fecd3e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,11 +45,15 @@ Rails.application.routes.draw do namespace :admin do get 'sign_in' => '/administrateurs/sessions#new' + resources :procedures do resource :types_de_champ, only: [:show, :update] do post '/:index/move_up' => 'types_de_champ#move_up', as: :move_up post '/:index/move_down' => 'types_de_champ#move_down', as: :move_down end + + put 'archive' => 'procedures#archive' + resources :types_de_champ, only: [:destroy] resource :pieces_justificatives, only: [:show, :update] resources :pieces_justificatives, only: :destroy diff --git a/db/migrate/20151126153425_add_archived_to_procedure.rb b/db/migrate/20151126153425_add_archived_to_procedure.rb new file mode 100644 index 000000000..c4654ff67 --- /dev/null +++ b/db/migrate/20151126153425_add_archived_to_procedure.rb @@ -0,0 +1,5 @@ +class AddArchivedToProcedure < ActiveRecord::Migration + def change + add_column :procedures, :archived, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 4835e6e14..1b1c8fff1 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: 20151124085333) do +ActiveRecord::Schema.define(version: 20151126153425) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -150,6 +150,7 @@ ActiveRecord::Schema.define(version: 20151124085333) do t.boolean "test" t.boolean "use_api_carto", default: false t.integer "administrateur_id" + t.boolean "archived", default: false end create_table "quartier_prioritaires", force: :cascade do |t| diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 127c37d1b..d0493a55a 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -166,4 +166,36 @@ describe Admin::ProceduresController, type: :controller do end end end + + describe 'PUT #archive' do + let(:procedure) { create(:procedure, administrateur: admin) } + + + + context 'when admin is the owner of the procedure' do + before do + put :archive, procedure_id: procedure.id + procedure.reload + end + + it { expect(procedure.archived).to be_truthy } + it { expect(response).to redirect_to :admin_procedures } + it { expect(flash[:notice]).to have_content 'Procédure archivée' } + end + + context 'when admin is not the owner of the procedure' do + let(:admin_2) { create(:administrateur) } + + before do + sign_out admin + sign_in admin_2 + + put :archive, procedure_id: procedure.id + procedure.reload + end + + it { expect(response).to redirect_to :admin_procedures } + it { expect(flash[:alert]).to have_content 'Procédure inéxistante' } + end + end end diff --git a/spec/features/backoffice/onglets_link_spec.rb b/spec/features/backoffice/onglets_link_spec.rb index ab6e7e70c..f249de58d 100644 --- a/spec/features/backoffice/onglets_link_spec.rb +++ b/spec/features/backoffice/onglets_link_spec.rb @@ -12,7 +12,7 @@ feature 'on click on tabs button' do context 'when he click on tabs a traitee' do before do visit backoffice_dossiers_en_attente_url - page.click_on 'À traiter (0)' + page.click_on 'À traiter 0' end scenario 'it redirect to backoffice dossier termine' do @@ -23,7 +23,7 @@ feature 'on click on tabs button' do context 'when he click on tabs en attente' do before do visit backoffice_dossiers_termine_url - page.click_on 'En attente (0)' + page.click_on 'En attente 0' end scenario 'it redirect to backoffice dossier en attente' do @@ -34,7 +34,7 @@ feature 'on click on tabs button' do context 'when he click on tabs termine' do before do visit backoffice_dossiers_a_traiter_url - page.click_on 'Terminé (0)' + page.click_on 'Terminé 0' end scenario 'it redirect to backoffice dossier termine' do