Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / vigiboard_plugin / shn.py @ 8484b8bd

History | View | Annotate | Download (2.4 KB)

1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4: 
3
"""
4
Plugin SHN : High level service
5
"""
6

    
7
from vigiboard.controllers.vigiboard_plugin import \
8
        VigiboardRequestPlugin
9
from vigiboard.model import DBSession, ServiceHautNiveau, Event
10
from sqlalchemy import sql
11
from pylons.i18n import gettext as _
12
from tg import tmpl_context, url
13
from tw.jquery.ui_dialog import JQueryUIDialog
14

    
15
class PluginSHN(VigiboardRequestPlugin):
16

    
17
    """
18
    Plugin permettant de rajouter le nombre de SHNs impactés à
19
    l'affichage
20
    """
21

    
22
    def __init__(self):
23
        super(PluginSHN, self).__init__(
24
            table = [ServiceHautNiveau.servicename_dep,
25
                sql.func.count(Event.idevent)],
26
            outerjoin = [(ServiceHautNiveau,
27
                ServiceHautNiveau.servicename_dep == Event.servicename)],
28
            groupby = [(Event),(ServiceHautNiveau.servicename_dep)],
29
            name = _(u'Impacted HLS'),
30
            style = {'title': _(u'Impacted High-Level Services'),
31
                'style': 'text-align:center'},
32
            object_name = "shn"
33
        )
34
    
35
    def show(self, req):
36
        """Fonction d'affichage"""
37
        if not req[1] is None:
38
            dico = {
39
                'baseurl': url('/'),
40
                'idevent': req[0].idcause,
41
                'impacted_hls': req[2],
42
            }
43
            return '<a href="javascript:vigiboard_shndialog(\'%(baseurl)s\','\
44
                    '\'%(idevent)s\')" class="SHNLien">%(impacted_hls)d</a>' % \
45
                    dico
46
        else:
47
            return ""
48

    
49
    def context(self, context):
50
        """Fonction de context"""
51

    
52
        # XXX We insert 10 unbreakable spaces (&#160;) to workaround a bug
53
        # in JQuery where the dialog's width is incorrectly set.
54
        tmpl_context.shndialog = JQueryUIDialog(id='SHNDialog',
55
                autoOpen=False, title='%s%s' % (_(u'High-Level Service'),
56
                '&#160;' * 10))
57
        context.append([tmpl_context.shndialog, self.object_name])
58

    
59
    def controller(self, *argv, **krgv):
60
        """Ajout de fonctionnalités au contrôleur"""
61
        idevent = krgv['idevent']
62
        service = DBSession.query(Event.servicename
63
                ).filter(Event.idevent == idevent).one().servicename
64

    
65
        shns = DBSession.query(ServiceHautNiveau.servicename
66
                ).filter(ServiceHautNiveau.servicename_dep == service)
67
        return dict( shns = [shn.servicename for shn in shns]) 
68