mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-06-03 06:22:34 +02:00
Continued date type
This commit is contained in:
parent
a3c4f2158b
commit
c70aa29523
91
dist/tablefilter/tablefilter.js
vendored
91
dist/tablefilter/tablefilter.js
vendored
|
@ -1990,8 +1990,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
function hasArg(sA, cellData, colIdx) {
|
function hasArg(sA, cellData, colIdx) {
|
||||||
sA = (0, _string.matchCase)(sA, this.caseSensitive);
|
sA = (0, _string.matchCase)(sA, this.caseSensitive);
|
||||||
|
|
||||||
var occurence = void 0;
|
var occurence = false;
|
||||||
var dateType = this.Mod.dateType;
|
|
||||||
// let dtType = this.hasColDateType ?
|
// let dtType = this.hasColDateType ?
|
||||||
// this.colDateType[colIdx] : this.defaultDateType;
|
// this.colDateType[colIdx] : this.defaultDateType;
|
||||||
// let dtType = this.hasType(colIdx, [DATE]) ?
|
// let dtType = this.hasType(colIdx, [DATE]) ?
|
||||||
|
@ -2020,54 +2019,59 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
// let isGEDate=hasGE && isValidDate(sA.replace(re_ge, ''), dtType);
|
// let isGEDate=hasGE && isValidDate(sA.replace(re_ge, ''), dtType);
|
||||||
// let isDFDate=hasDF && isValidDate(sA.replace(re_d, ''), dtType);
|
// let isDFDate=hasDF && isValidDate(sA.replace(re_d, ''), dtType);
|
||||||
// let isEQDate=hasEQ && isValidDate(sA.replace(re_eq, ''), dtType);
|
// let isEQDate=hasEQ && isValidDate(sA.replace(re_eq, ''), dtType);
|
||||||
var isLDate = hasLO && dateType.isValid(sA.replace(re_l, ''));
|
|
||||||
var isLEDate = hasLE && dateType.isValid(sA.replace(re_le, ''));
|
|
||||||
var isGDate = hasGR && dateType.isValid(sA.replace(re_g, ''));
|
|
||||||
var isGEDate = hasGE && dateType.isValid(sA.replace(re_ge, ''));
|
|
||||||
var isDFDate = hasDF && dateType.isValid(sA.replace(re_d, ''));
|
|
||||||
var isEQDate = hasEQ && dateType.isValid(sA.replace(re_eq, ''));
|
|
||||||
|
|
||||||
var dte1 = void 0,
|
|
||||||
dte2 = void 0;
|
|
||||||
//dates
|
//dates
|
||||||
if (this.hasType(colIdx, [_const.DATE]) && dateType.isValid(cellData)
|
if (this.hasType(colIdx, [_const.DATE]) /*&& isValidDate(cellData)*/
|
||||||
/*isValidDate(cellData, dtType)*/) {
|
/*isValidDate(cellData, dtType)*/) {
|
||||||
|
var dte1 = void 0,
|
||||||
|
dte2 = void 0;
|
||||||
|
var dateType = this.Mod.dateType;
|
||||||
|
var isValidDate = dateType.isValid.bind(dateType);
|
||||||
|
var parseDate = dateType.parse.bind(dateType);
|
||||||
var locale = dateType.getOptions(colIdx).locale || this.locale;
|
var locale = dateType.getOptions(colIdx).locale || this.locale;
|
||||||
|
|
||||||
|
var isLDate = hasLO && isValidDate(sA.replace(re_l, ''), locale);
|
||||||
|
var isLEDate = hasLE && isValidDate(sA.replace(re_le, ''), locale);
|
||||||
|
var isGDate = hasGR && isValidDate(sA.replace(re_g, ''), locale);
|
||||||
|
var isGEDate = hasGE && isValidDate(sA.replace(re_ge, ''), locale);
|
||||||
|
var isDFDate = hasDF && isValidDate(sA.replace(re_d, ''), locale);
|
||||||
|
var isEQDate = hasEQ && isValidDate(sA.replace(re_eq, ''), locale);
|
||||||
|
|
||||||
// dte1 = formatDate(cellData, dtType);
|
// dte1 = formatDate(cellData, dtType);
|
||||||
dte1 = dateType.parse(cellData, locale);
|
dte1 = parseDate(cellData, locale);
|
||||||
// lower date
|
// lower date
|
||||||
if (isLDate) {
|
if (isLDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_l, ''), locale);
|
dte2 = parseDate(sA.replace(re_l, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_l, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_l, ''), dtType);
|
||||||
occurence = dte1 < dte2;
|
occurence = dte1 < dte2;
|
||||||
}
|
}
|
||||||
// lower equal date
|
// lower equal date
|
||||||
else if (isLEDate) {
|
else if (isLEDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_le, ''), locale);
|
dte2 = parseDate(sA.replace(re_le, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_le, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_le, ''), dtType);
|
||||||
occurence = dte1 <= dte2;
|
occurence = dte1 <= dte2;
|
||||||
}
|
}
|
||||||
// greater equal date
|
// greater equal date
|
||||||
else if (isGEDate) {
|
else if (isGEDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_ge, ''), locale);
|
dte2 = parseDate(sA.replace(re_ge, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_ge, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_ge, ''), dtType);
|
||||||
occurence = dte1 >= dte2;
|
occurence = dte1 >= dte2;
|
||||||
}
|
}
|
||||||
// greater date
|
// greater date
|
||||||
else if (isGDate) {
|
else if (isGDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_g, ''), locale);
|
dte2 = parseDate(sA.replace(re_g, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_g, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_g, ''), dtType);
|
||||||
occurence = dte1 > dte2;
|
occurence = dte1 > dte2;
|
||||||
}
|
}
|
||||||
// different date
|
// different date
|
||||||
else if (isDFDate) {
|
else if (isDFDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_d, ''), locale);
|
dte2 = parseDate(sA.replace(re_d, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_d, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_d, ''), dtType);
|
||||||
occurence = dte1.toString() !== dte2.toString();
|
occurence = dte1.toString() !== dte2.toString();
|
||||||
}
|
}
|
||||||
// equal date
|
// equal date
|
||||||
else if (isEQDate) {
|
else if (isEQDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_eq, ''), locale);
|
dte2 = parseDate(sA.replace(re_eq, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_eq, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_eq, ''), dtType);
|
||||||
occurence = dte1.toString() === dte2.toString();
|
occurence = dte1.toString() === dte2.toString();
|
||||||
}
|
}
|
||||||
|
@ -2075,10 +2079,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
else if (re_lk.test(sA)) {
|
else if (re_lk.test(sA)) {
|
||||||
// like date
|
// like date
|
||||||
occurence = (0, _string.contains)(sA.replace(re_lk, ''), cellData, false, this.caseSensitive);
|
occurence = (0, _string.contains)(sA.replace(re_lk, ''), cellData, false, this.caseSensitive);
|
||||||
} else if (dateType.isValid(sA)
|
} else if (isValidDate(sA)
|
||||||
/*isValidDate(sA, dtType)*/) {
|
/*isValidDate(sA, dtType)*/) {
|
||||||
// dte2 = formatDate(sA, dtType);
|
// dte2 = formatDate(sA, dtType);
|
||||||
dte2 = dateType.parse(sA, locale);
|
dte2 = parseDate(sA, locale);
|
||||||
occurence = dte1.toString() === dte2.toString();
|
occurence = dte1.toString() === dte2.toString();
|
||||||
}
|
}
|
||||||
//empty
|
//empty
|
||||||
|
@ -10184,32 +10188,42 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
|
|
||||||
this.tf = tf;
|
this.tf = tf;
|
||||||
this.locale = tf.locale;
|
this.locale = tf.locale;
|
||||||
this.suDate = _sugarDate.Date;
|
this.datetime = _sugarDate.Date;
|
||||||
this.emitter = tf.emitter;
|
this.emitter = tf.emitter;
|
||||||
|
|
||||||
// Global locale
|
|
||||||
this.suDate.setLocale(this.locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DateType.prototype.init = function init() {
|
DateType.prototype.init = function init() {
|
||||||
// let locale = this.suDate.getLocale(this.locale);
|
if (this.initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Add formats from column types configuration
|
// Global locale
|
||||||
|
this.datetime.setLocale(this.locale);
|
||||||
|
|
||||||
|
// let locale = this.datetime.getLocale(this.locale);
|
||||||
|
|
||||||
|
// Add formats from column types configuration if any
|
||||||
this._addConfigFormats();
|
this._addConfigFormats();
|
||||||
// locale.addFormat('{dd}/{MM}/{yyyy}');
|
// locale.addFormat('{dd}/{MM}/{yyyy}');
|
||||||
// locale.addFormat('{MM}/{dd}/{yyyy}');
|
// locale.addFormat('{MM}/{dd}/{yyyy}');
|
||||||
// locale.addFormat('{dd}-{months}-{yyyy|yy}');
|
// locale.addFormat('{dd}-{months}-{yyyy|yy}');
|
||||||
// locale.addFormat('{dd}-{MM}-{yyyy|yy}');
|
// locale.addFormat('{dd}-{MM}-{yyyy|yy}');
|
||||||
|
|
||||||
|
this.initialized = true;
|
||||||
|
|
||||||
|
this.emitter.emit('date-type-initialized', this.tf, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
DateType.prototype.parse = function parse(dateStr, localeCode) {
|
DateType.prototype.parse = function parse(dateStr, localeCode) {
|
||||||
console.log('parse', localeCode);
|
// console.log('parse', dateStr, localeCode,
|
||||||
return this.suDate.create(dateStr, localeCode);
|
// this.datetime.create(dateStr, localeCode));
|
||||||
|
return this.datetime.create(dateStr, localeCode);
|
||||||
};
|
};
|
||||||
|
|
||||||
DateType.prototype.isValid = function isValid(dateStr, localeCode) {
|
DateType.prototype.isValid = function isValid(dateStr, localeCode) {
|
||||||
console.log(dateStr, localeCode, this.parse(dateStr, localeCode), this.suDate.isValid(this.parse(dateStr, localeCode)));
|
// console.log(dateStr, localeCode, this.parse(dateStr, localeCode),
|
||||||
return this.suDate.isValid(this.parse(dateStr, localeCode));
|
// this.datetime.isValid(this.parse(dateStr, localeCode)));
|
||||||
|
return this.datetime.isValid(this.parse(dateStr, localeCode));
|
||||||
};
|
};
|
||||||
|
|
||||||
DateType.prototype.getOptions = function getOptions(colIndex) {
|
DateType.prototype.getOptions = function getOptions(colIndex) {
|
||||||
|
@ -10223,13 +10237,24 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
this.tf.colTypes.forEach(function (type, idx) {
|
this.tf.colTypes.forEach(function (type, idx) {
|
||||||
var options = _this.getOptions(idx);
|
var options = _this.getOptions(idx);
|
||||||
if (options.hasOwnProperty('format')) {
|
if (options.hasOwnProperty('format')) {
|
||||||
var locale = _this.suDate.getLocale(options.locale || _this.locale);
|
(function () {
|
||||||
console.log(options.format);
|
var locale = _this.datetime.getLocale(options.locale || _this.locale);
|
||||||
locale.addFormat(options.format);
|
if ((0, _types.isArray)(options.format)) {
|
||||||
|
options.format.forEach(function (format) {
|
||||||
|
locale.addFormat(format);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
locale.addFormat(options.format);
|
||||||
|
}
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DateType.prototype.destroy = function destroy() {
|
||||||
|
this.initialized = false;
|
||||||
|
};
|
||||||
|
|
||||||
return DateType;
|
return DateType;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
|
59
dist/tablefilter/tf-1.js
vendored
59
dist/tablefilter/tf-1.js
vendored
|
@ -2416,8 +2416,6 @@ webpackJsonp([1],{
|
||||||
|
|
||||||
var _event = __webpack_require__(1);
|
var _event = __webpack_require__(1);
|
||||||
|
|
||||||
var _date = __webpack_require__(435);
|
|
||||||
|
|
||||||
var _number = __webpack_require__(6);
|
var _number = __webpack_require__(6);
|
||||||
|
|
||||||
var _const = __webpack_require__(7);
|
var _const = __webpack_require__(7);
|
||||||
|
@ -2427,6 +2425,8 @@ webpackJsonp([1],{
|
||||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||||
|
|
||||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||||
|
// import {formatDate} from '../../date';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SortableTable Adapter module
|
* SortableTable Adapter module
|
||||||
|
@ -2836,10 +2836,19 @@ webpackJsonp([1],{
|
||||||
// resolve column types
|
// resolve column types
|
||||||
if (tf.hasType(i, [_const.NUMBER, _const.FORMATTED_NUMBER, _const.FORMATTED_NUMBER_EU, _const.IP_ADDRESS])) {
|
if (tf.hasType(i, [_const.NUMBER, _const.FORMATTED_NUMBER, _const.FORMATTED_NUMBER_EU, _const.IP_ADDRESS])) {
|
||||||
colType = tf.colTypes[i].toLowerCase();
|
colType = tf.colTypes[i].toLowerCase();
|
||||||
} else if (tf.hasColDateType && tf.colDateType[i] !== null) {
|
// } else if (tf.hasColDateType && tf.colDateType[i] !== null) {
|
||||||
colType = tf.colDateType[i].toLowerCase() + 'date';
|
// colType = tf.colDateType[i].toLowerCase() + 'date';
|
||||||
|
} else if (tf.hasType(i, [_const.DATE])) {
|
||||||
|
(function () {
|
||||||
|
var dateType = tf.feature('dateType');
|
||||||
|
var locale = dateType.getOptions(i).locale || tf.locale;
|
||||||
|
colType = _const.DATE + '-' + locale;
|
||||||
|
_this3.addSortType(colType, function (dateStr) {
|
||||||
|
return dateType.parse(dateStr, locale);
|
||||||
|
});
|
||||||
|
})();
|
||||||
} else {
|
} else {
|
||||||
colType = 'String';
|
colType = _const.STRING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_sortTypes.push(colType);
|
_sortTypes.push(colType);
|
||||||
|
@ -2850,14 +2859,14 @@ webpackJsonp([1],{
|
||||||
//Custom sort types
|
//Custom sort types
|
||||||
this.addSortType(_const.NUMBER, Number);
|
this.addSortType(_const.NUMBER, Number);
|
||||||
this.addSortType('caseinsensitivestring', SortableTable.toUpperCase);
|
this.addSortType('caseinsensitivestring', SortableTable.toUpperCase);
|
||||||
this.addSortType(_const.DATE, SortableTable.toDate);
|
// this.addSortType(DATE, SortableTable.toDate);
|
||||||
this.addSortType(_const.STRING);
|
this.addSortType(_const.STRING);
|
||||||
this.addSortType(_const.FORMATTED_NUMBER, usNumberConverter);
|
this.addSortType(_const.FORMATTED_NUMBER, usNumberConverter);
|
||||||
this.addSortType(_const.FORMATTED_NUMBER_EU, euNumberConverter);
|
this.addSortType(_const.FORMATTED_NUMBER_EU, euNumberConverter);
|
||||||
this.addSortType('dmydate', dmyDateConverter);
|
// this.addSortType('dmydate', dmyDateConverter);
|
||||||
this.addSortType('ymddate', ymdDateConverter);
|
// this.addSortType('ymddate', ymdDateConverter);
|
||||||
this.addSortType('mdydate', mdyDateConverter);
|
// this.addSortType('mdydate', mdyDateConverter);
|
||||||
this.addSortType('ddmmmyyyydate', ddmmmyyyyDateConverter);
|
// this.addSortType('ddmmmyyyydate', ddmmmyyyyDateConverter);
|
||||||
this.addSortType(_const.IP_ADDRESS, ipAddress, sortIP);
|
this.addSortType(_const.IP_ADDRESS, ipAddress, sortIP);
|
||||||
|
|
||||||
this.stt = new SortableTable(tf.tbl, _sortTypes);
|
this.stt = new SortableTable(tf.tbl, _sortTypes);
|
||||||
|
@ -2932,21 +2941,21 @@ webpackJsonp([1],{
|
||||||
function euNumberConverter(s) {
|
function euNumberConverter(s) {
|
||||||
return (0, _number.unformat)(s, _const.FORMATTED_NUMBER_EU);
|
return (0, _number.unformat)(s, _const.FORMATTED_NUMBER_EU);
|
||||||
}
|
}
|
||||||
function dateConverter(s, format) {
|
// function dateConverter(s, format) {
|
||||||
return (0, _date.formatDate)(s, format);
|
// return formatDate(s, format);
|
||||||
}
|
// }
|
||||||
function dmyDateConverter(s) {
|
// function dmyDateConverter(s) {
|
||||||
return dateConverter(s, 'DMY');
|
// return dateConverter(s, 'DMY');
|
||||||
}
|
// }
|
||||||
function mdyDateConverter(s) {
|
// function mdyDateConverter(s) {
|
||||||
return dateConverter(s, 'MDY');
|
// return dateConverter(s, 'MDY');
|
||||||
}
|
// }
|
||||||
function ymdDateConverter(s) {
|
// function ymdDateConverter(s) {
|
||||||
return dateConverter(s, 'YMD');
|
// return dateConverter(s, 'YMD');
|
||||||
}
|
// }
|
||||||
function ddmmmyyyyDateConverter(s) {
|
// function ddmmmyyyyDateConverter(s) {
|
||||||
return dateConverter(s, 'DDMMMYYYY');
|
// return dateConverter(s, 'DDMMMYYYY');
|
||||||
}
|
// }
|
||||||
|
|
||||||
function ipAddress(value) {
|
function ipAddress(value) {
|
||||||
var vals = value.split('.');
|
var vals = value.split('.');
|
||||||
|
|
|
@ -2,7 +2,7 @@ import {Feature} from '../../feature';
|
||||||
import {isArray, isFn, isUndef} from '../../types';
|
import {isArray, isFn, isUndef} from '../../types';
|
||||||
import {createElm, elm, getText, tag} from '../../dom';
|
import {createElm, elm, getText, tag} from '../../dom';
|
||||||
import {addEvt} from '../../event';
|
import {addEvt} from '../../event';
|
||||||
import {formatDate} from '../../date';
|
// import {formatDate} from '../../date';
|
||||||
import {unformat as unformatNb} from '../../number';
|
import {unformat as unformatNb} from '../../number';
|
||||||
import {
|
import {
|
||||||
NONE, CELL_TAG, HEADER_TAG, STRING, NUMBER, DATE, FORMATTED_NUMBER,
|
NONE, CELL_TAG, HEADER_TAG, STRING, NUMBER, DATE, FORMATTED_NUMBER,
|
||||||
|
@ -407,10 +407,17 @@ export default class AdapterSortableTable extends Feature {
|
||||||
if (tf.hasType(i, [NUMBER, FORMATTED_NUMBER,
|
if (tf.hasType(i, [NUMBER, FORMATTED_NUMBER,
|
||||||
FORMATTED_NUMBER_EU, IP_ADDRESS])) {
|
FORMATTED_NUMBER_EU, IP_ADDRESS])) {
|
||||||
colType = tf.colTypes[i].toLowerCase();
|
colType = tf.colTypes[i].toLowerCase();
|
||||||
} else if (tf.hasColDateType && tf.colDateType[i] !== null) {
|
// } else if (tf.hasColDateType && tf.colDateType[i] !== null) {
|
||||||
colType = tf.colDateType[i].toLowerCase() + 'date';
|
// colType = tf.colDateType[i].toLowerCase() + 'date';
|
||||||
|
} else if (tf.hasType(i, [DATE])) {
|
||||||
|
let dateType = tf.feature('dateType');
|
||||||
|
let locale = dateType.getOptions(i).locale || tf.locale;
|
||||||
|
colType = `${DATE}-${locale}`;
|
||||||
|
this.addSortType(colType, (dateStr) => {
|
||||||
|
return dateType.parse(dateStr, locale);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
colType = 'String';
|
colType = STRING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_sortTypes.push(colType);
|
_sortTypes.push(colType);
|
||||||
|
@ -421,14 +428,14 @@ export default class AdapterSortableTable extends Feature {
|
||||||
//Custom sort types
|
//Custom sort types
|
||||||
this.addSortType(NUMBER, Number);
|
this.addSortType(NUMBER, Number);
|
||||||
this.addSortType('caseinsensitivestring', SortableTable.toUpperCase);
|
this.addSortType('caseinsensitivestring', SortableTable.toUpperCase);
|
||||||
this.addSortType(DATE, SortableTable.toDate);
|
// this.addSortType(DATE, SortableTable.toDate);
|
||||||
this.addSortType(STRING);
|
this.addSortType(STRING);
|
||||||
this.addSortType(FORMATTED_NUMBER, usNumberConverter);
|
this.addSortType(FORMATTED_NUMBER, usNumberConverter);
|
||||||
this.addSortType(FORMATTED_NUMBER_EU, euNumberConverter);
|
this.addSortType(FORMATTED_NUMBER_EU, euNumberConverter);
|
||||||
this.addSortType('dmydate', dmyDateConverter);
|
// this.addSortType('dmydate', dmyDateConverter);
|
||||||
this.addSortType('ymddate', ymdDateConverter);
|
// this.addSortType('ymddate', ymdDateConverter);
|
||||||
this.addSortType('mdydate', mdyDateConverter);
|
// this.addSortType('mdydate', mdyDateConverter);
|
||||||
this.addSortType('ddmmmyyyydate', ddmmmyyyyDateConverter);
|
// this.addSortType('ddmmmyyyydate', ddmmmyyyyDateConverter);
|
||||||
this.addSortType(IP_ADDRESS, ipAddress, sortIP);
|
this.addSortType(IP_ADDRESS, ipAddress, sortIP);
|
||||||
|
|
||||||
this.stt = new SortableTable(tf.tbl, _sortTypes);
|
this.stt = new SortableTable(tf.tbl, _sortTypes);
|
||||||
|
@ -492,21 +499,21 @@ function usNumberConverter(s) {
|
||||||
function euNumberConverter(s) {
|
function euNumberConverter(s) {
|
||||||
return unformatNb(s, FORMATTED_NUMBER_EU);
|
return unformatNb(s, FORMATTED_NUMBER_EU);
|
||||||
}
|
}
|
||||||
function dateConverter(s, format) {
|
// function dateConverter(s, format) {
|
||||||
return formatDate(s, format);
|
// return formatDate(s, format);
|
||||||
}
|
// }
|
||||||
function dmyDateConverter(s) {
|
// function dmyDateConverter(s) {
|
||||||
return dateConverter(s, 'DMY');
|
// return dateConverter(s, 'DMY');
|
||||||
}
|
// }
|
||||||
function mdyDateConverter(s) {
|
// function mdyDateConverter(s) {
|
||||||
return dateConverter(s, 'MDY');
|
// return dateConverter(s, 'MDY');
|
||||||
}
|
// }
|
||||||
function ymdDateConverter(s) {
|
// function ymdDateConverter(s) {
|
||||||
return dateConverter(s, 'YMD');
|
// return dateConverter(s, 'YMD');
|
||||||
}
|
// }
|
||||||
function ddmmmyyyyDateConverter(s) {
|
// function ddmmmyyyyDateConverter(s) {
|
||||||
return dateConverter(s, 'DDMMMYYYY');
|
// return dateConverter(s, 'DDMMMYYYY');
|
||||||
}
|
// }
|
||||||
|
|
||||||
function ipAddress(value) {
|
function ipAddress(value) {
|
||||||
let vals = value.split('.');
|
let vals = value.split('.');
|
||||||
|
|
|
@ -1,38 +1,48 @@
|
||||||
import {Date as SuDate} from 'sugar-date';
|
import {Date as SugarDate} from 'sugar-date';
|
||||||
import 'sugar-date/locales';
|
import 'sugar-date/locales';
|
||||||
import {isObj} from '../types';
|
import {isObj, isArray} from '../types';
|
||||||
|
|
||||||
export class DateType {
|
export class DateType {
|
||||||
|
|
||||||
constructor(tf) {
|
constructor(tf) {
|
||||||
this.tf = tf;
|
this.tf = tf;
|
||||||
this.locale = tf.locale;
|
this.locale = tf.locale;
|
||||||
this.suDate = SuDate;
|
this.datetime = SugarDate;
|
||||||
this.emitter = tf.emitter;
|
this.emitter = tf.emitter;
|
||||||
|
|
||||||
// Global locale
|
|
||||||
this.suDate.setLocale(this.locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
// let locale = this.suDate.getLocale(this.locale);
|
if (this.initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Add formats from column types configuration
|
// Global locale
|
||||||
|
this.datetime.setLocale(this.locale);
|
||||||
|
|
||||||
|
// let locale = this.datetime.getLocale(this.locale);
|
||||||
|
|
||||||
|
// Add formats from column types configuration if any
|
||||||
this._addConfigFormats();
|
this._addConfigFormats();
|
||||||
// locale.addFormat('{dd}/{MM}/{yyyy}');
|
// locale.addFormat('{dd}/{MM}/{yyyy}');
|
||||||
// locale.addFormat('{MM}/{dd}/{yyyy}');
|
// locale.addFormat('{MM}/{dd}/{yyyy}');
|
||||||
// locale.addFormat('{dd}-{months}-{yyyy|yy}');
|
// locale.addFormat('{dd}-{months}-{yyyy|yy}');
|
||||||
// locale.addFormat('{dd}-{MM}-{yyyy|yy}');
|
// locale.addFormat('{dd}-{MM}-{yyyy|yy}');
|
||||||
|
|
||||||
|
this.initialized = true;
|
||||||
|
|
||||||
|
this.emitter.emit('date-type-initialized', this.tf, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
parse(dateStr, localeCode) {console.log('parse', localeCode);
|
parse(dateStr, localeCode) {
|
||||||
return this.suDate.create(dateStr, localeCode);
|
// console.log('parse', dateStr, localeCode,
|
||||||
|
// this.datetime.create(dateStr, localeCode));
|
||||||
|
return this.datetime.create(dateStr, localeCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
isValid(dateStr, localeCode) {
|
isValid(dateStr, localeCode) {
|
||||||
console.log(dateStr, localeCode, this.parse(dateStr, localeCode),
|
// console.log(dateStr, localeCode, this.parse(dateStr, localeCode),
|
||||||
this.suDate.isValid(this.parse(dateStr, localeCode)));
|
// this.datetime.isValid(this.parse(dateStr, localeCode)));
|
||||||
return this.suDate.isValid(this.parse(dateStr, localeCode));
|
return this.datetime.isValid(this.parse(dateStr, localeCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
getOptions(colIndex) {
|
getOptions(colIndex) {
|
||||||
|
@ -44,12 +54,21 @@ export class DateType {
|
||||||
this.tf.colTypes.forEach((type, idx) => {
|
this.tf.colTypes.forEach((type, idx) => {
|
||||||
let options = this.getOptions(idx);
|
let options = this.getOptions(idx);
|
||||||
if (options.hasOwnProperty('format')) {
|
if (options.hasOwnProperty('format')) {
|
||||||
let locale = this.suDate.getLocale(
|
let locale = this.datetime.getLocale(
|
||||||
options.locale || this.locale
|
options.locale || this.locale
|
||||||
);
|
);
|
||||||
console.log(options.format);
|
if (isArray(options.format)) {
|
||||||
locale.addFormat(options.format);
|
options.format.forEach((format) => {
|
||||||
|
locale.addFormat(format);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
locale.addFormat(options.format);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this.initialized = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1793,8 +1793,7 @@ export class TableFilter {
|
||||||
function hasArg(sA, cellData, colIdx) {
|
function hasArg(sA, cellData, colIdx) {
|
||||||
sA = matchCase(sA, this.caseSensitive);
|
sA = matchCase(sA, this.caseSensitive);
|
||||||
|
|
||||||
let occurence;
|
let occurence = false;
|
||||||
let dateType = this.Mod.dateType;
|
|
||||||
// let dtType = this.hasColDateType ?
|
// let dtType = this.hasColDateType ?
|
||||||
// this.colDateType[colIdx] : this.defaultDateType;
|
// this.colDateType[colIdx] : this.defaultDateType;
|
||||||
// let dtType = this.hasType(colIdx, [DATE]) ?
|
// let dtType = this.hasType(colIdx, [DATE]) ?
|
||||||
|
@ -1822,53 +1821,64 @@ export class TableFilter {
|
||||||
// let isGEDate=hasGE && isValidDate(sA.replace(re_ge, ''), dtType);
|
// let isGEDate=hasGE && isValidDate(sA.replace(re_ge, ''), dtType);
|
||||||
// let isDFDate=hasDF && isValidDate(sA.replace(re_d, ''), dtType);
|
// let isDFDate=hasDF && isValidDate(sA.replace(re_d, ''), dtType);
|
||||||
// let isEQDate=hasEQ && isValidDate(sA.replace(re_eq, ''), dtType);
|
// let isEQDate=hasEQ && isValidDate(sA.replace(re_eq, ''), dtType);
|
||||||
let isLDate = hasLO && dateType.isValid(sA.replace(re_l, ''));
|
|
||||||
let isLEDate = hasLE && dateType.isValid(sA.replace(re_le, ''));
|
|
||||||
let isGDate = hasGR && dateType.isValid(sA.replace(re_g, ''));
|
|
||||||
let isGEDate = hasGE && dateType.isValid(sA.replace(re_ge, ''));
|
|
||||||
let isDFDate = hasDF && dateType.isValid(sA.replace(re_d, ''));
|
|
||||||
let isEQDate = hasEQ && dateType.isValid(sA.replace(re_eq, ''));
|
|
||||||
|
|
||||||
let dte1, dte2;
|
|
||||||
//dates
|
//dates
|
||||||
if (this.hasType(colIdx, [DATE]) && dateType.isValid(cellData)
|
if (this.hasType(colIdx, [DATE]) /*&& isValidDate(cellData)*/
|
||||||
/*isValidDate(cellData, dtType)*/) {
|
/*isValidDate(cellData, dtType)*/) {
|
||||||
|
let dte1, dte2;
|
||||||
|
let dateType = this.Mod.dateType;
|
||||||
|
let isValidDate = dateType.isValid.bind(dateType);
|
||||||
|
let parseDate = dateType.parse.bind(dateType);
|
||||||
let locale = dateType.getOptions(colIdx).locale || this.locale;
|
let locale = dateType.getOptions(colIdx).locale || this.locale;
|
||||||
|
|
||||||
|
let isLDate = hasLO &&
|
||||||
|
isValidDate(sA.replace(re_l, ''), locale);
|
||||||
|
let isLEDate = hasLE &&
|
||||||
|
isValidDate(sA.replace(re_le, ''), locale);
|
||||||
|
let isGDate = hasGR &&
|
||||||
|
isValidDate(sA.replace(re_g, ''), locale);
|
||||||
|
let isGEDate = hasGE &&
|
||||||
|
isValidDate(sA.replace(re_ge, ''), locale);
|
||||||
|
let isDFDate = hasDF &&
|
||||||
|
isValidDate(sA.replace(re_d, ''), locale);
|
||||||
|
let isEQDate = hasEQ &&
|
||||||
|
isValidDate(sA.replace(re_eq, ''), locale);
|
||||||
|
|
||||||
// dte1 = formatDate(cellData, dtType);
|
// dte1 = formatDate(cellData, dtType);
|
||||||
dte1 = dateType.parse(cellData, locale);
|
dte1 = parseDate(cellData, locale);
|
||||||
// lower date
|
// lower date
|
||||||
if (isLDate) {
|
if (isLDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_l, ''), locale);
|
dte2 = parseDate(sA.replace(re_l, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_l, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_l, ''), dtType);
|
||||||
occurence = dte1 < dte2;
|
occurence = dte1 < dte2;
|
||||||
}
|
}
|
||||||
// lower equal date
|
// lower equal date
|
||||||
else if (isLEDate) {
|
else if (isLEDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_le, ''), locale);
|
dte2 = parseDate(sA.replace(re_le, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_le, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_le, ''), dtType);
|
||||||
occurence = dte1 <= dte2;
|
occurence = dte1 <= dte2;
|
||||||
}
|
}
|
||||||
// greater equal date
|
// greater equal date
|
||||||
else if (isGEDate) {
|
else if (isGEDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_ge, ''), locale);
|
dte2 = parseDate(sA.replace(re_ge, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_ge, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_ge, ''), dtType);
|
||||||
occurence = dte1 >= dte2;
|
occurence = dte1 >= dte2;
|
||||||
}
|
}
|
||||||
// greater date
|
// greater date
|
||||||
else if (isGDate) {
|
else if (isGDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_g, ''), locale);
|
dte2 = parseDate(sA.replace(re_g, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_g, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_g, ''), dtType);
|
||||||
occurence = dte1 > dte2;
|
occurence = dte1 > dte2;
|
||||||
}
|
}
|
||||||
// different date
|
// different date
|
||||||
else if (isDFDate) {
|
else if (isDFDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_d, ''), locale);
|
dte2 = parseDate(sA.replace(re_d, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_d, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_d, ''), dtType);
|
||||||
occurence = dte1.toString() !== dte2.toString();
|
occurence = dte1.toString() !== dte2.toString();
|
||||||
}
|
}
|
||||||
// equal date
|
// equal date
|
||||||
else if (isEQDate) {
|
else if (isEQDate) {
|
||||||
dte2 = dateType.parse(sA.replace(re_eq, ''), locale);
|
dte2 = parseDate(sA.replace(re_eq, ''), locale);
|
||||||
// dte2 = formatDate(sA.replace(re_eq, ''), dtType);
|
// dte2 = formatDate(sA.replace(re_eq, ''), dtType);
|
||||||
occurence = dte1.toString() === dte2.toString();
|
occurence = dte1.toString() === dte2.toString();
|
||||||
}
|
}
|
||||||
|
@ -1877,10 +1887,10 @@ export class TableFilter {
|
||||||
occurence = contains(sA.replace(re_lk, ''), cellData,
|
occurence = contains(sA.replace(re_lk, ''), cellData,
|
||||||
false, this.caseSensitive);
|
false, this.caseSensitive);
|
||||||
}
|
}
|
||||||
else if (dateType.isValid(sA)
|
else if (isValidDate(sA)
|
||||||
/*isValidDate(sA, dtType)*/) {
|
/*isValidDate(sA, dtType)*/) {
|
||||||
// dte2 = formatDate(sA, dtType);
|
// dte2 = formatDate(sA, dtType);
|
||||||
dte2 = dateType.parse(sA, locale);
|
dte2 = parseDate(sA, locale);
|
||||||
occurence = dte1.toString() === dte2.toString();
|
occurence = dte1.toString() === dte2.toString();
|
||||||
}
|
}
|
||||||
//empty
|
//empty
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
Use the <code>col_types</code> property to set numeric formats
|
Use the <code>col_types</code> property to set numeric formats
|
||||||
('formatted-number', 'formatted-number-eu' or 'ipaddress') and <code>col_date_type</code> to set date
|
('formatted-number', 'formatted-number-eu' or 'ipaddress') and date types.
|
||||||
types.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!-- @import partials/pre.html -->
|
<!-- @import partials/pre.html -->
|
||||||
|
@ -76,19 +75,16 @@ var tfConfig = {
|
||||||
loader: true,
|
loader: true,
|
||||||
status_bar: true,
|
status_bar: true,
|
||||||
col_types: [
|
col_types: [
|
||||||
null, null, null,
|
'string', 'string', 'string',
|
||||||
'formatted-number-eu', 'formatted-number', null,
|
'formatted-number-eu', 'formatted-number', 'string',
|
||||||
{ type: 'date', locale: 'fr'/*, format: '{dd}/{MM}/{yyyy}'*/},
|
{
|
||||||
{ type: 'date', locale: 'en'/*, format: '{MM}/{dd}/{yyyy}'*/},
|
type: 'date', locale: 'fr'/*,
|
||||||
|
format: ['{dd}/{MM}/{yyyy}', '{dd}-{MM}-{yyyy|yy}']*/
|
||||||
|
},
|
||||||
|
{ type: 'date', locale: 'en'/*, format: '{dd}-{MM}-{yyyy|yy}'*/ },
|
||||||
'date',
|
'date',
|
||||||
'ipaddress'
|
'ipaddress'
|
||||||
],
|
],
|
||||||
// col_date_type: [
|
|
||||||
// null, null, null,
|
|
||||||
// null, null, null,
|
|
||||||
// 'dmy', 'mdy', 'ddmmmyyyy',
|
|
||||||
// null
|
|
||||||
// ],
|
|
||||||
rows_always_visible: [totRowIndex],
|
rows_always_visible: [totRowIndex],
|
||||||
on_filters_loaded: function(o){
|
on_filters_loaded: function(o){
|
||||||
o.setFilterValue(3, '>1.000');
|
o.setFilterValue(3, '>1.000');
|
||||||
|
@ -132,7 +128,11 @@ var tf2Config = {
|
||||||
btn_reset: true,
|
btn_reset: true,
|
||||||
loader: true,
|
loader: true,
|
||||||
status_bar: true,
|
status_bar: true,
|
||||||
default_date_type: 'YMD',
|
locale: 'en-us',
|
||||||
|
col_types: [
|
||||||
|
'string', 'number', 'string',
|
||||||
|
'number', 'string', 'date'
|
||||||
|
],
|
||||||
on_filters_loaded: function(o){
|
on_filters_loaded: function(o){
|
||||||
o.setFilterValue(5, '>95-05-18');
|
o.setFilterValue(5, '>95-05-18');
|
||||||
o.filter();
|
o.filter();
|
||||||
|
|
Loading…
Reference in a new issue