kandimat-user-app/src/app/euromat/components/theses.vue

294 lines
7.1 KiB
Vue
Raw Normal View History

2017-08-13 14:03:38 +02:00
<template>
2020-06-14 03:13:52 +02:00
<section v-if="thesesCount > 0 && theses.length > 0" class="theses">
2017-08-13 14:03:38 +02:00
<div class="header-progress">
2017-08-25 22:45:04 +02:00
<div>
<span class="progress-current">{{ currentThesisStep }}</span>
2017-08-25 22:45:04 +02:00
<span>/{{ thesesCount }}</span>
</div>
<button
:disabled="currentThesisStep === 1"
2017-08-25 22:45:04 +02:00
class="btn-dark btn-small"
type="button"
2019-03-20 23:39:49 +01:00
@click="goBack"
>
{{ $t('theses.backBtn') }}
2017-08-25 22:45:04 +02:00
</button>
2017-08-13 14:03:38 +02:00
</div>
<div class="theses-content">
<header class="theses-header">
2017-08-25 22:45:04 +02:00
<h2>{{ thesisCategory }}</h2>
<h1>{{ thesisTitle }}</h1>
</header>
<div class="theses-controls">
<ul class="theses-btns">
<li v-for="possiblePosition in possiblePositions" :key="possiblePosition.label">
<button type="button" @click="submitAnswer(possiblePosition, $event)">
{{ possiblePosition.label }} <component :is="'feather-' + possiblePosition.icon" />
2017-08-25 22:45:04 +02:00
</button>
</li>
</ul>
<div class="controls-sub">
<button
class="btn-dark btn-small"
type="button"
2019-03-20 23:39:49 +01:00
@click="submitAnswer(optionSkip)"
>
2020-06-14 03:13:52 +02:00
{{ optionSkip.label }}
<feather-corner-up-right />
2017-08-13 14:03:38 +02:00
</button>
2017-08-25 22:45:04 +02:00
</div>
2017-08-14 22:28:12 +02:00
</div>
2017-08-13 14:03:38 +02:00
</div>
</section>
2020-06-14 03:13:52 +02:00
<section v-else>
<span>Loading...</span>
</section>
2017-08-13 14:03:38 +02:00
</template>
<script>
import possiblePositions from '@/app/euromat/possiblePositions'
import { getTranslatedUrl } from '@/i18n/helper'
import {
apolloThesesCountQuery,
apolloThesesCountUpdate,
apolloThesesQuery,
apolloThesesUpdate
} from '@/app/euromat/graphqlQueries'
2017-08-13 14:03:38 +02:00
export default {
name: 'EuroMat',
components: {
'feather-corner-up-right': () =>
import('vue-feather-icons/icons/CornerUpRightIcon' /* webpackChunkName: "icons" */),
'feather-circle': () =>
import('vue-feather-icons/icons/CircleIcon' /* webpackChunkName: "icons" */),
'feather-thumbs-up': () =>
import('vue-feather-icons/icons/ThumbsUpIcon' /* webpackChunkName: "icons" */),
'feather-thumbs-down': () =>
import('vue-feather-icons/icons/ThumbsDownIcon' /* webpackChunkName: "icons" */)
},
2017-08-13 14:03:38 +02:00
data () {
return {
currentThesisStep: 1,
2020-06-14 03:13:52 +02:00
theses: [],
thesesCount: 0,
2017-08-13 14:03:38 +02:00
answers: []
}
},
2020-06-14 03:13:52 +02:00
apollo: {
theses: {
query: apolloThesesQuery,
update: apolloThesesUpdate
},
thesesCount: {
query: apolloThesesCountQuery,
update: apolloThesesCountUpdate
}
2020-06-14 03:13:52 +02:00
},
2017-08-13 14:03:38 +02:00
computed: {
isEmbedded () {
return (
this.$route.query.embedded &&
this.$route.query.embedded === 'iframe'
)
},
2017-08-13 14:03:38 +02:00
thesisTitle () {
if (this.currentThesisStep > this.thesesCount) {
2017-08-13 14:03:38 +02:00
return
}
return this.theses[this.currentThesisStep - 1].thesis[this.$i18n.locale]
2017-08-13 14:03:38 +02:00
},
2017-08-25 22:45:04 +02:00
thesisCategory () {
if (this.currentThesisStep > this.thesesCount) {
2017-08-25 22:45:04 +02:00
return
}
return this.theses[this.currentThesisStep - 1].category[this.$i18n.locale]
2017-08-25 22:45:04 +02:00
},
possiblePositions () {
return possiblePositions.map(option =>
Object.assign({}, option, {
label: this.$t(`theses.${option.position}`),
2017-08-25 22:45:04 +02:00
icon: this.getIconName(option.position)
}))
2019-03-20 23:39:49 +01:00
.filter(option => option.position !== 'skipped')
},
2017-08-13 14:03:38 +02:00
optionSkip () {
const skipped = possiblePositions.find(option => option.position === 'skipped')
return Object.assign({}, skipped, {
label: this.$t('theses.skipped')
})
2017-08-13 14:03:38 +02:00
}
},
methods: {
2017-08-25 22:45:04 +02:00
getIconName (type) {
switch (type) {
case 'positive': return 'thumbs-up'
case 'neutral': return 'circle'
case 'negative': return 'thumbs-down'
case 'skipped': return 'corner-up-right'
2019-03-20 23:39:49 +01:00
default:
2017-08-25 22:45:04 +02:00
}
},
2017-08-14 22:28:12 +02:00
goBack () {
const thesis = this.theses[this.currentThesisStep - 1]
2017-08-14 22:28:12 +02:00
const index = this.answers.findIndex(a => a.thesis === thesis.id)
this.answers.splice(index, 1)
this.currentThesisStep -= 1
2017-08-14 22:28:12 +02:00
},
2017-08-13 14:03:38 +02:00
submitAnswer (option, event) {
if (!option) {
2019-04-10 10:21:27 +02:00
// eslint-disable-next-line
2017-08-13 14:03:38 +02:00
return console.warn('Invalid answer')
}
const thesis = this.theses[this.currentThesisStep - 1]
2017-08-13 21:42:02 +02:00
this.answers.push({ thesis: thesis.id, position: option.position })
this.currentThesisStep += 1
2017-08-13 14:03:38 +02:00
event && event.target.blur()
2017-08-27 23:03:48 +02:00
window.scrollTo(0, 0)
if (this.currentThesisStep > this.thesesCount) {
this.forwardToResults()
}
2017-08-13 14:03:38 +02:00
},
forwardToResults () {
2017-09-05 00:33:31 +02:00
const answers = JSON.stringify(this.answers)
if (this.$browser.supports('sessionStorage')) {
sessionStorage.setItem('euromat-answers', answers)
} else {
this.$root.$data.backupStorage.answers = answers
}
this.$router.push({
path: getTranslatedUrl('emphasis', getTranslatedUrl('theses', null, true)),
query: this.isEmbedded ? { embedded: 'iframe' } : {}
})
2017-08-13 14:03:38 +02:00
}
}
}
</script>
<style lang="scss" scoped>
2019-03-20 23:19:13 +01:00
@import "~@/styles/fonts";
@import "~@/styles/colors";
@import "~@/styles/layout";
2017-08-13 14:03:38 +02:00
2017-08-25 23:28:07 +02:00
$breakpoint: 835px;
.theses {
2017-08-25 22:45:04 +02:00
display: flex;
align-items: flex-start;
2017-08-25 23:28:07 +02:00
@media (max-width: $breakpoint) {
flex-direction: column;
}
2017-08-25 22:45:04 +02:00
}
2017-08-13 14:03:38 +02:00
.header-progress {
2017-08-25 22:45:04 +02:00
flex: 1 0 100px;
2017-08-13 14:03:38 +02:00
display: flex;
2017-08-25 22:45:04 +02:00
flex-direction: column;
align-items: flex-end;
margin-right: $base-gap * 2;
color: $text-color-secondary;
2017-08-25 23:28:07 +02:00
@media (max-width: $breakpoint) {
flex: 1;
width: 100%;
flex-direction: row;
justify-content: space-between;
margin-right: 0;
margin-bottom: 0;
}
2017-08-25 22:45:04 +02:00
> div {
display: flex;
}
2017-08-13 14:03:38 +02:00
span {
2017-08-25 22:45:04 +02:00
font-size: $font-size-large;
font-weight: 600;
display: inline;
2017-08-25 23:28:07 +02:00
@media (max-width: $breakpoint) {
font-size: $font-size-large - 50%;
}
2017-08-25 22:45:04 +02:00
}
.progress-current {
color: $text-color-special;
2017-08-13 14:03:38 +02:00
}
2017-08-25 22:45:04 +02:00
button {
2017-08-26 00:18:00 +02:00
margin-top: $base-gap + 5;
2017-08-25 23:28:07 +02:00
@media (max-width: $breakpoint) {
margin-top: 0;
margin-left: $base-gap;
}
2017-08-25 22:45:04 +02:00
}
}
.theses-content {
2017-08-25 22:45:04 +02:00
text-align: left;
width: 100%;
2017-08-13 14:03:38 +02:00
}
.theses-header {
2017-08-25 22:45:04 +02:00
margin-bottom: $base-gap + 5;
text-align: left;
h1, h2 {
overflow-wrap: break-word;
}
2017-08-25 22:45:04 +02:00
h2 {
margin-bottom: $base-gap;
}
2017-08-13 14:03:38 +02:00
}
.theses-controls {
2017-08-13 14:03:38 +02:00
display: flex;
flex-direction: column;
justify-content: center;
2017-08-25 22:45:04 +02:00
align-items: flex-start;
2017-08-13 14:03:38 +02:00
}
2017-08-14 22:28:12 +02:00
.controls-sub {
display: flex;
margin-top: $small-gap;
button:first-of-type {
margin-right: $small-gap;
}
2017-08-13 14:03:38 +02:00
}
.theses-btns {
2017-08-13 14:03:38 +02:00
list-style: none;
display: flex;
justify-content: center;
li:not(:last-child) {
2017-08-14 22:28:12 +02:00
margin-right: $small-gap;
2017-08-13 14:03:38 +02:00
}
2017-08-25 23:28:07 +02:00
@media (max-width: $breakpoint) {
flex-direction: column;
margin-bottom: $base-gap;
li:not(:last-child) {
margin-right: 0;
margin-bottom: $small-gap;
}
}
2017-08-13 14:03:38 +02:00
}
</style>