Skip to content
Snippets Groups Projects
vmsg.js 4.38 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jake Read's avatar
    Jake Read committed
    /*
    view/vmsg.js
    
    largely unused appendage
    
    Jake Read at the Center for Bits and Atoms
    (c) Massachusetts Institute of Technology 2019
    
    This work may be reproduced, modified, distributed, performed, and
    displayed for any purpose, but must acknowledge the squidworks and cuttlefish projects.
    Copyright is retained and must be preserved. The work is provided as is;
    no warranty is provided, and users accept all liability.
    */
    
    
    Jake Read's avatar
    Jake Read committed
    // micro html console
    
    function MessageBox(View) {
      let view = View
      // and things inside of it,
      this.zoomCheckbox = {}
    
      // tracking a load,
      this.briefState = {
        recipName: '',
    
    Jake Read's avatar
    Jake Read committed
        numHunksLeft: 0,
        numLinksLeft: 0,
    
    Jake Read's avatar
    Jake Read committed
        isStateHappenning: false,
    
    Jake Read's avatar
    Jake Read committed
        setFromBrief: function(brief) {
    
    Jake Read's avatar
    Jake Read committed
          this.recipName = brief.interpreterName
          this.numHunksLeft = brief.numHunks
    
    Jake Read's avatar
    Jake Read committed
          briefStateToDom(this)
    
    Jake Read's avatar
    Jake Read committed
        },
    
    Jake Read's avatar
    Jake Read committed
        decrementHunks: function() {
          this.numHunksLeft--
    
    Jake Read's avatar
    Jake Read committed
          briefStateToDom(this)
    
    Jake Read's avatar
    Jake Read committed
        },
        incrementHunks: function() {
          this.numHunksLeft++
    
    Jake Read's avatar
    Jake Read committed
          briefStateToDom(this)
    
    Jake Read's avatar
    Jake Read committed
        },
        decrementLinks: function() {
          this.numLinksLeft--
    
    Jake Read's avatar
    Jake Read committed
          briefStateToDom(this)
    
    Jake Read's avatar
    Jake Read committed
        },
    
    Jake Read's avatar
    Jake Read committed
          this.numLinksLeft++
    
    Jake Read's avatar
    Jake Read committed
          briefStateToDom(this)
        }
      }
    
      let briefStateToDom = (brief) => {
        let str
        if (brief.numHunksLeft > 0) {
          str = `interpreter: ${brief.recipName} ${brief.recipVer} <br> awaiting ${brief.numHunksLeft} hunks`
        } else {
          str = `interpreter: ${brief.recipName} ${brief.recipVer} <br> all loaded OK`
    
    Jake Read's avatar
    Jake Read committed
        }
    
    Jake Read's avatar
    Jake Read committed
        $(this.msgbox).find('#titleBox').html(str)
    
      this.msgbox = {}
    
    Jake Read's avatar
    Jake Read committed
    
      /* ---------------------------    ---------------------------- */
      /* ------------------------- STARTUP ------------------------- */
      /* ---------------------------    ---------------------------- */
    
      this.init = () => {
    
    Jake Read's avatar
    Jake Read committed
        //view.log('message box alive')
    
        console.log("MSGBOXHELLO")
    
    Jake Read's avatar
    Jake Read committed
        // a box,
    
        this.msgbox = $('<div>').addClass('msgbox').get(0)
    
    Jake Read's avatar
    Jake Read committed
        // the title, and id of your manager
    
        this.msgbox.append($('<div>').attr('id', 'titleBox').addClass('msgboxmsg').append('name and interpreter:<br>~ unknown ~<br>truly').get(0))
    
    Jake Read's avatar
    Jake Read committed
        // say hello to your manager,
    
        this.msgbox.append($('<div><i class="em em-wave"></i>').addClass('msgboxbutton').addClass('msgboxmsg').append(' say hello').click((evt) => {
    
    Jake Read's avatar
    Jake Read committed
        }).get(0))
        // a refresh button
    
        this.msgbox.append($('<div><i class="em em-arrows_counterclockwise"></i>').addClass('msgboxbutton').addClass('msgboxmsg').append(' refresh view').click((evt) => {
    
    Jake Read's avatar
    Jake Read committed
          evt.preventDefault()
    
    Jake Read's avatar
    Jake Read committed
          view.refresh()
        }).get(0))
        // and then
    
        this.isHidden = false
    
        $(view.dom).append(this.msgbox)
    
      this.toggleHidden = () => {
        if(this.isHidden){
          $(this.msgbox).show()
        } else {
          $(this.msgbox).hide()
        }
      }
    
    
      let tpad = 10
    
      this.setTopMargin = (num) => {
        tpad = num
        this.checkHeight()
      }
    
      this.checkHeight = () => {
        let ht = view.dom.clientHeight
    
        $(this.msgbox).css('height', `${ht - 30 - tpad}px`).css('margin-top', `${tpad}px`)
    
    Jake Read's avatar
    Jake Read committed
      this.hide = () => {
    
        $(this.msgbox).css('display', 'none')
    
    Jake Read's avatar
    Jake Read committed
      }
    
      this.unhide = () => {
    
        $(this.msgbox).css('display', 'inline')
    
    Jake Read's avatar
    Jake Read committed
      }
    
    
    Jake Read's avatar
    Jake Read committed
      /* ---------------------------    ---------------------------- */
      /* -------------------------- WRITE -------------------------- */
      /* ---------------------------    ---------------------------- */
    
      this.write = (data) => {
    
    Jake Read's avatar
    Jake Read committed
        if(true) return false
    
    Jake Read's avatar
    Jake Read committed
        // write the message
    
        this.msgbox.append($('<div> -> ' + data + '</div>').addClass('msgboxmsg').get(0))
    
    Jake Read's avatar
    Jake Read committed
        // def check
        let heightcheck = () => {
          let height = 0;
    
          $(this.msgbox).children().each(function(child) {
    
    Jake Read's avatar
    Jake Read committed
            // jquery.each() syntax is a bit odd / different than elsewhere, sorry for inconsistency
            height += this.clientHeight + 5
          })
          return height
        }
        // if too tall, remove
    
        let ch = this.msgbox.clientHeight
    
    Jake Read's avatar
    Jake Read committed
        if (heightcheck() > ch) {
    
    Jake Read's avatar
    Jake Read committed
          //console.log('rm 1', heightcheck(), ch)
    
          $(this.msgbox).children().get(3).remove()
    
    Jake Read's avatar
    Jake Read committed
          // two at most, sloppy but fast
          if (heightcheck() > ch) {
    
    Jake Read's avatar
    Jake Read committed
            //console.log('rm 2', heightcheck(), ch)
    
            $(this.msgbox).children().get(3).remove()
    
        while($(this.msgbox).children().length > 3){
          $(this.msgbox).children().get(3).remove()
    
    Jake Read's avatar
    Jake Read committed
    }
    
    export default MessageBox