Skip to content

Commit

Permalink
Added community volunteer languages and pickup location lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcage committed Nov 18, 2023
1 parent 2ef67f7 commit 433eb99
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public function store(StoreCommunityVolunteer $request): JsonResponse
]);
}


public function show(CommunityVolunteer $cmtyvol): JsonResource
{
$this->authorize('view', $cmtyvol);
Expand Down Expand Up @@ -170,4 +169,33 @@ public function destroy(CommunityVolunteer $cmtyvol): JsonResponse
]);
}

public function languages(Request $request): array
{
return CommunityVolunteer::query()
->when($request->has('activeOnly'), fn ($qry) => $qry->workStatus('active'))
->select('languages')
->distinct()
->whereNotNull('languages')
->orderBy('languages')
->get()
->pluck('languages')
->flatten()
->unique()
->sort()
->values()
->toArray();
}

public function pickupLocations(Request $request): array
{
return CommunityVolunteer::query()
->when($request->has('activeOnly'), fn ($qry) => $qry->workStatus('active'))
->select('pickup_location')
->distinct()
->orderBy('pickup_location')
->whereNotNull('pickup_location')
->get()
->pluck('pickup_location')
->toArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Models\CommunityVolunteers\Responsibility;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\Rule;
use Illuminate\View\View;
Expand Down
10 changes: 10 additions & 0 deletions resources/js/api/cmtyvol/cmtyvol.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export default {
const url = route('api.cmtyvol.destroy', id)
return await api.delete(url)
},
async languages (activeOnly) {
let params = activeOnly ? { activeOnly: true } : {}
const url = route('api.cmtyvol.languages', params)
return await api.get(url)
},
async pickupLocations (activeOnly) {
let params = activeOnly ? { activeOnly: true } : {}
const url = route('api.cmtyvol.pickupLocations', params)
return await api.get(url)
},
async ageDistribution () {
const url = route('api.cmtyvol.ageDistribution')
return await api.get(url)
Expand Down
21 changes: 19 additions & 2 deletions resources/js/components/cmtyvol/CmtyvolForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@
<b-form-input
v-model="form.languages"
autocomplete="off"
list="language-list"
:state="getValidationState(validationContext)"
/>
</b-form-group>
<b-form-datalist id="language-list" :options="languages"/>
</validation-provider>
</b-col>

Expand Down Expand Up @@ -382,13 +384,15 @@
<b-form-input
v-model="form.pickup_location"
autocomplete="off"
list="pickup-list"
:state="getValidationState(validationContext)"
/>
</b-form-group>
<b-form-datalist id="pickup-list" :options="pickupLocations"/>
</validation-provider>
</b-col>

</b-form-row>
</b-form-row>

<template #footer>
<span>
Expand Down Expand Up @@ -430,6 +434,7 @@
</template>

<script>
import cmtyvolApi from '@/api/cmtyvol/cmtyvol'
import formValidationMixin from "@/mixins/formValidationMixin";
export default {
mixins: [formValidationMixin],
Expand Down Expand Up @@ -485,7 +490,9 @@ export default {
{ value: null, text: this.$t("Unspecified") },
{ value: "m", text: this.$t("male") },
{ value: "f", text: this.$t("female") },
]
],
languages: [],
pickupLocations: [],
}
},
computed: {
Expand All @@ -496,7 +503,17 @@ export default {
mounted() {
this.$store.dispatch('country/fetchCountryList');
},
created() {
this.fetchLanguages()
this.fetchPickupLocations()
},
methods: {
async fetchLanguages() {
this.languages = await cmtyvolApi.languages(false)
},
async fetchPickupLocations() {
this.pickupLocations = await cmtyvolApi.pickupLocations(true)
},
onSubmit () {
this.$emit('submit', this.form)
},
Expand Down
2 changes: 1 addition & 1 deletion resources/js/ziggy.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@
Route::name('cmtyvol.')
->prefix('cmtyvol')
->group(function () {
Route::get('languages', [CommunityVolunteerController::class, 'languages'])
->name('languages')
->middleware('can:viewAny,App\Models\CommunityVolunteers\CommunityVolunteer');

Route::get('pickupLocations', [CommunityVolunteerController::class, 'pickupLocations'])
->name('pickupLocations')
->middleware('can:viewAny,App\Models\CommunityVolunteers\CommunityVolunteer');

// Age distribution
Route::get('ageDistribution', [CommunityVolunteersReportController::class, 'ageDistribution'])
->name('ageDistribution')
Expand Down

0 comments on commit 433eb99

Please sign in to comment.