Example #1
0
  /*
    Create a new session (from the old one or new)

    @param {Object} session session object
    @returns {Promise}
  */
  createSession(session) {
    // map userId to session owner
    if(session.userId) session.owner = session.userId

    let newSession = {
      session_token: uuid(),
      created: new Date(),
      owner: session.owner
    }

    return new Promise(function(resolve, reject) {
      this.db.sessions.insert(newSession, function(err, session) {
        if (err) {
          reject(new Err('SessionStore.CreateError', {
            cause: err
          }))
        }
        // map session owner to userId,
        // session_token to sessionToken
        session.userId = session.owner
        session.sessionToken = session.session_token

        resolve(session)
      })
    }.bind(this))
  }
Example #2
0
 import (el, node, importer) {
   const doc = importer.state.doc
   const $$ = (type, props = {}) => doc.create(Object.assign(props, { type }))
   let rows = el.findAll('tr')
   let newRows = rows.map(tr => {
     return {
       id: tr.id,
       children: []
     }
   })
   // ATTENTION: this code is not 'idiomatic' as it does not delegate to converters for children elements
   // and instead creates document nodes on the fly
   for (let i = 0; i < rows.length; i++) {
     let tr = rows[i]
     let newRow = newRows[i]
     let children = tr.getChildren()
     for (let j = 0, k = 0; j < children.length; j++, k++) {
       // skipping spanned cells which is necessary
       // because HTML tables have a sparse representation w.r.t. span
       while (newRow.children[k]) k++
       let c = children[j]
       let attributes = {}
       if (c.is('th')) attributes.heading = true
       let rowspan = c.attr('rowspan')
       if (rowspan) {
         rowspan = Math.max(1, parseInt(rowspan, 10))
         if (rowspan > 1) {
           attributes.rowspan = rowspan
         }
       }
       let colspan = c.attr('colspan')
       if (colspan) {
         colspan = Math.max(1, parseInt(colspan, 10))
         if (colspan > 1) {
           attributes.colspan = colspan
         }
       }
       // flag all spanned cells so that we can skip them
       _fillSpanned($$, newRows, i, k, rowspan, colspan)
       const cellId = c.id || uuid()
       let cell = $$('table-cell', {
         id: cellId,
         heading: attributes['heading'],
         rowspan: attributes['rowspan'],
         colspan: attributes['colspan'],
         content: importer.annotatedText(c, [cellId, 'content'])
       })
       newRows[i].children[k] = cell
     }
   }
   node.rows = newRows.map(data => {
     let row = $$('table-row', {
       id: data.id,
       cells: data.children.map(cell => cell.id)
     })
     return row.id
   })
 }
 constructor(editorSession) {
   this.editorSession = editorSession
   this.doc = editorSession.getDocument()
   // Note: this id is used internally to
   // lookup variables and cells
   if (!this.doc.UUID) {
     this.doc.UUID = uuid()
   }
   // set by Engine
   this.engine = null
 }
      doc.transaction(function(tx) {
        var newWaypoint = tx.create({
          id: Substance.uuid("waypoint"),
          type: "waypoint",
          density: 1,
          entityId: entityId
        });

        waypointIds.push(newWaypoint.id);
        tx.set(["document", "interviewee_waypoints"], waypointIds);
      });
Example #5
0
  /*
    Create a new reference entry

    @param {Object} data JSON object
    @returns {Promise}
  */
  createReference(data) {
    // Generate a doc_id if not provided
    if (!data.reference_id) {
      data.reference_id = uuid()
    }

    return this.referenceExists(data.reference_id).bind(this)
      .then(function(exists) {
        if (exists) {
          throw new Err('ReferenceStore.CreateError', {
            message: 'Reference ' + data.reference_id + ' already exists.'
          })
        }

        return this._createReference(data)
      }.bind(this))
  }
Example #6
0
  /*
    Create a new rule

    @param {Object} ruleData JSON object
    @returns {Promise}
  */
  createRule(ruleData) {
    // Generate an rule_id if not provided
    if (!ruleData.rule_id) {
      ruleData.rule_id = uuid()
    }

    return this.ruleExists(ruleData.rule_id).bind(this)
      .then(function(exists) {
        if (exists) {
          throw new Err('RuleStore.CreateError', {
            message: 'Rule ' + ruleData.rule_id + ' already exists.'
          })
        }

        return this._createRule(ruleData)
      }.bind(this))
  }
Example #7
0
  /*
    Create a new mention entry

    @param {Object} data JSON object
    @returns {Promise}
  */
  createMention(data) {
    // Generate a doc_id if not provided
    if (!data.mention_id) {
      data.mention_id = uuid()
    }

    return this.mentionExists(data.mention_id).bind(this)
      .then(function(exists) {
        if (exists) {
          throw new Err('MentionStore.CreateError', {
            message: 'Mention ' + data.mention_id + ' already exists.'
          })
        }

        return this._createMention(data)
      }.bind(this))
  }
Example #8
0
  /*
    Create a new document source entry

    @param {Object} sourceData JSON object
    @returns {Promise}
  */
  createSource(sourceData) {
    // Generate a doc_id if not provided
    if (!sourceData.doc_id) {
      sourceData.doc_id = uuid()
    }

    if (!sourceData.guid) {
      sourceData.guid = sourceData.doc_id
    }

    return this.sourceExists(sourceData.doc_id).bind(this)
      .then(function(exists) {
        if (exists) {
          throw new Err('SourceStore.CreateError', {
            message: 'Document source ' + sourceData.doc_id + ' already exists.'
          })
        }

        return this._createSource(sourceData);
      }.bind(this))
  }
Example #9
0
function _populateBody (doc, jats, jatsImporter) {
  let $$ = jats.createElement.bind(jats)
  // ATTENTION: JATS can have multiple abstracts
  // ATM we only take the first, loosing the others
  let bodyEl = jats.find('article > body')
  if (bodyEl) {
    // add an empty paragraph if the body is empty
    if (bodyEl.getChildCount() === 0) {
      bodyEl.append($$('p'))
    }
    let body = doc.get('body')
    // ATTENTION: because there is already a body node in the document, *the* body, with id 'body'
    // we must change the id of the body element so that it does not collide with the internal one
    bodyEl.id = uuid()
    let tmp = jatsImporter.convertElement(bodyEl)
    let ids = tmp.content.slice()
    tmp.content = []
    body.content = ids
    doc.delete(tmp)
  }
}
 surface.transaction(function(tx, args) {
   var selection = args.selection;
   var path = selection.start.path;
   var startOffset = selection.start.offset;
   if (!selection.isCollapsed) {
     var out = editor.delete(tx, args);
     args.selection = out.selection;
   }
   args.text = '$';
   editor.insertText(tx, args);
   citation = tx.create({
     id: Substance.uuid(citationType),
     "type": citationType,
     "targets": [],
     "path": path,
     "startOffset": startOffset,
     "endOffset": startOffset + 1,
   });
   citation.label = "???";
   args.selection = citation.getSelection();
   return args;
 });
Example #11
0
export function generateTable (doc, nrows, ncols, tableId) {
  let $$ = doc.createElement.bind(doc)
  tableId = tableId || uuid('table')
  let table = $$('table', { id: tableId })
  let headRow = $$('table-row', { id: `${tableId}-h` })
  for (let j = 0; j < ncols; j++) {
    headRow.append(
      $$('table-cell', { id: `${tableId}-h-${j + 1}` })
        .attr('heading', true)
        .text(tableHelpers.getColumnLabel(j))
    )
  }
  table.append(headRow)
  for (let i = 0; i < nrows; i++) {
    let row = $$('table-row', { id: `${tableId}-${i + 1}` })
    for (let j = 0; j < ncols; j++) {
      row.append($$('table-cell', { id: `${tableId}-${i + 1}-${j + 1}` }).text(''))
    }
    table.append(row)
  }
  return table
}
Example #12
0
  _createRule() {
    let dataClient = this.context.documentClient
    let rule = {
      rule_id: uuid(),
      collection_id: this.props.collectionId,
      rubrics: [],
      entities: [],
      app_id: this.props.app
    }
    dataClient.createRule(rule, function(err) {
      if (err) {
        console.error(err)
        return
      }

      rule.entities_names = []
      rule.rubrics_names = []

      let rules = this.state.rules
      rules.unshift(rule)
      this.extendState({rules: rules})
    }.bind(this))
  }
Example #13
0
  _saveCollection() {
    let authClient = this.context.authenticationClient
    let user = authClient.getUser()
    let dataClient = this.context.documentClient
    let collection = {
      collection_id: uuid(),
      name: this.state.name,
      description: this.state.description,
      author: user.user_id,
      private: this.state.private,
      public: this.state.public,
      app_id: this.state.app_id
    }

    dataClient.createCollection(collection, function(err, col) {
      if (err) {
        console.error(err)
        return
      }

      this.send('saveCollection', col)
    }.bind(this))
  }
 constructor () {
   this.id = uuid()
   this.values = new Map()
   this.dirty = {}
   this.updates = {}
 }
Example #15
0
 /*
   Generates a new login key for a given email
 */
 _updateLoginKey(user) {
   let userStore = this.userStore
   let newLoginKey = uuid()
   return userStore.updateUser(user.userId, {loginKey: newLoginKey})
 }