// Path: app/models/RecordedLocation.java
// @MongoCollection(name = "recorded_location")
// public class RecordedLocation {
// 
// 	public static JacksonDBCollection<RecordedLocation.Model, String> coll = MongoDB.getCollection("recorded_location", RecordedLocation.Model.class, String.class);
// 	
// 	public static class Model {
// 	
// 		@ObjectId
// 		@Id
// 		public String _id;
// 		
// 		@ObjectId
// 		public String sessionId;
// 		
// 		public Date startedAt;
// 		public Date lastActionAt;
// 		
// 		//TODO: separate domain, path
// 		public String location;
// 		
// 	}
// 	public static WriteResult<RecordedLocation.Model, String> save(Model ob) {
// 		WriteResult<RecordedLocation.Model, String> tmp = coll.save(ob); 
// 		coll.ensureIndex( new BasicDBObject("sessionId", 1) );
// 		coll.ensureIndex( new BasicDBObject("location", 1) );
// 		return tmp;
// 	}
// 	
// 	public static Long getDurationSeconds(Model ob) {
// 		return ( ( ob.lastActionAt.getTime() - ob.startedAt.getTime() ) / 1000 );
// 	}
// 	public static String getDuration(Model ob) {
// 		Long seconds = getDurationSeconds(ob);
// 		Long min = seconds / 60;
// 		Long leftSeconds = seconds % 60 ;
// 		return min+":"+leftSeconds;
// 	}
// }


import org.bson.types.ObjectId;
import com.mongodb.BasicDBObject;
import net.vz.mongodb.jackson.DBQuery;
import net.vz.mongodb.jackson.DBQuery.Query;
import models.RecordedLocation;
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.Result;
import views.html.recordedlocations.*;
import play.mvc.Security;
package controllers;






@Security.Authenticated(AdminSecurity.class)
public class RecordedLocations extends Controller {

	public static class deleteRequest {
		public Long id;
		public deleteRequest() {}
	}
	
	public static class listingRequest extends utils.BasicRequests.listingRequest {
		public String sessId;
	}
	
	public static Result index() {
		Http.Context.current().args.put("admin_module", "Recorded Locations");
		Http.Context.current().args.put("admin_parent_section", "recorded_locations");
		
		listingRequest params = form( listingRequest.class ).bindFromRequest().get();
		//Listview init
	
		Query adminQuery = DBQuery.exists("sessionId");
		if( params.sessId != null && !params.sessId.isEmpty() )  {
			adminQuery.is("sessionId", new ObjectId( params.sessId ) );
		}
		net.vz.mongodb.jackson.DBCursor<RecordedLocation.Model> admins = models.RecordedLocation.coll.find( adminQuery )
															  .skip( params.resultsPerPage * params.p - params.resultsPerPage ).limit( params.resultsPerPage )
															  .sort( new BasicDBObject("lastActionAt", -1) );
		
// Path: app/models/RecordedLocation.java
// @MongoCollection(name = "recorded_location")
// public class RecordedLocation {
// 
// 	public static JacksonDBCollection<RecordedLocation.Model, String> coll = MongoDB.getCollection("recorded_location", RecordedLocation.Model.class, String.class);
// 	
// 	public static class Model {
// 	
// 		@ObjectId
// 		@Id
// 		public String _id;
// 		
// 		@ObjectId
// 		public String sessionId;
// 		
// 		public Date startedAt;
// 		public Date lastActionAt;
// 		
// 		//TODO: separate domain, path
// 		public String location;
// 		
// 	}
// 	public static WriteResult<RecordedLocation.Model, String> save(Model ob) {
// 		WriteResult<RecordedLocation.Model, String> tmp = coll.save(ob); 
// 		coll.ensureIndex( new BasicDBObject("sessionId", 1) );
// 		coll.ensureIndex( new BasicDBObject("location", 1) );
// 		return tmp;
// 	}
// 	
// 	public static Long getDurationSeconds(Model ob) {
// 		return ( ( ob.lastActionAt.getTime() - ob.startedAt.getTime() ) / 1000 );
// 	}
// 	public static String getDuration(Model ob) {
// 		Long seconds = getDurationSeconds(ob);
// 		Long min = seconds / 60;
// 		Long leftSeconds = seconds % 60 ;
// 		return min+":"+leftSeconds;
// 	}
// }


// Path: app/controllers/RecordedLocations.java
import org.bson.types.ObjectId;
import com.mongodb.BasicDBObject;
import net.vz.mongodb.jackson.DBQuery;
import net.vz.mongodb.jackson.DBQuery.Query;
import models.RecordedLocation;
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.Result;
import views.html.recordedlocations.*;
import play.mvc.Security;

package controllers;






@Security.Authenticated(AdminSecurity.class)
public class RecordedLocations extends Controller {

	public static class deleteRequest {
		public Long id;
		public deleteRequest() {}
	}
	
	public static class listingRequest extends utils.BasicRequests.listingRequest {
		public String sessId;
	}
	
	public static Result index() {
		Http.Context.current().args.put("admin_module", "Recorded Locations");
		Http.Context.current().args.put("admin_parent_section", "recorded_locations");
		
		listingRequest params = form( listingRequest.class ).bindFromRequest().get();
		//Listview init
	
		Query adminQuery = DBQuery.exists("sessionId");
		if( params.sessId != null && !params.sessId.isEmpty() )  {
			adminQuery.is("sessionId", new ObjectId( params.sessId ) );
		}
		net.vz.mongodb.jackson.DBCursor<RecordedLocation.Model> admins = models.RecordedLocation.coll.find( adminQuery )
															  .skip( params.resultsPerPage * params.p - params.resultsPerPage ).limit( params.resultsPerPage )
															  .sort( new BasicDBObject("lastActionAt", -1) );
		
		params.setTotalResults( models.RecordedLocation.coll.find( adminQuery ).count() );