From 5ca1b67d5212be39205126d36dc81566e26d03ac Mon Sep 17 00:00:00 2001 From: Mark Palnau Date: Thu, 28 Jan 2016 23:14:59 -0500 Subject: [PATCH 1/6] Added .raw(parameter, value) Added .raw(parameter, value) functionality to add default parameters in the URI concatenation string. --- src/joData.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/src/joData.js b/src/joData.js index 9119e74..e722399 100644 --- a/src/joData.js +++ b/src/joData.js @@ -1,6 +1,6 @@ (function (window) { "use strict"; - var jo, FilterObj, Helpers; + var jo, FilterObj, RawObj, Helpers; jo = function (baseUri) { if (!Array.remove) { @@ -123,6 +123,27 @@ } }; + this.RawSettings = { + Parameters: [], + DefaultParameters: [], + toString: function () { + var i, raw; + raw = ""; + if (this.Parameters.length > 0) { + for (i = 0; i < this.Parameters.length; i++) { + raw += '&' + this.Parameters[i].toString(); + } + } + return raw.substring(1); + }, + reset: function () { + this.Parameters = []; + }, + isSet: function () { + return this.Parameters.length > 0 || this.DefaultParameters.length > 0; + } + }; + this.FilterSettings = { Filters: [], DefaultFilters: [], @@ -382,6 +403,10 @@ this.InlineCountSettings.reset(); return this; }, + raw: function (parameter, parameterValue) { + this.RawSettings.Parameters.push(new RawObj(parameter,parameterValue)); + return this; + }, captureFilter: function () { this.FilterSettings.CapturedFilter = []; for (var i = 0; i < this.FilterSettings.Filters.length; i++) { @@ -442,6 +467,10 @@ url = this.baseUri; components = []; + if (this.RawSettings.isSet()) { + components.push(this.RawSettings.toString()); + } + if (this.OrderBySettings.isSet()) { components.push(this.OrderBySettings.toString()); } @@ -488,11 +517,16 @@ jsonObj.SelectSettings = null; jsonObj.ExpandSettings = null; jsonObj.FormatSettings = null; + jsonObj.RawSettings = null; jsonObj.InlineCountSettings = null; jsonObj.FilterSettings = null; jsonObj.defaults = this.defaults; + if (this.RawSettings.isSet()) { + jsonObj.RawSettings = this.RawSettings; + } + if (this.OrderBySettings.isSet()) { jsonObj.OrderBySettings = this.OrderBySettings; } @@ -608,6 +642,14 @@ } } + if (json.RawSettings !== null) { + for (key in json.RawSettings) { + if (json.RawSettings.hasOwnProperty(key)) { + joDataObj.RawSettings[key] = json.RawSettings[key]; + } + } + } + if (json.FilterSettings !== null) { joDataObj.FilterSettings.loadFromJson(json.FilterSettings); } @@ -615,6 +657,25 @@ return joDataObj; }; + RawObj = function (rawParameter, rawParameterValue) { + this.rawParameter = null; + this.rawParameterValue = null; + if (rawParameter !== undefined && rawParameter !== null && rawParameterValue !== undefined && rawParameterValue !== null) { + this.rawParameter = rawParameter; + this.rawParameterValue = rawParameterValue; + } + + return this; + }; + + RawObj.prototype = { + rawParameter: null, + rawParameterValue: null, + toString: function () { + return this.rawParameter + '=' + this.rawParameterValue; + } + }; + FilterObj = function (filterObj, logicalOperator) { this.filterObj = filterObj; this.logicalOperator = null; From 8299c2a5710ab25cce3b74d4bab17d185b616d8d Mon Sep 17 00:00:00 2001 From: Mark Palnau Date: Thu, 28 Jan 2016 23:17:13 -0500 Subject: [PATCH 2/6] Fixed test file and added .raw(p,v) test This test file was using the old "joData" name rather than "jo". Also fixed deprecated function calls, and finally added the new .raw() testing. --- example/tests.html | 77 +++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/example/tests.html b/example/tests.html index 6966afc..616ae5c 100644 --- a/example/tests.html +++ b/example/tests.html @@ -6,41 +6,48 @@ From 0ccf849c5b0773d6c00747fb3db3bd2d74dea1e4 Mon Sep 17 00:00:00 2001 From: Mark Palnau Date: Thu, 28 Jan 2016 23:36:28 -0500 Subject: [PATCH 3/6] Added raw() function doc Added initial doc for Raw parameters and removed incomplete sentence in description. --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d43935d..7121fe8 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ A pure javascript library to help you query jo data. joData creates a javascript object that represents an oData query. This allows you to easily modify parts of your oData query without effecting the rest of it. -joData's goal is to implement - All methods in joData are chainable. ##NOTE: @@ -970,6 +968,18 @@ Output: Output: $filter=ceiling(Price) eq 2 + +####Raw Parameters + +To add parameters onto the query outside of joData, you may use the Raw function. + +#####raw(parameter, value) + + query.raw('ParameterName',"'ParameterValue'") + +Output: + + ParameterName='ParameterValue' ##Saving Local From 219f19590dd840f113dd9d783a4b11ce38e7c612 Mon Sep 17 00:00:00 2001 From: Mark Palnau Date: Thu, 28 Jan 2016 23:46:35 -0500 Subject: [PATCH 4/6] Fixed styling --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7121fe8..a5779c6 100644 --- a/README.md +++ b/README.md @@ -969,11 +969,11 @@ Output: $filter=ceiling(Price) eq 2 -####Raw Parameters +###Raw Parameters To add parameters onto the query outside of joData, you may use the Raw function. -#####raw(parameter, value) +####raw(parameter, value) query.raw('ParameterName',"'ParameterValue'") From 9dfab9f203a360af4d58a1a85d736814c4edb9ef Mon Sep 17 00:00:00 2001 From: Mark Palnau Date: Sun, 14 Feb 2016 17:06:21 -0500 Subject: [PATCH 5/6] Added raw() functionality to joDataSpec Added test for 'raw' function and its save/load local. --- spec/javascripts/specs/joDataSpec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/javascripts/specs/joDataSpec.js b/spec/javascripts/specs/joDataSpec.js index b4b7fa8..e249825 100644 --- a/spec/javascripts/specs/joDataSpec.js +++ b/spec/javascripts/specs/joDataSpec.js @@ -941,6 +941,13 @@ describe('jo', function () { }); }); + describe('Raw Parameters', function() { + var j = new jo('http://foo.bar'); + j.raw("parameter1", 1); + j.raw("parameter2", "two"); + expect(j.toString()).toEqual("http://foo.bar?parameter1=1¶meter2=two"); + }); + describe('Saving to local, the loading from local', function () { describe('Order By', function () { it('should cause an $orderby query string parameter to appear upon toString', function () { @@ -1796,5 +1803,17 @@ describe('jo', function () { }); }); }); + + describe('Raw', function () { + it('should cause a raw parameter on toString', function () { + var j = new jo('http://foo.bar'); + j.raw("parameter",100); + + j.saveLocal(); + var l = jo.loadLocal(); + + expect(l.toString()).toEqual('http://foo.bar?parameter=100'); + }); + }); }); }); From b9f44bbaad0b11c51f3c120a95fe2aaad9987944 Mon Sep 17 00:00:00 2001 From: Mark Palnau Date: Mon, 15 Feb 2016 01:03:33 -0500 Subject: [PATCH 6/6] Fixed save/load local for Raw() Added loadFromJson function to rawSettings to fix and allow save/load from local --- src/joData.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/joData.js b/src/joData.js index e722399..bddade3 100644 --- a/src/joData.js +++ b/src/joData.js @@ -141,6 +141,14 @@ }, isSet: function () { return this.Parameters.length > 0 || this.DefaultParameters.length > 0; + }, + loadFromJson: function (rawSettings) { + var i, parameter; + + for (i = 0; i < rawSettings.Parameters.length; i++) { + parameter = rawSettings.Parameters[i]; + this.Parameters.push(new RawObj(parameter.rawParameter,parameter.rawParameterValue)); + } } }; @@ -643,11 +651,7 @@ } if (json.RawSettings !== null) { - for (key in json.RawSettings) { - if (json.RawSettings.hasOwnProperty(key)) { - joDataObj.RawSettings[key] = json.RawSettings[key]; - } - } + joDataObj.RawSettings.loadFromJson(json.RawSettings); } if (json.FilterSettings !== null) {