Skip to content

Commit

Permalink
Using store and syncs config in SmartSyncExplorer hybrid
Browse files Browse the repository at this point in the history
  • Loading branch information
wmathurin committed Nov 11, 2017
1 parent 99b3b47 commit 699602e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
17 changes: 12 additions & 5 deletions samples/common/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -22,16 +23,22 @@ 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);
}
);
});

function appStart(creds, refresh)
function appStart()
{
// Force init
Force.init();
Expand Down
20 changes: 3 additions & 17 deletions samples/smartsyncexplorer/SmartSyncExplorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ <h1 class="title">Contacts</h1>
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);
Expand Down Expand Up @@ -176,23 +175,11 @@ <h1 class="title">Contacts</h1>
},

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() {
Expand Down Expand Up @@ -360,8 +347,7 @@ <h1 class="title">Contacts</h1>

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() {
Expand Down
16 changes: 16 additions & 0 deletions samples/smartsyncexplorer/userstore.json
Original file line number Diff line number Diff line change
@@ -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"}
]
}
]
}
18 changes: 18 additions & 0 deletions samples/smartsyncexplorer/usersyncs.json
Original file line number Diff line number Diff line change
@@ -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"}
}
]
}

0 comments on commit 699602e

Please sign in to comment.