Skip to content

Commit

Permalink
implement different commands for run and "publish and run"
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Fenster committed Jun 27, 2017
1 parent 56e6df5 commit ad65124
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 29 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
# AL Runner README

AL Runner allows you to run a NAV AL object using Alt+R like in good old (actually bad old) C/SIDE for the object in the current selection or Shift+Alt+R for the first object in the file
AL Runner allows you to compile and publish your appliaction and run a NAV AL page or pageextension object using Alt+P for the object in the current selection or Shift+Alt+P for the first object in the file. It also allows you to just run (no compile and publish) a NAV AL page, pageextension or report object using Alt+R like in good old (actually bad old) C/SIDE for the object in the current selection or Shift+Alt+R for the first object in the file


## Features

Provides two commands:
- "ALRunner: Run Selection" or Alt+R which runs the object in the currently selected line, if that is a page or pageextension object
- "ALRunner: Run object on first line" or Shift+Alt+R which runs the object on the first line of the current file
Provides four commands:
- "ALRunner: Run selection" or Alt+R which runs the object in the currently selected line, if that is a page or report object
- "ALRunner: Run object on first line" or Shift+Alt+R which runs the object on the first line of the current file, if that is a page or report object
- "ALRunner: Publish and run selection" or Alt+P which publishes your extension and runs the object in the currently selected line, if that is a page object. Note: This changes your launch config
- "ALRunner: Publish and run object on first line" or Shift+Alt+P which publishes your extension and runs the object on the first line of the current file, if that is a page object. Note: This changes your launch config


## Requirements

You need to have the Microsoft AL Extension up and running
- You need to have the Microsoft AL Extension up and running (easiest way to get to that point is [here](https://msdn.microsoft.com/en-us/dynamics-nav/newdev-get-started))
- opn ^4.0.2


## Known Issues

Only supports page and pageextension objects as the AL Extension launch config also only allows to set those object types as startup objects
- Only supports page objects for "publish and run" as the AL Extension launch config also only allows to set those object types as startup objects
- Only supports page and report objects for "run" as the NAV Web Client also only allows to run those object types directly
- Only works for the first configuration in your launch config


## Future ideas

- Run the current object
- Run the current object even if the selection is somewhere down the object
- Run an arbitrary object
- Find out which base page object a pageextension changes and run that
- Allow to configure if full, tablet or phone Web Client is run


## Release Notes

Notes for the released versions

### 1.1.0.

Add the ability not only to publish and run but also to directly run. This also adds the ability to run Reports

### 1.0.2

Documentation fixes
Expand Down
32 changes: 29 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "alrunner",
"displayName": "ALRunner",
"description": "Can run AL objects",
"version": "1.0.2",
"version": "1.1.0",
"publisher": "tfenster",
"repository": "https://github.com/tfenster/ALRunner",
"engines": {
Expand All @@ -12,18 +12,29 @@
"Other"
],
"activationEvents": [
"onCommand:extension.runSelection"
"onCommand:extension.runSelection",
"onCommand:extension.runFirstObject",
"onCommand:extension.publishAndRunSelection",
"onCommand:extension.publishAndRunFirstObject"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "extension.runSelection",
"title": "ALRunner: Run Selection"
"title": "ALRunner: Run selection"
},
{
"command": "extension.runFirstObject",
"title": "ALRunner: Run object on first line"
},
{
"command": "extension.publishAndRunSelection",
"title": "ALRunner: Publish and run selection"
},
{
"command": "extension.publishAndRunFirstObject",
"title": "ALRunner: Publish and run object on first line"
}
],
"keybindings": [
Expand All @@ -38,6 +49,18 @@
"key": "shift+alt+r",
"mac": "shift+cmd+r",
"when": "editorTextFocus"
},
{
"command": "extension.publishAndRunSelection",
"key": "alt+p",
"mac": "cmd+p",
"when": "editorTextFocus"
},
{
"command": "extension.publishAndRunFirstObject",
"key": "shift+alt+p",
"mac": "shift+cmd+p",
"when": "editorTextFocus"
}
]
},
Expand All @@ -53,5 +76,8 @@
"mocha": "^2.3.3",
"@types/node": "^6.0.40",
"@types/mocha": "^2.2.32"
},
"dependencies": {
"opn": "^4.0.2"
}
}
77 changes: 58 additions & 19 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,104 @@
'use strict';
import {window, commands, Disposable, ExtensionContext, StatusBarAlignment, StatusBarItem, TextDocument, workspace, TextLine} from 'vscode';
import {window, commands, Disposable, ExtensionContext, StatusBarAlignment, StatusBarItem, TextDocument, TextEditor, workspace, TextLine} from 'vscode';

const open = require('opn');

export function activate(context: ExtensionContext) {
console.log('"alrunner" is now active!');

let alr = new ALRunner();

let disp = commands.registerCommand('extension.runSelection', () => {
alr.runSelection();
alr.runSelection(window.activeTextEditor);
});

let disp2 = commands.registerCommand('extension.runFirstObject', () => {
alr.runFirstObject();
alr.runFirstObject(window.activeTextEditor);
});

let disp3 = commands.registerCommand('extension.publishAndRunSelection', () => {
alr.publishAndRunSelection(window.activeTextEditor);
});

let disp4 = commands.registerCommand('extension.publishAndRunFirstObject', () => {
alr.publishAndRunFirstObject(window.activeTextEditor);
});

context.subscriptions.push(disp);
context.subscriptions.push(disp2);
context.subscriptions.push(disp3);
context.subscriptions.push(disp4);
}

// this method is called when your extension is deactivated
export function deactivate() {
}

class ALRunner {
public runSelection() {
// get the editor context and find the currently active line
let editor = window.activeTextEditor;
public runSelection(editor: TextEditor) {
// find the currently active line
let line = editor.document.lineAt(editor.selection.active.line);

this.runObjectOnLine(line, false);
}

public runFirstObject(editor: TextEditor) {
// find the first line
let line = editor.document.lineAt(0);

this.runObjectOnLine(line, false);
}

public publishAndRunSelection(editor: TextEditor) {
// find the currently active line
let line = editor.document.lineAt(editor.selection.active.line);

this.runObjectOnLine(line);
this.runObjectOnLine(line, true);
}

public runFirstObject() {
// get the editor context and find the first line
let editor = window.activeTextEditor;
public publishAndRunFirstObject(editor: TextEditor) {
// find the first line
let line = editor.document.lineAt(0);

this.runObjectOnLine(line);
this.runObjectOnLine(line, true);
}

private runObjectOnLine(line: TextLine) {
private runObjectOnLine(line: TextLine, publish: boolean) {
if (line != null && line.text != null) {
console.log('working on');
console.log(line);
let lowertext = line.text.toLowerCase();

// can only handle page or pageextension objects
if (lowertext.startsWith('page') || lowertext.startsWith('pageextension')) {
// can only handle page or report objects
if (lowertext.startsWith('page ') || lowertext.startsWith('report')) {
if (lowertext.startsWith('report') && publish) {
window.showErrorMessage('Publish and run is not supported for reports, only run without publish');
return;
}
let tokens = lowertext.split(' ');
if (isNaN(Number(tokens[1]))) {
window.showErrorMessage('Did not find an object number where I expected one. Are you at the first line of an object?');
} else {
// found a valid object id, now change the launch config and call publish (which will also launch the object)
let config = workspace.getConfiguration('launch');
let currentConfig = config.configurations;
currentConfig[0].startupObjectId = Number(tokens[1]);
config.update('configurations', currentConfig);
commands.executeCommand('al.publish');
if (publish) {
// found a valid object id, now change the launch config and call publish (which will also launch the object)
currentConfig[0].startupObjectId = Number(tokens[1]);
config.update('configurations', currentConfig);
commands.executeCommand('al.publish');
} else {
// found a valid object id, now run it
let server = currentConfig[0].server;
let serverInstance = currentConfig[0].serverInstance;
let objecttype = 'Page';
if (lowertext.startsWith('report')) {
objecttype = 'Report';
}
open(server + '/' + serverInstance + '/WebClient/default.aspx?' + objecttype + '=' + tokens[1]);
}
}
} else {
window.showErrorMessage('Did not find a page or pageextension object in the current line. Are you at the first line of a page or pageextension?')
window.showErrorMessage('Did not find a page or report object in the current line. Are you at the first line of a page or report?')
}
}
}
Expand Down

0 comments on commit ad65124

Please sign in to comment.