|
| 1 | +import Vue from 'vue' |
| 2 | +import App from './App.vue' |
| 3 | +import router from './router' |
| 4 | +import BootstrapVue from 'bootstrap-vue' |
| 5 | +import VueStash from 'vue-stash' |
| 6 | +import axios from 'axios' |
| 7 | +import config from './config' |
| 8 | + |
| 9 | +Vue.use(VueStash) |
| 10 | + |
| 11 | +Vue.mixin({ |
| 12 | + methods: { |
| 13 | + markdown (text) { |
| 14 | + return marked(text) |
| 15 | + }, |
| 16 | + post (route, data, competition) { |
| 17 | + return axios.post(config.API_URL + (competition === false ? '' : ('/competitions/' + this.$store.competition.id)) + route, data, { headers: { Authorization: 'Token ' + localStorage['token'] } }) |
| 18 | + }, |
| 19 | + get (route, competition) { |
| 20 | + return axios.get(config.API_URL + (competition === false ? '' : ('/competitions/' + this.$store.competition.id)) + route, { headers: { Authorization: 'Token ' + localStorage['token'] } }) |
| 21 | + }, |
| 22 | + patch (route, data, competition) { |
| 23 | + return axios.patch(config.API_URL + (competition === false ? '' : ('/competitions/' + this.$store.competition.id)) + route, data, { headers: { Authorization: 'Token ' + localStorage['token'] } }) |
| 24 | + }, |
| 25 | + put (route, data, competition) { |
| 26 | + return axios.put(config.API_URL + (competition === false ? '' : ('/competitions/' + this.$store.competition.id)) + route, data, { headers: { Authorization: 'Token ' + localStorage['token'] } }) |
| 27 | + }, |
| 28 | + deleteRequest (route, competition) { |
| 29 | + return axios.delete(config.API_URL + (competition === false ? '' : ('/competitions/' + this.$store.competition.id)) + route, { headers: { Authorization: 'Token ' + localStorage['token'] } }) |
| 30 | + }, |
| 31 | + logout () { |
| 32 | + localStorage.removeItem('token') |
| 33 | + this.reload() |
| 34 | + this.alert('Success!', 'You have been logged out.', 'success') |
| 35 | + }, |
| 36 | + updateCompetition (competition) { |
| 37 | + this.$store.competition = competition |
| 38 | + localStorage.competition = competition.id |
| 39 | + this.reload().then(function () { this.routerKey++ }.bind(this)) |
| 40 | + }, |
| 41 | + reload () { |
| 42 | + var emptyUser = { |
| 43 | + id: null, |
| 44 | + username: null, |
| 45 | + eligible: null, |
| 46 | + created: null, |
| 47 | + team: { |
| 48 | + id: null, |
| 49 | + name: null, |
| 50 | + members: [], |
| 51 | + eligible: null, |
| 52 | + affiliation: null, |
| 53 | + created: null, |
| 54 | + score: null, |
| 55 | + solves: [] |
| 56 | + } |
| 57 | + } |
| 58 | + return this.get('/competitions', false).then(function (res) { |
| 59 | + this.$store.competitions = res.data |
| 60 | + }.bind(this)).then(() => this.get('/self', false)).then(function (res) { |
| 61 | + this.$store.user = res.data.user |
| 62 | + this.$store.competition = localStorage.competition && this.$store.competitions.filter(c => c.id === parseInt(localStorage.competition))[0] ? this.$store.competitions.filter(c => c.id === parseInt(localStorage.competition))[0] : this.$store.competitions[0] |
| 63 | + this.$store.competitionLoaded = true |
| 64 | + this.$store.loaded = true |
| 65 | + }.bind(this)) |
| 66 | + } |
| 67 | + } |
| 68 | +}) |
| 69 | + |
| 70 | + |
| 71 | +Vue.use(BootstrapVue); |
| 72 | + |
| 73 | +Vue.config.productionTip = false |
| 74 | + |
| 75 | +new Vue({ |
| 76 | + router, |
| 77 | + components: { App }, |
| 78 | + template: '<App/>', |
| 79 | + data: { |
| 80 | + store: { |
| 81 | + user: { |
| 82 | + id: null, |
| 83 | + username: null, |
| 84 | + eligible: null, |
| 85 | + created: null, |
| 86 | + team: { |
| 87 | + id: null, |
| 88 | + name: null, |
| 89 | + members: [], |
| 90 | + eligible: null, |
| 91 | + affiliation: null, |
| 92 | + created: null, |
| 93 | + score: null, |
| 94 | + solves: [] |
| 95 | + }, |
| 96 | + theme: '', |
| 97 | + }, |
| 98 | + competition: null, |
| 99 | + competitions: [], |
| 100 | + loaded: false, |
| 101 | + competitionLoaded: false, |
| 102 | + alerts: [] |
| 103 | + }, |
| 104 | + refreshKey: 1 |
| 105 | + }, |
| 106 | + mounted () { |
| 107 | + this.reload() |
| 108 | + }, |
| 109 | + render: h => h(App) |
| 110 | +}).$mount('#app') |
0 commit comments