| 1 |
<template> |
| 2 |
<div class="hello"> |
| 3 |
<transition appear name="fade"> |
| 4 |
<loading :text="translations.loading.checking" v-if="loading"></loading> |
| 5 |
<div v-else> |
| 6 |
<bubble key="bubble"> |
| 7 |
<p v-if="activeCase && activeCase.status === 'open'">{{translations.case.activeCase}}</p> |
| 8 |
<p v-else>{{translations.case.newCase}}</p> |
| 9 |
</bubble> |
| 10 |
<div key="otto"> |
| 11 |
<img :src="updatedApi.static_url + '/robot-full.svg'" alt="Otto the Robot"> |
| 12 |
</div> |
| 13 |
<md-button v-if="activeCase && activeCase.status === 'open'" class="md-raised md-primary" @click="continueCase" key="continueButton">{{translations.case.continueButton}}</md-button> |
| 14 |
<md-button class="md-raised md-primary" key="newButton" @click="startNew">{{translations.case.newButton}}</md-button> |
| 15 |
</div> |
| 16 |
</transition> |
| 17 |
</div> |
| 18 |
</template> |
| 19 |
|
| 20 |
<script> |
| 21 |
import store from '@/store' |
| 22 |
import { mapState, mapActions, mapMutations, mapGetters } from 'vuex' |
| 23 |
import Bubble from './Bubble' |
| 24 |
import Loading from './Loading' |
| 25 |
|
| 26 |
export default { |
| 27 |
name: 'hello', |
| 28 |
components: { Bubble, Loading }, |
| 29 |
store, |
| 30 |
data () { |
| 31 |
return { |
| 32 |
loading: true |
| 33 |
} |
| 34 |
}, |
| 35 |
mounted () { |
| 36 |
this.loading = true |
| 37 |
this.getActiveCase() |
| 38 |
.then(() => { |
| 39 |
this.loading = false |
| 40 |
this.checkUrl() |
| 41 |
}) |
| 42 |
}, |
| 43 |
computed: { |
| 44 |
...mapState([ |
| 45 |
'api', |
| 46 |
'activeCase', |
| 47 |
'router', |
| 48 |
'requestProtocol', |
| 49 |
'translations' |
| 50 |
]), |
| 51 |
...mapGetters([ |
| 52 |
'updatedApi' |
| 53 |
]) |
| 54 |
}, |
| 55 |
methods: { |
| 56 |
checkUrl () { |
| 57 |
let params = new URLSearchParams(window.location.search) |
| 58 |
let setUrl = params.get('url') |
| 59 |
if (setUrl) { |
| 60 |
let url = document.createElement('a') |
| 61 |
url.setAttribute('href', setUrl) |
| 62 |
if (url.protocol !== this.requestProtocol) { |
| 63 |
setUrl.replace(url.protocol, this.requestProtocol) |
| 64 |
} |
| 65 |
} |
| 66 |
this.defineCaseUrl(setUrl || this.updatedApi.site_url) |
| 67 |
}, |
| 68 |
startNew () { |
| 69 |
this.loading = true |
| 70 |
if (this.activeCase && this.activeCase.status === 'open') { |
| 71 |
this.closeCase() |
| 72 |
.then(() => { |
| 73 |
this.openCase() |
| 74 |
.then(() => { |
| 75 |
this.router.push('/find-the-problem') |
| 76 |
}) |
| 77 |
}) |
| 78 |
} else { |
| 79 |
this.loading = true |
| 80 |
this.openCase() |
| 81 |
.then(() => { |
| 82 |
this.checkUrl() |
| 83 |
this.updateCase() |
| 84 |
.then(() => { |
| 85 |
this.router.push('/find-the-problem') |
| 86 |
}) |
| 87 |
}) |
| 88 |
} |
| 89 |
}, |
| 90 |
continueCase () { |
| 91 |
if (this.activeCase.clues.length) { |
| 92 |
this.router.push('/interrogating') |
| 93 |
} else { |
| 94 |
this.router.push('/find-the-problem') |
| 95 |
} |
| 96 |
}, |
| 97 |
...mapActions([ |
| 98 |
'getActiveCase', |
| 99 |
'openCase', |
| 100 |
'closeCase', |
| 101 |
'updateCase' |
| 102 |
]), |
| 103 |
...mapMutations([ |
| 104 |
'defineCaseUrl' |
| 105 |
]) |
| 106 |
} |
| 107 |
} |
| 108 |
</script> |
| 109 |
|