Skip to content
Snippets Groups Projects
Commit 211ca513 authored by nicrausaz's avatar nicrausaz
Browse files

Fix bugs, promises inutiles remplacées

parent c68a0544
No related branches found
No related tags found
No related merge requests found
<template>
<v-dialog v-model="is_open" persistent max-width="600px" id="mail-dialog">
<v-card>
<v-card-title>
<span class="headline">Contact</span>
</v-card-title>
<v-card-text>
<v-container grid-list-md>
<v-flex xs12>
<v-text-field label="Destinataires" readonly></v-text-field>
</v-flex>
<v-flex xs12>
<v-text-field label="Copie"></v-text-field>
</v-flex>
<v-flex xs12>
<v-textarea label="Contenu" required></v-textarea>
</v-flex>
<v-layout wrap>
<v-flex xs12 sm6>
<v-select
:items="['Refus', 'Dossier incomplet']"
label="Type de réponse"
required
></v-select>
</v-flex>
</v-layout>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="red" flat @click="is_open = false">Annuler</v-btn>
<v-btn color="green" flat @click="is_open = false">Envoyer</v-btn>
</v-card-actions>
{{to}}
</v-card>
</v-dialog>
</template>
<script>
export default {
name: 'mail-dialog',
props: {
opened: Boolean,
to: Array
},
watch: {
opened () {
this.is_open = this.opened
if (!this.is_open) {
this.$emit('closed')
}
}
},
created () {
// Get emails
console.log(this.to)
// console.log(this.to.arr.find(o => o.applicant_mail))
},
data () {
return {
is_open: false,
mail: {
to: '',
content: ''
}
}
}
}
</script>
......@@ -14,9 +14,11 @@ instance.interceptors.response.use(function (response) {
store.commit('moduleSnackbar/toggle', { open: true, message: 'API non atteignable', type: 'warning' }, { root: true })
} else if (error.response.status == 400 || error.response.status == 401) {
// Erreur de token
// store.commit('moduleSnackbar/toggle', { open: true, message: error.response.data.error, type: 'warning' }, { root: true })
// store.dispatch('moduleUser/logout', false)
console.log('token is dead')
if (error.response.data.type === 'expired') {
// Session expirée
// store.commit('moduleSnackbar/toggle', { open: true, message: error.response.data.error, type: 'warning' }, { root: true })
store.dispatch('moduleUser/logout', false)
}
} else if (error.response.status == 403 || error.response.status == 404) {
router.push({ name: 'error', params: { status: error.response.data.error, message: error.response.data.message, route: '' } })
} else {
......
import axios from '../../../plugins/axios'
export function getApplications(context) {
export function getApplications (context) {
axios({
method: 'get',
url: '/applicants'
......@@ -10,63 +10,54 @@ export function getApplications(context) {
})
}
export function getCurrentApplicationData(context, data) {
return new Promise((resolve) => {
axios({
method: 'get',
url: '/applicant/' + data.id
})
.then(response => {
context.commit('setCurrentApplicationData', response.data)
resolve()
})
export function getCurrentApplicationData (context, data) {
return axios({
method: 'get',
url: '/applicant/' + data.id
})
.then(response => {
context.commit('setCurrentApplicationData', response.data)
})
}
export function getCurrentApplicationComments(context, data) {
return new Promise((resolve) => {
axios({
method: 'get',
url: '/applicant/' + data.id + '/comments'
})
.then(response => {
let results = {
public: [],
private: []
}
response.data.public.forEach(comment => {
getOwnerData(comment.comment_owner_sciper).then(res => {
comment.ownerData = res
results.public.push(comment)
})
export function getCurrentApplicationComments (context, data) {
return axios({
method: 'get',
url: '/applicant/' + data.id + '/comments'
})
.then(response => {
let results = {
public: [],
private: []
}
response.data.public.forEach(comment => {
getOwnerData(comment.comment_owner_sciper).then(res => {
comment.ownerData = res
results.public.push(comment)
})
})
response.data.private.forEach(comment => {
getOwnerData(comment.comment_owner_sciper).then(res => {
comment.ownerData = res
results.private.push(comment)
})
response.data.private.forEach(comment => {
getOwnerData(comment.comment_owner_sciper).then(res => {
comment.ownerData = res
results.private.push(comment)
})
context.commit('setCurrentApplicationComments', results)
resolve()
})
})
context.commit('setCurrentApplicationComments', results)
})
}
export function getCurrentApplicationMarker(context, data) {
return new Promise((resolve) => {
axios({
method: 'get',
url: '/applicant/' + data.id + '/marker'
})
.then(response => {
context.commit('setCurrentApplicationMarker', response.data.marker)
resolve()
})
export function getCurrentApplicationMarker (context, data) {
return axios({
method: 'get',
url: '/applicant/' + data.id + '/marker'
})
.then(response => {
context.commit('setCurrentApplicationMarker', response.data.marker)
})
}
export function getAvailableStatus(context) {
export function getAvailableStatus (context) {
axios({
method: 'get',
url: '/status'
......@@ -76,7 +67,7 @@ export function getAvailableStatus(context) {
})
}
export function changeApplicationStatus(context, data) {
export function changeApplicationStatus (context, data) {
axios({
method: 'patch',
url: '/status/applicant/' + data.id,
......@@ -87,7 +78,7 @@ export function changeApplicationStatus(context, data) {
})
}
export function deleteApplication(context, data) {
export function deleteApplication (context, data) {
axios({
method: 'delete',
url: '/applicant/' + data.id,
......@@ -98,7 +89,7 @@ export function deleteApplication(context, data) {
})
}
export function getFile(context, data) {
export function getFile (context, data) {
axios({
method: 'get',
url: '/file/' + data.id,
......@@ -109,19 +100,17 @@ export function getFile(context, data) {
})
}
function getOwnerData(sciper) {
return new Promise((resolve) => {
axios({
method: 'get',
url: '/user/data/' + sciper
})
.then(response => {
resolve(response.data)
})
function getOwnerData (sciper) {
return axios({
method: 'get',
url: '/user/data/' + sciper
})
.then(response => {
return response.data
})
}
export function exportData(context, data) {
export function exportData (context, data) {
axios({
method: 'get',
url: '/applicant/' + data.id + '/export',
......@@ -132,7 +121,7 @@ export function exportData(context, data) {
})
}
function generateBlob(response, filename) {
function generateBlob (response, filename) {
const url = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a')
link.href = url
......@@ -141,7 +130,7 @@ function generateBlob(response, filename) {
link.click()
}
export function createMarker(context, data) {
export function createMarker (context, data) {
axios({
method: 'put',
url: '/marker',
......@@ -152,7 +141,7 @@ export function createMarker(context, data) {
})
}
export function updateMarker(context, data) {
export function updateMarker (context, data) {
axios({
method: 'patch',
url: '/marker/' + data.id,
......@@ -163,57 +152,48 @@ export function updateMarker(context, data) {
})
}
export function deleteMarker(context, data) {
export function deleteMarker (context, data) {
axios({
method: 'delete',
url: '/marker/' + data.id
})
}
export function addComment(context, data) {
return new Promise((resolve) => {
axios({
method: 'put',
url: '/comment',
data: {
applicant_id: data.applicant_id,
content: data.content,
is_private: data.is_private
}
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
resolve()
})
export function addComment (context, data) {
return axios({
method: 'put',
url: '/comment',
data: {
applicant_id: data.applicant_id,
content: data.content,
is_private: data.is_private
}
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
})
}
export function deleteComment(context, data) {
return new Promise((resolve) => {
axios({
method: 'delete',
url: '/comment/' + data.id
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
resolve()
})
export function deleteComment (context, data) {
return axios({
method: 'delete',
url: '/comment/' + data.id
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
})
}
export function updateComment(context, data) {
return new Promise((resolve) => {
axios({
method: 'patch',
url: '/comment/' + data.id,
data: {
content: data.content,
is_private: data.isPrivate
}
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
resolve()
})
export function updateComment (context, data) {
return axios({
method: 'patch',
url: '/comment/' + data.id,
data: {
content: data.content,
is_private: data.isPrivate
}
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
})
}
\ No newline at end of file
......@@ -28,4 +28,8 @@ export function setFilterStatus (state, data) {
export function setFilterSearch (state, data) {
state.filters.search = data
}
export function setMailDialogOpened (state, data) {
state.mail_dialog_opened = data
}
\ No newline at end of file
import axios from '../../../plugins/axios'
export function getPositions(context) {
export function getPositions (context) {
axios({
method: 'get',
url: '/positions'
......@@ -10,7 +10,7 @@ export function getPositions(context) {
})
}
export function getJobs(context) {
export function getJobs (context) {
axios({
method: 'get',
url: '/jobs'
......@@ -20,7 +20,7 @@ export function getJobs(context) {
})
}
export function getLocations(context) {
export function getLocations (context) {
axios({
method: 'get',
url: '/locations'
......@@ -30,7 +30,7 @@ export function getLocations(context) {
})
}
export function getAccessGroups(context) {
export function getAccessGroups (context) {
axios({
method: 'get',
url: '/groups'
......@@ -40,7 +40,7 @@ export function getAccessGroups(context) {
})
}
export function createPosition(context, data) {
export function createPosition (context, data) {
data.new_groups = []
data.access_group_cleared = []
data.access_groups.forEach(group => {
......@@ -61,7 +61,7 @@ export function createPosition(context, data) {
})
}
export function updatePosition(context, data) {
export function updatePosition (context, data) {
data.new_groups = []
data.access_group_cleared = []
data.access_groups.forEach(group => {
......@@ -71,60 +71,44 @@ export function updatePosition(context, data) {
data.access_group_cleared.push(group)
}
})
return new Promise(resolve => {
axios({
method: 'patch',
url: '/position/' + data.position_id,
data: data
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
resolve()
})
return axios({
method: 'patch',
url: '/position/' + data.position_id,
data: data
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
})
}
export function deletePosition(context, data) {
return new Promise(resolve => {
axios({
method: 'delete',
url: '/position/' + data.position_id
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
resolve()
})
export function deletePosition (context, data) {
return axios({
method: 'delete',
url: '/position/' + data.position_id
})
.then(response => {
context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true })
})
}
export function createJob(context, data) {
return new Promise((resolve, reject) => {
axios({
method: 'put',
url: '/job',
data: data
})
.then(response => {
resolve(response.data)
})
.catch(err => {
reject(err)
})
export function createJob (context, data) {
return axios({
method: 'put',
url: '/job',
data: data
})
.then(response => {
return response.data
})
}
export function createLocation(context, data) {
return new Promise((resolve, reject) => {
axios({
method: 'put',
url: '/location',
data: data
})
.then(response => {
resolve(response.data)
})
.catch(err => {
reject(err)
})
export function createLocation (context, data) {
return axios({
method: 'put',
url: '/location',
data: data
})
.then(response => {
return response.data
})
}
\ No newline at end of file
import axios from '../../../plugins/axios'
export function login(context, key) {
export function login (context, key) {
if (key) {
axios.get("/auth/login?key=" + key).then(response => {
localStorage.setItem('stored_token', response.data)
......@@ -12,34 +12,37 @@ export function login(context, key) {
}
}
export function logout(context, fullLogout) {
setLastConnection().then(() => {
localStorage.removeItem('stored_token')
if (fullLogout) {
window.location = 'https://tequila.epfl.ch/logout'
} else {
location.reload()
}
})
export function logout (context, fullLogout) {
localStorage.removeItem('stored_token')
if (fullLogout) {
// set last conn ?
window.location = 'https://tequila.epfl.ch/logout'
} else {
location.reload()
}
// setLastConnection().then(() => {
// console.log('test')
// localStorage.removeItem('stored_token')
// if (fullLogout) {
// window.location = 'https://tequila.epfl.ch/logout'
// } else {
// location.reload()
// }
// })
}
export function getUserData(context) {
return new Promise((resolve, reject) => {
axios({
method: 'get',
url: '/user'
})
.then(response => {
context.commit('setUserData', response.data)
resolve(response.data)
})
.catch(err => {
reject(err)
})
export function getUserData (context) {
return axios({
method: 'get',
url: '/user'
})
.then(response => {
context.commit('setUserData', response.data)
return response.data
})
}
export function getUserPermittedJobs(context) {
export function getUserPermittedJobs (context) {
axios({
method: 'get',
url: '/user/permittedjobs'
......@@ -49,7 +52,7 @@ export function getUserPermittedJobs(context) {
})
}
export function getLastConnection(context) {
export function getLastConnection (context) {
axios({
method: 'get',
url: '/user/connection'
......@@ -59,12 +62,9 @@ export function getLastConnection(context) {
})
}
export function setLastConnection() {
return new Promise((resolve) => {
axios({
method: 'patch',
url: '/user/connection'
})
.then(resolve())
export function setLastConnection () {
return axios({
method: 'patch',
url: '/user/connection'
})
}
\ No newline at end of file
......@@ -15,6 +15,7 @@
></v-select>
<v-btn round color="primary" @click="updateMultiple">Appliquer</v-btn>
<v-btn round color="primary" @click="deleteMultiple">Supprimer</v-btn>
<v-btn round color="primary" @click="toggleMailDialog()">Contacter</v-btn>
</div>
</v-card-title>
<v-data-table
......@@ -103,21 +104,23 @@
@change="updateStatus(props.item.applicant_id, props.item.fk_status)"
v-if="$store.getters['moduleUser/userIsResponsible']"
></v-select>
<span v-else>{{props.item.fk_status}}</span>
<span v-else>{{ props.item.fk_status }}</span>
</td>
</tr>
</template>
</v-data-table>
</div>
<MailDialog :opened="mail_dialog_opened" :to="selected" @closed="toggleMailDialog()"></MailDialog>
</div>
</template>
<script>
import ApplicationsFilters from '@/components/applicationsFilters.vue'
import MailDialog from '@/components/application/mailDialog.vue'
export default {
name: 'applications-view',
data() {
data () {
return {
selected: [],
multipleEditor: {
......@@ -139,37 +142,40 @@ export default {
{ text: 'Date postulation', value: 'applicant_application_date' },
{ text: 'Statut', value: 'fk_status' }
],
pagination: { sortBy: 'applicant_application_date', descending: true, rowsPerPage: 25 }
pagination: { sortBy: 'applicant_application_date', descending: true, rowsPerPage: 25 },
mail_dialog_opened: false
}
},
created() {
created () {
this.loadApplications()
if (!this.$store.getters['moduleUser/userIsResponsible']) {
this.headers.splice(this.headers.length-1, 0, { text: 'Note', value: 'applicant_marker' })
this.headers.splice(this.headers.length - 1, 0, { text: 'Note', value: 'applicant_marker' })
}
},
computed: {
hasSelected() { return this.selected.length > 0 }
hasSelected () { return this.selected.length > 0 }
},
methods: {
loadApplications() {
loadApplications () {
this.$store.dispatch('moduleApplications/getApplications')
this.$store.dispatch('moduleApplications/getAvailableStatus')
this.$store.dispatch('moduleUser/getUserPermittedJobs')
},
navigateTo(id) {
navigateTo (id) {
this.$router.push('/application/' + id)
},
updateStatus(id, status) {
updateStatus (id, status) {
this.$store.dispatch('moduleApplications/changeApplicationStatus', { id: id, status: status })
},
updateMultiple() {
updateMultiple () {
this.selected.forEach(item => {
this.updateStatus(item.applicant_id, this.multipleEditor.status)
})
setTimeout(() => {
this.$store.dispatch('moduleApplications/getApplications')
}, 300)
},
deleteMultiple() {
deleteMultiple () {
if (confirm('Voulez-vous vraiment supprimer les candidatures sélectionnées ? \n Cette action est irréversible.')) {
this.selected.forEach(item => {
this.$store.dispatch('moduleApplications/deleteApplication', { id: item.applicant_id })
......@@ -177,14 +183,17 @@ export default {
this.$store.dispatch('moduleApplications/getApplications')
}
},
isNew(status, date) {
toggleMailDialog () {
this.mail_dialog_opened = !this.mail_dialog_opened
},
isNew (status, date) {
if (this.$store.getters['moduleUser/userIsResponsible']) {
return status === 'Nouveau'
} else {
return date > this.$store.state.moduleUser.lastConnection.last_connection_date
}
},
getFormatedDate(value) {
getFormatedDate (value) {
let dateTimeParts = value.split(/[- :]/)
dateTimeParts[1]--
let date = new Date(...dateTimeParts)
......@@ -192,7 +201,8 @@ export default {
}
},
components: {
ApplicationsFilters
ApplicationsFilters,
MailDialog
}
}
</script>
......
......@@ -5,7 +5,7 @@
<div>
<v-toolbar flat color="white">
<v-spacer></v-spacer>
<v-dialog v-model="dialog" min-height="1700px" max-width="700px">
<v-dialog v-model="dialog" persistent min-height="1700px" max-width="700px">
<template v-slot:activator="{ on }">
<v-btn color="primary" dark class="mb-2" v-on="on">Ajouter</v-btn>
</template>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment