nl_tokens: var me = UI . authn . currentUser () Function : Render a single trip
pl_tokens: function renderTrip ( subject , thisDiv ) { var query = new $rdf . Query ( UI . utils . label ( subject ) ) var vars = [ 'date' , 'transaction' , 'comment' , 'type' , 'in_USD' ] var v = { } vars . map ( function ( x ) { query . vars . push ( v [ x ] = $rdf . variable ( x ) ) } ) // Only used by UI query . pat . add ( v [ 'transaction' ] , TRIP ( 'trip' ) , subject ) var opt = kb . formula ( ) opt . add ( v [ 'transaction' ] , ns . rdf ( 'type' ) , v [ 'type' ] ) // Issue: this will get stored supertypes too query . pat . optional . push ( opt ) query . pat . add ( v [ 'transaction' ] , UI . <mask> . qu ( 'date' ) , v [ 'date' ] ) opt . add ( v [ 'transaction' ] , ns . rdfs ( 'comment' ) , v [ 'comment' ] ) query . pat . optional . push ( opt ) // opt = kb.formula(); query . pat . add ( v [ 'transaction' ] , UI . ns . qu ( 'in_USD' ) , v [ 'in_USD' ] ) // query.pat.optional.push(opt); var calculations = function ( ) { var total = { } var trans = kb . each ( undefined , TRIP ( 'trip' ) , subject ) // complain("@@ Number of transactions in this trip: " + trans.length); trans . map ( function ( t ) { var ty = kb . the ( t , ns . rdf ( 'type' ) ) // complain(" -- one trans: "+t.uri + ' -> '+kb.any(t, UI.ns.qu('in_USD'))); if ( ! ty ) ty = UI . ns . qu ( 'ErrorNoType' ) if ( ty && ty . uri ) { var tyuri = ty . uri if ( ! total [ tyuri ] ) total [ tyuri ] = 0.0 var lit = kb . any ( t , UI . ns . qu ( 'in_USD' ) ) if ( ! lit ) { complain ( '    @@ No amount in USD: ' + lit + ' for ' + t ) } if ( lit ) { total [ tyuri ] = total [ tyuri ] + parseFloat ( lit . value ) // complain('      Trans type ='+ty+'; in_USD "' + lit //       +'; total[tyuri] = '+total[tyuri]+';') } } } ) var str = '' var types = 0 var grandTotal = 0.0 for ( var uri in total ) { str += UI . utils . label ( kb . sym ( uri ) ) + ': ' + total [ uri ] + '; ' types ++ grandTotal += total [ uri ] } complain ( 'Totals of ' + trans . length + ' transactions: ' + str , '' ) // @@@@@  yucky -- need 2 col table if ( types > 1 ) complain ( 'Overall net: ' + grandTotal , 'text-treatment: bold;' ) } var tableDiv = UI . table ( myDocument , { 'query' : query , 'onDone' : calculations } ) thisDiv . appendChild ( tableDiv ) }