Skip to content

Commit

Permalink
Merge branch 'feature/90-attribute-type-date' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
polosson committed Feb 1, 2021
2 parents 03b739b + 37d5734 commit c0a0cf2
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Ce projet adhère au principe du [Semantic Versioning](https://semver.org/spec/v

- Améliore le calcul du matériel restant dans les événements.
- Ajoute la possibilité de limiter les caractéristiques spéciales du matériel par catégorie (#91).
- Ajoute le type "date" aux caractéristiques spéciales du matériel (#90).

## 0.11.0 (2021-01-14)

Expand Down
4 changes: 3 additions & 1 deletion client/src/components/FormField/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

<script>
import Datepicker from 'vuejs-datepicker';
import moment from 'moment';
import * as lang from 'vuejs-datepicker/src/locale';
import store from '@/store';
import SwitchToggle from '@/components/SwitchToggle/SwitchToggle.vue';
Expand Down Expand Up @@ -136,7 +137,8 @@ export default {
methods: {
handleDatepickerChange(newDate) {
this.$emit('input', newDate);
this.$emit('change', { field: this.name, newDate });
const newValue = moment(newDate).format('YYYY-MM-DD');
this.$emit('change', { field: this.name, newValue, newDate });
},
handleSwitchChange(newValue) {
Expand Down
1 change: 1 addition & 0 deletions client/src/locale/en/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export default {
'type-integer': "Integer number",
'type-float': "Decimal number",
'type-boolean': "Boolean (Yes/No)",
'type-date': "Date",
'no-limit': "No limit",
'add-attributes': "Add attributes",
'no-attribute-yet': "No attribute yet.",
Expand Down
1 change: 1 addition & 0 deletions client/src/locale/fr/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export default {
'type-integer': "Nombre entier",
'type-float': "Nombre décimal",
'type-boolean': "Booléen (Oui / Non)",
'type-date': "Date",
'no-limit': "Sans limite",
'add-attributes': "Ajouter des caractéristiques",
'no-attribute-yet': "Aucune caractéristique spéciale pour le moment.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
class="AttributeEditForm__select"
@change="handleTypeChange"
>
<option value="string">{{ $t('page-attributes.type-string') }}</option>
<option value="integer">{{ $t('page-attributes.type-integer') }}</option>
<option value="float">{{ $t('page-attributes.type-float') }}</option>
<option value="date">{{ $t('page-attributes.type-date') }}</option>
<option value="string">{{ $t('page-attributes.type-string') }}</option>
<option value="boolean">{{ $t('page-attributes.type-boolean') }}</option>
</select>
<ul v-if="errors.type" class="AttributeEditForm__error">
Expand Down
1 change: 1 addition & 0 deletions client/src/pages/Attributes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default {

saveAttribute() {
this.isLoading = true;
this.error = null;
const data = this.$refs.AttributeEditForm.getValues();

this.$http.post('/attributes', data)
Expand Down
1 change: 1 addition & 0 deletions client/src/pages/Material/Material.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
:label="extraAttribute.name"
:addon="extraAttribute.unit"
:type="getAttributeType(extraAttribute.type)"
:datepickerOptions="{ format: 'dd/MM/yyyy' }"
@change="handleAttributeChange"
/>
</div>
Expand Down
2 changes: 2 additions & 0 deletions client/src/pages/Material/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export default {
return 'number';
case 'boolean':
return 'switch';
case 'date':
return 'date';
default:
return 'text';
}
Expand Down
15 changes: 14 additions & 1 deletion client/src/pages/MaterialView/Infos/Attributes/Attributes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
>
{{ attribute.name }}:
<span
v-if="attribute.type !== 'boolean'"
v-if="!['boolean', 'date'].includes(attribute.type)"
class="MaterialViewInfosAttributes__list__item__value"
>
{{ attribute.value }}
{{ attribute.unit }}
</span>
<span
v-if="attribute.type === 'date'"
class="MaterialViewInfosAttributes__list__item__value"
>
{{ formatDate(attribute.value) }}
</span>
<span
v-if="attribute.type === 'boolean'"
class="MaterialViewInfosAttributes__list__item__value"
Expand All @@ -35,10 +41,17 @@
</style>

<script>
import moment from 'moment';
export default {
name: 'MaterialViewInfosAttributes',
props: {
attributes: { required: true, type: Array },
},
methods: {
formatDate(value) {
return moment(value).format('DD/MM/yyyy');
},
},
};
</script>
3 changes: 2 additions & 1 deletion server/src/App/Models/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function __construct(array $attributes = [])
v::equals('string'),
v::equals('integer'),
v::equals('float'),
v::equals('boolean')
v::equals('boolean'),
v::equals('date')
),
'unit' => V::optional(V::length(1, 8)),
'max_length' => V::optional(V::numeric()),
Expand Down
2 changes: 1 addition & 1 deletion server/src/App/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class BaseModel extends Model

public $validation;

const EXTRA_CHARS = '-_. ÇçàÀâÂäÄåÅèÈéÉêÊëËíÍìÌîÎïÏòÒóÓôÔöÖðÐõÕøØúÚùÙûÛüÜýÝÿŸŷŶøØæÆœŒñÑßÞ';
const EXTRA_CHARS = "-_.' ÇçàÀâÂäÄåÅèÈéÉêÊëËíÍìÌîÎïÏòÒóÓôÔöÖðÐõÕøØúÚùÙûÛüÜýÝÿŸŷŶøØæÆœŒñÑßÞ";

public function __construct(array $attributes = [])
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
use Phinx\Migration\AbstractMigration;

class AddDateTypeToAttributes extends AbstractMigration
{
public function up()
{
$table = $this->table('attributes');
$table->changeColumn('type', 'enum', [
'values' => ['string', 'integer', 'float', 'boolean', 'date']
])->update();
}

public function down()
{
// - Obligé de nettoyer "à la main" étant donné que `material_attributes` n'a pas de
// contrainte "CASCADE" pour la suppression...
$attributes = $this->fetchAll("SELECT `id` FROM `attributes` WHERE `type` = 'date'");
foreach ($attributes as $attribute) {
$this->execute(sprintf(
"DELETE FROM `material_attributes` WHERE `attribute_id` = %d",
$attribute['id']
));
}

$this->execute("DELETE FROM `attributes` WHERE `type` = 'date'");

$table = $this->table('attributes');
$table->changeColumn('type', 'enum', [
'values' => ['string', 'integer', 'float', 'boolean']
])->update();
}
}
7 changes: 7 additions & 0 deletions server/tests/Fixtures/seed/attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@
"type" : "boolean",
"unit" : null,
"max_length" : null
},
{
"id" : 5,
"name" : "Date d'achat",
"type" : "date",
"unit" : null,
"max_length" : null
}
]
6 changes: 6 additions & 0 deletions server/tests/Fixtures/seed/material_attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,11 @@
"material_id" : 4,
"attribute_id" : 4,
"value" : "true"
},
{
"id" : 11,
"material_id" : 6,
"attribute_id" : 5,
"value" : "2021-01-28"
}
]
39 changes: 36 additions & 3 deletions server/tests/endpoints/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ public function testGetAll()
'updated_at' => null,
'deleted_at' => null,
],
[
'id' => 5,
'name' => "Date d'achat",
'type' => "date",
'unit' => null,
'max_length' => null,
'categories' => [],
'created_at' => null,
'updated_at' => null,
'deleted_at' => null,
],
[
'id' => 1,
'name' => "Poids",
Expand Down Expand Up @@ -117,6 +128,17 @@ public function testGetAllForCategory()
'updated_at' => null,
'deleted_at' => null,
],
[
'id' => 5,
'name' => "Date d'achat",
'type' => "date",
'unit' => null,
'max_length' => null,
'categories' => [],
'created_at' => null,
'updated_at' => null,
'deleted_at' => null,
],
];
$this->assertEquals($expected, $response);

Expand Down Expand Up @@ -148,6 +170,17 @@ public function testGetAllForCategory()
'updated_at' => null,
'deleted_at' => null,
],
[
'id' => 5,
'name' => "Date d'achat",
'type' => "date",
'unit' => null,
'max_length' => null,
'categories' => [],
'created_at' => null,
'updated_at' => null,
'deleted_at' => null,
],
[
'id' => 1,
'name' => "Poids",
Expand Down Expand Up @@ -195,7 +228,7 @@ public function testCreateAttribute()
$this->client->post('/api/attributes', $data);
$this->assertStatusCode(SUCCESS_CREATED);
$expected = [
'id' => 5,
'id' => 6,
'name' => 'Speed',
'type' => 'float',
'unit' => 'km/h',
Expand All @@ -208,13 +241,13 @@ public function testCreateAttribute()
['id' => 4, 'name' => 'dimmers', 'category_id' => 2],
['id' => 3, 'name' => 'projectors', 'category_id' => 2],
],
'pivot' => ['attribute_id' => 5, 'category_id' => 2]
'pivot' => ['attribute_id' => 6, 'category_id' => 2]
],
[
'id' => 3,
'name' => "transport",
'sub_categories' => [],
'pivot' => ['attribute_id' => 5, 'category_id' => 3]
'pivot' => ['attribute_id' => 6, 'category_id' => 3]
],
],
'created_at' => 'fakedTestContent',
Expand Down
46 changes: 27 additions & 19 deletions server/tests/endpoints/MaterialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,34 @@ public function testGetMaterials()
],
'data' => [
[
'id' => 6,
'name' => 'Behringer X Air XR18',
'description' => 'Mélangeur numérique 18 canaux',
'reference' => 'XR18',
'is_unitary' => true,
'park_id' => null,
'category_id' => 1,
'sub_category_id' => 1,
'rental_price' => 49.99,
'stock_quantity' => 0,
'id' => 6,
'name' => 'Behringer X Air XR18',
'description' => 'Mélangeur numérique 18 canaux',
'reference' => 'XR18',
'is_unitary' => true,
'park_id' => null,
'category_id' => 1,
'sub_category_id' => 1,
'rental_price' => 49.99,
'stock_quantity' => 0,
'out_of_order_quantity' => 0,
'replacement_price' => 419,
'is_hidden_on_bill' => false,
'is_discountable' => false,
'note' => null,
'created_at' => null,
'updated_at' => null,
'deleted_at' => null,
'tags' => [],
'attributes' => [],
'replacement_price' => 419,
'is_hidden_on_bill' => false,
'is_discountable' => false,
'note' => null,
'created_at' => null,
'updated_at' => null,
'deleted_at' => null,
'tags' => [],
'attributes' => [
[
'id' => 5,
'name' => "Date d'achat",
'type' => 'date',
'unit' => null,
'value' => '2021-01-28',
],
],
],
[
'id' => 5,
Expand Down
4 changes: 2 additions & 2 deletions server/tests/endpoints/PersonsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,13 @@ public function testCreatePersonBadData()
'first_name' => [
"first_name must not be empty",
'first_name must contain only letters (a-z) and ' .
'""-_. ÇçàÀâÂäÄåÅèÈéÉêÊëËíÍìÌîÎïÏòÒóÓôÔöÖðÐõÕøØúÚùÙûÛüÜýÝÿŸŷŶøØæÆœŒñÑßÞ""',
'""-_.\' ÇçàÀâÂäÄåÅèÈéÉêÊëËíÍìÌîÎïÏòÒóÓôÔöÖðÐõÕøØúÚùÙûÛüÜýÝÿŸŷŶøØæÆœŒñÑßÞ""',
"first_name must have a length between 2 and 96"
],
'last_name' => [
"last_name must not be empty",
'last_name must contain only letters (a-z) and ' .
'""-_. ÇçàÀâÂäÄåÅèÈéÉêÊëËíÍìÌîÎïÏòÒóÓôÔöÖðÐõÕøØúÚùÙûÛüÜýÝÿŸŷŶøØæÆœŒñÑßÞ""',
'""-_.\' ÇçàÀâÂäÄåÅèÈéÉêÊëËíÍìÌîÎïÏòÒóÓôÔöÖðÐõÕøØúÚùÙûÛüÜýÝÿŸŷŶøØæÆœŒñÑßÞ""',
"last_name must have a length between 2 and 96"
],
'email' => [
Expand Down
13 changes: 12 additions & 1 deletion server/tests/models/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testTableName(): void
public function testGetAll(): void
{
$result = $this->model->getAll()->get()->toArray();
$this->assertCount(4, $result);
$this->assertCount(5, $result);
$this->assertEquals([
[
'id' => 1,
Expand Down Expand Up @@ -97,6 +97,17 @@ public function testGetAll(): void
'updated_at' => null,
'deleted_at' => null,
],
[
'id' => 5,
'name' => "Date d'achat",
'type' => "date",
'unit' => null,
'max_length' => null,
'categories' => [],
'created_at' => null,
'updated_at' => null,
'deleted_at' => null,
],
], $result);
}

Expand Down
Loading

0 comments on commit c0a0cf2

Please sign in to comment.