Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Personalviews #29

Merged
merged 6 commits into from
Aug 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ga_bigboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
admin.site.register(models.SharedOverlay)
admin.site.register(models.Overlay)

admin.site.register(models.PersonalView, admin_class=admin.OSMGeoAdmin)

22 changes: 22 additions & 0 deletions ga_bigboard/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,27 @@ def obj_create(self, bundle, request=None, **kwargs):
return super(ChatResource, self).obj_create(bundle, request, user=request.user)


class PersonalViewResource(GeoResource):
room = f.ForeignKey(to=RoomResource, attribute='room')
user = f.ForeignKey(to=UserResource, attribute='user')

class Meta:
authentication = ApiKeyAuthentication()
authorization = Authorization()
queryset = models.PersonalView.objects.all()
resource_name = 'personal_views'
allowed_methods = ('get','post','put','delete')
filtering = {
'room' : ALL_WITH_RELATIONS,
'user' : ALL_WITH_RELATIONS,
'when' : ALL,
'id' : ALL
}

def obj_create(self, bundle, request=None, **kwargs):
return super(PersonalViewResource, self).obj_create(bundle, request, user=request.user)


api_v4 = Api('v4')
api_v4.register(UserResource())
api_v4.register(RoleResource())
Expand All @@ -211,3 +232,4 @@ def obj_create(self, bundle, request=None, **kwargs):
api_v4.register(RoomResource())
api_v4.register(ParticipantResource())
api_v4.register(ChatResource())
api_v4.register(PersonalViewResource())
33 changes: 33 additions & 0 deletions ga_bigboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,36 @@ def __unicode__(self):

class Meta:
ordering = ['when']


class PersonalView(m.Model):
"""An entry for list of interesting views stored per user per room.
"""
room = m.ForeignKey(Room, db_index=True)

#: the user to whom this item belongs
user = m.ForeignKey(User)

#: name of the location
name = m.CharField(max_length=255, blank=False)

#: optional description of the location
description = m.TextField(blank=True)

#: center of map at the desired view
where = m.PointField(srid=4326, null=False);

#: The zoom level of this view
zoom_level = m.IntegerField(default=5, null=False)

#: when this view was stored
when = m.DateTimeField(auto_now_add=True, db_index=True)

def __unicode__(self):
return self.room.name + '.' + self.user.username + ' -> ' + self.name

objects = m.GeoManager()

class Meta:
ordering = ['when']

67 changes: 67 additions & 0 deletions ga_bigboard/static/ga_bigboard/bigboard_mainloop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function BigBoard(args) {
var chats = [];
var roles;
var annotations;
var personal_views;
var last_chat_update = 0;

var started = false; // Whether this bigboard instance has been started
Expand All @@ -17,6 +18,7 @@ function BigBoard(args) {
var received_roles = false;
var received_room = false;
var received_shared_overlays = false;
var received_personal_views = false;


var my_username = args.user_name; // DEPRECATED
Expand All @@ -41,6 +43,7 @@ function BigBoard(args) {
var bb_api_join = either(args, 'bb_api_joins', '../join/');
var bb_api_leave = either(args, 'bb_api_leave', '../leave/');
var bb_api_heartbeat = either(args, 'bb_api_heartbeat', '../heartbeat/');
var bb_api_personalviews = either(args, 'bb_api_personalviews', '../api/v4/personal_views/');

var location = [0,0];

Expand Down Expand Up @@ -209,6 +212,15 @@ function BigBoard(args) {
//either(args, 'receivedSharedOverlays', noop)(shared_overlays, textStatus, jqXHR);
received_shared_overlays = true;
}

function receivedPersonalViews(data, textStatus, jqXHR) {
personal_views = data.objects;
if(debug) { console.log("latest version of personal views received"); }

runCallbacks('receivedPersonalViews', personal_views, textStatus, jqXHR);

received_personal_views = true;
}

function refreshAnnotations() {
received_annotations = false;
Expand Down Expand Up @@ -310,6 +322,18 @@ function BigBoard(args) {
beforeSend : function(xhr) { xhr.setRequestHeader('Authorization', hash)}
});
}

// Refreshes the personal views list
function refreshPersonalViews() {
received_personal_views = false;
$.ajax({
url : bb_api_personalviews,
data : { user__username: user_name, room : room.id, limit : 0, format : 'json', username : user_name, api_key : api_key },
accepts : 'application/json',
success : receivedPersonalViews,
error : errorHandler(either(args, 'refreshPersonalViewsError', noop))
});
}

function receivedLoginCredentials(data, textStatus, jqXHR) {
my_userid = data.user_id;
Expand Down Expand Up @@ -554,6 +578,10 @@ function BigBoard(args) {
z:zoom
}, errorHandler(noop));
}

function getRoomCenter() {
return $.extend({},room.center,{zoom_level:room.zoom_level});
}

var once = true;
function mainLoop() {
Expand All @@ -567,6 +595,7 @@ function BigBoard(args) {
refreshParticipants();
refreshSharedOverlays();
refreshChats();
refreshPersonalViews();
once = false;
}
}
Expand All @@ -578,6 +607,7 @@ function BigBoard(args) {
if(received_roles) { refreshRoles(); }
if(received_shared_overlays) { refreshSharedOverlays(); }
if(received_room) { refreshRoom(); }
if(received_personal_views) { refreshPersonalViews(); }
}
}

Expand All @@ -602,6 +632,40 @@ function BigBoard(args) {
function isStarted() {
return started;
}

function addPersonalView(name, description, lon, lat, zoom) {
// Add a personal view to the server

var data = {
name: name,
description: description,
user : my_user,
room : room.resource_uri,
zoom_level: zoom,
where : { coordinates: [lon, lat], type:'Point' }
};

$.ajax({
url : bb_api_personalviews + '?username=' + user_name + "&api_key=" + api_key,
type : 'POST',
data: JSON.stringify(data),
cache: false,
contentType: 'application/json',
processData: false,
error: errorHandler(noop),
success: function(data) { console.log('success'); console.log(data); }
});
}

function deletePersonalView(view) {
// Remove the personal view from the server

$.ajax({
url: view.resource_uri + "?username=" + user_name + "&api_key=" + api_key,
type: 'DELETE',
error : errorHandler(either(args, 'failedDeleteAnnotation', noop))
});
}

return {
room : room_name,
Expand All @@ -622,6 +686,9 @@ function BigBoard(args) {
persistAnnotation: persistAnnotation,
deleteAnnotation: deleteAnnotation,
setRoomCenter: setRoomCenter,
getRoomCenter: getRoomCenter,
addPersonalView: addPersonalView,
deletePersonalView: deletePersonalView,

registerCallback: registerCallback
};
Expand Down
100 changes: 96 additions & 4 deletions ga_bigboard/static/ga_bigboard/bigboard_mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $(document).ready(function() {
var geojson = new OpenLayers.Format.GeoJSON();
var roles = null;
var overlays = {};
var personalViews = {};

function init() { if(!initted) {
initted = true;
Expand Down Expand Up @@ -316,7 +317,80 @@ $(document).ready(function() {
map.setLayerIndex(annotationLayer, 9999);
map.setLayerIndex(participantsLayer, 10000);
}
]
],

// adds the personal views to the list
receivedPersonalViews: [
function(data) {
iter(data, function(obj) {

// Check if personal view has already been added
if(!personalViews.hasOwnProperty(obj.resource_uri)) {
personalViews[obj.resource_uri] = obj;

$('<li/>', {
id: 'views_item_'+obj.id
}).appendTo('#personal_views_list');
$('<div/>', {
id: 'views_item_top_'+obj.id,
html: "\
<span class='views-list-operations'>\
<span id='views_item_go_icon_"+obj.id+"' data-action='jump_to_personal_view' data-view-index='"+obj.resource_uri+"' class='views-item-go-icon'>Go</span>\
<span id='views_item_remove_icon_"+obj.id+"' data-action='remove_personal_view' data-view-index='"+obj.resource_uri+"' class='views-item-go-icon'>x</span>\
</span>\
"+obj.name+"<br />"
}).appendTo('#views_item_'+obj.id);
$('<div/>', {
id: 'views_item_extra_'+obj.id,
class: 'views-item-extra'
}).appendTo('#views_item_'+obj.id);
$('<span/>', {
id: 'views_item_toggle_description_'+obj.id,
class: 'views-item-toggle-description',
html: 'Show Description'
}).appendTo('#views_item_extra_'+obj.id);
$('<div/>', {
id: 'views_item_description_'+obj.id,
style: 'display: none;',
html: obj.description
}).appendTo('#views_item_extra_'+obj.id);

// view description toggle
$('#views_item_toggle_description_'+obj.id).click(function() {
if( $('#views_item_description_'+obj.id).css('display') == 'none' ) {
$('#views_item_description_'+obj.id).show(150);
$('#views_item_toggle_description_'+obj.id).html('Hide Description');
} else {
$('#views_item_description_'+obj.id).hide(150);
$('#views_item_toggle_description_'+obj.id).html('Show Description');
}
});

// sets map center to chosen personal view
$('#views_item_go_icon_'+obj.id).click(function(e) {
var uri = $(this).data('view-index');
var center = personalViews[uri];

var newCenter = new OpenLayers.LonLat(center.where.coordinates[0], center.where.coordinates[1])
newCenter.transform(gm, sm);
map.setCenter(newCenter, center.zoom_level);
});

// removes the chosen personal view
$('#views_item_remove_icon_'+obj.id).click(function(e) {
// delete on server and remove from list
var uri = $(this).data('view-index');
var view = personalViews[uri];

$('#views_item_'+view.id).remove();

bb.deletePersonalView( view );
});
}
});

}
] // end receivedPersonalViews
}
});

Expand Down Expand Up @@ -367,9 +441,13 @@ $(document).ready(function() {
});
}


// chat log
var rest_of_height = contentHeight-360;
$("#chat_log").height(rest_of_height);

// personal views
rest_of_height = contentHeight-305;
$("#personal_views_list").height(rest_of_height);

// Map zoom
$("#plus").click(function() { map.zoomIn(); });
Expand Down Expand Up @@ -417,7 +495,7 @@ $(document).ready(function() {
};
controls.select_control.onUnselect = function(annotation) {
iter(annotations, function(ann) {
ann.selected = ann.selected && ann.attributes.resource_uri !== annotations.attributes.resource_uri;
ann.selected = ann.selected && ann.attributes.resource_uri !== annotation.attributes.resource_uri;
});
};

Expand All @@ -431,6 +509,20 @@ $(document).ready(function() {
// );
// return false;
//});

// add teh current center/zoom to personal views
$('#bb_map_add_personal_view_form').submit(function(e) {
var name = $('#bb_map_add_personal_view_name').val();
var description = $('#bb_map_add_personal_view_description').val();;

var c = map.getCenter();
c.transform(sm, gm);
bb.addPersonalView(name, description, c.lon, c.lat, map.getZoom());

$('#bb_map_add_personal_view_name').val('');
$('#bb_map_add_personal_view_description').val('');
return false;
});

$("#center_all_here").submit(function() {
var c = map.getCenter();
Expand Down Expand Up @@ -483,7 +575,7 @@ $(document).ready(function() {
info_container.append('<li><img src="' + ann.attributes.image + '"/></li>');
break;
default:
info_container.append('<li>' + v + '<li>');
info_container.append('<li>' + v + '</li>');
break;
}
}
Expand Down
Loading