From 20df3c48785b735aa94b96a3be0587414f40ec9e Mon Sep 17 00:00:00 2001 From: Zaid Safadi Date: Sat, 30 Dec 2017 14:51:14 -0500 Subject: [PATCH] add referece to liteevent --- Demo/JSLib/Query/QueryPageModel.js | 103 +++++++++++++++++++++++++ Demo/JSLib/Query/QueryPageModel.js.map | 1 + Demo/JSLib/Query/QueryPageModel.ts | 3 +- Demo/JSLib/Query/QueryPagerView.js | 60 ++++++++++++++ Demo/JSLib/Query/QueryPagerView.js.map | 1 + Demo/JSLib/Query/QueryPagerView.ts | 3 +- Demo/JSLib/Types/ILiteEvent.js | 2 +- Demo/JSLib/Types/ILiteEvent.js.map | 2 +- 8 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 Demo/JSLib/Query/QueryPageModel.js create mode 100644 Demo/JSLib/Query/QueryPageModel.js.map create mode 100644 Demo/JSLib/Query/QueryPagerView.js create mode 100644 Demo/JSLib/Query/QueryPagerView.js.map diff --git a/Demo/JSLib/Query/QueryPageModel.js b/Demo/JSLib/Query/QueryPageModel.js new file mode 100644 index 0000000..e1a38da --- /dev/null +++ b/Demo/JSLib/Query/QueryPageModel.js @@ -0,0 +1,103 @@ +/// +var QueryPageModel = (function () { + function QueryPageModel() { + this.totalCount = 0; + this._resultsCount = 0; + this.firstOffset = -1; + this.prevOffset = -1; + this.nextOffset = -1; + this.lastOffset = -1; + this._currentPageOffset = 0; + this.pageLimit = 12; + this.currentPage = 0; + this.pageCount = 0; + } + QueryPageModel.prototype.setLinkHeader = function (linkHeader, resultsCount, totalCount) { + var _this = this; + if (typeof linkHeader == "undefined" || linkHeader == null) { + return; + } + this.totalCount = totalCount; + this.ResultsCount = resultsCount; + var pageLinks = linkHeader.split(","); + this.firstOffset = this.prevOffset = this.nextOffset = this.lastOffset = -1; + pageLinks.forEach(function (link) { + var linkParts = link.split(";"); + var queryPart = linkParts[0].split("?")[1]; + var offset = parseInt(_this.getQueryVariable(queryPart, "offset"), 10); + _this.pageLimit = parseInt(_this.getQueryVariable(queryPart, "limit"), 10); + var rel = _this.getQueryVariable(linkParts[1], "rel"); + switch (rel) { + case "\"first\"": + { + _this.firstOffset = offset; + } + break; + case "\"prev\"": + { + _this.prevOffset = offset; + } + break; + case "\"next\"": + { + _this.nextOffset = offset; + } + break; + case "\"last\"": + { + _this.lastOffset = offset; + } + break; + } + }); + }; + Object.defineProperty(QueryPageModel.prototype, "currentOffset", { + get: function () { + return this._currentPageOffset; + }, + set: function (offset) { + this._currentPageOffset = offset; + this.currentPage = Math.floor(this._currentPageOffset / this.pageLimit) + 1; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(QueryPageModel.prototype, "pageLimit", { + get: function () { + return this._pageLimit; + }, + set: function (limit) { + if (limit < 1) { + throw "page limit can't be less than 1"; + } + this._pageLimit = limit; + this.currentPage = Math.floor(this._currentPageOffset / this.pageLimit) + 1; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(QueryPageModel.prototype, "ResultsCount", { + get: function () { + return this._resultsCount; + }, + set: function (count) { + this._resultsCount = count; + this.pageCount = Math.ceil(this.totalCount / this.pageLimit); + }, + enumerable: true, + configurable: true + }); + //https://stackoverflow.com/questions/2090551/parse-query-string-in-javascript + QueryPageModel.prototype.getQueryVariable = function (query, variable) { + var vars = query.split('&'); + for (var i = 0; i < vars.length; i++) { + var pair = vars[i].split('='); + if (decodeURIComponent(pair[0]).trim() == variable) { + return decodeURIComponent(pair[1]); + } + } + return ""; + }; + return QueryPageModel; +}()); +//# sourceMappingURL=QueryPageModel.js.map \ No newline at end of file diff --git a/Demo/JSLib/Query/QueryPageModel.js.map b/Demo/JSLib/Query/QueryPageModel.js.map new file mode 100644 index 0000000..c54cf6b --- /dev/null +++ b/Demo/JSLib/Query/QueryPageModel.js.map @@ -0,0 +1 @@ +{"version":3,"file":"QueryPageModel.js","sourceRoot":"","sources":["QueryPageModel.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C;IAcG;QAEG,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC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G,KAAK,CAAC;YAExB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/E,CAAC;;;OAXA;IAaD,sBAAI,wCAAY;aAAhB;YACG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC;QAC7B,CAAC;aACD,UAAiB,KAAa;YAC3B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;YAE3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;QAChE,CAAC;;;OALA;IAOD,8EAA8E;IAC9E,yCAAgB,GAAhB,UAAiB,KAAY,EAAE,QAAe;QAC3C,IAAI,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5B,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,IAAI,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC9B,EAAE,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,QAAQ,CAAC,CAAC,CAAC;gBAClD,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACtC,CAAC;QACJ,CAAC;QAED,MAAM,CAAC,EAAE,CAAC;IACb,CAAC;IAIJ,qBAAC;AAAD,CAAC,AAjID,IAiIC"} \ No newline at end of file diff --git a/Demo/JSLib/Query/QueryPageModel.ts b/Demo/JSLib/Query/QueryPageModel.ts index e6f5668..31a6717 100644 --- a/Demo/JSLib/Query/QueryPageModel.ts +++ b/Demo/JSLib/Query/QueryPageModel.ts @@ -1,4 +1,5 @@ -class QueryPageModel +/// +class QueryPageModel { public totalCount: number; public firstOffset: number; diff --git a/Demo/JSLib/Query/QueryPagerView.js b/Demo/JSLib/Query/QueryPagerView.js new file mode 100644 index 0000000..5857291 --- /dev/null +++ b/Demo/JSLib/Query/QueryPagerView.js @@ -0,0 +1,60 @@ +/// +var QueryPagerView = (function () { + function QueryPagerView($element, model) { + this.onFirst = new LiteEvent(); + this.onPrev = new LiteEvent(); + this.onNext = new LiteEvent(); + this.onLast = new LiteEvent(); + this._$element = $element; + this.model = model; + this._$first = $(this._$element).find(".page-first"); + this._$prev = $(this._$element).find(".page-previous"); + this._$next = $(this._$element).find(".page-next"); + this._$last = $(this._$element).find(".page-last"); + this._$pageInfo = $(this._$element).find(".page-info"); + this._registerEvents(); + this.render(); + } + QueryPagerView.prototype._registerEvents = function () { + var _this = this; + this._$first.click(function () { _this.onFirst.trigger(); }); + this._$prev.click(function () { _this.onPrev.trigger(); }); + this._$next.click(function () { _this.onNext.trigger(); }); + this._$last.click(function () { _this.onLast.trigger(); }); + }; + QueryPagerView.prototype.render = function () { + if (this.model.firstOffset < 0) { + this._$first.addClass("disabled"); + } + else { + this._$first.removeClass("disabled"); + } + if (this.model.prevOffset < 0) { + this._$prev.addClass("disabled"); + } + else { + this._$prev.removeClass("disabled"); + } + if (this.model.nextOffset < 0) { + this._$next.addClass("disabled"); + } + else { + this._$next.removeClass("disabled"); + } + if (this.model.lastOffset < 0) { + this._$last.addClass("disabled"); + } + else { + this._$last.removeClass("disabled"); + } + this._$pageInfo.text("Page: " + this.model.currentPage + "/" + this.model.pageCount); + }; + QueryPagerView.prototype.show = function () { + this._$element.show(); + }; + QueryPagerView.prototype.hide = function () { + this._$element.hide(); + }; + return QueryPagerView; +}()); +//# sourceMappingURL=QueryPagerView.js.map \ No newline at end of file diff --git a/Demo/JSLib/Query/QueryPagerView.js.map b/Demo/JSLib/Query/QueryPagerView.js.map new file mode 100644 index 0000000..0762512 --- /dev/null +++ b/Demo/JSLib/Query/QueryPagerView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AAC;YACH,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACxF,CAAC;IAEM,6BAAI,GAAX;QAEG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IACM,6BAAI,GAAX;QACG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IACJ,qBAAC;AAAD,CAAC,AA7ED,IA6EC"} \ No newline at end of file diff --git a/Demo/JSLib/Query/QueryPagerView.ts b/Demo/JSLib/Query/QueryPagerView.ts index f1b9579..4b020cb 100644 --- a/Demo/JSLib/Query/QueryPagerView.ts +++ b/Demo/JSLib/Query/QueryPagerView.ts @@ -1,4 +1,5 @@ -class QueryPagerView +/// +class QueryPagerView { _$first: JQuery; _$prev: JQuery; diff --git a/Demo/JSLib/Types/ILiteEvent.js b/Demo/JSLib/Types/ILiteEvent.js index 488483f..3b6e21c 100644 --- a/Demo/JSLib/Types/ILiteEvent.js +++ b/Demo/JSLib/Types/ILiteEvent.js @@ -13,4 +13,4 @@ var LiteEvent = (function () { }; return LiteEvent; }()); -//# sourceMappingURL=ILiteEvent.js.map \ No newline at end of file +//# sourceMappingURL=iliteevent.js.map \ No newline at end of file diff --git a/Demo/JSLib/Types/ILiteEvent.js.map b/Demo/JSLib/Types/ILiteEvent.js.map index e62dbda..790bd5b 100644 --- a/Demo/JSLib/Types/ILiteEvent.js.map +++ b/Demo/JSLib/Types/ILiteEvent.js.map @@ -1 +1 @@ -{"version":3,"file":"ILiteEvent.js","sourceRoot":"","sources":["ILiteEvent.ts"],"names":[],"mappings":"AAMA;IAAA;QACW,aAAQ,GAA4B,EAAE,CAAC;IAalD,CAAC;IAXS,sBAAE,GAAT,UAAU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