From f4ff76eaf71c325f7d6ac40e2c400836cf439653 Mon Sep 17 00:00:00 2001 From: Eric Kean Date: Thu, 16 Mar 2023 08:36:00 -0700 Subject: [PATCH] Can optionally show question URL's with or without pagination --- app/Http/Controllers/AssignmentController.php | 39 ++++++++++++++ app/Policies/AssignmentPolicy.php | 13 +++++ ...pdate_question_url_view_to_assignments.php | 34 ++++++++++++ .../js/components/AssignmentProperties.vue | 2 +- .../js/components/QuestionUrlViewToggle.vue | 54 +++++++++++++++++++ .../assignment_information/control_panel.vue | 49 +++++++++++++---- .../pages/instructors/assignments.index.vue | 20 ++++++- resources/js/pages/questions.view.vue | 7 ++- routes/api.php | 2 + .../Instructors/AssignmentsIndex1Test.php | 9 ++++ 10 files changed, 214 insertions(+), 15 deletions(-) create mode 100644 database/migrations/2023_03_16_132104_update_question_url_view_to_assignments.php create mode 100644 resources/js/components/QuestionUrlViewToggle.vue diff --git a/app/Http/Controllers/AssignmentController.php b/app/Http/Controllers/AssignmentController.php index 8b2fd5ad2..f5fcc44c8 100644 --- a/app/Http/Controllers/AssignmentController.php +++ b/app/Http/Controllers/AssignmentController.php @@ -752,7 +752,45 @@ function gradersCanSeeStudentNames(Assignment $assignment, int $gradersCanSeeStu return $response; } + /** + * @param Assignment $assignment + * @return array + * @throws Exception + */ + public + function questionUrlView(Assignment $assignment): array + { + $response['type'] = 'error'; + $authorized = Gate::inspect('questionUrlView', $assignment); + + if (!$authorized->allowed()) { + $response['message'] = $authorized->message(); + return $response; + } + + try { + $question_url_view = $assignment->question_url_view === 'assignment' ? 'question' : 'assignment'; + $assignment->update(['question_url_view' => $question_url_view]); + $response['type'] = 'info'; + $response['question_url_view'] = $question_url_view; + $response['message'] = "The question URL view has been updated."; + } catch (Exception $e) { + $h = new Handler(app()); + $h->report($e); + $response['message'] = "There was an error updating the question URL view for $assignment->name. Please try again or contact us for assistance."; + } + return $response; + } + + + /** + * @param Request $request + * @param Assignment $assignment + * @param int $showScores + * @return array + * @throws Exception + */ public function showScores(Request $request, Assignment $assignment, int $showScores) { @@ -1085,6 +1123,7 @@ function viewQuestionsInfo(Request $request, 'show_points_per_question' => $assignment->show_points_per_question, 'solutions_released' => $assignment->solutions_released, 'show_scores' => $assignment->show_scores, + 'question_url_view' => $assignment->question_url_view, 'shown' => !(Auth::user()->role === 3 && !$is_fake_student) || Helper::isAnonymousUser() || $assignment->shown, 'scoring_type' => $assignment->scoring_type, 'students_can_view_assignment_statistics' => $assignment->students_can_view_assignment_statistics, diff --git a/app/Policies/AssignmentPolicy.php b/app/Policies/AssignmentPolicy.php index cf3c3766a..8a7d36065 100644 --- a/app/Policies/AssignmentPolicy.php +++ b/app/Policies/AssignmentPolicy.php @@ -20,6 +20,19 @@ class AssignmentPolicy use HandlesAuthorization; use CommonPolicies; + /** + * @param User $user + * @param Assignment $assignment + * @return Response + */ + public function questionUrlView(User $user, Assignment $assignment): Response + { + return $assignment->course->user_id === $user->id + ? Response::allow() + : Response::deny('You are not allowed to update the question URL view for this assignment.'); + + } + /** * @param User $user * @param Assignment $assignment diff --git a/database/migrations/2023_03_16_132104_update_question_url_view_to_assignments.php b/database/migrations/2023_03_16_132104_update_question_url_view_to_assignments.php new file mode 100644 index 000000000..b1b008eac --- /dev/null +++ b/database/migrations/2023_03_16_132104_update_question_url_view_to_assignments.php @@ -0,0 +1,34 @@ +string('question_url_view') + ->after('solutions_availability') + ->default('assignment'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('assignments', function (Blueprint $table) { + $table->dropColumn('question_url_view'); + }); + } +} diff --git a/resources/js/components/AssignmentProperties.vue b/resources/js/components/AssignmentProperties.vue index dfceff14a..533f373c6 100644 --- a/resources/js/components/AssignmentProperties.vue +++ b/resources/js/components/AssignmentProperties.vue @@ -1707,7 +1707,7 @@ export default { this.showHintPenalty = this.form.can_view_hint === 1 this.showMinimumNumberOfSuccessfulAssessments = this.form.learning_tree_success_criteria === 'assessment based' this.showMinimumNumberOfSuccessfulBranches = this.form.learning_tree_success_level === 'branch' - if (this.isFormativeAssignment){ + if (this.isFormativeAssignment) { this.form.formative = '1' } }) diff --git a/resources/js/components/QuestionUrlViewToggle.vue b/resources/js/components/QuestionUrlViewToggle.vue new file mode 100644 index 000000000..74d3fb75d --- /dev/null +++ b/resources/js/components/QuestionUrlViewToggle.vue @@ -0,0 +1,54 @@ + + + + + diff --git a/resources/js/pages/instructors/assignment_information/control_panel.vue b/resources/js/pages/instructors/assignment_information/control_panel.vue index 157c3ac7b..d25369217 100644 --- a/resources/js/pages/instructors/assignment_information/control_panel.vue +++ b/resources/js/pages/instructors/assignment_information/control_panel.vue @@ -9,7 +9,7 @@ color="#007BFF" background="#FFFFFF" /> - +
- + - + - + - + -