Line 1: |
Line 1: |
| // License: GPL | | // License: GPL |
− |
| |
| console.log('_'); | | console.log('_'); |
| | | |
Line 9: |
Line 8: |
| interface_button_id = 487, | | interface_button_id = 487, |
| | | |
− | language = "en"; | + | language = "en", |
| | | |
− | wbEStruct = { | + | wbEStruct = { |
| subclassOfRelations: 'claims.P4', // location of P4 relations in wbEntity | | subclassOfRelations: 'claims.P4', // location of P4 relations in wbEntity |
| defaultValRelation: 'claims.P108', | | defaultValRelation: 'claims.P108', |
Line 20: |
Line 19: |
| qIDPropName: 'id', | | qIDPropName: 'id', |
| standardValue: 'labels' + '.' + language + '.' + 'value' | | standardValue: 'labels' + '.' + language + '.' + 'value' |
− | },
| + | }, |
− | mwEStruct = {
| + | mwEStruct = { |
− | wbXntity: 'config.values.wbEntity'
| + | wbXntity: 'config.values.wbEntity' |
− | };
| + | }; |
− | | |
| | | |
− | hashCode = function(s) {
| + | hashCode = function(s) { |
− | var h = 0, l = s.length, i = 0;
| + | var h = 0, l = s.length, i = 0; |
− | if ( l > 0 )
| + | if ( l > 0 ) |
− | while (i < l)
| + | while (i < l) |
− | h = (h << 5) - h + s.charCodeAt(i++) | 0;
| + | h = (h << 5) - h + s.charCodeAt(i++) | 0; |
− | return h;
| + | return h; |
| }; | | }; |
| | | |
Line 41: |
Line 39: |
| console.log(idgen); | | console.log(idgen); |
| // Take username for standard databasename format | | // Take username for standard databasename format |
− | var PersonalDataDataBaseName = "PD.IO" + self + "Database"; | + | var PersonalDataDataBaseName = "PD.IO" + idgen + "Database"; |
| // Use username in user to get up to date version of self | | // Use username in user to get up to date version of self |
− | var CurrentPerson = {id: idgen, name: {user: self, first: "", last: ""}, 119: {0: '1337', 1: '2611'}, age: 0}; | + | var CurrentPerson = {id: idgen, name: {user: self}, age: 0}; |
| | | |
− | console.log( CurrentPerson );
| |
− | console.log( PersonalDataDataBaseName );
| |
− | console.log( CurrentPerson );
| |
| recordAdd( PersonalDataDataBaseName, CurrentPerson ); | | recordAdd( PersonalDataDataBaseName, CurrentPerson ); |
− | recordUpdate( PersonalDataDataBaseName, CurrentPerson, "id", idgen );
| + | recordCheck( PersonalDataDataBaseName, CurrentPerson ); |
− | /*
| |
− | recordCheck(PersonalDataDataBaseName, CurrentPerson); | |
− | recordDeleteFrom(PersonalDataDataBaseName, CurrentPerson, )
| |
− | */
| |
| | | |
| // check if we are on a page of any of the targeted Entity | | // check if we are on a page of any of the targeted Entity |
Line 101: |
Line 92: |
| var obj = interjson( get_Y_from_X( mw, mwEStruct['wbXntity'] ) ); // wbEntity as json obj | | var obj = interjson( get_Y_from_X( mw, mwEStruct['wbXntity'] ) ); // wbEntity as json obj |
| var string_temporary_store_1 = get_Y_from_X( obj, wbEStruct['standardValue'] ); // input name | | var string_temporary_store_1 = get_Y_from_X( obj, wbEStruct['standardValue'] ); // input name |
− | var string_temporary_store_2 = get_Y_from_X ( get_Y_from_X ( get_Y_from_X( obj, wbEStruct['defaultValRelation'] ), '0'), wbEStruct['IDPropLoc'] ); //placeholder_text | + | var string_temporary_store_2 = get_Y_from_X ( get_Y_from_X ( get_Y_from_X ( obj, wbEStruct['defaultValRelation'] ), '0'), wbEStruct['IDPropLoc'] ); //placeholder_text |
| var string_temporary_store_3 = get_Y_from_X ( get_Y_from_X ( get_Y_from_X ( get_Y_from_X( obj, wbEStruct['concernsRelation'] ), '0'), wbEStruct['IDPropLoc']), wbEStruct['IDName'] ); //property name | | var string_temporary_store_3 = get_Y_from_X ( get_Y_from_X ( get_Y_from_X ( get_Y_from_X( obj, wbEStruct['concernsRelation'] ), '0'), wbEStruct['IDPropLoc']), wbEStruct['IDName'] ); //property name |
| interface_media( PersonalDataDataBaseName, CurrentPerson, string_temporary_store_1, string_temporary_store_2, string_temporary_store_3 ); | | interface_media( PersonalDataDataBaseName, CurrentPerson, string_temporary_store_1, string_temporary_store_2, string_temporary_store_3 ); |
Line 112: |
Line 103: |
| $( function () { | | $( function () { |
| var person = {}; | | var person = {}; |
− | console.log( "Mark Finite ||");
| |
| person = prs; | | person = prs; |
| if ( recordCheck( db, prs ) != undefined ) { | | if ( recordCheck( db, prs ) != undefined ) { |
Line 243: |
Line 233: |
| } | | } |
| | | |
− | //find second argument in first argument as a boolean | + | // find second argument in first argument as a boolean |
| function check_Y_in_X(obj, to_check){ | | function check_Y_in_X(obj, to_check){ |
| if (obj === to_check) { return true }; | | if (obj === to_check) { return true }; |
Line 263: |
Line 253: |
| return read.split('.').reduce(indexcheck, array); | | return read.split('.').reduce(indexcheck, array); |
| } | | } |
− |
| |
− |
| |
− |
| |
| | | |
| // ADD MORE DOC | | // ADD MORE DOC |
− |
| |
| // Add new record (create pddbname@record) if it does not exist. | | // Add new record (create pddbname@record) if it does not exist. |
| // If it exists, the contents of record are disregarded, and the indexeddb version is returned | | // If it exists, the contents of record are disregarded, and the indexeddb version is returned |
| | | |
− | function recordAdd(pddbname, record){ | + | function recordDelta( pddbname, record, switch, control_1, control_2, control_3 ){ |
| console.log(record); | | console.log(record); |
| var pddb = window.indexedDB.open(pddbname, 3); | | var pddb = window.indexedDB.open(pddbname, 3); |
| pddb.onupgradeneeded = function() { | | pddb.onupgradeneeded = function() { |
− | var db = pddb.result;
| + | var db = pddb.result; |
− | var store = db.createObjectStore(pddbname, {keyPath: "id"});
| + | var store = db.createObjectStore(pddbname, {keyPath: "id"}); |
| | | |
− | // shouldn't the index be the wiki.personaldata.io username? | + | // shouldn't the index be the wiki.personaldata.io username? |
| | | |
| var index = store.createIndex("NameIndex", ["id"]); | | var index = store.createIndex("NameIndex", ["id"]); |
Line 289: |
Line 275: |
| var index = store.index("NameIndex"); | | var index = store.index("NameIndex"); |
| | | |
− | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||[ Essential recordAdd ]|||||||||||||||||||||||||||||| | + | |
| | | |
| // Get the original record from the db... | | // Get the original record from the db... |
| var getRecord = index.get([record.id]); | | var getRecord = index.get([record.id]); |
| + | var inp_obj; |
| getRecord.onsuccess = function() { | | getRecord.onsuccess = function() { |
− | /*
| + | |
− | if (getRecord.result != undefined) { | + | |
− | // if found, let's use that from now on | + | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||[ Essential recordAdd ]|||||||||||||||||||||||||||||| |
− | console.log("updating"); | + | if ( switch === "aggressive push" ) { |
− | inp_obj = getRecord.result;
| + | inp_obj = record; |
− | // let's return it so that our addrecord can be used as a getter as well
| + | store.put( inp_obj ); |
| return inp_obj; | | return inp_obj; |
| } else { | | } else { |
− | */
| + | |
− | // if it didn't exist, let's use the provided record to push to store | + | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||[ Essential recordCheck ]|||||||||||||||||||||||||||||| |
− | inp_obj = record;
| + | |
− | store.put(inp_obj); | + | var getRecord = index.get([record.id]); |
− | return inp_obj; | + | getRecord.onsuccess = function() { |
− |
| + | if (getRecord.result != undefined) { |
| + | |
| + | if ( switch === "get record" ) { |
| + | // if found, let's use that from now on |
| + | console.log("updating"); |
| + | inp_obj = getRecord.result; |
| + | // let's return it so that our addrecord can be used as a getter as well |
| + | return inp_obj; |
| + | } else |
| + | |
| + | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||[ Essential recordUpdate ]|||||||||||||||||||||||||||||| |
| + | Nif ( switch ==== "update record" ) |
| + | if ( typeof control_1 != undefined ) { |
| + | if ( typeof control_2 != undefined ) { |
| + | if ( typeof control_3 != undefined ) { |
| + | inp_obj[ control_1 ][ control_2 ] = control_3; // => "Bob" |
| + | // write new version of record back to database |
| + | 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; |
| + | } |
| + | } |
| + | //// |
| + | // +3 |
| + | } |
| + | // +2 |
| + | } |
| + | // +1 |
| + | } |
| + | // |
| + | } |
| + | // endof onsuccess |
| + | } |
| + | // endof resultdefined |
| + | } else { |
| + | // if it does not exist in store, use the given record |
| + | inp_obj = record; |
| + | } |
| + | // endofELSE |
| + | } |
| + | |
| + | // perform a sanity check if the update was successful, could be used to initiate a retry upon false |
| + | getRecordAgain = index.get([inp_obj.id]); |
| + | getRecordAgain.onsuccess = function() { |
| + | console.log(getRecordAgain); // => "Bob" |
| + | if ( getRecordAgain.result[field] == value ) { |
| + | console.log("Update succeeded"); |
| + | } else { |
| + | console.log("Update unsuccessful"); |
| + | } |
| + | }; |
| + | |
| //} | | //} |
| | | |
Line 315: |
Line 356: |
| } | | } |
| } | | } |
− |
| |
| | | |
| //||||||||||||||||||||||||||||||||||||||||||||| | | //||||||||||||||||||||||||||||||||||||||||||||| |
Line 344: |
Line 384: |
| var index = store.index("NameIndex"); | | var index = store.index("NameIndex"); |
| | | |
− | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||[ Essential recordUpdate ]||||||||||||||||||||||||||||||
| |
− |
| |
− | var inp_obj;
| |
− | var getRecord = index.get([record.id]);
| |
− | // let's try to get the record to be updated from the store
| |
− | getRecord.onsuccess = function() {
| |
− | if( getRecord.result != undefined ) {
| |
− | // if we have it, use that copy to update on
| |
− | console.log("updating");
| |
− | inp_obj = getRecord.result;
| |
− | } else {
| |
− | // if it does not exist in store, use the given record
| |
− | inp_obj = record;
| |
− | }
| |
− | //give the value to the field to update
| |
− | inp_obj[field][cellnumber] = value; // => "Bob"
| |
− | // write new version of record back to database
| |
− | store.put(inp_obj);
| |
− |
| |
− |
| |
− | // perform a sanity check if the update was successful, could be used to initiate a retry upon false
| |
− | getRecordAgain = index.get([inp_obj.id]);
| |
− | getRecordAgain.onsuccess = function() {
| |
− | console.log(getRecordAgain); // => "Bob"
| |
− | if ( getRecordAgain.result[field] == value ) {
| |
− | console.log("Update succeeded");
| |
− | } else {
| |
− | console.log("Update unsuccessful");
| |
− | }
| |
− | };
| |
− | };
| |
− |
| |
− | //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |
| tx.oncomplete = function() { | | tx.oncomplete = function() { |
| db.close(); | | db.close(); |