Пример #1
0
    def loadChildren(self):
        if self.groupPrefix in conf["vi.groupedModules"]:
            childs = conf["vi.groupedModules"][self.groupPrefix]
            childs.sort(key=lambda entry: "%d-%010d-%s" %
                        (1 if entry[1].get("sortIndex") is None else 0, entry[
                            1].get("sortIndex", 0), entry[1].get("name")))

            for module, info in childs:
                conf["modules"][module]["visibleName"] = conf["modules"][
                    module]["name"].replace(self.groupPrefix, "")
                handlerCls = HandlerClassSelector.select(module, info)
                assert handlerCls is not None, "No handler available for module '%s'" % module
                handler = handlerCls(module, info)
                conf["mainWindow"].addPane(handler, self)

        self.unlock()
Пример #2
0
    def startup(self):
        config = conf["mainConfig"]
        assert config

        if not conf["currentUser"]:
            self.getCurrentUser()
            return

        conf["server"] = config.get("configuration", {})

        if "vi.name" in conf["server"]:
            conf["vi.name"] = str(conf["server"]["vi.name"])

        self.userLoggedOutMsg = UserLogoutMsg()
        self.topBar.invoke()

        moduleGroups = []

        # Save module groups
        if ("configuration" in config.keys()
                and isinstance(config["configuration"], dict)):

            if ("modulGroups" in config["configuration"].keys() and isinstance(
                    config["configuration"]["modulGroups"], list)):
                alert(
                    "Hello! Your project is still using 'admin.modulGroups' for its module grouping information.\n"
                    "Please rename it to 'admin.moduleGroups' (yes, with 'e') to avoid this alert message.\n\n"
                    "Thank you!")

                moduleGroups = config["configuration"]["modulGroups"]

            if ("moduleGroups" in config["configuration"].keys() and
                    isinstance(config["configuration"]["moduleGroups"], list)):
                moduleGroups = config["configuration"]["moduleGroups"]

        # Modules
        groupPanes = {}
        panes = []
        userAccess = conf["currentUser"].get("access", [])
        predefinedFilterCounter = 1

        groupedModules = {}

        # First create group panes, if configured
        for group in moduleGroups:
            groupedModules[group["prefix"]] = []
            groupPanes[group["prefix"]] = GroupPane(group["name"],
                                                    iconURL=group.get("icon"))
            groupPanes[group["prefix"]].groupPrefix = group["prefix"]
            panes.append((group["name"], group.get("sortIndex"),
                          groupPanes[group["prefix"]]))

        # Sort all modules first

        # read Hash to register startup module
        currentActiveGroup = None
        path = None
        urlHash = conf["startupHash"]
        if urlHash:

            if "?" in urlHash:
                hashStr = urlHash[1:urlHash.find("?")]
            else:
                hashStr = urlHash[1:]
            path = [x for x in hashStr.split("/") if x]

        sortedModules = []
        topLevelModules = {}

        for module, info in config["modules"].items():
            if not "root" in userAccess and not any(
                [x.startswith(module) for x in userAccess]):
                # Skip this module, as the user couldn't interact with it anyway
                continue

            sortedModules.append((module, info))

            groupName = info["name"].split(":")[0] + ": "

            if groupName not in groupPanes.keys():
                topLevelModules.update({module: info})
            else:
                if path and module == path[0]:
                    currentActiveGroup = groupName

                groupedModules[groupName].append((module, info))

        conf["vi.groupedModules"] = groupedModules

        sortedModules.sort(key=lambda entry: "%d-%010d-%s" % (
            1 if entry[1].get("sortIndex") is None else 0, entry[1].get(
                "sortIndex", 0), entry[1].get("name")))

        # When create module panes
        for module, info in sortedModules:
            if "views" in info.keys() and info["views"]:
                for v in info[
                        "views"]:  # Work-a-round for PyJS not supporting id()
                    v["__id"] = predefinedFilterCounter
                    predefinedFilterCounter += 1

            if currentActiveGroup or module in topLevelModules:
                handlerCls = HandlerClassSelector.select(module, info)
                assert handlerCls is not None, "No handler available for module '%s'" % module

                info["visibleName"] = info["name"]
                handler = None

                if info["name"] and currentActiveGroup and info[
                        "name"].startswith(currentActiveGroup):
                    info["visibleName"] = info["name"].replace(
                        currentActiveGroup, "")
                    handler = handlerCls(module, info)
                    groupPanes[currentActiveGroup].addChildPane(handler)

                if not handler and module in topLevelModules:
                    handler = handlerCls(module, info)
                    panes.append(
                        (info["visibleName"], info.get("sortIndex"), handler))

                info["_handler"] = handler

            conf["modules"][module] = info

    # Sorting our top level entries
        panes.sort(key=lambda entry: "%d-%010d-%s" %
                   (1 if entry[1] is None else 0, entry[1] or 0, entry[0]))

        # Add panes in the created order
        for name, idx, pane in panes:
            self.addPane(pane)

        # Finalizing!
        viInitializedEvent.fire()
        DeferredCall(self.checkInitialHash)
        self.unlock()
Пример #3
0
				if pathList[1] in ["list"] or (pathList[1] == "edit" and len(pathList) > 2):
					return (True)
		return (False)

	def handleInitialHash(self, pathList, params):
		assert self.canHandleInitialHash(pathList, params)
		if pathList[1] == "list":
			self.addWidget(HierarchyWidget(self.moduleName))
			self.focus()
		elif pathList[1] in ["edit", "clone"] and len(pathList) > 2:
			pane = Pane(translate("Edit"), closeable=True,
			            iconClasses=["module_%s" % self.moduleName, "apptype_hierarchy", "action_edit"])
			edwg = EditWidget(self.moduleName, EditWidget.appHierarchy, key=pathList[2], hashArgs=(params or None), clone=pathList[1] == "clone")
			pane.addWidget(edwg)
			conf["mainWindow"].addPane(pane, parentPane=self)
			pane.focus()

	@staticmethod
	def canHandle(moduleName, moduleInfo):
		return moduleInfo["handler"] == "hierarchy" or moduleInfo["handler"].startswith("hierarchy.")

	def onClick(self, *args, **kwargs):
		conf["theApp"].setPath(self.moduleName + "/list")

		if not len(self.widgetsDomElm._children):
			self.addWidget(HierarchyWidget(self.moduleName))
		super(HierarchyHandler, self).onClick(*args, **kwargs)


HandlerClassSelector.insert(3, HierarchyHandler.canHandle, HierarchyHandler)
Пример #4
0
			self._buildViewPanes(self.moduleInfo["views"])
			self.unlock()
		'''

        if self.requestedViews is None and "views.request" in self.moduleInfo:
            self.lock()

            NetworkService.request(
                self.moduleName,
                self.moduleInfo["views.request"],
                successHandler=self._onRequestViewsAvailable)

        super(ListHandler, self).onClick(*args, **kwargs)

    def _onRequestViewsAvailable(self, req):
        self.requestedViews = NetworkService.decode(req)
        self._buildViewPanes(self.requestedViews,
                             register=True,
                             requested=True)

        self.unlock()

        if not self.isExpanded:
            if self.mode == "normal":
                super(ListHandler, self).onClick()
            elif self.childPanes:
                self.childPanes[0].onClick()


HandlerClassSelector.insert(1, ListHandler.canHandle, ListHandler)
Пример #5
0
    def canHandleInitialHash(self, pathList, params):
        if len(pathList) > 1:
            if pathList[0] == self.moduleName and pathList[1] == "edit":
                return True

        return False

    def handleInitialHash(self, pathList, params):
        assert self.canHandleInitialHash(pathList, params)

        self.addWidget(
            EditWidget(self.moduleName,
                       EditWidget.appSingleton,
                       hashArgs=(params or None)))
        self.focus()

    @staticmethod
    def canHandle(moduleName, moduleInfo):
        return moduleInfo["handler"] == "singleton" or moduleInfo[
            "handler"].startswith("singleton.")

    def onClick(self, *args, **kwargs):
        if not self.widgetsDomElm.children():
            self.addWidget(EditWidget(self.moduleName,
                                      EditWidget.appSingleton))

        super(SingletonHandler, self).onClick(*args, **kwargs)


HandlerClassSelector.insert(3, SingletonHandler.canHandle, SingletonHandler)
Пример #6
0
                            "action_edit"
                        ])
            edwg = EditWidget(self.moduleName,
                              EditWidget.appTree,
                              key=pathList[3],
                              skelType=pathList[2],
                              hashArgs=(params or None),
                              clone=pathList[1] == "clone")
            pane.addWidget(edwg)
            conf["mainWindow"].addPane(pane, parentPane=self)
            pane.focus()

    @staticmethod
    def canHandle(moduleName, moduleInfo):
        return moduleInfo["handler"] == "tree" or moduleInfo[
            "handler"].startswith("tree.")

    def onClick(self, *args, **kwargs):
        conf["theApp"].setPath(self.moduleName + "/list")

        if not len(self.widgetsDomElm._children):
            wdg = displayDelegateSelector.select(self.moduleName,
                                                 self.moduleInfo)
            assert wdg is not None, "Got no handler for %s" % self.moduleName
            self.addWidget(wdg(self.moduleName))

        super(TreeHandler, self).onClick(*args, **kwargs)


HandlerClassSelector.insert(3, TreeHandler.canHandle, TreeHandler)
Пример #7
0
    def startup(self):
        config = conf["mainConfig"]
        assert config

        if not conf["currentUser"]:
            self.getCurrentUser()
            return

        conf["server"] = config.get("configuration", {})

        if "vi.name" in conf["server"]:
            conf["vi.name"] = str(conf["server"]["vi.name"])

        self.userLoggedOutMsg = UserLogoutMsg()
        self.topBar.invoke()

        moduleGroups = []

        # Save module groups
        if ("configuration" in config.keys()
                and isinstance(config["configuration"], dict)):

            if ("modulGroups" in config["configuration"].keys() and isinstance(
                    config["configuration"]["modulGroups"], list)):

                alert(
                    "Hello! Your project is still using 'admin.modulGroups' for its module grouping information.\n"
                    "Please rename it to 'admin.moduleGroups' (yes, with 'e') to avoid this alert message.\n\n"
                    "Thank you!")

                moduleGroups = config["configuration"]["modulGroups"]

            if ("moduleGroups" in config["configuration"].keys() and
                    isinstance(config["configuration"]["moduleGroups"], list)):

                moduleGroups = config["configuration"]["moduleGroups"]

        # Modules
        groupPanes = {}
        panes = []
        userAccess = conf["currentUser"].get("access", [])
        predefinedFilterCounter = 1

        # First create group panes, if configured
        for group in moduleGroups:
            groupPanes[group["prefix"]] = GroupPane(group["name"],
                                                    iconURL=group.get("icon"))
            panes.append((group["name"], group.get("sortIndex"),
                          groupPanes[group["prefix"]]))

        # Sort all modules first
        sortedModules = [(x, y) for x, y in config["modules"].items()]
        sortedModules.sort(key=lambda entry: "%d-%010d-%s" % (
            1 if entry[1].get("sortIndex") is None else 0, entry[1].get(
                "sortIndex", 0), entry[1].get("name")))

        # When create module panes
        for module, info in sortedModules:
            if not "root" in userAccess and not any(
                [x.startswith(module) for x in userAccess]):
                #Skip this module, as the user couldn't interact with it anyway
                continue

            conf["modules"][module] = info

            if "views" in conf["modules"][module].keys(
            ) and conf["modules"][module]["views"]:
                for v in conf["modules"][module][
                        "views"]:  #Work-a-round for PyJS not supporting id()
                    v["__id"] = predefinedFilterCounter
                    predefinedFilterCounter += 1

            handlerCls = HandlerClassSelector.select(module, info)
            assert handlerCls is not None, "No handler available for module '%s'" % module

            conf["modules"][module]["visibleName"] = conf["modules"][module][
                "name"]
            handler = None

            for k in groupPanes.keys():
                if info["name"].startswith(k):
                    conf["modules"][module]["visibleName"] = conf["modules"][
                        module]["name"].replace(k, "")
                    handler = handlerCls(module, info)
                    groupPanes[k].addChildPane(handler)
                    break

            if not handler:
                handler = handlerCls(module, info)
                panes.append(
                    (info["visibleName"], info.get("sortIndex"), handler))

            conf["modules"][module]["_handler"] = handler

        # Sorting our top level entries
        panes.sort(key=lambda entry: "%d-%010d-%s" %
                   (1 if entry[1] is None else 0, entry[1] or 0, entry[0]))

        # Push the panes, ignore group panes with no children (due to right restrictions)
        for name, idx, pane in panes:
            #print("idx", name, idx)

            # Don't display GroupPanes without children.
            if (isinstance(pane, GroupPane) and
                (not pane.childPanes or all(c["style"].get("display") == "none"
                                            for c in pane.childPanes))):
                continue

            self.addPane(pane)

        # Finalizing!
        viInitializedEvent.fire()
        DeferredCall(self.checkInitialHash)
        self.unlock()