Skip to content

Commit

Permalink
More auto-release updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kreut committed Oct 8, 2024
1 parent bebcd28 commit 0699a1a
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 53 deletions.
1 change: 0 additions & 1 deletion app/AutoRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class AutoRelease extends Model
{
Expand Down
9 changes: 1 addition & 8 deletions app/Console/Commands/processAutoRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class processAutoRelease extends Command
{
Expand Down Expand Up @@ -37,13 +36,7 @@ public function __construct()
parent::__construct();
}

/**
* Execute the console command.
*
* @param AutoRelease $autoRelease
* @return int
* @throws Exception
*/

public function handle(AutoRelease $autoRelease): int
{
try {
Expand Down
64 changes: 61 additions & 3 deletions app/Http/Controllers/AutoReleaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,74 @@
class AutoReleaseController extends Controller
{

/**
* @param Request $request
* @param Course $course
* @param AutoRelease $autoRelease
* @param Assignment $assignment
* @return array
* @throws Exception
*/
public function globalUpdate(Request $request,
Course $course,
AutoRelease $autoRelease,
Assignment $assignment): array
{
$response['type'] = 'error';
$authorized = Gate::inspect('globalUpdate', [$autoRelease, $course]);

if (!$authorized->allowed()) {
$response['message'] = $authorized->message();
return $response;
}
try {
$setting = $request->setting;
$value = $request->value;
$auto_release_keys = $autoRelease->keys();
$course_assignment_ids = $course->assignments->pluck('id')->toArray();
foreach ($auto_release_keys as $auto_release) {
switch ($setting) {
case('manual'):
$assignment->whereIn('id', $course_assignment_ids)
->update([$auto_release => $value]);
break;
case('auto'):
$assignment_ids = DB::table('assignments')
->where('assignments.assessment_type', '<>', 'clicker')
->whereIn('id', $course_assignment_ids)
->get('id')
->pluck('id')
->toArray();
$autoRelease->where('type', 'assignment')
->whereNotNull($auto_release)
->whereIn('type_id', $assignment_ids)
->update(["{$auto_release}_activated" => $value]);
break;
}
}
$response['type'] = $value ? 'success' : 'info';
$new_state = $value ? 'on' : 'off';
$response['message'] = "The '$setting' setting has been turned $new_state for all assignments in your course.";
} catch (Exception $e) {
$h = new Handler(app());
$h->report($e);
$response['message'] = "We were unable to globally update the auto-releases for this course. Please try again or contact us for assistance.";
}
return $response;

}

/**
* @param Assignment $assignment
* @param string $property
* @param AutoRelease $autoRelease
* @return array
* @throws Exception
*/
public function autoReleaseTimingMessage(Assignment $assignment,
string $property,
AutoRelease $autoRelease): array
public
function autoReleaseTimingMessage(Assignment $assignment,
string $property,
AutoRelease $autoRelease): array
{

$response['type'] = 'error';
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/SetAppVersionHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handle($request, Closure $next)
//$app_version = env('VAPOR_COMMIT_HASH') ? env('VAPOR_COMMIT_HASH') : '1.0';
if(!$response instanceof StreamedResponse) {
//https://stackoverflow.com/questions/72060913/call-to-undefined-method-symfony-component-httpfoundation-streamedresponsehead
$response->header('appversion', '2.57');
$response->header('appversion', '2.58');
}
return $response;
}
Expand Down
10 changes: 10 additions & 0 deletions app/Policies/AutoReleasePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Assignment;
use App\AutoRelease;
use App\Course;
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Auth\Access\Response;
Expand All @@ -21,6 +22,15 @@ public function compareAssignmentToCourseDefault(User $user): Response

}

public function globalUpdate(User $user, AutoRelease $autoRelease, Course $course): Response
{

return $course->user_id === $user->id
? Response::allow()
: Response::deny('You are not allowed to globally update the auto-releases for this course.');

}

public function updateActivated(User $user, AutoRelease $autoRelease, Assignment $assignment ): Response
{

Expand Down
100 changes: 96 additions & 4 deletions resources/js/components/AutoRelease.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
<template>
<div v-show="showAutoRelease" class="mt-2">
<AllFormErrors :all-form-errors="allFormErrors" :modal-id="'modal-form-errors-auto-release'" />
<b-modal id="modal-confirm-global-update-auto-release-property"
title="Confirm Global Update"
>
<p>
You are about to turn all of your {{ globalAutoRelease.setting }} settings
"{{ Boolean(globalAutoRelease.value) ? 'on' : 'off' }}".
</p>
<p v-if="globalAutoRelease.setting=== 'auto' && globalAutoRelease.value">
This will only impact non-clicker assignments and auto-release properties with existing timings.
</p>
<template #modal-footer>
<b-button
size="sm"
class="float-right"
@click="$bvModal.hide('modal-confirm-global-update-auto-release-property')"
>
Cancel
</b-button>
<b-button
:variant="Boolean(globalAutoRelease.value) ? 'success' :'danger'"
size="sm"
class="float-right"
@click="globalUpdateAutoReleaseProperty()"
>
{{ Boolean(globalAutoRelease.value) ? 'Turn On' : 'Turn Off' }}
</b-button>
</template>
</b-modal>
<b-modal id="modal-apply-auto-release-to"
title="Auto-release Options"
>
Expand Down Expand Up @@ -76,8 +104,10 @@
</div>
</template>
<b-alert variant="info" show style="font-size:90%">
Assignments will be shown the specified amount of time <strong>before</strong> your first "available on". Scores,
solutions, and statistics will be released the specified amount of time <strong>after</strong> your last due date
Assignments will be shown the specified amount of time <strong>before</strong> your first "available on".
Scores,
solutions, and statistics will be released the specified amount of time <strong>after</strong> your last due
date
or final submissison date if applicable.
</b-alert>
<table class="table table-striped table-sm">
Expand Down Expand Up @@ -346,6 +376,48 @@
</b-button>
</div>
</b-card>
<div v-if="courseId" class="pt-3">
<b-card
header="default"
header-html="<h2 class=&quot;h7&quot;>Global Update</h2>"
>
<b-card-text>
<p>You can globally update the "manual" and "auto" properties for all assignments in the course.</p>
<b-container>
<b-row class="pb-2">
<span class="pr-2"><label>Set all "manual" to :</label></span>
<span class="pr-2">
<b-button size="sm"
variant="success"
@click="initBulkUpdateAutoRelease('manual',1)"
>
On</b-button>
</span>
<b-button size="sm"
variant="danger"
@click="initBulkUpdateAutoRelease('manual',0)"
>
Off
</b-button>
</b-row>
<b-row>
<span class="pr-2"><label>Set all "auto" to:</label></span>
<span class="pr-2"><b-button
size="sm"
variant="success"
@click="initBulkUpdateAutoRelease('auto',1)"
>On</b-button></span>
<b-button size="sm"
variant="danger"
@click="initBulkUpdateAutoRelease('auto',0)"
>
Off
</b-button>
</b-row>
</b-container>
</b-card-text>
</b-card>
</div>
</div>
</template>

Expand All @@ -357,6 +429,7 @@ import { ToggleButton } from 'vue-js-toggle-button'
import axios from 'axios'
import AutoReleaseStatus from './AutoReleaseStatus.vue'
import ErrorMessage from './ErrorMessage.vue'
import { mapGetters } from 'vuex'
export default {
name: 'Autorelease',
Expand Down Expand Up @@ -394,6 +467,7 @@ export default {
}
},
data: () => ({
globalAutoRelease: {},
showAutoRelease: false,
applyTo: 'all',
autoReleaseAfterOptions: [],
Expand All @@ -412,7 +486,10 @@ export default {
}
),
computed: {
isMe: () => window.config.isMe
isMe: () => window.config.isMe,
...mapGetters({
user: 'auth/user'
})
},
watch: {
'autoReleaseForm.solutions_availability': {
Expand Down Expand Up @@ -468,7 +545,7 @@ export default {
}
},
mounted () {
this.showAutoRelease = this.isMe
this.showAutoRelease = this.isMe || [1387, 1344, 173].includes(this.user.id)
this.headerHtml = this.courseId ? '<h2 class="h7 m-0">Default Auto-Release</h2>' : '<h2 class="h7 m-0">Auto-Release</h2>'
if (this.assignmentId) {
this.getReleasedSettings()
Expand All @@ -487,6 +564,21 @@ export default {
}]
},
methods: {
async globalUpdateAutoReleaseProperty () {
try {
const { data } = await axios.patch(`/api/auto-release/global-update/course/${this.courseId}`, this.globalAutoRelease)
this.$noty[data.type](data.message)
if (data.type !== 'error') {
this.$bvModal.hide('modal-confirm-global-update-auto-release-property')
}
} catch (error) {
this.$noty.error(error.message)
}
},
initBulkUpdateAutoRelease (setting, value) {
this.globalAutoRelease = { setting: setting, value: value }
this.$bvModal.show('modal-confirm-global-update-auto-release-property')
},
initSaveCourseAutoRelease () {
this.$bvModal.show('modal-apply-auto-release-to')
},
Expand Down
1 change: 0 additions & 1 deletion resources/js/components/AutoReleaseDate.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<div>
{{assignmentProperty}}
<div v-html="getAutoReleaseDateText()" />
</div>
</template>
Expand Down
25 changes: 23 additions & 2 deletions resources/js/components/GradersCanSeeStudentNamesToggle.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<template>
<div>
<b-form-radio-group
v-if="radioButtons"
v-model="assignment.graders_can_see_student_names"
stacked
required
@change="submitGradersCanSeeStudentNames(assignment)"
>
<b-form-radio name="showPointsPerQuestion" value="1">
Shown
</b-form-radio>
<b-form-radio name="showPointsPerQuestion" value="0">
Hidden
</b-form-radio>
</b-form-radio-group>
<toggle-button
v-if="!radioButtons"
tabindex="0"
:width="84"
:value="Boolean(assignment.graders_can_see_student_names)"
Expand All @@ -27,7 +42,11 @@ export default {
type: Object,
default: function () {
}
}
},
radioButtons: {
type: Boolean,
default: false
}
},
data: () => ({
toggleColors: window.config.toggleColors,
Expand All @@ -41,7 +60,9 @@ export default {
if (data.type === 'error') {
return false
}
this.assignment.graders_can_see_student_names = !this.assignment.graders_can_see_student_names
if (!this.radioButtons) {
this.assignment.graders_can_see_student_names = !this.assignment.graders_can_see_student_names
}
} catch (error) {
this.$noty.error(error.message)
}
Expand Down
21 changes: 20 additions & 1 deletion resources/js/components/QuestionUrlViewToggle.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<template>
<div>
<b-form-radio-group
v-if="radioButtons"
v-model="assignment.question_url_view"
stacked
required
@change="submitQuestionUrlView()"
>
<b-form-radio name="showPointsPerQuestion" value="1">
Shown
</b-form-radio>
<b-form-radio name="showPointsPerQuestion" value="0">
Hidden
</b-form-radio>
</b-form-radio-group>
<toggle-button
v-if="!radioButtons"
tabindex="0"
:width="115"
:value="assignment.question_url_view==='question'"
Expand All @@ -26,7 +41,11 @@ export default {
type: Object,
default: function () {
}
}
},
radioButtons: {
type: Boolean,
default: false
}
},
data: () => ({
assessmentType: '',
Expand Down
Loading

0 comments on commit 0699a1a

Please sign in to comment.