Skip to content

Commit

Permalink
Merge pull request #134 from KorzhCom/dev
Browse files Browse the repository at this point in the history
Version 1.4.5
  • Loading branch information
antifree authored May 13, 2022
2 parents 85fbdd8 + bee25e7 commit fd1fa08
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 60 deletions.
19 changes: 14 additions & 5 deletions easydata.js/packs/crud/src/views/entity_data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class EntityDataView {

private grid: EasyGrid;

private filterWidget : TextFilterWidget;

private defaultValidators: Validator[] = [ new RequiredValidator(), new TypeValidator()];

constructor (
Expand Down Expand Up @@ -103,7 +105,7 @@ export class EntityDataView {
this.slot.insertBefore(filterBarDiv, gridSlot);

const dataFilter = this.context.createFilter();
new TextFilterWidget(filterWidgetSlot, this.grid, dataFilter);
this.filterWidget = new TextFilterWidget(filterWidgetSlot, this.grid, dataFilter);
}
});
}
Expand Down Expand Up @@ -164,7 +166,7 @@ export class EntityDataView {
}

private editClickHandler(ev: MouseEvent, rowIndex: number) {
this.context.getData().getRow(rowIndex)
this.grid.getData().getRow(rowIndex)
.then(row => {
if (row) {
this.showEditForm(row);
Expand All @@ -191,7 +193,7 @@ export class EntityDataView {

form.getData()
.then(obj => this.context.updateRecord(obj))
.then(() => {
.then(() => {
return this.refreshData();
})
.catch((error) => {
Expand All @@ -208,7 +210,7 @@ export class EntityDataView {
}

private deleteClickHandler(ev: MouseEvent, rowIndex: number) {
this.context.getData().getRow(rowIndex)
this.grid.getData().getRow(rowIndex)
.then(row => {
if (row) {
const activeEntity = this.context.getActiveEntity();
Expand Down Expand Up @@ -253,7 +255,14 @@ export class EntityDataView {
private refreshData(): Promise<void> {
return this.context.fetchDataset()
.then(() => {
this.grid.refresh();
let processed = false;
if (this.filterWidget) {
processed = this.filterWidget.applyFilter(false);
}

if (!processed) {
this.grid.refresh();
}
});
}
}
76 changes: 43 additions & 33 deletions easydata.js/packs/crud/src/widgets/text_filter_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface TextFilterWidgetOptions {
}

export class TextFilterWidget {

private options = {
focus: false,
instantMode: false,
Expand Down Expand Up @@ -45,8 +44,7 @@ export class TextFilterWidget {

private filterInput: HTMLInputElement;

private render() {

private render() {
const horizClass = browserUtils.IsIE()
? 'kfrm-fields-ie is-horizontal'
: 'kfrm-fields is-horizontal';
Expand Down Expand Up @@ -103,7 +101,7 @@ export class TextFilterWidget {

private inputKeydownHandler(ev: Event) {
if ((ev as KeyboardEvent).keyCode == 13) {
this.applyFilter();
this.applyFilter(true);
}
}

Expand All @@ -113,33 +111,35 @@ export class TextFilterWidget {
}

this.applyFilterTimeout = setTimeout(() => {
this.applyFilter();
this.applyFilter(true);
}, this.options.instantTimeout);
}

private clearButtonClickHander() {
this.filterInput.value = '';
this.filterInput.focus();

this.applyFilter();
this.applyFilter(true);
}

private searchButtonClickHandler() {
this.applyFilter();
this.applyFilter(true);
}

private applyFilter() {
public applyFilter(checkChange : boolean) : boolean {
if (this.applyFilterTimeout) {
clearTimeout(this.applyFilterTimeout);
}

const filterValue = this.filter.getValue();
if (filterValue != this.filterInput.value) {
if (!checkChange || filterValue != this.filterInput.value) {
this.filter.apply(this.filterInput.value)
.then(data => {
this.grid.setData(data);
});
return true;
}
return false;
}

private highlightCellRenderer(defaultRenderer: GridCellRenderer, value: any, column: GridColumn, cellElement: HTMLElement, rowElement: HTMLElement) {
Expand All @@ -157,29 +157,37 @@ export class TextFilterWidget {
value = value.toLocaleString();
}

value = this.highlightText(value.toString());

const result = this.highlightText(value.toString());
if (result instanceof HTMLElement) {
cellElement.title = value;
cellElement.appendChild(result);
return;
}
}
}

defaultRenderer(value, column, cellElement, rowElement);
}

private highlightText(content: string): string {
private highlightText(content: string): HTMLElement | string{
const normalizedContent = content.toLowerCase();
const filterValue = this.filter.getValue().toString();
if (filterValue && filterValue.length > 0 && content && content.length > 0) {
const insertValue1 = `<span style='background-color: yellow'>`;
const insertValue2 = `</span>`;

let indexInMas = [];

const indexInMas = [];
const words = filterValue.split('||').map(w => w.trim().toLowerCase());
for(let i = 0; i < words.length; i++) {
let pos = 0;
let lowerWord = words[i];
const lowerWord = words[i];
if (!lowerWord.length)
continue;
if (lowerWord === normalizedContent) {
return insertValue1 + content + insertValue2;
const highlightSpan = document.createElement('span');
highlightSpan.style.backgroundColor = 'yellow';
highlightSpan.innerText = content;

return highlightSpan;
}
while (pos < content.length - 1) {
const index = normalizedContent.indexOf(lowerWord, pos);
Expand Down Expand Up @@ -223,28 +231,30 @@ export class TextFilterWidget {
}
}

let result = '';
const div = document.createElement('div');
for (let i = 0; i < indexInMas.length; i++) {
if (i === 0) {
result += content.substring(0, indexInMas[i].index);
}

result += insertValue1
+ content.substring(indexInMas[i].index,
indexInMas[i].index + indexInMas[i].length)
+ insertValue2;

if (i < indexInMas.length - 1) {
result += content.substring(indexInMas[i].index
+ indexInMas[i].length, indexInMas[i + 1].index);
} else {
result += content.substring(indexInMas[i].index
+ indexInMas[i].length);
const text = document.createTextNode(content.substring(0, indexInMas[i].index));
div.appendChild(text);
}

const highlightSpan = document.createElement('span');
highlightSpan.style.backgroundColor = 'yellow';
highlightSpan.innerText = content.substring(indexInMas[i].index,
indexInMas[i].index + indexInMas[i].length)

div.appendChild(highlightSpan);

const text = (i < indexInMas.length - 1)
? document.createTextNode(content.substring(indexInMas[i].index
+ indexInMas[i].length, indexInMas[i + 1].index))
: document.createTextNode(content.substring(indexInMas[i].index
+ indexInMas[i].length));

div.appendChild(text);
}

content = result;
return div;
}
}

Expand Down
9 changes: 3 additions & 6 deletions easydata.js/packs/ui/src/grid/easy_grid_cell_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type GridCellRenderer = (value: any, column: GridColumn,
const StringCellRendererDefault: GridCellRenderer = (value: any, column: GridColumn, cellValueElement: HTMLElement, rowElement: HTMLElement) => {
const text = value ? value.toString().replace(/\n/g, '\u21B5 ') : '';

cellValueElement.innerHTML = text;
cellValueElement.innerText = text;
cellValueElement.title = text;
if (column.align == GridColumnAlign.NONE) {
cellValueElement.classList.add(`${cssPrefix}-cell-value-align-left`);
Expand All @@ -44,7 +44,7 @@ const NumberCellRendererDefault: GridCellRenderer = (value: any, column: GridCol
}
}

cellValueElement.innerHTML = strValue;
cellValueElement.innerText = strValue;
cellValueElement.title = strValue;
if (column.align == GridColumnAlign.NONE) {
cellValueElement.classList.add(`${cssPrefix}-cell-value-align-right`);
Expand Down Expand Up @@ -80,7 +80,7 @@ const DateTimeCellRendererDefault: GridCellRenderer = (value: any, column: GridC
}
}

cellValueElement.innerHTML = strValue;
cellValueElement.innerText = strValue;
cellValueElement.title = strValue;
if (column.align == GridColumnAlign.NONE) {
cellValueElement.classList.add(`${cssPrefix}-cell-value-align-right`);
Expand All @@ -101,11 +101,8 @@ const BoolCellRendererDefault: GridCellRenderer = (value: any, column: GridColum
cellValueElement.classList.add(`${cssPrefix}-cell-value-bool`);
cellValueElement.classList.add(`${cssPrefix}-${value ? 'cell-value-true' : 'cell-value-false'}`);
}

}



interface CellRendererCollection {
[name: string]: GridCellRenderer;
}
Expand Down
8 changes: 4 additions & 4 deletions easydata.js/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.4.4",
"baseVersion": "1.4.4",
"assetVersion": "01_04_04",
"tag": "latest"
"version": "1.4.5",
"baseVersion": "1.4.5",
"assetVersion": "01_04_05",
"tag": "latest"
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ Task WriteRowAsync(EasyDataRow row, bool isExtraRow = false,
continue;

if (mappedSettings.BeforeRowInsert != null)
await mappedSettings.BeforeRowInsert(row, WriteExtraRowAsync, ct);
await mappedSettings.BeforeRowInsert(row, WriteExtraRowAsync, ct).ConfigureAwait(false);

await WriteRowAsync(row, cancellationToken: ct);
await WriteRowAsync(row, cancellationToken: ct).ConfigureAwait(false);

currentRowNum++;
}

if (mappedSettings.BeforeRowInsert != null)
await mappedSettings.BeforeRowInsert(null, WriteExtraRowAsync, ct);
await mappedSettings.BeforeRowInsert(null, WriteExtraRowAsync, ct).ConfigureAwait(false);

cellNum--;

Expand Down
16 changes: 10 additions & 6 deletions easydata.net/src/EasyData.Exporters.Default/Csv/CsvDataExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public void Export(IEasyDataResultSet data, Stream stream)
/// <param name="settings">The settings.</param>
public void Export(IEasyDataResultSet data, Stream stream, IDataExportSettings settings)
{
ExportAsync(data, stream, settings).GetAwaiter().GetResult();
ExportAsync(data, stream, settings)
.ConfigureAwait(false)
.GetAwaiter()
.GetResult();
}

/// <summary>
Expand All @@ -66,8 +69,9 @@ public Task ExportAsync(IEasyDataResultSet data, Stream stream, CancellationToke
/// <returns>Task.</returns>
public async Task ExportAsync(IEasyDataResultSet data, Stream stream, IDataExportSettings settings, CancellationToken ct = default)
{
var writer = new StreamWriter(stream, new UTF8Encoding(false));
await ExportAsync(data, writer, settings, ct).ConfigureAwait(false);
using (var writer = new StreamWriter(stream, new UTF8Encoding(false))) {
await ExportAsync(data, writer, settings, ct).ConfigureAwait(false);
}
}

private async Task ExportAsync(IEasyDataResultSet data, TextWriter writer, IDataExportSettings settings, CancellationToken ct)
Expand Down Expand Up @@ -155,15 +159,15 @@ async Task WriteRowAsync(EasyDataRow row, bool isExtra = false,
continue;

if (mappedSettings.BeforeRowInsert != null)
await mappedSettings.BeforeRowInsert(row, WriteExtraRowAsync, ct);
await mappedSettings.BeforeRowInsert(row, WriteExtraRowAsync, ct).ConfigureAwait(false);

await WriteRowAsync(row, false, null, ct);
await WriteRowAsync(row, false, null, ct).ConfigureAwait(false);

currentRowNum++;
}

if (mappedSettings.BeforeRowInsert != null) {
await mappedSettings.BeforeRowInsert(null, WriteExtraRowAsync, ct);
await mappedSettings.BeforeRowInsert(null, WriteExtraRowAsync, ct).ConfigureAwait(false);
}

await writer.FlushAsync().ConfigureAwait(false);
Expand Down
6 changes: 3 additions & 3 deletions easydata.net/version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"assemblyVersion": "1.4.4.1",
"packageVersion": "1.4.4",
"assetVersion": "01_04_04"
"assemblyVersion": "1.4.5.3",
"packageVersion": "1.4.5",
"assetVersion": "01_04_05"
}

0 comments on commit fd1fa08

Please sign in to comment.