Skip to content

Commit

Permalink
Merge pull request #33 from KorzhCom/dev
Browse files Browse the repository at this point in the history
Version 1.2.5
  • Loading branch information
antifree authored Apr 28, 2021
2 parents 24e1f15 + 19051aa commit 71bca10
Show file tree
Hide file tree
Showing 31 changed files with 789 additions and 583 deletions.
38 changes: 30 additions & 8 deletions easydata.js/packs/core/src/http/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,24 @@ export class HttpClient {
const responseContentType = xhr.getResponseHeader('Content-Type') || '';
const status = xhr.status;
if (status >= 300 || status < 200) {
const responseObj = (responseContentType.indexOf('application/json') == 0)
? JSON.parse(xhr.responseText)
: xhr.responseText;
const message = responseObj.message ||
(status == 404
? `No such endpoint: ${url}`
: responseObj);
reject(new HttpResponseError(status, message));
const rtPromise = (xhr.responseType === 'arraybuffer'
|| xhr.responseType === 'blob')
? HttpClient.decodeArrayBuffer(xhr.response)
: Promise.resolve(xhr.responseText);

rtPromise.then(responseText => {
const responseObj = (responseContentType.indexOf('application/json') == 0)
? JSON.parse(responseText)
: responseText;

const message = responseObj.message ||
(status == 404
? `No such endpoint: ${url}`
: responseObj);

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

return;
}

Expand All @@ -132,4 +142,16 @@ export class HttpClient {

}));
}

private static decodeArrayBuffer(uintArray): Promise<string> {
var reader = new FileReader();
return new Promise<string>((resolve) => {
reader.onloadend = function () {
if (reader.readyState == FileReader.DONE) {
resolve(reader.result as string);
}
};
reader.readAsText(new Blob([uintArray]));
});
}
}
62 changes: 57 additions & 5 deletions easydata.js/packs/core/src/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ export namespace i18n {
displayName: 'English',
texts: {
ButtonOK: 'OK',
ButtonCancel: 'Cancel'
ButtonCancel: 'Cancel',
Yes: 'Yes',
No: 'No',
True: 'True',
False: 'False'
},
settings: englishUSLocaleSettings
};
Expand Down Expand Up @@ -421,16 +425,64 @@ export namespace i18n {
return format;
}

export function numberToStr(number: Number, format?: string): string {
if (format) {
const locale = getCurrentLocale();
return number.toLocaleString(locale, getNumberFromatOptions(format));
export function numberToStr(number: number, format?: string): string {
if (format && format.length > 0) {
const type = format.charAt(0);
if (['D', 'F', 'C'].indexOf(type) >= 0) {
const locale = getCurrentLocale();
return number.toLocaleString(locale, getNumberFromatOptions(format));
}
else {
return convertWithMask(Math.trunc(number), format);
}
}

const localeSettings = getLocaleSettings();
return utils.numberToStr(number, localeSettings.decimalSeparator);
}

export function booleanToStr(bool: boolean, format?: string) {
if (format && format.length > 0) {
const type = format.charAt(0);
if (type === 'S') {
const values = format.slice(1).split('|');
if (values.length === 2) {
const value = values[(bool) ? 1 : 0];
return i18n.getText(value) || value;
}
}
}
return `${bool}`;
}

function convertWithMask(number: number, mask: string) {
let value = number.toString();
let result = '';
let index = value.length - 1;

for(let i = mask.length - 1; i >= 0; i--) {

const ch = mask.charAt(i);

if (ch === '#' || ch === '0') {
if (index >= 0) {
result += value.charAt(index);
index--;
}
else {
if (ch === '0') {
result += 0;
}
}
}
else {
result += ch;
}
}

return result.split('').reverse().join('');
}

function getNumberFromatOptions(format: string): Intl.NumberFormatOptions {
const localeSettings = getLocaleSettings();
const type = format[0].toUpperCase();
Expand Down
26 changes: 20 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 @@ -19,10 +19,14 @@ export type GridCellRenderer = (value: any, column: GridColumn, cellElement: HTM

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

if (column.align == GridColumnAlign.NONE) {
builder.addClass(`${cssPrefix}-cell-value-align-right`);
}
}


Expand All @@ -41,7 +45,7 @@ const NumberCellRendererDefault: GridCellRenderer = (value: any, column: GridCol
}
}

let builder = domel('div', cellElement)
const builder = domel('div', cellElement)
.addClass(`${cssPrefix}-cell-value`)
.addHtml(strValue)
.title(strValue);
Expand Down Expand Up @@ -92,10 +96,20 @@ const DateTimeCellRendererDefault: GridCellRenderer = (value: any, column: GridC


const BoolCellRendererDefault: GridCellRenderer = (value: any, column: GridColumn, cellElement: HTMLElement, rowElement: HTMLElement) => {
domel('div', cellElement)
.addClass(`${cssPrefix}-cell-value`)
.addClass(`${cssPrefix}-cell-value-bool`)
.addClass(`${cssPrefix}-${value ? 'cell-value-true' : 'cell-value-false'}`);
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);
}
else {
domel('div', cellElement)
.addClass(`${cssPrefix}-cell-value`)
.addClass(`${cssPrefix}-cell-value-bool`)
.addClass(`${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,5 +1,5 @@
{
"version": "1.2.4",
"baseVersion": "1.2.4",
"assetVersion": "01_02_04"
"version": "1.2.5",
"baseVersion": "1.2.5",
"assetVersion": "01_02_05"
}
Loading

0 comments on commit 71bca10

Please sign in to comment.