Merge branch 'dev' into fix_3282_datatime_with_empty_value

This commit is contained in:
Mathieu Magnin 2019-02-01 11:45:45 +01:00 committed by GitHub
commit 86a2a426bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 241 additions and 103 deletions

View file

@ -7,3 +7,6 @@ $default-padding: 2 * $default-spacer;
// layouts
$two-columns-padding: 60px;
$two-columns-breakpoint: $page-width + (2 * $two-columns-padding);
// z-order
$alert-z-index: 100;

View file

@ -311,8 +311,9 @@
margin-left: $default-spacer;
}
.button.danger {
margin-right: auto;
// If there are more than one button, align the "Send" button to the right
.button:not(:first-of-type).send {
margin-left: auto;
}
}
@ -321,8 +322,7 @@
flex-direction: column-reverse;
align-items: center;
.button,
.button.danger {
.button {
width: 100%;
max-width: 350px;
line-height: 30px;

View file

@ -1,4 +1,5 @@
@import "colors";
@import "constants";
.alert {
padding: 15px;
@ -24,8 +25,10 @@
.alert-fixed {
position: fixed;
left: 50%;
margin-left: -100px;
width: 200px;
transform: translate(-50%);
max-width: 700px;
top: 10px;
border-radius: 10px;
// Ensure fixed flash messages are above `position: absolute` elements (like maps)
z-index: $alert-z-index;
}

View file

@ -74,5 +74,9 @@ class Champs::CarteController < ApplicationController
if @champ.persisted?
@champ.save
end
rescue RestClient::ResourceNotFound
flash.alert = 'Les données cartographiques sont temporairement indisponibles. Réessayez dans un instant.'
response.status = 503
end
end

View file

@ -17,7 +17,7 @@ module Manager
flash.notice = "Administrateur créé"
redirect_to manager_demandes_path
else
flash.now.alert = administrateur.errors.full_messages
flash.now.alert = administrateur.errors.full_messages.to_sentence
@pending_demandes = pending_demandes
render :index
end

View file

@ -129,9 +129,9 @@ class StatsController < ApplicationController
def satisfaction_usagers
legend = {
Feedback.ratings.fetch(:happy) => "Satisfaits",
Feedback.ratings.fetch(:neutral) => "Neutres",
Feedback.ratings.fetch(:unhappy) => "Mécontents"
Feedback.ratings.fetch(:unhappy) => "Mécontents",
Feedback.ratings.fetch(:neutral) => "Neutres",
Feedback.ratings.fetch(:happy) => "Satisfaits"
}
number_of_weeks = 6
@ -139,7 +139,7 @@ class StatsController < ApplicationController
.group_by_week(:created_at, last: number_of_weeks, current: false)
.count
Feedback.ratings.values.map do |rating|
legend.keys.map do |rating|
data = Feedback
.where(rating: rating)
.group_by_week(:created_at, last: number_of_weeks, current: false)

View file

@ -18,6 +18,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
id: Field::Number.with_options(searchable: true),
libelle: Field::String,
description: Field::String,
lien_site_web: Field::String, # TODO: use Field::Url when administrate-v0.12 will be released
organisation: Field::String,
direction: Field::String,
created_at: Field::DateTime,
@ -59,6 +60,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
:administrateur,
:libelle,
:description,
:lien_site_web,
:organisation,
:direction,
:service,

View file

@ -13,10 +13,10 @@ class ApiCarto::API
def self.call(url, geojson)
params = geojson.to_s
RestClient.post(url, params, content_type: 'application/json')
rescue RestClient::InternalServerError
rescue RestClient::InternalServerError, RestClient::BadGateway, RestClient::GatewayTimeout => e
Rails.logger.error "[ApiCarto] Error on #{url}: #{e}"
raise RestClient::ResourceNotFound
end
end

View file

@ -1,19 +1,9 @@
class Champs::CheckboxChamp < Champ
def search_terms
if value == 'on'
[libelle]
end
end
def to_s
value == 'on' ? 'Oui' : 'Non'
class Champs::CheckboxChamp < Champs::YesNoChamp
def true?
value == 'on'
end
def for_export
value == 'on' ? 'on' : 'off'
end
def for_api
value == 'on' ? 'on' : 'off'
true? ? 'on' : 'off'
end
end

View file

@ -1,6 +1,6 @@
class Champs::YesNoChamp < Champs::CheckboxChamp
class Champs::YesNoChamp < Champ
def search_terms
if value == 'true'
if true?
[libelle]
end
end
@ -13,13 +13,13 @@ class Champs::YesNoChamp < Champs::CheckboxChamp
processed_value
end
def for_api
processed_value
def true?
value == 'true'
end
private
def processed_value
value == 'true' ? 'Oui' : 'Non'
true? ? 'Oui' : 'Non'
end
end

View file

@ -14,11 +14,15 @@ module TrustedDeviceConcern
def trusted_device?
trusted_device_cookie.present? &&
Time.zone.now - TRUSTED_DEVICE_PERIOD < JSON.parse(trusted_device_cookie)['created_at']
(Time.zone.now - TRUSTED_DEVICE_PERIOD) < trusted_device_cookie_created_at
end
private
def trusted_device_cookie_created_at
Time.zone.parse(JSON.parse(trusted_device_cookie)['created_at'])
end
def trusted_device_cookie
cookies.encrypted[TRUSTED_DEVICE_COOKIE_NAME]
end

View file

@ -1,8 +1,8 @@
require 'prawn/measurement_extensions'
prawn_document(margin: [50, 100, 20, 100]) do |pdf|
pdf.font_families.update( 'open sans' => { normal: './lib/prawn/fonts/OpenSans-Regular.ttf' })
pdf.font 'open sans'
pdf.font_families.update( 'liberation serif' => { normal: Rails.root.join('lib/prawn/fonts/liberation_serif/LiberationSerif-Regular.ttf' )})
pdf.font 'liberation serif'
grey = '555555'
black = '333333'
@ -21,7 +21,7 @@ prawn_document(margin: [50, 100, 20, 100]) do |pdf|
pdf.pad_top(40) { pdf.text @title, size: 18, character_spacing: -0.2 }
pdf.fill_color grey
pdf.pad_top(30) { pdf.text @body, size: 10, character_spacing: -0.2 }
pdf.pad_top(30) { pdf.text @body, size: 10, character_spacing: -0.2, align: :justify }
if @signature.present?
pdf.pad_top(40) do

View file

@ -3,7 +3,4 @@
= form_for @procedure, url: url_for({ controller: 'admin/procedures', action: :update, id: @procedure.id }), multipart: true do |f|
= render partial: 'informations', locals: { f: f }
.text-right
- if !Flipflop.publish_draft? || @availability.in?(Procedure::PATH_CAN_PUBLISH)
= f.button 'Enregistrer', class: 'btn btn-success'
- else
= f.button 'Enregistrer', class: 'btn btn-success', disabled: true
= f.button 'Enregistrer', class: 'btn btn-success'

View file

@ -1,3 +1,5 @@
<%= render_flash(timeout: 5000, fixed: true) %>
<%= render_to_element("#{@selector} + .geo-areas",
partial: 'shared/champs/carte/geo_areas',
locals: { champ: @champ, error: @error }) %>

View file

@ -52,7 +52,7 @@
= dossier.updated_at.strftime("%d/%m/%Y")
%td.action-col.delete-col
- if dossier.brouillon?
= link_to(ask_deletion_dossier_path(dossier), method: :post, class: 'button danger', data: { disable: true, confirm: "En continuant, vous allez supprimer ce dossier ainsi que les informations quil contient. Toute suppression entraine lannulation de la démarche en cours.\n\nConfirmer la suppression ?" }) do
= link_to(ask_deletion_dossier_path(dossier), method: :post, class: 'button danger', data: { disable: true, confirm: "En continuant, vous allez supprimer ce dossier ainsi que les informations quil contient. Toute suppression entraine lannulation de la démarche en cours.\n\nConfirmer la suppression ?" }) do
%span.icon.delete
Supprimer
= paginate(@dossiers)

View file

@ -40,7 +40,7 @@
%input{ type: "password", value: "12345678" }
.send-wrapper
= f.submit 'Enregistrer un brouillon (formnovalidate)', formnovalidate: true, class: 'button send'
= f.submit 'Envoyer', class: 'button send'
= f.submit 'Envoyer', class: 'button send primary'
%hr

View file

@ -70,13 +70,6 @@
- if !apercu
.send-wrapper
- if dossier.brouillon?
- if current_user.owns?(dossier)
= link_to ask_deletion_dossier_path(dossier),
method: :post,
class: 'button danger',
data: { disable: true, confirm: "En continuant, vous allez supprimer ce dossier ainsi que les informations quil contient. Toute suppression entraine lannulation de la démarche en cours.\n\nConfirmer la suppression ?" } do
Supprimer le brouillon
= f.button 'Enregistrer le brouillon',
formnovalidate: true,
name: :save_draft,

View file

@ -1,3 +1,23 @@
-# Allowed formats:
-# 0123456789
-# 01 23 45 67 89
-# 01.23.45.67.89
-# 0123 45.67.89
-# 0033 123-456-789
-# 0035 123-456-789
-# 0033 123-456-789
-# 0033(0)123456789
-# +33-1.23.45.67.89
-# +33 - 123 456 789
-# +33(0) 123 456 789
-# +33 (0)123 45 67 89
-# +33 (0)1 2345-6789
-# +33(0) - 123456789
-# +1(0) - 123456789
-# +2 123456789
-# 012345678
-# 01234567890
= form.phone_field :value,
placeholder: champ.libelle,
required: champ.mandatory?
required: champ.mandatory?,
pattern: "([\\+\\d\\(][\\(\\)\\s\\.\\-\\d]{4,}\\d)"

View file

@ -25,8 +25,12 @@
.chart-container
.chart
= line_chart @satisfaction_usagers,
colors: ["#15AD70", "#F28900", "rgba(161, 0, 5, 0.9)"]
= area_chart @satisfaction_usagers,
stacked: true,
suffix: ' %',
max: 100,
library: { plotOptions: { series: { marker: { enabled: true }}}},
colors: ["#C31C25", "#F5962A", "#25B177"]
.stat-card.stat-card-half.pull-left
%span.stat-card-title

View file

@ -1,5 +1,7 @@
Chartkick.options = {
content_for: :charts_js,
defer: true,
colors: ["rgba(61, 149, 236, 1)"]
colors: ["rgba(61, 149, 236, 1)"],
thousands: ' ',
decimal: ','
}

Binary file not shown.

View file

@ -0,0 +1,46 @@
Digitized data copyright (c) 2010 Google Corporation
with Reserved Font Arimo, Tinos and Cousine.
Copyright (c) 2012 Red Hat, Inc.
with Reserved Font Name Liberation.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

View file

@ -25,43 +25,65 @@ describe Champs::CarteController, type: :controller do
describe 'POST #show' do
render_views
before { sign_in user }
before do
allow_any_instance_of(ApiCarto::QuartiersPrioritairesAdapter)
.to receive(:results)
.and_return([{ code: "QPCODE1234", geometry: { type: "MultiPolygon", coordinates: [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }])
context 'when the API is available' do
render_views
post :show, params: params, format: 'js'
before do
sign_in user
allow_any_instance_of(ApiCarto::QuartiersPrioritairesAdapter)
.to receive(:results)
.and_return([{ code: "QPCODE1234", geometry: { type: "MultiPolygon", coordinates: [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }])
post :show, params: params, format: 'js'
end
context 'when coordinates are empty' do
let(:value) { '[]' }
it {
expect(assigns(:error)).to eq(nil)
expect(champ.reload.value).to eq(nil)
expect(champ.reload.geo_areas).to eq([])
expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":null,\"quartiersPrioritaires\":[],\"cadastres\":[],\"parcellesAgricoles\":[]});")
}
end
context 'when coordinates are informed' do
let(:value) { [[{ "lat": 48.87442541960633, "lng": 2.3859214782714844 }, { "lat": 48.87273183590832, "lng": 2.3850631713867183 }, { "lat": 48.87081237174292, "lng": 2.3809432983398438 }, { "lat": 48.8712640169951, "lng": 2.377510070800781 }, { "lat": 48.87510283703279, "lng": 2.3778533935546875 }, { "lat": 48.87544154230615, "lng": 2.382831573486328 }, { "lat": 48.87442541960633, "lng": 2.3859214782714844 }]].to_json }
it { expect(response.body).not_to be_nil }
it { expect(response.body).to include('MultiPolygon') }
it { expect(response.body).to include('[2.38715792094576,48.8723062632126]') }
end
context 'when error' do
let(:geojson) { [[{ "lat": 48.87442541960633, "lng": 2.3859214782714844 }, { "lat": 48.87273183590832, "lng": 2.3850631713867183 }, { "lat": 48.87081237174292, "lng": 2.3809432983398438 }, { "lat": 48.8712640169951, "lng": 2.377510070800781 }, { "lat": 48.87510283703279, "lng": 2.3778533935546875 }, { "lat": 48.87544154230615, "lng": 2.382831573486328 }, { "lat": 48.87442541960633, "lng": 2.3859214782714844 }]] }
let(:value) { '' }
it {
expect(assigns(:error)).to eq(true)
expect(champ.reload.value).to eq(nil)
expect(champ.reload.geo_areas).to eq([])
}
end
end
context 'when coordinates are empty' do
let(:value) { '[]' }
context 'when the API is unavailable' do
before do
sign_in user
it {
expect(assigns(:error)).to eq(nil)
expect(champ.reload.value).to eq(nil)
expect(champ.reload.geo_areas).to eq([])
expect(response.body).to include("DS.drawMapData(\".carte-1\", {\"position\":{\"lon\":\"2.428462\",\"lat\":\"46.538192\",\"zoom\":\"13\"},\"selection\":null,\"quartiersPrioritaires\":[],\"cadastres\":[],\"parcellesAgricoles\":[]});")
}
end
allow_any_instance_of(ApiCarto::QuartiersPrioritairesAdapter)
.to receive(:results)
.and_raise(RestClient::ResourceNotFound)
post :show, params: params, format: 'js'
end
context 'when coordinates are informed' do
let(:value) { [[{ "lat": 48.87442541960633, "lng": 2.3859214782714844 }, { "lat": 48.87273183590832, "lng": 2.3850631713867183 }, { "lat": 48.87081237174292, "lng": 2.3809432983398438 }, { "lat": 48.8712640169951, "lng": 2.377510070800781 }, { "lat": 48.87510283703279, "lng": 2.3778533935546875 }, { "lat": 48.87544154230615, "lng": 2.382831573486328 }, { "lat": 48.87442541960633, "lng": 2.3859214782714844 }]].to_json }
it { expect(response.body).not_to be_nil }
it { expect(response.body).to include('MultiPolygon') }
it { expect(response.body).to include('[2.38715792094576,48.8723062632126]') }
end
context 'when error' do
let(:geojson) { [[{ "lat": 48.87442541960633, "lng": 2.3859214782714844 }, { "lat": 48.87273183590832, "lng": 2.3850631713867183 }, { "lat": 48.87081237174292, "lng": 2.3809432983398438 }, { "lat": 48.8712640169951, "lng": 2.377510070800781 }, { "lat": 48.87510283703279, "lng": 2.3778533935546875 }, { "lat": 48.87544154230615, "lng": 2.382831573486328 }, { "lat": 48.87442541960633, "lng": 2.3859214782714844 }]] }
let(:value) { '' }
it {
expect(assigns(:error)).to eq(true)
expect(champ.reload.value).to eq(nil)
expect(champ.reload.geo_areas).to eq([])
}
it { expect(response.status).to eq 503 }
it { expect(response.body).to include('Les données cartographiques sont temporairement indisponibles') }
end
end
end

View file

@ -112,20 +112,6 @@ feature 'The user' do
expect(page).to have_current_path(merci_dossier_path(user_dossier))
end
scenario 'delete a draft', js: true do
log_in(user.email, password, simple_procedure)
fill_individual
page.accept_alert('Confirmer la suppression ?') do
click_on 'Supprimer le brouillon'
end
expect(page).to have_current_path(dossiers_path)
expect(page).to have_text('Votre dossier a bien été supprimé')
expect(page).not_to have_text(user_dossier.procedure.libelle)
expect(user_dossier.reload.hidden_at).to be_present
end
private
def log_in(email, password, procedure)

View file

@ -49,13 +49,13 @@ describe 'user access to the list of his dossier' do
expect(page).not_to have_link(nil, href: ask_deletion_dossier_path(dossier1))
end
context 'when user clicks on delete brouillon list', js: true do
before do
find(:xpath, "//a[@href='#{ask_deletion_dossier_path(dossier_brouillon)}']").click
page.driver.browser.switch_to.alert.accept
end
context 'when user clicks on delete brouillon', js: true do
scenario 'dossier is deleted' do
expect(page).not_to have_link("Supprimer", href: dossier_brouillon.procedure.libelle)
page.accept_alert('Confirmer la suppression ?') do
find(:xpath, "//a[@href='#{ask_deletion_dossier_path(dossier_brouillon)}']").click
end
expect(page).to have_content('Votre dossier a bien été supprimé.')
end
end

View file

@ -196,5 +196,65 @@ describe ChampSerializer do
expect(subject[:entreprise]).to include(capital_social: etablissement.entreprise_capital_social)
}
end
context 'when type champ yes_no' do
context 'true' do
let(:champ) { create(:champ_yes_no, value: 'true') }
it { is_expected.to include(value: 'true') }
end
context 'false' do
let(:champ) { create(:champ_yes_no, value: 'false') }
it { is_expected.to include(value: 'false') }
end
context 'nil' do
let(:champ) { create(:champ_yes_no, value: nil) }
it { is_expected.to include(value: nil) }
end
end
context 'when type champ checkbox' do
context 'on' do
let(:champ) { create(:champ_checkbox, value: 'on') }
it { is_expected.to include(value: 'on') }
end
context 'off' do
let(:champ) { create(:champ_checkbox, value: 'off') }
it { is_expected.to include(value: 'off') }
end
context 'nil' do
let(:champ) { create(:champ_checkbox, value: nil) }
it { is_expected.to include(value: nil) }
end
end
context 'when type champ engagement' do
context 'on' do
let(:champ) { create(:champ_engagement, value: 'on') }
it { is_expected.to include(value: 'on') }
end
context 'off' do
let(:champ) { create(:champ_engagement, value: 'off') }
it { is_expected.to include(value: 'off') }
end
context 'nil' do
let(:champ) { create(:champ_engagement, value: nil) }
it { is_expected.to include(value: nil) }
end
end
end
end