This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject GeoTaskList "1.0.0-SNAPSHOT" | |
:description "Geolocated Tasklist mobile application" | |
:dependencies [[org.clojure/clojure "1.3.0"] [cheshire "2.2.0"] [compojure "1.0.1"]] | |
:dev-dependencies [[appengine-magic "0.4.7"]] | |
:aot [GeoTaskList.app_servlet GeoTaskList.core GeoTaskList.persistence]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Loads all locations. Retrieves the location field map for all locations | |
; and then adds in the locationId key value pair for each location. | |
(defn get-all-locations [user] | |
(map | |
(fn [k] | |
(assoc (:location k) :locationId (ds/key-id k)));This line sets the id onto the map at load time | |
(ds/query :kind Location :filter (= :user user)))) | |
;Deletes a location by locationId, note we need to check that the user is the one who owns the location | |
(defn delete-location [user locationId] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Get Email function | |
(defn getEmail [] | |
(.getEmail (aeu/current-user))) | |
;Example of adding user to the routes | |
(GET "/locations" [] | |
(json-response {:locations (persist/get-all-locations (getEmail))})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Middleware to add authentication | |
(defn require-login [application] | |
(fn [request] | |
(if | |
(aeu/user-logged-in?) | |
(application request) | |
(ring-response/redirect | |
(aeu/login-url)) | |
))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry" type="text/javascript"></script> | |
<script type="text/javascript"> | |
function calcDistance (fromLat, fromLng, toLat, toLng) { | |
return google.maps.geometry.spherical.computeDistanceBetween( | |
new google.maps.LatLng(fromLat, fromLng), new google.maps.LatLng(toLat, toLng)); | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Task Page --> | |
<div data-role="page" id="task-page"> | |
<div data-role="navbar"> | |
<ul> | |
<li><a href="#location-page" >Location</a></li> | |
<li><a href="#task-page" class="ui-btn-active ui-state-persist">Tasks</a></li> | |
</ul> | |
</div> | |
<div data-role="content"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTasks() { | |
$.mobile.showPageLoadingMsg("a", "Loading Tasks", false); | |
$.getJSON( '/tasks', | |
function(data) { | |
$('#tasks-list').empty(); | |
navigator.geolocation.getCurrentPosition(function(position) { | |
$.each( data.tasks, function(i, task) { | |
var distance = calcDistance(position.coords.latitude, position.coords.longitude, task.taskLat, task.taskLng)/1000.0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("form[name='task-edit-form']").submit(function() { | |
if ($("form[name='task-edit-form']").validate().numberOfInvalids()==0) { | |
$.post("/task", $("form[name='task-edit-form']").serializeArray(), function(){ | |
$.mobile.changePage($("#task-page"), { transition: "pop", role: "page", reverse: false } ); | |
}); | |
} | |
return false; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Edit Task Popup--> | |
<div data-role="page" id="task-edit-page"> | |
<div data-role="header"> | |
<h1>Task</h1> | |
</div> | |
<div data-role="content"> | |
<form name="task-edit-form"> | |
<input id="taskId" name="taskId" type="hidden"/> | |
<label for="taskName">Task Name</label> | |
<input id="taskName" name="taskName" type="text" class="required" minlength="2"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ds/defentity Task [^:key taskId, locationId, ^:clj task]) |
NewerOlder