Skip to content

Commit

Permalink
Merge pull request #120 from KorzhCom/dev
Browse files Browse the repository at this point in the history
Version 1.4.3
  • Loading branch information
korzh authored Feb 16, 2022
2 parents 6a8ecec + 0710fac commit 2f55a8c
Show file tree
Hide file tree
Showing 22 changed files with 234 additions and 162 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,4 @@ dist/
!/playground/**/ts/styles.js
/easydata.net/src/**/EasyData*.xml
/playground/EasyDataTest
/playground/EasyDataTest02
41 changes: 22 additions & 19 deletions easydata.js/packs/core/src/http/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,31 @@ export class HttpClient {
if (options.responseType)
xhr.responseType = options.responseType;

xhr.onerror = (error) => {
reject(new HttpResponseError(xhr.status, xhr.responseText));
};

xhr.onreadystatechange = () => {
if (xhr.readyState != 4) {
return;
}
if (xhr.readyState != 4) return; //we process only the state change to DONE(4)

const responseContentType = xhr.getResponseHeader('Content-Type') || '';
const status = xhr.status;
if (status >= 400) {
const rtPromise = (xhr.responseType === 'arraybuffer'
|| xhr.responseType === 'blob')
if (status === 0) {
reject(new HttpResponseError(status, "Network error or the request was aborted"));
}
else if (status >= 200 && status < 400) {
//Success
const responseObj = (xhr.responseType === 'arraybuffer'|| xhr.responseType === 'blob')
? xhr.response
: (responseContentType.indexOf('application/json') == 0
? JSON.parse(xhr.responseText)
: xhr.responseText);

resolve(responseObj);
}
else {
//Error
const rtPromise = (xhr.responseType === 'arraybuffer' || xhr.responseType === 'blob')
? HttpClient.decodeArrayBuffer(xhr.response)
: Promise.resolve(xhr.responseText);

Expand All @@ -119,23 +134,11 @@ export class HttpClient {
: responseObj);

reject(new HttpResponseError(status, message));
});

return;
});
}

const responseObj =
(xhr.responseType === 'arraybuffer'|| xhr.responseType === 'blob')
? xhr.response
: (responseContentType.indexOf('application/json') == 0)
? JSON.parse(xhr.responseText)
: xhr.responseText;

resolve(responseObj);
}

xhr.send(dataToSend);

}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ export class EasyDataViewDispatcher {
return idIndex < path.length ? path.substring(idIndex) : null;
}

run(): Promise<void> {

run(): Promise<void> {
this.attach();

return this.context.loadMetaData()
Expand Down
28 changes: 15 additions & 13 deletions easydata.js/packs/crud/src/views/entity_data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { EasyDataViewOptions } from './options';
import { setLocation } from '../utils/utils';

export class EntityDataView {

private options: EasyDataViewOptions = {
showFilterBox: true,
showBackToEntities: true
}

Expand Down Expand Up @@ -91,18 +91,20 @@ export class EntityDataView {
onSyncGridColumn: this.syncGridColumnHandler.bind(this)
}, this.options.grid || {}));

let widgetSlot: HTMLElement;
const filterBar = domel('div')
.addClass(`kfrm-form`)
.setStyle('margin', '10px 0px')
.addChild('div', b =>
widgetSlot = b.toDOM()
).toDOM();

this.slot.insertBefore(filterBar, gridSlot);

const dataFilter = this.context.createFilter();
new TextFilterWidget(widgetSlot, this.grid, dataFilter);
if (this.options.showFilterBox) {
let filterWidgetSlot: HTMLElement;
const filterBarDiv = domel('div')
.addClass(`kfrm-form`)
.setStyle('margin', '10px 0px')
.addChild('div', b =>
filterWidgetSlot = b.toDOM()
).toDOM();

this.slot.insertBefore(filterBarDiv, gridSlot);

const dataFilter = this.context.createFilter();
new TextFilterWidget(filterWidgetSlot, this.grid, dataFilter);
}
});
}

Expand Down
1 change: 1 addition & 0 deletions easydata.js/packs/crud/src/views/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EasyDataTableOptions } from '@easydata/core';
import { EasyGridOptions } from '@easydata/ui';

export interface EasyDataViewOptions {
showFilterBox?: boolean;
showBackToEntities?: boolean,
grid?: Omit<EasyGridOptions, 'slot' | 'dataTable'>,
dataTable?: EasyDataTableOptions
Expand Down
1 change: 0 additions & 1 deletion easydata.js/packs/crud/src/views/root_data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { setLocation } from '../utils/utils';
import { DataContext } from '../main/data_context';

export class RootDataView {

private metaData: MetaData;

constructor (
Expand Down
2 changes: 2 additions & 0 deletions easydata.js/packs/ui/assets/css/easy-dialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@
padding: 20px;
background-color: #e2f5ff;
color: #004aef;
min-width: 1px;
min-height: 60px;
}

.kdlg-alert.success {
Expand Down
13 changes: 10 additions & 3 deletions easydata.js/packs/ui/src/grid/easy_grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ export class EasyGrid {
}

protected renderCell(column: GridColumn, colIndex: number, value: any, rowElement: HTMLElement): HTMLDivElement {
let builder = domel('div')
const builder = domel('div')
.addClass(`${this.cssPrefix}-cell`)
.data('col-idx', `${colIndex}`)
.attr('tabindex', '-1')
Expand All @@ -983,11 +983,18 @@ export class EasyGrid {
builder.addClass(`${this.cssPrefix}-cell-align-center`);
}

const cellElement = builder.toDOM();
const valueCell = cellElement.appendChild(
domel('div')
.addClass(`${this.cssPrefix}-cell-value`)
.toDOM()
);

if (column.cellRenderer) {
column.cellRenderer(value, column, builder.toDOM(), rowElement);
column.cellRenderer(value, column, valueCell, rowElement);
}

return builder.toDOM();
return cellElement;
}

public setPage(page: number) {
Expand Down
45 changes: 17 additions & 28 deletions easydata.js/packs/ui/src/grid/easy_grid_cell_renderer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { i18n, DataType } from '@easydata/core';

import { GridColumn, GridColumnAlign } from './easy_grid_columns';
import { domel } from '../utils/dom_elem_builder';
import { EasyGridOptions } from './easy_grid_options';

const cssPrefix = "keg";
Expand All @@ -15,23 +14,21 @@ export enum CellRendererType {
}

export type GridCellRenderer = (value: any, column: GridColumn,
cellElement: HTMLElement, rowElement: HTMLElement, isGroup?: boolean) => void;
cellValueElement: HTMLElement, rowElement: HTMLElement, isGroup?: boolean) => void;


const StringCellRendererDefault: GridCellRenderer = (value: any, column: GridColumn, cellElement: HTMLElement, rowElement: HTMLElement) => {
const StringCellRendererDefault: GridCellRenderer = (value: any, column: GridColumn, cellValueElement: HTMLElement, rowElement: HTMLElement) => {
const text = value ? value.toString().replace(/\n/g, '\u21B5 ') : '';
const builder = domel('div', cellElement)
.addClass(`${cssPrefix}-cell-value`)
.addHtml(text)
.title(value || '');

cellValueElement.innerHTML = text;
cellValueElement.title = text;
if (column.align == GridColumnAlign.NONE) {
builder.addClass(`${cssPrefix}-cell-value-align-left`);
cellValueElement.classList.add(`${cssPrefix}-cell-value-align-left`);
}
}


const NumberCellRendererDefault: GridCellRenderer = (value: any, column: GridColumn, cellElement: HTMLElement, rowElement: HTMLElement) => {
const NumberCellRendererDefault: GridCellRenderer = (value: any, column: GridColumn, cellValueElement: HTMLElement, rowElement: HTMLElement) => {
let strValue = (value || '').toString();

if(typeof value == 'number') {
Expand All @@ -47,17 +44,14 @@ const NumberCellRendererDefault: GridCellRenderer = (value: any, column: GridCol
}
}

const builder = domel('div', cellElement)
.addClass(`${cssPrefix}-cell-value`)
.addHtml(strValue)
.title(strValue);

cellValueElement.innerHTML = strValue;
cellValueElement.title = strValue;
if (column.align == GridColumnAlign.NONE) {
builder.addClass(`${cssPrefix}-cell-value-align-right`);
cellValueElement.classList.add(`${cssPrefix}-cell-value-align-right`);
}
}

const DateTimeCellRendererDefault: GridCellRenderer = (value: any, column: GridColumn, cellElement: HTMLElement, rowElement: HTMLElement) => {
const DateTimeCellRendererDefault: GridCellRenderer = (value: any, column: GridColumn, cellValueElement: HTMLElement, rowElement: HTMLElement) => {
const isDate = Object.prototype.toString.call(value) === '[object Date]';
let strValue = (value || '').toString();

Expand Down Expand Up @@ -86,31 +80,26 @@ const DateTimeCellRendererDefault: GridCellRenderer = (value: any, column: GridC
}
}

const builder = domel('div', cellElement)
.addClass(`${cssPrefix}-cell-value`)
.addHtml(strValue)
.title(strValue);

cellValueElement.innerHTML = strValue;
cellValueElement.title = strValue;
if (column.align == GridColumnAlign.NONE) {
builder.addClass(`${cssPrefix}-cell-value-align-right`);
cellValueElement.classList.add(`${cssPrefix}-cell-value-align-right`);
}
}


const BoolCellRendererDefault: GridCellRenderer = (value: any, column: GridColumn, cellElement: HTMLElement, rowElement: HTMLElement) => {
const BoolCellRendererDefault: GridCellRenderer = (value: any, column: GridColumn, cellValueElement: HTMLElement, rowElement: HTMLElement) => {
if (column.dataColumn && column.dataColumn.displayFormat
&& DFMT_REGEX.test(column.dataColumn.displayFormat)) {
const strValue = column.dataColumn.displayFormat.replace(DFMT_REGEX, (_, $1) => {
return i18n.booleanToStr(value, $1);
});

return StringCellRendererDefault(strValue, column, cellElement, rowElement);
return StringCellRendererDefault(strValue, column, cellValueElement, rowElement);
}
else {
domel('div', cellElement)
.addClass(`${cssPrefix}-cell-value`)
.addClass(`${cssPrefix}-cell-value-bool`)
.addClass(`${cssPrefix}-${value ? 'cell-value-true' : 'cell-value-false'}`);
cellValueElement.classList.add(`${cssPrefix}-cell-value-bool`);
cellValueElement.classList.add(`${cssPrefix}-${value ? 'cell-value-true' : 'cell-value-false'}`);
}

}
Expand Down
6 changes: 3 additions & 3 deletions easydata.js/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.4.2",
"baseVersion": "1.4.2",
"assetVersion": "01_04_02",
"version": "1.4.3",
"baseVersion": "1.4.3",
"assetVersion": "01_04_03",
"tag": "latest"
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public class EasyDataApiHandler
/// </summary>
protected readonly EasyDataOptions Options;

private static JsonSerializer _jsonSerializer;

static EasyDataApiHandler()
{
_jsonSerializer = new JsonSerializer();
_jsonSerializer.MaxDepth = 1;
_jsonSerializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
}


/// <summary>
/// Initializes a new instance of the <see cref="EasyDataApiHandler"/> class.
/// </summary>
Expand Down Expand Up @@ -175,9 +185,14 @@ await WriteOkJsonResponseAsync(HttpContext, async (jsonWriter, cancellationToken
}, ct);
}

protected virtual JObject ToJObject(object entity)
{
return JObject.FromObject(entity, _jsonSerializer);
}

protected virtual async Task WriteFetchRecordResponseAsync(JsonWriter jsonWriter, object entity, CancellationToken ct)
{
var jObj = JObject.FromObject(entity);
var jObj = ToJObject(entity);
await jsonWriter.WritePropertyNameAsync("record", ct);
await jObj.WriteToAsync(jsonWriter, ct);
}
Expand All @@ -198,7 +213,7 @@ await WriteOkJsonResponseAsync(HttpContext, async (jsonWriter, cancellationToken

protected virtual async Task WriteCreateRecordResponseAsync(JsonWriter jsonWriter, object entity, CancellationToken ct)
{
var jObj = JObject.FromObject(entity);
var jObj = ToJObject(entity);
await jsonWriter.WritePropertyNameAsync("record", ct);
await jObj.WriteToAsync(jsonWriter, ct);
}
Expand All @@ -221,7 +236,7 @@ protected virtual async Task WriteUpdateRecordResponseAsync(JsonWriter jsonWrite
{
ct.ThrowIfCancellationRequested();

var jObj = JObject.FromObject(entity);
var jObj = ToJObject(entity);
await jsonWriter.WritePropertyNameAsync("record", ct);
await jObj.WriteToAsync(jsonWriter, ct);
}
Expand Down Expand Up @@ -290,6 +305,7 @@ protected static async Task WriteJsonResponseAsync(HttpContext context, string r
}
await jsonWriter.WriteEndObjectAsync(ct);
await jsonWriter.FlushAsync(ct);
await jsonWriter.CloseAsync(ct);
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions easydata.net/src/EasyData.Core/Common/DataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,22 @@ public DataTypeList() : base()
/// The list which represents the most common data types
/// </summary>
static public readonly DataTypeList CommonDataTypes = new DataTypeList(new DataType[] {
DataType.String,
DataType.Byte,
DataType.Word,
DataType.Int32,
DataType.Int64,
DataType.Autoinc,
DataType.Blob,
DataType.Bool,
DataType.Float,
DataType.Byte,
DataType.Currency,
DataType.BCD,
DataType.Date,
DataType.Time,
DataType.DateTime,
DataType.Autoinc,
DataType.FixedChar,
DataType.Float,
DataType.Guid,
DataType.Int32,
DataType.Int64,
DataType.Memo,
DataType.FixedChar
DataType.String,
DataType.Time,
DataType.Word
});

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion easydata.net/src/EasyData.Core/EasyData.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

</Project>
Loading

0 comments on commit 2f55a8c

Please sign in to comment.