Revision 8ad24667
Ajout de fonctionnalités pour les plugins de Vigiboard
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@517 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigiboard/controllers/root.py | ||
---|---|---|
109 | 109 |
page = page, |
110 | 110 |
event_edit_status_options = edit_event_status_options, |
111 | 111 |
history = [], |
112 |
hist_error = False |
|
112 |
hist_error = False, |
|
113 |
plugin_context = events.context_fct |
|
113 | 114 |
) |
114 | 115 |
|
115 | 116 |
@validate(validators={'idevent':validators.Int(not_empty=True)}, |
... | ... | |
161 | 162 |
{'idevent': events.idevent,'host': events.hostname, 'service': events.servicename}, |
162 | 163 |
servicetype_link = tg.config['vigiboard_links.servicetype'] % \ |
163 | 164 |
{'idevent': events.idevent,'host': events.hostname, 'service': events.servicename} |
165 |
|
|
164 | 166 |
) |
165 | 167 |
|
166 | 168 |
@validate(validators={'idevent':validators.Int(not_empty=True)}, |
... | ... | |
196 | 198 |
page = 1, |
197 | 199 |
event_edit_status_options = edit_event_status_options, |
198 | 200 |
history = events.hist, |
199 |
hist_error = True |
|
201 |
hist_error = True, |
|
202 |
plugin_context = events.context_fct |
|
200 | 203 |
) |
201 | 204 |
|
202 | 205 |
@validate(validators={'host':validators.NotEmpty(), |
... | ... | |
235 | 238 |
page = 1, |
236 | 239 |
event_edit_status_options = edit_event_status_options, |
237 | 240 |
history = events.hist, |
238 |
hist_error = True |
|
241 |
hist_error = True, |
|
242 |
plugin_context = events.context_fct |
|
239 | 243 |
) |
240 | 244 |
|
241 | 245 |
@validate(validators={ |
... | ... | |
302 | 306 |
redirect(request.environ.get('HTTP_REFERER').split( |
303 | 307 |
request.environ.get('HTTP_HOST')+tg.config['base_url_filter.base_url'])[1]) |
304 | 308 |
|
309 |
|
|
310 |
@validate(validators={"plugin_name":validators.OneOf( |
|
311 |
[i for [i,j] in tg.config['vigiboard_plugins']])}, |
|
312 |
error_handler=process_form_errors) |
|
313 |
@expose('json') |
|
314 |
def get_plugin_value(self,plugin_name,*arg,**krgv): |
|
315 |
""" |
|
316 |
Permet aux plugins de pouvoir récupérer des valeurs Json |
|
317 |
""" |
|
318 |
plugin = [i for i in tg.config['vigiboard_plugins'] if i[0] == plugin_name][0] |
|
319 |
try: |
|
320 |
mypac = __import__( |
|
321 |
'vigiboard.controllers.vigiboard_plugin.' +\ |
|
322 |
plugin[0],globals(), locals(), [plugin[1]],-1) |
|
323 |
p = getattr(mypac,plugin[1])() |
|
324 |
return p.controller(*arg,**krgv) |
|
325 |
except: |
|
326 |
raise |
vigiboard/controllers/vigiboard_plugin/__init__.py | ||
---|---|---|
9 | 9 |
|
10 | 10 |
def __init__ (self, table = None, join = None, outerjoin = None, |
11 | 11 |
filters = None, groupby = None, orderby = None, name = '', |
12 |
style = None): |
|
12 |
style = None, object_name = ""):
|
|
13 | 13 |
|
14 | 14 |
self.table = table |
15 | 15 |
self.join = join |
... | ... | |
19 | 19 |
self.name = name |
20 | 20 |
self.groupby = groupby |
21 | 21 |
self.style = style |
22 |
self.object_name = object_name |
|
22 | 23 |
|
23 | 24 |
def __show__ (self, event): |
24 | 25 |
|
... | ... | |
47 | 48 |
|
48 | 49 |
return '' |
49 | 50 |
|
51 |
def context(self,context): |
|
52 |
|
|
53 |
""" |
|
54 |
Fonction permettant de rajouter du context à la page d'évènements, |
|
55 |
comme par exemple un css ou une fonction Javascript |
|
56 |
""" |
|
57 |
|
|
58 |
pass |
|
59 |
|
|
60 |
|
|
61 |
def controller(self): |
|
62 |
|
|
63 |
""" |
|
64 |
Fonction permettant de rajouter un pseudo controller pour le plugin. |
|
65 |
Ceci permet par exemple de faire de appels json |
|
66 |
""" |
|
67 |
|
|
68 |
pass |
vigiboard/controllers/vigiboard_plugin/shn.py | ||
---|---|---|
3 | 3 |
|
4 | 4 |
from vigiboard.controllers.vigiboard_plugin import \ |
5 | 5 |
VigiboardRequestPlugin |
6 |
from vigiboard.model import ServiceHautNiveau, Events
|
|
6 |
from vigiboard.model import DBSession, ServiceHautNiveau, Events, Service
|
|
7 | 7 |
from sqlalchemy import sql, asc |
8 | 8 |
from pylons.i18n import ugettext as _ |
9 |
from tg import tmpl_context,config,url |
|
10 |
from tw.jquery.ui_dialog import JQueryUIDialog |
|
9 | 11 |
|
10 | 12 |
class PluginSHN (VigiboardRequestPlugin): |
11 | 13 |
|
... | ... | |
22 | 24 |
ServiceHautNiveau.servicename_dep == Events.servicename)], |
23 | 25 |
groupby = [(Events),(ServiceHautNiveau.servicename_dep)], |
24 | 26 |
name = _(u'SHNs impacté'), |
25 |
style = {'style':'text-align:center'} |
|
27 |
style = {'style':'text-align:center'}, |
|
28 |
object_name = "shn" |
|
26 | 29 |
) |
27 | 30 |
|
28 | 31 |
def show(self, req): |
29 | 32 |
"""Fonction d'affichage""" |
30 | 33 |
if req[1] : |
31 |
return req[2]
|
|
34 |
return '<a href="javascript:vigiboard_shndialog(\'%s\',\'%d\')" class="SHNLien">%s</a>' % (url(''), req[0].idevent, req[2])
|
|
32 | 35 |
else : |
33 |
return None |
|
36 |
return "" |
|
37 |
|
|
38 |
def context(self,context): |
|
39 |
"""Fonction de context""" |
|
40 |
|
|
41 |
tmpl_context.shndialog = JQueryUIDialog(id='SHNDialog', |
|
42 |
autoOpen=False,title='%s%s' % (_('Service de haut niveau'),' ')) |
|
43 |
context.append([tmpl_context.shndialog,self.object_name]) |
|
44 |
|
|
45 |
def controller(self,*argv,**krgv): |
|
46 |
idevent = krgv['idevent'] |
|
47 |
e = DBSession.query(Events.servicename).filter(Events.idevent == idevent) |
|
48 |
s = e.one().servicename |
|
49 |
e = DBSession.query(ServiceHautNiveau.servicename).filter(ServiceHautNiveau.servicename_dep == s) |
|
50 |
return dict( shns = [ee.servicename for ee in e]) |
|
51 |
|
vigiboard/controllers/vigiboardrequest.py | ||
---|---|---|
66 | 66 |
self.idevents = [] |
67 | 67 |
self.hist = [] |
68 | 68 |
self.req = DBSession |
69 |
self.context_fct = [] |
|
69 | 70 |
|
70 | 71 |
def add_plugin(self, *argv): |
71 | 72 |
|
... | ... | |
427 | 428 |
# Dialogue de détail d'un évènement |
428 | 429 |
tmpl_context.historydialog = JQueryUIDialog(id='HistoryDialog', |
429 | 430 |
autoOpen=False,title=_('History')) |
431 |
|
|
432 |
# Exécution des contexts des plugins |
|
433 |
for j in self.plugin: |
|
434 |
j.context(self.context_fct) |
vigiboard/public/javascript/vigiboard_plugin/shn.js | ||
---|---|---|
1 |
|
|
2 |
function vigiboard_shndialog(url,idd) { |
|
3 |
$.getJSON(url+'/get_plugin_value',{plugin_name:'shn',idevent:idd},function(json){ |
|
4 |
var ht = ''; |
|
5 |
for (var i = 0; i < json.shns.length; i++) { |
|
6 |
ht += '<li>' + json.shns[i] + '</li>'; |
|
7 |
} |
|
8 |
$('#SHNDialog_liste').html(ht); |
|
9 |
$('#SHNDialog').dialog('open'); |
|
10 |
}) |
|
11 |
} |
|
12 |
$('.SHNLien').each(function() { |
|
13 |
$(this).click(function(e){ |
|
14 |
$('#SHNDialog').dialog('option','position',[e.clientX+10,e.clientY]); |
|
15 |
})}); |
vigiboard/templates/vigiboard_event_table.html | ||
---|---|---|
2 | 2 |
xmlns:xi="http://www.w3.org/2001/XInclude" |
3 | 3 |
py:strip=""> |
4 | 4 |
|
5 |
|
|
6 |
|
|
5 | 7 |
<py:def function="event_table(events,page,pages,id_first_row,id_last_row,total_row,edit_event_status_options)"> |
6 | 8 |
<?python from genshi import HTML ?> |
7 | 9 |
|
... | ... | |
48 | 50 |
<td>${event.hostname}</td> |
49 | 51 |
<td>${event.servicename}</td> |
50 | 52 |
<td>${event.output}</td> |
51 |
<td py:for="plug in plugin" py:attrs="plug[1]">${plug[0]}</td>
|
|
53 |
<td py:for="plug in plugin" py:attrs="plug[1]">${HTML(plug[0])}</td>
|
|
52 | 54 |
<td>${event.trouble_ticket}</td> |
53 | 55 |
<td><img py:attrs="img_statu" py:if="img_statu != None" /></td> |
54 | 56 |
<td py:attrs="class_td_date"><a class="Edit_EventsLien" href="javascript:vigiboard_edit_eventdialog('${event.idevent}')"><img src="${tg.url('/images/icon_page_edit.png')}" /></a></td> |
... | ... | |
61 | 63 |
|
62 | 64 |
</table> |
63 | 65 |
|
64 |
${tmpl_context.historydialog()} |
|
65 | 66 |
${tmpl_context.edit_eventdialog()} |
66 |
${tmpl_context.searchdialog()} |
|
67 |
${tmpl_context.searchdialog} |
|
68 |
${tmpl_context.historydialog} |
|
69 |
<py:for each="fct,tpl in plugin_context"> |
|
70 |
${fct()} |
|
71 |
<xi:include href="vigiboard_plugin/${tpl}.html" /> |
|
72 |
</py:for> |
|
67 | 73 |
|
68 | 74 |
<script type="text/javascript"> |
69 | 75 |
function vigiboard_historydialog(idd) { |
vigiboard/templates/vigiboard_plugin/shn.html | ||
---|---|---|
1 |
<html xmlns:py="http://genshi.edgewall.org/" |
|
2 |
xmlns:xi="http://www.w3.org/2001/XInclude" |
|
3 |
py:strip=""> |
|
4 |
|
|
5 |
|
|
6 |
<div id="SHNDialog"> |
|
7 |
<ul id="SHNDialog_liste" /> |
|
8 |
</div> |
|
9 |
|
|
10 |
<script type="text/javascript" src="${tg.url('/javascript/vigiboard_plugin/shn.js')}" ></script> |
|
11 |
|
|
12 |
</html> |
Also available in: Unified diff