All question type frontend completed

This commit is contained in:
Qais Yousuf 2024-04-23 20:00:09 +02:00
parent 1a43f8b456
commit 98ec7a6561

View file

@ -7,14 +7,9 @@
body {
height: 100% !important;
background-color: #141c27 !important;
}
#QuestionCard{
height:auto;
padding:15px;
}
#rowSectionError {
display: flex;
flex-wrap: nowrap;
@ -40,8 +35,8 @@
.QuestionContainer {
padding-top: 100px;
padding-bottom: 100px;
}
.stepper {
display: flex;
flex-direction: column;
@ -64,7 +59,6 @@
box-shadow: 0px 0px 6px 2px rgba(0,0,0,0.18);
-webkit-box-shadow: 0px 0px 6px 2px rgba(0,0,0,0.18);
-moz-box-shadow: 0px 0px 6px 2px rgba(0,0,0,0.18);
}
.step-indicator.active {
@ -77,7 +71,6 @@
h4, h5, h6, p, label {
color: aliceblue;
}
@ -89,7 +82,6 @@
border-radius: 10px;
background-color: transparent;
padding: 50px;
}
@ -147,7 +139,6 @@
padding: 5px;
margin-bottom: 2px;
color: white
}
@ -158,7 +149,6 @@
border-radius: 5px;
background-color: transparent;
padding: 20px;
}
.likert .statement {
@ -179,7 +169,7 @@
display: block;
cursor: pointer;
padding: 20px;
background-color: #182c4b;
background-color: #33b3ae;
border-radius: 2px;
margin: 3px;
transition: background-color 0.3s;
@ -190,27 +180,25 @@
background-color: transparent;
color: white;
font-size: 1rem;
}
.card-deck .card {
cursor: pointer;
padding:0px;
padding: 10px;
border: 2px solid transparent;
box-shadow: 0px 0px 36px -12px rgba(20,101,230,1);
-webkit-box-shadow: 0px 0px 5px 0px rgba(20,101,230,1);
-moz-box-shadow: 0px 0px 36px -12px rgba(20, 101, 230, 1);
background-color: transparent;
transition: border 0.3s ease; /* Add transition for a smooth effect */
}
img{
/* img{
border-radius:3px;
box-shadow: 0px 0px 36px -12px rgba(20,101,230,1);
-webkit-box-shadow: 0px 0px 5px 0px rgba(20,101,230,1);
-moz-box-shadow: 0px 0px 36px -12px rgba(20, 101, 230, 1);
}
*/
.card-deck .card:hover {
border: 2px solid #007bff;
transition: border 0.3s ease; /* Ensure the transition applies to the hover state as well */
@ -230,6 +218,95 @@
display: none; /* Hide radio button */
}
.matrix-question .table {
box-shadow: 0px 0px 7px 0px rgba(20,101,230,1);
-moz-box-shadow: 0px 0px 36px -12px rgba(20, 101, 230, 1);
-webkit-box-shadow: 0px 0px 7px 0px rgba(20,101,230,1);
border-radius: 5px;
background-color: transparent;
padding: 20px;
width: 100%;
}
.matrix-question th, .matrix-question td {
text-align: left; /* Aligns text to the left */
border: 2px solid white;
width: 100%;
}
.matrix-question th {
background-color: #33b3ae; /* Semi-transparent background for headers */
color: white; /* White text color for headers */
}
.matrix-question td {
background-color: #33b3ae; /* Semi-transparent background for headers */
color: white;
text-align: left;
}
input[type="radio"] {
border: 1px solid #007bff !important;
}
.matrix-question input[type="radio"] {
border: 1px solid #007bff !important;
}
.sortable-list {
list-style: none;
padding: 0;
}
.draggable-item:hover {
background-color: #e0e0e0;
}
button {
margin-left: 10px;
}
.draggable-item {
padding: 10px;
margin-bottom: 5px;
background-color: #f8f9fa; /* Light gray background for default state */
border: 1px solid #ccc;
cursor: grab; /* Cursor indicates that this item is draggable */
transition: background-color 0.3s ease; /* Smooth transition for background color */
border-radius: 5px;
margin: 10px;
display: flex; /* Enable flexbox */
align-items: center; /* Center items vertically */
justify-content: space-between; /* Spread out content */
}
.draggable-item.selected {
background-color: #33b3ae;
; /* Blue background for selected state */
color: white; /* White text color for better visibility */
}
.up-button, .down-button {
margin: 0 5px; /* Spacing between buttons */
}
.answer-index {
font-weight: bold;
}
.draggable-item .bi-grip-vertical {
margin-right: auto; /* Pushes all elements to the right of it to the far right */
}
.draggable-item button {
margin-left: 5px; /* Space between buttons */
}
</style>
@ -282,7 +359,7 @@
<p class="font-weight-normal">@(i + 1). @question.Text</p>
<div id="QuestionCard">
@switch (question.Type)
{
@ -326,10 +403,8 @@
</label>
</div>
}
</div>
break;
@ -377,64 +452,118 @@
break;
case QuestionType.Ranking:
<div class="ranking" data-question="@i">
<ul class="rank-list">
<div class="ranking-question">
<p class="ml-3">drag and drop to move the answers</p>
<ul class="sortable-list" id="ranking_@question.Id">
@{
int index = 1; // Initialize the index to start numbering from 1
}
@foreach (var answer in question.Answers)
{
<li data-answer-id="@answer.Id">
@answer.Text
<button type="button" class="up-button btn btn-primary btn-sm" onclick="moveUp(this)"><i class="bi bi-arrow-up"></i> Up</button>
<button type="button" class="down-button btn btn-info btn-sm" onclick="moveDown(this)"><i class="bi bi-arrow-down"></i> Down</button>
<li class="draggable-item" draggable="true" id="@answer.Id" ondragstart="dragStart(event);" ondragover="allowDrop(event);" ondrop="drop(event);">
<span class="answer-index">@index. </span> @answer.Text
<i class="bi bi-grip-vertical mr-auto"></i>
<input type="hidden" name="Questions[@i].SelectedAnswerIds" value="@answer.Id">
<button type="button" class="up-button btn btn-primary btn-sm " onclick="moveUp(this.parentElement)">
<i class="bi bi-arrow-up"></i> Up
</button>
<button type="button" class="down-button btn btn-info btn-sm" onclick="moveDown(this.parentElement)">
<i class="bi bi-arrow-down"></i> Down
</button>
</li>
index++; // Increment the index for the next item
}
</ul>
</div>
<script>
function allowDrop(ev) {
ev.preventDefault(); // Necessary to allow a drop event
}
function dragStart(ev) {
ev.dataTransfer.setData("text", ev.target.id); // Stores the id of the draggable item
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
var draggedElement = document.getElementById(data);
var dropTarget = ev.target.closest('.draggable-item');
if (dropTarget) {
var targetRect = dropTarget.getBoundingClientRect();
var midPoint = targetRect.top + (targetRect.height / 2); // Calculate the midpoint of the drop target
var list = dropTarget.parentNode;
if (ev.clientY < midPoint) {
// Drop above the target
list.insertBefore(draggedElement, dropTarget);
} else {
// Drop below the target
if (dropTarget.nextSibling) {
list.insertBefore(draggedElement, dropTarget.nextSibling);
} else {
list.appendChild(draggedElement); // In case the target is the last child
}
}
}
}
// Click to select item
document.querySelectorAll('.draggable-item').forEach(item => {
item.addEventListener('click', function () {
// Remove previous selections
removeSelected(this.parentNode);
// Mark this as selected
this.classList.add('selected');
});
});
// Function to remove selected class from siblings
function removeSelected(parent) {
parent.querySelectorAll('.draggable-item').forEach(sibling => {
sibling.classList.remove('selected');
});
}
</script>
break;
case QuestionType.Likert:
@if (Model.Questions.Any(q => q.Type == QuestionType.Likert))
{
<div class="likert">
@foreach (var questions in Model.Questions.Where(q => q.Type == QuestionType.Likert))
{
<div class="statement">
<label>Please indicate your level of agreement with the following statements:</label>
<div class="responses">
@foreach (var answer in questions.Answers)
@foreach (var answer in question.Answers)
{
<label class="likert-option">
<input class="form-check-input" type="radio" name="Questions[@i].SelectedAnswerIds" value="@answer.Id">
<input class="form-check-input" type="radio" id="question@(i)_answer@(answer.Id)" name="Questions[@i].SelectedAnswerIds" value="@answer.Id">
@answer.Text
</label>
}
</div>
</div>
}
</div>
}
break;
case QuestionType.Matrix:
@if (Model.Questions.Any(q => q.Type == QuestionType.Matrix)) // Check for Matrix type questions
{
@foreach (var matrixQuestion in Model.Questions.Where(q => q.Type == QuestionType.Matrix)) // Iterate through Matrix questions
{
<div class="matrix-question">
<table class="table table-responsive">
<thead>
<tr>
<th>Question</th>
@foreach (var option in matrixQuestion.Answers) // Assuming these are the consistent answer options across all sub-questions
@foreach (var option in question.Answers) // Assuming these are the consistent answer options across all sub-questions
{
<th>@option.Text</th>
}
@ -442,8 +571,8 @@
</thead>
<tbody>
<tr>
<td>@matrixQuestion.Text</td>
@foreach (var option in matrixQuestion.Answers) // Use consistent options for each sub-question
<td>@question.Text</td>
@foreach (var option in question.Answers) // Use consistent options for each sub-question
{
<td>
<input type="radio" name="Questions[@i].SelectedAnswerIds" value="@option.Id">
@ -452,15 +581,11 @@
</tr>
</tbody>
</table>
</div>
}
}
break;
case QuestionType.Image:
@if (Model.Questions.Any(q => q.Type == QuestionType.Image))
{
<script>
function selectImageCard(answerId, questionId) {
@ -480,21 +605,19 @@
}
</script>
@foreach (var imageQuestion in Model.Questions.Where(q => q.Type == QuestionType.Image))
{
<div class="image-question" data-question-id="@imageQuestion.Id">
<div class="image-question" data-question-id="@question.Id">
<div class="card-deck">
@foreach (var answer in imageQuestion.Answers)
@foreach (var answer in question.Answers)
{
<div class="card image-card" id="card_@answer.Id" onclick="selectImageCard('@answer.Id', '@imageQuestion.Id')">
<div class="card image-card" id="card_@answer.Id" onclick="selectImageCard('@answer.Id', '@question.Id')">
<img src="@answer.Text" alt="Image option" class="img-fluid" />
<input type="radio" id="image_answer_@answer.Id" name="Questions[@i].SelectedAnswerIds" value="@answer.Id" hidden />
</div>
}
</div>
</div>
}
}
break;
default:
<div class="alert alert-danger" role="alert">
@ -502,7 +625,7 @@
</div>
break;
}
</div>
<div class="mt-3">
@if (i > 0)
{
@ -533,6 +656,7 @@
@{
<partial name="_ValidationScriptsPartial" />
}
<script>
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById('questionnaireForm');
@ -675,27 +799,27 @@
showStep(currentStep);
});
document.addEventListener("DOMContentLoaded", function () {
const stepper = document.querySelector('.stepper');
if (!stepper) {
console.error('Stepper not found!');
return;
}
// document.addEventListener("DOMContentLoaded", function () {
// const stepper = document.querySelector('.stepper');
// if (!stepper) {
// console.error('Stepper not found!');
// return;
// }
let shownTypes = new Set(); // Set to track shown question types
const stepIndicators = stepper.querySelectorAll('.step-indicator');
// let shownTypes = new Set(); // Set to track shown question types
// const stepIndicators = stepper.querySelectorAll('.step-indicator');
stepIndicators.forEach(indicator => {
const type = indicator.querySelector('.step-label').textContent.trim(); // Get the text content of the step-label
if (shownTypes.has(type)) {
// If this type has already been shown, hide this indicator
indicator.style.display = 'none';
} else {
// Otherwise, mark this type as shown
shownTypes.add(type);
}
});
});
// stepIndicators.forEach(indicator => {
// const type = indicator.querySelector('.step-label').textContent.trim(); // Get the text content of the step-label
// if (shownTypes.has(type)) {
// // If this type has already been shown, hide this indicator
// indicator.style.display = 'none';
// } else {
// // Otherwise, mark this type as shown
// shownTypes.add(type);
// }
// });
// });
</script>
@* <script>
@ -845,7 +969,6 @@
});
}
// Add submit event listener to the form
showStep(currentStep);
updateStepper();