Skip to content

Commit

Permalink
#249 - Prefixing fields and other controls on Report Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
waldo committed Jul 4, 2022
1 parent 75da4a2 commit 79a3c62
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to the "crs-al-language-extension" extension:

## [1.5.13] - 2022-07-04
Fixed [Prefixing fields and other controls on Report Extensions](https://github.com/waldo1001/crs-al-language-extension/issues/249), Reported by [g-franck](https://github.com/g-franck). Thanks!

## [1.5.12] - 2022-07-01
Fixed [Issue with DGML export](https://github.com/waldo1001/crs-al-language-extension/issues/228) (Reported by [tscottjendev](https://github.com/tscottjendev)).

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "crs-al-language-extension",
"displayName": "waldo's CRS AL Language Extension",
"description": "Make working with the (Dynamics NAV / 365) AL Language easier and more efficient.",
"version": "1.5.12",
"version": "1.5.13",
"publisher": "waldo",
"icon": "images/waldo.png",
"author": {
Expand Down
77 changes: 72 additions & 5 deletions src/NAVObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class NAVObject {
public tableFields: NAVTableField[] = new Array();
public pageFields: NAVPageField[] = new Array();
public pageGroups: NAVPageGroup[] = new Array();
public reportColumns: NAVReportColumn[] = new Array();
public extendedObjectName: string;
public extendedObjectId: string;
public NAVObjectText: string;
Expand Down Expand Up @@ -106,7 +107,7 @@ export class NAVObject {
NAVObjectTextFixed = this.AddPrefixAndSuffixToFields(NAVObjectTextFixed);
NAVObjectTextFixed = this.AddPrefixAndSuffixToPageFields(NAVObjectTextFixed);
NAVObjectTextFixed = this.AddPrefixAndSuffixToPageGroups(NAVObjectTextFixed);

NAVObjectTextFixed = this.AddPrefixAndSuffixToReportColumns(NAVObjectTextFixed);

return NAVObjectTextFixed;
}
Expand Down Expand Up @@ -314,6 +315,12 @@ export class NAVObject {
this.pageGroups.push(new NAVPageGroup(result[1], this.objectType, this._workSpaceSettings[Settings.ObjectNamePrefix], this._workSpaceSettings[Settings.ObjectNameSuffix]))
}

var reg = NAVReportColumn.columnRegEx();
var result;
while ((result = reg.exec(this.NAVObjectText)) !== null) {
this.reportColumns.push(new NAVReportColumn(result[1], this.objectType, this._workSpaceSettings[Settings.ObjectNamePrefix], this._workSpaceSettings[Settings.ObjectNameSuffix]))
}

this.NAVObjectText = initNAVObjectText;
}

Expand Down Expand Up @@ -474,6 +481,13 @@ export class NAVObject {
objectText = objectText.replace(group.fullGroupText, group.fullGroupTextFixed);
})

return objectText;
}
private AddPrefixAndSuffixToReportColumns(objectText: string): string {
this.reportColumns.forEach(column => {
objectText = objectText.replace(column.fullColumnText, column.fullColumnTextFixed);
})

return objectText;
}
}
Expand All @@ -491,7 +505,7 @@ class NAVObjectAction {

get nameFixed(): string {
if (!this._prefix && !this._suffix) { return this.name }
if (this._objectType.toLocaleLowerCase() != "pageextension") { return this.name }; //avoid on pages
if (!this._objectType.toLocaleLowerCase().endsWith('extension')) { return this.name }; //only for extensionobjects

let result = this.name
if (this._prefix && !this.name.startsWith(this._prefix)) {
Expand Down Expand Up @@ -542,7 +556,7 @@ class NAVTableField {

get nameFixed(): string {
if (!this._prefix && !this._suffix) { return this.name }
if (this._objectType.toLocaleLowerCase() != "tableextension") { return this.name }; //avoid on tables
if (!this._objectType.toLocaleLowerCase().endsWith('extension')) { return this.name }; //only for extensionobjects

let result = this.name
if (this._prefix && !this.name.startsWith(this._prefix)) {
Expand Down Expand Up @@ -594,7 +608,7 @@ class NAVPageField {

get nameFixed(): string {
if (!this._prefix && !this._suffix) { return this.name }
if (this._objectType.toLocaleLowerCase() != "pageextension") { return this.name }; //avoid on pages
if (!this._objectType.toLocaleLowerCase().endsWith('extension')) { return this.name }; //only for extensionobjects

let result = this.name
if (this._prefix && !this.name.startsWith(this._prefix)) {
Expand Down Expand Up @@ -645,7 +659,7 @@ class NAVPageGroup {

get nameFixed(): string {
if (!this._prefix && !this._suffix) { return this.name }
if (this._objectType.toLocaleLowerCase() != "pageextension") { return this.name }; //avoid on pages
if (!this._objectType.toLocaleLowerCase().endsWith('extension')) { return this.name }; //only for extensionobjects

let result = this.name
if (this._prefix && !this.name.startsWith(this._prefix)) {
Expand Down Expand Up @@ -681,3 +695,56 @@ class NAVPageGroup {
}

}

class NAVReportColumn {
public name: string;
public fullColumnText: string;
public expression: string;
private _objectType: string;
private _prefix: string;
private _suffix: string;

public static columnRegEx(): RegExp {
return /.*(column\( *"?([ a-zA-Z0-9._/&%\/()-]+)"? *; *([" a-zA-Z0-9._/&%\/()-]+) *\))/g;
}

get nameFixed(): string {
if (!this._prefix && !this._suffix) { return this.name }
if (!this._objectType.toLocaleLowerCase().endsWith('extension')) { return this.name }; //only for extensionobjects

let result = this.name
if (this._prefix && !this.name.startsWith(this._prefix)) {
result = this._prefix + result
}
if (this._suffix && !this.name.endsWith(this._suffix)) {
result = result + this._suffix
}
return result
}

get fullColumnTextFixed(): string {
if (!this._prefix && !this._suffix) { return this.fullColumnText }

return "column(" + StringFunctions.encloseInQuotesIfNecessary(this.nameFixed) + "; " + this.expression + ")"
}

constructor(fullColumnText: string, objectType: string, prefix?: string, suffix?: string) {
this.fullColumnText = fullColumnText;
this._prefix = prefix ? prefix : null;
this._suffix = suffix ? suffix : null;
this._objectType = objectType;

this.parseColumnText();
}

private parseColumnText() {
var reg = NAVReportColumn.columnRegEx();
var result = reg.exec(this.fullColumnText)
if (result !== null) {
this.name = result[2].trim().toString();
this.expression = result[3].trim().toString();
}
}

}

56 changes: 56 additions & 0 deletions src/test/suite/NAVObject.PrefexAndSuffix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as myExtension from '../../extension';
import * as NAVTestObjectLibrary from './NAVTestObjectLibrary'
import { Settings } from '../../Settings';
import { settings } from 'cluster';
import { FileDecoration } from 'vscode';

suite("NAVObject ObjectNamePrefix Tests", () => {
test("Object without prefix - No prefix to set", () => {
Expand Down Expand Up @@ -287,5 +288,60 @@ suite("NAVObject ObjectNamePrefix Tests", () => {
assert.strictEqual(navObject.objectFileName.endsWith(testSettings[Settings.ObjectNameSuffix]), false)
assert.notStrictEqual(navObject.objectFileNameFixed.indexOf(testSettings[Settings.ObjectNameSuffix]), -1)
});
test("Reportextension - Set prefix", () => {
let testSettings = Settings.GetConfigSettings(null)
testSettings[Settings.ObjectNamePrefix] = 'waldo';

let navTestObject = NAVTestObjectLibrary.getSimpleReportExtension();
let navObject = new NAVObject(navTestObject.ObjectText, testSettings, navTestObject.ObjectFileName)

assert.notStrictEqual(navObject.reportColumns.length, 0)

navObject.reportColumns.forEach(column => {
assert.strictEqual(column.nameFixed.startsWith(testSettings[Settings.ObjectNamePrefix]), true);
})
});
test("Reportextension - Set Suffix", () => {
let testSettings = Settings.GetConfigSettings(null)
testSettings[Settings.ObjectNameSuffix] = 'waldo';

let navTestObject = NAVTestObjectLibrary.getSimpleReportExtension();
let navObject = new NAVObject(navTestObject.ObjectText, testSettings, navTestObject.ObjectFileName)

assert.notStrictEqual(navObject.reportColumns.length, 0)

navObject.reportColumns.forEach(column => {
assert.strictEqual(column.nameFixed.endsWith(testSettings[Settings.ObjectNameSuffix]), true);
})
});
test("Reportextension - Don't set double suffix", () => {
let testSettings = Settings.GetConfigSettings(null)
testSettings[Settings.ObjectNameSuffix] = 'waldo';

let navTestObject = NAVTestObjectLibrary.getReportExtensionWithSuffix();
let navObject = new NAVObject(navTestObject.ObjectText, testSettings, navTestObject.ObjectFileName)

assert.notStrictEqual(navObject.reportColumns.length, 0)

let navObject2 = new NAVObject(navObject.NAVObjectTextFixed, testSettings, navTestObject.ObjectFileName)
navObject2.reportColumns.forEach(column => {
assert.strictEqual(column.name.endsWith(testSettings[Settings.ObjectNameSuffix]), true);
assert.strictEqual(column.name, column.nameFixed);
})
});
test("Reportextension - Fields on request page", () => {
let testSettings = Settings.GetConfigSettings(null)
testSettings[Settings.ObjectNameSuffix] = 'waldo';

let navTestObject = NAVTestObjectLibrary.getSimpleReportExtension();
let navObject = new NAVObject(navTestObject.ObjectText, testSettings, navTestObject.ObjectFileName)

assert.notStrictEqual(navObject.reportColumns.length, 0)
assert.notStrictEqual(navObject.pageFields.length, 0)

navObject.pageFields.forEach(field => {
assert.strictEqual(field.nameFixed.endsWith(testSettings[Settings.ObjectNameSuffix]), true);
assert.notStrictEqual(field.name, field.nameFixed);
})
});
});
63 changes: 61 additions & 2 deletions src/test/suite/NAVTestObjectLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,13 +899,70 @@ export function getSimpleReportExtension(): NAVTestObject {
{
dataset
{
// Add changes to dataitems and columns here
add(Header)
{
column("APO_YourReference"; YourReference)
{
}
column("APO_YourReference2"; YourReference)
{
}
column("APO_YourReference3"; YourReference)
{
}
}
}
requestpage
{
// Add changes to the requestpage here
layout
{
addfirst(Somewhere)
{
field(Name; Expression)
{
Caption = 'This Field';
}
}
}
}
var
YourReference: Text[35];
}
`
return object;
}
export function getReportExtensionWithSuffix(): NAVTestObject {
let object = new NAVTestObject;

object.ObjectFileName = 'getSimpleReportExtension.al'
object.ObjectText = `reportextension 50100 "Customer Top 10 List Ext" extends "Customer - Top 10 List"
{
dataset
{
add(Header)
{
column("APO_YourReference waldo"; YourReference)
{
}
column("APO_YourReference2 waldo"; YourReference)
{
}
column("APO_YourReference3 waldo"; YourReference)
{
}
}
}
var
YourReference: Text[35];
}
`
return object;
Expand All @@ -932,4 +989,6 @@ export function getSimpleReportExtensionWithSummaryComments(): NAVTestObject {
}
`
return object;

}

0 comments on commit 79a3c62

Please sign in to comment.