Newer
Older
Sébastien DA ROCHA
committed
<template>
<div class="fourteen wide column">
<h1 class="ui header">
Gérer les membres
</h1>
Sébastien DA ROCHA
committed
<div
id="form-feature-edit"
class="ui form"
name="add-member"
>
<div class="two fields">
<div class="field">
<Dropdown
:options="userOptions"
:selected="newMember.user.name"
:selection.sync="newMember.user"
:search="true"
:clearable="true"
/>
<ul
id="errorlist"
class="errorlist"
>
<li
v-for="error in newMember.errors"
:key="error"
>
</div>
<div class="field">
<Dropdown
:options="levelOptions"
:selected="newMember.role.name"
:selection.sync="newMember.role"
<span class="padding-1">Ajouter</span>
</button>
<h4>Modifier le rôle d'un membre</h4>
<div
id="form-members"
class="ui form"
>
Sébastien DA ROCHA
committed
<table class="ui red table">
<thead>
<tr>
<th>
Membre
<i
:class="{
down: isSortedAsc('member'),
up: isSortedDesc('member'),
}"
class="icon sort"
@click="changeSort('member')"
/>
</th>
<th>
Niveau d'autorisation
<i
:class="{
down: isSortedAsc('role'),
up: isSortedDesc('role'),
}"
class="icon sort"
@click="changeSort('role')"
/>
</th>
Sébastien DA ROCHA
committed
</tr>
</thead>
<tbody>
<tr
v-for="member in projectMembers"
:key="member.username"
>
{{ member.user.last_name }} {{ member.user.first_name }}<br><i>{{ member.user.username }}</i>
<div class="required field online">
<Dropdown
:options="levelOptions"
:selected="member.userLevel.name"
:selection.sync="member.userLevel"
:search="true"
/>
<button
type="button"
class="ui icon button"
</button>
</div>
</td>
</tr>
Sébastien DA ROCHA
committed
</tbody>
</table>
Sébastien DA ROCHA
committed
<button
type="button"
class="ui teal icon button"
@click="saveMembers"
>
Sébastien DA ROCHA
committed
</button>
Sébastien DA ROCHA
committed
</div>
</template>
<script>
import { mapState } from 'vuex';
import Dropdown from '@/components/Dropdown.vue';
Sébastien DA ROCHA
committed
export default {
Sébastien DA ROCHA
committed
directives: {
frag,
},
components: {
Dropdown,
},
data() {
return {
{ name: 'Utilisateur connecté', value: 'logged_user' },
{ name: 'Contributeur', value: 'contributor' },
{ name: 'Super Contributeur', value: 'super_contributor' },
{ name: 'Modérateur', value: 'moderator' },
{ name: 'Administrateur projet', value: 'admin' },
Sébastien DA ROCHA
committed
],
role: {
name: 'Contributeur',
value: 'contributor',
sort: {
ascending: true,
},
Sébastien DA ROCHA
committed
};
},
...mapState('projects', ['project']),
userOptions: function () {
return this.projectUsers
.filter((el) => el.userLevel.value === 'logged_user')
if (el.user.last_name) {
name: [name, el.user.username],
value: el.user.id,
};
});
},
levelOptions: function () {
return this.options.filter(
(el) =>
(this.project && this.project.moderation ? el : el.value !== 'moderator') &&
.filter((el) => el.userLevel.value !== 'logged_user')
if (this.sort.column !== '') {
if (this.sort.column === 'member') {
const textA = a.user.username.toUpperCase();
const textB = b.user.username.toUpperCase();
if (this.sort.ascending) {
return textA < textB ? -1 : textA > textB ? 1 : 0;
} else {
return textA > textB ? -1 : textA < textB ? 1 : 0;
}
const textA = a.userLevel.name.toUpperCase();
const textB = b.userLevel.name.toUpperCase();
if (this.sort.ascending) {
return textA < textB ? -1 : textA > textB ? 1 : 0;
} else {
return textA > textB ? -1 : textA < textB ? 1 : 0;
}
}
this.$store.dispatch('projects/GET_PROJECT', this.$route.params.slug);
this.$store.dispatch('projects/GET_PROJECT_INFO', this.$route.params.slug);
}
this.populateMembers();
},
destroyed() {
//* allow user to change page if ever stuck on loader
this.$store.commit('DISCARD_LOADER');
},
Sébastien DA ROCHA
committed
methods: {
validateNewMember() {
this.newMember.errors = [];
if (!this.newMember.user.value) {
this.newMember.errors.push('Veuillez compléter ce champ.');
changeUserRole(id, role) {
const indexOfUser = this.projectUsers.findIndex(
(el) => el.user.id === id
);
//* modify its userLever
this.projectUsers[indexOfUser].userLevel = role;
},
this.changeUserRole(this.newMember.user.value, this.newMember.role);
this.newMember.user = { value: '', name: '' };
},
isSortedAsc(column) {
return this.sort.column === column && this.sort.ascending;
},
isSortedDesc(column) {
return this.sort.column === column && !this.sort.ascending;
},
changeSort(column) {
if (this.sort.column === column) {
//changer order
this.sort.ascending = !this.sort.ascending;
} else {
this.sort.column = column;
this.sort.ascending = true;
}
removeMember(member) {
this.changeUserRole(member.user.id, {
name: 'Utilisateur connecté',
value: 'logged_user',
});
},
const data = this.projectUsers.map((member) => {
return {
user: member.user,
level: {
display: member.userLevel.name,
codename: member.userLevel.value,
},
};
});
axios
.put(
`${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.project.slug}/utilisateurs/`,
data
)
Sébastien DA ROCHA
committed
.then((response) => {
if (response.status === 200) {
this.$store.dispatch('GET_USER_LEVEL_PROJECTS'); //* update user status in top right menu
this.$store.commit('DISPLAY_MESSAGE', { comment: 'Permissions mises à jour', level: 'positive' });
{
comment : "Une erreur s'est produite pendant la mises à jour des permissions",
Sébastien DA ROCHA
committed
})
.catch((error) => {
throw error;
});
Sébastien DA ROCHA
committed
},
fetchMembers() {
// todo: move function to a service
Sébastien DA ROCHA
committed
return axios
.get(
`${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/utilisateurs/`
Sébastien DA ROCHA
committed
)
.then((response) => response.data)
Sébastien DA ROCHA
committed
.catch((error) => {
throw error;
});
},
this.$store.commit(
'DISPLAY_LOADER',
'Récupération des membres en cours...'
this.fetchMembers().then((members) => {
this.projectUsers = members.map((el) => {
Sébastien DA ROCHA
committed
return {
userLevel: { name: el.level.display, value: el.level.codename },
Sébastien DA ROCHA
committed
...el,
};
});
});
},
},
};
</script>
<style>
.padding-1 {
padding: 0 1em;
}
i.icon.sort:not(.down):not(.up) {
color: rgb(220, 220, 220);
}
.online {
display: flex;
}