source: cowsclient/cowsclient/controllers/wmsviz.py @ 5300

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cowsclient/cowsclient/controllers/wmsviz.py@5300
Revision 5300, 4.0 KB checked in by domlowe, 13 years ago (diff)

removing some of the hardcoded stuff

Line 
1# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
2# This software may be distributed under the terms of the
3# Q Public License, version 1.0 or later.
4# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
5#
6"""
7 Controller for the 'View' tab - allowing the display of WMC map layers
8
9 @author C Byrom Feb 08, Modified D Lowe, May 09
10"""
11
12from cowsclient.lib.base import *
13from paste.request import parse_querystring
14#from ows_server.models import Utilities
15from cowsclient.lib.wmc_util import *
16from cowsclient.model import selectedItem
17from pylons import config
18import copy, logging
19log = logging.getLogger(__name__)
20
21class WmsvizController(BaseController):
22   
23    def index(self):
24        """
25        Default controller method to handle the initial requests to the page
26        """
27        log.debug('wmsviz controller')
28        self.inputs=dict(parse_querystring(request.environ))
29        log.info(self.inputs)
30        c.wmcURL = ""
31        # check if all we're doing is removing a view item
32        if 'removeItem' in self.inputs:
33            return self.removeViewItem(self.inputs['removeItem'])
34        # check if we're doing an AJAX callback to get some WMC data
35        if 'REQUEST' in self.inputs:           
36            if self.inputs['REQUEST'] == 'GetWebMapContext':
37                log.debug('request is in inputs and is of getwmapcontext')
38                return GetWebMapContext(self)
39            elif self.inputs['REQUEST'] == 'GetLegend':
40                return GetLegend(self)
41
42       
43        #get server information from config file
44        g.server=config['app_conf']['serverurl']
45   
46       
47        #TODO: WORK OUT HOW TO COUPLE THIS TO BROWSE
48        # otherwise, we can get here by two routes:
49        # i) either by clicking on the WMC icon in the details view - if so, get passed endpoint and add to
50        #    selected items;
51        # ii) or from the selections tab - which will already have set up the correct selected items
52           
53        # if ENDPOINT specified, we've reached the page via the WMC icon
54               
55        if ('ENDPOINT' in self.inputs):
56            self.addViewItem(self.inputs['ENDPOINT'])
57       
58        # avoid page crashing if we come here without view items defined
59#        if 'viewItems' not in session:
60#            h.redirect_to(h.url_for(controller='discovery'))
61#                                       
62        session.save() 
63        log.info('SAVED SESSION')
64       
65        # check if page has been visited before; if not display tab
66#        if (Utilities.isTabRequired(c.pageTabs, 'View')):
67#            c.pageTabs.append(('View', h.url_for(controller='viewItems',action='index')))
68
69        return render('wmsviz')
70
71
72    def addViewItem(self,endpoint):
73        """
74        Add a selected item to the session
75         - if this is the first item, then display the selections tab
76         @param endpoint: WMC endpoint
77        """
78       
79        item = selectedItem.SelectedItem(None, None, None, endpoint)
80       
81        selections = [item,]
82        # avoid duplicates
83        if 'viewItems' in session:
84            for selection in session['viewItems']:
85                if selection.wmcURL != endpoint:
86                    selections.append(selection)
87                   
88        session['viewItems'] = selections
89        session.save()  #TODO, why won't session save?
90       
91   
92    def removeViewItem(self,endpoint):
93        """
94        Remove view item from session data
95        - NB, do this by rebuilding the session data without the input data included
96        @param endpoint: The WMC endpoint of the view item to remove
97        """
98        selections = []
99        for selection in session['viewItems']:
100            if selection.wmcURL != endpoint:
101                selections.append(selection)
102               
103        # if the new list is empty, remove the session variable
104        if len(selections) == 0:
105            del session['viewItems']
106            c.UpdatePageTabs=1
107        else:
108            session['viewItems'] = selections
109
110        session.save()
111       
Note: See TracBrowser for help on using the repository browser.