Changes

Jump to navigation Jump to search
m
no edit summary
Line 37: Line 37:  
 
 
this.EnqueuePDIO = function( sw, c1, c2, c3 ) {
 
this.EnqueuePDIO = function( sw, c1, c2, c3 ) {
var k = Enquire( PersonalDataDataBaseName, CurrentPerson, sw, c1, c2, c3 );
+
return Enquire( PersonalDataDataBaseName, CurrentPerson, sw, c1, c2, c3 );
k.onsuccess = function () {
  −
console.log("xturn 5")
  −
return k;
  −
}
  −
console.log("xturn 4")
  −
return k;
   
}
 
}
   Line 63: Line 57:  
// retrieve record, make record.field1 = field2, push back
 
// retrieve record, make record.field1 = field2, push back
   −
async function Enquire( pddbname, record, sqitch, control_1, control_2, control_3 ) {
+
function Enquire( pddbname, record, sqitch, control_1, control_2, control_3 ) {
var pddb = window.indexedDB.open(pddbname, 3);
+
return new Promise(
var inp_obj;
+
function(resolve, reject) {
pddb.onupgradeneeded = function() {
  −
var db = pddb.result;
  −
var store = db.createObjectStore(pddbname, {keyPath: "id"});
     −
// shouldn't the index be the wiki.personaldata.io username?
+
var pddb = await window.indexedDB.open(pddbname, 3);
 +
var inp_obj;
 +
pddb.onupgradeneeded = function() {
 +
var db = pddb.result;
 +
var store = db.createObjectStore(pddbname, {keyPath: "id"});
   −
var index = store.createIndex("NameIndex", ["id"]);
+
// shouldn't the index be the wiki.personaldata.io username?
};
  −
pddb.onsuccess = function() {
  −
var db = pddb.result;
  −
var tx = db.transaction(pddbname, "readwrite");
  −
var store = tx.objectStore(pddbname);
  −
var index = store.index("NameIndex");
     −
// Get the original record from the db...
+
var index = store.createIndex("NameIndex", ["id"]);
var getRecord = index.get([record.id]);
+
};
 +
pddb.onsuccess = function() {
 +
var db = pddb.result;
 +
var tx = db.transaction(pddbname, "readwrite");
 +
var store = tx.objectStore(pddbname);
 +
var index = store.index("NameIndex");
   −
getRecord.onsuccess = function() {
+
// Get the original record from the db...
console.log( "Record found in database: \n <<");
+
var getRecord = index.get([record.id]);
console.log( getRecord.result );
  −
console.log( ">>");
     −
// Essential recordAdd
+
getRecord.onsuccess = function() {
if ( sqitch === "aggressive push" ) {
+
console.log( "Record found in database: \n <<");
inp_obj = record;
+
console.log( getRecord.result );
store.put( inp_obj );
+
console.log( ">>");
return inp_obj;
  −
} else if ( sqitch === "checkin" ) {
  −
  −
if ( getRecord.result != undefined ) {
  −
console.log("getting from store");
  −
inp_obj = getRecord.result;
  −
} else {
  −
console.log("overriding whatever in there");
  −
inp_obj = record;
  −
store.put(inp_obj);
  −
}
     −
} else {
+
// Essential recordAdd
if ( getRecord.result != undefined ) {
+
if ( sqitch === "aggressive push" ) {
inp_obj = getRecord.result;
+
inp_obj = record;
if ( sqitch === "get record" ) {
+
await store.put( inp_obj );
// if found, let's use that from now on
  −
console.log("Getting record");
  −
// let's return it so that our addrecord can be used as a getter as well
   
return inp_obj;
 
return inp_obj;
}  
+
} else if ( sqitch === "checkin" ) {
//
+
// endof onsuccess
+
if ( getRecord.result != undefined ) {
} else {
+
console.log("getting from store");
console.log("record not found");
+
inp_obj = getRecord.result;
if ( sqitch === "update record" ) {
+
} else {
inp_obj = record;
+
console.log("overriding whatever in there");
 +
inp_obj = record;
 +
await store.put(inp_obj);
 +
}
 +
 
 
} else {
 
} else {
return undefined;
+
if ( getRecord.result != undefined ) {
}
+
inp_obj = getRecord.result;
}
+
if ( sqitch === "get record" ) {
// endof resultdefined
+
// if found, let's use that from now on
}
+
console.log("Getting record");
// endofELSE
+
// let's return it so that our addrecord can be used as a getter as well
if ( sqitch === "update record" ) { // Record Update
+
return inp_obj;
if ( control_1 != undefined ) {
+
}
if ( control_2 != undefined ) {
+
//
if ( control_3 != undefined ) {
+
// endof onsuccess
+
} else {
if ( Array.isArray( inp_obj[ control_1 ][ control_2 ] ) ) {
+
console.log("record not found");
inp_obj[ control_1 ][ control_2 ].push( control_3 );
+
if ( sqitch === "update record" ) {
 +
inp_obj = record;
 
} else {
 
} else {
inp_obj[ control_1 ][ control_2 ] = control_3; // => "Bob"
+
return undefined;
 
}
 
}
store.put(inp_obj);
+
}
} else {
+
// endof resultdefined
+
}
if ( Array.isArray( inp_obj[ control_1 ] ) ) {
+
// endofELSE
inp_obj[ control_1 ].push( control_2 );
+
if ( sqitch === "update record" ) { // Record Update
 +
if ( control_1 != undefined ) {
 +
if ( control_2 != undefined ) {
 +
if ( control_3 != undefined ) {
 +
 +
if ( Array.isArray( inp_obj[ control_1 ][ control_2 ] ) ) {
 +
inp_obj[ control_1 ][ control_2 ].push( control_3 );
 +
} else {
 +
inp_obj[ control_1 ][ control_2 ] = control_3; // => "Bob"
 +
}
 +
store.put(inp_obj);
 +
} else {
 +
 +
if ( Array.isArray( inp_obj[ control_1 ] ) ) {
 +
inp_obj[ control_1 ].push( control_2 );
 +
} else {
 +
inp_obj[ control_1 ] = control_2;
 +
}
 +
store.put(inp_obj);
 +
 
 +
}
 +
// +3
 
} else {
 
} else {
inp_obj[ control_1 ] = control_2;
+
store.put(inp_obj);
 +
console.log("mark N");
 +
console.log(inp_obj);
 +
console.log(inp_obj[ control_1 ]);
 +
console.log("mark NN")
 +
inp_obj = inp_obj[ control_1 ];
 
}
 
}
store.put(inp_obj);
+
// +2
 +
} else {
 +
 
 +
//return inp_obj;
    
}
 
}
// +3
+
console.log("return 3")
} else {
+
// return inp_obj;
store.put(inp_obj);
  −
console.log("mark N");
  −
console.log(inp_obj);
  −
console.log(inp_obj[ control_1 ]);
  −
console.log("mark NN")
  −
inp_obj = inp_obj[ control_1 ];
  −
}
  −
// +2
  −
} else {
     −
//return inp_obj;
+
};
 +
console.log("return 2")
 +
resolve( inp_obj );
   −
}
+
};
console.log("return 3")
  −
return inp_obj;
      +
await tx.oncomplete = function() {
 +
console.log("return 1")
 +
db.close();
 +
};
 
};
 
};
console.log("return 2")
+
console.log("return 0")
return inp_obj;
+
});
 
+
}
};
  −
 
  −
tx.oncomplete = function() {
  −
console.log("return 1")
  −
db.close();
  −
return inp_obj;
  −
};
  −
};
  −
console.log("return 0")
  −
return inp_obj;
  −
};
   
};
 
};
530

edits

Navigation menu