Line 1: |
Line 1: |
− | console.log("~"); | + | // License: GPL |
| + | // Experimental Main |
| + | console.log("'⌣'"); |
| | | |
− | var pddb = window.indexedDB.open("pdio", 1); | + | var mwEStruct = { |
| + | wbXntity: 'config.values.wbEntity' |
| + | }, |
| | | |
− | pddb.addEventListener('error', (event) => {
| + | language = "en", |
− | console.log('Request error:', pddb.error);
| |
− | }, false);
| |
| | | |
− | pddb.onupgradeneeded = function() {
| + | WBEStructure = { |
− | var db = pddb.result;
| + | subclassOfRelations: 'claims.P4', // location of P4 relations in wbEntity |
− | var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
| + | defaultValRelation: 'claims.P108', |
− | var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
| + | 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.onsuccess = function() {
| + | Relational_id_list = { |
− | // Start a new transaction
| + | controller_id: [ WBEStructure['instanceOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 96 ], |
− | var db = pddb.result;
| + | personal_data_id: [ WBEStructure['subclassOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 421 ], |
− | var tx = db.transaction("MyObjectStore", "readwrite");
| + | interface_button_id: [ WBEStructure ['instanceOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 487 ] |
− | var store = tx.objectStore("MyObjectStore");
| + | }, |
− | var index = store.index("NameIndex");
| |
| | | |
− | // Add some data
| + | PDWikibaseProcessor, |
− | // var John = {id: 12345, name: {first: "John", last: "Doe"}, age: 42, phone: '+33123456789'};
| + | PDindexedDB, |
− | // var Bob = {id: 67890, name: {first: "Bob", last: "Smith"}, age: 35};
| + | PDOOUI, |
− | // store.put(John);
| + | Current_entity; |
− | // store.put(Bob);
| |
− | var Pete = {id: 11345, name: {first: "Pete", last: "Rock"}, age: 52};
| |
− | store.put(Pete);
| |
− | recordUpdate(["Pete", "Rock"], phoneNumber, '+674316');
| |
− | // Query the data
| |
− | };
| |
− |
| |
− | // Close the db when the transaction is done
| |
− | tx.oncomplete = function() {
| |
− | db.close();
| |
− | };
| |
− | }
| |
| | | |
− | function recordUpdate(record, field, value){
| |
| | | |
− | var getRecord = index.get(record); | + | // JQ.'when' loads the current scripts asynchronously, continues when loading is 'done' |
| + | $.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(){ |
| | | |
− | getRecord.onsuccess = function() {
| + | console.log('Main thread'); |
− | console.log("updating");
| |
− | getRecord.result.field = value; // => "Bob"
| |
− | store.put(getRecord.result);
| |
− | checkrecord(record, field)
| |
− | };
| |
− | }
| |
| | | |
− | function checkRecord(record, field) {
| + | // WBproc reads current mediawiki Entity upon instantiation |
− | checkRecord = index.get(record);
| + | PDWikibaseProcessor = new WikibaseProcessorContainer(mw, mwEStruct['wbXntity']); |
− | checkRecord.onsuccess = function() {
| + | |
− | console.log(getRecordAgain.result.phone); // => "Bob"
| + | // PDxDB takes mediawiki, reads user name from it, creates a hash, and 'checks in' the user upon instantiation |
− | };
| + | // (i.e. read record belonging to user, if it does not exist, create it) |
− | } | + | PDindexedDB = new IndexedDBContainer( mw ); |
| + | |
| + | // Contains classes for creating UI elements, no instantiation consequences |
| + | PDOOUI = new InterfaceMediaContainer( PDWikibaseProcessor, PDindexedDB ); |
| + | |
| + | // 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) |
| + | // - [ 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 |
| + | |
| + | 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 |
| + | } |
| + | } |
| + | }); |
| + | } |
| + | |
| + | }); |