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 Pete = {id: 11345, name: {first: "Pete", last: "Rock"}, age: 52};
+
wbXntity: 'config.values.wbEntity'
 +
},
   −
addRecord(PersonalDataDataBaseName, Pete);
+
language = "en",
recordUpdate(PersonalDataDataBaseName, Pete, 'phone', '+313855777');
     −
function addRecord(pddbname, record){
+
WBEStructure = {
  console.log("pn1");
+
subclassOfRelations: 'claims.P4', // location of P4 relations in wbEntity
  var pddb = window.indexedDB.open(pddbname, 3);
+
defaultValRelation: 'claims.P108',
 +
concernsRelation: 'claims.P110',
 +
instanceOfRelations: 'claims.P3',
 +
IDPropLoc: 'mainsnak.datavalue.value', // location of ID properties in related entity
 +
IDName: 'numeric-id', // ID property name which checked
 +
qIDPropName: 'id',
 +
standardValue: 'labels' + '.' + language + '.' + 'value'
 +
},
   −
  pddb.addEventListener('error', (event) => {
+
Relational_id_list = {
    console.log('Request error:', pddb.error);
+
controller_id: [ WBEStructure['instanceOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 96 ],
  }, false);
+
personal_data_id: [ WBEStructure['subclassOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 421 ],
 +
interface_button_id: [ WBEStructure ['instanceOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 487 ]
 +
},
   −
  pddb.onupgradeneeded = function() {
+
PDWikibaseProcessor,
    var db = pddb.result;
+
PDindexedDB,
    var store = db.createObjectStore(PersonalDataDataBaseName, {keyPath: "id"});
+
PDOOUI,
    var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
+
Current_entity;
  };
     −
  pddb.onsuccess = function() {
  −
    var db = pddb.result;
  −
    var tx = db.transaction(PersonalDataDataBaseName, "readwrite");
  −
    var store = tx.objectStore(PersonalDataDataBaseName);
  −
    var index = store.index("NameIndex"); 
  −
 
  −
    store.put(record);
     −
     console.log("Mark 1: " + record.name.first);
+
// JQ.'when' loads the current scripts asynchronously, continues when loading is 'done'
     console.log("Mark 1: " + record.name.last);
+
$.when(
 +
     $.getScript( "//wiki.personaldata.io/w/index.php?title=User:Abel/WbProcessor.js&action=raw&ctype=text/javascript" ),
 +
    $.getScript( "//wiki.personaldata.io/w/index.php?title=User:Abel/PersonalData.js&action=raw&ctype=text/javascript" ),
 +
     $.getScript( "//wiki.personaldata.io/w/index.php?title=User:Abel/OOInterface.js&action=raw&ctype=text/javascript" ),
 +
    $.Deferred( function( deferred ){
 +
        $( deferred.resolve );
 +
    })
 +
).done( function(){
   −
    var recordcheck = index.get([record.name.last, record.name.first]);
+
console.log('Main thread');
    recordcheck.onsuccess = function() {
  −
      console.log(recordcheck);
  −
      console.log("Mark 1.1: " + recordcheck.result.phone);
  −
    }
     −
    tx.oncomplete = function() {
+
// WBproc reads current mediawiki Entity upon instantiation
      db.close();
+
PDWikibaseProcessor = new WikibaseProcessorContainer(mw, mwEStruct['wbXntity']);
    }; 
  −
  };
  −
};
     −
function recordUpdate(pddbname, record, field, value){
+
// PDxDB takes mediawiki, reads user name from it, creates a hash, and 'checks in' the user upon instantiation
  console.log("pn2");
+
// (i.e. read record belonging to user, if it does not exist, create it)
  var pddb = window.indexedDB.open(pddbname, 3);
+
PDindexedDB = new IndexedDBContainer( mw );
 +
 +
// Contains classes for creating UI elements, no instantiation consequences
 +
PDOOUI = new InterfaceMediaContainer( PDWikibaseProcessor, PDindexedDB );
   −
  pddb.addEventListener('error', (event) => {
+
// Check if the current entity belongs to any path of interest.  
    console.log('Request error:', pddb.error);
+
// For each element in object argument, a corresponding element in the return object will contain one of the following:
  }, false);
+
// - undefined - the path didn't exist even partly)
 +
// - [ 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
   −
  pddb.onupgradeneeded = function() {
+
Current_entity = PDWikibaseProcessor.checkentity( Relational_id_list );
    var db = pddb.result;
+
    var store = db.createObjectStore(PersonalDataDataBaseName, {keyPath: "id"});
+
// Business logicish part.
    var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
+
// 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
 +
}
 +
}
 +
});
 +
}
   −
  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");
  −
 
  −
        var getRecord = index.get([record.name.last, record.name.first]);
  −
        getRecord.onsuccess = function() {
  −
          console.log("updating");
  −
            dive(getRecord.result, field) = value;  // => "Bob"
  −
            store.put(getRecord.result);
  −
 
  −
            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");
  −
                }
  −
              }; 
  −
            };
  −
 
  −
 
  −
      // Close the db when the transaction is done
  −
      tx.oncomplete = function() {
  −
        db.close();
  −
      };
  −
    };
  −
  };
  −
 
  −
function indexinterpolate(obj,i) { return  (obj[i] != undefined) ? obj[i] : obj};
  −
 
  −
// helper function for checking a part of an array exists
  −
function indexcheck(obj,i) {  return  (obj[i] != undefined) ? obj[i] : undefined };
  −
 
  −
// dive selects matrix.a.b.c.d from the array called matrix and 'a.b.c.d' as string
  −
// if a.b.c.d does not exists, it returns the substructure until the substructure exists, if d does not exist, it returns matrix.a.b.c e.g.
  −
 
  −
function dive(array, read){
  −
return read.split('.').reduce(indexinterpolate, array);
  −
}
  −
 
  −
function check(array, read){
  −
return read.split('.').reduce(indexcheck, array);
  −
}
 
530

edits

Navigation menu