Skip to content

Commit

Permalink
Merge pull request #69 from KorzhCom/dev
Browse files Browse the repository at this point in the history
Version 1.3.6
  • Loading branch information
antifree authored Nov 13, 2021
2 parents 79b3cd0 + 03de773 commit 3c1de05
Show file tree
Hide file tree
Showing 44 changed files with 831 additions and 252 deletions.
1 change: 0 additions & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
include-prerelease: true

- name: Setup .NET 5
uses: actions/setup-dotnet@v1
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/netcore-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
include-prerelease: true
- name: Setup .NET 5
uses: actions/setup-dotnet@v1
with:
Expand All @@ -64,7 +63,7 @@ jobs:
run: dotnet pack EasyData.sln -o ./easydata.net/packs --configuration Release --no-restore

- name: Test
run: dotnet test EasyData.Dev.sln --no-restore --verbosity normal
run: dotnet test EasyData.Dev.sln --no-restore --verbosity minimal

- name: Upload artifacts
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion EasyData.Dev.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyData.AspNetCore", "easy
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyData.EntityFrameworkCore.Relational", "easydata.net\src\EasyData.EntityFrameworkCore.Relational\EasyData.EntityFrameworkCore.Relational.csproj", "{6932386C-2619-41F9-B72B-95C989CEA605}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyData.Core.Test", "easydata.net\test\EasyData.Core.Test\EasyData.Core.Test.csproj", "{33EF6180-5CD8-4E00-A015-3715E92B049E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyData.Core.Tests", "easydata.net\test\EasyData.Core.Test\EasyData.Core.Tests.csproj", "{33EF6180-5CD8-4E00-A015-3715E92B049E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyData.AspNetCore.Tests", "easydata.net\test\EasyData.AspNetCore.Tests\EasyData.AspNetCore.Tests.csproj", "{E3DC30EE-52B0-4CEC-959B-71A4DC01DAB7}"
EndProject
Expand Down
8 changes: 2 additions & 6 deletions easydata.js/packs/core/src/http/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export class HttpResponseError extends Error {
}

export class HttpClient {

public defaultHeaders: HttpHeaders;

public customPayload: [string];
Expand Down Expand Up @@ -46,7 +45,6 @@ export class HttpClient {
}

public send<T = any>(method: HttpMethod, url: string, data?: any, options?: HttpRequestOptions): HttpActionResult<T> {

options = options || {};

const dataType = options.dataType || 'json';
Expand Down Expand Up @@ -93,20 +91,18 @@ export class HttpClient {

request.open();

return new HttpActionResult<T>(request, new Promise<T>((resolve, reject) => {

return new HttpActionResult<T>(request, new Promise<T>((resolve, reject) => {
if (options.responseType)
xhr.responseType = options.responseType;

xhr.onreadystatechange = () => {

if (xhr.readyState != 4) {
return;
}

const responseContentType = xhr.getResponseHeader('Content-Type') || '';
const status = xhr.status;
if (status >= 300 || status < 200) {
if (status >= 400) {
const rtPromise = (xhr.responseType === 'arraybuffer'
|| xhr.responseType === 'blob')
? HttpClient.decodeArrayBuffer(xhr.response)
Expand Down
16 changes: 11 additions & 5 deletions easydata.js/packs/core/src/meta/dto/meta_entity_dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ import { DataType } from '../../types/data_type';
export interface MetaEntityDTO {
/** The id. */
id: string;

/** The name. */
name: string;
/**
* The name in plural form
*/

/** The name in the plural form */
namePlur?: string;

/** The description. */
desc?: string;
/** List of sub-entities. */

/** IsEditable */
ied?: boolean;

/** The list of sub-entities. */
ents?: MetaEntityDTO[];
/** List of attributes.*/

/** The list of attributes.*/
attrs?: MetaEntityAttrDTO[];
}

Expand Down
5 changes: 5 additions & 0 deletions easydata.js/packs/core/src/meta/meta_entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class MetaEntity {
/** The description of entity. */
public description: string;

/** Returns false if this entity is read-only */
public isEditable: boolean = true;

/**
* List of Attributes that belong to this entity.
*/
Expand Down Expand Up @@ -65,6 +68,8 @@ export class MetaEntity {
this.captionPlural = dto.namePlur;
this.caption = dto.name;
this.description = dto.desc;
if (typeof(dto.ied) !== 'undefined')
this.isEditable = dto.ied;

this.subEntities = new Array<MetaEntity>();
if (dto.ents) {
Expand Down
1 change: 1 addition & 0 deletions easydata.js/packs/core/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export * from './i18n/i18n'
export * from './utils/easy_guid'
export * from './utils/string_utils'
export * from './utils/utils'
export * from './utils/liquid'

import './i18n/load_default_locale_settings'

Expand Down
13 changes: 13 additions & 0 deletions easydata.js/packs/core/src/utils/liquid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export namespace liquid {
export function renderLiquidTemplate(template : string, vars: any) {
let result = template;

if (vars) {
for (let v in vars) {
const liquidVarRegexp = new RegExp('\{\{' + v + '\}\}', 'g');
result = result.replace(liquidVarRegexp, vars[v]);
}
}
return result;
}
}
90 changes: 53 additions & 37 deletions easydata.js/packs/core/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { i18n } from '../i18n/i18n';


export namespace utils {

export function getAllDataTypes(): DataType[] {
return Object.values(DataType) as DataType[];
}
Expand Down Expand Up @@ -424,15 +423,13 @@ export namespace utils {
function getNowTicks(): number {
return (621355968e9 + (new Date()).getTime() * 1e4)
}



function safeParseInt(str: string) {
const res = parseInt(str);
if (isNaN(res))
throw `"${str}" is not a valid number`;

let isnum = /^\d+$/.test(str);
if (!isnum)
throw "Is not a valid number";

return parseInt(str);
return res;
}

function getDaysInMonth(month, year) {
Expand All @@ -442,70 +439,89 @@ export namespace utils {
// ------------- date/time functions -------------------
// TO DO: improve to process all datetime cases
export function strToDateTime(value: string, format: string): Date {

if (!value || value.length == 0)
return new Date();

const normalized = value.replace(/[^a-zA-Z0-9_]/g, '-');
const normalizedFormat= format.replace(/[^a-zA-Z0-9_]/g, '-');
const formatItems = normalizedFormat.split('-');
const dateItems = normalized.split('-');
const normalizedValue = value.replace(/[^a-zA-Z0-9_]/g, '-');
const normalizedFormat = format.replace(/[^a-zA-Z0-9_]/g, '-');
const formatItems = normalizedFormat.split('-');
const dateItems = normalizedValue.split('-');

const monthIndex = formatItems.indexOf("MM");
const dayIndex = formatItems.indexOf("dd");
const yearIndex = formatItems.indexOf("yyyy");
const hourIndex = formatItems.indexOf("HH");
const dayIndex = formatItems.indexOf("dd");
const yearIndex = formatItems.indexOf("yyyy");
const hourIndex = formatItems.indexOf("HH");
const minutesIndex = formatItems.indexOf("mm");
const secondsIndex = formatItems.indexOf("ss");

const today = new Date();

try {
const year = yearIndex > -1 && yearIndex < dateItems.length ? safeParseInt(dateItems[yearIndex]) : today.getFullYear();
const month = monthIndex > -1 && monthIndex < dateItems.length ? safeParseInt(dateItems[monthIndex]) - 1 : today.getMonth() - 1;
const year = yearIndex > -1 && yearIndex < dateItems.length
? safeParseInt(dateItems[yearIndex])
: today.getFullYear();

const month = monthIndex > -1 && monthIndex < dateItems.length
? safeParseInt(dateItems[monthIndex]) - 1
: today.getMonth() - 1;

if (month > 11)
throw '';

const day = dayIndex > -1 && dayIndex < dateItems.length ? safeParseInt(dateItems[dayIndex]) : today.getDate();
const day = dayIndex > -1 && dayIndex < dateItems.length
? safeParseInt(dateItems[dayIndex])
: today.getDate();

if (day > getDaysInMonth(month, year))
throw '';

const hour = hourIndex > -1 && hourIndex < dateItems.length ? safeParseInt(dateItems[hourIndex]) : 0;
const hour = hourIndex > -1 && hourIndex < dateItems.length
? safeParseInt(dateItems[hourIndex])
: 0;

if (hour > 23)
throw '';

const minute = minutesIndex > -1 && minutesIndex < dateItems.length ? safeParseInt(dateItems[minutesIndex]) : 0;
const minute = minutesIndex > -1 && minutesIndex < dateItems.length
? safeParseInt(dateItems[minutesIndex])
: 0;
if (minute > 59)
throw '';

const second = secondsIndex > -1 && secondsIndex < dateItems.length ? safeParseInt(dateItems[secondsIndex]) : 0;
const second = secondsIndex > -1 && secondsIndex < dateItems.length
? safeParseInt(dateItems[secondsIndex])
: 0;
if (second > 59)
throw '';

return new Date(year,month,day,hour,minute,second);
}
catch {
throw "Is not a valid date time."
throw `${value} is not a valid date.`
}
}

export function strToTime(str: string): Date {

const timeItems = str.split(':');

const hour = timeItems.length > 0 ? safeParseInt(timeItems[0]) : 0;
if (hour > 23)
throw '';

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

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

return new Date(0, 0, 0, hour, minute, second);
try{
const hour = timeItems.length > 0 ? safeParseInt(timeItems[0]) : 0;
if (hour > 23)
throw '';

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

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

return new Date(0, 0, 0, hour, minute, second);
}
catch {
throw `${str} is not a valid time.`
}
}

const DT_FORMAT_RGEX = /\[([^\]]+)]|y{4}|M{1,4}|d{1,2}|H{1,2}|h{1,2}|m{2}|s{2}|t{2}/g;
Expand Down
12 changes: 5 additions & 7 deletions easydata.js/packs/crud/src/main/data_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export class DataContext {
this.setDefaultEndpoints(this.options.endpoint || '/api/easydata')
}

public getActiveEntity() {
return this.activeEntity;
}

public setActiveEntity(entityId: string) {
this.activeEntity = this.model.getRootEntity().subEntities
.filter(e => e.id == entityId)[0];
Expand Down Expand Up @@ -102,20 +106,14 @@ export class DataContext {
});
}


public getActiveEntity() {
return this.activeEntity;
}

public getHttpClient() {
return this.http;
}

public getEntities() {
this.data.clear();
return this.dataLoader.loadChunk({offset: 0, limit: this.data.chunkSize, needTotal: true})
.then(result => {

.then(result => {
for(const col of result.table.columns.getItems()) {
this.data.columns.add(col);
}
Expand Down
14 changes: 10 additions & 4 deletions easydata.js/packs/crud/src/views/entity_data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class EntityDataView {
this.dlg = new DefaultDialogService();

const ent = this.context.getActiveEntity();

this.slot.innerHTML += `<h1>${ent.captionPlural || ent.caption}</h1>`;
if (this.options.showBackToEntities) {
domel(this.slot)
Expand Down Expand Up @@ -107,9 +108,11 @@ export class EntityDataView {
if (column.isRowNum) {
column.width = 110;
return (value: any, column: GridColumn, cell: HTMLElement, rowEl: HTMLElement) => {
domel('div', cell)
.addClass(`keg-cell-value`)
.addChild('a', b => b
const b = domel('div', cell)
.addClass(`keg-cell-value`);

if (this.context.getActiveEntity().isEditable) {
b.addChild('a', b => b
.attr('href', 'javascript:void(0)')
.text(i18n.getText('EditBtn'))
.on('click', (ev) => this.editClickHandler(ev as MouseEvent,
Expand All @@ -123,6 +126,7 @@ export class EntityDataView {
this.deleteClickHandler(ev as MouseEvent,
parseInt(rowEl.getAttribute('data-row-idx'))))
);
}
}
}
}
Expand Down Expand Up @@ -198,7 +202,9 @@ export class EntityDataView {
}

private rowDbClickHandler(ev: RowClickEvent) {
this.showEditForm(ev.row);
if (this.context.getActiveEntity().isEditable) {
this.showEditForm(ev.row);
}
}

private deleteClickHandler(ev: MouseEvent, rowIndex: number) {
Expand Down
Loading

0 comments on commit 3c1de05

Please sign in to comment.