From 699602ebe218eed956fbe442ec2a365db28dfec0 Mon Sep 17 00:00:00 2001 From: Wolfgang Mathurin Date: Fri, 10 Nov 2017 20:48:06 -0800 Subject: [PATCH] Using store and syncs config in SmartSyncExplorer hybrid --- samples/common/auth.js | 17 +++++++++++----- .../smartsyncexplorer/SmartSyncExplorer.html | 20 +++---------------- samples/smartsyncexplorer/userstore.json | 16 +++++++++++++++ samples/smartsyncexplorer/usersyncs.json | 18 +++++++++++++++++ 4 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 samples/smartsyncexplorer/userstore.json create mode 100644 samples/smartsyncexplorer/usersyncs.json diff --git a/samples/common/auth.js b/samples/common/auth.js index 8ea87b45..8e23825d 100644 --- a/samples/common/auth.js +++ b/samples/common/auth.js @@ -5,14 +5,15 @@ var app = { utils: {} }; +var inBrowser = cordova.interceptExec; + jQuery(document).ready(function() { //Add event listeners and so forth here console.log("onLoad: jquery ready"); // FastClick new FastClick(document.body); - // Browser - if (cordova.interceptExec) { + if (inBrowser) { force.init({loginURL: "https://test.salesforce.com/", appId: "3MVG98dostKihXN53TYStBIiS8BTFb20jwWfFcShqfABb3c.HH3CkmA00FuCmc0aM3v4LZOGR5QBnEi77fotN", oauthCallbackURL: "http://localhost:8200/test/oauthcallback.html", @@ -22,8 +23,14 @@ jQuery(document).ready(function() { force.login( function() { - console.log("Auth succeeded"); - appStart(); + console.log("Auth succeeded"); + + if (inBrowser) { + storeMap.setupUserStoreFromDefaultConfig(() => syncManagerMap.setupUserSyncsFromDefaultConfig(() => appStart())) + } + else { + appStart(); + } }, function(error) { console.log("Auth failed: " + error); @@ -31,7 +38,7 @@ jQuery(document).ready(function() { ); }); -function appStart(creds, refresh) +function appStart() { // Force init Force.init(); diff --git a/samples/smartsyncexplorer/SmartSyncExplorer.html b/samples/smartsyncexplorer/SmartSyncExplorer.html index 1cf2c22d..9b387f5d 100644 --- a/samples/smartsyncexplorer/SmartSyncExplorer.html +++ b/samples/smartsyncexplorer/SmartSyncExplorer.html @@ -142,7 +142,6 @@

Contacts

initialize: function() { var that = this; this.fieldlist = app.models.Contact.prototype.fieldlist; - this.fieldlistForSyncUp = _.without(app.models.Contact.prototype.fieldlist, "Id", "LastModifiedDate"); this.listView = new app.views.ContactListView({model: this.model}); document.addEventListener("sync", function() { that.handleSyncUpdate(event.detail); @@ -176,23 +175,11 @@

Contacts

}, syncDown: function() { - var self = this; - var syncName = "smartSyncExplorerSyncDown"; - cordova.require("com.salesforce.plugin.smartsync").getSyncStatus(syncName, function(sync) { - if (sync == null) { - // First time - var target = {type:"soql", query:"SELECT " + self.fieldlist.join(",") + " FROM Contact LIMIT 10000"}; - cordova.require("com.salesforce.plugin.smartsync").syncDown(target, "contacts", {mergeMode:Force.MERGE_MODE_DOWNLOAD.OVERWRITE}, syncName, self.handleSyncUpdate.bind(self)); - } - else { - // Subsequent times - cordova.require("com.salesforce.plugin.smartsync").reSync(syncName, self.handleSyncUpdate.bind(self)); - } - }); + cordova.require("com.salesforce.plugin.smartsync").reSync("syncDownContacts" /* see usersyncs.json */, this.handleSyncUpdate.bind(this)); }, syncUp: function() { - cordova.require("com.salesforce.plugin.smartsync").syncUp("contacts", {fieldlist: this.fieldlistForSyncUp}, this.handleSyncUpdate.bind(this)); + cordova.require("com.salesforce.plugin.smartsync").reSync("syncUpContacts" /* see usersyncs.json */, this.handleSyncUpdate.bind(this)); }, sync: function() { @@ -360,8 +347,7 @@

Contacts

setupCaches: function() { // Cache for offline support - app.cache = new Force.StoreCache("contacts", [ {path:"FirstName", type:"full_text"}, {path:"LastName", type:"full_text"}]); - app.cache.init(); + app.cache = new Force.StoreCache("contacts" /* see userstore.json */); }, initialize: function() { diff --git a/samples/smartsyncexplorer/userstore.json b/samples/smartsyncexplorer/userstore.json new file mode 100644 index 00000000..9426ad30 --- /dev/null +++ b/samples/smartsyncexplorer/userstore.json @@ -0,0 +1,16 @@ +{ + "soups": [ + { + "soupName": "contacts", + "indexes": [ + { "path": "Id", "type": "string"}, + { "path": "FirstName", "type": "full_text"}, + { "path": "LastName", "type": "full_text"}, + { "path": "__local__", "type": "string"}, + { "path": "__locally_created__", "type": "string"}, + { "path": "__locally_updated__", "type": "string"}, + { "path": "__locally_deleted__", "type": "string"} + ] + } + ] +} diff --git a/samples/smartsyncexplorer/usersyncs.json b/samples/smartsyncexplorer/usersyncs.json new file mode 100644 index 00000000..04a9c091 --- /dev/null +++ b/samples/smartsyncexplorer/usersyncs.json @@ -0,0 +1,18 @@ +{ + "syncs": [ + { + "syncName": "syncDownContacts", + "syncType": "syncDown", + "soupName": "contacts", + "target": {"type":"soql", "query":"SELECT Id, FirstName, LastName, Title, MobilePhone, Email, Department, HomePhone, LastModifiedDate FROM Contact LIMIT 10000"}, + "options": {"mergeMode":"OVERWRITE"} + }, + { + "syncName": "syncUpContacts", + "syncType": "syncUp", + "soupName": "contacts", + "target": {"createFieldlist":["FirstName", "LastName", "Title", "MobilePhone", "Email", "Department", "HomePhone"]}, + "options": {"fieldlist":["Id", "FirstName", "LastName", "Title", "MobilePhone", "Email", "Department", "HomePhone"], "mergeMode":"LEAVE_IF_CHANGED"} + } + ] +}