Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gamification quizview scroll and Export access #17

Merged
merged 8 commits into from
Mar 11, 2024
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions ons-social-crawler-fe/src/views/QuizGeneratorView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import QuizGeneratorTrueFalse from './components/QuizGeneratorTrueFalse.vue'
import QuizGeneratorAnswer from './components/QuizGeneratorAnswer.vue'
import QuizGeneratorCategories from './components/QuizGeneratorCategories.vue'
import axios from 'axios'
import { nextTick } from 'vue';
import { isArray } from '@vue/shared'
import { useAuthStore } from '../stores/auth'

const loading = useLoadingStore()
const authStore = useAuthStore()
const route = useRoute()
const { dangerAlert, operationConfirm } = alert()

Expand All @@ -31,6 +35,30 @@ const init = async () => {
}
}

const hasAccess = (roles) => {
console.log('check role:' + roles)
console.log('authStore.userRoles:' + authStore.userRoles)
return !isArray(roles) ? false : roles.some((x) => authStore.userRoles.includes(x))
}

const scrollToTop = () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
};

const scrollToNewQuiz = () => {
setTimeout(() => {
//nextTick(() => { // to remove ?
const firstNewQuizIndex = createdQuiz.value.length - quizQta.value + 1;
const newQuizElement = document.getElementById(`quiz_${firstNewQuizIndex}`);
if (newQuizElement) {
newQuizElement.scrollIntoView({ behavior: 'smooth', block: 'start' });
} else {
console.log("New quiz element not found.");
}
//});
}, 500); // delay needed despite nextTick() because of operationConfirm()
};

const selecteQuizType = (type) => {
quizType.value = type
}
Expand All @@ -46,7 +74,7 @@ const generateQuiz = async () => {
const quiz = res.data
createdQuiz.value.push(quiz)
}
operationConfirm()
operationConfirm().then(scrollToNewQuiz);
} catch (e) {
dangerAlert(e)
} finally {
Expand All @@ -66,7 +94,7 @@ const generateRandomQuiz = async () => {
const quiz = res.data
createdQuiz.value.push(quiz)
}
operationConfirm()
operationConfirm().then(scrollToNewQuiz);
} catch (e) {
dangerAlert(e)
} finally {
Expand Down Expand Up @@ -163,7 +191,7 @@ const existCreatedQuiz = computed(() => createdQuiz.value.length > 0)
<h3>Genera quiz</h3>
<div class="row">
<div class="col-12 col-md-4">
<input v-model="quizQta" type="number" class="generator-quiz-number" min="0" max="10" />
<input v-model="quizQta" type="number" class="generator-quiz-number" min="1" max="10" />
</div>
<div class="col-12 col-md-4">
<button class="generator-quiz-button" :disabled="quizType === 0" @click="generateQuiz">
Expand All @@ -182,15 +210,15 @@ const existCreatedQuiz = computed(() => createdQuiz.value.length > 0)
<h3>Quiz Generati</h3>
</div>
<div class="col-12 col-md-4">
<button class="generator-quiz-export" @click="exportQuiz">
<button v-if="hasAccess(['Admin', 'Teacher'])" class="generator-quiz-export" @click="exportQuiz">
<!-- :disabled="true"
style="opacity: 0.3" -->
Esporta Excel
</button>
</div>
</div>
<div class="row">
<div v-for="(q, index) in createdQuiz" :key="q.id" class="col-12">
<div v-for="(q, index) in createdQuiz" :key="q.id" class="col-12" :id="'quiz_' + (index + 1)">
<QuizGeneratorTrueFalse
v-if="q.type === 1"
:index="index + 1"
Expand All @@ -208,9 +236,15 @@ const existCreatedQuiz = computed(() => createdQuiz.value.length > 0)
></QuizGeneratorCategories>
</div>
</div>
<div class="row justify-content-end">
<div class="col-12 col-md-4">
<button @click="scrollToTop" class="generator-quiz-button">Torna su</button>
</div>
</div>
</template>
</div>
</main>

</template>

<style scoped>
Expand Down