Line 2: |
Line 2: |
| // Experimental Main | | // Experimental Main |
| console.log("'⌣'"); | | console.log("'⌣'"); |
| + | |
| var mwEStruct = { | | var mwEStruct = { |
| wbXntity: 'config.values.wbEntity' | | wbXntity: 'config.values.wbEntity' |
Line 8: |
Line 9: |
| language = "en", | | language = "en", |
| | | |
− | wbEStruct = { | + | WBEStructure = { |
| 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 19: |
Line 20: |
| }, | | }, |
| | | |
− | relational_id_list = { | + | Relational_id_list = { |
− | controller_id: [ wbEStruct['instanceOfRelations'], wbEStruct['IDPropLoc'], wbEStruct['IDName'], 96 ], | + | controller_id: [ WBEStructure['instanceOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 96 ], |
− | personal_data_id: [ wbEStruct['subclassOfRelations'], wbEStruct['IDPropLoc'], wbEStruct['IDName'], 421 ], | + | personal_data_id: [ WBEStructure['subclassOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 421 ], |
− | interface_button_id: [ wbEStruct ['instanceOfRelations'], wbEStruct['IDPropLoc'], wbEStruct['IDName'], 487 ] | + | interface_button_id: [ WBEStructure ['instanceOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 487 ] |
− | }; | + | }, |
− | | |
− | var wbproc = new wbContainer(mw, mwEStruct['wbXntity']);
| |
− | | |
− | // Check whether the current page is in a relation of interest to an id of interest
| |
− | var current_entity = wbproc.checkentity( relational_id_list );
| |
− | // This should return an object of relations and ids
| |
− | | |
− | console.log(current_entity);
| |
− | | |
− | // for each match, render the corresponding ui elements
| |
− | // current_entity.forEach(pdooui.render);
| |
− | | |
− | // License: GPL
| |
− | // Wikibase Processor
| |
− | | |
− | function wbContainer( universe, location ) {
| |
− | | |
− | this.main = interjson( checkdive( universe, location ));
| |
− | var the = this.main;
| |
− |
| |
− | this.checkentity = function ( paths ) {
| |
− | return proceed( the, paths );
| |
− | }
| |
− | | |
− | // the list of private helper functions, could not be accessed from outside
| |
− | 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) { if ( obj !== undefined) { 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){
| |
− | if ( array !== undefined ) {
| |
− | return (read + '').split('.').reduce(indexinterpolate, array);
| |
− | }
| |
− | }
| |
− | function check(array, read){
| |
− | if ( array !== undefined ) {
| |
− | return (read + '').split('.').reduce(indexcheck, array);
| |
− | }
| |
− | }
| |
− | function proceed(array, read) {
| |
− | var ret_obj = {},
| |
− | temp_obj = array,
| |
− | // Have a holder for instructional control return array
| |
− | future_instructional_return = [];
| |
− |
| |
− | //|||||||||||||||||||||||||||||||||||||||||||||||||||||[ I N S T R U C T I O N S C O N T R O L ]||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |
− | | |
− | // Init program, check if instructions are an object :
| |
− | if ( ( !Array.isArray(read) ) && ( Object.keys(read).length > 0 ) ) {
| |
− | | |
− |
| |
− | Object.keys(read).forEach( function(path) {
| |
− | console.log("instructions are an object, in path " + path);
| |
− | | |
− | //||||||||||||||||||||||||||[ Check if elements of instruction object are arrays themselves ]||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |
− |
| |
− | if ( Array.isArray (read[path]) ) {
| |
− | var future_return_partition = temp_obj;
| |
− | Object.keys(read[path]).forEach( function( path2 ) {
| |
− | | |
− | console.log("instructions are an array of arrays, going through " + read[ path ][ path2 ] );
| |
− | future_return_partition = data_function( future_return_partition, read[ path ][ path2 ] );
| |
− | | |
− | //|||||||||||||||||||||||||||||||||||||||||||||||||||[ I N S T R U C T I O N S C O N T R O L ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |
− | | |
− | });
| |
− | // Put the result of the travel along the paths in array element of array into the future_instructional_return bunch
| |
− | console.log("arrived at")
| |
− | console.log(future_return_partition);
| |
− | future_instructional_return.push(future_return_partition);
| |
− | | |
− | }
| |
− | | |
− | //|||||||||||||||||| If instruction object element is not an array anymore, lets just do one step ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |
− | | |
− | else {
| |
− |
| |
− | // INCLUDE step block with read[path]
| |
− | future_instructional_return.push( data_function( temp_obj, read[ path ] ) );
| |
− | | |
− | }
| |
− | });
| |
| | | |
− | temp_obj = future_instructional_return;
| + | PDWikibaseProcessor, |
− | }
| + | PDindexedDB, |
| + | PDOOUI, |
| + | Current_entity; |
| | | |
− | //||||||||||||[ If we are not in instruction object, let's see if we have an instruction array ]|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |
| | | |
− | else if ( Array.isArray(read) ) {
| + | // JQ.'when' loads the current scripts asynchronously, continues when loading is 'done' |
− | // If so let's follow the array of instructions
| + | $.when( |
− | Object.keys( read ).forEach( function ( ect ) {
| + | $.getScript( "//wiki.personaldata.io/w/index.php?title=User:Abel/WbProcessor.js&action=raw&ctype=text/javascript" ), |
− | temp_obj = data_function( temp_obj, read[ ect ] );
| + | $.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(){ |
| | | |
− | //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + | console.log('Main thread'); |
| | | |
− | else {
| + | // WBproc reads current mediawiki Entity upon instantiation |
− | temp_obj = data_function( temp_obj, read );
| + | PDWikibaseProcessor = new WikibaseProcessorContainer(mw, mwEStruct['wbXntity']); |
− | }
| |
| | | |
− | return temp_obj;
| + | // 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 ); |
| | | |
− | //|||||||||||||||||||||||||||||||||||||||||||||||||||||[ S T E P B L O C K ]||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | + | // 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 |
| | | |
− | function data_function ( temp_obj, moving ) {
| + | Current_entity = PDWikibaseProcessor.checkentity( Relational_id_list ); |
− | var future_temp_obj = [];
| + | |
− | if ( Array.isArray( temp_obj ) ) {
| + | // Business logicish part. |
− | console.log("data is on an array level");
| + | // If any path of interest returned anything... |
− | Object.keys( temp_obj ).forEach( function ( ect ) {
| + | if ( Current_entity != undefined ) { |
− | // if we are on an array level in the data, lets iterate through the array
| + | Object.keys(Current_entity).forEach( function ( entity_checked ){ |
− | console.log("Within partition: " + ect );
| + | //... for each path that returned something |
− | future_temp_obj.push( checkdive( temp_obj[ ect ], moving ) );
| + | if ( Current_entity[entity_checked] != undefined ){ |
− | | + | if ( Object.keys( Current_entity[entity_checked] ).length > 0 ) { |
− | });
| + | PDOOUI.renderInterface( entity_checked ); |
− | temp_obj = future_temp_obj;
| + | //... call the OOUI renderer to render what belongs to this input |
− |
| |
− | } else { | |
− | // if we are not on an array level, proceed with the path
| |
− | console.log("data is on an objective level");
| |
− | future_temp_obj = checkdive( temp_obj, moving );
| |
− | if ( future_temp_obj !== undefined ){
| |
− | temp_obj = future_temp_obj;
| |
− | } else { | |
− | Object.keys( temp_obj ).forEach( function ( piece ) {
| |
− | if ( temp_obj[ piece ] === moving ) { return moving };
| |
− | }); | |
− | if ( temp_obj === moving ) { return moving };
| |
| } | | } |
− |
| |
| } | | } |
| + | }); |
| + | } |
| | | |
− | return temp_obj;
| + | }); |
− | }
| |
− |
| |
− | //|||||||||||||||||||||||||||||||||||||||||||||||||||||[ E N D O F S T E P B L O C K ]|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |
− | | |
− | function checkdive( array, read){
| |
− | if ( check(array, read) !== undefined) {
| |
− | return dive(array, read);
| |
− | } else if ( Array.isArray(array) ) {
| |
− | var potential_return = [];
| |
− | Object.keys(array).forEach( function(item){
| |
− | if ( check(array[item], read) !== undefined ) {
| |
− | potential_return.push( dive( array[item], read) );
| |
− | }
| |
− | });
| |
− | return potential_return;
| |
− | }
| |
− | if ( array == read || )
| |
− | }
| |
− | | |
− | function interjson( obj ) {
| |
− | try {
| |
− | return JSON.parse( obj )
| |
− | } catch (e) {
| |
− | // if not JSON, do silly things
| |
− | console.log('not a json ¯\_(ツ)_/¯');
| |
− | };
| |
− | }
| |
− |
| |
− | }
| |