/* istanbul ignore file */ // Original author: kennyluck // // Kenny's Notes: /* places to generate SPARQL update: clearInputAndSave() pasteFromClipboard()->insertTermTo(); undetermined statement generated formUndetStat() ->fillInRequest() ontological issues temporarily using the tabont namespace clipboard: 'predicates' 'objects' 'all'(internal) request: 'from' 'to' 'message' 'Request' */ const UI = require('solid-ui') const $rdf = UI.rdf const panes = require('pane-registry') let UserInputFormula // Formula to store references of user's work let TempFormula // Formula to store incomplete triples (Requests), // temporarily disjoint with kb to avoid bugs module.exports = function UserInput (outline) { const kb = UI.store const myDocument = outline.document // is this ok? // UI.log.warn("myDocument when it's set is "+myDocument.location); this.menuId = 'predicateMenu1' /* //namespace information, as a subgraph of the knowledge base, is built in showMenu this.namespaces={}; for (var name in UI.ns) { this.namespaces[name] = UI.ns[name]('').uri; } var NameSpaces=this.namespaces; */ // hq, print and trim functions const qp = function qp (str) { console.log(str + '\n') } // var tabont = UI.ns.tabont; // var foaf = UI.ns.foaf const rdf = UI.ns.rdf // var RDFS = UI.ns.rdfs // var OWL = UI.ns.owl // var dc = UI.ns.dc // var rss = UI.ns.rss // var contact = UI.ns.contact // var mo = UI.ns.mo const bibo = UI.rdf.Namespace('http://purl.org/ontology/bibo/') // hql for pubsPane // var dcterms = UI.rdf.Namespace('http://purl.org/dc/terms/') const dcelems = UI.rdf.Namespace('http://purl.org/dc/elements/1.1/') let movedArrow = false // hq // var updateService=new updateCenter(kb); if (!UserInputFormula) { UserInputFormula = new UI.rdf.Formula() UserInputFormula.superFormula = kb // UserInputFormula.registerFormula("Your Work"); } if (!TempFormula) TempFormula = new UI.rdf.IndexedFormula() // Use RDFIndexedFormula so add returns the statement TempFormula.name = 'TempFormula' if (!UI.store.updater) UI.store.updater = new UI.rdf.UpdateManager(kb) return { // updateService: updateService, sparqler: UI.store.updater, lastModified: null, // the last being modified, .isNew indicates whether it's a new input lastModifiedStat: null, // the last statement being modified statIsInverse: false, // whether the statement is an inverse /** * Triggering Events: event entry points, should be called only from outline.js but not anywhere else * in userinput.js, should be as short as possible, function names to be discussed */ // Called when the blue cross under the default pane is clicked. // Add a new row to a property list ( P and O) addNewPredicateObject: function addNewPredicateObject (e) { if (UI.utils.getTarget(e).className !== 'bottom-border-active') return const This = outline.UserInput const target = UI.utils.getTarget(e) // UI.log.warn(ancestor(target,'TABLE').textContent); const insertTr = myDocument.createElement('tr') UI.utils .ancestor(target, 'DIV') .insertBefore(insertTr, UI.utils.ancestor(target, 'TR')) const tempTr = myDocument.createElement('tr') const reqTerm1 = This.generateRequest('(TBD)', tempTr, true) insertTr.appendChild(tempTr.firstChild) const reqTerm2 = This.generateRequest( '(Enter text or drag an object onto this field)', tempTr, false ) insertTr.appendChild(tempTr.firstChild) // there should be an elegant way of doing this // Take the why of the last TR and write to it. if ( UI.utils.ancestor(target, 'TR').previousSibling && // there is a previous predicate/object line UI.utils.ancestor(target, 'TR').previousSibling.AJAR_statement ) { const preStat = UI.utils.ancestor(target, 'TR').previousSibling .AJAR_statement // This should always(?) input a non-inverse statement This.formUndetStat( insertTr, preStat.subject, reqTerm1, reqTerm2, preStat.why, false ) } else { // no previous row: write to the document defining the subject const subject = UI.utils.getAbout( kb, UI.utils.ancestor(target.parentNode.parentNode, 'TD') ) const doc = kb.sym(UI.rdf.Util.uri.docpart(subject.uri)) This.formUndetStat(insertTr, subject, reqTerm1, reqTerm2, doc, false) } outline.walk('moveTo', insertTr.firstChild) UI.log.info( 'addNewPredicateObject: selection = ' + outline .getSelection() .map(function (item) { return item.textContent }) .join(', ') ) this.startFillInText(outline.getSelection()[0]) }, // Called when a blue cross on a predicate is clicked // tr.AJAR_inverse stores whether the clicked predicate is an inverse one // tr.AJAR_statement (an incomplete statement in TempFormula) stores the destination(why), now // determined by the preceding one (is this good?) addNewObject: function addNewObject (e) { const predicateTd = UI.utils.getTarget(e).parentNode.parentNode // var predicateTerm = UI.utils.getAbout(kb, predicateTd) const isInverse = predicateTd.parentNode.AJAR_inverse // var titleTerm=UI.utils.getAbout(kb,UI.utils.ancestor(predicateTd.parentNode,'TD')); // set pseudo lastModifiedStat here this.lastModifiedStat = predicateTd.parentNode.AJAR_statement const insertTr = this.appendToPredicate(predicateTd) const reqTerm = this.generateRequest(' (Error) ', insertTr, false) const preStat = insertTr.previousSibling.AJAR_statement if (!isInverse) { this.formUndetStat( insertTr, preStat.subject, preStat.predicate, reqTerm, preStat.why, false ) } else { this.formUndetStat( insertTr, reqTerm, preStat.predicate, preStat.object, preStat.why, true ) } outline.walk('moveTo', insertTr.lastChild) this.startFillInText(insertTr.lastChild) // this.statIsInverse=false; }, // Called when delete is pressed Delete: function Delete (selectedTd) { this.deleteTriple(selectedTd, false) }, // Called when enter is pressed Enter: function Enter (selectedTd) { this.literalModification(selectedTd) }, // Called when a selected cell is clicked again Click: function Click (e) { const target = UI.utils.getTarget(e) if (UI.utils.getTerm(target).termType !== 'Literal') return this.literalModification(target) // this prevents the generated inputbox to be clicked again e.preventDefault() e.stopPropagation() }, // Called when paste is called (Ctrl+v) pasteFromClipboard: function pasteFromClipboard (address, selectedTd) { function termFrom (fromCode) { const term = outline.clipboard[fromCode].shift() if (term === null) { UI.log.warn('no more element in clipboard!') return } switch (fromCode) { case 'predicates': case 'objects': { const allArray = outline.clipboard.all for (let i = 0; true; i++) { if (term.sameTerm(allArray[i])) { allArray.splice(i, 1) break } } break } case 'all': throw new Error( 'hostorical code not understood - what is theCollection?' ) /* var isObject = term.sameTerm(theCollection('objects').elements[0]) isObject ? outline.clipboard.objecs.shift() : outline.clipboard.predicates.shift() // drop the corresponding term return [term, isObject] break */ } return term } let term switch (selectedTd.className) { case 'undetermined selected': term = selectedTd.nextSibling ? termFrom('predicates') : termFrom('objects') if (!term) return break case 'pred selected': // paste objects into this predicate term = termFrom('objects') if (!term) return break case 'selected': { // header , undetermined generated const returnArray = termFrom('all') if (!returnArray) return term = returnArray[0] this.insertTermTo(selectedTd, term, returnArray[1]) return } } this.insertTermTo(selectedTd, term) }, /** * Intermediate Processing: */ // a general entry point for any event except Click&Enter(goes to literalModification) // do a little inference to pick the right input box startFillInText: function startFillInText (selectedTd) { switch (this.whatSortOfEditCell(selectedTd)) { case 'DatatypeProperty-like': // this.clearMenu(); // selectedTd.className=''; UI.utils.emptyNode(selectedTd) this.lastModified = this.createInputBoxIn( selectedTd, ' (Please Input) ' ) this.lastModified.isNew = false this.lastModified.select() break case 'predicate': // the goal is to bring back all the menus (with autocomplete functionality // this.performAutoCompleteEdit(selectedTd,['PredicateAutoComplete', // this.choiceQuery('SuggestPredicateByDomain')]); this.performAutoCompleteEdit(selectedTd, 'PredicateAutoComplete') break case 'ObjectProperty-like': case 'no-idea': // menu should be either function that this.performAutoCompleteEdit(selectedTd, 'GeneralAutoComplete') /* // emptyNode(selectedTd); this.lastModified=this.createInputBoxIn(selectedTd,""); this.lastModified.select(); this.lastModified.addEventListener('keypress',this.AutoComplete,false); //this pops up the autocomplete menu this.AutoComplete(1); // */ } }, literalModification: function literalModification (selectedTd) { UI.log.debug( 'entering literal Modification with ' + selectedTd + selectedTd.textContent ) // var This=outline.UserInput; if (selectedTd.className.indexOf(' pendingedit') !== -1) { UI.log.warn( 'The node you attempted to edit has a request still pending.\n' + 'Please wait for the request to finish (the text will turn black)\n' + 'before editing this node again.' ) return true } const target = selectedTd const about = this.getStatementAbout(target) // timbl - to avoid alert from random clicks if (!about) return let obj let trNode try { obj = UI.utils.getTerm(target) trNode = UI.utils.ancestor(target, 'TR') } catch (e) { UI.log.warn('userinput.js: ' + e + UI.utils.getAbout(kb, selectedTd)) UI.log.error(target + ' getStatement Error:' + e) } let tdNode try { tdNode = trNode.lastChild } catch (e) { UI.log.error(e + '@' + target) } // seems to be a event handling problem of firefox3 /* if (e.type!='keypress'&&(selectedTd.className=='undetermined selected'||selectedTd.className=='undetermined')){ this.Refill(e,selectedTd); return; } */ // ignore clicking trNode.firstChild (be careful for
or ) // if (e.type!='keypress'&&target!=tdNode && UI.utils.ancestor(target,'TD')!=tdNode) return; if (obj.termType === 'Literal') { tdNode.removeChild(tdNode.firstChild) // remove the text if (obj.value.match('\n')) { // match a line feed and require