ui_viewport.py 8.5 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
from gluon import current
from gluon.html import URL
11
from ui_selector import SelectorUi
LE GAC Renaud's avatar
LE GAC Renaud committed
12 13 14

Node = dbui.Node
Panel = dbui.Panel
15
to_grid = dbui.to_gridPanel
LE GAC Renaud's avatar
LE GAC Renaud committed
16 17


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

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

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

30
        """
31 32 33 34
        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
35
        nodes = [
36 37
            ViewportUi.help_node(db, T),
            ViewportUi.app_node(db, T),
38
            ViewportUi.event_node(db, T),
39
            ViewportUi.meta_node(db, T),
40
            ViewportUi.people_object_node(db, T),
41
            ViewportUi.configure_node(db, T),
42
            ViewportUi.source_node(db, T, selector_source),
43
            ViewportUi.list_node(db, T, selector_list),
44
            ViewportUi.metric2d_node(db, T, selector_metric2d)]
LE GAC Renaud's avatar
LE GAC Renaud committed
45 46 47 48 49 50 51

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

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

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

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

    @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

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

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

            add_child = node.add_child

76 77 78
            add_child(T("users"), to_grid(db.auth_user))
            add_child(T("groups"), to_grid(db.auth_group))
            add_child(T("relation user / groups"), to_grid(db.auth_membership))
LE GAC Renaud's avatar
LE GAC Renaud committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

        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,
95 96
                      renderer="html",
                      url=URL("plugin_dbui", "about"))
LE GAC Renaud's avatar
LE GAC Renaud committed
97

98
        about_panel = Panel(loader=loader, autoScroll=True)
LE GAC Renaud's avatar
LE GAC Renaud committed
99 100

        loader = dict(autoLoad=True,
101
                      renderer="html",
102
                      url=URL("plugin_dbui", "documentations_list"))
LE GAC Renaud's avatar
LE GAC Renaud committed
103

104
        doc_panel = Panel(loader=loader, plugins=["pPanelLoaderException"])
LE GAC Renaud's avatar
LE GAC Renaud committed
105 106

        loader = dict(autoLoad=True,
107
                      renderer="html",
LE GAC Renaud's avatar
LE GAC Renaud committed
108
                      scripts=True,
109
                      url=URL("plugin_dbui", "versions"))
LE GAC Renaud's avatar
LE GAC Renaud committed
110

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

113
        node = Node(T("Help"))
LE GAC Renaud's avatar
LE GAC Renaud committed
114

LE GAC Renaud's avatar
LE GAC Renaud committed
115 116 117
        # NOTE
        # Immediate translation is required by node.short_children

LE GAC Renaud's avatar
LE GAC Renaud committed
118
        add_child = node.add_child
LE GAC Renaud's avatar
LE GAC Renaud committed
119 120 121
        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
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

        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.
        """
139
        node = Node(T("Configure lists and metrics"))
LE GAC Renaud's avatar
LE GAC Renaud committed
140 141

        add_child = node.add_child
142 143
        add_child(T("the lists"), to_grid(db.lists2))
        add_child(T("the metrics 2d"), to_grid(db.metrics2d2))
LE GAC Renaud's avatar
LE GAC Renaud committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

        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.
        """
159
        node = Node(T("Events"))
LE GAC Renaud's avatar
LE GAC Renaud committed
160 161

        add_child = node.add_child
162 163
        add_child(T("definitions"), to_grid(db.events))
        add_child(T("history"), to_grid(db.history))
LE GAC Renaud's avatar
LE GAC Renaud committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178

        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.
        """
179
        node = Node(T("Metadata"))
LE GAC Renaud's avatar
LE GAC Renaud committed
180

LE GAC Renaud's avatar
LE GAC Renaud committed
181 182 183
        # NOTE
        # Immediate translation is required by node.short_children

LE GAC Renaud's avatar
LE GAC Renaud committed
184
        add_child = node.add_child
LE GAC Renaud's avatar
LE GAC Renaud committed
185 186 187 188
        add_child(T("domains", lazy=False), to_grid(db.domains))
        add_child(T("fundings", lazy=False), to_grid(db.fundings))
        add_child(T("teams", lazy=False), to_grid(db.teams))
        add_child(T("projects", lazy=False), to_grid(db.projects))
LE GAC Renaud's avatar
LE GAC Renaud committed
189 190 191 192 193 194

        node.sort_children()

        return node

    @staticmethod
195 196
    def list_node(db, T, selector_panel):
        """To deal with lists.
LE GAC Renaud's avatar
LE GAC Renaud committed
197 198 199 200

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

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

LE GAC Renaud's avatar
LE GAC Renaud committed
210
        add_child = node.add_child
LE GAC Renaud's avatar
LE GAC Renaud committed
211

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

214 215 216
            panel = selector_panel
            panel.baseUrl = URL("plugin_event", "grid")
            panel.baseParams = {"id_list": row.id}
LE GAC Renaud's avatar
LE GAC Renaud committed
217

218
            add_child(row.name, panel)
LE GAC Renaud's avatar
LE GAC Renaud committed
219 220 221 222

        return node

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

        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.
        """
236
        node = Node(T("The metrics 2d"))
LE GAC Renaud's avatar
LE GAC Renaud committed
237 238 239

        add_child = node.add_child

240
        for row in db(db.metrics2d2.id > 0).select(orderby=db.metrics2d2.name):
LE GAC Renaud's avatar
LE GAC Renaud committed
241 242

            panel = selector_panel
243 244
            panel.baseUrl = URL("plugin_event", "metric2d")
            panel.baseParams = {"id_metric2d": row.id}
LE GAC Renaud's avatar
LE GAC Renaud committed
245 246 247 248 249

            add_child(row.name, panel)

        return node

LE GAC Renaud's avatar
LE GAC Renaud committed
250
    @staticmethod
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
    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
        add_child(T("people", lazy=False), to_grid(db.people))

        add_child(T("people_categories", lazy=False),
                  to_grid(db.people_categories))

        add_child(T("objects", lazy=False), to_grid(db.objects))

        add_child(T("object_categories", lazy=False),
                  to_grid(db.object_categories))

        node.sort_children()

        return node

    @staticmethod
    def source_node(db, T, selector_panel):
        """To deal with sources.
285 286 287 288 289 290 291 292 293 294 295

        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.
        """
296
        node = Node(T("The sources"))
297 298 299

        add_child = node.add_child

300
        for source in sorted(Event.get_sources()):
301 302

            panel = selector_panel
303 304
            panel.baseUrl = URL("plugin_event", "source")
            panel.baseParams = {"source": source}
305

306
            add_child(source, panel)
307 308

        return node
309