Skip to content

Commit

Permalink
feat: split coordinates field into lat, long and set geolocation on v…
Browse files Browse the repository at this point in the history
…alidate

(cherry picked from commit 239e1a4)

# Conflicts:
#	frontend/src/components/CheckInPanel.vue
#	hrms/hr/doctype/employee_checkin/employee_checkin.json
  • Loading branch information
ruchamahabal authored and mergify[bot] committed May 29, 2024
1 parent 609657f commit 7aad1ae
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 32 deletions.
27 changes: 13 additions & 14 deletions frontend/src/components/CheckInPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
:initial-breakpoint="1"
:breakpoints="[0, 1]"
>
<div
class="h-120 w-full flex flex-col items-center justify-center gap-5 p-4 mb-5"
>
<div class="h-120 w-full flex flex-col items-center justify-center gap-5 p-4 mb-5">
<div class="flex flex-col gap-1.5 mt-2 items-center justify-center">
<div class="font-bold text-xl">
{{ dayjs(checkinTimestamp).format("hh:mm:ss a") }}
Expand All @@ -81,9 +79,7 @@
{{ locationStatus }}
</span>

<div
class="rounded border-4 translate-z-0 block overflow-hidden w-full h-170"
>
<div class="rounded border-4 translate-z-0 block overflow-hidden w-full h-170">
<iframe
width="100%"
height="170"
Expand All @@ -98,6 +94,7 @@
</div>
</template>

<<<<<<< HEAD
<Button
class="mt-4 mb-1 drop-shadow-sm py-5 text-base"
id="open-checkin-modal"
Expand All @@ -110,6 +107,10 @@
/>
</template>
{{ nextAction.label }}
=======
<Button variant="solid" class="w-full py-5 text-sm" @click="submitLog(nextAction.action)">
Confirm {{ nextAction.label }}
>>>>>>> 239e1a499 (feat: split coordinates field into lat, long and set geolocation on validate)
</Button>

<ion-modal
Expand Down Expand Up @@ -156,8 +157,8 @@ const socket = inject("$socket")
const employee = inject("$employee")
const dayjs = inject("$dayjs")
const checkinTimestamp = ref(null)
const latitude = ref("")
const longitude = ref("")
const latitude = ref(0)
const longitude = ref(0)
const locationStatus = ref("")

const checkins = createListResource({
Expand Down Expand Up @@ -214,14 +215,10 @@ function handleLocationError(error) {

const fetchLocation = () => {
if (!navigator.geolocation) {
locationStatus.value =
"Geolocation is not supported by your current browser"
locationStatus.value = "Geolocation is not supported by your current browser"
} else {
locationStatus.value = "Locating..."
navigator.geolocation.getCurrentPosition(
handleLocationSuccess,
handleLocationError
)
navigator.geolocation.getCurrentPosition(handleLocationSuccess, handleLocationError)
}
}

Expand All @@ -241,6 +238,8 @@ const submitLog = (logType) => {
employee: employee.data.name,
log_type: logType,
time: checkinTimestamp.value,
latitude: latitude.value,
longitude: longitude.value,
},
{
onSuccess() {
Expand Down
38 changes: 31 additions & 7 deletions hrms/hr/doctype/employee_checkin/employee_checkin.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"skip_auto_attendance",
"attendance",
"location_section",
"coordinates",
"latitude",
"column_break_yqpi",
"longitude",
"section_break_ksbo",
"geolocation",
"shift_timings_section",
"shift_start",
Expand Down Expand Up @@ -118,12 +121,6 @@
"fieldtype": "Section Break",
"label": "Location"
},
{
"fieldname": "coordinates",
"fieldtype": "Data",
"label": "Coordinates",
"read_only": 1
},
{
"fieldname": "geolocation",
"fieldtype": "Geolocation",
Expand All @@ -137,14 +134,41 @@
{
"fieldname": "column_break_vyyt",
"fieldtype": "Column Break"
},
{
"fieldname": "latitude",
"fieldtype": "Float",
"label": "Latitude",
"precision": "7",
"read_only": 1
},
{
"fieldname": "longitude",
"fieldtype": "Float",
"label": "Longitude",
"precision": "7",
"read_only": 1
},
{
"fieldname": "column_break_yqpi",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_ksbo",
"fieldtype": "Section Break",
"hide_border": 1
}
],
"links": [],
<<<<<<< HEAD
<<<<<<< HEAD
"modified": "2024-04-02 01:50:23.150627",
=======
"modified": "2024-04-03 06:36:07.640893",
>>>>>>> e54e79b27 (feat: geolocation in Employee Checkin)
=======
"modified": "2024-05-29 20:09:19.489203",
>>>>>>> 239e1a499 (feat: split coordinates field into lat, long and set geolocation on validate)
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Checkin",
Expand Down
27 changes: 16 additions & 11 deletions hrms/hr/doctype/employee_checkin/employee_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def validate(self):
validate_active_employee(self.employee)
self.validate_duplicate_log()
self.fetch_shift()
self.set_geolocation_coordinates()
self.set_geolocation_from_coordinates()

def validate_duplicate_log(self):
doc = frappe.db.exists(
Expand Down Expand Up @@ -61,18 +61,23 @@ def fetch_shift(self):
else:
self.shift = None

def set_geolocation_coordinates(self):
if not self.geolocation:
def set_geolocation_from_coordinates(self):
if not (self.latitude and self.longitude):
return

try:
self.coordinates = str(get_coordinates_from_geolocation(self.geolocation))
except Exception:
frappe.log_error("Error parsing geolocation field")


def get_coordinates_from_geolocation(geolocation: str):
return frappe.parse_json(geolocation)["features"][0]["geometry"]["coordinates"]
self.geolocation = frappe.json.dumps(
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
# geojson needs coordinates in reverse order: long, lat instead of lat, long
"geometry": {"type": "Point", "coordinates": [self.longitude, self.latitude]},
}
],
}
)


@frappe.whitelist()
Expand Down

0 comments on commit 7aad1ae

Please sign in to comment.