From 217e823fdce29420d6cae93a943bc97d8b0f2f23 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 17:31:17 +0530 Subject: [PATCH 01/64] beginnings of api - route --- chaloBEST/mumbai/apiviews.py | 10 +++++++++ chaloBEST/mumbai/models.py | 39 +++++++++++++++++++++++++++++++++++- chaloBEST/mumbai/views.py | 1 + chaloBEST/settings.py | 2 ++ chaloBEST/urls.py | 5 ++++- 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 chaloBEST/mumbai/apiviews.py diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py new file mode 100644 index 0000000..25a00d8 --- /dev/null +++ b/chaloBEST/mumbai/apiviews.py @@ -0,0 +1,10 @@ +from models import * +from ox.django.shortcuts import get_object_or_404_json + +def route(request, code): + route = get_object_or_404_json(Route, code=code) + stops = [r.stop.get_dict() for r in RouteDetail.objects.filter(route=route)] + return render_to_json_response({ + 'route': route.get_dict(), + 'stops': stops + }) diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index aaeee15..72e2e41 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -95,6 +95,34 @@ class Stop(models.Model): point = models.PointField(null=True) alt_names = generic.GenericRelation("AlternativeName") + def get_dict(self): + return { + 'id': self.id, + 'code': self.code, + 'slug': self.slug, + 'official_name': self.name, + 'display_name': self.display_name, + 'road': self.road.name, + 'area': self.area.name, + 'name_mr': self.name_mr + #FIXME: add alt names + } + + def get_geojson(self, srid=4326): + if self.point is not None: + geom = json.loads(self.point.transform(srid, True).geojson) + else: + geom = {} + + properties = self.get_dict() + + return { + 'type': 'Feature', + 'properties': properties, + 'geometry': geom + } + + def __unicode__(self): return self.name @@ -130,6 +158,14 @@ class Route(models.Model): def __unicode__(self): return self.alias + def get_dict(self): + return { + 'id': self.id, + 'code': self.code, + 'alias': self.alias, + 'slug': self.slug, + 'distance': self.distance + } class RouteDetail(models.Model): route_code = models.TextField() @@ -141,7 +177,8 @@ class RouteDetail(models.Model): class Meta: verbose_name = 'Route Detail' - + ordering = ['serial'] + def __unicode__(self): return str(self.route) + " : " + str(self.serial) diff --git a/chaloBEST/mumbai/views.py b/chaloBEST/mumbai/views.py index 4a1c164..0079b50 100644 --- a/chaloBEST/mumbai/views.py +++ b/chaloBEST/mumbai/views.py @@ -2,6 +2,7 @@ from models import * from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext +from actions import * def index(request): return render_to_response("index.html", {}) diff --git a/chaloBEST/settings.py b/chaloBEST/settings.py index 1cf223a..53a0719 100644 --- a/chaloBEST/settings.py +++ b/chaloBEST/settings.py @@ -11,6 +11,8 @@ ADMINS = ( # ('Your Name', 'your_email@domain.com'), ) +SITENAME = "ChaloBEST" + LOCAL_DEVELOPMENT = True JSON_DEBUG = True diff --git a/chaloBEST/urls.py b/chaloBEST/urls.py index 2ecc4de..f437764 100644 --- a/chaloBEST/urls.py +++ b/chaloBEST/urls.py @@ -4,6 +4,9 @@ from os.path import join # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() +#import ox.django.api.urls +#import mumbai + urlpatterns = patterns('', # Example: @@ -14,7 +17,7 @@ urlpatterns = patterns('', (r'^route/(?P[a-zA-Z0-9\s\-]*?)/$', 'mumbai.views.route'), (r'^areas/$', 'mumbai.views.areas'), (r'^area/(?P.*?)/$', 'mumbai.views.area'), - + (r'^1.0/', include('mumbai.apiurls')), # Uncomment the admin/doc line below to enable admin documentation: (r'^admin/doc/', include('django.contrib.admindocs.urls')), #(r'^grappelli/', include('grappelli.urls')), From 64858f7662bf2471ba23df67f08cbe795b26de78 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 17:33:44 +0530 Subject: [PATCH 02/64] ups, did not add apiurls.py --- chaloBEST/mumbai/apiurls.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 chaloBEST/mumbai/apiurls.py diff --git a/chaloBEST/mumbai/apiurls.py b/chaloBEST/mumbai/apiurls.py new file mode 100644 index 0000000..15ce22b --- /dev/null +++ b/chaloBEST/mumbai/apiurls.py @@ -0,0 +1,6 @@ +from django.conf.urls.defaults import * +import apiviews + +urlpatterns = patterns('', + (r'^route/(?P[0-9]*)$', apiviews.route), +) From fa32d2d6cd116e0cbc279468a6d2f7e04529ab56 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 17:34:40 +0530 Subject: [PATCH 03/64] dont import actions --- chaloBEST/mumbai/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/chaloBEST/mumbai/views.py b/chaloBEST/mumbai/views.py index 0079b50..4a1c164 100644 --- a/chaloBEST/mumbai/views.py +++ b/chaloBEST/mumbai/views.py @@ -2,7 +2,6 @@ from models import * from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext -from actions import * def index(request): return render_to_response("index.html", {}) From a852e6ec4b1fb32b7f867d10d66245ecc2acfd8c Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 17:35:29 +0530 Subject: [PATCH 04/64] ups, import render_to_json_response --- chaloBEST/mumbai/apiviews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 25a00d8..dfdf441 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -1,5 +1,5 @@ from models import * -from ox.django.shortcuts import get_object_or_404_json +from ox.django.shortcuts import get_object_or_404_json, render_to_json_response def route(request, code): route = get_object_or_404_json(Route, code=code) From 68e18398fdd054066eb550f71a788e41188c04f4 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 17:39:07 +0530 Subject: [PATCH 05/64] convert Decimal instance to str before JSON serialization --- chaloBEST/mumbai/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index 72e2e41..a896524 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -164,7 +164,7 @@ class Route(models.Model): 'code': self.code, 'alias': self.alias, 'slug': self.slug, - 'distance': self.distance + 'distance': str(self.distance) } class RouteDetail(models.Model): From 1c16d27d9914d25bbb66be8ad185484be07280ae Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 17:44:19 +0530 Subject: [PATCH 06/64] convert stops feed to GeoJSON --- chaloBEST/mumbai/apiviews.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index dfdf441..5e31772 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -3,8 +3,11 @@ from ox.django.shortcuts import get_object_or_404_json, render_to_json_response def route(request, code): route = get_object_or_404_json(Route, code=code) - stops = [r.stop.get_dict() for r in RouteDetail.objects.filter(route=route)] + stops = [r.stop.get_geojson() for r in RouteDetail.objects.filter(route=route)] return render_to_json_response({ 'route': route.get_dict(), - 'stops': stops + 'stops': { + 'type': 'FeatureCollection', + 'features': stops + } }) From fe3c276ec743e1efb8adebebba5baea6eae8611a Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 17:46:18 +0530 Subject: [PATCH 07/64] import json; change code to alias in route api lookup --- chaloBEST/mumbai/apiurls.py | 2 +- chaloBEST/mumbai/apiviews.py | 5 +++-- chaloBEST/mumbai/models.py | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/chaloBEST/mumbai/apiurls.py b/chaloBEST/mumbai/apiurls.py index 15ce22b..56704dc 100644 --- a/chaloBEST/mumbai/apiurls.py +++ b/chaloBEST/mumbai/apiurls.py @@ -2,5 +2,5 @@ from django.conf.urls.defaults import * import apiviews urlpatterns = patterns('', - (r'^route/(?P[0-9]*)$', apiviews.route), + (r'^route/(?P.*)$', apiviews.route), #FIXME: better regexp for route alias? ) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 5e31772..2c7044f 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -1,8 +1,9 @@ from models import * from ox.django.shortcuts import get_object_or_404_json, render_to_json_response -def route(request, code): - route = get_object_or_404_json(Route, code=code) + +def route(request, alias): + route = get_object_or_404_json(Route, alias=alias) stops = [r.stop.get_geojson() for r in RouteDetail.objects.filter(route=route)] return render_to_json_response({ 'route': route.get_dict(), diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index a896524..b8aca72 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -2,6 +2,7 @@ from django.contrib.gis.db import models from django import forms from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic +import json STOP_CHOICES = ( ('U','Up'), ('D', 'Down'), From ebdb732921116736b12075d1580619e10f89a3b6 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 18:24:28 +0530 Subject: [PATCH 08/64] added api call to edit stop --- chaloBEST/mumbai/apiviews.py | 8 ++++++++ chaloBEST/mumbai/models.py | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 2c7044f..6c8f6ce 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -1,5 +1,6 @@ from models import * from ox.django.shortcuts import get_object_or_404_json, render_to_json_response +from django.contrib.auth.decorators import login_required def route(request, alias): @@ -12,3 +13,10 @@ def route(request, alias): 'features': stops } }) + +@login_required(request, id): + if not id: + stop = Stop() #FIXME: should this return an error instead? + else: + stop = get_object_or_404_json(Stop, id=id) + return stop.from_geojson(request.POST) diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index b8aca72..e938621 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -1,4 +1,5 @@ from django.contrib.gis.db import models +from django.contrib.gis.geos import Point from django import forms from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic @@ -123,6 +124,16 @@ class Stop(models.Model): 'geometry': geom } + def from_geojson(self, geojson): + geom = geojson['geometry']['coordinates'] + data = geojson['properties'] + self.point = Point(geom[0], geom[1]) + self.display_name = data['display_name'] + self.name_mr = data['name_mr'] + #FIXME: add alt names logic + self.save() + return self.get_geojson() + def __unicode__(self): return self.name From be8376c8fabd6201ff786f1db646bde1844f0db9 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 18:27:08 +0530 Subject: [PATCH 09/64] get / edit stop --- chaloBEST/mumbai/apiurls.py | 1 + chaloBEST/mumbai/apiviews.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/chaloBEST/mumbai/apiurls.py b/chaloBEST/mumbai/apiurls.py index 56704dc..7360b4e 100644 --- a/chaloBEST/mumbai/apiurls.py +++ b/chaloBEST/mumbai/apiurls.py @@ -3,4 +3,5 @@ import apiviews urlpatterns = patterns('', (r'^route/(?P.*)$', apiviews.route), #FIXME: better regexp for route alias? + (r'^stop/(?P[0-9]*)$', apiviews.stop), ) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 6c8f6ce..d2548ce 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -14,9 +14,14 @@ def route(request, alias): } }) -@login_required(request, id): - if not id: - stop = Stop() #FIXME: should this return an error instead? + +def stop:(request, id): + if request.POST: + if not id: + stop = Stop() #FIXME: should this return an error instead? + else: + stop = get_object_or_404_json(Stop, id=id) + return stop.from_geojson(request.POST) else: stop = get_object_or_404_json(Stop, id=id) - return stop.from_geojson(request.POST) + return stop.get_geojson() From df56eed833d07317c38cea8af5ef0806659e11d9 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 18:28:12 +0530 Subject: [PATCH 10/64] oops, syntax --- chaloBEST/mumbai/apiviews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index d2548ce..9a8ea22 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -15,7 +15,7 @@ def route(request, alias): }) -def stop:(request, id): +def stop(request, id): if request.POST: if not id: stop = Stop() #FIXME: should this return an error instead? From eb75240f2e2d091de11a9e7e5682dcb12209f414 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 18:30:21 +0530 Subject: [PATCH 11/64] silly, dont return a dict, return a response --- chaloBEST/mumbai/apiviews.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 9a8ea22..9e589f1 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -21,7 +21,7 @@ def stop(request, id): stop = Stop() #FIXME: should this return an error instead? else: stop = get_object_or_404_json(Stop, id=id) - return stop.from_geojson(request.POST) + return render_to_json_response(stop.from_geojson(request.POST)) else: stop = get_object_or_404_json(Stop, id=id) - return stop.get_geojson() + return render_to_json_response(stop.get_geojson()) #FIXME: please don't repeat this code, its retarded. From 48580ad4be21ffecf8eeaacee41f0bfedcfdaca2 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 18:37:11 +0530 Subject: [PATCH 12/64] add make_slugs script --- chaloBEST/imports/make_slugs.py | 11 +++++++++++ chaloBEST/mumbai/models.py | 1 - 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 chaloBEST/imports/make_slugs.py diff --git a/chaloBEST/imports/make_slugs.py b/chaloBEST/imports/make_slugs.py new file mode 100644 index 0000000..bad6b41 --- /dev/null +++ b/chaloBEST/imports/make_slugs.py @@ -0,0 +1,11 @@ +from django.template.defaultfilters import slugify +from mumbai.models import * + +def do(): + for cls in [Road, Area, Stop]: + for obj in cls.objects.all(): + obj.slug = slugify(obj.display_name) + obj.save() + for r in Route.objects.all(): + r.slug = r.alias + r.save() diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index e938621..014949a 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -56,7 +56,6 @@ class Area(models.Model): def __unicode__(self): return self.name - class Road(models.Model): code = models.IntegerField()#primary_key=True) From df16e4cfe5b5deb5f4564231b8c556b52287fcde Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 18:41:19 +0530 Subject: [PATCH 13/64] change stop requests to slugs instead of ids --- chaloBEST/mumbai/apiurls.py | 4 ++-- chaloBEST/mumbai/apiviews.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/chaloBEST/mumbai/apiurls.py b/chaloBEST/mumbai/apiurls.py index 7360b4e..19781c2 100644 --- a/chaloBEST/mumbai/apiurls.py +++ b/chaloBEST/mumbai/apiurls.py @@ -2,6 +2,6 @@ from django.conf.urls.defaults import * import apiviews urlpatterns = patterns('', - (r'^route/(?P.*)$', apiviews.route), #FIXME: better regexp for route alias? - (r'^stop/(?P[0-9]*)$', apiviews.stop), + (r'^route/(?P.*)$', apiviews.route), #FIXME: better regexp for route alias? + (r'^stop/(?P.*)$', apiviews.stop), ) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 9e589f1..f02a1ba 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -3,8 +3,8 @@ from ox.django.shortcuts import get_object_or_404_json, render_to_json_response from django.contrib.auth.decorators import login_required -def route(request, alias): - route = get_object_or_404_json(Route, alias=alias) +def route(request, slug): + route = get_object_or_404_json(Route, slug=slug) stops = [r.stop.get_geojson() for r in RouteDetail.objects.filter(route=route)] return render_to_json_response({ 'route': route.get_dict(), @@ -15,13 +15,13 @@ def route(request, alias): }) -def stop(request, id): +def stop(request, slug): if request.POST: - if not id: + if not slug: stop = Stop() #FIXME: should this return an error instead? else: - stop = get_object_or_404_json(Stop, id=id) + stop = get_object_or_404_json(Stop, slug=slug) return render_to_json_response(stop.from_geojson(request.POST)) else: - stop = get_object_or_404_json(Stop, id=id) + stop = get_object_or_404_json(Stop, slug=slug) return render_to_json_response(stop.get_geojson()) #FIXME: please don't repeat this code, its retarded. From de01b12eed986b2dedffcc8a9a306be8e7aa71c9 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 18:52:34 +0530 Subject: [PATCH 14/64] return geojson from stops --- chaloBEST/mumbai/apiurls.py | 3 +++ chaloBEST/mumbai/apiviews.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/chaloBEST/mumbai/apiurls.py b/chaloBEST/mumbai/apiurls.py index 19781c2..ba5c793 100644 --- a/chaloBEST/mumbai/apiurls.py +++ b/chaloBEST/mumbai/apiurls.py @@ -4,4 +4,7 @@ import apiviews urlpatterns = patterns('', (r'^route/(?P.*)$', apiviews.route), #FIXME: better regexp for route alias? (r'^stop/(?P.*)$', apiviews.stop), + (r'^routes/$', apiviews.routes), + (r'^areas/$', apiviews.areas), + (r'^stops/$', apiviews.stops), ) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index f02a1ba..36609ab 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -15,6 +15,35 @@ def route(request, slug): }) +def routes(request): + qset = Route.objects.all() + if request.GET.has_key('q'): + q = request.GET.get('q', '') + qset = qset.filter(alias__icontains=q) #FIXME: make a better Q object + routes = [route.alias for route in qset] + return render_to_json_response(routes) + + +def areas(request): + qset = Area.objects.all() + if request.GET.has_key('q'): + q = request.GET.get('q', '') + qset = qset.filter(display_name__icontains=q) + areas = [area.slug for area in qset] + return render_to_json_response(areas) + +def stops(request): + qset = Stop.objects.all() + if request.GET.has_key('q'): + q = request.GET.get('q', '') + qset = qset.filter(display_name__icontains=q) #FIXME: This definitely needs to be a Q object with OR lookups for area name, road name, etc. + return render_to_json_response({ + 'type': 'FeatureCollection', + 'features': [stop.get_geojson() for stop in qset] + }) + + + def stop(request, slug): if request.POST: if not slug: From e92fc98ab1452e1fb3bf11b6f4c666e247cbe4c7 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 19:02:27 +0530 Subject: [PATCH 15/64] add routes list to stop GET --- chaloBEST/mumbai/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index 014949a..212ee1c 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -97,6 +97,7 @@ class Stop(models.Model): alt_names = generic.GenericRelation("AlternativeName") def get_dict(self): + routes = [r.route.alias for r in RouteDetail.objects.filter(stop=self)] return { 'id': self.id, 'code': self.code, @@ -105,7 +106,8 @@ class Stop(models.Model): 'display_name': self.display_name, 'road': self.road.name, 'area': self.area.name, - 'name_mr': self.name_mr + 'name_mr': self.name_mr, + 'routes': routes #FIXME: add alt names } From 89b46e1bcedf72c0066721234f64b24c07c78b6a Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 20:01:00 +0530 Subject: [PATCH 16/64] add call for area --- chaloBEST/mumbai/apiurls.py | 1 + chaloBEST/mumbai/apiviews.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/chaloBEST/mumbai/apiurls.py b/chaloBEST/mumbai/apiurls.py index ba5c793..b33c5c2 100644 --- a/chaloBEST/mumbai/apiurls.py +++ b/chaloBEST/mumbai/apiurls.py @@ -3,6 +3,7 @@ import apiviews urlpatterns = patterns('', (r'^route/(?P.*)$', apiviews.route), #FIXME: better regexp for route alias? + (r'^area/(?P.*)$', apiviews.area), (r'^stop/(?P.*)$', apiviews.stop), (r'^routes/$', apiviews.routes), (r'^areas/$', apiviews.areas), diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 36609ab..ec0fb37 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -14,6 +14,13 @@ def route(request, slug): } }) +def area(request, slug) + area = get_object_or_404_json(Area, slug=slug) + stops = [stop.get_geojson() for stop in Stop.objects.filter(area=area)] + return render_to_json_response({ + 'type': 'FeatureCollection', + 'features': stops + }) def routes(request): qset = Route.objects.all() From 9d2648e33c42168b7196547be09c01a3dcf67368 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 20:01:39 +0530 Subject: [PATCH 17/64] ups, syntax --- chaloBEST/mumbai/apiviews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index ec0fb37..40caa52 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -14,7 +14,7 @@ def route(request, slug): } }) -def area(request, slug) +def area(request, slug): area = get_object_or_404_json(Area, slug=slug) stops = [stop.get_geojson() for stop in Stop.objects.filter(area=area)] return render_to_json_response({ From caafe71240127c2b282b0dc807f363e22a1ec368 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 18:58:22 +0530 Subject: [PATCH 18/64] first step toward editstops --- chaloBEST/mumbai/models.py | 15 +++++++++--- chaloBEST/mumbai/views.py | 7 ++++++ chaloBEST/static/css/editstops.css | 0 chaloBEST/static/js/editstops.js | 31 ++++++++++++++++++++++++ chaloBEST/templates/base.html | 1 + chaloBEST/templates/editstops.html | 39 ++++++++++++++++++++++++++++++ chaloBEST/urls.py | 1 + 7 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 chaloBEST/static/css/editstops.css create mode 100644 chaloBEST/static/js/editstops.js create mode 100644 chaloBEST/templates/editstops.html diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index 212ee1c..5fc40d0 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -97,7 +97,6 @@ class Stop(models.Model): alt_names = generic.GenericRelation("AlternativeName") def get_dict(self): - routes = [r.route.alias for r in RouteDetail.objects.filter(stop=self)] return { 'id': self.id, 'code': self.code, @@ -107,8 +106,8 @@ class Stop(models.Model): 'road': self.road.name, 'area': self.area.name, 'name_mr': self.name_mr, - 'routes': routes - #FIXME: add alt names + 'routes': ",".join([r.route.alias for r in RouteDetail.objects.filter(stop=self)]), + 'alternative_names': ",".join([a.name for a in self.alt_names.all().filter(typ='common')]) } def get_geojson(self, srid=4326): @@ -131,6 +130,16 @@ class Stop(models.Model): self.point = Point(geom[0], geom[1]) self.display_name = data['display_name'] self.name_mr = data['name_mr'] + if data.has_key('alternative_names') and data['alternative_names'].strip() != '': + for a in self.alt_names.all(): + a.delete() + for a in data['alternative_names'].split(","): + alt_name = AlternativeName() + alt_name.name = a['name'] + alt_name.typ = 'common' + alt_name.save() + self.alt_names.add(alt_name) + #FIXME: add alt names logic self.save() return self.get_geojson() diff --git a/chaloBEST/mumbai/views.py b/chaloBEST/mumbai/views.py index 4a1c164..4affe51 100644 --- a/chaloBEST/mumbai/views.py +++ b/chaloBEST/mumbai/views.py @@ -2,6 +2,7 @@ from models import * from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext +from django.contrib.auth.decorators import login_required def index(request): return render_to_response("index.html", {}) @@ -36,3 +37,9 @@ def area(request, name): }) return render_to_response("area.html", context) +@login_required +def editstops(request): + context = RequestContext(request, {}) + return render_to_response("editstops.html", context) + + diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css new file mode 100644 index 0000000..e69de29 diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js new file mode 100644 index 0000000..50257d6 --- /dev/null +++ b/chaloBEST/static/js/editstops.js @@ -0,0 +1,31 @@ +var API_BASE = "/1.0/" +$(function() { + $('.tabButton').click(function() { + if ($(this).hasClass("selected")) { + return; + } + var $that = $(this); + var name = $that.attr("data-name"); + var $listWrapper = $('#' + name); + if ($that.data("loaded")) { + $.noop(); //dont load data + } else { + $that.data("loaded", true); + var $list = $('#' + name + 'List'); + $.post("/" + name, {}, function(items) { + $.each(items, function(i,v) { + var $li = $('
  • ') + .addClass("listItem") + .text(v) + .appendTo($list); + }); + }, "json"); + } + + $('.listWrapper').hide(); + $listWrapper.show(); + $('.selected').removeClass("selected"); + $that.addClass("selected"); + }); + +}); diff --git a/chaloBEST/templates/base.html b/chaloBEST/templates/base.html index 28ae2eb..a6eca7e 100644 --- a/chaloBEST/templates/base.html +++ b/chaloBEST/templates/base.html @@ -1,6 +1,7 @@ + ChaloBEST: {% block title %} {% endblock %} {% block head %} diff --git a/chaloBEST/templates/editstops.html b/chaloBEST/templates/editstops.html new file mode 100644 index 0000000..9320288 --- /dev/null +++ b/chaloBEST/templates/editstops.html @@ -0,0 +1,39 @@ +{% extends 'base.html' %} + +{% block head %} + + +{% endblock %} + + +{% block body %} +
    +
    +
    + Areas +
    +
    + Routes +
    +
    +
    +
    + +
      +
    +
    +
    + +
      +
    +
    +
    +
    +
    + +
    +
    + +
    + +{% endblock %} diff --git a/chaloBEST/urls.py b/chaloBEST/urls.py index f437764..807cce1 100644 --- a/chaloBEST/urls.py +++ b/chaloBEST/urls.py @@ -17,6 +17,7 @@ urlpatterns = patterns('', (r'^route/(?P[a-zA-Z0-9\s\-]*?)/$', 'mumbai.views.route'), (r'^areas/$', 'mumbai.views.areas'), (r'^area/(?P.*?)/$', 'mumbai.views.area'), + (r'^editstops/$', 'mumbai.views.editstops'), (r'^1.0/', include('mumbai.apiurls')), # Uncomment the admin/doc line below to enable admin documentation: (r'^admin/doc/', include('django.contrib.admindocs.urls')), From 8531eb53ecf7b6569a6247f76b26e213113feee1 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:00:10 +0530 Subject: [PATCH 19/64] ups, wrong api url in js --- chaloBEST/static/js/editstops.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 50257d6..8274ddc 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -12,7 +12,8 @@ $(function() { } else { $that.data("loaded", true); var $list = $('#' + name + 'List'); - $.post("/" + name, {}, function(items) { + var url = "/" + API_BASE + "/" + name; + $.post(url, {}, function(items) { $.each(items, function(i,v) { var $li = $('
  • ') .addClass("listItem") From de4ab219ce89425bdb92c13180e3f8d5212a2a9f Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:01:44 +0530 Subject: [PATCH 20/64] ups, wrong api url in js again --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 8274ddc..ed2a0b0 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -12,7 +12,7 @@ $(function() { } else { $that.data("loaded", true); var $list = $('#' + name + 'List'); - var url = "/" + API_BASE + "/" + name; + var url = API_BASE + name; $.post(url, {}, function(items) { $.each(items, function(i,v) { var $li = $('
  • ') From f967fa184b547b696c8a5d3761ae422410c807fd Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:02:41 +0530 Subject: [PATCH 21/64] argh, append slash to url --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index ed2a0b0..fc5657e 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -12,7 +12,7 @@ $(function() { } else { $that.data("loaded", true); var $list = $('#' + name + 'List'); - var url = API_BASE + name; + var url = API_BASE + name + "/"; $.post(url, {}, function(items) { $.each(items, function(i,v) { var $li = $('
  • ') From 0d051bcbb7360d2ed5a183708aee27be46d8a159 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:04:29 +0530 Subject: [PATCH 22/64] ups, request is GET --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index fc5657e..b255cc9 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -13,7 +13,7 @@ $(function() { $that.data("loaded", true); var $list = $('#' + name + 'List'); var url = API_BASE + name + "/"; - $.post(url, {}, function(items) { + $.get(url, {}, function(items) { $.each(items, function(i,v) { var $li = $('
  • ') .addClass("listItem") From 338e5a4ead69eb33877d2da04a7299f07ca79c9e Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:32:53 +0530 Subject: [PATCH 23/64] edit stops should fetch stops for area / route --- chaloBEST/mumbai/apiviews.py | 7 +++-- chaloBEST/mumbai/models.py | 11 ++++++++ chaloBEST/static/css/editstops.css | 27 +++++++++++++++++++ chaloBEST/static/js/editstops.js | 42 +++++++++++++++++++++++++++--- chaloBEST/templates/editstops.html | 8 +++--- 5 files changed, 86 insertions(+), 9 deletions(-) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 40caa52..10d3424 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -18,8 +18,11 @@ def area(request, slug): area = get_object_or_404_json(Area, slug=slug) stops = [stop.get_geojson() for stop in Stop.objects.filter(area=area)] return render_to_json_response({ - 'type': 'FeatureCollection', - 'features': stops + 'area': area.get_dict(), + 'stops': { + 'type': 'FeatureCollection', + 'features': stops + } }) def routes(request): diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index 5fc40d0..6529d05 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -51,6 +51,17 @@ class Area(models.Model): geometry = models.PolygonField(blank=True, null=True) alt_names = generic.GenericRelation("AlternativeName") + def get_dict(self): + return { + 'id': self.id, + 'code': self.code, + 'slug': self.slug, + 'name': self.name, + 'name_mr': self.name_mr, + 'display_name': self.display_name + #FIXME add alt_names and geometry + } + def get_absolute_url(self): return "/area/%s/" % self.name diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index e69de29..d51faa0 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -0,0 +1,27 @@ +html, body { + width: 100%; +} + +#wrapper { + width: 100%; +} + +#listsCol { + width: 24%; + float: left; +} + +#mapCol { + width: 50%; + float: left; +} + +#formCol { + width: 24%; + float: left; +} + +.listWrapper { + display: none; +} + diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index b255cc9..9cd8a4c 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -13,14 +13,16 @@ $(function() { $that.data("loaded", true); var $list = $('#' + name + 'List'); var url = API_BASE + name + "/"; - $.get(url, {}, function(items) { + var $loadingLi = $('
    ').text("Loading...").appendTo($list); + $.getJSON(url, {}, function(items) { + $loadingLi.remove(); $.each(items, function(i,v) { - var $li = $('
  • ') + var $li = $('
    ') .addClass("listItem") .text(v) .appendTo($list); }); - }, "json"); + }); } $('.listWrapper').hide(); @@ -29,4 +31,38 @@ $(function() { $that.addClass("selected"); }); + $('.list').click(function(e) { + var name = $(this).attr("id").replace("List", ""); + var $target = $(e.target); + if (!target.hasClass('list')) { + return; + } + if ($target.data("loading")) { + return; + } + if ($target.data("hasList")) { + $target.find(".stopList").toggle(); + return; + } + var url = API_BASE + name + "/" + $target.text(); + $target.data("loading", true); + $.getJSON(url, {}, function(area) { + var stops = area.stops.features; + var $stopsList = getStopsList(stops); + $target.append($stopsList); + $target.data("hasList", true); + $target.data("loading", false); + }); + }); + }); + +function getStopsList(stops) { + var $ul = $('
      ').addClass("stopsList"); + $.each(stops, function(i,v) { + var props = v.properties; + var geom = v.geometry; + var $li = $('
    • ').addClass("stopItem").data("slug", props.slug).data("geometry", geom).text(props.display_name).appendTo($ul); + }); + return $ul; +} diff --git a/chaloBEST/templates/editstops.html b/chaloBEST/templates/editstops.html index 9320288..6d28c6d 100644 --- a/chaloBEST/templates/editstops.html +++ b/chaloBEST/templates/editstops.html @@ -19,13 +19,13 @@
      -
        -
      +
      +
      -
        -
      +
      +
    From 2b43cc90b7abb89686d2063597e1a4e0f2434840 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:34:51 +0530 Subject: [PATCH 24/64] silly error + loading behaviour --- chaloBEST/static/js/editstops.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 9cd8a4c..93ac9c8 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -34,7 +34,7 @@ $(function() { $('.list').click(function(e) { var name = $(this).attr("id").replace("List", ""); var $target = $(e.target); - if (!target.hasClass('list')) { + if (!$target.hasClass('list')) { return; } if ($target.data("loading")) { @@ -46,7 +46,9 @@ $(function() { } var url = API_BASE + name + "/" + $target.text(); $target.data("loading", true); + var $loading = $('').addClass("loadingSpan").text("Loading...").appendTo($target); $.getJSON(url, {}, function(area) { + $loading.remove(); var stops = area.stops.features; var $stopsList = getStopsList(stops); $target.append($stopsList); From 45c37db9af7da9886e23294c7e79b76b410f5748 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:36:16 +0530 Subject: [PATCH 25/64] ups, checking for wrong class --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 93ac9c8..0049235 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -34,7 +34,7 @@ $(function() { $('.list').click(function(e) { var name = $(this).attr("id").replace("List", ""); var $target = $(e.target); - if (!$target.hasClass('list')) { + if (!$target.hasClass('listItem')) { return; } if ($target.data("loading")) { From c1aedefbc7d88c3ab23ace3eb26da01dd33e1499 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:37:18 +0530 Subject: [PATCH 26/64] silly - route, not routes --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 0049235..322cd7e 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -32,7 +32,7 @@ $(function() { }); $('.list').click(function(e) { - var name = $(this).attr("id").replace("List", ""); + var name = $(this).attr("id").replace("sList", ""); //FIXME: stick name in a data attr or so? var $target = $(e.target); if (!$target.hasClass('listItem')) { return; From 974a57ee1aaa12108d4f1d04dc210ce04c35d215 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:40:22 +0530 Subject: [PATCH 27/64] update slug script to ensure unique / ugly hack --- chaloBEST/imports/make_slugs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chaloBEST/imports/make_slugs.py b/chaloBEST/imports/make_slugs.py index bad6b41..3ef2daa 100644 --- a/chaloBEST/imports/make_slugs.py +++ b/chaloBEST/imports/make_slugs.py @@ -4,7 +4,10 @@ from mumbai.models import * def do(): for cls in [Road, Area, Stop]: for obj in cls.objects.all(): - obj.slug = slugify(obj.display_name) + slug = slugify(obj.display_name) + if cls.objects.filter(slug=slug).count() > 1: + slug += "2" + obj.slug = slug obj.save() for r in Route.objects.all(): r.slug = r.alias From 087b2e5ab97020e85a5965783bae22460de6575f Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:43:43 +0530 Subject: [PATCH 28/64] minor, var cleanup + add TODO for render on map --- chaloBEST/static/js/editstops.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 322cd7e..18aa3ce 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -47,9 +47,10 @@ $(function() { var url = API_BASE + name + "/" + $target.text(); $target.data("loading", true); var $loading = $('').addClass("loadingSpan").text("Loading...").appendTo($target); - $.getJSON(url, {}, function(area) { + $.getJSON(url, {}, function(obj) { $loading.remove(); - var stops = area.stops.features; + var stopsGeojson = obj.stops; //TODO: render filtered geojson with known geometries on map + var stops = stopsGeojson.features; var $stopsList = getStopsList(stops); $target.append($stopsList); $target.data("hasList", true); From 6458eb978df04dd810076342b8b7a0de80d4cc1b Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:46:00 +0530 Subject: [PATCH 29/64] toggle stopsList typo fix --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 18aa3ce..b555383 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -41,7 +41,7 @@ $(function() { return; } if ($target.data("hasList")) { - $target.find(".stopList").toggle(); + $target.find(".stopsList").toggle(); return; } var url = API_BASE + name + "/" + $target.text(); From 2eb37a82ca620608f4463e9c7b8d49f096b284c8 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:52:06 +0530 Subject: [PATCH 30/64] list filter --- chaloBEST/static/js/editstops.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index b555383..ca885ea 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -19,8 +19,8 @@ $(function() { $.each(items, function(i,v) { var $li = $('
    ') .addClass("listItem") - .text(v) .appendTo($list); + var $txt = $('').addClass("listItemText").text(v).appendTo($li); }); }); } @@ -44,7 +44,7 @@ $(function() { $target.find(".stopsList").toggle(); return; } - var url = API_BASE + name + "/" + $target.text(); + var url = API_BASE + name + "/" + $target.find(".listItemText").text(); $target.data("loading", true); var $loading = $('').addClass("loadingSpan").text("Loading...").appendTo($target); $.getJSON(url, {}, function(obj) { @@ -58,6 +58,21 @@ $(function() { }); }); + $('.listSearch').keydown(function(e) { + var val = $(this).val(); + var name = $(this).attr("id").replace("Search", ""); + var $list = $('#' + name + "List"); + $list.find(".listItem").each(function() { + var $that = $(this); + var txt = $that.find(".listItemText").text(); + if (txt.indexOf(val) == -1) { + $that.hide(); + } else { + $that.show(); + } + }); + }); + }); function getStopsList(stops) { From eb8da64a04dd5ef1af883d17b0999906f1f71791 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:54:09 +0530 Subject: [PATCH 31/64] bubble event to parent --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index ca885ea..2c2a77a 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -33,7 +33,7 @@ $(function() { $('.list').click(function(e) { var name = $(this).attr("id").replace("sList", ""); //FIXME: stick name in a data attr or so? - var $target = $(e.target); + var $target = $(e.target).parent(); if (!$target.hasClass('listItem')) { return; } From 300a510e07624f44ac33c7ec6d5e4488ad423db3 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 19:56:11 +0530 Subject: [PATCH 32/64] remove login_required to see front-end editstops template --- chaloBEST/mumbai/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/mumbai/views.py b/chaloBEST/mumbai/views.py index 4affe51..25d520b 100644 --- a/chaloBEST/mumbai/views.py +++ b/chaloBEST/mumbai/views.py @@ -37,7 +37,7 @@ def area(request, name): }) return render_to_response("area.html", context) -@login_required + def editstops(request): context = RequestContext(request, {}) return render_to_response("editstops.html", context) From a6763707c8a252b85ce0f5572a53f578573259ae Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 20:05:22 +0530 Subject: [PATCH 33/64] minor, css --- chaloBEST/static/css/editstops.css | 17 +++++++++++++++++ chaloBEST/templates/editstops.html | 1 + 2 files changed, 18 insertions(+) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index d51faa0..ad9223c 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -25,3 +25,20 @@ html, body { display: none; } +.selected { + color: blue; + border: 1px solid #f00; +} + +.listItem { + cursor: pointer; +} + +.tabButton { + cursor: pointer; + border: 1px solid #000; +} + +.clear { + clear: both; +} diff --git a/chaloBEST/templates/editstops.html b/chaloBEST/templates/editstops.html index 6d28c6d..7c1f24f 100644 --- a/chaloBEST/templates/editstops.html +++ b/chaloBEST/templates/editstops.html @@ -15,6 +15,7 @@
    Routes
    +
    From ed256ad6ed15ee38ffac66c1096f3d7776ac860f Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 20:06:31 +0530 Subject: [PATCH 34/64] tab button width --- chaloBEST/static/css/editstops.css | 1 + 1 file changed, 1 insertion(+) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index ad9223c..c93741e 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -36,6 +36,7 @@ html, body { .tabButton { cursor: pointer; + width: 150px; border: 1px solid #000; } From 569e81d5b19f38dc01d55840d86abc8157447b3b Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 20:08:20 +0530 Subject: [PATCH 35/64] css for selected list item --- chaloBEST/static/css/editstops.css | 3 +++ chaloBEST/static/js/editstops.js | 2 ++ 2 files changed, 5 insertions(+) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index c93741e..c978eb3 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -40,6 +40,9 @@ html, body { border: 1px solid #000; } +.selectedListItem { + color: blue; +} .clear { clear: both; } diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 2c2a77a..960f501 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -40,6 +40,8 @@ $(function() { if ($target.data("loading")) { return; } + $('.selectedListItem').removeClass("selectedListItem"); + $target.addClass("selectedListItem"); if ($target.data("hasList")) { $target.find(".stopsList").toggle(); return; From 23d074b141b83fc07dcc215fd63ac1347b1472f3 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 20:09:12 +0530 Subject: [PATCH 36/64] er style only item text --- chaloBEST/static/css/editstops.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index c978eb3..b619790 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -40,7 +40,7 @@ html, body { border: 1px solid #000; } -.selectedListItem { +.selectedListItem .listItemText { color: blue; } .clear { From 9c104e8fca07f6b5b70c7d8c2d40395abcc04517 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 20:36:01 +0530 Subject: [PATCH 37/64] add outline code to get form for stop --- chaloBEST/static/js/editstops.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 960f501..fe8edd8 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -78,11 +78,28 @@ $(function() { }); function getStopsList(stops) { - var $ul = $('
      ').addClass("stopsList"); + var $ul = $('
        ').addClass("stopsList").click(function(e) { + var $target = $(e.target); + if ($target.hasClass("selectedStop")) { + return; + } + $('.selectedStop').removeClass("selectedStop"); + $target.addClass("selectedStop"); + var props = $target.data("properties"); + var $form = getStopForm(props); + $('#formCol').empty(); + $('#formCol').append($form); + }); $.each(stops, function(i,v) { var props = v.properties; var geom = v.geometry; - var $li = $('
      • ').addClass("stopItem").data("slug", props.slug).data("geometry", geom).text(props.display_name).appendTo($ul); + var $li = $('
      • ').addClass("stopItem").data("slug", props.slug).data("properties", props).data("geometry", geom).text(props.display_name).appendTo($ul); }); return $ul; } + +function getStopForm(stop) { + var $div = $('
        '); + var $displayName = $('
        ').text(stop.display_name).appendTo($div); + +} From eecfbe17eb9dd79112974981e427312fccc7976b Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 20:36:19 +0530 Subject: [PATCH 38/64] css for selected stop --- chaloBEST/static/css/editstops.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index b619790..8be93b6 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -43,6 +43,10 @@ html, body { .selectedListItem .listItemText { color: blue; } + +.selectedStop { + color: blue; +} .clear { clear: both; } From 10a6b474f0952f2f942dbd05f9b410c00f5d5e1d Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 20:37:41 +0530 Subject: [PATCH 39/64] silly, forgot to return --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index fe8edd8..dce08cd 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -101,5 +101,5 @@ function getStopsList(stops) { function getStopForm(stop) { var $div = $('
        '); var $displayName = $('
        ').text(stop.display_name).appendTo($div); - + return $div; } From 49dddf338626cbc07e4480685a39cf87b1e3a69b Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 20:38:42 +0530 Subject: [PATCH 40/64] typo in css --- chaloBEST/static/css/editstops.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index 8be93b6..c02414c 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -6,7 +6,7 @@ html, body { width: 100%; } -#listsCol { +#listCol { width: 24%; float: left; } From 86a3c3d91b1b38002cfc074ae6796e89a4a15a4d Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 20:39:00 +0530 Subject: [PATCH 41/64] more css --- chaloBEST/static/css/editstops.css | 1 + 1 file changed, 1 insertion(+) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index c02414c..f69bc7c 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -38,6 +38,7 @@ html, body { cursor: pointer; width: 150px; border: 1px solid #000; + float: left; } .selectedListItem .listItemText { From addc753b2fe7f99ace4c63c8faa4d3f30c3a4304 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 22:16:14 +0530 Subject: [PATCH 42/64] display routes for stop --- chaloBEST/static/js/editstops.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index dce08cd..100c224 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -101,5 +101,7 @@ function getStopsList(stops) { function getStopForm(stop) { var $div = $('
        '); var $displayName = $('
        ').text(stop.display_name).appendTo($div); + var $routes = $('
        ').text("Routes: " + stop.routes); + var $form = $('
        ').apendTo($div); return $div; } From a4234b5b887a746991c10a94ee92ede980a5e571 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 22:20:26 +0530 Subject: [PATCH 43/64] fixing js error --- chaloBEST/static/js/editstops.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 100c224..87db24d 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -99,9 +99,10 @@ function getStopsList(stops) { } function getStopForm(stop) { +// console.log(stop); var $div = $('
        '); var $displayName = $('
        ').text(stop.display_name).appendTo($div); - var $routes = $('
        ').text("Routes: " + stop.routes); - var $form = $('').apendTo($div); + var $routes = $('
        ').text("Routes: " + stop.routes).appendTo($div); +// var $form = $('').apendTo($div); return $div; } From e33f55730b6ad3d5110169a9af29556723f064ed Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 22:21:56 +0530 Subject: [PATCH 44/64] add a space after , --- chaloBEST/mumbai/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index 6529d05..6836f3c 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -117,8 +117,8 @@ class Stop(models.Model): 'road': self.road.name, 'area': self.area.name, 'name_mr': self.name_mr, - 'routes': ",".join([r.route.alias for r in RouteDetail.objects.filter(stop=self)]), - 'alternative_names': ",".join([a.name for a in self.alt_names.all().filter(typ='common')]) + 'routes': ", ".join([r.route.alias for r in RouteDetail.objects.filter(stop=self)]), + 'alternative_names': ", ".join([a.name for a in self.alt_names.all().filter(typ='common')]) } def get_geojson(self, srid=4326): From 0c0017bb9805ba08a83bb4a8cee48e12302cf349 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 22:27:47 +0530 Subject: [PATCH 45/64] indicate whether stop has_point --- chaloBEST/static/css/editstops.css | 8 ++++++++ chaloBEST/static/js/editstops.js | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index f69bc7c..d011a9b 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -51,3 +51,11 @@ html, body { .clear { clear: both; } + +.has_point { + color: #222; +} + +.no_has_point { + color: #666; +} diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 87db24d..cfecb5b 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -94,6 +94,7 @@ function getStopsList(stops) { var props = v.properties; var geom = v.geometry; var $li = $('
      • ').addClass("stopItem").data("slug", props.slug).data("properties", props).data("geometry", geom).text(props.display_name).appendTo($ul); + isEmpty(geom) ? $li.addClass("no_has_point") : $li.addClass("has_point"); }); return $ul; } @@ -106,3 +107,7 @@ function getStopForm(stop) { // var $form = $('').apendTo($div); return $div; } + +function isEmpty(obj) { + return ($.toJSON(obj) == "{}") +} From c5cfaa24eb15fce9d08287b130a97259398255a7 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 22:29:02 +0530 Subject: [PATCH 46/64] use JSON.stringify --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index cfecb5b..81dba4d 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -109,5 +109,5 @@ function getStopForm(stop) { } function isEmpty(obj) { - return ($.toJSON(obj) == "{}") + return (JSON.stringify(obj) == "{}") } From f85895b7eca0a8554ebe1b93d1452942d37f849f Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 22:33:18 +0530 Subject: [PATCH 47/64] use keyup and not keydown for search input --- chaloBEST/static/css/editstops.css | 1 + chaloBEST/static/js/editstops.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index d011a9b..93ffa9e 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -48,6 +48,7 @@ html, body { .selectedStop { color: blue; } + .clear { clear: both; } diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 81dba4d..dab3616 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -60,7 +60,7 @@ $(function() { }); }); - $('.listSearch').keydown(function(e) { + $('.listSearch').keyup(function(e) { var val = $(this).val(); var name = $(this).attr("id").replace("Search", ""); var $list = $('#' + name + "List"); From f512c5c1633d85aef3086425a7cf04ffee0cef93 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 23:08:03 +0530 Subject: [PATCH 48/64] css --- chaloBEST/static/css/editstops.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index 93ffa9e..31ec303 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -1,5 +1,6 @@ html, body { width: 100%; + height: 100%; } #wrapper { @@ -7,6 +8,8 @@ html, body { } #listCol { + height: 100%; + overflow-x: scroll; width: 24%; float: left; } From 49ddea41be42649b3876b6b349f692c1c8933ed5 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 23:15:26 +0530 Subject: [PATCH 49/64] overflow x/y nonsense --- chaloBEST/static/css/editstops.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index 31ec303..61835cb 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -9,7 +9,8 @@ html, body { #listCol { height: 100%; - overflow-x: scroll; + overflow-y: scroll; + overflow-x: hidden; width: 24%; float: left; } @@ -49,7 +50,7 @@ html, body { } .selectedStop { - color: blue; + color: blue !important; } .clear { From 04eeb27096704ff1a93226659585968d6255bd07 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 23:16:54 +0530 Subject: [PATCH 50/64] whoever said css was easy.. --- chaloBEST/static/css/editstops.css | 1 + 1 file changed, 1 insertion(+) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index 61835cb..f8aca5f 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -5,6 +5,7 @@ html, body { #wrapper { width: 100%; + height: 100%; } #listCol { From 8f017f40a799e37e017f486b54a43cf076350d68 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 23:19:17 +0530 Subject: [PATCH 51/64] more css foo --- chaloBEST/static/css/editstops.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index f8aca5f..be086fe 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -9,7 +9,7 @@ html, body { } #listCol { - height: 100%; + height: 98%; overflow-y: scroll; overflow-x: hidden; width: 24%; @@ -65,3 +65,8 @@ html, body { .no_has_point { color: #666; } + +ul { + list-style-type: none; + padding-left: 4px; +} From 3c36a2730fafca680e4639853d3375e837557123 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 23:20:10 +0530 Subject: [PATCH 52/64] minor, placeholder for map --- chaloBEST/templates/editstops.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/templates/editstops.html b/chaloBEST/templates/editstops.html index 7c1f24f..0d6fc10 100644 --- a/chaloBEST/templates/editstops.html +++ b/chaloBEST/templates/editstops.html @@ -31,7 +31,7 @@
      • - + Map goes here
        From 7829f6828ba544e7e8bd406172f2228b8af20a0c Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 23:27:29 +0530 Subject: [PATCH 53/64] use jquery isEmptyObject --- chaloBEST/static/css/editstops.css | 4 +++- chaloBEST/static/js/editstops.js | 5 +---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index be086fe..6181a81 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -41,9 +41,11 @@ html, body { .tabButton { cursor: pointer; - width: 150px; + width: 50px; border: 1px solid #000; float: left; + text-align: center; + padding: 4px; } .selectedListItem .listItemText { diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index dab3616..872b65c 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -94,7 +94,7 @@ function getStopsList(stops) { var props = v.properties; var geom = v.geometry; var $li = $('
      • ').addClass("stopItem").data("slug", props.slug).data("properties", props).data("geometry", geom).text(props.display_name).appendTo($ul); - isEmpty(geom) ? $li.addClass("no_has_point") : $li.addClass("has_point"); + $.isEmptyObject(geom) ? $li.addClass("no_has_point") : $li.addClass("has_point"); }); return $ul; } @@ -108,6 +108,3 @@ function getStopForm(stop) { return $div; } -function isEmpty(obj) { - return (JSON.stringify(obj) == "{}") -} From 06f75c9f0b0b03edd730d0dc1b7b61223059018e Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 23:48:23 +0530 Subject: [PATCH 54/64] lets put a map in there --- chaloBEST/static/js/editstops.js | 256 +++++++++++++++++------------ chaloBEST/templates/editstops.html | 1 + 2 files changed, 154 insertions(+), 103 deletions(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 872b65c..dbfeb7f 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -1,110 +1,160 @@ -var API_BASE = "/1.0/" -$(function() { - $('.tabButton').click(function() { - if ($(this).hasClass("selected")) { - return; - } - var $that = $(this); - var name = $that.attr("data-name"); - var $listWrapper = $('#' + name); - if ($that.data("loaded")) { - $.noop(); //dont load data - } else { - $that.data("loaded", true); - var $list = $('#' + name + 'List'); - var url = API_BASE + name + "/"; - var $loadingLi = $('
        ').text("Loading...").appendTo($list); - $.getJSON(url, {}, function(items) { - $loadingLi.remove(); - $.each(items, function(i,v) { - var $li = $('
        ') - .addClass("listItem") - .appendTo($list); - var $txt = $('').addClass("listItemText").text(v).appendTo($li); - }); - }); - } - - $('.listWrapper').hide(); - $listWrapper.show(); - $('.selected').removeClass("selected"); - $that.addClass("selected"); - }); - - $('.list').click(function(e) { - var name = $(this).attr("id").replace("sList", ""); //FIXME: stick name in a data attr or so? - var $target = $(e.target).parent(); - if (!$target.hasClass('listItem')) { - return; - } - if ($target.data("loading")) { - return; - } - $('.selectedListItem').removeClass("selectedListItem"); - $target.addClass("selectedListItem"); - if ($target.data("hasList")) { - $target.find(".stopsList").toggle(); - return; - } - var url = API_BASE + name + "/" + $target.find(".listItemText").text(); - $target.data("loading", true); - var $loading = $('').addClass("loadingSpan").text("Loading...").appendTo($target); - $.getJSON(url, {}, function(obj) { - $loading.remove(); - var stopsGeojson = obj.stops; //TODO: render filtered geojson with known geometries on map - var stops = stopsGeojson.features; - var $stopsList = getStopsList(stops); - $target.append($stopsList); - $target.data("hasList", true); - $target.data("loading", false); - }); - }); - - $('.listSearch').keyup(function(e) { - var val = $(this).val(); - var name = $(this).attr("id").replace("Search", ""); - var $list = $('#' + name + "List"); - $list.find(".listItem").each(function() { - var $that = $(this); - var txt = $that.find(".listItemText").text(); - if (txt.indexOf(val) == -1) { - $that.hide(); - } else { - $that.show(); +var API_BASE = "/1.0/", + map; +(function() { + $(function() { + initMap(); + $('.tabButton').click(function() { + if ($(this).hasClass("selected")) { + return; } + var $that = $(this); + var name = $that.attr("data-name"); + var $listWrapper = $('#' + name); + if ($that.data("loaded")) { + $.noop(); //dont load data + } else { + $that.data("loaded", true); + var $list = $('#' + name + 'List'); + var url = API_BASE + name + "/"; + var $loadingLi = $('
        ').text("Loading...").appendTo($list); + $.getJSON(url, {}, function(items) { + $loadingLi.remove(); + $.each(items, function(i,v) { + var $li = $('
        ') + .addClass("listItem") + .appendTo($list); + var $txt = $('').addClass("listItemText").text(v).appendTo($li); + }); + }); + } + + $('.listWrapper').hide(); + $listWrapper.show(); + $('.selected').removeClass("selected"); + $that.addClass("selected"); }); + + $('.list').click(function(e) { + var name = $(this).attr("id").replace("sList", ""); //FIXME: stick name in a data attr or so? + var $target = $(e.target).parent(); + if (!$target.hasClass('listItem')) { + return; + } + if ($target.data("loading")) { + return; + } + $('.selectedListItem').removeClass("selectedListItem"); + $target.addClass("selectedListItem"); + if ($target.data("hasList")) { + $target.find(".stopsList").toggle(); + return; + } + var url = API_BASE + name + "/" + $target.find(".listItemText").text(); + $target.data("loading", true); + var $loading = $('').addClass("loadingSpan").text("Loading...").appendTo($target); + $.getJSON(url, {}, function(obj) { + $loading.remove(); + var stopsGeojson = obj.stops; + var stops = stopsGeojson.features; + var $stopsList = getStopsList(stops); + var stopsWithGeom = []; + $.each(stopsGeojson.stops, function(i,v) { + if (!$.isEmptyObject(v.geometry)) { + stopsWithGeom.push(v); + } + }); + stopsGeojson.stops = stopsWithGeom; + var currFeatures = jsonLayer.features; + jsonLayer.removeFeatures(currFeatures); + jsonLayer.addFeatures(geojson_format.read(stopsGeojson)); + var maxExtent = jsonLayer.getDataExtent(); + map.zoomToExtent(maxExtent); + $target.append($stopsList); + $target.data("hasList", true); + $target.data("loading", false); + }); + }); + + $('.listSearch').keyup(function(e) { + var val = $(this).val(); + var name = $(this).attr("id").replace("Search", ""); + var $list = $('#' + name + "List"); + $list.find(".listItem").each(function() { + var $that = $(this); + var txt = $that.find(".listItemText").text(); + if (txt.indexOf(val) == -1) { + $that.hide(); + } else { + $that.show(); + } + }); + }); + }); -}); + function getStopsList(stops) { + var $ul = $('
          ').addClass("stopsList").click(function(e) { + var $target = $(e.target); + if ($target.hasClass("selectedStop")) { + return; + } + $('.selectedStop').removeClass("selectedStop"); + $target.addClass("selectedStop"); + var props = $target.data("properties"); + var $form = getStopForm(props); + $('#formCol').empty(); + $('#formCol').append($form); + }); + $.each(stops, function(i,v) { + var props = v.properties; + var geom = v.geometry; + var $li = $('
        • ').addClass("stopItem").data("slug", props.slug).data("properties", props).data("geometry", geom).text(props.display_name).appendTo($ul); + $.isEmptyObject(geom) ? $li.addClass("no_has_point") : $li.addClass("has_point"); + }); + return $ul; + } -function getStopsList(stops) { - var $ul = $('
            ').addClass("stopsList").click(function(e) { - var $target = $(e.target); - if ($target.hasClass("selectedStop")) { - return; - } - $('.selectedStop').removeClass("selectedStop"); - $target.addClass("selectedStop"); - var props = $target.data("properties"); - var $form = getStopForm(props); - $('#formCol').empty(); - $('#formCol').append($form); - }); - $.each(stops, function(i,v) { - var props = v.properties; - var geom = v.geometry; - var $li = $('
          • ').addClass("stopItem").data("slug", props.slug).data("properties", props).data("geometry", geom).text(props.display_name).appendTo($ul); - $.isEmptyObject(geom) ? $li.addClass("no_has_point") : $li.addClass("has_point"); - }); - return $ul; -} + function getStopForm(stop) { + // console.log(stop); + var $div = $('
            '); + var $displayName = $('
            ').text(stop.display_name).appendTo($div); + var $routes = $('
            ').text("Routes: " + stop.routes).appendTo($div); + // var $form = $('').apendTo($div); + return $div; + } -function getStopForm(stop) { -// console.log(stop); - var $div = $('
            '); - var $displayName = $('
            ').text(stop.display_name).appendTo($div); - var $routes = $('
            ').text("Routes: " + stop.routes).appendTo($div); -// var $form = $('').apendTo($div); - return $div; -} + function initMap() { + var center = new OpenLayers.LonLat(72.855211097628413, 19.010775291486027); + map = new OpenLayers.Map("mapCol", {}); + var layers = []; + layers[0] = new OpenLayers.Layer.Google( + "Google Streets", // the default + {numZoomLevels: 20, isBaseLayer: true} + ); + geojson_format = new OpenLayers.Format.GeoJSON(); + //yes, jsonLayer is global. Yes, I know it's wrong. + jsonLayer = layers[1] = new OpenLayers.Layer.Vector({'geometryType': 'Point'}); + // map.addLayer(vector_layer); + map.addLayers(layers); + map.setCenter(center, 12); + mapControl = new OpenLayers.Control.SelectFeature(layers[1]); + zoomControl = new OpenLayers.Control.ZoomToMaxExtent(); + map.addControl(mapControl); + // map.addControl(zoomControl); + mapControl.activate(); + // zoomControl.activate(); + layers[1].events.on({ + 'featureselected': onFeatureSelect, + 'featureunselected': onFeatureUnselect + }); + } + + function onFeatureSelect(feature) { + console.log("selected", feature); + } + + function onFeatureUnselect(feature) { + console.log("unselected", feature); + } +})(); diff --git a/chaloBEST/templates/editstops.html b/chaloBEST/templates/editstops.html index 0d6fc10..cf84e44 100644 --- a/chaloBEST/templates/editstops.html +++ b/chaloBEST/templates/editstops.html @@ -3,6 +3,7 @@ {% block head %} + {% endblock %} From 34f519cd89fb448867cde0c2330d26f981609c35 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 23:53:43 +0530 Subject: [PATCH 55/64] urgh, google api key --- chaloBEST/templates/editstops.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chaloBEST/templates/editstops.html b/chaloBEST/templates/editstops.html index cf84e44..e5212b8 100644 --- a/chaloBEST/templates/editstops.html +++ b/chaloBEST/templates/editstops.html @@ -4,6 +4,8 @@ + + {% endblock %} From d441a5d622ff37123f076b97ac527e370f1c9366 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 23:55:54 +0530 Subject: [PATCH 56/64] give mapCol a height --- chaloBEST/static/css/editstops.css | 1 + chaloBEST/templates/editstops.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index 6181a81..c075d6f 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -18,6 +18,7 @@ html, body { #mapCol { width: 50%; + height: 95%; float: left; } diff --git a/chaloBEST/templates/editstops.html b/chaloBEST/templates/editstops.html index e5212b8..0583921 100644 --- a/chaloBEST/templates/editstops.html +++ b/chaloBEST/templates/editstops.html @@ -34,7 +34,7 @@
            - Map goes here +
            From d54d281f1750a05b662707b265e41e5f7309dc93 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 23:58:23 +0530 Subject: [PATCH 57/64] silliness, create the geojson object correctly filtering out stops with empty geoms --- chaloBEST/static/js/editstops.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index dbfeb7f..40db688 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -58,12 +58,12 @@ var API_BASE = "/1.0/", var stops = stopsGeojson.features; var $stopsList = getStopsList(stops); var stopsWithGeom = []; - $.each(stopsGeojson.stops, function(i,v) { + $.each(stops, function(i,v) { if (!$.isEmptyObject(v.geometry)) { stopsWithGeom.push(v); } }); - stopsGeojson.stops = stopsWithGeom; + stopsGeojson.features = stopsWithGeom; var currFeatures = jsonLayer.features; jsonLayer.removeFeatures(currFeatures); jsonLayer.addFeatures(geojson_format.read(stopsGeojson)); From fbde0b9f2f33c4cd6970aa1559e7b9ab3d2b3269 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 21 Feb 2012 00:46:07 +0530 Subject: [PATCH 58/64] try switching to OSM --- chaloBEST/static/js/editstops.js | 5 +++++ chaloBEST/templates/editstops.html | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 40db688..a29b934 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -127,10 +127,15 @@ var API_BASE = "/1.0/", var center = new OpenLayers.LonLat(72.855211097628413, 19.010775291486027); map = new OpenLayers.Map("mapCol", {}); var layers = []; + layers[0] = new OpenLayers.Layer.WMS("OpenStreetMaps", + "http://vmap0.tiles.osgeo.org/wms/vmap0", + {layers: 'basic'}); +/* layers[0] = new OpenLayers.Layer.Google( "Google Streets", // the default {numZoomLevels: 20, isBaseLayer: true} ); +*/ geojson_format = new OpenLayers.Format.GeoJSON(); //yes, jsonLayer is global. Yes, I know it's wrong. jsonLayer = layers[1] = new OpenLayers.Layer.Vector({'geometryType': 'Point'}); diff --git a/chaloBEST/templates/editstops.html b/chaloBEST/templates/editstops.html index 0583921..2d01515 100644 --- a/chaloBEST/templates/editstops.html +++ b/chaloBEST/templates/editstops.html @@ -4,7 +4,7 @@ - + {% endblock %} From 1441cb98a9f994925804c112c72d0df9b1742bce Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 21 Feb 2012 00:48:09 +0530 Subject: [PATCH 59/64] fiddle with OSM layer settings --- chaloBEST/static/js/editstops.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index a29b934..a37e7c5 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -127,9 +127,7 @@ var API_BASE = "/1.0/", var center = new OpenLayers.LonLat(72.855211097628413, 19.010775291486027); map = new OpenLayers.Map("mapCol", {}); var layers = []; - layers[0] = new OpenLayers.Layer.WMS("OpenStreetMaps", - "http://vmap0.tiles.osgeo.org/wms/vmap0", - {layers: 'basic'}); + layers[0] = new OpenLayers.Layer.OSM(); /* layers[0] = new OpenLayers.Layer.Google( "Google Streets", // the default From 5dfad354ff2c76f3085a9f1a1b38dd5b58cd98e5 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 21 Feb 2012 00:49:28 +0530 Subject: [PATCH 60/64] switch back to google maps until i understand projections --- chaloBEST/static/js/editstops.js | 6 +++--- chaloBEST/templates/editstops.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index a37e7c5..15b0408 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -127,13 +127,13 @@ var API_BASE = "/1.0/", var center = new OpenLayers.LonLat(72.855211097628413, 19.010775291486027); map = new OpenLayers.Map("mapCol", {}); var layers = []; - layers[0] = new OpenLayers.Layer.OSM(); -/* +// layers[0] = new OpenLayers.Layer.OSM(); + layers[0] = new OpenLayers.Layer.Google( "Google Streets", // the default {numZoomLevels: 20, isBaseLayer: true} ); -*/ + geojson_format = new OpenLayers.Format.GeoJSON(); //yes, jsonLayer is global. Yes, I know it's wrong. jsonLayer = layers[1] = new OpenLayers.Layer.Vector({'geometryType': 'Point'}); diff --git a/chaloBEST/templates/editstops.html b/chaloBEST/templates/editstops.html index 2d01515..0583921 100644 --- a/chaloBEST/templates/editstops.html +++ b/chaloBEST/templates/editstops.html @@ -4,7 +4,7 @@ - + {% endblock %} From c918ef2cfcb840b4a2a6f6615db9300cf81a1786 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 21 Feb 2012 15:27:41 +0530 Subject: [PATCH 61/64] highlight stop name when you hover over location on map --- chaloBEST/static/css/editstops.css | 5 +++ chaloBEST/static/js/editstops.js | 51 ++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css index c075d6f..c388a21 100644 --- a/chaloBEST/static/css/editstops.css +++ b/chaloBEST/static/css/editstops.css @@ -73,3 +73,8 @@ ul { list-style-type: none; padding-left: 4px; } + +.highlightedStop { + background-color: #FFFF00; +} + diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 15b0408..2e53b59 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -93,22 +93,36 @@ var API_BASE = "/1.0/", }); function getStopsList(stops) { - var $ul = $('
              ').addClass("stopsList").click(function(e) { - var $target = $(e.target); - if ($target.hasClass("selectedStop")) { - return; - } - $('.selectedStop').removeClass("selectedStop"); - $target.addClass("selectedStop"); - var props = $target.data("properties"); - var $form = getStopForm(props); - $('#formCol').empty(); - $('#formCol').append($form); - }); + var $ul = $('
                ') + .addClass("stopsList") + .click(function(e) { + var $target = $(e.target); + if ($target.hasClass("selectedStop")) { + return; + } + $('.selectedStop').removeClass("selectedStop"); + $target.addClass("selectedStop"); + var props = $target.data("properties"); + var $form = getStopForm(props); + $('#formCol').empty(); + $('#formCol').append($form); + }); + $.each(stops, function(i,v) { var props = v.properties; var geom = v.geometry; - var $li = $('
              • ').addClass("stopItem").data("slug", props.slug).data("properties", props).data("geometry", geom).text(props.display_name).appendTo($ul); + var $li = $('
              • ') + .addClass("stopItem") + .data("slug", props.slug) + .addClass(props.slug) //FIXME: please dont set data AND addClass AND include slug in properties. + .data("properties", props).data("geometry", geom) + .text(props.display_name) + .hover(function() { + //TODO: when hover over a stop name in list, it should set some styleMap stuff on the map to colour the moused-over location. + }, function() { + + }); + .appendTo($ul); $.isEmptyObject(geom) ? $li.addClass("no_has_point") : $li.addClass("has_point"); }); return $ul; @@ -141,7 +155,7 @@ var API_BASE = "/1.0/", map.addLayers(layers); map.setCenter(center, 12); - mapControl = new OpenLayers.Control.SelectFeature(layers[1]); + mapControl = new OpenLayers.Control.SelectFeature(layers[1], {hover: true}); zoomControl = new OpenLayers.Control.ZoomToMaxExtent(); map.addControl(mapControl); // map.addControl(zoomControl); @@ -154,10 +168,15 @@ var API_BASE = "/1.0/", } function onFeatureSelect(feature) { - console.log("selected", feature); + var slug = feature.attributes.slug; + var matchedStops = $('.' + slug); + matchedStops.addClass('highlightedStop'); } function onFeatureUnselect(feature) { - console.log("unselected", feature); + var slug = feature.attributes.slug; + var matchedStops = $('.' + slug); + matchedStops.removeClass('highlightedStop'); } + })(); From 7c4f092c7bf5cfd86ecdd0b81bdb40dab9060376 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 21 Feb 2012 15:33:32 +0530 Subject: [PATCH 62/64] debugging select hover control --- chaloBEST/static/js/editstops.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 2e53b59..6de2739 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -169,12 +169,14 @@ var API_BASE = "/1.0/", function onFeatureSelect(feature) { var slug = feature.attributes.slug; + alert("selected " + slug); var matchedStops = $('.' + slug); matchedStops.addClass('highlightedStop'); } function onFeatureUnselect(feature) { var slug = feature.attributes.slug; + alert("unselected " + slug); var matchedStops = $('.' + slug); matchedStops.removeClass('highlightedStop'); } From afecacdc5eee2620a5bbe525068eae817e6befd5 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 21 Feb 2012 15:34:35 +0530 Subject: [PATCH 63/64] ups, extra ; --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 6de2739..7a9db2e 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -121,7 +121,7 @@ var API_BASE = "/1.0/", //TODO: when hover over a stop name in list, it should set some styleMap stuff on the map to colour the moused-over location. }, function() { - }); + }) .appendTo($ul); $.isEmptyObject(geom) ? $li.addClass("no_has_point") : $li.addClass("has_point"); }); From dd5801d7f64ac3dcdbf27f7e05032946a9ff567d Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 21 Feb 2012 15:38:58 +0530 Subject: [PATCH 64/64] debugging selectFeature --- chaloBEST/static/js/editstops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js index 7a9db2e..bfe098c 100644 --- a/chaloBEST/static/js/editstops.js +++ b/chaloBEST/static/js/editstops.js @@ -155,7 +155,7 @@ var API_BASE = "/1.0/", map.addLayers(layers); map.setCenter(center, 12); - mapControl = new OpenLayers.Control.SelectFeature(layers[1], {hover: true}); + mapControl = new OpenLayers.Control.SelectFeature(layers[1]); zoomControl = new OpenLayers.Control.ZoomToMaxExtent(); map.addControl(mapControl); // map.addControl(zoomControl);