diff --git a/app/Http/Controllers/DataEntryController.php b/app/Http/Controllers/DataEntryController.php index 16773280..f2fd3b52 100644 --- a/app/Http/Controllers/DataEntryController.php +++ b/app/Http/Controllers/DataEntryController.php @@ -13,24 +13,25 @@ class DataEntryController extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response */ - public function sites(Request $request) + public function sites(Request $request): \Illuminate\Http\Response|\Illuminate\Http\JsonResponse { - /** @var \App\User $user */ - $user = $request->user(); - - return $this->success($user->sites() + return $this->success(Site::where(function ($query) use ($request) { + $query->withShared($request->user()); + $query->orWhere('user_id', $request->user()->id); + }) ->orderBy('name', 'asc') ->with('plots') ->get()); } /** - * @param \App\Site $site - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response + * @param Site $site + * @param Request $request + * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse * @throws \Illuminate\Auth\Access\AuthorizationException + * @throws \Illuminate\Validation\ValidationException */ - public function plots(Site $site, Request $request) + public function plots(Site $site, Request $request): \Illuminate\Http\Response|\Illuminate\Http\JsonResponse { $this->authorize('view', $site); @@ -52,8 +53,7 @@ public function plots(Site $site, Request $request) if ($request->search) { $query->where('plants.tag', $request->search); } - switch ($request->sort_order) - { + switch ($request->sort_order) { case 'tag_asc': $query->orderBy('plants.tag', 'asc'); break; @@ -81,7 +81,7 @@ public function plots(Site $site, Request $request) }, ])->orderBy('plots.number', 'asc')->get(); - if (! empty($request->limit)) { + if (!empty($request->limit)) { $plots->transform(function (Plot $plot) use ($request) { $plot->plants->transform(function (Plant $plant) use ($request) { $plant->setRelation('measurements', diff --git a/resources/js/components/PlotsMap.vue b/resources/js/components/PlotsMap.vue index b61f362d..f3cb1f48 100644 --- a/resources/js/components/PlotsMap.vue +++ b/resources/js/components/PlotsMap.vue @@ -25,7 +25,7 @@ export default { if (this.plots[0]) { const pos = new google.maps.LatLng(this.plots[0].latitude, this.plots[0].longitude) this.map = new google.maps.Map(this.$refs.map, { - zoom: 9, + zoom: 11, center: pos, }) diff --git a/resources/js/forms/PlotForm.vue b/resources/js/forms/PlotForm.vue index 60633db6..482bf22d 100644 --- a/resources/js/forms/PlotForm.vue +++ b/resources/js/forms/PlotForm.vue @@ -59,13 +59,15 @@ id="longitude" placeholder="E,g. -36.898723" :class="['form-control', {'is-invalid': form.errors.has('longitude')}]" - v-model="form.longitude"> + v-model="form.longitude" + @click="setLongitude()"> {{ form.errors.first('longitude') }}
- When entering coordinates manually, please verify the location on the map + When entering coordinates manually, please verify the location on the + map
@@ -273,17 +275,17 @@ export default { data() { return { loading: false, - form : new Form({ - number : '', - latitude : null, - longitude : null, - basal_area : '', - ground_cover : '', - subcanopy : '', - canopy : '', - is_protected : '', + form: new Form({ + number: '', + latitude: null, + longitude: null, + basal_area: '', + ground_cover: '', + subcanopy: '', + canopy: '', + is_protected: '', protection_seasons: '', - recorders : '', + recorders: '', }), options: Options, showMap: false, @@ -350,9 +352,15 @@ export default { }, setGpsFromMap(pos) { - this.form.latitude = pos.latitude + this.form.latitude = pos.latitude this.form.longitude = pos.longitude }, + + setLongitude() { + if (!this.form.longitude) { + this.form.longitude = "-" + } + }, }, }