Changeset 6908 for cows_wps


Ignore:
Timestamp:
28/05/10 23:02:05 (9 years ago)
Author:
astephen
Message:

working on jobviewer page to do ajax polling if not complete.

Location:
cows_wps/trunk/cows_wps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cows_wps/trunk/cows_wps/controllers/jobviewer.py

    r6907 r6908  
    88from pylons import request, response, session, tmpl_context as c 
    99from pylons.controllers.util import abort, redirect_to 
     10from routes import url_for 
    1011 
    1112 
     
    3839        job_xml = getter.read() 
    3940        getter.close() 
    40  
    41         job_id = re.search("<JobID>(.*)</JobID>", job_xml).groups()[0] 
    42  
     41  
    4342        job_as_table = self._xmlToTable(job_xml) 
    4443        job_xml_encoded = self._htmlifyXML(job_xml) 
     
    4645 
    4746        resp = """<div id="view_options" style="background: #EEF4FF; border: 2px outset blue; padding: 5px;"> 
    48                 <a href="javascript:switchViewTo('table_view');">View as table</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    49                 <a href="javascript:switchViewTo('xml_view');">View as XML</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    50                 <a href="javascript:switchViewTo('plots_view');">View Plots (if available)</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
     47                <a href="javascript:switchViewTo('table_view');">Normal View</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;""" 
     48 
     49        if self.status == "complete": 
     50            resp += """<a href="javascript:switchViewTo('xml_view');">View as XML</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
     51                <a href="javascript:switchViewTo('plots_view');">View Plots (if available)</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;""" 
     52 
     53        resp  += """ 
    5154</div> 
    5255<div id="view_container" style="background: white; border: 2px outset blue; padding: 5px;"> 
    5356        <div id="view_contents"> 
    54                 <div id="table_view" style="visibility: visible; height: auto;">%s</div> 
     57                <div id="table_view" style="visibility: visible; height: auto;">%s</div>""" % (job_as_table) 
     58 
     59        if self.status == "complete": 
     60            resp += """ 
    5561                <div id="xml_view" style="visibility: hidden; height: 0px;">%s</div> 
    5662                <div id="plots_view" style="visibility: hidden; height: 0px;">%s</div> 
    57 </div>""" % (job_as_table, job_xml_encoded, job_as_plots) 
     63</div>""" % (job_xml_encoded, job_as_plots) 
     64 
     65        elif self.status == "running": 
     66            jobviewer_url = url_for(controller='jobviewer', status_url = status_url) 
     67 
     68            base_url = "http://" + request.url[7:].split("/")[0] 
     69            full_url = base_url + jobviewer_url 
     70 
     71            resp += """<input type="hidden" id="poll_url" value="%s" />""" % full_url  
     72            resp += """<div id="poll_info">Polling here...</div>""" 
     73            resp += """<script type="text/javascript">pollWPS()</script>""" 
     74# </form>""" % (submitter_url, urllib.unquote(wps_request_url)) 
    5875 
    5976        renderer = UIPageRenderer() 
    6077        resp = renderer.render("WPS Job Information", 
    61                               [("Job: %s" % job_id, resp)]) 
     78                              [("Job: %s" % self.job_id, resp)]) 
    6279        return resp 
    6380 
     81    def _resolveStatus(self, status_node): 
     82        snode = status_node.getchildren()[0].tag 
     83        mdict = {"Succeeded": "complete", 
     84                 "Failed": "failed", 
     85                 "Accepted": "running"} 
     86 
     87        for k,v in mdict.items(): 
     88            if snode.find(k) > -1: 
     89                return v 
     90        else: 
     91            raise Exception("Could not match status tag.") 
    6492 
    6593    def _xmlToTable(self, xml): 
    6694        "Chops up xml to get table of outputs." 
    67         node = ET.fromstring(xml) 
    68  
    69         proc_id = node.find("{http://www.opengeospatial.net/ows}Identifier").text 
    70         job_details = node.find("{http://www.opengeospatial.net/wps}ProcessOutputs").find("{http://www.opengeospatial.net/wps}Output").find("{http://www.opengeospatial.net/wps}ComplexValue").find("{http://www.opengeospatial.net/wps}WPSResponseDetails").find("{http://www.opengeospatial.net/wps}JobDetails") 
    71  
    72         file_set_list = job_details.find("{http://www.opengeospatial.net/wps}FileSet").getchildren() 
     95        self.node = ET.fromstring(xml) 
     96        self.namespace_ows = "http://www.opengeospatial.net/ows" 
     97        self.namespace = "http://www.opengeospatial.net/wps" 
     98 
     99        self.status = self._resolveStatus(self.node.find("{" + self.namespace + "}Status"))  
     100 
     101        job_details = self.node.find("{" + self.namespace +  "}ProcessOutputs").find("{" + self.namespace +  "}Output").find("{" + self.namespace +  "}ComplexValue").find("{" + self.namespace +  "}WPSResponseDetails").find("{" + self.namespace +  "}JobDetails") 
     102 
     103        file_set_list = job_details.find("{" + self.namespace +  "}FileSet").getchildren() 
    73104 
    74105        items = ["JobID", "JobCompletionTimeDate", "JobDuration", "JobVolume", "RequestDescription", 
     
    80111        resp += "Need to realise that in costonly response we have JobCompletionTimeDate empty because it hasn't run yet!<br><br>" 
    81112 
     113        self.job_id = job_details.find("{" + self.namespace + "}JobID").text 
     114 
    82115        for (i, item) in enumerate(items): 
    83             x = job_details.find("{http://www.opengeospatial.net/wps}" + item).text 
     116            x = job_details.find("{" + self.namespace +  "}" + item).text 
    84117            if type(x) != str: x = "Undefined" 
    85118            resp += "<b>%s</b> = %s<br>" % (mapped_names[i], x.strip()) 
     
    91124        for fnode in file_set_list: 
    92125 
    93             furl = fnode.find("{http://www.opengeospatial.net/wps}FileURL").text 
     126            furl = fnode.find("{" + self.namespace +  "}FileURL").text 
    94127            fname = furl.split("/")[-1] 
    95128            len_fname = len(fname) 
     
    99132            if padding < 0: padding = 0 
    100133 
    101 #            fname = fname[:p] + (padding * "&nbsp") 
    102134            resp += ('<br><kbd>%s [<a href="%s">Download</a>]</kbd>' + (padding * "&nbsp;")) % (fname, furl) 
    103 #            resp += '<br><span style="width: 500px;">%s [<a href="%s">Download</a>]</span>' % (fname, furl) 
    104135 
    105136            for (i, file_item) in enumerate(file_items): 
    106                 x = fnode.find("{http://www.opengeospatial.net/wps}" + file_item).text 
     137                x = fnode.find("{" + self.namespace +  "}" + file_item).text 
    107138                resp += '%s Bytes' % x 
    108139 
     
    131162        for line in lines: 
    132163 
    133             colour = pad * 20000  
     164            colour = pad * 50000  
    134165            col = ("000000" + hex(colour).split("x")[-1])[-6:] 
    135166            line2 = retag(line) 
  • cows_wps/trunk/cows_wps/public/js/ui/jobviewer_utils.js

    r6905 r6908  
    3434} 
    3535 
     36/* function: pollWPS 
     37 Dependencies: 
     38  * Jquery 
     39*/ 
     40function pollWPS() { 
     41        // Inform that request is being made 
     42        $("#poll_info").append('<span style="color: blue;">contacting the server now...</span>'); 
    3643 
     44        // Set up AJAX call 
     45        $.ajax({ 
     46                type: "GET", 
     47                url: $("#poll_url").val(), 
     48                dataType: "xml", 
     49                success:  parsePollResponse 
     50        }); 
     51 
     52        $("#poll_info").append("Sent ajax request."); 
     53 
     54 
     55function parsePollResponse(xml) 
     56{ 
     57    alert("GOT RESPONSE"); 
     58    $(xml).find("ProcessSucceeded").each(function() 
     59    { 
     60        alert("FOUND IT"); 
     61        $("#poll_info").html("The job has completed! Re-loading page in 3 seconds..."); 
     62        setTimeout("window.location = $('#poll_url').val();", 3000);  
     63    }); 
     64 
     65    $("#poll_info").html("Polling again..."); 
     66    setTimeout("pollWPS();", 10000);  
     67} 
     68 
Note: See TracChangeset for help on using the changeset viewer.