source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/visualise.py @ 3421

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/visualise.py@3421
Revision 3421, 4.7 KB checked in by cbyrom, 12 years ago (diff)

Implement 'Selections' tab - a shopping cart type function to
allow the storing of different DIF selections together. Functionality
implemented to allow users to select/unselect DIFs from the results
screen and also to remove them, and remove everything, from the
Selections tab. Also, if KML is available for the DIF, icons are
provided to allow the user to open the file - currently valid for
the GoogleEarth? option but not the ConTerra?. Lastly, checkboxes
are provided - together with a 'select all' one - to allow selection
of multiple DIFs when viewing the associated KML. NB, this latter
functionality is not yet implemented.

Line 
1from ows_server.lib.base import *
2from ows_server.lib.ndgInterface import interface
3
4
5class VisualiseController(BaseController):
6   
7    def __setup(self):
8       
9        c.fullpage=1  # we want the whole page
10        c.selections = {}
11        c.selected = {}
12        c.names={}
13        c.bbox = (90, -180, 180, -90)
14        c.inpageid = 'api'
15
16        for uri, name in session.get('selection', []):
17            (rstatus, dataset) = interface.GetParsedCSML(uri)               
18            if not rstatus: 
19                c.xml='<div class="error">%s</div>'%dataset
20                return render_response('error')
21            c.selections[uri]=dataset
22            c.names[uri]=name
23       
24        c.nothing2see=0
25        print c.selections
26        if c.selections=={}:
27            c.nothing2see=1
28            return 0
29       
30        # Need two fundamental variables: the granules which has been selected
31        # for *possible* visualisation, and the granules (up to two) which have been
32        # selected for *actual* visualisation:
33        # session['selection'] holds the uris assocated with the first
34        # session['selectedVis'] holds the uris and featureIDs associated with the second
35        # c.selections holds the uris and the parsed csml for the datasets
36        # c.selected holds the uris, featureIDs and the parsed feature instances for the second
37       
38        # some defaults
39        defURI=c.selections.keys()[0]
40        defFid=c.selections[defURI].getFeatureList()[0]
41       
42        keys=session.get('selectedVis',[])
43        if keys==[]: keys=[(defURI,defFid)]
44        #yes, I know I could have sued the default on the session.get, but
45        #it's also possible that selectedVis is actually set to [] and we
46        #want to override that case too!
47        for uri,featureID in keys:
48            featureInstance=c.selections[uri].getFeature(featureID)
49            c.selected[(uri,featureID)]=featureInstance
50         
51        # We also need to know which dataset (if any) we are looking at   
52        c.viewedDataset=session.get('viewedDataset',c.selections.keys()[0])
53        print c.selected.keys()
54        return 0
55       
56    def __plotops(self):
57        ''' Works out what we can do in the way of plot options and flags the info to the template'''
58        c.wmsAvailable=0
59        for i in c.selected:
60            if 'latitude' and 'longitude' in c.selected[i].getAxisLabels(): c.wmsAvailable=1
61     
62    def index(self):
63        s=self.__setup()
64        if s: return s
65        c.visible='Granules'
66        self.__plotops()
67        return render_response('visualise')
68       
69    def tabChange(self,dataset,view):
70        ''' Take ajax request for inpage tab change '''
71       
72        s=self.__setup()
73        if s: return s
74        c.visible=view
75        formValue=request.params.get('dataset',0)
76        if formValue: dataset=formValue
77        print 'TabChange ',dataset,formValue
78        #dataset is really a uri ...shame about the variable name we chose ...
79       
80        # the incoming dataset ought to be in the selections, so this is only
81        # about telling the interface what variable list to display ... and
82        # remembering it
83        c.viewedDataset=dataset
84        session['viewedDataset']=dataset
85        session.save()
86       
87        c.fullpage=0 
88        self.__plotops()
89        return render_response('visualise',fragment=True)
90       
91    def featureChange(self,view):
92        ''' Take an ajax request and update the current list of features '''
93       
94        self.__setup()
95        if s: return s
96        c.visible=view
97        checkedFeatures=[]
98       
99        # ok, we know we are getting features from viewedDataset
100        # let's collect them up a we go so we know which ones we've
101        # lost (if any), as well as parse them as we go ...
102        checkedFeatures
103        for i in request.params:
104            featureID=request.params[i]
105            checkedFeatures.append(featureID)
106            if 'Feature' in i: 
107                if (c.viewedDataset,featureID) not in c.selected:
108                    featureInstance=c.selections[c.viewedDataset].getFeature(featureID)
109                    c.selected[(c.viewedDataset,featureID)]=featureInstance
110        #ok, now we remove them if necessary
111        removeList=[]
112        for suri,sf in c.selected:
113            if suri==c.viewedDataset and sf not in checkedFeatures:
114                removeList.append((suri,sf)) 
115        for i in removeList: del c.selected[i]
116        # and update the session
117        session['selectedVis']=c.selected.keys()
118        session.save()   
119       
120        c.fullpage=0
121        self.__plotops()
122        return render_response('visualise',fragment=True)
123       
124    def tabcontent(self):
125        pass
126   
127    def plot(self):
128        pass
129       
Note: See TracBrowser for help on using the repository browser.