Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/js-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
with:
node-version: 20.x
- name: Install dependencies
run: npm install
run: npm ci

- name: Set version
run: npm run setver
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ MigrationBackup/
easydata.js/**/docs

package-lock.json
!/package-lock.json
dist/

/samples/**/wwwroot/js/easydata.js
Expand Down
2 changes: 1 addition & 1 deletion EasyData.Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyDataBasicDemo.MVC.Net6"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyDataBasicDemo.Angular.Net6", "samples\EasyDataBasicDemo.Angular.Net6\EasyDataBasicDemo.Angular.Net6.csproj", "{4BBC1DDE-416B-4370-9345-0A0FAA53ED63}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyDataBasicDemo.React.Net6", "samples\EasyDataBasicDemo.React.Net6\EasyDataBasicDemo.React.Net6.csproj", "{A1FFADD3-A719-4989-AF96-76CF057595F2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyDataBasicDemo.React.Net10", "samples\EasyDataBasicDemo.React.Net10\EasyDataBasicDemo.React.Net10.csproj", "{A1FFADD3-A719-4989-AF96-76CF057595F2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyDataBasicDemo.BlazorAppServer.Net6", "samples\EasyDataBasicDemo.BlazorAppServer.Net6\EasyDataBasicDemo.BlazorAppServer.Net6.csproj", "{7D40E51C-607D-4017-A11B-901D3AA62DC1}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion easydata.js/bundles/crud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"defaults"
],
"dependencies": {
"@easydata/crud": "^1.5.2"
"@easydata/crud": "*"
},
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion easydata.js/packs/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@easydata/core",
"version": "1.6.0-rc01",
"version": "1.6.0",
"description": "EasyData.JS core functions, classes, and data structures",
"types": "./dist/public_api.d.ts",
"main": "./dist/easydata.core.cjs.js",
Expand Down
5 changes: 4 additions & 1 deletion easydata.js/packs/core/src/data/aggr_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@
? colIndexOrId
: this.colStore.getColumnIds(colIndexOrId, colIndexOrId)[0];

if (this.hasColumnsInUse([colId]) || !this.colStore.validateAggregate(colId, funcId))
if (this.hasColumnsInUse([colId]))
throw "Can't add same columns to different groups/aggregates";

Check warning on line 72 in easydata.js/packs/core/src/data/aggr_settings.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expected an error object to be thrown.

See more on https://sonarcloud.io/project/issues?id=KorzhCom_EasyData&issues=AaC7rBzSTpzexTo1dV6Z&open=AaC7rBzSTpzexTo1dV6Z&pullRequest=212

if (!this.colStore.validateAggregate(colId, funcId))
throw 'Invalid aggregation function for the column: ' + colId;

this.aggregates.push({ colId, funcId });
Expand Down
7 changes: 5 additions & 2 deletions easydata.js/packs/core/src/data/easy_data_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export class EasyDataTable {
if (typeof options.inMemory !== 'undefined') {
this.isInMemory = options.inMemory
}
else if (options.rows && !options.loader) {
// built from rows with nothing to load more from: it holds all its data
this.isInMemory = true;
}
if (this.isInMemory) {
this.needTotal = false;
this.totalKnown = true;
Expand All @@ -102,8 +106,7 @@ export class EasyDataTable {

if (options.rows) {
for (const rowData of options.rows) {
const row = this.createRow(rowData);
this.addRow(row);
this.addRow(rowData);
}
}

Expand Down
9 changes: 4 additions & 5 deletions easydata.js/packs/core/src/http/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,15 @@ export class HttpClient {
options = options || {};

const dataType = options.dataType || 'json';
const contentType = options.contentType || (dataType !== 'form-data')
? 'application/json'
: null;
const contentType = options.contentType
|| (dataType !== 'form-data' ? 'application/json' : null);

if (data && dataType != 'form-data' && this.customPayload) {
data.data = utils.assignDeep(data.data || {}, this.customPayload);
}

const XHR = ('onload' in new XMLHttpRequest())
? XMLHttpRequest
const XHR = (typeof XMLHttpRequest !== 'undefined')
? XMLHttpRequest
: window["XDomainRequest"]; //IE support

const xhr: XMLHttpRequest = new XHR();
Expand Down
6 changes: 3 additions & 3 deletions easydata.js/packs/core/src/http/http_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export class HttpRequest {

let url = this.url;
if (this.queryParams && Object.keys(this.queryParams).length > 0) {
url += encodeURI('?' + Object.keys(this.queryParams)
.map(param => param + '=' + this.queryParams[param])
.join('&'));
url += '?' + Object.keys(this.queryParams)
.map(param => encodeURIComponent(param) + '=' + encodeURIComponent(this.queryParams[param]))
.join('&');
}

this.xhr.open(this.method, url, true);
Expand Down
12 changes: 8 additions & 4 deletions easydata.js/packs/core/src/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,15 @@ export namespace i18n {
determineSettingsByLocale(lang);
}

/**
* Resets the locales to the initial state: the default (en-US) locale only, as the current one.
*/
export function resetLocales() {
if (!currentLocale) {
currentLocale = utils.assignDeep({}, defaultLocale);
loadBrowserLocaleSettings();
}
allLocales = {
'en-US': defaultLocale
};
currentLocale = utils.assignDeep({}, defaultLocale);
loadBrowserLocaleSettings();
}
const DT_FORMAT_RGEX = /\[([^\]]+)]|y{2,4}|M{1,4}|d{1,2}|H{1,2}|h{1,2}|m{2}|s{2}|t{2}/g;

Expand Down
3 changes: 2 additions & 1 deletion easydata.js/packs/core/src/meta/meta_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
this.id = '__none';
this.name = 'Empty model';
this.rootEntity = this.createEntity();
this.editors = [];

this.displayFormats = new Map<DataType, DisplayFormatDescriptor[]>();
}
Expand Down Expand Up @@ -232,7 +233,7 @@
else if (attribute.lookupAttr) {
attrId = attribute.lookupAttr;
attribute = this.getAttributeById(attrId);
return attribute && attribute[propName];
return !!(attribute && attribute[propName]);

Check warning on line 236 in easydata.js/packs/core/src/meta/meta_data.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=KorzhCom_EasyData&issues=AaC7rBxgTpzexTo1dV6V&open=AaC7rBxgTpzexTo1dV6V&pullRequest=212
}
else {
return false;
Expand Down
5 changes: 3 additions & 2 deletions easydata.js/packs/core/src/meta/meta_entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class MetaEntity {
}

public getFirstPrimaryAttr(): MetaEntityAttr | null {
return this.getPrimaryAttrs()[0];
return this.getPrimaryAttrs()[0] || null;
}

public getPrimaryAttrs(): MetaEntityAttr[] {
Expand Down Expand Up @@ -275,7 +275,8 @@ export class MetaEntityAttr {

this.isNullable = utils.getIfDefined(dto.nul, this.isNullable);
this.isEditable = utils.getIfDefined(dto.ied, this.isEditable);
this.showOnView = utils.getIfDefined(dto.ivis || dto.sov, this.showOnView);
// 'ivis' is the old name of 'sov'; `||` would lose an explicit false
this.showOnView = utils.getIfDefined(utils.getIfDefined(dto.sov, dto.ivis), this.showOnView);
this.showOnCreate = utils.getIfDefined(dto.soc, this.showOnCreate);
this.showOnEdit = utils.getIfDefined(dto.soe, this.showOnEdit);
this.showInLookup = utils.getIfDefined(dto.sil, this.showInLookup);
Expand Down
10 changes: 7 additions & 3 deletions easydata.js/packs/core/src/meta/value_editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@
public loadFromData(data: ValueEditorDTO) {
if (data) {
this.id = data.id;
this.tag = data.tag;
this.defValue = data.defval;
this.resType = data.rtype;
// keep the defaults for whatever the DTO leaves out
if (typeof data.tag !== 'undefined')

Check warning on line 76 in easydata.js/packs/core/src/meta/value_editor.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Compare with `undefined` directly instead of using `typeof`.

See more on https://sonarcloud.io/project/issues?id=KorzhCom_EasyData&issues=AaC7rByCTpzexTo1dV6W&open=AaC7rByCTpzexTo1dV6W&pullRequest=212
this.tag = data.tag;
if (typeof data.defval !== 'undefined')

Check warning on line 78 in easydata.js/packs/core/src/meta/value_editor.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Compare with `undefined` directly instead of using `typeof`.

See more on https://sonarcloud.io/project/issues?id=KorzhCom_EasyData&issues=AaC7rByCTpzexTo1dV6X&open=AaC7rByCTpzexTo1dV6X&pullRequest=212
this.defValue = data.defval;
if (typeof data.rtype !== 'undefined')

Check warning on line 80 in easydata.js/packs/core/src/meta/value_editor.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Compare with `undefined` directly instead of using `typeof`.

See more on https://sonarcloud.io/project/issues?id=KorzhCom_EasyData&issues=AaC7rByCTpzexTo1dV6Y&open=AaC7rByCTpzexTo1dV6Y&pullRequest=212
this.resType = data.rtype;
this.accept = data.accept;
this.multiline = data.multiline;
if (data.subType) {
Expand Down
4 changes: 2 additions & 2 deletions easydata.js/packs/core/src/types/time_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export class TimeValue {
return this.date;
}
else {
specialDatesResolver.getDateByName(this._name);
return specialDatesResolver.getDateByName(this._name, settings);
}
}

get name() : string {
return this.name;
return this._name;
}
}

Expand Down
4 changes: 2 additions & 2 deletions easydata.js/packs/core/src/utils/string_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


export function strEndsWith(str : string, symbol: string): boolean {
return str && str.lastIndexOf(symbol) == (str.length - symbol.length);
return typeof str === 'string' && str.endsWith(symbol);
}

/**
Expand All @@ -23,7 +23,7 @@

if (result.charAt(result.length - 1) != '/')
result += "/";
result += path2;
result += (path2 && path2.charAt(0) == '/') ? path2.substring(1) : path2;

Check warning on line 26 in easydata.js/packs/core/src/utils/string_utils.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=KorzhCom_EasyData&issues=AaC7rBv3TpzexTo1dV6T&open=AaC7rBv3TpzexTo1dV6T&pullRequest=212

Check warning on line 26 in easydata.js/packs/core/src/utils/string_utils.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'String#startsWith' method instead.

See more on https://sonarcloud.io/project/issues?id=KorzhCom_EasyData&issues=AaC7rBv3TpzexTo1dV6U&open=AaC7rBv3TpzexTo1dV6U&pullRequest=212
}
else {
result = path2;
Expand Down
7 changes: 6 additions & 1 deletion easydata.js/packs/core/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export namespace utils {

for (let source of sources) {
if (source && source.hasOwnProperty) {
// a reference back to the source itself must point to the target
if (typeof source === 'object' && !hashSet.has(source)) {
hashSet.set(source, target);
}

for (let key in source) {
if (source.hasOwnProperty(key)) {
let sourceVal = source[key];
Expand Down Expand Up @@ -520,7 +525,7 @@ export namespace utils {
if (minute > 59)
throw '';

const second = timeItems.length > 1 ? safeParseInt(timeItems[1]) : 0
const second = timeItems.length > 2 ? safeParseInt(timeItems[2]) : 0;
if (second > 59)
throw '';

Expand Down
26 changes: 14 additions & 12 deletions easydata.js/packs/core/tests/aggr_settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import {
} from '../src/data/aggr_settings';
import { AggregationColumnStore, DataGroup, GroupDescriptor } from '../src/data/aggr_structures';
import { DataRow } from '../src/data/data_row';
import { thrownMessage } from './helpers/errors';

describe('AggregationSettings', () => {
let columnStore: AggregationColumnStore;
let settings: AggregationSettings;

beforeEach(() => {
// Creating a mock for AggregationColumnStore
columnStore = mock<AggregationColumnStore>({
// Creating a mock for AggregationColumnStore (a plain object:
// latte's mock() turns an object into a function returning it)
columnStore = <AggregationColumnStore>({
getColumnIds: (from, to) => {
const result = [];
for (let i = from; i <= to; i++) {
Expand Down Expand Up @@ -77,9 +79,9 @@ describe('AggregationSettings', () => {
title: 'Invalid Group'
};

expect(() => {
expect(thrownMessage(() => {
settings.addGroup(groupDescriptor);
}).toThrow("Invalid columns");
})).toMatch(/^Invalid columns/);
});

it('should add aggregate column correctly', () => {
Expand All @@ -92,25 +94,25 @@ describe('AggregationSettings', () => {
});

it('should throw error when adding invalid aggregate function', () => {
expect(() => {
expect(thrownMessage(() => {
settings.addAggregateColumn('col5', 'invalid_func');
}).toThrow('Invalid aggregation function');
})).toMatch(/^Invalid aggregation function/);
});

it('should throw error when adding same column to different groups', () => {
settings.addGroup({ columns: ['col1', 'col2'] });

expect(() => {
expect(thrownMessage(() => {
settings.addGroup({ columns: ['col2', 'col3'] });
}).toThrow("Can't add same columns to different groups/aggregates");
})).toBe("Can't add same columns to different groups/aggregates");
});

it('should throw error when adding column to both group and aggregate', () => {
settings.addGroup({ columns: ['col1', 'col2'] });

expect(() => {
expect(thrownMessage(() => {
settings.addAggregateColumn('col1', 'sum');
}).toThrow("Can't add same columns to different groups/aggregates");
})).toBe("Can't add same columns to different groups/aggregates");
});

it('should add grand totals correctly', () => {
Expand Down Expand Up @@ -181,7 +183,7 @@ describe('AggregationSettings', () => {

it('should build group key correctly', () => {
const group: DataGroup = { columns: ['col1', 'col2'] };
const row = mock<DataRow>({
const row = <DataRow><any>({
getValue: (colId) => {
if (colId === 'col1') return 'Value1';
if (colId === 'col2') return 'Value2';
Expand All @@ -196,7 +198,7 @@ describe('AggregationSettings', () => {

it('should build group key with case sensitivity', () => {
const group: DataGroup = { columns: ['col1', 'col2'] };
const row = mock<DataRow>({
const row = <DataRow><any>({
getValue: (colId) => {
if (colId === 'col1') return 'Value1';
if (colId === 'col2') return 'Value2';
Expand Down
2 changes: 1 addition & 1 deletion easydata.js/packs/core/tests/aggr_structures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('AggregatesCalculator Interface', () => {
errorOccurred: errorCallback
});

expect(resultCallback).toHaveBeenCalledWith({ sum: 100, count: 10 }, 1);
expect(resultCallback).toHaveBeenCalledWith([{ sum: 100, count: 10 }, 1]);
expect(errorCallback).not.toHaveBeenCalled();
expect(calculator.needRecalculation()).toBe(false);
});
Expand Down
Loading
Loading