@frui.ts/data
Advanced tools
Comparing version 1.0.0-alpha.9 to 1.0.0-alpha.10
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./pagerHelper"), exports); | ||
__exportStar(require("./sortingDirection"), exports); | ||
__exportStar(require("./sortingHelper"), exports); | ||
__exportStar(require("./types"), exports); | ||
__export(require("./pagerHelper")); | ||
__export(require("./sortingDirection")); | ||
__export(require("./sortingHelper")); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import type { IPagingFilter, IPagingInfo } from "./types"; | ||
import { IPagingFilter, IPagingInfo } from "./types"; | ||
declare type onPageChangedHandler = (offset: number, limit: number) => void; | ||
@@ -3,0 +3,0 @@ export interface IPagerProps { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handlePageSizeChanged = exports.pageChangedHandler = exports.handlePageChanged = exports.handlePagingChanged = void 0; | ||
const defaultPageSize = 25; | ||
var defaultPageSize = 25; | ||
function handlePagingChanged(offset, limit, filter, onPageChanged) { | ||
@@ -16,4 +15,4 @@ if (filter) { | ||
function handlePageChanged(newPageNumber, filter, onPageChanged) { | ||
const pageSize = (filter === null || filter === void 0 ? void 0 : filter.limit) || defaultPageSize; | ||
const offset = (newPageNumber - 1) * pageSize; | ||
var pageSize = (filter && filter.limit) || defaultPageSize; | ||
var offset = (newPageNumber - 1) * pageSize; | ||
handlePagingChanged(offset, pageSize, filter, onPageChanged); | ||
@@ -23,3 +22,3 @@ } | ||
function pageChangedHandler(newPageNumber, filter, onPageChanged) { | ||
return () => handlePageChanged(newPageNumber, filter, onPageChanged); | ||
return function () { return handlePageChanged(newPageNumber, filter, onPageChanged); }; | ||
} | ||
@@ -26,0 +25,0 @@ exports.pageChangedHandler = pageChangedHandler; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SortingDirection = void 0; | ||
var SortingDirection; | ||
@@ -5,0 +4,0 @@ (function (SortingDirection) { |
@@ -1,5 +0,2 @@ | ||
import { SortingDirection } from "./sortingDirection"; | ||
import type { IPagingFilter } from "./types"; | ||
export declare function getSortingDirection(filter: IPagingFilter, columnName: string): SortingDirection | undefined; | ||
export declare function setSort(filter: IPagingFilter, columnName: string, direction?: SortingDirection): void; | ||
export declare function addSort(filter: IPagingFilter, columnName: string, direction?: SortingDirection): void; | ||
import { IPagingFilter } from "./types"; | ||
export declare function applySort(filter: IPagingFilter, columnName: string): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addSort = exports.setSort = exports.getSortingDirection = void 0; | ||
const sortingDirection_1 = require("./sortingDirection"); | ||
function getSortingDirection(filter, columnName) { | ||
var _a, _b; | ||
const existingIndex = (_a = filter.sorting) === null || _a === void 0 ? void 0 : _a.findIndex(x => x.column === columnName); | ||
if (existingIndex === undefined || existingIndex < 0) { | ||
return undefined; | ||
var sortingDirection_1 = require("./sortingDirection"); | ||
function applySort(filter, columnName) { | ||
if (filter.sortColumn === columnName) { | ||
filter.sortDirection = | ||
filter.sortDirection === sortingDirection_1.SortingDirection.Ascending ? sortingDirection_1.SortingDirection.Descending : sortingDirection_1.SortingDirection.Ascending; | ||
} | ||
return (_b = filter.sorting) === null || _b === void 0 ? void 0 : _b[existingIndex].direction; | ||
} | ||
exports.getSortingDirection = getSortingDirection; | ||
function setSort(filter, columnName, direction) { | ||
var _a; | ||
const existingSort = ((_a = filter.sorting) === null || _a === void 0 ? void 0 : _a.length) ? filter.sorting[0] : undefined; | ||
const sortDirection = direction !== null && direction !== void 0 ? direction : ((existingSort === null || existingSort === void 0 ? void 0 : existingSort.column) === columnName && existingSort.direction === sortingDirection_1.SortingDirection.Ascending | ||
? sortingDirection_1.SortingDirection.Descending | ||
: sortingDirection_1.SortingDirection.Ascending); | ||
if (filter.sorting) { | ||
filter.sorting[0] = { column: columnName, direction: sortDirection }; | ||
filter.sorting.length = 1; | ||
} | ||
else { | ||
filter.sorting = [{ column: columnName, direction: sortDirection }]; | ||
filter.sortColumn = columnName; | ||
filter.sortDirection = sortingDirection_1.SortingDirection.Ascending; | ||
} | ||
} | ||
exports.setSort = setSort; | ||
function addSort(filter, columnName, direction) { | ||
if (!filter.sorting) { | ||
filter.sorting = [{ column: columnName, direction: direction !== null && direction !== void 0 ? direction : sortingDirection_1.SortingDirection.Ascending }]; | ||
return; | ||
} | ||
const existingIndex = filter.sorting.findIndex(x => x.column === columnName); | ||
if (existingIndex === -1) { | ||
filter.sorting.push({ column: columnName, direction: direction !== null && direction !== void 0 ? direction : sortingDirection_1.SortingDirection.Ascending }); | ||
} | ||
else { | ||
filter.sorting[existingIndex].direction = | ||
direction !== null && direction !== void 0 ? direction : (filter.sorting[existingIndex].direction === sortingDirection_1.SortingDirection.Ascending | ||
? sortingDirection_1.SortingDirection.Descending | ||
: sortingDirection_1.SortingDirection.Ascending); | ||
} | ||
} | ||
exports.addSort = addSort; | ||
exports.applySort = applySort; | ||
//# sourceMappingURL=sortingHelper.js.map |
@@ -1,6 +0,6 @@ | ||
import type { SortingDirection } from "./sortingDirection"; | ||
import { SortingDirection } from "./sortingDirection"; | ||
export interface IPagingInfo { | ||
readonly totalItems: number; | ||
readonly offset: number; | ||
readonly limit: number; | ||
totalItems: number; | ||
offset: number; | ||
limit: number; | ||
} | ||
@@ -10,7 +10,5 @@ export interface IPagingFilter { | ||
limit: number; | ||
sorting?: { | ||
column: string; | ||
direction: SortingDirection; | ||
}[]; | ||
sortColumn?: string; | ||
sortDirection?: SortingDirection; | ||
} | ||
export declare type PagedQueryResult<TEntity> = [TEntity[], IPagingInfo]; |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.0.0-alpha.9", | ||
"version": "1.0.0-alpha.10", | ||
"description": "Helpers and interfaces for handling paged and sorted data sets", | ||
@@ -37,3 +37,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "718298c96617555dd2121f87a2dfefb3ea16d039" | ||
"gitHead": "5454d007244bb9cdd28be5207a9f125f04a9ac43" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10994
93