Projet

Général

Profil

0001-backoffice-display-demands-with-coloured-markers-on-.patch

Serghei Mihai, 11 avril 2017 10:29

Télécharger (4,52 ko)

Voir les différences:

Subject: [PATCH] backoffice: display demands with coloured markers on map view
 (#15533)

 tests/test_backoffice_pages.py      |  2 ++
 wcs/backoffice/management.py        |  6 ++++++
 wcs/qommon/static/css/dc2/admin.css | 14 ++++++++++++++
 wcs/qommon/static/js/qommon.map.js  | 23 +++++++++--------------
 4 files changed, 31 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
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
939 939
	stroke-width: 2px;
940 940
}
941 941

  
942
/* Styling for Leaflet's markers */
943

  
944
div.leaflet-div-icon span {
945
    width: 2.3rem;
946
    height: 2.3rem;
947
    display: block;
948
    left: -1rem;
949
    top: -1rem;
950
    position: relative;
951
    border-radius: 5rem 5rem 0.8rem;
952
    transform: rotate(45deg);
953
    border: 1px solid #aaa;
954
}
955

  
942 956
.foldable {
943 957
	cursor: pointer;
944 958
}
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
-