From e54d43be5138e2c8608f133167f340b2dd3dc054 Mon Sep 17 00:00:00 2001 From: Rami Hadi Date: Sun, 29 May 2016 23:08:29 +0300 Subject: [PATCH 1/4] Add Deeplink functionality --- scripts/buildfire.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/scripts/buildfire.js b/scripts/buildfire.js index b55b44be..24e59352 100644 --- a/scripts/buildfire.js +++ b/scripts/buildfire.js @@ -1457,13 +1457,19 @@ var buildfire = { getData: function (callback) { var qs = buildfire.parseQueryString(); callback(qs.dld); /// dld: Deep Link Data - } - , createLink: function (obj) { - var root = "app" + buildfire._context.appId + "://plugin"; - if (!obj) - return root; - else - return root + "?dld=" + JSON.stringify(obj); + }, + template: { + get: function (callback) { + var p = new Packet(null, 'deepLink.getTemplate', {}); + buildfire._sendPacket(p, callback); + } + }, + setData: function (obj, options, callback) { + var p = new Packet(null, 'deepLink.setData', {data : obj, options: options}); + buildfire._sendPacket(p, callback); + + /*var p = new Packet(null, 'deepLink.addValues', {values : [{key:'rami',value:'test'},{key:'rami8',value:'test9'}] , options : {}}); + buildfire._sendPacket(p, function(err,data){});*/ } } /// ref: https://github.com/BuildFire/sdk/wiki/Spinners From 5e2a5ae793afec6a03d4b78e7a5276fbeb2bd3cb Mon Sep 17 00:00:00 2001 From: Rami Hadi Date: Sun, 29 May 2016 23:27:48 +0300 Subject: [PATCH 2/4] json parse for deep link data --- scripts/buildfire.js | 53 +++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/scripts/buildfire.js b/scripts/buildfire.js index 24e59352..16b8cddc 100644 --- a/scripts/buildfire.js +++ b/scripts/buildfire.js @@ -896,7 +896,7 @@ var buildfire = { ,userData: { /// ref: get: function (tag, callback) { - + var tagType = typeof (tag); if (tagType == "undefined") tag = ''; @@ -911,13 +911,13 @@ var buildfire = { }, /// ref: getById: function (id, tag, callback) { - + var idType = typeof (id); if (idType == "function" && typeof (callback) == "undefined") { callback = id; id = ''; } - + var tagType = typeof (tag); if (tagType == "undefined") tag = ''; @@ -932,7 +932,7 @@ var buildfire = { } /// ref: , save: function (obj, tag,userToken, callback) { - + var tagType = typeof (tag); if (tagType == "undefined") tag = ''; @@ -947,16 +947,16 @@ var buildfire = { callback = userToken; userToken = ''; } - + var p = new Packet(null, 'userData.save', { tag: tag,userToken: userToken, obj: obj }); buildfire._sendPacket(p, function (err, result) { - + if (callback) callback(err, result); }); } /// ref: , insert: function (obj, tag, userToken, checkDuplicate, callback) { - + var userTokenType = typeof (userToken); if (userTokenType == "undefined") userToken = ''; @@ -986,18 +986,18 @@ var buildfire = { callback = tag; tag = ''; } - + var p = new Packet(null, 'userData.insert', { tag: tag, userToken: userToken, obj: obj, checkDuplicate: checkDuplicate }); buildfire._sendPacket(p, function (err, result) { - + callback(err, result); }); } /// ref: , bulkInsert: function (arrayObj, tag, userToken, callback) { - + if (arrayObj.constructor !== Array) { - + callback({ "code": "error", "message": "the data should be an array" }, null); return; } @@ -1015,10 +1015,10 @@ var buildfire = { callback = tag; tag = ''; } - + var p = new Packet(null, 'userData.bulkInsert', { tag: tag, userToken: userToken, obj: arrayObj }); buildfire._sendPacket(p, function (err, result) { - + callback(err, result); }); } @@ -1039,16 +1039,16 @@ var buildfire = { callback = tag; tag = ''; } - + var p = new Packet(null, 'userData.update', { tag: tag, userToken: userToken, id: id, obj: obj }); buildfire._sendPacket(p, function (err, result) { - + if (callback) callback(err, result); }); } /// ref , delete: function (id, tag, userToken, callback) { - + var userTokenType = typeof (userToken); if (userTokenType == "undefined") userToken = ''; @@ -1063,16 +1063,16 @@ var buildfire = { callback = tag; tag = ''; } - + var p = new Packet(null, 'userData.delete', { tag: tag, userToken: userToken, id: id }); buildfire._sendPacket(p, function (err, result) { - + if (callback) callback(err, result); }); } /// , search: function (options, tag, callback) { - + var tagType = typeof (tag); if (tagType == "undefined") tag = ''; @@ -1080,11 +1080,11 @@ var buildfire = { callback = tag; tag = ''; } - + //auto correct empty string filter if (typeof (options) == "undefined") options = { filter: {} }; if (!options.filter) options.filter = {}; - + var p = new Packet(null, 'userData.search', { tag: tag, obj: options }); buildfire._sendPacket(p, function (err, result) { callback(err, result); @@ -1130,7 +1130,7 @@ var buildfire = { if(ratio < 1){ var ratio = 1; } - + if (!options) options = {width: window.innerWidth}; else if (typeof(options) != "object") @@ -1292,7 +1292,7 @@ var buildfire = { console.warn("smartcrop.js isnt imported"); - + if (url.indexOf("http://imageserver.prod.s3.amazonaws.com") == 0 || url.indexOf("https://imageserver.prod.s3.amazonaws.com") == 0) { url = url.replace(/^https:\/\//i, 'http://'); @@ -1313,7 +1313,7 @@ var buildfire = { canvas.height = options.height; SmartCrop.crop(img, options, function(result){ - + var sug = result.topCrop; ctx.drawImage(img, sug.x, sug.y, sug.width, sug.height,0,0,options.width, options.height); @@ -1456,7 +1456,10 @@ var buildfire = { , deeplink: { getData: function (callback) { var qs = buildfire.parseQueryString(); - callback(qs.dld); /// dld: Deep Link Data + if(qs.dld) + callback(JSON.parse(qs.dld)); /// dld: Deep Link Data + else + callback(null); }, template: { get: function (callback) { From 34de69b8cc1f46906e91443de056f14cd6d31496 Mon Sep 17 00:00:00 2001 From: Rami Hadi Date: Wed, 1 Jun 2016 01:30:45 +0300 Subject: [PATCH 3/4] Remove the commented code --- scripts/buildfire.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/buildfire.js b/scripts/buildfire.js index 16b8cddc..fa02cc43 100644 --- a/scripts/buildfire.js +++ b/scripts/buildfire.js @@ -1470,9 +1470,6 @@ var buildfire = { setData: function (obj, options, callback) { var p = new Packet(null, 'deepLink.setData', {data : obj, options: options}); buildfire._sendPacket(p, callback); - - /*var p = new Packet(null, 'deepLink.addValues', {values : [{key:'rami',value:'test'},{key:'rami8',value:'test9'}] , options : {}}); - buildfire._sendPacket(p, function(err,data){});*/ } } /// ref: https://github.com/BuildFire/sdk/wiki/Spinners From caa47dd920b31dc5cf72c5dc89605ad8e0f6177a Mon Sep 17 00:00:00 2001 From: Rami Hadi Date: Wed, 1 Jun 2016 23:49:25 +0300 Subject: [PATCH 4/4] remove unneeded tests --- test/deeplink.spec.js | 15 --------------- test/ftest/deeplink.spec.js | 5 ----- 2 files changed, 20 deletions(-) diff --git a/test/deeplink.spec.js b/test/deeplink.spec.js index 287a80e4..d3375df7 100644 --- a/test/deeplink.spec.js +++ b/test/deeplink.spec.js @@ -33,19 +33,4 @@ describe('buildfire.deeplink', function () { }); }); - describe('deeplink createLink', function () { - beforeEach( function () { - spyOn(buildfire.deeplink, 'createLink'); - - buildfire.deeplink.createLink('section:7'); - }); - - it("deeplink createLink should exist and be a function", function () { - expect(typeof buildfire.deeplink.createLink).toEqual("function"); - }); - - it("deeplink createLink", function () { - expect(buildfire.deeplink.createLink).toHaveBeenCalledWith('section:7'); - }); - }); }); \ No newline at end of file diff --git a/test/ftest/deeplink.spec.js b/test/ftest/deeplink.spec.js index 673b324f..6ef78e7b 100755 --- a/test/ftest/deeplink.spec.js +++ b/test/ftest/deeplink.spec.js @@ -10,9 +10,4 @@ describe('buildfire.deeplink', function () { }); }); - describe('deeplink createLink', function () { - it("deeplink createLink should exist and be a function", function () { - expect(buildfire.deeplink.createLink).to.a("function"); - }); - }); }); \ No newline at end of file