diff --git a/README.md b/README.md index 8796784..de406f0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ Provides five commands: - "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 -- "ALRunner: Generate objects by parsing and interpreting a JSON object" asks you for a URL, which should return a JSON file (authentication currently not supported) and then for the name of the entity represented by that JSON file. It then generates a table structured like the JSON file, a page showing that table and a codeunit with a function to refresh that data +- "ALRunner: Generate objects by parsing a JSON object from a URL" asks you for a URL, which should return a JSON file (authentication currently not supported) and then for the name of the entity represented by that JSON file. It then generates a table structured like the JSON file, a page showing that table and a codeunit with a function to refresh that data +- "ALRunner: Generate objects by parsing a JSON object in the current selection" does the same as the previous command but uses the currently selected text as data for parsing. This als asks you for a URL, which is only used for generating the AL code do download data and then for the name of the entity represented by that JSON file. With this command you code download a JSON object using authentication and then put the result into VS Code, select the relevant part and let generation run. For nested objects you could do the same but would need to handle linking parent and child objects ## Requirements @@ -26,7 +27,7 @@ Provides five commands: - 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 -- Generating objects for JSON doesn't support authorization and ignores nested structures +- Generating objects for JSON doesn't support authorization and ignores nested structures. You might use the "parse current selection" feature to work around those limitations ## Future ideas @@ -42,6 +43,10 @@ Provides five commands: Notes for the released versions +### 2.4.0 + +Add support for parsing the current selection additionally to downloading it + ### 2.3.0 Slight problems with vsce... diff --git a/package.json b/package.json index cd07dbf..7d6c652 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "onCommand:extension.runFirstObject", "onCommand:extension.publishAndRunSelection", "onCommand:extension.publishAndRunFirstObject", - "onCommand:extension.generateObjectsFromJson" + "onCommand:extension.generateObjectsFromURL", + "onCommand:extension.generateObjectsFromEditor" ], "main": "./out/src/extension", "contributes": { @@ -38,8 +39,12 @@ "title": "ALRunner: Publish and run object on first line" }, { - "command": "extension.generateObjectsFromJson", - "title": "ALRunner: Generate objects by parsing and interpreting a JSON object" + "command": "extension.generateObjectsFromURL", + "title": "ALRunner: Generate objects by parsing a JSON object from a URL" + }, + { + "command": "extension.generateObjectsFromEditor", + "title": "ALRunner: Generate objects by parsing a JSON object in the current selection" } ], "keybindings": [ diff --git a/src/extension.ts b/src/extension.ts index 22bdaf0..1c2a2ed 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -27,8 +27,12 @@ export function activate(context: ExtensionContext) { alr.publishAndRunFirstObject(window.activeTextEditor); }); - let disp5 = commands.registerCommand('extension.generateObjectsFromJson', () => { - alr.generateObjectsFromJson(window.activeTextEditor); + let disp5 = commands.registerCommand('extension.generateObjectsFromURL', () => { + alr.generateObjectsFromURL(); + }); + + let disp6 = commands.registerCommand('extension.generateObjectsFromEditor', () => { + alr.generateObjectsFromEditor(window.activeTextEditor); }); context.subscriptions.push(disp); @@ -36,6 +40,7 @@ export function activate(context: ExtensionContext) { context.subscriptions.push(disp3); context.subscriptions.push(disp4); context.subscriptions.push(disp5); + context.subscriptions.push(disp6); } // this method is called when your extension is deactivated @@ -76,7 +81,27 @@ class ALRunner { this.runObjectOnLine(line, true); } - public generateObjectsFromJson(editor: TextEditor) { + public generateObjectsFromEditor(editor: TextEditor) { + let alr = this; + window.showInputBox({prompt: 'From which URL do you want to read JSON data? (only for generating access code in AL)'}) + .then(val => { + if (val === undefined) { + return; + } + + window.showInputBox({prompt: 'What entity are you reading?'}) + .then(val2 => { + if (val2 === undefined) { + return; + } + alr.DoGenerate(editor.document.getText(editor.selection), val2, val); + }); + }); + + + } + + public generateObjectsFromURL() { let alr = this; window.showInputBox({prompt: 'From which URL do you want to read JSON data?'}) .then(val => { @@ -106,6 +131,9 @@ class ALRunner { } window.showInputBox({prompt: 'What entity are you reading?'}) .then(val2 => { + if (val2 === undefined) { + return; + } alr.DoGenerate(body, val2, val); }); }); diff --git a/src/templates.ts b/src/templates.ts index e36b749..4302847 100644 --- a/src/templates.ts +++ b/src/templates.ts @@ -6,10 +6,10 @@ export const tableTemplateBefore: string = `table 50100 ##entity## `; -export const tableFieldTemplate: string = ` field(##id##;##name##;##type##) - { - CaptionML=ENU='##name##'; - } +export const tableFieldTemplate: string = ` field(##id##;##name##;##type##) + { + CaptionML=ENU='##name##'; + } `; export const tableKeyTemplate: string = ` @@ -55,9 +55,9 @@ export const pageTemplateBefore: string = `page 50100 ##entity##List `; -export const pageFieldTemplate: string = ` field(##name##;##name##) { - ApplicationArea = All; - } +export const pageFieldTemplate: string = ` field(##name##;##name##) { + ApplicationArea = All; + } `; export const pageTemplateAfter: string = `