Changes

Jump to navigation Jump to search
m
no edit summary
Line 1: Line 1: −
console.log("~");
+
// License: GPL
 +
// Experimental Main
 +
console.log("'⌣'");
   −
var PersonalDataDataBaseName = "PDIO2";
+
var mwEStruct = {
var Jonathan = {id: 11345, name: {first: "Jonatha", last: "Lemmings"}, age: 32};
+
wbXntity: 'config.values.wbEntity'
 +
},
   −
recordAdd(PersonalDataDataBaseName, Jonathan);
+
language = "en",
recordUpdate(PersonalDataDataBaseName, Jonathan, 'phone', '+313851777');
  −
recordCheck(PersonalDataDataBaseName, Jonathan);
     −
function recordAdd(pddbname, record){
+
WBEStructure = {
  var pddb = window.indexedDB.open(pddbname, 3);
+
subclassOfRelations: 'claims.P4', // location of P4 relations in wbEntity
  pddb.addEventListener('error', (event) => {
+
defaultValRelation: 'claims.P108',
    console.log('Request error:', pddb.error);
+
concernsRelation: 'claims.P110',
  }, false);
+
instanceOfRelations: 'claims.P3',
  pddb.onupgradeneeded = function() {
+
IDPropLoc: 'mainsnak.datavalue.value', // location of ID properties in related entity
    var db = pddb.result;
+
IDName: 'numeric-id', // ID property name which checked
    var store = db.createObjectStore(PersonalDataDataBaseName, {keyPath: "id"});
+
qIDPropName: 'id',
    var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
+
standardValue: 'labels' + '.' + language + '.' + 'value'
  };
+
},
  pddb.onsuccess = function() {
  −
    var db = pddb.result;
  −
    var tx = db.transaction(PersonalDataDataBaseName, "readwrite");
  −
    var store = tx.objectStore(PersonalDataDataBaseName);
  −
    var index = store.index("NameIndex"); 
  −
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||[  Essential recordAdd  ]||||||||||||||||||||||||||||||
  −
    var getRecord = index.get([record.name.last, record.name.first]);
  −
    getRecord.onsuccess = function() {
  −
        if (getRecord.result != undefined) {
  −
            console.log("updating");
  −
            inp_obj = getRecord.result;
  −
        } else {
  −
          inp_obj = record;
  −
          store.put(inp_obj);
  −
        }
  −
        var sanitycheck = index.get([inp_obj.name.last, inp_obj.name.first]);
  −
        sanitycheck.onsuccess = function() {
  −
            console.log(sanitycheck);
  −
        }
  −
    }
  −
    //|||||||||||||||||||||||||||||||||||||||||||||
  −
    tx.oncomplete = function() {
  −
      db.close();
  −
    }; 
  −
  };
  −
};
     −
function recordUpdate(pddbname, record, field, value){
+
Relational_id_list = {  
  var pddb = window.indexedDB.open(pddbname, 3);
+
controller_id: [ WBEStructure['instanceOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 96 ],
  pddb.addEventListener('error', (event) => {
+
personal_data_id: [ WBEStructure['subclassOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 421 ],
    console.log('Request error:', pddb.error);
+
interface_button_id: [ WBEStructure ['instanceOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 487 ]
  }, false);
+
},
  pddb.onupgradeneeded = function() {
  −
    var db = pddb.result;
  −
    var store = db.createObjectStore(PersonalDataDataBaseName, {keyPath: "id"});
  −
    var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
  −
  };
  −
  pddb.onsuccess = function() {
  −
        // Start a new transaction
  −
        var db = pddb.result;
  −
        var tx = db.transaction(PersonalDataDataBaseName, "readwrite");
  −
        var store = tx.objectStore(PersonalDataDataBaseName);
  −
        var index = store.index("NameIndex");
  −
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||[ Essential recordUpdate  ]||||||||||||||||||||||||||||||
  −
        var inp_obj;
  −
        var getRecord = index.get([record.name.last, record.name.first]);
  −
        getRecord.onsuccess = function() {
  −
            if( getRecord.result != undefined ) {
  −
              console.log("updating");
  −
              inp_obj = getRecord.result;
  −
            } else {
  −
              inp_obj = record;
  −
            }
     −
            inp_obj[field] = value;  // => "Bob"
+
PDWikibaseProcessor,
            store.put(inp_obj);
+
PDindexedDB,
 +
PDOOUI,
 +
Current_entity;
   −
            getRecordAgain = index.get([record.name.last, record.name.first]);
  −
            getRecordAgain.onsuccess = function() {
  −
                console.log(getRecordAgain);  // => "Bob"
  −
                if ( getRecordAgain.result[field] == value ) {
  −
                  console.log("Update succeeded");
  −
                } else {
  −
                  console.log("Update unsuccessful");
  −
                }
  −
              }; 
  −
            };
  −
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  −
      tx.oncomplete = function() {
  −
        db.close();
  −
      };
  −
    };
  −
  };
     −
function recordCheck(pddbname, record){
+
// JQ.'when' loads the current scripts asynchronously, continues when loading is 'done'
  var pddb = window.indexedDB.open(pddbname, 3);
+
$.when(
  pddb.addEventListener('error', (event) => {
+
    $.getScript( "//wiki.personaldata.io/w/index.php?title=User:Abel/WbProcessor.js&action=raw&ctype=text/javascript" ),
    console.log('Request error:', pddb.error);
+
    $.getScript( "//wiki.personaldata.io/w/index.php?title=User:Abel/PersonalData.js&action=raw&ctype=text/javascript" ),
  }, false);
+
    $.getScript( "//wiki.personaldata.io/w/index.php?title=User:Abel/OOInterface.js&action=raw&ctype=text/javascript" ),
  pddb.onupgradeneeded = function() {
+
    $.Deferred( function( deferred ){
    var db = pddb.result;
+
        $( deferred.resolve );
    var store = db.createObjectStore(PersonalDataDataBaseName, {keyPath: "id"});
+
    })
    var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
+
).done( function(){
  };
+
 
  pddb.onsuccess = function() {
+
console.log('Main thread');
    var db = pddb.result;
+
 
    var tx = db.transaction(PersonalDataDataBaseName, "readwrite");
+
// WBproc reads current mediawiki Entity upon instantiation
    var store = tx.objectStore(PersonalDataDataBaseName);
+
PDWikibaseProcessor = new WikibaseProcessorContainer(mw, mwEStruct['wbXntity']);
    var index = store.index("NameIndex")
+
 
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||[ Essential recordCheck ]||||||||||||||
+
// PDxDB takes mediawiki, reads user name from it, creates a hash, and 'checks in' the user upon instantiation
    var recordcheck = index.get([record.name.last, record.name.first]);
+
// (i.e. read record belonging to user, if it does not exist, create it)
    recordcheck.onsuccess = function() {
+
PDindexedDB = new IndexedDBContainer( mw );
      if ( recordcheck.result != undefined ) {
+
        console.log(recordcheck);
+
// Contains classes for creating UI elements, no instantiation consequences
      } else {
+
PDOOUI = new InterfaceMediaContainer( PDWikibaseProcessor, PDindexedDB );
        console.log("...else undefined");
+
 
      }
+
// Check if the current entity belongs to any path of interest.  
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+
// For each element in object argument, a corresponding element in the return object will contain one of the following:
    }
+
// - undefined - the path didn't exist even partly)
    tx.oncomplete = function() {
+
// - [ value or object ] - if the path existed fully, it returns what is at the end of the path. If last element in path is a value, it will return the value if found
      db.close();
+
 
    }
+
Current_entity = PDWikibaseProcessor.checkentity( Relational_id_list );
  };
+
};
+
// Business logicish part.
 +
// If any path of interest returned anything...
 +
if ( Current_entity != undefined ) {
 +
Object.keys(Current_entity).forEach( function ( entity_checked ){
 +
//... for each path that returned something
 +
if ( Current_entity[entity_checked] != undefined ){
 +
if ( Object.keys( Current_entity[entity_checked] ).length > 0 ) {
 +
PDOOUI.renderInterface( entity_checked );
 +
//... call the OOUI renderer to render what belongs to this input
 +
}
 +
}
 +
});
 +
}
 +
 
 +
});
530

edits

Navigation menu