diff --git a/src/scripts/js/es6/common/vuecomponents/init.js b/src/scripts/js/es6/common/vuecomponents/init.js index b24bc409..cccff5c6 100644 --- a/src/scripts/js/es6/common/vuecomponents/init.js +++ b/src/scripts/js/es6/common/vuecomponents/init.js @@ -9,6 +9,7 @@ import { CellDefault } from './table/cells/renderer/CellDefault' import { ColumnBase } from './table/columns/ColumnBase' import { Created } from './table/columns/Created' import { Updated } from './table/columns/Updated' +import { DateColumnBase } from './table/columns/DateColumnBase' import { ColumnFactoryBase } from './table/columns/ColumnFactoryBase' import { RowObjectsSourceBase } from './table/rows/RowObjectsSourceBase' import { RowBase } from './table/rows/RowObjectBase' @@ -31,6 +32,7 @@ let table = { ColumnBase, Created, Updated, + DateColumnBase, ColumnFactoryBase, }, cells: { diff --git a/src/scripts/js/es6/common/vuecomponents/table/columns/Created.js b/src/scripts/js/es6/common/vuecomponents/table/columns/Created.js index 49d998b1..db4026c9 100644 --- a/src/scripts/js/es6/common/vuecomponents/table/columns/Created.js +++ b/src/scripts/js/es6/common/vuecomponents/table/columns/Created.js @@ -1,25 +1,13 @@ -import { CellPrettyDate } from '../cells/renderer/CellPrettyDate' -import {ColumnBase} from './ColumnBase' +import {DateColumnBase} from './DateColumnBase' /** * Column showing the objects _created prettyfied */ - -export class Created extends ColumnBase{ +export class Created extends DateColumnBase{ constructor() { super('Created', 'row-created'); this.includedByDefault = false; } - - /** - * - * @param {RowObject} rowObject - * @returns {String} Name of the Cell renderer component - */ - getCellRenderer(rowObject) { - return CellPrettyDate.options.name; - } - /** * * @param {RowObject} rowObject @@ -28,31 +16,4 @@ export class Created extends ColumnBase{ getRawCellValue(rowObject) { return rowObject.underlyingObject['_created']; } - - /** - * Cell tooltip - * @param {Any} rawCellValue - * @param {RowObject} rowObject - * @returns {String} - */ - getCellTitle(rawCellValue, rowObject) { - return rawCellValue; - } - - /** - * Compare two rows to sort them. Can be overridden for more complex situations. - * - * @param {RowObject} rowObject1 - * @param {RowObject} rowObject2 - * @returns {Number} -1, 0, 1 - */ - compareRows(rowObject1, rowObject2) { - let dueDateStr1 = this.getRawCellValue(rowObject1); - let dueDateStr2 = this.getRawCellValue(rowObject2); - if (dueDateStr1 === dueDateStr2) return 0; - if (dueDateStr1 && dueDateStr2) { - return new Date(dueDateStr1) < new Date(dueDateStr2) ? -1 : 1; - } - return dueDateStr1 ? -1 : 1; - } } diff --git a/src/scripts/js/es6/common/vuecomponents/table/columns/DateColumnBase.js b/src/scripts/js/es6/common/vuecomponents/table/columns/DateColumnBase.js new file mode 100644 index 00000000..afb84f6c --- /dev/null +++ b/src/scripts/js/es6/common/vuecomponents/table/columns/DateColumnBase.js @@ -0,0 +1,41 @@ +import { CellPrettyDate } from '../cells/renderer/CellPrettyDate' +import { ColumnBase } from './ColumnBase' + +/** + * Column showing a pretty date + */ +export class DateColumnBase extends ColumnBase{ + /** + * + * @param {RowObject} rowObject + * @returns {String} Name of the Cell renderer component + */ + getCellRenderer(rowObject) { + return CellPrettyDate.options.name; + } + + /** + * Cell tooltip + * @param {Any} rawCellValue + * @param {RowObject} rowObject + * @returns {String} + */ + getCellTitle(rawCellValue, rowObject) { + return rawCellValue; + } + + /** + * @param {RowObject} rowObject1 + * @param {RowObject} rowObject2 + * @returns {Number} -1, 0, 1 + */ + compareRows(rowObject1, rowObject2) { + let dueDateStr1 = this.getRawCellValue(rowObject1); + let dueDateStr2 = this.getRawCellValue(rowObject2); + if (dueDateStr1 === dueDateStr2) return 0; + if (dueDateStr1 && dueDateStr2) { + return new Date(dueDateStr1) < new Date(dueDateStr2) ? -1 : 1; + } + return dueDateStr1 ? -1 : 1; + } +} diff --git a/src/scripts/js/es6/common/vuecomponents/table/columns/Updated.js b/src/scripts/js/es6/common/vuecomponents/table/columns/Updated.js index 855ae48d..4b711fa3 100644 --- a/src/scripts/js/es6/common/vuecomponents/table/columns/Updated.js +++ b/src/scripts/js/es6/common/vuecomponents/table/columns/Updated.js @@ -1,25 +1,13 @@ -import { CellPrettyDate } from '../cells/renderer/CellPrettyDate' -import {ColumnBase} from './ColumnBase' +import {DateColumnBase} from './DateColumnBase' /** * Column showing the objects _updated prettyfied */ - -export class Updated extends ColumnBase{ +export class Updated extends DateColumnBase{ constructor() { super('Updated', 'row-updated'); this.includedByDefault = false; } - - /** - * - * @param {RowObject} rowObject - * @returns {String} Name of the Cell renderer component - */ - getCellRenderer(rowObject) { - return CellPrettyDate.options.name; - } - /** * * @param {RowObject} rowObject @@ -28,31 +16,4 @@ export class Updated extends ColumnBase{ getRawCellValue(rowObject) { return rowObject.underlyingObject['_updated']; } - - /** - * Cell tooltip - * @param {Any} rawCellValue - * @param {RowObject} rowObject - * @returns {String} - */ - getCellTitle(rawCellValue, rowObject) { - return rawCellValue; - } - - /** - * Compare two rows to sort them. Can be overridden for more complex situations. - * - * @param {RowObject} rowObject1 - * @param {RowObject} rowObject2 - * @returns {Number} -1, 0, 1 - */ - compareRows(rowObject1, rowObject2) { - let dueDateStr1 = this.getRawCellValue(rowObject1); - let dueDateStr2 = this.getRawCellValue(rowObject2); - if (dueDateStr1 === dueDateStr2) return 0; - if (dueDateStr1 && dueDateStr2) { - return new Date(dueDateStr1) < new Date(dueDateStr2) ? -1 : 1; - } - return dueDateStr1 ? -1 : 1; - } }