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 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"))
41 page.add_js_chunks ('$(function() { messages.debug("manifold URL %s"); });'%(config.manifold_url()))
42 page.expose_js_metadata()
44 metadata = page.get_metadata()
45 resource_md = metadata.details_by_object('resource')
46 resource_fields = [column['name'] for column in resource_md['column']]
48 user_md = metadata.details_by_object('user')
49 user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
51 # TODO The query to run is embedded in the URL
52 main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
55 'resource.hrn', 'resource.hostname', 'resource.type',
56 'resource.network_hrn',
59 #'application.measurement_point.counter'
62 query_resource_all = Query.get('resource').select(resource_fields)
64 query_user_all = Query.get('user').select(user_fields)
66 aq = AnalyzedQuery(main_query, metadata=metadata)
67 page.enqueue_query(main_query, analyzed_query=aq)
68 page.enqueue_query(query_resource_all)
70 page.enqueue_query(query_user_all)
72 # ... and for the relations
73 # XXX Let's hardcode resources for now
74 sq_resource = aq.subquery('resource')
75 sq_user = aq.subquery('user')
76 sq_lease = aq.subquery('lease')
77 sq_measurement = aq.subquery('measurement')
80 # Prepare the display according to all metadata
81 # (some parts will be pending, others can be triggered by users).
83 # For example slice measurements will not be requested by default...
85 # Create the base layout (Stack)...
88 title="Slice %s"%slicename,
92 # ... responsible for the slice properties...
99 html="<h2 class='well well-lg'> Slice %s</h2>"%slicename)
102 # --------------------------------------------------------------------------
103 # ResourcesSelected (Pending Operations)
105 main_stack.insert(ResourcesSelected(
107 title = 'Pending operations',
110 # start turned off, it will open up itself when stuff comes in
113 outline_complete = True,
116 # --------------------------------------------------------------------------
119 filter_query_editor = QueryEditor(
122 query_all = query_resource_all,
123 title = "Select Columns",
124 domid = 'select-columns',
126 filter_active_filters = ActiveFilters(
129 title = "Active Filters",
131 filters_area = Stack(
133 title = 'Filter Resources',
135 sons = [filter_query_editor, filter_active_filters],
137 toggled = 'persistent',
138 outline_complete = True,
140 main_stack.insert (filters_area)
142 # --------------------------------------------------------------------------
144 # the resources part is made of a Tabs (Geographic, List),
146 resources_as_map = GoogleMap(
148 title = 'Geographic view',
149 domid = 'resources-map',
150 # tab's sons preferably turn this off
153 query_all = query_resource_all,
161 resources_as_list = Hazelnut(
163 domid = 'resources-list',
165 # this is the query at the core of the slice list
167 query_all = query_resource_all,
169 datatables_options = {
170 'iDisplayLength': 25,
171 'bLengthChange' : True,
176 # with the new 'Filter' stuff on top, no need for anything but the hazelnut
177 resources_as_list_area = resources_as_list
179 resources_area = Tabs ( page=page,
183 outline_complete=True,
184 sons=[ resources_as_map, resources_as_list_area, ],
185 active_domid = 'resources-map',
187 main_stack.insert (resources_area)
190 # --------------------------------------------------------------------------
197 outline_complete = True,
200 active_domid = 'users-list',
202 main_stack.insert(tab_users)
204 tab_users.insert(Hazelnut(
206 title = 'Users List',
207 domid = 'users-list',
208 # tab's sons preferably turn this off
210 # this is the query at the core of the slice list
212 query_all = query_user_all,
214 datatables_options = {
215 'iDisplayLength' : 25,
216 'bLengthChange' : True,
221 # --------------------------------------------------------------------------
223 # tab_measurements = Tabs (
225 # active_domid = 'measurements-list',
226 # outline_complete = True,
228 # title = 'Measurements',
229 # domid = 'measurements',
231 # main_stack.insert(tab_measurements)
233 # tab_measurements.insert(Hazelnut(
235 # title = 'Measurements',
236 # domid = 'measurements-list',
237 # # tab's sons preferably turn this off
239 # # this is the query at the core of the slice list
240 # query = sq_measurement,
241 # # do NOT set checkboxes to False
242 # # this table being otherwise empty, it just does not fly with dataTables
244 # datatables_options = {
245 # 'iDisplayLength' : 25,
246 # 'bLengthChange' : True,
247 # 'bAutoWidth' : True,
251 # # --------------------------------------------------------------------------
252 # # MESSAGES (we use transient=False for now)
253 # main_stack.insert(Messages(
255 # title = "Runtime messages for slice %s"%slicename,
256 # domid = "msgs-pre",
258 # # plain messages are probably less nice for production but more reliable for development for now
260 # # these make sense only in non-transient mode..
262 # toggled = 'persistent',
263 # outline_complete = True,
267 # variables that will get passed to the view-unfold1.html template
270 # define 'unfold1_main' to the template engine - the main contents
271 template_env [ 'unfold1_main' ] = main_stack.render(request)
273 # more general variables expected in the template
274 template_env [ 'title' ] = '%(slicename)s'%locals()
275 # the menu items on the top
276 template_env [ 'topmenu_items' ] = topmenu_items('Slice', request)
277 # so we can sho who is logged
278 template_env [ 'username' ] = the_user (request)
280 # don't forget to run the requests
281 page.expose_queries ()
283 # xxx create another plugin with the same query and a different layout (with_datatables)
284 # show that it worls as expected, one single api call to backend and 2 refreshed views
286 # the prelude object in page contains a summary of the requirements() for all plugins
287 # define {js,css}_{files,chunks}
288 prelude_env = page.prelude_env()
289 template_env.update(prelude_env)
290 result=render_to_response ('view-unfold1.html',template_env,
291 context_instance=RequestContext(request))