Commit cfe66135 authored by Daniel STAN's avatar Daniel STAN

[wifimap] édition borne (server side)

parent 7d8c1062
import models
from django.contrib import admin
admin.site.register(models.VirtAP)
from django.db import models
# Create your models here.
class VirtAP(models.Model):
u"""Une borne virtuelle"""
class Meta:
verbose_name = "Borne WiFi virtuelle"
verbose_name_plural = "Bornes WiFi virtuelles"
#ordering = ['batiment', 'etage']
host = models.CharField(max_length=255)
location = models.CharField(max_length=255)
lat = models.FloatField()
lon = models.FloatField()
def xmlRepr(self, doc):
borne = doc.createElement('borne')
borne.setAttribute('virtual', 'virtual')
def addTextNode(label, value):
node = doc.createElement(label)
node.appendChild(doc.createTextNode(unicode(value)))
borne.appendChild(node)
addTextNode('hostname', self.host)
addTextNode('lon', self.lon)
addTextNode('lat', self.lat)
addTextNode('location', self.location)
addTextNode('client_count', '0')
return borne
......@@ -24,6 +24,8 @@ import django.shortcuts
from django.template import RequestContext
from django.http import HttpResponse
from models import VirtAP
#from django.contrib.auth.decorators import login_required, permission_required
......@@ -31,6 +33,8 @@ def get_xml(request):
import parse_xml
public = not request.user.groups.filter(name='crans_nounou')
doc = parse_xml.global_status(public)
for ap in VirtAP.objects.all():
doc.documentElement.appendChild(ap.xmlRepr(doc))
return HttpResponse(doc.toxml('utf-8'),content_type='text/xml; coding=utf-8')
def index(request):
......
......@@ -102,7 +102,7 @@ LOGIN_URL = "/login"
LOGIN_REDIRECT_URL = "/"
AUTHENTICATION_BACKENDS = (
# 'intranet.login.LDAPUserBackend',
'intranet.login.LDAPUserBackend',
'django.contrib.auth.backends.ModelBackend',
)
......
......@@ -106,6 +106,10 @@
font-weight: normal;
}
.borne .coords.modified {
color: red;
}
/* sorting */
.order {
......
......@@ -15,7 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var debug = document.location.hostname != 'intranet2.crans.org';
//var debug = document.location.hostname != 'intranet2.crans.org';
var debug = false;
var WifiMap;
......@@ -27,6 +28,7 @@ WifiMap = {
'init': function() {
var that = this;
this.map = new OpenLayers.Map({'div': 'map','controls':[]});
this.moved = null;
// Note: Min lon: 2.325175
// : Min lat: 48.786424
// : Min lon: 2.33118
......@@ -91,10 +93,17 @@ WifiMap = {
}
});
WifiMap.map.events.register("click",map,function (e) {
var pos = WifiMap.map.getLonLatFromViewPortPx(WifiMap.map.events.getMousePosition(e));
console.debug(pos.lon, pos.lat);
});
this.map.events.register("click",this,function (e) {
var pos = this.map.getLonLatFromViewPortPx(this.map.events.getMousePosition(e));
var gps = pos.clone().transform(this.projections.map,this.projections.gps);
$('x').value = gps.lon;
$('y').value = gps.lat;
if( this.moved) {
this.moved.moveTo(gps);
this.moved = false;
}
});
//Event select: tout déselectionner
this.map.events.register('click', undefined, this.highlight.bind(this,undefined));
......@@ -136,15 +145,19 @@ WifiMap = {
borne.wifiMap = this;
//Noms des fichiers images suivant le mode de la borne
var files = {'on': 'marker-green', 'ens': 'marker-blue', 'off': 'marker'};
var files = {'on': 'marker-green', 'ens': 'marker-blue', 'off': 'marker',
'autres': 'marker-gold'};
borne.update_info = function(xml) {
//Clean up last marker
var old = this.marker;
this.xml = xml;
var highlighted = this.highlighted;
var type = "on";
if( xml.hasAttribute('offline'))
type = "off";
if( xml.hasAttribute('virtual'))
type = "autres";
this.layer = that.bornesLayers[type]; //On définit layer même
//S'il n'est pas sûr qu'on placera la borne sur la carte
if(old) {
......@@ -153,20 +166,22 @@ WifiMap = {
old.destroy(); this.marker = null;
}
//New coords !
try {
var x = parseFloat(xml.getElementsByTagName('lon')[0].firstChild.nodeValue);
var y = parseFloat(xml.getElementsByTagName('lat')[0].firstChild.nodeValue);
}
catch(e) {
this.mapPosition = undefined;
//Mettre à jour les infos tabulaires de la borne avant de quitter
this.update_borne_infos(xml);
return;
}
//New coords ?
if( !this.mapPosition || !this.mapPosition.modified) {
try {
var x = parseFloat(xml.getElementsByTagName('lon')[0].firstChild.nodeValue);
var y = parseFloat(xml.getElementsByTagName('lat')[0].firstChild.nodeValue);
}
catch(e) {
this.mapPosition = undefined;
//Mettre à jour les infos tabulaires de la borne avant de quitter
this.update_borne_infos(xml);
return;
}
//mapPosition sera stockée dans les coordonnées de la map
this.mapPosition = new OpenLayers.LonLat(x,y);
//mapPosition sera stockée dans les coordonnées de la map
this.mapPosition = new OpenLayers.LonLat(x,y);
}
this.mapPosition.transform(that.projections.gps,that.projections.map);
......@@ -184,7 +199,7 @@ WifiMap = {
var url = '/static/OpenLayers/img/' + (files[type]) + '.png';
var icon = new OpenLayers.Icon(url,size,offset);
this.marker = new OpenLayers.Marker(this.mapPosition,icon);
this.marker = new OpenLayers.Marker(this.mapPosition, icon);
this.layer.addMarker(this.marker);
this.update_marker_size();
......@@ -222,6 +237,12 @@ WifiMap = {
this.update_marker_size();
};
borne.moveTo = function (gps) {
this.mapPosition = gps;
this.mapPosition.modified = true;
this.update_info(this.xml);
};
//Met à jour la taille du markeur (notamment après un zoom)
borne.update_marker_size = function() {
if( ! this.marker ) return; //Nothing to do
......@@ -310,7 +331,7 @@ WifiMap = {
//Si position sur la carte, on active le bouton pour zoomer dessus
if(this.mapPosition) {
panTo = getElementsByClassName(html,'pan_to')[0]
panTo = getElementsByClassName(html,'pan_to')[0];
panTo.addEventListener('click',
(function (event) {
if(this.mapPosition) {
......@@ -322,6 +343,22 @@ WifiMap = {
panTo.className = panTo.className.replace(/ *template ?/,'');
}
setCoord = getElementsByClassName(html,'setCoord')[0];
setCoord.addEventListener('click',
(function (event) {
this.wifiMap.moved = this;
event.preventDefault();
}).bind(this));
coords = getElementsByClassName(html, 'coords')[0];
if( this.mapPosition) {
var gps = this.mapPosition.clone();
gps.transform(that.projections.map, that.projections.gps);
setInnerText(coords, gps.lon + ' ' + gps.lat)
this.mapPosition.modified && coords.setAttribute('class', 'coords modified');
}
else
setInnerText(coords, 'N/A');
//On fixe la nouvelle bar d'info
if(this.html_list)
this.html_list.parentNode.replaceChild(html,this.html_list);
......
......@@ -26,6 +26,8 @@ Dernière mise à jour il y a <label id="last_update"> </label>
<span class="uptime template">Uptime: <span class="content"></span></span>
<ul>
<li class="comment template">Liste commentaire</li>
<li class="coord">Lon/Lat <span class="coords">N/A</span>
<a href="#" class="setCoord">Placer</a></li>
<li class="prise template">Prise: <span class="content"></span></li>
</ul>
<div class="network template">
......@@ -42,4 +44,6 @@ Dernière mise à jour il y a <label id="last_update"> </label>
</div>
<div id="map">
</div>
<input type="text" id="x">
<input type="text" id="y">
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment