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()
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()
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()