can pass starting lat/lon/zoom to googlemap
[unfold.git] / trash / sliceview.py
1 # Create your views here.
2
3 from django.template import RequestContext
4 from django.shortcuts import render_to_response
5
6 from django.contrib.auth.decorators import login_required
7
8 from unfold.page import Page
9 from manifold.manifoldquery import ManifoldQuery
10
11 from plugins.raw.raw import Raw
12 from plugins.stack.stack import Stack
13 from plugins.tabs.tabs import Tabs
14 from plugins.lists.slicelist import SliceList
15 from plugins.hazelnut.hazelnut import Hazelnut 
16 from plugins.googlemap.googlemap import GoogleMap 
17 from plugins.senslabmap.senslabmap import SensLabMap
18 from plugins.querycode.querycode import QueryCode
19 from plugins.quickfilter.quickfilter import QuickFilter
20 from plugins.messages.messages import Messages
21
22 from myslice.viewutils import quickfilter_criterias
23
24 from myslice.viewutils import topmenu_items, the_user
25
26 tmp_default_slice='ple.inria.sfatest'
27
28 @login_required
29 def slice_view (request, slicename=tmp_default_slice):
30     
31     page = Page(request)
32
33     main_query = ManifoldQuery (action='get',
34                                 subject='resource',
35                                 timestamp='latest',
36                                 fields=['network','type','hrn','hostname'],
37                                 filters= [ [ 'slice_hrn', '=', slicename, ] ],
38                                 )
39     page.enqueue_query (main_query)
40
41     main_plugin = Stack (
42         page=page,
43         title="Slice view for %s"%slicename,
44         domid='thestack',
45         togglable=False,
46         sons=[
47             Messages (
48                 page=page,
49                 title="Runtime messages",
50                 domid="msgs-pre",
51                 levels="ALL",
52                 ),
53             Tabs (
54                 page=page,
55                 title="2 tabs : w/ and w/o checkboxes",
56                 domid='thetabs',
57                 # active_domid='checkboxes',
58                 active_domid='gmap',
59                 sons=[
60                     Hazelnut ( 
61                         page=page,
62                         title='a sample and simple hazelnut',
63                         domid='simple',
64                         # tab's sons preferably turn this off
65                         togglable=False,
66                         # this is the query at the core of the slice list
67                         query=main_query,
68                         ),
69                     Hazelnut ( 
70                         page=page,
71                         title='with checkboxes',
72                         domid='checkboxes',
73                         # tab's sons preferably turn this off
74                         togglable=False,
75                         # this is the query at the core of the slice list
76                         query=main_query,
77                         checkboxes=True,
78                         datatables_options = { 
79                             # for now we turn off sorting on the checkboxes columns this way
80                             # this of course should be automatic in hazelnut
81                             'aoColumns' : [ None, None, None, None, {'bSortable': False} ],
82                             'iDisplayLength' : 25,
83                             'bLengthChange' : True,
84                             },
85                         ),
86                     GoogleMap (
87                         page=page,
88                         title='geographic view',
89                         domid='gmap',
90                         # tab's sons preferably turn this off
91                         togglable=False,
92                         query=main_query,
93                         # center on Paris
94                         latitude=49.,
95                         longitude=2.2,
96                         zoom=3,
97                         ),
98                     Raw (
99 #                    SensLabMap (
100                         page=page,
101                         title='3D view (disabled)',
102                         domid='smap',
103 #                        # tab's sons preferably turn this off
104                         togglable=False,
105 #                        query=main_query,
106                         html="""<p class='well'>
107 Thierry: I am commeting off the use of <button class="btn btn-danger">SensLabMap</button> which,
108  although rudimentarily ported to the django framework, 
109 causes a weird behaviour especially wrt scrolling. 
110 On my Mac <button class="btn btn-warning"> I cannot use the mouse to scroll</button> any longer
111 if I keep this active, so for now it's disabled
112 </p>""",
113                         ),
114                     ]),
115             Hazelnut ( 
116                 page=page,
117                 title='a hazelnut not in tabs',
118                 domid='standalone',
119                 # this is the query at the core of the slice list
120                 query=main_query,
121                 columns=['hrn','hostname'],
122                 ),
123               # you don't *have to* set a domid, but if you plan on using toggled=persistent then it's required
124               # because domid is the key for storing toggle status in the browser
125             QueryCode (
126                 page=page,
127                 title='xmlrpc code (toggled=False)',
128                 query=main_query,
129 #                domid='xmlrpc',
130                 toggled=False,
131                 ),
132             QuickFilter (
133                 page=page,
134                 title="QuickFilter - requires metadata (toggled=False)",
135                 criterias=quickfilter_criterias,
136                 domid='filters',
137                 toggled=False,
138                 ),
139             Messages (
140                 page=page,
141                 title="Runtime messages (again)",
142                 domid="msgs-post",
143                 )
144               ])
145
146     # variables that will get passed to the view-unfold1.html template
147     template_env = {}
148     
149     # define 'unfold1_main' to the template engine - the main contents
150     template_env [ 'unfold1_main' ] = main_plugin.render(request)
151
152     # more general variables expected in the template
153     template_env [ 'title' ] = 'Test view that combines various plugins'
154     # the menu items on the top
155     template_env [ 'topmenu_items' ] = topmenu_items('slice', request) 
156     # so we can sho who is logged
157     template_env [ 'username' ] = the_user (request) 
158
159     # don't forget to run the requests
160     page.expose_queries ()
161
162     # xxx create another plugin with the same query and a different layout (with_datatables)
163     # show that it worls as expected, one single api call to backend and 2 refreshed views
164
165     # the prelude object in page contains a summary of the requirements() for all plugins
166     # define {js,css}_{files,chunks}
167     prelude_env = page.prelude_env()
168     template_env.update(prelude_env)
169     result=render_to_response ('view-unfold1.html',template_env,
170                                context_instance=RequestContext(request))
171     return result