2018-09-14 07:38:33 +02:00
< template >
2019-03-02 11:25:10 +01:00
< div class = "loader-container" v -bind : class = "{ 'is-loading': teamService.loading}" >
2018-09-14 07:38:33 +02:00
< div class = "card" v-if = "userIsAdmin" >
< header class = "card-header" >
< p class = "card-header-title" >
Edit Team
< / p >
< / header >
< div class = "card-content" >
< div class = "content" >
< form @submit.prevent ="submit()" >
< div class = "field" >
< label class = "label" for = "teamtext" > Team Name < / label >
< div class = "control" >
2019-03-02 11:25:10 +01:00
< input v -focus : class = "{ 'disabled': teamMemberService.loading}" :disabled = "teamMemberService.loading" class = "input" type = "text" id = "teamtext" placeholder = "The team text is here..." v-model = "team.name" >
2018-09-14 07:38:33 +02:00
< / div >
< / div >
< div class = "field" >
< label class = "label" for = "teamdescription" > Description < / label >
< div class = "control" >
2019-03-02 11:25:10 +01:00
< textarea : class = "{ 'disabled': teamService.loading}" :disabled = "teamService.loading" class = "textarea" placeholder = "The teams description goes here..." id = "teamdescription" v-model = "team.description" > < / textarea >
2018-09-14 07:38:33 +02:00
< / div >
< / div >
< / form >
< div class = "columns bigbuttons" >
< div class = "column" >
2019-03-02 11:25:10 +01:00
< button @click ="submit()" class = "button is-success is-fullwidth" : class = "{ 'is-loading': teamService.loading}" >
2018-09-14 07:38:33 +02:00
Save
< / button >
< / div >
< div class = "column is-1" >
2019-03-02 11:25:10 +01:00
< button @ click = "showDeleteModal = true" class = "button is-danger is-fullwidth" : class = "{ 'is-loading': teamService.loading}" >
2018-09-14 07:38:33 +02:00
< span class = "icon is-small" >
< icon icon = "trash-alt" / >
< / span >
< / button >
< / div >
< / div >
< / div >
< / div >
< / div >
< div class = "card" >
< header class = "card-header" >
< p class = "card-header-title" >
Team Members
< / p >
< / header >
2018-09-14 08:29:09 +02:00
< div class = "card-content content team-members" >
2018-09-17 08:28:43 +02:00
< form @submit.prevent ="addUser()" class = "add-member-form" v-if = "userIsAdmin" >
2018-09-14 08:41:28 +02:00
< div class = "field is-grouped" >
2019-03-02 11:25:10 +01:00
< p class = "control has-icons-left is-expanded" v -bind : class = "{ 'is-loading': teamMemberService.loading}" >
< input class = "input" v -bind : class = "{ 'disabled': teamMemberService.loading}" v -model .number = " member.id " type = "text" placeholder = "Add a new user..." >
2018-09-14 08:41:28 +02:00
< span class = "icon is-small is-left" >
< icon icon = "user" / >
< / span >
< / p >
< p class = "control" >
< button type = "submit" class = "button is-success" >
< span class = "icon is-small" >
< icon icon = "plus" / >
< / span >
Add
< / button >
< / p >
< / div >
< / form >
2018-09-14 08:29:09 +02:00
< table class = "table is-striped is-hoverable is-fullwidth" >
< tbody >
< tr v-for = "m in team.members" :key="m.id" >
< td > { { m . username } } < / td >
< td >
< template v-if = "m.id === user.infos.id" >
< b class = "is-success" > You < / b >
< / template >
< / td >
< td class = "type" >
< template v-if = "m.admin" >
< span class = "icon is-small" >
< icon icon = "lock" / >
< / span >
Admin
< / template >
< template v-else >
< span class = "icon is-small" >
< icon icon = "user" / >
< / span >
Member
< / template >
< / td >
< td class = "actions" v-if = "userIsAdmin" >
2019-03-02 11:25:10 +01:00
< button @click ="toggleUserType(m)" class = "button buttonright is-primary" v-if = "m.id !== user.infos.id" >
2018-09-14 08:29:09 +02:00
Make
< template v-if = "!m.admin" >
Admin
< / template >
< template v-else >
Member
< / template >
< / button >
2019-03-02 11:25:10 +01:00
< button @ click = "member = m; showUserDeleteModal = true" class = "button is-danger" v-if = "m.id !== user.infos.id" >
2018-09-14 08:29:09 +02:00
< span class = "icon is-small" >
< icon icon = "trash-alt" / >
< / span >
< / button >
< / td >
< / tr >
< / tbody >
2018-09-14 07:38:33 +02:00
< / table >
< / div >
< / div >
2018-09-14 08:29:09 +02:00
<!-- Team delete modal -- >
2018-09-14 07:38:33 +02:00
< modal
v - if = "showDeleteModal"
@ close = "showDeleteModal = false"
v - on : submit = "deleteTeam()" >
< span slot = "header" > Delete the team < / span >
< p slot = "text" > Are you sure you want to delete this team and all of its members ? < br / >
All team members will loose access to lists and namespaces shared with this team . < br / >
< b > This CANNOT BE UNDONE ! < / b > < / p >
< / modal >
2018-09-14 08:29:09 +02:00
<!-- User delete modal -- >
< modal
v - if = "showUserDeleteModal"
@ close = "showUserDeleteModal = false"
2018-09-14 08:41:28 +02:00
v - on : submit = "deleteUser()" >
2018-09-14 08:29:09 +02:00
< span slot = "header" > Remove a user from the team < / span >
< p slot = "text" > Are you sure you want to remove this user from the team ? < br / >
He will loose access to all lists and namespaces this team has access to . < br / >
< b > This CANNOT BE UNDONE ! < / b > < / p >
< / modal >
2018-09-14 07:38:33 +02:00
< / div >
< / template >
< script >
2019-03-02 11:25:10 +01:00
import auth from '../../auth'
import router from '../../router'
import message from '../../message'
import TeamService from '../../services/team'
import TeamModel from '../../models/team'
import TeamMemberService from '../../services/teamMember'
import TeamMemberModel from '../../models/teamMember'
2018-09-14 07:38:33 +02:00
2019-03-02 11:25:10 +01:00
export default {
name : "EditTeam" ,
data ( ) {
return {
teamService : TeamService ,
teamMemberService : TeamMemberService ,
team : TeamModel ,
member : TeamMemberModel ,
showDeleteModal : false ,
2018-09-14 08:29:09 +02:00
showUserDeleteModal : false ,
2018-09-14 07:38:33 +02:00
user : auth . user ,
userIsAdmin : false ,
2019-03-02 11:25:10 +01:00
}
} ,
beforeMount ( ) {
// Check if the user is already logged in, if so, redirect him to the homepage
if ( ! auth . user . authenticated ) {
router . push ( { name : 'home' } )
}
} ,
created ( ) {
this . teamService = new TeamService ( )
this . teamMemberService = new TeamMemberService ( )
this . loadTeam ( )
} ,
watch : {
// call again the method if the route changes
'$route' : 'loadTeam'
} ,
2018-09-14 07:38:33 +02:00
methods : {
2019-03-02 11:25:10 +01:00
loadTeam ( ) {
this . member = new TeamMemberModel ( { teamID : this . $route . params . id } )
this . team = new TeamModel ( { id : this . $route . params . id } )
this . teamService . get ( this . team )
. then ( response => {
this . $set ( this , 'team' , response )
let members = response . members
2018-09-14 07:38:33 +02:00
for ( const m in members ) {
2019-03-02 11:25:10 +01:00
members [ m ] . teamID = this . $route . params . id
2018-09-14 07:39:54 +02:00
if ( members [ m ] . id === this . user . infos . id && members [ m ] . admin ) {
this . userIsAdmin = true
2018-09-14 07:38:33 +02:00
}
}
2019-03-02 11:25:10 +01:00
} )
. catch ( e => {
message . error ( e , this )
} )
} ,
submit ( ) {
this . teamService . update ( this . team )
. then ( response => {
this . team = response
message . success ( { message : 'The team was successfully updated.' } , this )
} )
. catch ( e => {
message . error ( e , this )
} )
} ,
deleteTeam ( ) {
this . teamService . delete ( this . team )
. then ( ( ) => {
message . success ( { message : 'The team was successfully deleted.' } , this )
router . push ( { name : 'listTeams' } )
} )
. catch ( e => {
message . error ( e , this )
} )
2018-09-14 07:38:33 +02:00
} ,
2018-09-14 08:29:09 +02:00
deleteUser ( ) {
2019-03-02 11:25:10 +01:00
this . teamMemberService . delete ( this . member )
2018-09-14 08:29:09 +02:00
. then ( ( ) => {
2019-03-02 11:25:10 +01:00
message . success ( { message : 'The user was successfully deleted from the team.' } , this )
2018-09-14 08:29:09 +02:00
this . loadTeam ( )
} )
. catch ( e => {
2019-03-02 11:25:10 +01:00
message . error ( e , this )
} )
. finally ( ( ) => {
this . showUserDeleteModal = false
2018-09-14 08:29:09 +02:00
} )
} ,
2019-03-02 11:25:10 +01:00
addUser ( ) {
this . teamMemberService . create ( this . member )
2018-09-14 08:29:09 +02:00
. then ( ( ) => {
2018-09-14 08:41:28 +02:00
this . loadTeam ( )
2019-03-02 11:25:10 +01:00
message . success ( { message : 'The team member was successfully added.' } , this )
2018-09-14 08:29:09 +02:00
} )
. catch ( e => {
2019-03-02 11:25:10 +01:00
message . error ( e , this )
2018-09-14 08:29:09 +02:00
} )
} ,
2019-03-02 11:25:10 +01:00
toggleUserType ( member ) {
this . member = member
this . member . admin = ! member . admin
2018-09-14 08:29:09 +02:00
this . deleteUser ( )
2019-03-02 11:25:10 +01:00
this . addUser ( )
}
2018-09-14 07:38:33 +02:00
}
2019-03-02 11:25:10 +01:00
}
2018-09-14 07:38:33 +02:00
< / script >
2018-09-14 08:29:09 +02:00
< style lang = "scss" scoped >
2018-09-14 07:38:33 +02:00
. card {
margin - bottom : 1 rem ;
2018-09-14 08:29:09 +02:00
2018-09-14 08:41:28 +02:00
. add - member - form {
margin : 1 rem ;
}
2018-09-14 08:29:09 +02:00
. table {
2018-09-14 08:41:28 +02:00
border - top : 1 px solid darken ( # fff , 15 % ) ;
2018-12-25 16:03:51 +01:00
border - radius : 4 px ;
overflow : hidden ;
2018-09-14 08:41:28 +02:00
2018-09-14 08:29:09 +02:00
td {
vertical - align : middle ;
}
td . type , td . actions {
width : 200 px ;
}
td . actions {
text - align : right ;
}
}
}
. team - members {
padding : 0 ;
2018-09-14 07:38:33 +02:00
}
< / style >