Skip to content

Commit

Permalink
Collection table dyanmic table form
Browse files Browse the repository at this point in the history
  • Loading branch information
MuchQuak committed Dec 17, 2024
1 parent 9a01431 commit 46dcb38
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 9 deletions.
5 changes: 5 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public function boot(): void {
});
}

// Helper Macro to Progate Apline binds from parent component to subcomponent within blade. This May be required if you have dynamic names from generated input fields.
Blade::directive('bind', function($expression) {
return '<?php echo $attributes["x-bind:" . "'. $expression.'"] ? \'x-bind:\'. "' . $expression . '" . \'="\' . $attributes["x-bind:" . "'. $expression.'"] . \'"\': "" ?>';
});

Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
$event->extendSocialite('orcid', \App\Socialite\Orcid\Provider::class);
});
Expand Down
80 changes: 80 additions & 0 deletions resources/views/core/occurrence-attribute-select.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@php
$items = [
['title'=> 'Associated Collectors', 'value' => 'associatedCollectors', 'disabled' => false ],
['title'=> 'Associated Occurrences', 'value' => 'associatedOccurrences', 'disabled' => false ],
['title'=> 'Associated Taxa', 'value' => 'associatedTaxa', 'disabled' => false ],
['title'=> 'Attributes', 'value' => 'attributes', 'disabled' => false ],
['title'=> 'Author', 'value' => 'scientificNameAuthorship', 'disabled' => false ],
['title'=> 'Basis Of Record', 'value' => 'basisOfRecord', 'disabled' => false ],
['title'=> 'Behavior', 'value' => 'behavior', 'disabled' => false ],
['title'=> 'Catalog Number', 'value' => 'catalogNumber', 'disabled' => false ],
['title'=> 'Collection Code (override)', 'value' => 'collectionCode', 'disabled' => false ],
['title'=> 'Collector Number', 'value' => 'recordNumber', 'disabled' => false ],
['title'=> 'Collector/Observer', 'value' => 'recordedBy', 'disabled' => false ],
['title'=> 'Coordinate Uncertainty (m)', 'value' => 'coordinateUncertaintyInMeters', 'disabled' => false ],
['title'=> 'Country', 'value' => 'country', 'disabled' => false ],
['title'=> 'County', 'value' => 'county', 'disabled' => false ],
['title'=> 'Cultivation Status', 'value' => 'cultivationStatus', 'disabled' => false ],
['title'=> 'Data Generalizations', 'value' => 'dataGeneralizations', 'disabled' => false ],
['title'=> 'Date', 'value' => 'eventDate', 'disabled' => false ],
['title'=> 'Date Entered', 'value' => 'dateEntered', 'disabled' => false ],
['title'=> 'Date Last Modified', 'value' => 'dateLastModified', 'disabled' => false ],
['title'=> 'dbpk', 'value' => 'dbpk', 'disabled' => false ],
['title'=> 'Decimal Latitude', 'value' => 'decimalLatitude', 'disabled' => false ],
['title'=> 'Decimal Longitude', 'value' => 'decimalLongitude', 'disabled' => false ],
['title'=> 'Depth Maximum (m)', 'value' => 'maximumDepthInMeters', 'disabled' => false ],
['title'=> 'Depth Minimum (m)', 'value' => 'minimumDepthInMeters', 'disabled' => false ],
['title'=> 'Description', 'value' => 'verbatimAttributes', 'disabled' => false ],
['title'=> 'Disposition', 'value' => 'disposition', 'disabled' => false ],
['title'=> 'Dynamic Properties', 'value' => 'dynamicProperties', 'disabled' => false ],
['title'=> 'Elevation Maximum (m)', 'value' => 'maximumElevationInMeters', 'disabled' => false ],
['title'=> 'Elevation Minimum (m)', 'value' => 'minimumElevationInMeters', 'disabled' => false ],
['title'=> 'Establishment Means', 'value' => 'establishmentMeans', 'disabled' => false ],
['title'=> 'Family', 'value' => 'family', 'disabled' => false ],
['title'=> 'Field Notes', 'value' => 'fieldNotes', 'disabled' => false ],
['title'=> 'Field Number', 'value' => 'fieldnumber', 'disabled' => false ],
['title'=> 'Geodetic Datum', 'value' => 'geodeticDatum', 'disabled' => false ],
['title'=> 'Georeference Protocol', 'value' => 'georeferenceProtocol', 'disabled' => false ],
['title'=> 'Georeference Remarks', 'value' => 'georeferenceRemarks', 'disabled' => false ],
['title'=> 'Georeference Sources', 'value' => 'georeferenceSources', 'disabled' => false ],
['title'=> 'Georeference Verification Status', 'value' => 'georeferenceVerificationStatus', 'disabled' => false ],
['title'=> 'Georeferenced By', 'value' => 'georeferencedBy', 'disabled' => false ],
['title'=> 'Habitat', 'value' => 'habitat', 'disabled' => false ],
['title'=> 'Identification Qualifier', 'value' => 'identificationQualifier', 'disabled' => false ],
['title'=> 'Identification References', 'value' => 'identificationReferences', 'disabled' => false ],
['title'=> 'Identification Remarks', 'value' => 'identificationRemarks', 'disabled' => false ],
['title'=> 'Identified By', 'value' => 'identifiedBy', 'disabled' => false ],
['title'=> 'Individual Count', 'value' => 'individualCount', 'disabled' => false ],
['title'=> 'Information Withheld', 'value' => 'informationWithheld', 'disabled' => false ],
['title'=> 'Institution Code (override)', 'value' => 'institutionCode', 'disabled' => false ],
['title'=> 'Label Project', 'value' => 'labelProject', 'disabled' => false ],
['title'=> 'Language', 'value' => 'language', 'disabled' => false ],
['title'=> 'Life Stage', 'value' => 'lifeStage', 'disabled' => false ],
['title'=> 'Location ID', 'value' => 'locationid', 'disabled' => false ],
['title'=> 'Locality', 'value' => 'locality', 'disabled' => false ],
['title'=> 'Locality Security', 'value' => 'localitySecurity', 'disabled' => false ],
['title'=> 'Locality Security Reason', 'value' => 'localitySecurityReason', 'disabled' => false ],
['title'=> 'Location Remarks', 'value' => 'locationRemarks', 'disabled' => false ],
['title'=> 'Modified By', 'value' => 'username', 'disabled' => false ],
['title'=> 'Municipality', 'value' => 'municipality', 'disabled' => false ],
['title'=> 'Notes (Occurrence Remarks)', 'value' => 'occurrenceRemarks', 'disabled' => false ],
['title'=> 'OCR Fragment', 'value' => 'ocrFragment', 'disabled' => false ],
['title'=> 'Other Catalog Numbers', 'value' => 'otherCatalogNumbers', 'disabled' => false ],
['title'=> 'Owner Code', 'value' => 'ownerInstitutionCode', 'disabled' => false ],
['title'=> 'Preparations', 'value' => 'preparations', 'disabled' => false ],
['title'=> 'Reproductive Condition', 'value' => 'reproductiveCondition', 'disabled' => false ],
['title'=> 'Sampling Effort', 'value' => 'samplingEffort', 'disabled' => false ],
['title'=> 'Sampling Protocol', 'value' => 'samplingProtocol', 'disabled' => false ],
['title'=> 'Scientific Name', 'value' => 'sciname', 'disabled' => false ],
['title'=> 'Sex', 'value' => 'sex', 'disabled' => false ],
['title'=> 'State/Province', 'value' => 'stateProvince', 'disabled' => false ],
['title'=> 'Substrate', 'value' => 'substrate', 'disabled' => false ],
['title'=> 'Taxon Remarks', 'value' => 'taxonRemarks', 'disabled' => false ],
['title'=> 'Type Status', 'value' => 'typeStatus', 'disabled' => false ],
['title'=> 'Verbatim Coordinates', 'value' => 'verbatimCoordinates', 'disabled' => false ],
['title'=> 'Verbatim Date', 'value' => 'verbatimEventDate', 'disabled' => false ],
['title'=> 'Verbatim Depth', 'value' => 'verbatimDepth', 'disabled' => false ],
['title'=> 'Verbatim Elevation', 'value' => 'verbatimElevation', 'disabled' => false ],
];
@endphp
<x-select :items="$items" {{ $attributes }} />
92 changes: 83 additions & 9 deletions resources/views/core/pages/collections/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,50 @@ function getOccurrenceEditorUrl($other_params) {
return $base_url . $query;
}
$custom_fields = [];
for($i = 1; $i < 10; $i++) {
$type = request('q_customtype' . $i);
$field = request('q_customfield' . $i);
$value = request('q_customvalue' . $i);
if($type && $field && $value) {
array_push($custom_fields,[
[
'id' => $i,
'type' => $type,
'field' => $value,
'value' => $field,
]
]);
}
}
if(count($custom_fields) === 0) {
$custom_fields = [
[
'id' => 1,
'type' => 'EQUALS',
'field' => NULL,
'value' => "",
]
];
}
@endphp
<x-layout class="p-0 h-[100vh] relative" x-data="{ menu_open: false}" :hasFooter="false" :hasHeader="false"
<x-layout class="p-0 h-[100vh] relative" x-data="{ menu_open: true }" :hasFooter="false" :hasHeader="false"
:hasNavbar="false">
<div class="pt-4 px-4 flex flex-col gap-2 h-[7rem] relative">
<x-breadcrumbs :items="[
['title' => 'Home'],
['title' => 'Collection Management', 'href' => url(config('portal.name') . '/collections/misc/collprofiles.php?emode=1&collid='. request('collid'))],
['title' => 'Occurrence Table view'],
]" />
['title' => 'Home'],
['title' => 'Collection Management', 'href' => url(config('portal.name') . '/collections/misc/collprofiles.php?emode=1&collid='. request('collid'))],
['title' => 'Occurrence Table view'],
]" />
<div class="text-2xl text-primary font-bold">
{{$collection->collectionName}} ({{$collection->institutionCode}})
</div>

<x-button x-on:click="menu_open = true" class="w-fit absolute right-4">Adjust Search</x-button>
</div>

<div class="absolute h-screen w-1/2 min-w-[40rem] bg-base-100 z-[100] top-0 left-0" x-cloak x-show="menu_open">
<div class="absolute h-screen w-full min-w-[40rem] bg-base-100 z-[100] top-0 left-0" x-cloak x-show="menu_open">
<button x-on:click="menu_open = false"
class="float-right mr-2 mt-2 hover:ring-4 focus:outline-none focus:ring-4 rounded-md w-6 h-6 ring-accent">
<i class="cursor-pointer fa fas fa-close"></i>
Expand Down Expand Up @@ -114,9 +141,56 @@ class="float-right mr-2 mt-2 hover:ring-4 focus:outline-none focus:ring-4 rounde
['title' => 'Select Exsiccati', 'value' => null, 'disabled' => false]
]" />
@endif
<div class="text-2xl font-bold w-full py-10 text-center bg-base-200">
TODO CUSTOM FILTERS

<div x-data="{ data: {{ json_encode($custom_fields) }} }" class="flex flex-col gap-4">
<template x-for="(d, index) of data" :key="'custom-form-' + index">
<div>
<div>
Custom Field <span x-text="index + 1"></span>
</div>
<div class="flex flex-row gap-4 items-center">
{{--
<x-select x-bind:name="'q_customopenparen' + (index + 1)" :default="0" :items="[
['title' => '---', 'value' => null, 'disabled' => false],
['title' => '(', 'value' => '(', 'disabled' => false],
['title' => '((', 'value' => '((', 'disabled' => false],
['title' => '(((', 'value' => '(((', 'disabled' => false],
]"/>
--}}
<x-occurrence-attribute-select x-bind:name="'q_customfield' + (index + 1)" class="min-w-72" :select_text="'Select Field Name'" />
<x-select class="min-w-72" x-bind:value="data && data[index]? data[index].type:'EQUALS'" x-on:change='data[index].type = $event.target.type;' x-bind:name="'q_customtype' + (index + 1)" :items="[
['title'=> 'EQUALS', 'value' => 'EQUALS', 'disabled' => false ],
['title'=> 'NOT EQUALS', 'value' => 'NOT_EQUALS', 'disabled' => false ],
['title'=> 'STARTS WITH', 'value' => 'STARTS_WITH', 'disabled' => false ],
['title'=> 'CONTAINS', 'value' => 'LIKE', 'disabled' => false ],
['title'=> 'DOES NOT CONTAIN', 'value' => 'NOT_LIKE', 'disabled' => false ],
['title'=> 'GREATER THAN', 'value' => 'GREATER_THAN', 'disabled' => false ],
['title'=> 'LESS THAN', 'value' => 'LESS_THAN', 'disabled' => false ],
['title'=> 'IS NULL', 'value' => 'IS_NULL', 'disabled' => false ],
['title'=> 'IS NOT NULL', 'value' => 'NOT_NULL', 'disabled' => false ],
]"/>
<x-input x-bind:name="'q_customvalue' + (index + 1)" x-bind:value="data && data[index]? data[index].value: ''" x-on:change='data[index].value = $event.target.value;'/>

{{--
<x-select x-bind:name="'q_customclosedparen' + (index + 1)" :default="0" :items="[
['title' => '---', 'value' => null, 'disabled' => false],
['title' => ')', 'value' => ')', 'disabled' => false],
['title' => '))', 'value' => '))', 'disabled' => false],
['title' => ')))', 'value' => ')))', 'disabled' => false],
]"/>
--}}

<x-button type="button" @click="data.splice(index, 1)">
<i class="fa fa-minus"></i>
</x-button>
</div>
</div>
</template>
<x-button type="button" @click="if(data.length < 10) data.push([{type: 'EQUALS', field: null, value: ''}])">
<i class="fa fa-plus"></i> Add Custom Field
</x-button>
</div>

@if(false)
<div class="flex gap-4 items-center">
<x-select id="sort" class="w-full" label="Sort By" :items="[
Expand Down
51 changes: 51 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,57 @@
}
}

for ($i=1; $i < 10; $i++) {
$custom_field = $request->query('q_customfield' . $i);
$type = $request->query('q_customtype' . $i);
$value= $request->query('q_customvalue' . $i);

if(!$custom_field) continue;

if (($idx = array_search($custom_field, $sortables)) > 0) {
switch ($type) {
case 'EQUALS':
$query->where('o.' . $sortables[$idx], '=', $value);
break;
case 'NOT_EQUALS':
$query->where('o.' . $sortables[$idx], '!=', $value);
break;

case 'START_WITH':
$query->whereLike('o.' . $sortables[$idx], '%' . $value);
break;

case 'CONTAINS':
$query->whereLike('o.' . $sortables[$idx], '%' . $value . '%');
break;

case 'DOES_NOT_CONTAIN':
$query->whereNotLike('o.' . $sortables[$idx], '%' . $value . '%');
break;

case 'GREATER_THAN':
$query->where('o.' . $sortables[$idx], '>', $value);
break;

case 'LESS_THAN':
$query->where('o.' . $sortables[$idx], '<', $value);
break;

case 'IS_NULL':
$query->whereNull('o.' . $sortables[$idx]);
break;

case 'NOT_NULL':
$query->whereNotNull('o.');
break;

default:
break;
}
$query->orderByRaw('ISNULL(o.' . $sortables[$idx] . ') ASC');
}
}

if ($request->query('sort')) {
if (($idx = array_search($request->query('sort'), $sortables)) > 0) {
$query->orderByRaw('ISNULL(o.' . $sortables[$idx] . ') ASC');
Expand Down

0 comments on commit 46dcb38

Please sign in to comment.