changeset 4:6d286ce1a64f default

inline refresh
author dwinter
date Thu, 10 Jan 2013 17:38:13 +0100
parents f198c86dd1f6
children 2715bff4628d
files WebContent/mmpa/index.html WebContent/mmpa/mmpa.js eventsRestService.py eventsRestService_orig.py
diffstat 4 files changed, 388 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/WebContent/mmpa/index.html	Wed Jan 09 14:37:39 2013 +0100
+++ b/WebContent/mmpa/index.html	Thu Jan 10 17:38:13 2013 +0100
@@ -10,11 +10,19 @@
 <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 
-<title>Spatio Temporal Interface 3</title>
+<title>Spatio Temporal Interface 4</title>
 
 <script type="text/javascript" language="javascript" src="/e4D/sti/sti.nocache.js"></script>
 
 <script src="/e4D/scripts/jQuery/jquery-1.5.1.js"></script>
+	<script>
+		$.fn.cleanWhitespace = function() {
+			textNodes = this.contents().filter(
+			function() { return (this.nodeType == 3 && !/\S/.test(this.nodeValue)); })
+			.remove();
+			return this;
+		};
+ 	</script>	
 <script src="/e4D/scripts/blockUI/FullscreenWindow.js">
 </script>
 
--- a/WebContent/mmpa/mmpa.js	Wed Jan 09 14:37:39 2013 +0100
+++ b/WebContent/mmpa/mmpa.js	Thu Jan 10 17:38:13 2013 +0100
@@ -46,4 +46,16 @@
  $("#restrictionChoiceSpecies").load("/m/restricted?path="+kml1+"&newRestriction=http%3A%2F%2Flocalhost%2Fm%2Fxpath%2F%2F%2Fspecies%2Ftext%28%29&select=%20distinct%20cast%28xpath%28%27//species/text%28%29%27,%20data%29%20as%20text[]%29%20AS%20name");
 
 
-});
\ No newline at end of file
+});
+
+
+function callKML(kml,title){
+	this.loadKml(kml,title);
+	//this.STICore.retrieveKML(1,kml);
+};
+
+function callKMLs(kml1,kml2){
+	this.loadKml(kml1,"applicants");
+	this.loadKml(kml2,"research");
+	
+};
--- a/eventsRestService.py	Wed Jan 09 14:37:39 2013 +0100
+++ b/eventsRestService.py	Thu Jan 10 17:38:13 2013 +0100
@@ -31,25 +31,23 @@
         url1=urllib.quote_plus(APPLICANT_FILE_NAME)
         ret+="""
             
-            <a href="
-            %s?kml1=%s&source1=1"  
-            >applicants</a><br/>
-            """%(E4D_URL,url1)
+            <a href="javascript:callKML('%s','applicants')">applicants</a><br/>
+            
+            """%(url1)
+            
             
             
         url2=urllib.quote_plus(RESEARCH_FILE_NAME)
         ret+="""
             
-            <a href="
-            %s?kml1=%s&source1=1"  
-            >research</a><br/>
-            """%(E4D_URL,url2)
+            <a href="javascript:callKML('%s','research')">research</a><br/>
+            """%(url2)
+         
             
         ret+= """
-        <a href="
-           %s?kml1=%s&source1=1&kml2=%s&source2=1"  
-            >both</a><br/>
-            """%(E4D_URL,url1,url2)
+        <a href="javascript:callKMLs('%s','%s')">both</a><br/>
+            """%(url1,url2)
+      
             
         return ret
         
@@ -283,10 +281,9 @@
             url=urllib.quote_plus("%sxpath///applicant/name/text()?q=%s"%(BASE_URL,x))
             ret+="""
             
-            <a href="
-            %s?kml1=%s&source1=1"  
-            >e4D</a><br/>
-            """%(E4D_URL,url)
+            <a href="javascript:callKML('%s','%s')">e4D</a><br/>
+            """%(url,x)
+           
         
         return ret
 class species:
@@ -340,10 +337,8 @@
             url=urllib.quote_plus("%sxpath///species/text()?q=%s"%(BASE_URL,x))
             ret+="""
             
-            <a href="
-            %s?kml1=%s&source1=1"  
-            >e4D</a><br/>
-            """%(E4D_URL,url)
+            <a href="javascript:callKML('%s','%s')">e4D</a><br/>
+            """%(url,x)
         
         return ret
           
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eventsRestService_orig.py	Thu Jan 10 17:38:13 2013 +0100
@@ -0,0 +1,351 @@
+import web
+import eventsDB2kml
+import harvestDataFromEvents
+import urllib
+import urlparse
+
+urls = (
+    '/xpath/(.*)', 'xpath',
+    '/xpathSearch', 'xpathSearch',
+    '/sqlSearch', 'sqlSearch',
+    '/sql', 'sql',
+    '/species', 'species',
+    '/applicants', 'applicants',
+    '/locations','locations',
+    '/restricted', 'restricted'
+)
+app = web.application(urls, globals())
+
+#E4D_URL="http://localhost/mmpa/"
+E4D_URL="http://localhost/~dwinter/mmpa/events2kml/mmpa/"
+BASE_URL="http://localhost/m/"
+
+APPLICANT_FILE_NAME="http://localhost/outApplicants.xml"
+RESEARCH_FILE_NAME="http://localhost/outResearch.xml"
+class locations:
+    
+    def GET(self):
+        
+        ret=""
+        
+        url1=urllib.quote_plus(APPLICANT_FILE_NAME)
+        ret+="""
+            
+            <a href="
+            %s?kml1=%s&source1=1"  
+            >applicants</a><br/>
+            """%(E4D_URL,url1)
+            
+            
+        url2=urllib.quote_plus(RESEARCH_FILE_NAME)
+        ret+="""
+            
+            <a href="
+            %s?kml1=%s&source1=1"  
+            >research</a><br/>
+            """%(E4D_URL,url2)
+            
+        ret+= """
+        <a href="
+           %s?kml1=%s&source1=1&kml2=%s&source2=1"  
+            >both</a><br/>
+            """%(E4D_URL,url1,url2)
+            
+        return ret
+        
+class restricted:
+    def GET(self):      
+        x=web.input()
+        pathes=x.get("path")
+        print pathes
+        select=x.get("select")
+        newRestriction=x.get("newRestriction")
+        
+        if select is None:
+            select="data"
+        
+        
+        
+        #path kann meherer abfragen enthalten durch | getrennt
+      
+        splittedPath = pathes.split("|")
+        print splittedPath
+        queriesArray=[]
+        for xlinkPath in splittedPath:
+            url = urllib.unquote_plus(xlinkPath);
+        
+       
+            qs=urlparse.urlparse(url).query
+      
+            queries=urlparse.parse_qsl(qs)
+            q=""
+            for query in queries:
+                if query[0]=='q':
+                    q=query[1]
+        
+        
+        
+        
+        
+            url= urlparse.urlparse(url).path
+            
+            pathSplitted=url.split("xpath/")
+            if len(pathSplitted)>1:
+                path=pathSplitted[1]
+                queriesArray.append((path,q))
+        print queriesArray
+        
+        
+        
+        db = eventsDB2kml.DBQuery()
+       
+        if newRestriction is None: # keine weiteren Einschaenkungen dann erzeugen das kml file
+            res= "<events>"+ db.searchXPaths(queriesArray)+"</events>"
+        
+        
+           
+            hv=harvestDataFromEvents.EventKMLTransformer()
+        
+        
+            #x,cnt=hv.readString(res, ".//research_location/place_information", 0)
+            x,cnt=hv.readString(res, ".//place_information", 0)
+        
+            
+        
+            s = hv.toKML(x)
+            
+            return s
+             
+             
+        #sonst suche nach restriction suche muss eine liste von werten ergeben die sich mit der REstriction versteht, dh. restriction =wert wird dann in die Links eingebaut
+        # e.g. man such nach name d.h
+        # select=%20distinct%20cast%28xpath%28%27//applicant/name/text%28%29%27,%20data%29%20as%20text[]%29%20AS%20name
+        # dann muss die Restriction darauf passen i.a. wird die Restriction dem xpath im Suchstring entsprechen,
+        # newRestriction=http%3A%2F%2Flocalhost%2Fm%2Fxpath%2F%2F%2Fapplicant%2Fnam%2Ftext%28%29%
+        
+        newRestriction=urllib.unquote_plus(newRestriction)
+       
+        vals = db.searchXPaths(queriesArray,select,True)
+        
+        
+        ret=""
+        
+        
+        #berechen den neuer link = alter path ergaenzt um neue restriction
+        for val in vals:
+            val=val[0] # result ist immer ein tuple
+            # mehr als ein Treffer pro eintrag
+            for v in val:
+                newQuery=""
+                splittedPath.append(newRestriction+"?q="+v)
+                splittedPathQuoted=[urllib.quote_plus(x) for x in splittedPath]
+                
+                pathNew="|".join(splittedPathQuoted)
+                urlNew=urllib.quote_plus("""%srestricted?path=%s"""%(BASE_URL,pathNew))
+                ret+="""<a href="%s?kml1=%s&source1=1">%s</a><br/>"""%(E4D_URL,urlNew,v)
+        return ret
+        
+class sqlSearch:
+    def GET(self):      
+        x=web.input()
+        sql=x.get("sql")
+        p=x.get("xpathPlace")
+        output=x.get("output")
+        
+       
+            
+        url="%ssql?q=%s&p=%s"%(BASE_URL,urllib.quote_plus(sql),p)
+        
+        if output=="sql":
+            raise web.seeother(url)
+        
+        url=urllib.quote_plus(url)
+        
+        
+        
+        url="""%s?kml1=%s&source1=1"""%(E4D_URL,url)
+        raise web.seeother(url)
+    
+    
+class xpathSearch:
+    def GET(self):      
+        x=web.input()
+        path=x.get("path")
+        value=x.get("value")
+        
+        url="%sxpath/%s?q=%s"%(BASE_URL,path,value)
+        
+        url=urllib.quote_plus(url)
+        
+        
+        
+        url="""%s?kml1=%s&source1=1"""%(E4D_URL,url)
+        raise web.seeother(url)
+  
+class sql:
+    def GET(self):
+        x = web.input()
+        q= x.get("q")
+        p= x.get("p")
+        db = eventsDB2kml.DBQuery()
+        res= "<events>"+db.sql(q)+"</events>"
+    
+    
+       
+        hv=harvestDataFromEvents.EventKMLTransformer()
+    
+    
+        #x,cnt=hv.readString(res, ".//research_location/place_information", 0)
+        x,cnt=hv.readString(res, p, 0)
+    
+        
+    
+        s = hv.toKML(x)
+        
+        return s
+      
+      
+class xpath:
+ 
+    def GET(self, path):
+        
+        if not path: 
+            return ""
+        
+        x = web.input()
+        q= x.get("q")
+        
+        db = eventsDB2kml.DBQuery()
+        res= "<events>"+db.searchXPath(path, q)+"</events>"
+    
+    
+       
+        hv=harvestDataFromEvents.EventKMLTransformer()
+    
+    
+        #x,cnt=hv.readString(res, ".//research_location/place_information", 0)
+        x,cnt=hv.readString(res, ".//place_information", 0)
+    
+        
+    
+        s = hv.toKML(x)
+        
+        return s
+
+class applicants:
+    
+     def GET(self):
+        db = eventsDB2kml.DBQuery()
+        
+           
+        x = web.input()
+        where= x.get("where")
+      
+        whereClause=""
+
+#Beispiel:
+#select distinct
+# 
+#cast (xpath('//name/text()',data) as text[]) AS name
+#
+#from locations
+#        where
+#        'Astrophytum asterius'  = ANY (cast (xpath('//species/text()', data) as text[])) ;
+        
+        if where!="" and where is not None:
+            whereClause="where %s"%where
+            
+        q="""
+          select 
+            cast(xpath('//applicant/name/text()', data) as text[]) AS name 
+            from locations
+            %s
+            """%whereClause
+            
+        res=db.query(q)
+        #hole alle species
+        spec=set()
+       
+        for r in res:
+           
+            l=r[0] 
+            for x in l:
+                spec.add(x)
+                
+        ret=""
+        spList=[x for x in spec]
+        
+        spList.sort()
+        for x in spList:
+          
+            ret+="""<a href="%sxpath///applicant/name/text()?q=%s">%s</a>"""%(BASE_URL,x,x)
+            
+            url=urllib.quote_plus("%sxpath///applicant/name/text()?q=%s"%(BASE_URL,x))
+            ret+="""
+            
+            <a href="
+            %s?kml1=%s&source1=1"  
+            >e4D</a><br/>
+            """%(E4D_URL,url)
+        
+        return ret
+class species:
+    
+    def GET(self):
+        db = eventsDB2kml.DBQuery()
+        
+        x = web.input()
+        where= x.get("where")
+        
+        whereClause=""
+        
+# Beispiel:       
+#select 
+# 
+#cast (xpath('//species/text()',data) as text[]) AS name
+#
+#from locations
+#        where
+#        'Anna George'  = ANY (cast (xpath('//name/text()', data) as text[])) ;
+#        
+        if where!="" and where is not None:
+            whereClause="where %s"%where
+            
+        q="""
+          select distinct
+            cast(xpath('//species/text()', data) as text[]) AS name 
+            from locations
+            %s
+            """%whereClause
+        
+      
+        res=db.query(q)
+        #hole alle species
+        spec=set()
+       
+        for r in res:
+           
+            l=r[0] 
+            for x in l:
+                spec.add(x)
+                
+        ret=""
+        spList=[x for x in spec]
+        
+        spList.sort()
+        for x in spList:
+            
+            ret+="""<a href="%sxpath///species/text()?q=%s">%s</a>"""%(BASE_URL,x,x)
+            
+            url=urllib.quote_plus("%sxpath///species/text()?q=%s"%(BASE_URL,x))
+            ret+="""
+            
+            <a href="
+            %s?kml1=%s&source1=1"  
+            >e4D</a><br/>
+            """%(E4D_URL,url)
+        
+        return ret
+          
+if __name__ == "__main__":
+    app.run()
\ No newline at end of file