Projet

Général

Profil

0001-backoffice-display-status-coloured-markers-on-maps-1.patch

Serghei Mihai, 11 avril 2017 13:51

Télécharger (4,92 ko)

Voir les différences:

Subject: [PATCH] backoffice: display status-coloured markers on maps (#15533)

 tests/test_backoffice_pages.py      |  4 ++++
 wcs/backoffice/management.py        |  6 ++++++
 wcs/qommon/static/css/dc2/admin.css | 14 ++++++++++++++
 wcs/qommon/static/js/qommon.map.js  | 23 +++++++++--------------
 4 files changed, 33 insertions(+), 14 deletions(-)
tests/test_backoffice_pages.py
928 928
    resp = app.get('/backoffice/management/form-title/geojson')
929 929
    assert len(resp.json['features']) == 1
930 930
    assert resp.json['features'][0]['geometry']['coordinates'] == [2.32, 48.83]
931
    assert 'status_colour' in resp.json['features'][0]['properties']
932
    assert resp.json['features'][0]['properties']['status_colour'] == '#66FF00'
931 933

  
932 934
    resp = app.get('/backoffice/management/form-title/geojson?filter=pending&filter-status=on')
933 935
    assert len(resp.json['features']) == 1
......
2257 2259
    resp = app.get('/backoffice/management/geojson')
2258 2260
    assert len(resp.json['features']) == 17
2259 2261
    assert resp.json['features'][0]['geometry']['coordinates'] == [2.32, 48.83]
2262
    for feature in resp.json['features']:
2263
        assert feature['properties']['status_colour'] == '#66FF00'
2260 2264

  
2261 2265
    resp = app.get('/backoffice/management/geojson?q=aa')
2262 2266
    assert len(resp.json['features']) == 5
wcs/backoffice/management.py
68 68
        if not formdata.geolocations or not geoloc_key in formdata.geolocations:
69 69
            continue
70 70
        coords = formdata.geolocations[geoloc_key]
71
        try:
72
            status_colour = formdata.get_status().colour
73
        except AttributeError:
74
            status_colour = 'ffffff'
75

  
71 76
        feature = {
72 77
            'type': 'Feature',
73 78
            'properties': {
74 79
                'name':  formdata.get_display_name(),
75 80
                'url': formdata.get_url(backoffice=True),
81
                'status_colour': '#%s' % status_colour
76 82
            },
77 83
            'geometry': {
78 84
                'type': 'Point',
wcs/qommon/static/css/dc2/admin.css
1561 1561
	height: 70vh;
1562 1562
	margin-bottom: 1em;
1563 1563
}
1564

  
1565
/* Styling for Leaflet's markers */
1566

  
1567
div.leaflet-div-icon span {
1568
	width: 2.3rem;
1569
	height: 2.3rem;
1570
	display: block;
1571
	left: -1rem;
1572
	top: -1rem;
1573
	position: relative;
1574
	border-radius: 11rem 6rem 0.8rem;
1575
	transform: scale(1, 1.3) rotate(45deg);
1576
	border: 1px solid #aaa;
1577
}
wcs/qommon/static/js/qommon.map.js
80 80
       $map_widget.parent().parent().find('label').addClass('activity')
81 81
       map.locate({timeout: 10000, maximumAge: 300000, enableHighAccuracy: false});
82 82
     }
83
     if ($(this).data('geojson-url')) {
84
       $.getJSON($(this).data('geojson-url'), function(data) {
85
         var geo_json = L.geoJson(data, {
86
           onEachFeature: function(feature, layer) {
87
             layer.on('click', function() {
88
               window.location = feature.properties.url;
89
               return false;
90
             });
91
           }
92
         });
93
         map.fitBounds(geo_json.getBounds());
94
         geo_json.addTo(map);
95
       });
96
     }
97 83

  
98 84
    $(document).on('backoffice-filter-change', function(event, listing_settings) {
99 85
      $('.qommon-map').each(function() {
......
110 96
                 window.location = feature.properties.url;
111 97
                 return false;
112 98
               });
99
             },
100
             pointToLayer: function (feature, latlng) {
101
                 var markerStyles = "background-color: "+feature.properties.status_colour+";";
102
                 marker = L.divIcon({iconAnchor: [0, 24],
103
                                     html: '<span style="' + markerStyles + '" />'});
104
                 return L.marker(latlng, {icon: marker});
113 105
             }
114 106
           });
115 107
           map.fitBounds(geo_json.getBounds());
......
117 109
         });
118 110
      });
119 111
    });
112
    if ($(this).data('geojson-url')) {
113
        $(document).trigger('backoffice-filter-change', $('form#listing-settings').serialize());
114
    }
120 115
  });
121 116
});
122
-