ui_viewport.py 6.64 KB
Newer Older
1 2 3 4 5 6 7
"""Main user interface the viewport

"""
from gluon import current
from gluon.html import URL
from gluon.tools import PluginManager

8 9 10 11 12 13 14
from .plugin_dbui import (Node,
                          Panel,
                          to_formPanel,
                          to_gridPanel,
                          to_panelWithUrlSelector,
                          ViewportModifier,
                          Window)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245


def to_grid(tablename):
    """helper function to translate a tablename into the grid configuration.

    Args:
        tablename (str)

    Return:
        dict

    """
    return to_gridPanel(current.db[tablename])


class ViewportUi(object):

    @staticmethod
    def configure(virtdb, db, T):
        """Configure the viewport.

        Args:
            virtdb (pyDAL.DAL):
                virtual database with the definition of selectors
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        """
        nodes = [
            ViewportUi.help_node(db, T),
            ViewportUi.app_node(db, T),
            ViewportUi.forms_node(db, T),
            ViewportUi.tables_node(db, T),
            ViewportUi.reports_node(virtdb, db, T)]

        mdf = ViewportModifier()
        mdf.add_node(*nodes)

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

        # mdf.configure(plugins=["pViewportLogin"], logged=True);

        mdf.default_node(T("Tables"), T("categories"))
        # mdf.default_node(T("Tables"), T("new_fields"))
        # mdf.default_node(T("Tables"), T("publications"))

    @staticmethod
    def app_node(db, T):
        """To deal with preferences for the application.

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

        Returns:
            dbui.Node:
                the configuration of a tree node.

        """
        node = Node(T("Application"))
        # node.add_child(T("preferences"), to_grid("preferences"))

        window = Window(closable=True,
                        items=[{"dbtable": "preferences",
                                "sourceConfig": {"my_date": {"type": "date"}},
                                "xtype": "xpreferences",
                                "width": 300}],
                        layout="fit",
                        title=T("Preferences"),
                        modal=True)

        node.add_child(T("preferences"), window)

        return node

    @staticmethod
    def forms_node(db, T):
        """To configure forms node.

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

        Returns:
            dbui.Node:
                the configuration of a tree node.

        """
        tables = ("categories", "harvesters", "publications", "new_fields")
        node = Node(T("Forms"))

        for tablename in tables:

            leaf = Window(closable=True,
                          items=[to_formPanel(db[tablename])],
                          layout="fit",
                          title="Add %s ..." % tablename,
                          modal=True)

            node.add_child(T(tablename), leaf)

        return node

    @staticmethod
    def tables_node(db, T):
        """To configure tables node.

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

        Returns:
            dbui.Node:
                the configuration of a tree node.

        """
        node = Node(T("Tables"))
        node.add_children(db.tables, func=to_grid)

        return node

    @staticmethod
    def help_node(db, T):
        """To configure help node.

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

        Returns:
            dbui.Node:
                the configuration of a tree node.

        """
        plugin = PluginManager("dbui").dbui

        node = Node(T("Help"))

        loader = dict(
            autoLoad=True,
            renderer="html",
            scripts=False,
            url=URL("static", plugin.app_about.replace("static/", "")))

        about_panel = Panel(
            loader=loader,
            plugins=["pPanelLoaderException"],
            autoScroll=True)

        loader = dict(
            autoLoad=True,
            renderer="html",
            scripts=True,
            url=URL("plugin_dbui", "documentations_table"))

        doctable_panel = Panel(
            loader=loader,
            plugins=["pPanelLoaderException"],
            autoScroll=True)

        loader = dict(
            autoLoad=True,
            renderer="html",
            scripts=True,
            url=URL("plugin_dbui", "documentations_list"))

        doclist_panel = Panel(
            loader=loader,
            plugins=["pPanelLoaderException"],
            autoScroll=True)

        loader = dict(
            autoLoad=True,
            renderer="html",
            scripts=True,
            url=URL("plugin_dbui", "versions"))

        version_panel = Panel(
            loader=loader,
            plugins=["pPanelLoaderException"])

        node.add_child(T("about"), about_panel)
        node.add_child(T("documentations (table)"), doctable_panel)
        node.add_child(T("documentations (list)"), doclist_panel)
        node.add_child(T("versions"), version_panel)

        return node

    @staticmethod
    def reports_node(virtdb, db, T):
        """To configure reports nodes.

        Args:
            virtdb (pyDAL.DAL):
                virtual database with the definition of selectors
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator
                configuration of the selector panel.

        Returns:
            dbui.Node:
                the configuration of a tree node.

        """
        node = Node(T("Reports"))

        panel_1 = Panel(html="salut ma poule")

        panel_2 = to_panelWithUrlSelector(
            virtdb.foo1,
            baseUrl=URL("reports", "report_2"),
            baseParams={"hello": 3},
            extField="my_format",
            plugins=["pMathJax"])

        panel_3 = to_panelWithUrlSelector(
            virtdb.harvester_selector,
            baseUrl=URL("reports", "report_3"),
            selectorRegion="east",
            selectorTitle="Select a project")

        panel_4 = to_panelWithUrlSelector(
            virtdb.report4,
            baseUrl=URL("reports", "report_4"))

        node.add_child(T("report_1"), panel_1)
        node.add_child(T("report_2"), panel_2)
        node.add_child(T("report_3"), panel_3)
        node.add_child(T("report_4"), panel_4)

        return node