@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
170 lines (168 loc) • 6.78 kB
JavaScript
import { Logging } from '../diagnostics/logging';
import { RpcShellNavigateClient } from '../rpc/shell-navigate/rpc-shell-navigate-client';
export class ShellNavigationConnection {
rpc;
/**
* Initializes a new instance of the ShellNavigationConnection class.
*
* @param rpc the rpc object.
*/
constructor(rpc) {
this.rpc = rpc;
}
/**
* Navigate to the shell home page.
*
* @return Promise<RpcShellNavigateResult> the navigation result.
*/
navigateHome() {
return RpcShellNavigateClient.shellNavigate(this.rpc, {});
}
/**
* Reload the shell.
*
* @return Promise<RpcShellNavigateResult> the navigation result.
*/
navigateReload() {
return RpcShellNavigateClient.shellNavigate(this.rpc, { reload: true });
}
/**
* Navigate to a settings of gateway.
*
* @param name the name of setting of gateway.
* @param nestedUrlAndOptions the nested URL and Options on the setting of gateway.
* @return Promise<RpcShellNavigateResult> the navigation result.
*/
navigateSettings(name, nestedUrlAndOptions) {
return RpcShellNavigateClient.shellNavigate(this.rpc, {
settings: {
name,
nestedUrlAndOptions: nestedUrlAndOptions
}
});
}
/**
* Navigate to URL.
*
* @return Promise<RpcShellNavigateResult> the navigation result.
*/
navigateUrl(url) {
return RpcShellNavigateClient.shellNavigate(this.rpc, { navigateNext: url });
}
/**
* Navigate a view by the shell.
*
* @param solution the solution - module name and entry point name.
* @param tool the tool - module name and entry point name.
* @param connection the connection - name and type.
* @param connectionSettings the setting tab name, omit tabUrlName if goes to the first item.
* @param reserved (deprecated - use tool parameters such as toolUrl, toolQueryParams and toolFragment)
* @param settings the settings on the shell/gateway.
* @param navigateNext the navigate next url.
* @param reload the reload shell.
* @param popoutOptions options indicating how to popout the navigation.
* @return Promise<RpcShellNavigateResult> the navigation result.
*/
navigate(solution, tool, connection, connectionSettings, reserved, settings, navigateNext, reload, popoutOptions) {
return RpcShellNavigateClient.shellNavigate(this.rpc, {
solution: solution,
tool: tool,
connection: connection,
connectionSettings: connectionSettings,
settings: settings,
toolNestedUrlAndOptions: reserved,
navigateNext: navigateNext,
reload: reload,
popoutOptions: popoutOptions
});
}
navigateTool(solutionModuleName, solutionEntryPointName, toolModuleName, toolEntryPointName, connectionName, connectionType, toolUrlOrToolNestedUrlAndOptions, toolQueryParams, toolFragment) {
let toolUrl = toolUrlOrToolNestedUrlAndOptions;
if (toolUrlOrToolNestedUrlAndOptions) {
toolUrl = MsftSme.trimStart(toolUrlOrToolNestedUrlAndOptions, '/');
try {
const url = new URL('http://fake/' + toolUrl);
toolUrl = url.pathname;
toolFragment = url.hash.length > 0 ? MsftSme.trimStart(url.hash, '#') : null;
toolQueryParams = {};
url.searchParams.forEach((value, key) => toolQueryParams[key] = value);
}
catch {
// skip if parsing caused an error of URL object.
Logging.logWarning('navigation', 'Couldn\'t parse toolNestedUrlAndOptions.');
}
}
return RpcShellNavigateClient.shellNavigate(this.rpc, {
solution: {
moduleName: solutionModuleName,
entryPointName: solutionEntryPointName
},
tool: {
moduleName: toolModuleName,
entryPointName: toolEntryPointName,
nestedUrl: toolUrl,
fragment: toolFragment,
queryParams: toolQueryParams
},
connection: {
name: connectionName,
type: connectionType
}
});
}
navigateSolutionTool(solutionModuleName, solutionEntryPointName, toolModuleName, toolEntryPointName, toolUrlOrToolNestedUrlAndOptions, toolQueryParams, toolFragment) {
let toolUrl = toolUrlOrToolNestedUrlAndOptions;
if (toolUrlOrToolNestedUrlAndOptions) {
toolUrl = MsftSme.trimStart(toolUrlOrToolNestedUrlAndOptions, '/');
try {
const url = new URL('http://fake/' + toolUrl);
toolUrl = url.pathname;
toolFragment = url.hash.length > 0 ? MsftSme.trimStart(url.hash, '#') : null;
toolQueryParams = {};
url.searchParams.forEach((value, key) => toolQueryParams[key] = value);
}
catch {
// skip if parsing caused an error of URL object.
Logging.logWarning('navigation', 'Couldn\'t parse toolNestedUrlAndOptions.');
}
}
return RpcShellNavigateClient.shellNavigate(this.rpc, {
solution: {
moduleName: solutionModuleName,
entryPointName: solutionEntryPointName
},
tool: {
moduleName: toolModuleName,
entryPointName: toolEntryPointName,
nestedUrl: toolUrl,
queryParams: toolQueryParams,
fragment: toolFragment
}
});
}
/**
* Navigate to a setting of a tool.
*
* @param solutionModuleName the solution module name.
* @param solutionEntryPointName the solution entry point name.
* @param connectionName the connection name.
* @param connectionType the connection type.
* @param tabUrlName the setting tab name, omit tabUrlName goes to the default setting item.
*/
navigateToolSetting(solutionModuleName, solutionEntryPointName, connectionName, connectionType, tabUrlName) {
return RpcShellNavigateClient.shellNavigate(this.rpc, {
solution: {
moduleName: solutionModuleName,
entryPointName: solutionEntryPointName
},
connection: {
name: connectionName,
type: connectionType
},
connectionSettings: {
tabUrlName: tabUrlName
}
});
}
}
//# sourceMappingURL=shell-navigation-connection.js.map