Moved getting teams to service

This commit is contained in:
kolaente 2019-02-27 19:35:31 +01:00
parent 030a34f61e
commit 339ec3523a
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 33 additions and 41 deletions

View File

@ -18,45 +18,41 @@
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import {HTTP} from '../../http-common'
import message from '../../message'
export default {
name: "ListTeams",
data() {
return {
teams: [],
error: '',
loading: false,
}
},
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.loadTeams()
},
import auth from '../../auth'
import router from '../../router'
import message from '../../message'
import TeamService from '../../services/team'
export default {
name: "ListTeams",
data() {
return {
teamService: TeamService,
teams: [],
error: '',
loading: false,
}
},
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.loadTeams()
},
methods: {
loadTeams() {
const cancel = message.setLoading(this)
HTTP.get(`teams`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
this.$set(this, 'teams', response.data)
cancel()
})
.catch(e => {
this.handleError(e)
})
this.teamService.getAll()
.then(response => {
this.$set(this, 'teams', response)
})
.catch(e => {
message.error(e, this)
})
},
handleError(e) {
message.error(e, this)
},
}
}
}
</script>

View File

@ -15,8 +15,4 @@ export default class TeamService extends AbstractService {
modelFactory(data) {
return new TeamModel(data)
}
// TODO: add methods to manage team members
// Remove/Add members
// Maybe extra model/service?
}