From af384a9f4b593b639a53e198ab8e81277540bb40 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 18 Sep 2018 07:38:26 +0200 Subject: [PATCH] Added methods to give a team access to a list --- src/components/lists/EditList.vue | 149 ++++++++++++++++++++++++++++-- src/main.js | 2 + 2 files changed, 145 insertions(+), 6 deletions(-) diff --git a/src/components/lists/EditList.vue b/src/components/lists/EditList.vue index 74fae091c..d17c99b93 100644 --- a/src/components/lists/EditList.vue +++ b/src/components/lists/EditList.vue @@ -112,6 +112,81 @@ +
+ +
+

+ Teams with access to this list +

+
+
+
+
+

+ + + + +

+

+ +

+
+
+ + + + + + + + +
+ + {{t.name}} + + + + + + + + +
+
+
- Remove a user from the team -

Are you sure you want to remove this user from the team?
- He will loose access to all lists and namespaces this team has access to.
+ Remove a user from the list +

Are you sure you want to remove this user from the list?
+ This CANNOT BE UNDONE!

+
+ + + + Remove a team from the list +

Are you sure you want to remove this team from the list?
This CANNOT BE UNDONE!

@@ -148,12 +232,19 @@ error: '', loading: false, showDeleteModal: false, - listUsers: [], user: auth.user, userIsAdmin: false, + + listUsers: [], newUser: {user_id: 0}, showUserDeleteModal: false, userToDelete: 0, + + listTeams: [], + teamIsAdmin: false, + newTeam: {team_id: 0}, + showTeamDeleteModal: false, + teamToDelete: 0, } }, beforeMount() { @@ -180,6 +271,7 @@ this.userIsAdmin = true } this.loadUsers() + this.loadTeams() this.loading = false }) .catch(e => { @@ -263,6 +355,51 @@ this.deleteUser() this.addUser(!current) }, + loadTeams() { + HTTP.get(`lists/` + this.$route.params.id + `/teams`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) + .then(response => { + this.$set(this, 'listTeams', response.data) + this.loading = false + }) + .catch(e => { + this.handleError(e) + }) + }, + deleteTeam() { + HTTP.delete(`lists/` + this.$route.params.id + `/teams/` + this.teamToDelete, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) + .then(() => { + this.showTeamDeleteModal = false; + this.handleSuccess({message: 'The team was successfully deleted from the list.'}) + this.loadTeams() + }) + .catch(e => { + this.handleError(e) + }) + }, + addTeam(admin) { + if(admin === null) { + admin = false + } + this.newTeam.right = 0 + if (admin) { + this.newTeam.right = 2 + } + + HTTP.put(`lists/` + this.$route.params.id + `/teams`, this.newTeam, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}) + .then(() => { + this.loadTeams() + this.handleSuccess({message: 'The team was successfully added.'}) + }) + .catch(e => { + this.handleError(e) + }) + }, + toggleTeamType(teamid, current) { + this.teamToDelete = teamid + this.newTeam.team_id = teamid + this.deleteTeam() + this.addTeam(!current) + }, handleError(e) { this.loading = false message.error(e, this) @@ -283,7 +420,7 @@ .card{ margin-bottom: 1rem; - .add-user-form { + .add-user-form, .add-team-form { margin: 1rem; } @@ -304,7 +441,7 @@ } } - .users-list{ + .users-list, .teams-list{ padding: 0; } \ No newline at end of file diff --git a/src/main.js b/src/main.js index 161fb192f..812e435c5 100644 --- a/src/main.js +++ b/src/main.js @@ -28,6 +28,7 @@ import { faTrashAlt } from '@fortawesome/free-solid-svg-icons' import { faUsers } from '@fortawesome/free-solid-svg-icons' import { faUser } from '@fortawesome/free-solid-svg-icons' import { faLock } from '@fortawesome/free-solid-svg-icons' +import { faPen } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' library.add(faSignOutAlt) @@ -41,6 +42,7 @@ library.add(faTrashAlt) library.add(faUsers) library.add(faUser) library.add(faLock) +library.add(faPen) Vue.component('icon', FontAwesomeIcon)