-
Notifications
You must be signed in to change notification settings - Fork 5
Add feature to edit questions #61
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
Open
KIRA009
wants to merge
2
commits into
sandy9999:master
Choose a base branch
from
KIRA009:feat/edit-questions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| .selectable-field { | ||
| /* padding: 1em 1em; */ | ||
| display: flex; | ||
| justify-content: space-between; | ||
| } | ||
| .selectable-field:hover { | ||
| background: rgba(0, 0, 0, 0.05); | ||
| color: rgba(0, 0, 0, 0.95); | ||
| } | ||
| .pencil { | ||
| cursor: pointer; | ||
| transition: 0.3s; | ||
| } | ||
| .pencil:hover { | ||
| font-size: 1.2em; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| $(document).ready(() => { | ||
| $('#board').dropdown({ | ||
| onChange: value => filter(value, 'board') | ||
| }); | ||
| $('#grade').dropdown({ | ||
| onChange: value => filter(value, 'grade') | ||
| }); | ||
| $('#subject').dropdown({ | ||
| onChange: value => filter(value, 'subject') | ||
| }); | ||
| $('#chapter').dropdown({ | ||
| onChange: value => filter(value, 'chapter') | ||
| }); | ||
| $('#question_type').dropdown({ | ||
| onChange: value => filter(value, 'question_type') | ||
| }); | ||
| $('#question_weightage').dropdown({ | ||
| onChange: value => filter(value, 'question_weightage') | ||
| }); | ||
| $('#text').keyup(function (e) { | ||
| e.preventDefault(); | ||
| filter(e.target.value, 'text'); | ||
| }); | ||
| $('.modal .actions .deny').click(function(e) { | ||
| e.target.parentElement.previousElementSibling.children[0].value = ''; | ||
| }) | ||
| $('.modal .actions .positive').click(function(e) { | ||
| let element = $(this).parent().prev().children('input'); | ||
| let data = { | ||
| id: element.attr('question'), | ||
| text: element.val(), | ||
| csrfmiddlewaretoken: $('input[name="csrfmiddlewaretoken"]').val() | ||
| } | ||
| $.ajax({ | ||
| type: "post", | ||
| url: "/edit_questions", | ||
| data, | ||
| dataType: "json", | ||
| success: resp => { | ||
| questions = questions.map(question => { | ||
| if (question.id === resp.id) question.text = resp.text; | ||
| return question | ||
| }) | ||
| filter(null, 'chapter') | ||
| new PNotify({ | ||
| title: 'Success!', | ||
| text: 'Question successfully edited in the database', | ||
| type: 'success' | ||
| }); | ||
| }, | ||
| error: err => { | ||
| new PNotify({ | ||
| title: 'Error', | ||
| text: err.responseJSON.error, | ||
| type: 'error' | ||
| }); | ||
| } | ||
| }); | ||
| }) | ||
| fill_rows(questions); | ||
| }) | ||
|
|
||
| let questions = JSON.parse($('#questions')[0].innerHTML); | ||
| $('#questions').remove(); | ||
| let filters = { | ||
| board: [], | ||
| grade: [], | ||
| subject: [], | ||
| chapter: [], | ||
| question_type: [], | ||
| question_weightage: [], | ||
| text: '' | ||
| } | ||
|
|
||
| const fill_rows = questions => { | ||
| let rows = `` | ||
| for (var question of questions) { | ||
| rows += ` | ||
| <tr question="${question.id}"> | ||
| <td>${question.board}</td> | ||
| <td>${question.grade}</td> | ||
| <td>${question.subject}</td> | ||
| <td>${question.chapter}</td> | ||
| <td>${question.question_type}</td> | ||
| <td>${question.question_weightage}</td> | ||
| <td class="selectable-field icon"> | ||
| <span class="text">${question.text}</span> | ||
| <i class="pencil alternate icon"></i> | ||
| </td> | ||
| </tr> | ||
| ` | ||
| } | ||
| $('#questions_table').html(rows); | ||
| $('.pencil').click(function(e) { | ||
| $('.modal .content input').val(e.target.previousElementSibling.innerText); | ||
| $('.modal .content input').attr('question', $(this).parent().parent().attr('question')); | ||
| $('.ui.modal').modal('show'); | ||
| }) | ||
| } | ||
|
|
||
|
|
||
| const filter = (value, field) => { | ||
| if (value !== null) { | ||
| const values = field != 'text' ? value.split(',') : [value]; | ||
| // console.log(values) | ||
| filters[field] = values; | ||
| } | ||
| if (filters[field].includes("")) filters[field] = [] | ||
| // console.log(value) | ||
| // console.log(filters) | ||
| let filtered_questions = questions.filter(question => { | ||
| let removed = false; | ||
| // console.log(question) | ||
| Object.keys(filters).forEach(filter => { | ||
| if (removed) return; | ||
| // console.log(filter) | ||
| // console.log(question[filter]) | ||
| // console.log(filters[filter].length != 0 && !filters[filter].includes(question[filter])) | ||
| if (filter == 'text') { | ||
| if (filters[filter].length != 0 && !question[filter].toLowerCase().includes(filters[filter][0].toLowerCase())) { | ||
| removed = true; | ||
| } | ||
| } | ||
| else if (filters[filter].length != 0 && !filters[filter].includes(question[filter])) { | ||
| removed = true; | ||
| } | ||
| }) | ||
| return !removed; | ||
| }); | ||
| fill_rows(filtered_questions); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| {% extends "layout.html" %} | ||
| {% load static %} | ||
|
|
||
| {% block title %} | ||
| Edit Questions | ||
| {% endblock %} | ||
| {% block li %} | ||
| {% if user.is_authenticated %} | ||
| <li><a href="/mentor_view">Mentor Dashboard</a></li> | ||
| {% else %} | ||
| <li><a href="/login">Login</a></li> | ||
| {% endif %} | ||
| {% endblock %} | ||
| {% block student_view %} | ||
| <!-- Select worksheet type --> | ||
| <br> | ||
|
|
||
| <div id="div"> | ||
| <div id="board" class="ui fluid multiple search selection dropdown chapter"> | ||
| <input name="board" type="hidden"> | ||
| <i class="dropdown icon"></i> | ||
| <div class="default text">Select board</div> | ||
| <div id="board-options-parent" class="menu"> | ||
| {% for element in boards %} | ||
| <div class="item" data-value="{{element}}">{{element}}</div> | ||
| {% endfor %} | ||
| </div> | ||
| </div> | ||
| <br> | ||
| <div id="grade" class="ui fluid multiple search selection dropdown chapter"> | ||
| <input name="grade" type="hidden"> | ||
| <i class="dropdown icon"></i> | ||
| <div class="default text">Select Grade</div> | ||
| <div id="grade-options-parent" class="menu"> | ||
| {% for element in grades %} | ||
| <div class="item" data-value="{{element}}">{{element}}</div> | ||
| {% endfor %} | ||
| </div> | ||
| </div> | ||
| <br> | ||
| <div id="subject" class="ui fluid multiple search selection dropdown chapter"> | ||
| <input name="subject" type="hidden"> | ||
| <i class="dropdown icon"></i> | ||
| <div class="default text">Select Subject</div> | ||
| <div id="board-options-parent" class="menu"> | ||
| {% for element in subjects %} | ||
| <div class="item" data-value="{{element}}">{{element}}</div> | ||
| {% endfor %} | ||
| </div> | ||
| </div> | ||
| <br> | ||
| <div id="chapter" class="ui fluid multiple search selection dropdown chapter"> | ||
| <input name="chapter" type="hidden"> | ||
| <i class="dropdown icon"></i> | ||
| <div class="default text">Select Chapter</div> | ||
| <div id="chapter-options-parent" class="menu"> | ||
| {% for element in chapters %} | ||
| <div class="item" data-value="{{element}}">{{element}}</div> | ||
| {% endfor %} | ||
| </div> | ||
| </div> | ||
| <br> | ||
| <div id="question_type" class="ui fluid multiple search selection dropdown chapter"> | ||
| <input name="question_type" type="hidden"> | ||
| <i class="dropdown icon"></i> | ||
| <div class="default text">Select Question Type</div> | ||
| <div id="question_type-options-parent" class="menu"> | ||
| {% for element in question_types %} | ||
| <div class="item" data-value="{{element}}">{{element}}</div> | ||
| {% endfor %} | ||
| </div> | ||
| </div> | ||
| <br> | ||
| <div id="question_weightage" class="ui fluid multiple search selection dropdown chapter"> | ||
| <input name="question_weightage" type="hidden"> | ||
| <i class="dropdown icon"></i> | ||
| <div class="default text">Select Question Weightage</div> | ||
| <div id="question_weightage-options-parent" class="menu"> | ||
| {% for element in question_weightage %} | ||
| <div class="item" data-value="{{element}}">{{element}}</div> | ||
| {% endfor %} | ||
| </div> | ||
| </div> | ||
| <br> | ||
| <div id="text" class="ui fluid search icon input chapter"> | ||
| <i class="search icon"></i> | ||
| <input type="text" placeholder="Search by text"> | ||
| </div> | ||
| <br> | ||
| </div> | ||
| <br> | ||
| <!-- <button id="submit">GET QUESTIONS</button> --> | ||
| <table class="ui celled padded table"> | ||
| <thead> | ||
| <tr> | ||
| <th>Board</th> | ||
| <th>Grade</th> | ||
| <th>Subject</th> | ||
| <th>Chapter</th> | ||
| <th>Question Type</th> | ||
| <th>Question Weightage</th> | ||
| <th>Text</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody id="questions_table"></tbody> | ||
| </table> | ||
| <div class="ui modal"> | ||
| {% csrf_token %} | ||
| <div class="header">Edit question</div> | ||
| <div class="ui input content"> | ||
| <input type="text" placeholder="Question here" style="width: 100%;"> | ||
| </div> | ||
| <div class="actions"> | ||
| <div class="ui black deny button">Cancel</div> | ||
| <div class="ui positive right button">Save</div> | ||
| </div> | ||
| </div> | ||
| {% endblock %} | ||
| {% block js %} | ||
| <link rel="stylesheet" type="text/css" href="{% static 'edit_questions.css' %}"/> | ||
| <script type="application/json" id="questions"> | ||
| {{questions|safe}} | ||
| </script> | ||
|
|
||
| <script type="text/javascript" src="{% static 'edit_questions.js' %}"></script> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all
console.log()