Skip to content

Commit

Permalink
feat: refactor form for routes, ropes and attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 committed Nov 21, 2021
1 parent 30b8aeb commit b2f2a4a
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 168 deletions.
27 changes: 27 additions & 0 deletions assets/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,33 @@ body,
height: ~"-webkit-calc(100% - 60px)";
overflow: auto;
width: 100%;

.item-card {
width: 100%;
margin-bottom: 16px;
border: 1px solid yellowgreen;
}
.item-card .info {
width: 124px;
text-align: left;
margin-right: 8px;
}
.item-card .info-block {
display: flex;
}
.spaced {
justify-content: space-evenly;
}
@media only screen and (min-width: 600px) {
.item-card {
width: 330px;
margin: 0px;
}
}
.item-row {
display: flex;
flex-wrap: wrap;
}
}
@media (min-width: 1025px) {
.filterItem {
Expand Down
24 changes: 10 additions & 14 deletions components/attempts/AttemptsAddForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@
</template>

<script>
const defaultValues = {
routeId: null,
ropeId: null,
styleId: null,
tries: 1,
climbingDate: new Date(),
};
export default {
props: {
ropes: {
Expand All @@ -175,13 +182,7 @@ export default {
},
data() {
return {
form: {
routeId: null,
ropeId: null,
styleId: null,
tries: 1,
climbingDate: new Date(),
},
form: { ...defaultValues },
};
},
computed: {
Expand Down Expand Up @@ -217,18 +218,13 @@ export default {
hasGrade: { french: this.form.french },
});
});
this.form = { ...defaultValues };
this.$bvModal.hide("attemptAddForm");
},
onReset(event) {
event.preventDefault();
this.$bvModal.hide("attemptAddForm");
this.form = {
name: "",
sector: "",
grade: "",
link: "",
city: "",
};
this.form = { ...defaultValues };
},
},
};
Expand Down
31 changes: 3 additions & 28 deletions components/attempts/AttemptsCards.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<div class="jc-c spaced attempt-row">
<div class="jc-c spaced item-row">
<Empty />

<b-card
v-for="item in attempts"
:key="item.id"
tag="article"
class="attempt-card"
class="item-card"
>
<div class="info-block">
<span class="info"><strong>grade(style)</strong></span>
Expand Down Expand Up @@ -112,29 +112,4 @@ export default {
};
</script>

<style>
.attempt-card {
width: 100%;
margin-bottom: 16px;
border: 1px solid yellowgreen;
}
.attempt-card .info {
width: 94px;
}
.attempt-card .info-block {
display: flex;
}
.spaced {
justify-content: space-evenly;
}
@media only screen and (min-width: 600px) {
.attempt-card {
width: 330px;
margin: 0px;
}
}
.attempt-row {
display: flex;
flex-wrap: wrap;
}
</style>
<style></style>
14 changes: 9 additions & 5 deletions components/climbingRoutes/ClimbingRoutesAddForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,15 @@ export default {
},
})
.then((data) => {
this.$emit("updateListItem", {
...data.result,
hasGrade: { french: this.form.french },
});
this.$emit("updateListItem");
});
this.form = {
name: "",
sector: "",
french: "",
link: "",
city: "",
};
this.$bvModal.hide("climbingRouteAddForm");
},
onReset(event) {
Expand All @@ -174,7 +178,7 @@ export default {
this.form = {
name: "",
sector: "",
grade: "",
french: "",
link: "",
city: "",
};
Expand Down
5 changes: 1 addition & 4 deletions components/climbingRoutes/ClimbingRoutesEditForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ export default {
},
})
.then((data) => {
this.$emit("updateItemById", this.form.id, {
...data.result,
hasGrade: { french: this.form.hasGrade.french },
});
this.$emit("updateListItem");
})
.catch((e) => {
console.error(e);
Expand Down
3 changes: 0 additions & 3 deletions components/climbingRoutes/RouteTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ export default {
editItem(route) {
this.$emit("editItem", route);
},
updateItemById(id) {
this.$emit("updateItemById", id);
},
deleteItemById(id) {
this.$emit("deleteItemById", id);
},
Expand Down
27 changes: 27 additions & 0 deletions components/ropes/Empty.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<b-card tag="article" class="attempt-card">
<small>
<b-btn id="add" @click.stop="addNew()"> Add </b-btn> Click here to add new
rope
</small>
</b-card>
</template>

<script>
export default {
name: "Empty",
data() {
return {
size: 200,
showDelete: false,
};
},
methods: {
addNew() {
this.$bvModal.show("ropeAddForm");
},
},
};
</script>

<style></style>
5 changes: 3 additions & 2 deletions components/ropes/RopeAddForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default {
data() {
return {
previewImageSrc: "",
form: defaultValues,
form: { ...defaultValues },
};
},
methods: {
Expand Down Expand Up @@ -206,8 +206,9 @@ export default {
},
})
.then((data) => {
this.$emit("updateListItem", data.result.rope);
this.$emit("updateListItem");
});
this.form = { ...defaultValues };
this.$bvModal.hide("addRopeForm");
},
onReset(event) {
Expand Down
8 changes: 4 additions & 4 deletions components/ropes/RopeEditForm.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<b-modal id="editRopeForm" title="Edit Rope Form" hide-footer>
<b-modal id="ropeEditForm" title="Edit Rope Form" hide-footer>
<b-form @submit="onSubmit" @reset="onReset">
<b-form-group
v-slot="{ ariaDescribedby }"
Expand Down Expand Up @@ -220,14 +220,14 @@ export default {
},
})
.then((data) => {
this.$emit("updateItemById", this.form.id, data.result);
this.$emit("updateListItem");
});
this.$bvModal.hide("editRopeForm");
this.$bvModal.hide("ropeEditForm");
},
onReset(event) {
event.preventDefault();
this.$bvModal.hide("editRopeForm");
this.$bvModal.hide("ropeEditForm");
// Reset our form values
this.form = { ...defaultValues };
},
Expand Down
110 changes: 110 additions & 0 deletions components/ropes/RopesCards.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<template>
<div class="jc-c spaced item-row">
<Empty />

<b-card
v-for="item in ropes"
:key="item.id"
tag="article"
class="item-card"
>
<div class="info-block">
<span class="info"><strong>brand</strong></span>
<span>{{ `${item.brand}` }}</span>
</div>
<div class="info-block">
<span class="info"><strong>length</strong></span>
<span>{{ `${item.length} m` }}</span>
</div>
<div class="info-block">
<span class="info"><strong>thickness</strong></span>
<span>{{ `${item.thickness} mm` }}</span>
</div>
<div class="info-block">
<span class="info"><strong>color</strong></span>
<span>{{ `${item.color}` }}</span>
</div>
<div class="info-block">
<span class="info"><strong> purchase date</strong></span>
<span>{{
item.purchaseDate
? `${new Date(item.purchaseDate).getDate()}/${
new Date(item.purchaseDate).getMonth() + 1
}/${new Date(item.purchaseDate).getFullYear()}`
: "N.A."
}}</span>
</div>

<template #footer>
<div>
<b-btn @click.stop="editItem(item)">
<b-icon icon="pencil" scale="0.75" />
</b-btn>
<b-btn
:id="`${item.id}deleteRope`"
@click.stop="showPopoverById(item.id)"
>
<b-icon icon="trash" scale="0.75"
/></b-btn>
<b-popover
:show="itemId === item.id"
:target="`${item.id}deleteRope`"
triggers="focus"
title="Click on Delete if you are sure"
>
<b-btn @click="showPopoverById(null)">Cancel</b-btn>
<b-btn variant="danger" @click="deleteItemById(item.id)"
>Delete</b-btn
>
</b-popover>
</div>
</template>
</b-card>
</div>
</template>

<script>
import Empty from "./Empty.vue";
export default {
name: "RopesCards",
components: {
Empty,
},
props: {
ropes: {
type: Array,
default: () => [],
},
},
data() {
return {
itemId: null,
};
},
methods: {
showPopoverById(id) {
this.itemId = id;
},
editItem(item) {
this.$store.commit("setEditingItem", item);
this.$bvModal.show("ropeEditForm");
},
async deleteItemById(id) {
await this.$axios.$delete(`/api/v1/ropes/${id}`, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${this.$store.getters.accessToken}`,
},
});
const ropes = await this.$axios.$get("api/v1/ropes");
this.$store.commit("setResources", {
name: "ropes",
resources: ropes.result,
});
},
},
};
</script>

<style></style>
Loading

0 comments on commit b2f2a4a

Please sign in to comment.