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', '+313851777');
| |
− | recordCheck(PersonalDataDataBaseName, Pete);
| |
| | | |
− | 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");
| |
− | if ( index.get([record.name.last, record.name.first]) != undefined ) {
| |
− | var getRecord = index.get([record.name.last, record.name.first]);
| |
− | getRecord.onsuccess = function() {
| |
− | console.log("updating");
| |
− | inp_obj = getRecord.result;
| |
− | console.log("Mark 2: " + record.name.first);
| |
− | console.log("Mark 2: " + record.name.last + "...");
| |
− | var recordcheck = index.get([inp_obj.name.last, inp_obj.name.first]);
| |
− | recordcheck.onsuccess = function() {
| |
− | console.log(recordcheck);
| |
− | }
| |
− | }
| |
− | }
| |
− | tx.oncomplete = function() {
| |
− | db.close();
| |
− | };
| |
− | };
| |
− | };
| |
| | | |
− | function recordUpdate(pddbname, record, field, value){
| + | // JQ.'when' loads the current scripts asynchronously, continues when loading is 'done' |
− | console.log("pn2");
| + | $.when( |
− | var pddb = window.indexedDB.open(pddbname, 3);
| + | $.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(){ |
| | | |
− | pddb.addEventListener('error', (event) => {
| + | console.log('Main thread'); |
− | console.log('Request error:', pddb.error);
| |
− | }, false);
| |
| | | |
− | pddb.onupgradeneeded = function() {
| + | // WBproc reads current mediawiki Entity upon instantiation |
− | var db = pddb.result;
| + | PDWikibaseProcessor = new WikibaseProcessorContainer(mw, mwEStruct['wbXntity']); |
− | var store = db.createObjectStore(PersonalDataDataBaseName, {keyPath: "id"});
| |
− | var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
| |
− | };
| |
| | | |
− | pddb.onsuccess = function() {
| + | // PDxDB takes mediawiki, reads user name from it, creates a hash, and 'checks in' the user upon instantiation |
− | // Start a new transaction
| + | // (i.e. read record belonging to user, if it does not exist, create it) |
− | var db = pddb.result;
| + | PDindexedDB = new IndexedDBContainer( mw ); |
− | var tx = db.transaction(PersonalDataDataBaseName, "readwrite");
| + | |
− | var store = tx.objectStore(PersonalDataDataBaseName);
| + | // Contains classes for creating UI elements, no instantiation consequences |
− | var index = store.index("NameIndex");
| + | PDOOUI = new InterfaceMediaContainer( PDWikibaseProcessor, PDindexedDB ); |
| | | |
− | var getRecord = index.get([record.name.last, record.name.first]);
| + | // Check if the current entity belongs to any path of interest. |
− | getRecord.onsuccess = function() {
| + | // For each element in object argument, a corresponding element in the return object will contain one of the following: |
− | console.log("updating");
| + | // - undefined - the path didn't exist even partly) |
− | inp_obj = getRecord.result;
| + | // - [ 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 |
− | inp_obj[field] = value; // => "Bob"
| |
− | store.put(inp_obj);
| |
| | | |
− | getRecordAgain = index.get([record.name.last, record.name.first]);
| + | Current_entity = PDWikibaseProcessor.checkentity( Relational_id_list ); |
− | getRecordAgain.onsuccess = function() {
| + | |
− | console.log("Mark 1...");
| + | // Business logicish part. |
− | console.log(getRecordAgain); // => "Bob"
| + | // If any path of interest returned anything... |
− | if ( getRecordAgain.result[field] == value ) {
| + | if ( Current_entity != undefined ) { |
− | console.log("update succeeded");
| + | Object.keys(Current_entity).forEach( function ( entity_checked ){ |
− | } else {
| + | //... for each path that returned something |
− | console.log("update unsuccessful");
| + | 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 |
| + | } |
| + | } |
| + | }); |
| + | } |
| | | |
− | | + | }); |
− | // Close the db when the transaction is done
| |
− | tx.oncomplete = function() {
| |
− | db.close();
| |
− | };
| |
− | };
| |
− | };
| |
− | | |
− | function recordCheck(pddbname, record){
| |
− | console.log("pn1");
| |
− | var pddb = window.indexedDB.open(pddbname, 3);
| |
− | | |
− | pddb.addEventListener('error', (event) => {
| |
− | console.log('Request error:', pddb.error);
| |
− | }, 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() {
| |
− | var db = pddb.result;
| |
− | var tx = db.transaction(PersonalDataDataBaseName, "readwrite");
| |
− | var store = tx.objectStore(PersonalDataDataBaseName);
| |
− | var index = store.index("NameIndex");
| |
− |
| |
− | var recordcheck = index.get([record.name.last, record.name.first]);
| |
− | recordcheck.onsuccess = function() {
| |
− | console.log(recordcheck);
| |
− | console.log("...Mark 0");
| |
− | }
| |
− | | |
− | tx.oncomplete = function() {
| |
− | db.close();
| |
− | };
| |
− | };
| |
− | };
| |