ui_viewport.py 8.66 KB
Newer Older
LE GAC Renaud's avatar
LE GAC Renaud committed
1 2 3 4 5 6 7
# -*- coding: utf-8 -*-
"""Main user interface the viewport

"""
import plugin_dbui as dbui


8
from event import Event
LE GAC Renaud's avatar
LE GAC Renaud committed
9 10 11
from gluon import current
from gluon.html import URL

12 13 14 15 16
from plugin_dbui import (Node,
                         Panel,
                         to_gridPanel)

from ui_selector import SelectorUi
LE GAC Renaud's avatar
LE GAC Renaud committed
17 18


19
class ViewportUi(object):
LE GAC Renaud's avatar
LE GAC Renaud committed
20

21
    @staticmethod
22
    def configure(db, T, virtdb):
23
        """Configure the viewport.
LE GAC Renaud's avatar
LE GAC Renaud committed
24

25 26 27
        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator
28 29
            virtdb (pyDAL.DAL):
                virtual database with the definiton of selectors
LE GAC Renaud's avatar
LE GAC Renaud committed
30

31
        """
32 33 34 35
        selector_list = SelectorUi.selector_list(virtdb, db, T)
        selector_metric2d = SelectorUi.selector_metric2d(virtdb, db, T)
        selector_source = SelectorUi.selector_source(virtdb, db, T)

LE GAC Renaud's avatar
LE GAC Renaud committed
36
        nodes = [
37 38
            ViewportUi.help_node(db, T),
            ViewportUi.app_node(db, T),
39
            ViewportUi.event_node(db, T),
40
            ViewportUi.meta_node(db, T),
41
            ViewportUi.people_object_node(db, T),
42
            ViewportUi.configure_node(db, T),
43
            ViewportUi.source_node(db, T, selector_source),
44
            ViewportUi.list_node(db, T, selector_list),
45
            ViewportUi.metric2d_node(db, T, selector_metric2d)]
LE GAC Renaud's avatar
LE GAC Renaud committed
46 47 48 49 50 51 52

        modifier = dbui.ViewportModifier()
        modifier.add_node(*nodes)

        modifier.configure(tabTitleTpl="{1}")

        if current.session.auth:
53
            modifier.configure(logged=True, plugins=["pViewportLogin"])
LE GAC Renaud's avatar
LE GAC Renaud committed
54

55
        modifier.default_node(T("Events"), T("history"))
LE GAC Renaud's avatar
LE GAC Renaud committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

    @staticmethod
    def app_node(db, T):
        """To deal with authentication and preferences.

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        Returns:
            dbui.Node:
                the configuration of a tree node.
        """
        node = None

71
        if "auth" in current.globalenv:
LE GAC Renaud's avatar
LE GAC Renaud committed
72

73
            node = Node(T("Application"))
LE GAC Renaud's avatar
LE GAC Renaud committed
74 75 76

            add_child = node.add_child

77 78 79 80 81 82
            add_child(T("users"), to_gridPanel(db.auth_user))
            add_child(T("groups"), to_gridPanel(db.auth_group))

            add_child(
                T("relation user / groups"),
                to_gridPanel(db.auth_membership))
LE GAC Renaud's avatar
LE GAC Renaud committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

        return node

    @staticmethod
    def help_node(db, T):
        """To deal with documentation and version.

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        Returns:
            dbui.Node:
                the configuration of a tree node.
        """
        loader = dict(autoLoad=True,
99 100
                      renderer="html",
                      url=URL("plugin_dbui", "about"))
LE GAC Renaud's avatar
LE GAC Renaud committed
101

102
        about_panel = Panel(loader=loader, autoScroll=True)
LE GAC Renaud's avatar
LE GAC Renaud committed
103 104

        loader = dict(autoLoad=True,
105
                      renderer="html",
106
                      url=URL("plugin_dbui", "documentations_list"))
LE GAC Renaud's avatar
LE GAC Renaud committed
107

108
        doc_panel = Panel(loader=loader, plugins=["pPanelLoaderException"])
LE GAC Renaud's avatar
LE GAC Renaud committed
109 110

        loader = dict(autoLoad=True,
111
                      renderer="html",
LE GAC Renaud's avatar
LE GAC Renaud committed
112
                      scripts=True,
113
                      url=URL("plugin_dbui", "versions"))
LE GAC Renaud's avatar
LE GAC Renaud committed
114

115
        version_panel = Panel(loader=loader, plugins=["pPanelLoaderException"])
LE GAC Renaud's avatar
LE GAC Renaud committed
116

117
        node = Node(T("Help"))
LE GAC Renaud's avatar
LE GAC Renaud committed
118

LE GAC Renaud's avatar
LE GAC Renaud committed
119 120 121
        # NOTE
        # Immediate translation is required by node.short_children

LE GAC Renaud's avatar
LE GAC Renaud committed
122
        add_child = node.add_child
LE GAC Renaud's avatar
LE GAC Renaud committed
123 124 125
        add_child(T("about", lazy=False), about_panel)
        add_child(T("documentations", lazy=False), doc_panel)
        add_child(T("versions", lazy=False), version_panel)
LE GAC Renaud's avatar
LE GAC Renaud committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

        node.sort_children()

        return node

    @staticmethod
    def configure_node(db, T):
        """To configure lists and metrics.

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        Returns:
            dbui.Node:
                the configuration of a tree node.
        """
143
        node = Node(T("Configure lists and metrics"))
LE GAC Renaud's avatar
LE GAC Renaud committed
144 145

        add_child = node.add_child
146 147
        add_child(T("the lists"), to_gridPanel(db.lists2))
        add_child(T("the metrics 2d"), to_gridPanel(db.metrics2d2))
LE GAC Renaud's avatar
LE GAC Renaud committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

        return node

    @staticmethod
    def event_node(db, T):
        """To deal with event.

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        Returns:
            dbui.Node:
                the configuration of a tree node.
        """
163
        node = Node(T("Events"))
LE GAC Renaud's avatar
LE GAC Renaud committed
164 165

        add_child = node.add_child
166 167
        add_child(T("definitions"), to_gridPanel(db.events))
        add_child(T("history"), to_gridPanel(db.history))
LE GAC Renaud's avatar
LE GAC Renaud committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

        return node

    @staticmethod
    def meta_node(db, T):
        """To deal with meta data.

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        Returns:
            dbui.Node:
                the configuration of a tree node.
        """
183
        node = Node(T("Metadata"))
LE GAC Renaud's avatar
LE GAC Renaud committed
184

LE GAC Renaud's avatar
LE GAC Renaud committed
185 186 187
        # NOTE
        # Immediate translation is required by node.short_children

LE GAC Renaud's avatar
LE GAC Renaud committed
188
        add_child = node.add_child
189 190 191 192
        add_child(T("domains", lazy=False), to_gridPanel(db.domains))
        add_child(T("fundings", lazy=False), to_gridPanel(db.fundings))
        add_child(T("teams", lazy=False), to_gridPanel(db.teams))
        add_child(T("projects", lazy=False), to_gridPanel(db.projects))
LE GAC Renaud's avatar
LE GAC Renaud committed
193 194 195 196 197 198

        node.sort_children()

        return node

    @staticmethod
199 200
    def list_node(db, T, selector_panel):
        """To deal with lists.
LE GAC Renaud's avatar
LE GAC Renaud committed
201 202 203 204

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator
205 206
            selector_panel (gluon.storage.Storage):
                configuration of the selector panel.
LE GAC Renaud's avatar
LE GAC Renaud committed
207 208 209 210 211

        Returns:
            dbui.Node:
                the configuration of a tree node.
        """
212
        node = Node(T("The lists"))
LE GAC Renaud's avatar
LE GAC Renaud committed
213

LE GAC Renaud's avatar
LE GAC Renaud committed
214
        add_child = node.add_child
LE GAC Renaud's avatar
LE GAC Renaud committed
215

216
        for row in db(db.lists2.id > 0).select(orderby=db.lists2.name):
LE GAC Renaud's avatar
LE GAC Renaud committed
217

218 219 220
            panel = selector_panel
            panel.baseUrl = URL("plugin_event", "grid")
            panel.baseParams = {"id_list": row.id}
LE GAC Renaud's avatar
LE GAC Renaud committed
221

222
            add_child(row.name, panel)
LE GAC Renaud's avatar
LE GAC Renaud committed
223 224 225 226

        return node

    @staticmethod
227 228
    def metric2d_node(db, T, selector_panel):
        """To deal with two-dimension metrics.
LE GAC Renaud's avatar
LE GAC Renaud committed
229 230 231 232 233 234 235 236 237 238 239

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator
            selector_panel (gluon.storage.Storage):
                configuration of the selector panel.

        Returns:
            dbui.Node:
                the configuration of a tree node.
        """
240
        node = Node(T("The metrics 2d"))
LE GAC Renaud's avatar
LE GAC Renaud committed
241 242 243

        add_child = node.add_child

244
        for row in db(db.metrics2d2.id > 0).select(orderby=db.metrics2d2.name):
LE GAC Renaud's avatar
LE GAC Renaud committed
245 246

            panel = selector_panel
247 248
            panel.baseUrl = URL("plugin_event", "metric2d")
            panel.baseParams = {"id_metric2d": row.id}
LE GAC Renaud's avatar
LE GAC Renaud committed
249 250 251 252 253

            add_child(row.name, panel)

        return node

LE GAC Renaud's avatar
LE GAC Renaud committed
254
    @staticmethod
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
    def people_object_node(db, T):
        """To deal with people and objects.

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        Returns:
            dbui.Node:
                the configuration of a tree node.
        """
        node = Node(T("People and objects"))

        # NOTE
        # Immediate translation is required by node.short_children

        add_child = node.add_child
272
        add_child(T("people", lazy=False), to_gridPanel(db.people))
273

274 275 276
        add_child(
            T("people_categories", lazy=False),
            to_gridPanel(db.people_categories))
277

278
        add_child(T("objects", lazy=False), to_gridPanel(db.objects))
279

280 281 282
        add_child(
            T("object_categories", lazy=False),
            to_gridPanel(db.object_categories))
283 284 285 286 287 288 289 290

        node.sort_children()

        return node

    @staticmethod
    def source_node(db, T, selector_panel):
        """To deal with sources.
291 292 293 294 295 296 297 298 299 300 301

        Args:
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator
            selector_panel (gluon.storage.Storage):
                configuration of the selector panel.

        Returns:
            dbui.Node:
                the configuration of a tree node.
        """
302
        node = Node(T("The sources"))
303 304 305

        add_child = node.add_child

306
        for source in sorted(Event.get_sources()):
307 308

            panel = selector_panel
309 310
            panel.baseUrl = URL("plugin_event", "source")
            panel.baseParams = {"source": source}
311

312
            add_child(source, panel)
313 314

        return node