Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring api requests of Revision components to use new async await js promise syntax #412

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 42 additions & 40 deletions src/components/Revision/AddRevision.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<template>
<div>
<div>
<button type="button" class="btn btn-info btn-md falko-button" id="addButton"
data-toggle="modal" data-target="#addRevisionModal">
Add Revision
</button>
<button
type="button"
class="btn btn-info btn-md falko-button"
id="addButton"
data-toggle="modal"
data-target="#addRevisionModal"
>Add Revision</button>
</div>

<div class="row no-margin justify-content-center modal fade" id="addRevisionModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">
Add Sprint Revision
</h3>
<h3 class="modal-title">Add Sprint Revision</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
<span aria-hidden="true">&times;</span>
</button>
Expand All @@ -23,15 +24,13 @@
<listRevision parent="UndoneReport" v-on:listUpdated="updateList"></listRevision>
</div>
<div class="modal-footer">
<button class="btn btn-info btn-md falko-button"
v-bind:disabled="FieldsNotFilled" v-on:click="addRevision"
data-dismiss="modal"
>
Save
</button>
<button class="btn btn-info btn-md falko-button-grey" data-dismiss="modal">
Cancel
</button>
<button
class="btn btn-info btn-md falko-button"
v-bind:disabled="FieldsNotFilled"
v-on:click="addRevision"
data-dismiss="modal"
>Save</button>
<button class="btn btn-info btn-md falko-button-grey" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
Expand All @@ -40,65 +39,68 @@
</template>

<script>
import { mapState } from 'vuex';
import ListRevision from './ListRevision.vue';
import { HTTP } from '../../http-common';
import { mapState } from "vuex";
import ListRevision from "./ListRevision.vue";
import { HTTP as api } from "../../http-common";

export default {
components: {
listRevision: ListRevision,
listRevision: ListRevision
},

data() {
return {
doneReport: [],
undoneReport: [],
resivionId: '',
resivionId: ""
};
},

computed: {
...mapState({
token: state => state.auth.token,
token: state => state.auth.token
}),

FieldsNotFilled() {
return this.undoneReport.length === 0 || this.doneReport.length === 0;
},
}
},

methods: {
addRevision() {
async addRevision() {
const headers = { Authorization: this.token };

HTTP.post(`sprints/${this.$route.params.id}/revisions`, {
done_report: this.doneReport,
undone_report: this.undoneReport,
}, { headers })
.then((response) => {
this.$emit('revisionCreated');
this.revisionId = response.data.id;
this.$router.push({ path: `/revisions/${this.revisionId}` });
})
.catch((e) => {
this.errors.push(e);
});
try {
const response = await api.post(
`sprints/${this.$route.params.id}/revisions`,
{
done_report: this.doneReport,
undone_report: this.undoneReport
},
{ headers }
);
this.$emit("revisionCreated");
this.revisionId = response.data.id;
this.$router.push({ path: `/revisions/${this.revisionId}` });
} catch (err) {
this.errors.push(err);
}
},

updateList(items, parent) {
if (parent === 'DoneReport') {
if (parent === "DoneReport") {
this.doneReport = [];
for (let i = 0; i < items.length; i += 1) {
this.doneReport.push(items[i].title);
}
} else if (parent === 'UndoneReport') {
} else if (parent === "UndoneReport") {
this.undoneReport = [];
for (let i = 0; i < items.length; i += 1) {
this.undoneReport.push(items[i].title);
}
}
},
},
}
}
};
</script>

Expand Down
76 changes: 43 additions & 33 deletions src/components/Revision/DeleteRevision.vue
Original file line number Diff line number Diff line change
@@ -1,69 +1,79 @@
<template>
<div>
<button type="button" class="btn btn-info btn-md falko-button-danger" id="deletebutton" data-toggle="modal" data-target="#deleteRevisionModal">
Delete
</button>
<button
type="button"
class="btn btn-info btn-md falko-button-danger"
id="deletebutton"
data-toggle="modal"
data-target="#deleteRevisionModal"
>Delete</button>

<div class="modal fade" id ="deleteRevisionModal" role="dialog">
<div class="modal fade" id="deleteRevisionModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<div>
<h4 class="modal-title">Delete Revision?</h4>
</div>
<button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p><label> Are you sure?</label></p>
</div>
<div class="modal-footer">
<button v-on:click="deleteRevision()" type="button" class="btn btn-primary" data-dismiss="modal" >Yes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
</div>
<div class="modal-content">
<div class="modal-header">
<div>
<h4 class="modal-title">Delete Revision?</h4>
</div>
<button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>
<label>Are you sure?</label>
</p>
</div>
<div class="modal-footer">
<button
v-on:click="deleteRevision()"
type="button"
class="btn btn-primary"
data-dismiss="modal"
>Yes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
</div>
</template>

<script>
import { mapState } from 'vuex';
import { HTTP } from '../../http-common';
import { mapState } from "vuex";
import { HTTP as api } from "../../http-common";

export default {
name: 'deleteRevision',
name: "deleteRevision",
data() {
return {

};
return {};
},

computed: {
...mapState({
token: state => state.auth.token,
}),
token: state => state.auth.token
})
},

methods: {
async deleteRevision() {
const headers = { Authorization: this.token };

try {
const response = await HTTP.get(`/revisions/${this.$route.params.id}`, { headers });
const response = await api.get(`/revisions/${this.$route.params.id}`, {
headers
});
const id = response.data.sprint_id;

await HTTP.delete(`/revisions/${this.$route.params.id}`, { headers });
await api.delete(`/revisions/${this.$route.params.id}`, { headers });
this.$router.push({ path: `/Sprints/${id}` });
} catch (err) {
console.log(err);
}
},
},
}
}
};
</script>

<style scoped>

</style>
69 changes: 38 additions & 31 deletions src/components/Revision/EditRevision.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<template>
<div>
<div>
<button type="button" class="btn btn-info btn-md falko-button" id="addButton"
data-toggle="modal" data-target="#editRevisionModal">
Edit Revision
</button>
<button
type="button"
class="btn btn-info btn-md falko-button"
id="addButton"
data-toggle="modal"
data-target="#editRevisionModal"
>Edit Revision</button>
</div>

<div class="row no-margin justify-content-center modal fade" id="editRevisionModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">
Add Sprint Revision
</h3>
<h3 class="modal-title">Add Sprint Revision</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
<span aria-hidden="true">&times;</span>
</button>
Expand All @@ -23,7 +24,11 @@
<list-revision parent="UndoneReport" v-on:listUpdated="updateList"></list-revision>
</div>
<div class="modal-footer">
<button class="btn btn-info btn-md falko-button" v-on:click="editRevision()" data-dismiss="modal">Save</button>
<button
class="btn btn-info btn-md falko-button"
v-on:click="editRevision()"
data-dismiss="modal"
>Save</button>
<button class="btn btn-info btn-md falko-button-grey" data-dismiss="modal">Cancel</button>
</div>
</div>
Expand All @@ -33,59 +38,61 @@
</template>

<script>
import { mapState } from 'vuex';
import ListRevision from './ListRevision.vue';
import { HTTP } from '../../http-common';

import { mapState } from "vuex";
import ListRevision from "./ListRevision.vue";
import { HTTP as api } from "../../http-common";

export default {
components: {
'list-revision': ListRevision,
"list-revision": ListRevision
},

data() {
return {
doneReport: [],
undoneReport: [],
undoneReport: []
};
},

computed: {
...mapState({
token: state => state.auth.token,
}),
token: state => state.auth.token
})
},

methods: {
editRevision() {
async editRevision() {
const headers = { Authorization: this.token };

HTTP.patch(`revisions/${this.$route.params.id}`, {
done_report: this.doneReport,
undone_report: this.undoneReport,
}, { headers })
.then(() => {
this.$emit('revisionCreated');
})
.catch((e) => {
this.errors.push(e);
});
try {
await api.patch(
`revisions/${this.$route.params.id}`,
{
done_report: this.doneReport,
undone_report: this.undoneReport
},
{ headers }
);
this.$emit("revisionCreated");
} catch (err) {
this.errors.push(err);
}
},

updateList(items, parent) {
if (parent === 'DoneReport') {
if (parent === "DoneReport") {
this.doneReport = [];
for (let i = 0; i < items.length; i += 1) {
this.doneReport.push(items[i].title);
}
} else if (parent === 'UndoneReport') {
} else if (parent === "UndoneReport") {
this.undoneReport = [];
for (let i = 0; i < items.length; i += 1) {
this.undoneReport.push(items[i].title);
}
}
},
},
}
}
};
</script>

Expand Down
Loading