1 from django.template import RequestContext
2 from django.shortcuts import render_to_response
4 from unfold.loginrequired import LoginRequiredAutoLogoutView
6 from unfold.page import Page
7 from manifold.core.query import Query, AnalyzedQuery
9 from ui.topmenu import topmenu_items, the_user
11 from plugins.raw import Raw
12 from plugins.stack import Stack
13 from plugins.tabs import Tabs
14 from plugins.hazelnut import Hazelnut
15 from plugins.resources_selected import ResourcesSelected
16 from plugins.googlemap import GoogleMap
17 from plugins.senslabmap.senslabmap import SensLabMap
18 from plugins.querycode import QueryCode
19 from plugins.query_editor import QueryEditor
20 from plugins.active_filters import ActiveFilters
21 from plugins.quickfilter import QuickFilter
22 from plugins.messages import Messages
24 from myslice.config import Config
26 tmp_default_slice='ple.upmc.myslicedemo'
28 # temporary : turn off the users part to speed things up
31 class SliceView (LoginRequiredAutoLogoutView):
33 def get (self,request, slicename=tmp_default_slice):
36 page.add_css_files ('css/slice-view.css')
37 page.add_js_files ( [ "js/common.functions.js" ] )
38 page.add_js_chunks ('$(function() { messages.debug("sliceview: jQuery version " + $.fn.jquery); });')
39 page.add_js_chunks ('$(function() { messages.debug("sliceview: users turned %s"); });'%("on" if do_query_users else "off"))
40 page.add_js_chunks ('$(function() { messages.debug("manifold URL %s"); });'%(Config.manifold_url()))
41 page.expose_js_metadata()
43 metadata = page.get_metadata()
44 resource_md = metadata.details_by_object('resource')
45 resource_fields = [column['name'] for column in resource_md['column']]
47 user_md = metadata.details_by_object('user')
48 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
50 # TODO The query to run is embedded in the URL
51 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
54 'resource.resource_hrn', 'resource.hostname', 'resource.type',
55 #'resource.network_hrn',
58 #'application.measurement_point.counter'
61 query_resource_all = Query.get('resource').select(resource_fields)
63 query_user_all = Query.get('user').select(user_fields)
65 aq = AnalyzedQuery(main_query, metadata=metadata)
66 page.enqueue_query(main_query, analyzed_query=aq)
67 page.enqueue_query(query_resource_all)
69 page.enqueue_query(query_user_all)
71 # ... and for the relations
72 # XXX Let's hardcode resources for now
73 sq_resource = aq.subquery('resource')
74 sq_user = aq.subquery('user')
75 sq_lease = aq.subquery('lease')
76 sq_measurement = aq.subquery('measurement')
79 # Prepare the display according to all metadata
80 # (some parts will be pending, others can be triggered by users).
82 # For example slice measurements will not be requested by default...
84 # Create the base layout (Stack)...
87 title="Slice %s"%slicename,
91 # ... responsible for the slice properties...
98 html="<h2 class='well well-lg'> Slice %s</h2>"%slicename)
101 # --------------------------------------------------------------------------
102 # ResourcesSelected (Pending Operations)
104 main_stack.insert(ResourcesSelected(
106 title = 'Pending operations',
109 # start turned off, it will open up itself when stuff comes in
112 outline_complete = True,
115 # --------------------------------------------------------------------------
117 # the resources part is made of a Tabs (Geographic, List),
119 resources_as_map = GoogleMap(
121 title = 'Geographic view',
122 domid = 'resources-map',
123 # tab's sons preferably turn this off
126 query_all = query_resource_all,
134 resources_as_list = Hazelnut(
136 domid = 'resources-list',
137 # this is the query at the core of the slice list
139 query_all = query_resource_all,
141 datatables_options = {
142 'iDisplayLength': 25,
143 'bLengthChange' : True,
148 resources_query_editor = QueryEditor(
150 query = query_resource_all,
151 title = "Select Columns",
153 resources_active_filters = ActiveFilters(
156 title = "Active Filters ?",
159 # List area itself is a Stack with hazelnut on top,
160 # and a togglable tabs for customization plugins
161 resources_as_list_area = Stack(
163 title = 'Resources as a List',
164 domid = 'resources-list-area',
165 sons= [ resources_as_list,
167 title="Customize Resources layout",
169 toggled='persistent',
170 domid="customize-resources",
171 outline_complete=True,
172 sons = [ resources_query_editor, resources_active_filters, ],
176 resources_area = Tabs ( page=page,
180 outline_complete=True,
181 sons=[ resources_as_map, resources_as_list_area, ],
182 active_domid = 'resources-map',
184 main_stack.insert (resources_area)
187 # --------------------------------------------------------------------------
194 outline_complete = True,
197 active_domid = 'users-list',
199 main_stack.insert(tab_users)
201 tab_users.insert(Hazelnut(
203 title = 'Users List',
204 domid = 'users-list',
205 # tab's sons preferably turn this off
207 # this is the query at the core of the slice list
209 query_all = query_user_all,
211 datatables_options = {
212 'iDisplayLength' : 25,
213 'bLengthChange' : True,
218 # --------------------------------------------------------------------------
220 tab_measurements = Tabs (
222 active_domid = 'measurements-list',
223 outline_complete = True,
225 title = 'Measurements',
226 domid = 'measurements',
228 main_stack.insert(tab_measurements)
230 tab_measurements.insert(Hazelnut(
232 title = 'Measurements',
233 domid = 'measurements-list',
234 # tab's sons preferably turn this off
236 # this is the query at the core of the slice list
237 query = sq_measurement,
238 # do NOT set checkboxes to False
239 # this table being otherwise empty, it just does not fly with dataTables
241 datatables_options = {
242 'iDisplayLength' : 25,
243 'bLengthChange' : True,
248 # --------------------------------------------------------------------------
249 # MESSAGES (we use transient=False for now)
250 main_stack.insert(Messages(
252 title = "Runtime messages for slice %s"%slicename,
255 # plain messages are probably less nice for production but more reliable for development for now
257 # these make sense only in non-transient mode..
259 toggled = 'persistent',
260 outline_complete = True,
264 # variables that will get passed to the view-unfold1.html template
267 # define 'unfold1_main' to the template engine - the main contents
268 template_env [ 'unfold1_main' ] = main_stack.render(request)
270 # more general variables expected in the template
271 template_env [ 'title' ] = '%(slicename)s'%locals()
272 # the menu items on the top
273 template_env [ 'topmenu_items' ] = topmenu_items('Slice', request)
274 # so we can sho who is logged
275 template_env [ 'username' ] = the_user (request)
277 # don't forget to run the requests
278 page.expose_queries ()
280 # xxx create another plugin with the same query and a different layout (with_datatables)
281 # show that it worls as expected, one single api call to backend and 2 refreshed views
283 # the prelude object in page contains a summary of the requirements() for all plugins
284 # define {js,css}_{files,chunks}
285 prelude_env = page.prelude_env()
286 template_env.update(prelude_env)
287 result=render_to_response ('view-unfold1.html',template_env,
288 context_instance=RequestContext(request))