Skip to content

Commit

Permalink
Merge branch 'feature/101-remove-attributes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
polosson committed Mar 9, 2021
2 parents ba5bb4b + 8b76921 commit 10a4d40
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Ce projet adhère au principe du [Semantic Versioning](https://semver.org/spec/v
- Dans l'édition d'un événement, la modification de la date de début ne change plus la date de fin automatiquement (#99).
- Affiche certains messages d'aide sur plusieurs lignes, et corrige quelques fautes dans ces messages.
- Améliore l'affichage de la page du calendrier.
- Permet la suppression des caractéristiques spéciales de matériel (#101).
- Ajoute la possibilité de mettre des chiffres dans le nom des caractéristiques spéciales (#103).
- Améliore l'affichage de l'onglet "Facturation" des événements pour les utilisateurs du groupe "visiteur" (#104).
- Place le champ "sous-catégorie" en dessous du champ "catégorie" dans l'édition de matériel (#105).
Expand Down
17 changes: 16 additions & 1 deletion client/src/locale/en/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ export default {

'page-attributes': {
'title': "Material special attributes",
'help': "Here you can check, and add fields that allows you to describe your material according to your own criteria.",
'help': (
`Here you can add fields that allows you to describe your material according to your own criteria.
Once created, a special attribute cannot be modified (except for its name).`
),
'go-back-to-material': "Back to material",
'name': "Name of the attribute",
'type': "Attribute type",
Expand All @@ -192,6 +195,18 @@ export default {
'no-attribute-yet': "No attribute yet.",
'add-btn': "Add an attribute",
'limited-to-categories': "Limited to categories",
'confirm-permanently-delete': (
`Do you really want to permanently delete this special attribute?
WARNING: All data related to this special attribute will be deleted DEFINITIVELY!!`
),
'second-confirm': {
'confirm-permanently-delete': (
`Sorry to insist, but this operation is IRREVERSIBLE.
Do you REALLY want to remove this special attribute?`
),
},
},

'page-categories': {
Expand Down
17 changes: 16 additions & 1 deletion client/src/locale/fr/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ export default {

'page-attributes': {
'title': "Caractéristiques spéciales du matériel",
'help': "Ici vous pouvez consulter, et ajouter les champs qui permettent de décrire votre matériel selon vos propres critères.",
'help': (
`Ici vous pouvez ajouter les champs qui permettent de décrire votre matériel selon vos propres critères.
Une fois créée, une caractéristique spéciale ne pourra plus être modifiée (sauf son nom).`
),
'go-back-to-material': "Retourner au matériel",
'name': "Nom de la caractéristique",
'type': "Type de donnée",
Expand All @@ -192,6 +195,18 @@ export default {
'no-attribute-yet': "Aucune caractéristique spéciale pour le moment.",
'add-btn': "Ajouter une caractéristique",
'limited-to-categories': "Limitée aux catégories",
'confirm-permanently-delete': (
`Voulez-vous vraiment supprimer définitivement cette caractéristique spéciale\u00a0?
ATTENTION\u00a0: Toutes les données relative à cette caractéristique spéciale seront supprimées DÉFINITIVEMENT\u00a0!!`
),
'second-confirm': {
'confirm-permanently-delete': (
`Désolé d'insister, mais cette opération IRRÉVERSIBLE.
Voulez-vous VRAIMENT supprimer cette caractéristique spéciale\u00a0?`
),
},
},

'page-categories': {
Expand Down
23 changes: 20 additions & 3 deletions client/src/pages/Attributes/Attributes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
&__header {
.Help {
margin-top: $content-padding-small-horizontal;
margin-right: $content-padding-small-vertical;
}
}

&__back-button {
margin-top: $content-padding-small-horizontal;
margin-right: $content-padding-small-vertical;
}

&__no-data {
Expand Down Expand Up @@ -38,7 +38,8 @@
&__type,
&__unit,
&__max-length,
&__categories {
&__categories,
&__delete {
padding: .8rem .5rem;
border-bottom: 1px solid $bg-color-body;
}
Expand All @@ -60,8 +61,24 @@
}
}

&__delete {
width: 30px;

&__button {
visibility: hidden;
transition: none;
padding: 5px 8px;
font-size: .9rem;

&--show {
visibility: visible;
}
}
}

&__line:hover {
.Attributes__items__edit-name__edit-button {
.Attributes__items__edit-name__edit-button,
.Attributes__items__delete__button {
visibility: visible;
}
}
Expand Down
22 changes: 17 additions & 5 deletions client/src/pages/Attributes/Attributes.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<template>
<div class="content Attributes">
<div class="Attributes__header header-page">
<button @click="goBack" class="info Attributes__back-button">
<i class="fas fa-arrow-left" />
{{ $t('page-attributes.go-back-to-material') }}
</button>
<Help
:message="help"
:error="error"
:isLoading="isLoading"
/>
<button @click="goBack" class="info Attributes__back-button">
<i class="fas fa-arrow-left" />
{{ $t('page-attributes.go-back-to-material') }}
</button>
</div>
<div class="content__main-view">
<div class="Attributes__content">
Expand All @@ -28,7 +28,7 @@
<th class="Attributes__items__max-length">
{{ $t('page-attributes.max-length') }}
</th>
<th class="Attributes__items__categories">
<th class="Attributes__items__categories" colspan="2">
{{ $t('page-attributes.limited-to-categories') }}
</th>
</tr>
Expand Down Expand Up @@ -83,6 +83,18 @@
{{ attribute.categories.map(({ name }) => name).join(', ') }}
</span>
</td>
<td class="Attributes__items__delete">
<button
v-if="!editAttribute"
class="Attributes__items__delete__button danger"
:class="{
'Attributes__items__delete__button--show': currentlyDeleting === attribute.id
}"
@click="deleteAttribute(attribute.id)"
>
<i class="fas fa-trash" />
</button>
</td>
</tr>
</tbody>
</table>
Expand Down
34 changes: 34 additions & 0 deletions client/src/pages/Attributes/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import router from '@/router';
import Alert from '@/components/Alert';
import Help from '@/components/Help/Help.vue';
import AttributeEditForm from './AttributeEditForm/AttributeEditForm.vue';

Expand All @@ -15,6 +16,7 @@ export default {
isLoading: false,
editAttribute: null,
editAttributeName: '',
currentlyDeleting: null,
};
},
mounted() {
Expand Down Expand Up @@ -84,6 +86,38 @@ export default {
.catch(this.displayError);
},

async deleteAttribute(id) {
this.currentlyDeleting = id;

const { value: firstConfirm } = await Alert.ConfirmDelete(this.$t, 'attributes', false);
if (!firstConfirm) {
this.currentlyDeleting = null;
return;
}

const { value: secondConfirm } = await Alert.ConfirmDelete(
this.$t,
'attributes.second-confirm',
false,
);
if (!secondConfirm) {
this.currentlyDeleting = null;
return;
}

this.error = null;
this.isLoading = true;

try {
await this.$http.delete(`attributes/${id}`);
this.fetchAttributes();
} catch (error) {
this.displayError(error);
} finally {
this.currentlyDeleting = null;
}
},

displayError(error) {
this.isLoading = false;
this.error = error;
Expand Down
1 change: 1 addition & 0 deletions client/src/style/vendors/_sweetalert2.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

.swal2-content {
color: $text-base-color;
white-space: pre-line;
}

.swal2-file,
Expand Down
1 change: 1 addition & 0 deletions server/src/App/ApiRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class ApiRouter
'/companies/{id:[0-9]+}[/]' => 'CompanyController:delete',
'/parks/{id:[0-9]+}[/]' => 'ParkController:delete',
'/materials/{id:[0-9]+}[/]' => 'MaterialController:delete',
'/attributes/{id:[0-9]+}[/]' => 'AttributeController:delete',
'/events/{id:[0-9]+}[/]' => 'EventController:delete',
'/bills/{id:[0-9]+}[/]' => 'BillController:delete',
'/documents/{id:[0-9]+}[/]' => 'DocumentController:delete',
Expand Down
14 changes: 14 additions & 0 deletions server/src/App/Models/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,18 @@ public function edit(?int $id = null, array $data = []): Model

return parent::edit($id, $data);
}

public function remove(int $id, array $options = []): ?Model
{
$model = self::find($id);
if (empty($model)) {
throw new Errors\NotFoundException;
}

if (!$model->delete()) {
throw new \RuntimeException(sprintf("Unable to delete the attribute %d.", $id));
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
use Phinx\Migration\AbstractMigration;

class ChangeMaterialAttributesRelationship extends AbstractMigration
{
public function up()
{
$table = $this->table('material_attributes');
$table->dropForeignKey('attribute_id')->save();

$table->addForeignKey('attribute_id', 'attributes', 'id', [
'delete' => 'CASCADE',
'update' => 'NO_ACTION',
'constraint' => 'fk_material_attributes_attribute'
])->save();
}

public function down()
{
$table = $this->table('material_attributes');
$table->dropForeignKey('attribute_id')->save();

$table->addForeignKey('attribute_id', 'attributes', 'id', [
'delete' => 'NO_ACTION',
'update' => 'NO_ACTION',
'constraint' => 'fk_material_attributes_attribute'
])->save();
}
}
8 changes: 8 additions & 0 deletions server/tests/models/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,12 @@ public function testEdit(): void
unset($result->created_at, $result->updated_at, $result->deleted_at);
$this->assertEquals($expected, $result->toArray());
}

public function testRemove(): void
{
// - Supprime une caractéristique spéciale
$this->model->remove(3);
// - Vérifie qu'elle a bien été supprimée
$this->assertEmpty(Models\Attribute::find(3));
}
}

0 comments on commit 10a4d40

Please sign in to comment.