From 6d19e49279a3a7b477dbd55e830f568b2938df39 Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Mon, 22 Sep 2025 10:18:59 -0500 Subject: [PATCH] Adjust app page editing. --- README.md | 28 ++++++++++++++-------------- src/commands/dashboards.ts | 13 ++++++++----- src/universal.ts | 8 ++++++++ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1fb7c83..88afcd9 100644 --- a/README.md +++ b/README.md @@ -14,33 +14,33 @@ Please open issues on the [PowerShell Universal issue repository](https://github ### APIs -![](https://github.com/ironmansoftware/universal-code/raw/master/images/apis.png) +![PowerShell Universal APIs](https://github.com/ironmansoftware/universal-code/raw/master/images/apis.png) - View APIs - Automatically insert `Invoke-RestMethod` to call APIs - Edit APIs -### Dashboards +### Apps -![](https://github.com/ironmansoftware/universal-code/raw/master/images/dashboards.png) +![PowerShell Universal Apps](https://github.com/ironmansoftware/universal-code/raw/master/images/dashboards.png) -- View dashboards -- Open Dashboard scripts -- Restart Dashboards -- View Dashboard log -- Debug Dashboard Process +- View Apps +- Open App scripts +- Restart Apps +- View App log +- Debug App Process -### Scripts +### Scripts -![](https://github.com/ironmansoftware/universal-code/raw/master/images/scripts.png) +![PowerShell Universal Scripts](https://github.com/ironmansoftware/universal-code/raw/master/images/scripts.png) - View scripts - Edit scripts - Run scripts and receive notifications on job status -### Configuration +### Configuration -![](https://github.com/ironmansoftware/universal-code/raw/master/images/config.png) +![PowerShell Universal Configuration](https://github.com/ironmansoftware/universal-code/raw/master/images/config.png) - Edit configuration scripts @@ -58,7 +58,7 @@ Next, click your user name in the top right corner and select Tokens. Create a n Within Visual Studio Code, open the command palette (Ctrl+Shift+P) and type "Preferences: Open Settings (UI)". Search for PowerShell Universal and fill in the following values: -- App Token - The contents of the token you created in PowerShell Universal. +- App Token - The contents of the token you created in PowerShell Universal. Use the Administrator role to provide full access. - URL - The URL to your PowerShell Universal server (e.g. http://localhost:5000) Once connected, click the PowerShell Universal icon in the Activity Bar on the left side of the window. You can now start using the extension. @@ -69,7 +69,7 @@ For more information, visit the [PowerShell Universal documentation](https://doc This extension contributes the following settings: -* `powershellUniversal.appToken`: An app token for communicating with the Universal REST API. An app token will be granted the first time the extension starts up. +* `powershellUniversal.appToken`: An app token for communicating with the Universal REST API. An app token will be granted the first time the extension starts up. * `powershellUniversal.url`: The URL to your PowerShell Universal server. * `powershellUniversal.localEditing`: Whether to edit local configuration files or using the REST API * `powershellUniversal.connections`: An array of connections. diff --git a/src/commands/dashboards.ts b/src/commands/dashboards.ts index c9cc718..b3cc011 100644 --- a/src/commands/dashboards.ts +++ b/src/commands/dashboards.ts @@ -46,8 +46,11 @@ export const registerDashboardCommands = (context: vscode.ExtensionContext) => { vscode.window.showErrorMessage(`Page ${info.name} not found.`); return; } else { - page.content = file.getText(); - Container.universal.saveDashboardPage(page.modelId, dashboard.id, page); + const codePath = path.join(tmpdir(), '.universal.code.dashboardPage'); + const fileName = file.fileName.toLocaleLowerCase().replace(codePath.toLocaleLowerCase(), "").substring(1); + const filePath = path.join("dashboards", info.dashboardName, "pages", info.name + ".ps1"); + await Container.universal.saveFileContent(filePath, file.getText()); + await Container.universal.deployApp(dashboard.id); } } else if (file.fileName.includes('.universal.code.dashboardModule')) { @@ -245,20 +248,20 @@ export const openFileRemote = async (dashboard: DashboardTreeItem) => { } export const openPageFile = async (page: DashboardPageTreeItem) => { - const os = require('os'); const codePath = path.join(tmpdir(), '.universal.code.dashboardPage'); //Use the id in the path so that we can save the dashboard const codePathId = path.join(codePath, page.page.modelId.toString()); const filePath = path.join(codePathId, page.page.name + ".ps1"); - const dashboardFile = await Container.universal.getDashboardPage(page.page.dashboardId, page.page.modelId); const dashboard = await Container.universal.getDashboard(page.page.dashboardId); var dirName = path.dirname(filePath); if (!fs.existsSync(dirName)) { fs.mkdirSync(dirName, { recursive: true }); } - fs.writeFileSync(filePath, dashboardFile.content); + const content = await Container.universal.getFileContent(path.join("dashboards", dashboard.name, "pages", page.page.name + ".ps1")); + + fs.writeFileSync(filePath, content.content); files.push({ id: page.page.modelId, diff --git a/src/universal.ts b/src/universal.ts index 54c79c8..20729bc 100644 --- a/src/universal.ts +++ b/src/universal.ts @@ -262,6 +262,14 @@ export class Universal { }) } + deployApp(id: number): Promise { + return new Promise((resolve, reject) => { + this.request(`/api/v1/dashboard/${id}/status/deploy`, 'PUT')?.then(x => resolve(x.data)).catch(x => { + reject(x.message); + }); + }); + } + getDashboard(id: number): Promise { return new Promise((resolve, reject) => { this.request(`/api/v1/dashboard/${id}`, 'GET')?.then(x => resolve(x.data)).catch(x => {