[bknr-cvs] hans changed trunk/projects/bos/

BKNR Commits bknr at bknr.net
Sun Nov 30 10:29:41 UTC 2008


Revision: 4102
Author: hans
URL: http://bknr.net/trac/changeset/4102

Improve map handling.
Add infrastructure for sponsor queries.

U   trunk/projects/bos/m2/m2.lisp
U   trunk/projects/bos/m2/packages.lisp
U   trunk/projects/bos/payment-website/static/poi-ms.css
U   trunk/projects/bos/payment-website/static/poi-ms.js
U   trunk/projects/bos/web/packages.lisp
U   trunk/projects/bos/web/sponsor-handlers.lisp
U   trunk/projects/bos/web/webserver.lisp

Modified: trunk/projects/bos/m2/m2.lisp
===================================================================
--- trunk/projects/bos/m2/m2.lisp	2008-11-29 21:55:51 UTC (rev 4101)
+++ trunk/projects/bos/m2/m2.lisp	2008-11-30 10:29:40 UTC (rev 4102)
@@ -712,8 +712,6 @@
   (json:encode-object-elements
    "name" (user-full-name sponsor)
    "country" (or (sponsor-country sponsor) "sponsor-country-unknown")
-   "sqmCount" (reduce #'+ (mapcar (alexandria:compose #'length #'contract-m2s) (sponsor-contracts sponsor))
-                      :initial-value 0)
    "infoText" (sponsor-info-text sponsor))
   (unless (user-full-name sponsor)
     (json:encode-object-element "anonymous" t))
@@ -723,10 +721,10 @@
         (json:with-object ()
           (json-encode contract))))))
 
-(defun last-sponsors-as-json ()
-  "Render the last sponsors as JSON"
+(defun sponsors-as-json (sponsors)
+  "Render the SPONSORS as JSON"
   (json:with-array ()
-    (dolist (sponsor (mapcar #'contract-sponsor (last-paid-contracts)))
+    (dolist (sponsor sponsors)
       (json:with-object ()
         (json-encode sponsor)))))
 

Modified: trunk/projects/bos/m2/packages.lisp
===================================================================
--- trunk/projects/bos/m2/packages.lisp	2008-11-29 21:55:51 UTC (rev 4101)
+++ trunk/projects/bos/m2/packages.lisp	2008-11-30 10:29:40 UTC (rev 4102)
@@ -171,7 +171,7 @@
            #:contract-stats-for-country
            #:last-paid-contracts
            #:do-sponsor-countries
-           #:last-sponsors-as-json
+           #:sponsors-as-json
 
            #:make-m2-javascript
            #:recolorize-contracts

Modified: trunk/projects/bos/payment-website/static/poi-ms.css
===================================================================
--- trunk/projects/bos/payment-website/static/poi-ms.css	2008-11-29 21:55:51 UTC (rev 4101)
+++ trunk/projects/bos/payment-website/static/poi-ms.css	2008-11-30 10:29:40 UTC (rev 4102)
@@ -23,10 +23,14 @@
     font-size: 180%;
 }
 
+.map img {
+     vertical-align: bottom; /* align images without space for character descenders */
+}
+
 .map {
     position: relative;
 }
 
-.map .icon {
+.map .icon, .map .contract {
     position: absolute;
 }

Modified: trunk/projects/bos/payment-website/static/poi-ms.js
===================================================================
--- trunk/projects/bos/payment-website/static/poi-ms.js	2008-11-29 21:55:51 UTC (rev 4101)
+++ trunk/projects/bos/payment-website/static/poi-ms.js	2008-11-30 10:29:40 UTC (rev 4102)
@@ -72,7 +72,7 @@
 function showMedium(e) {
     var medium = e.data;
 
-    /* work around jQuery bug when trying to remove applet from dom with IE */
+    /* Work around jQuery bug when trying to remove applet from DOM with IE. */
     var applet = $("#applet")[0];
     if (applet) {
         applet.parentNode.removeChild(applet);
@@ -105,28 +105,36 @@
         rows.push(DIV(null, tiles));
     }
 
-    return DIV({ 'class': 'map' }, rows);
+    return DIV(null, rows);
 }
 
+function positionMapIcon(img, x, y) {
+    img.style.left = (x - (Math.floor(x / 90) - 1) * 90) + 'px';
+    img.style.top = (y - (Math.floor(y / 90) - 1) * 90) + 'px';
+    return img;
+}
+
 function loadMainInfo(poi) {
-    var map = [];
-    map.push(makeMap(poi.x, poi.y));
-    map.push(IMG({ 'class': 'icon',
-                   src: '/images/' + poi.icon + '.gif',
-                   width: 16, height: 16,
-                   style: 'left: ' + (poi.x - ((Math.floor(poi.x / 90) - 1) * 90) - 8) + 'px; '
-                                   + 'top: ' + (poi.y - ((Math.floor(poi.y / 90) - 1) * 90) - 8) + 'px'}));
 
-    $('#content').empty().append(H2(null, poi.subtitle),
-                                 DIV({ 'class': 'map' }, map),
-                                 P(null, poi.description));
+    $('#content')
+    .empty()
+    .append(H2(null, poi.subtitle),
+            DIV({ 'class': 'map' },
+                makeMap(poi.x, poi.y),
+                positionMapIcon(IMG({ 'class': 'icon',
+                                      src: '/images/' + poi.icon + '.gif',
+                                      width: 16, height: 16}),
+                                poi.x - 8, poi.y - 8)),
+            P(null, poi.description));
 }
 
 function showPOI(e) {
     var poi = pois[(e.target && e.target.value) || e.data];
 
 
-    $('#left-bar').empty().append(UL({ id: 'media-list' }));
+    $('#left-bar')
+    .empty()
+    .append(UL({ id: 'media-list' }));
     if (!poi) {
         showOverview();
     } else {
@@ -152,10 +160,17 @@
 
 function showSponsor(e) {
     var sponsor = e.data;
+    var contract = sponsor.contracts[0];
     $('#content')
     .empty()
     .append(H2(null, sponsor.name),
-            makeMap(sponsor.contracts[0].left, sponsor.contracts[0].top));
+            DIV({ 'class': 'map' },
+                makeMap(contract.left, contract.top),
+                positionMapIcon(IMG({ 'class': 'contract',
+                                      src: '/contract-image/' + contract.id,
+                                      width: contract.width, height: contract.height}),
+                                contract.left, contract.top))
+           );
 }
 
 function showOverview() {
@@ -228,7 +243,7 @@
         }
         $('#poi-selector').bind('change', null, showPOI);
 
-        loadJSONDoc('/last-sponsors-json').addCallback(loadSponsors);
+        loadJSONDoc('/sponsors-json').addCallback(loadSponsors);
     }
     catch (e) {
         alert(e);

Modified: trunk/projects/bos/web/packages.lisp
===================================================================
--- trunk/projects/bos/web/packages.lisp	2008-11-29 21:55:51 UTC (rev 4101)
+++ trunk/projects/bos/web/packages.lisp	2008-11-30 10:29:40 UTC (rev 4102)
@@ -7,6 +7,7 @@
         :cl-user
         :cl-interpol
         :cl-ppcre
+        :alexandria
         :xhtml-generator
         :cxml
         :puri
@@ -22,4 +23,5 @@
         :bos.m2
         :bos.m2.config)
   (:shadowing-import-from :cl-interpol #:quote-meta-chars)
+  (:shadowing-import-from :alexandria #:array-index)
   (:export))

Modified: trunk/projects/bos/web/sponsor-handlers.lisp
===================================================================
--- trunk/projects/bos/web/sponsor-handlers.lisp	2008-11-29 21:55:51 UTC (rev 4101)
+++ trunk/projects/bos/web/sponsor-handlers.lisp	2008-11-30 10:29:40 UTC (rev 4102)
@@ -348,12 +348,32 @@
           (cmslink #?"edit-sponsor/$((store-object-id sponsor))" "return to sponsor")))))
 
 
-;;; last-sponsors-json-handler
-(defclass last-sponsors-json-handler (page-handler)
+;;; sponsors-json-handler
+(defclass sponsors-json-handler (page-handler)
   ())
 
-(defmethod handle ((handler last-sponsors-json-handler))
+(defun sponsors-matching (query)
+  (when (< 2 (length query))
+    (remove-if-not (curry #'search (string-downcase query))
+                   (class-instances 'sponsor)
+                   :key (compose #'string-downcase #'user-full-name))))
+
+(defun largest-sponsors ()
+  (mapcar #'contract-sponsor
+          (subseq (sort (copy-list (class-instances 'contract))
+                        #'>
+                        :key (compose #'length #'contract-m2s))
+                  0 20)))
+
+(defmethod handle ((handler sponsors-json-handler))
   (last-contracts-handle-if-modified-since)
   (with-json-response ()
     (json:with-object-element ("sponsors")
-      (bos.m2:last-sponsors-as-json))))
\ No newline at end of file
+      (bos.m2:sponsors-as-json
+       (cond
+         ((query-param "q")
+          (sponsors-matching (query-param "q")))
+         ((query-param "largest")
+          (largest-sponsors))
+         (t
+          (mapcar #'contract-sponsor (last-paid-contracts))))))))
\ No newline at end of file

Modified: trunk/projects/bos/web/webserver.lisp
===================================================================
--- trunk/projects/bos/web/webserver.lisp	2008-11-29 21:55:51 UTC (rev 4101)
+++ trunk/projects/bos/web/webserver.lisp	2008-11-30 10:29:40 UTC (rev 4102)
@@ -185,7 +185,7 @@
                                         ("/poi-javascript" poi-javascript-handler)
                                         ("/m2-javascript" m2-javascript-handler)
                                         ("/poi-json" poi-json-handler)
-                                        ("/last-sponsors-json" last-sponsors-json-handler)
+                                        ("/sponsors-json" sponsors-json-handler)
                                         ("/sponsor-login" sponsor-login-handler)
                                         ("/create-allocation-area" create-allocation-area-handler)
                                         ("/allocation-area" allocation-area-handler)





More information about the Bknr-cvs mailing list