UNPKG

@grouparoo/core

Version:
256 lines (255 loc) 9.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NavigationList = void 0; const optionallyAuthenticatedAction_1 = require("../classes/actions/optionallyAuthenticatedAction"); const GrouparooModel_1 = require("../models/GrouparooModel"); const Setting_1 = require("../models/Setting"); const Team_1 = require("../models/Team"); const configUser_1 = require("../modules/configUser"); const runMode_1 = require("../modules/runMode"); class NavigationList extends optionallyAuthenticatedAction_1.OptionallyAuthenticatedAction { constructor() { super(...arguments); this.name = "navigation:list"; this.description = "returns a list of pages for the UI navigation for this user"; this.permission = { topic: "*", mode: "read" }; this.outputExample = {}; } async runWithinTransaction({ session: { teamMember }, }) { const navigationMode = (0, runMode_1.getGrouparooRunMode)() === "cli:config" ? (await configUser_1.ConfigUser.isAuthenticated()) ? "config:authenticated" : "config:unauthenticated" : teamMember ? "authenticated" : "unauthenticated"; const models = await GrouparooModel_1.GrouparooModel.findAll({ order: [["name", "asc"]], }); let navResponse; switch (navigationMode) { case "authenticated": navResponse = await this.authenticatedNav(teamMember, models); break; case "unauthenticated": navResponse = await this.unauthenticatedNav(); break; case "config:authenticated": navResponse = await this.authenticatedConfigNav(models); break; case "config:unauthenticated": navResponse = await this.unauthenticatedConfigNav(); break; } const clusterNameSetting = await Setting_1.Setting.findOne({ where: { pluginName: "core", key: "cluster-name" }, }); return { navigationMode, navigation: navResponse, clusterName: { default: (clusterNameSetting === null || clusterNameSetting === void 0 ? void 0 : clusterNameSetting.value) && clusterNameSetting.value === clusterNameSetting.defaultValue, value: (clusterNameSetting === null || clusterNameSetting === void 0 ? void 0 : clusterNameSetting.value) || "", }, teamMember: teamMember ? await teamMember.apiData() : undefined, }; } static createModelNavigationItems(models) { const navigationItems = []; const hasModels = !!models.length; if (hasModels) { navigationItems.push({ type: "divider" }); models.forEach((model) => { navigationItems.push({ type: "link", title: model.name, icon: model.getIcon(), href: `/model/${model.id}/overview`, mainPathSectionIdx: 2, subNavItems: [ { type: "link", title: "Model Data", icon: "file-import", href: `/model/${model.id}/overview#model-data`, mainPathSectionIdx: 3, small: true, }, { type: "link", title: "Sample Record", icon: "flask", href: `/model/${model.id}/overview#sample-record`, mainPathSectionIdx: 3, small: true, }, { type: "link", title: "Records", icon: "file-alt", href: `/model/${model.id}/records`, mainPathSectionIdx: 3, small: true, }, { type: "link", title: "Destinations", icon: "file-export", href: `/model/${model.id}/overview#destinations`, mainPathSectionIdx: 3, small: true, }, ], }); }); } if (process.env.GROUPAROO_UI_EDITION !== "community") { navigationItems.push({ type: "link", title: "New Model", icon: "plus", href: `/model/new`, mainPathSectionIdx: 2, small: hasModels, }); } if (hasModels) { navigationItems.push({ type: "divider" }); } return navigationItems; } async authenticatedNav(teamMember, models) { const systemPermissionsCount = await teamMember.team.$count("permissions", { where: { read: true, topic: [ "system", "app", "file", "import", "export", "run", "notifications", "resque", ], }, }); const showSystemLinks = systemPermissionsCount > 0; const navigationItems = [ { type: "link", title: "Dashboard", href: "/dashboard", icon: "home", }, { type: "link", title: "Apps", href: "/apps", icon: "th-large" }, ]; navigationItems.push(...NavigationList.createModelNavigationItems(models)); navigationItems.push({ type: "subNavMenu", title: "Platform", icon: "terminal", }); const platformItems = [ { type: "link", title: "Imports", href: "/imports" }, { type: "link", title: "Exports", href: "/exports" }, { type: "link", title: "Runs", href: "/runs" }, { type: "link", title: "Export Processors", href: "/exportProcessors" }, ]; if (showSystemLinks) { platformItems.push({ type: "link", title: "Settings", href: "/settings/core", }); platformItems.push({ type: "link", title: "Teams and Members", href: "/teams", }); platformItems.push({ type: "link", title: "API Keys", href: "/apiKeys", }); platformItems.push({ type: "link", title: "API Documentation", href: "/swagger", }); platformItems.push({ type: "link", title: "Notifications", href: "/notifications", }); platformItems.push({ type: "link", title: "Resque", href: "/resque/overview", }); } const bottomMenuItems = [ { type: "link", title: "Account", href: "/account", }, { type: "link", title: "About", href: "/about" }, { type: "link", title: "Help", href: "/help" }, { type: "divider" }, { type: "link", title: "Sign Out", href: "/session/sign-out", }, ]; return { navigationItems, platformItems, bottomMenuItems }; } async unauthenticatedNav() { const navigationItems = [ { type: "link", title: "Home", href: "/" }, { type: "link", title: "About", href: "/about" }, ]; let platformItems = []; let bottomMenuItems = []; const teamsCount = await Team_1.Team.count(); if (teamsCount > 0) { bottomMenuItems = [ { type: "link", title: "Sign In", href: "/session/sign-in" }, ]; } else { bottomMenuItems = [ { type: "link", title: "Create Team", href: "/team/initialize" }, ]; } bottomMenuItems.push({ type: "link", title: "Help", href: "/help" }); return { navigationItems, platformItems, bottomMenuItems }; } async authenticatedConfigNav(models) { const navigationItems = [ { type: "link", title: "Apps", href: "/apps", icon: "th-large", }, ]; navigationItems.push(...NavigationList.createModelNavigationItems(models)); return { navigationItems, platformItems: [], bottomMenuItems: [], }; } async unauthenticatedConfigNav() { const navigationItems = [ { type: "link", title: "Home", href: "/" }, ]; const platformItems = []; const bottomMenuItems = []; return { navigationItems, platformItems, bottomMenuItems }; } } exports.NavigationList = NavigationList;