Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.

Commit d214a2d

Browse files
authored
Merge pull request #49 from ironmansoftware/pageEditing
Adjust app page editing.
2 parents 8810307 + 6d19e49 commit d214a2d

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@ Please open issues on the [PowerShell Universal issue repository](https://github
1414

1515
### APIs
1616

17-
![](https://github.com/ironmansoftware/universal-code/raw/master/images/apis.png)
17+
![PowerShell Universal APIs](https://github.com/ironmansoftware/universal-code/raw/master/images/apis.png)
1818

1919
- View APIs
2020
- Automatically insert `Invoke-RestMethod` to call APIs
2121
- Edit APIs
2222

23-
### Dashboards
23+
### Apps
2424

25-
![](https://github.com/ironmansoftware/universal-code/raw/master/images/dashboards.png)
25+
![PowerShell Universal Apps](https://github.com/ironmansoftware/universal-code/raw/master/images/dashboards.png)
2626

27-
- View dashboards
28-
- Open Dashboard scripts
29-
- Restart Dashboards
30-
- View Dashboard log
31-
- Debug Dashboard Process
27+
- View Apps
28+
- Open App scripts
29+
- Restart Apps
30+
- View App log
31+
- Debug App Process
3232

33-
### Scripts
33+
### Scripts
3434

35-
![](https://github.com/ironmansoftware/universal-code/raw/master/images/scripts.png)
35+
![PowerShell Universal Scripts](https://github.com/ironmansoftware/universal-code/raw/master/images/scripts.png)
3636

3737
- View scripts
3838
- Edit scripts
3939
- Run scripts and receive notifications on job status
4040

41-
### Configuration
41+
### Configuration
4242

43-
![](https://github.com/ironmansoftware/universal-code/raw/master/images/config.png)
43+
![PowerShell Universal Configuration](https://github.com/ironmansoftware/universal-code/raw/master/images/config.png)
4444

4545
- Edit configuration scripts
4646

@@ -58,7 +58,7 @@ Next, click your user name in the top right corner and select Tokens. Create a n
5858

5959
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:
6060

61-
- App Token - The contents of the token you created in PowerShell Universal.
61+
- App Token - The contents of the token you created in PowerShell Universal. Use the Administrator role to provide full access.
6262
- URL - The URL to your PowerShell Universal server (e.g. http://localhost:5000)
6363

6464
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
6969

7070
This extension contributes the following settings:
7171

72-
* `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.
72+
* `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.
7373
* `powershellUniversal.url`: The URL to your PowerShell Universal server.
7474
* `powershellUniversal.localEditing`: Whether to edit local configuration files or using the REST API
7575
* `powershellUniversal.connections`: An array of connections.

src/commands/dashboards.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ export const registerDashboardCommands = (context: vscode.ExtensionContext) => {
4646
vscode.window.showErrorMessage(`Page ${info.name} not found.`);
4747
return;
4848
} else {
49-
page.content = file.getText();
50-
Container.universal.saveDashboardPage(page.modelId, dashboard.id, page);
49+
const codePath = path.join(tmpdir(), '.universal.code.dashboardPage');
50+
const fileName = file.fileName.toLocaleLowerCase().replace(codePath.toLocaleLowerCase(), "").substring(1);
51+
const filePath = path.join("dashboards", info.dashboardName, "pages", info.name + ".ps1");
52+
await Container.universal.saveFileContent(filePath, file.getText());
53+
await Container.universal.deployApp(dashboard.id);
5154
}
5255
}
5356
else if (file.fileName.includes('.universal.code.dashboardModule')) {
@@ -245,20 +248,20 @@ export const openFileRemote = async (dashboard: DashboardTreeItem) => {
245248
}
246249

247250
export const openPageFile = async (page: DashboardPageTreeItem) => {
248-
const os = require('os');
249251
const codePath = path.join(tmpdir(), '.universal.code.dashboardPage');
250252
//Use the id in the path so that we can save the dashboard
251253
const codePathId = path.join(codePath, page.page.modelId.toString());
252254
const filePath = path.join(codePathId, page.page.name + ".ps1");
253255

254-
const dashboardFile = await Container.universal.getDashboardPage(page.page.dashboardId, page.page.modelId);
255256
const dashboard = await Container.universal.getDashboard(page.page.dashboardId);
256257
var dirName = path.dirname(filePath);
257258
if (!fs.existsSync(dirName)) {
258259
fs.mkdirSync(dirName, { recursive: true });
259260
}
260261

261-
fs.writeFileSync(filePath, dashboardFile.content);
262+
const content = await Container.universal.getFileContent(path.join("dashboards", dashboard.name, "pages", page.page.name + ".ps1"));
263+
264+
fs.writeFileSync(filePath, content.content);
262265

263266
files.push({
264267
id: page.page.modelId,

src/universal.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ export class Universal {
262262
})
263263
}
264264

265+
deployApp(id: number): Promise<Dashboard> {
266+
return new Promise((resolve, reject) => {
267+
this.request(`/api/v1/dashboard/${id}/status/deploy`, 'PUT')?.then(x => resolve(x.data)).catch(x => {
268+
reject(x.message);
269+
});
270+
});
271+
}
272+
265273
getDashboard(id: number): Promise<Dashboard> {
266274
return new Promise((resolve, reject) => {
267275
this.request(`/api/v1/dashboard/${id}`, 'GET')?.then(x => resolve(x.data)).catch(x => {

0 commit comments

Comments
 (0)