<commit_before>
Controller.defineMethod("initView", function initView(updateView = []) {
  if (!this.view) return;
  this.view.controller = this;

  var element = this.view;

  // Init textarea
  element.querySelectorAll("textarea").forEach(function (element) {
    if (element._textareaInit) return;

    var style = window.getComputedStyle(element);
    var defaultRows = element.getAttribute("rows") || 1;

    element.rows = defaultRows;
    var paddingTop = parseInt(style.paddingTop);
    var paddingBottom = parseInt(style.paddingBottom);
    var lineHeight = parseInt(style.lineHeight);

    var resizeTextArea = function () {
      this.rows = defaultRows; // Reset to 1 for scroll height detection
      if (this.scrollHeight == 0) return;

      var rows = Math.round((this.scrollHeight - paddingTop - paddingBottom) / lineHeight);
      var maxRows = getElementProperty(this, "data-ica-max-rows");
      if (maxRows) this.rows = Math.min(rows, maxRows);
      else this.rows = rows;
    }.bind(element);

    element.addEventListener("click", resizeTextArea);
    element.addEventListener("focus", resizeTextArea);
    element.addEventListener("input", resizeTextArea);
    element.addEventListener("blur", resizeTextArea);
    resizeTextArea();

    element._textareaInit = true;
  });

  // Init input tokens
  element.querySelectorAll("[data-ica-format='tokens']").forEach(function (element) {
    if (element._formatInit) return;

    var tokenInputHandler = new TokenInputHandler(element);

    var tokenInputFragment = TokenInputController.createViewFragment();
    var tokenInputElement = tokenInputFragment.querySelector(".tokens");
    element.parentNode.insertBefore(tokenInputFragment, element);
    var tokenInputController = new TokenInputController(tokenInputHandler, tokenInputElement);
    if (element.controller) tokenInputController.componentOf = element.controller;

    switch (getElementProperty(element, "suggestions")) {
      case "themes":
        var tokenSuggestionsFragment = TokenInputSuggestionsController.createViewFragment();
        var tokenSuggestionsElement = tokenSuggestionsFragment.querySelector(".tokens");
        element.parentNode.insertBefore(tokenSuggestionsFragment, element.nextSibling);
        var tokenSuggestionsController = new TokenInputThemeSuggestionsController(tokenInputHandler, tokenSuggestionsElement);
        if (element.controller) tokenSuggestionsController.componentOf = element.controller;
        break;
    }

    element._formatInit = true;
  });

  // Use Plyr for audio/video
  plyr.setup(element.querySelectorAll(".player:not(.plyr--setup)"), {
    controls: ["play", "progress", "current-time", "fullscreen"]
  });

  resize(this.view);

  setElementProperty(this.view, "controller-id", this.controllerId);
  if (updateView) this.updateView.apply(this, updateView);
});

Controller.defineMethod("hideView", function hideView() {
  if (!this.view) return;
  this.view.hidden = true;
});

Controller.defineMethod("unhideView", function hideView() {
  if (!this.view) return;
  this.view.hidden = false;
});

Controller.defineMethod("uninitView", function () {
  this.unlockBodyScrolling();
});

(function (Controller) {

  let numBodyScrollLocks = 0;

  Controller.defineMethod("lockBodyScrolling", function lockBodyScrolling() {
    if (!this.lockingBodyScroll) {
      this.lockingBodyScroll = true;
      ++numBodyScrollLocks;

      document.body.style.overflow = "hidden";
    }
  });

  Controller.defineMethod("unlockBodyScrolling", function unlockBodyScrolling() {
    if (this.lockingBodyScroll) {
      this.lockingBodyScroll = false;

      if (--numBodyScrollLocks === 0) document.body.style.overflow = "";
    }
  });

}(Controller));

function resize(container = document.body) {
  container.querySelectorAll("[data-ica-width-multiple]")
    .forEach(function (element) {
      let multiple = parseInt(getElementProperty(element, "width-multiple"));
      element.style.width = Math.floor(document.body.offsetWidth / multiple) * multiple + "px";
    });
}
<commit_msg>Review and annotate Controller (extension)<commit_after>
// Controller extension

Controller.defineMethod("initView", function initView(updateView = []) {
  if (!this.view) return;
  this.view.controller = this;

  let element = this.view;

  // Init textarea
  element.querySelectorAll("textarea").forEach(function (element) {
    if (element._textareaInit) return;

    let style = window.getComputedStyle(element);
    let defaultRows = element.getAttribute("rows") || 1;

    element.rows = defaultRows;
    let paddingTop = parseInt(style.paddingTop);
    let paddingBottom = parseInt(style.paddingBottom);
    let lineHeight = parseInt(style.lineHeight);

    let resizeTextArea = function () {
      this.rows = defaultRows; // Reset to 1 for scroll height detection
      if (this.scrollHeight === 0) return;

      let rows = Math.round((this.scrollHeight - paddingTop - paddingBottom) / lineHeight);
      let maxRows = getElementProperty(this, "data-ica-max-rows");
      if (maxRows) this.rows = Math.min(rows, maxRows);
      else this.rows = rows;
    }.bind(element);

    element.addEventListener("click", resizeTextArea);
    element.addEventListener("focus", resizeTextArea);
    element.addEventListener("input", resizeTextArea);
    element.addEventListener("blur", resizeTextArea);
    resizeTextArea();

    element._textareaInit = true;
  });

  // Init input tokens
  element.querySelectorAll("[data-ica-format='tokens']").forEach(function (element) {
    if (element._formatInit) return;

    let tokenInputHandler = new TokenInputHandler(element);

    let tokenInputFragment = TokenInputController.createViewFragment();
    let tokenInputElement = tokenInputFragment.querySelector(".tokens");
    element.parentNode.insertBefore(tokenInputFragment, element);
    let tokenInputController = new TokenInputController(tokenInputHandler, tokenInputElement);
    if (element.controller) tokenInputController.componentOf = element.controller;

    switch (getElementProperty(element, "suggestions")) {
      case "themes": {
        let tokenSuggestionsFragment = TokenInputSuggestionsController.createViewFragment();
        let tokenSuggestionsElement = tokenSuggestionsFragment.querySelector(".tokens");
        element.parentNode.insertBefore(tokenSuggestionsFragment, element.nextSibling);
        let tokenSuggestionsController = new TokenInputThemeSuggestionsController(tokenInputHandler, tokenSuggestionsElement);
        if (element.controller) tokenSuggestionsController.componentOf = element.controller;
        break;
      }
    }

    element._formatInit = true;
  });

  // Use Plyr for audio/video
  plyr.setup(element.querySelectorAll(".player:not(.plyr--setup)"), {
    controls: ["play", "progress", "current-time", "fullscreen"]
  });

  resize(this.view);

  setElementProperty(this.view, "controller-id", this.controllerId);
  if (updateView) this.updateView.apply(this, updateView);
});

Controller.defineMethod("hideView", function hideView() {
  if (!this.view) return;
  this.view.hidden = true;
});

Controller.defineMethod("unhideView", function hideView() {
  if (!this.view) return;
  this.view.hidden = false;
});

Controller.defineMethod("uninitView", function () {
  this.unlockBodyScrolling();
});

(function (Controller) {

  let numBodyScrollLocks = 0;

  Controller.defineMethod("lockBodyScrolling", function lockBodyScrolling() {
    if (!this.lockingBodyScroll) {
      this.lockingBodyScroll = true;
      ++numBodyScrollLocks;

      document.body.style.overflow = "hidden";
    }
  });

  Controller.defineMethod("unlockBodyScrolling", function unlockBodyScrolling() {
    if (this.lockingBodyScroll) {
      this.lockingBodyScroll = false;

      if (--numBodyScrollLocks === 0) document.body.style.overflow = "";
    }
  });

}(Controller));

function resize(container = document.body) {
  container.querySelectorAll("[data-ica-width-multiple]")
    .forEach(function (element) {
      let multiple = parseInt(getElementProperty(element, "width-multiple"));
      element.style.width = Math.floor(document.body.offsetWidth / multiple) * multiple + "px";
    });
}
<|endoftext|>


<commit_before>// #!/usr/bin/env node

var dataFolder = '../repository/techonmap';
var contentFolder = '../content';
var _ = require('underscore');
var Fs = require('fs');
var Path = require('path');
var Visitor = require('./FileVisitor');
var Q = require('q');
var Yaml = require('yamljs');

function yamlToObject(description, yaml) {
    var description = (description || '').trim();
    var obj = Yaml.parse(yaml || '');
    if (obj)
        obj.description = description;
    return obj;
}

function toStructuredContent(obj) {
    var copy = JSON.parse(JSON.stringify(obj));
    var description = copy.description || '';
    delete copy.description;
    var dataYaml = Yaml.stringify(copy, 1, 2);
    // var text = description + "\n\n----\n" + dataYaml;
    return {yaml:dataYaml, content: description};
}

function dumpSync(file, data) {
    var str = data.content+'\n\n-------\n\n'+data.yaml;
    Fs.writeFileSync(file, str);

}

var counter = 0;
var ids = [];
var prestataires = [];

Visitor.visit(dataFolder, function(file, directory) {
    if (Path.extname(file) !== '.md')
        return;

    var content = Fs.readFileSync(file).toString();
    content = content.split('-------');
    var description = content[0].trim();
    var object = yamlToObject(description, content[1]);

    if (!object) {
        console.log(file);
    } else {
        ids.push(object.id);
        if (object.category == 'Prestataire') {
            prestataires.push(object);
            object.category = 'Entreprise';
            if (object.tags.indexOf('B2B') < 0)
                object.tags.push('B2B');
            var data = toStructuredContent(object);
            dumpSync(file, data);

        }

        if (object.tags && object.tags.indexOf('b2b') >=0) {

            var idx = object.tags.indexOf('b2b');
            object.tags.splice(idx, 1, 'B2B');
            var data = toStructuredContent(object);
            dumpSync(file, data);
        }

        if (object.tags && object.tags.indexOf('apps') >=0) {

            var idx = object.tags.indexOf('apps');
            object.tags.splice(idx, 1, 'applications mobiles');
            var data = toStructuredContent(object);
            dumpSync(file, data);
        }

    }

}).then(function() {
    ids = ids.sort();
//    _.each(ids, function(id) {
//        console.log(id);
//    })
    console.log(prestataires.length);
    console.log('done');
}).done();<commit_msg>tag refactoring update<commit_after>// #!/usr/bin/env node

var dataFolder = '../repository/techonmap';
var contentFolder = '../content';
var _ = require('underscore');
var Fs = require('fs');
var Path = require('path');
var Visitor = require('./FileVisitor');
var Q = require('q');
var Yaml = require('yamljs');

function yamlToObject(description, yaml) {
    var description = (description || '').trim();
    var obj = Yaml.parse(yaml || '');
    if (obj)
        obj.description = description;
    return obj;
}

function toStructuredContent(obj) {
    var copy = JSON.parse(JSON.stringify(obj));
    var description = copy.description || '';
    delete copy.description;
    var dataYaml = Yaml.stringify(copy, 1, 2);
    // var text = description + "\n\n----\n" + dataYaml;
    return {
        yaml : dataYaml,
        content : description
    };
}

function dumpSync(file, data) {
    var str = data.content + '\n\n-------\n\n' + data.yaml;
    Fs.writeFileSync(file, str);

}

function replaceTag(object, oldTag, newTag) {
    if (!object.tags)
        return;

    if (object.tags.indexOf(oldTag) >= 0) {
        var idx = object.tags.indexOf(oldTag);
        object.tags.splice(idx, 1, newTag);
        var data = toStructuredContent(object);
        dumpSync(file, data);
    }
}

var counter = 0;
var ids = [];
var prestataires = [];

Visitor.visit(dataFolder, function(file, directory) {
    if (Path.extname(file) !== '.md')
        return;

    var content = Fs.readFileSync(file).toString();
    content = content.split('-------');
    var description = content[0].trim();
    var object = yamlToObject(description, content[1]);

    if (!object) {
        console.log(file);
    } else {
        ids.push(object.id);
        if (object.category == 'Prestataire') {
            prestataires.push(object);
            object.category = 'Entreprise';
            if (object.tags.indexOf('B2B') < 0)
                object.tags.push('B2B');
            var data = toStructuredContent(object);
            dumpSync(file, data);

        } else if (object.category == 'Entreprise') {

            replaceTag(object, 'b2b', 'B2B');
            replaceTag(object, 'apps', 'applications mobiles');
            replaceTag(object, 'design', 'webdesign');
            replaceTag(object, 'Design', 'webdesign');
            replaceTag(object, 'conseils', 'conseil');
            replaceTag(object, 'jeu', 'Jeux vidéo');
            replaceTag(object, 'reseausocial', 'réseau social');
        } else if (object.category == 'École') {

            replaceTag(object, 'designer', 'webdesign');
            replaceTag(object, 'Designer', 'webdesign');
            replaceTag(object, 'graphiste', 'webdesign');
            replaceTag(object, 'Graphiste', 'webdesign');

        } else if (object.category == 'Tiers-lieu') {

            replaceTag(object, 'bureau', 'bureaux partagés');
            replaceTag(object, 'bureaux', 'bureaux partagés');
            replaceTag(object, 'bureauxpartages', 'bureaux partagés');
            replaceTag(object, 'Graphiste', 'webdesign');
        }

    }

}).then(function() {
    ids = ids.sort();
    // _.each(ids, function(id) {
    // console.log(id);
    // })
    console.log(prestataires.length);
    console.log('done');
}).done();<|endoftext|>


<commit_before>function getopt (patterns, argv) {
    patterns = patterns.map(function (pattern) {
        return {
            valuable: pattern.valuable,
            verbose: '--' + pattern.verbose,
            terse: pattern.terse ? '-' + pattern.terse : '',
            key: pattern.verbose
        }
    })

    const ordered = []

    let i = 0, terminal = false
    for (;;) {
        if (argv[0] == '--') {
            break
        }
        if (argv.length == 0 || !/^--?[^-]/.test(argv[0])) {
            break
        }
        const arg = argv.shift()
        const $ = /^(--[^=]+)=(.*)$/.exec(arg) || /^(-[^-])(.+)$/.exec(arg) || [false, arg, true]
        const catenated = !! $[0]
        const parameter = $[1]
        let value = $[2]
        const isLong = parameter[1] == '-'
       const alternates = patterns.filter(function (pattern) {
            return pattern.verbose.lastIndexOf(parameter, 0) == 0
                || pattern.terse.lastIndexOf(parameter, 0) == 0
        })
        if (alternates.length != 1) {
            throw {
                abend: alternates.length ? 'ambiguous argument' : 'unknown argument',
                context: parameter
            }
        }

        const pattern = alternates.shift()
        if (pattern.valuable) {
            if (!catenated) {
                if (argv.length == 0) {
                    throw {
                        abend: 'missing argument',
                        context: isLong ? pattern.verbose : pattern.terse
                    }
                }
                value = argv.shift()
            }
        } else if (catenated) {
            if (isLong) {
                throw {
                    abend: 'unexpected argument value',
                    context: pattern.verbose
                }
            } else {
                argv.unshift('-' + value)
                value = true
            }
        }

        ordered.push({ name: pattern.key, value: value })

        i++
    }

// TODO Implement `--no-foo`.
// https://github.com/trentm/node-dashdash/pull/13
// http://stackoverflow.com/questions/9234258/in-python-argparse-is-it-possible-to-have-paired-no-something-something-arg/9236426#9236426
// http://stackoverflow.com/questions/9234258/in-python-argparse-is-it-possible-to-have-paired-no-something-something-arg
    return ordered
}

module.exports = getopt
<commit_msg>Parse negations of toggles in `getopt.js`.<commit_after>function getopt (patterns, argv) {
    patterns = patterns.map(function (pattern) {
        return {
            valuable: pattern.valuable,
            verbose: '--' + pattern.verbose,
            terse: pattern.terse ? '-' + pattern.terse : '',
            key: pattern.verbose
        }
    })

    const ordered = []

    let i = 0, terminal = false
    for (;;) {
        if (argv[0] == '--') {
            break
        }
        if (argv.length == 0 || !/^--?[^-]/.test(argv[0])) {
            break
        }
        const arg = argv.shift()
        const $ = /^(--[^=]+)=(.*)$/.exec(arg) || /^(-[^-])(.+)$/.exec(arg) || [false, arg, true]
        const catenated = !! $[0]
        const parameter = $[1]
        let value = $[2]
        const isLong = parameter[1] == '-'
        const negated = /^--no-(.*)$/.exec(parameter)
        const negation = negated == null ? '\u0000' : `--${negated[1]}`
        const alternates = patterns.filter(function (pattern) {
            return pattern.verbose.lastIndexOf(negation, 0) == 0
                || pattern.verbose.lastIndexOf(parameter, 0) == 0
                || pattern.terse.lastIndexOf(parameter, 0) == 0
        })

        if (alternates.length != 1) {
            throw {
                abend: alternates.length ? 'ambiguous argument' : 'unknown argument',
                context: parameter
            }
        }

        const pattern = alternates.shift()

        if (negated != null) {
            if (pattern.valuable) {
                throw {
                    abend: 'argument not negatable',
                    context: parameter
                }
            }
            value = false
        }

        if (pattern.valuable) {
            if (!catenated) {
                if (argv.length == 0) {
                    throw {
                        abend: 'missing argument',
                        context: isLong ? pattern.verbose : pattern.terse
                    }
                }
                value = argv.shift()
            }
        } else if (catenated) {
            if (isLong) {
                throw {
                    abend: 'unexpected argument value',
                    context: pattern.verbose
                }
            } else {
                argv.unshift('-' + value)
                value = true
            }
        }

        ordered.push({ name: pattern.key, value: value })

        i++
    }

// TODO Implement `--no-foo`.
// https://github.com/trentm/node-dashdash/pull/13
// http://stackoverflow.com/questions/9234258/in-python-argparse-is-it-possible-to-have-paired-no-something-something-arg/9236426#9236426
// http://stackoverflow.com/questions/9234258/in-python-argparse-is-it-possible-to-have-paired-no-something-something-arg
    return ordered
}

module.exports = getopt
<|endoftext|>


<commit_before>/* call using this enclosure
  (function(){
    var url = 'https://rawgit.com/jamesona/SEO-Tools/master/am-dashboard/dashboard.js';
    document.head.appendChild(document.createElement('script')).src=url;
    function initialize(){
      if (typeof(Dashboard) !== 'undefined' && typeof(ko) !== 'undefined' && ko.dataFor(app) !== undefined) {
          //console.log('Knockout:');console.log(ko);console.log('App:');console.log(ko.dataFor(app));
          db = new Dashboard(ko.dataFor(app))
      } else {
          setTimeout(function(){initialize()}, 100);
      }
    }
    initialize();
  })();
*/

function Dashboard(app) {
  var self = this;
  this.app = app;
  this.Tools = {
    bobCal: function(){},
    openClient: function(client) {
      self.app.showManageCustomer(client);
    },
    closeClient: function() {
      var buttons = document.getElementsByClassName('close'),
      i = buttons.length - 1;
      if (i >= 1) buttons[i - 1].click();
    },
    createElement: function(parent, tag, attributes) {
      var element = parent.appendChild(document.createElement(tag));
      for (var attribute in attributes) {
        if (attributes.hasOwnProperty(attribute)) {
          element[attribute] = attributes[attribute];
        }
      }
      return element;
    },
    bobParse: function(raw){
      var clients = [], data = {};
      // exit on null entry
      if ( raw == null ) return;
      for (var cells = raw.replace(/Basic[\r\n\s\ta-z]*Partner ID[\t\s]+/i, '').split(/\t/),
        client = {}, cols = ['Account ID',	'Account Start Date',	'Account Bucket',	'Account Spend',
        'Date of Next Ticket',	'Engaged Status',	'Timezone',	'Welcome Call',	'Keyword Research',
        'Local Profile Tab',	'Obtain or Create Google Logins',	'Create and Verify Google Profile',
        'Obtain Site Access',	'Implement Onsite Edits',	'Create Yahoo Account',	'Create and Verify Yahoo Profile',
        'Create and Verify Bing Profile',	'Install Analytics',	'Company Name',	'Contact Name',	'Website URL',
        'Email Address',	'Phone Number',	'Partner ID',];
        cells.length>0;){
        keys = Object.keys(client).length;
        if (keys<cols.length-1){
          var param = cols[keys];
          client[param] = cells[0];
          cells.shift();
        } else {
          client.count = keys;
          clients.push(client);
          client = {};
        }
      }
      for (var i=0;i<clients.length;i++){
        var date = clients[i]['Date of Next Ticket']
        if (data[date] === undefined) data[date] = [];
        data[date].push(clients[i]);
      }
      return data;
    },
  };
  this.Tickets = {
    calendar: function(month, year, data) {
      console.log(data);
      if (typeof(month) == Object) {data = month, month = null;}
      this.current_date = new Date();
      this.day_labels = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
      this.month_labels = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
      this.month = (isNaN(month) || month === null) ? this.current_date.getMonth() : month;
      this.year = (isNaN(year) || year === null) ? this.current_date.getFullYear() : year;
      this.draw = function(ele){
          if (this.month > 11) {
            this.month -= 12;
            this.year += 1;
          } else if (month < 0) {
            this.month += 12;
            this.year -= 1;
          }
          // get dates
          var startingDay = new Date(this.year, this.month, 1).getDay(),
          endingDate = new Date(this.year, this.month + 1, 0),
          monthLength = endingDate.getDate(),
          inLastRow = 6 - endingDate.getDay();

          // generate header
          this.table = document.createElement('table');
          this.head = document.createElement('thead');
          this.prev = document.createElement('th');
          this.next = document.createElement('th');
          this.title = document.createElement('th');
          this.days = document.createElement('tr');
          this.body = document.createElement('tbody');
          this.cells = '';
          this.table.setAttribute('class', 'calendar');
          this.table.appendChild(this.head);
          this.head.appendChild(this.prev);
          this.prev.innerHTML = "«";
          this.prev.id = 'prev';
          this.head.appendChild(this.title);
          this.head.appendChild(this.next);
          this.next.innerHTML = "»";
          this.next.id = 'next';
          this.table.appendChild(this.days);
          this.title.innerHTML = this.month_labels[this.month] + " " + this.year;
          this.title.setAttribute('colspan', '5');
          this.days.setAttribute('class', 'header');
          for (var i = 0; i <= 6; i++ ) this.cells += '' + this.day_labels[i] + '	';
          this.days.innerHTML = this.cells;

          //generate calendar
          var html = '
';
          if ( startingDay ) html += '	';
          for (var day = 1; day <= monthLength; day++) {
          html += '
' + day + '
';
          //if data argument present, append key value for current day
          if (data) {
            var today = (this.month+1)+'/'+day+'/'+this.year;
            if (data[today]) html += '
'+Object.keys(data[today]).length+' Clients
';
          }
          html += '	';
          if ( (day + startingDay) % 7 === 0 && day != monthLength ) html += '

';
          }
          if ( inLastRow ) html += '	';
          html += '
';
          this.table.innerHTML += html;
          if (ele) {
            ele.innerHTML = this.table.outerHTML;
          } else {
            return this.table.outerHTML;
          }
          // save reference to dom node in object
          this.node = ele;
          // save reference to calendar object for enclosure scope
          var cal = this;
              (function(){
            // save calendar object reference for listeners
            var self = this;
                self.prev.addEventListener('click', function(){
              cal.month--;
                    cal.draw(cal.node);
                });
            self.next.addEventListener('click', function(){
                    cal.month++;
              cal.draw(cal.node);
                });
                document.onkeydown = function(e) {
                  e = e || window.event;
                    if (e.keyCode == '37') {
                    // left arrow
                    cal.month--;
                    cal.draw(cal.node);
                    } else if (e.keyCode == '39') {
                        // right arrow
                        cal.month++;
                    cal.draw(cal.node);
                    }
                };
              })();
        };
    },
    getTickets: function() {
      //get tickets
      try {
        if (typeof(self.app.contentViewModel().myTickets) === "function"){
          self.Tickets.ticketArray = self.app.contentViewModel().myTickets();
        } else if (localStorage.ticketCache) {
          self.Tickets.ticketArray = JSON.parse(localStorage.ticketCache);
        }
      } catch(err) {
        console.log(err.message);
      }
      //return results
      if (self.Tickets.ticketArray) {
        localStorage.ticketCache = JSON.stringify(self.Tickets.ticketArray);
        return self.Tickets.ticketArray;
      } else {
        alert('Unable to access tickets at this time!');
        return [];
      }
    },
    getCritical: function() {
      var tickets = this.getTickets(),
      critical = [];
      for (var i = 0; i < tickets.length; i++) {
        if (tickets[i].ScheduledEndDate < new Date()) {
          critical.push(tickets[i]);
        }
      }
      if (tickets.length > 0){
        return critical;
      } else {
        return false;
      }
    },
    countCritical: function() {
      var criticals = self.Tickets.getCritical();
      if (criticals) {
        return 'Critical Tickets: ' + criticals.length + '';
      } else {
        return 'Error loading tickets!';
      }
    },
    sortTickets: function(tickets){
      if (! tickets){
        tickets = this.getTickets();
      }
      var data = {};
      for (var i=0;i<tickets.length;i++){
        var ticket = tickets[i],
        date = new Date(ticket.ScheduledEndDate),
        day = date.getDate()+'/'+(date.getMonth()+1)+'/'+date.getFullYear();
        if (! data[day]){ data[day] = [];}
        data[day].push(ticket);
      }
      return data;
    },
    listTickets: function(tickets){
      var list = document.createElement('ul');
      for (var i=0;i<tickets.length;i++){
        var ticket = tickets[i],
        listItem = document.createElement('li'),
        text = ticket.CompanyName+': '+ticket.TicketTypeName;
        text += ' (Due: '+(ticket.ScheduledEndDate.getMonth()+1);
        text += '/'+ticket.ScheduledEndDate.getDate()+'/';
        text += ticket.ScheduledEndDate.getFullYear()+')';
        listItem.innerHTML = text;
        list.appendChild(listItem);
      }
      return list;
    },
    tryCache: function(){
      if (self.Tickets.ticketArray) {
        localStorage.ticketCache = JSON.stringify(self.Tickets.ticketArray);
      }
    },
  };
  this.HTML = {};
  this.HTML.dashboard = this.Tools.createElement(document.body, 'div', {
        className: 'navbar navbar-inverse navbar-fixed-bottom',
        id: 'dashboard',
  });
  this.HTML.style = this.Tools.createElement(this.HTML.dashboard, 'link', {
    rel: 'stylesheet',
    type: 'text/css',
    href: 'https://rawgit.com/jamesona/SEO-Tools/master/am-dashboard/dashboard.css',
  }),
  this.HTML.nav = this.Tools.createElement(this.HTML.dashboard, 'ul', {
    className: 'nav navbar-nav',
  }),
  this.HTML.tools = this.Tools.createElement(this.HTML.nav, 'li', {
    innerHTML: 'Tools',
    className: 'dropup',
  }),
  this.HTML.toolsMenu = this.Tools.createElement(this.HTML.tools, 'ul', {
    className: 'dropdown-menu',
  }),
  this.HTML.tickets = this.Tools.createElement(this.HTML.nav, 'li', {
    innerHTML: 'Tickets',
    className: 'dropup',
  }),
  this.HTML.ticketsMenu = this.Tools.createElement(this.HTML.tickets, 'ul', {
    className: 'dropdown-menu',
  }),
  this.HTML.ticketCalendar = this.Tools.createElement(this.HTML.ticketsMenu, 'li', {
    innerHTML: 'Calendar',
    onclick: function(){
      var node = bootbox.alert('none')[0].children[0].children[0].children[0],
      data = self.Tickets.sortTickets(),
      calendar = new self.Tickets.calendar(data);
      calendar.draw(node);
    }
  }),
  this.HTML.critical = this.Tools.createElement(this.HTML.nav, 'li', {
    innerHTML: 'Click to show Critical',
    id: 'critical',
    onclick: self.Tickets.countCritical(),
  });

  window.beforeunload = function(){
    self.Tickets.tryCache();
  };
  window.onhashchange = function(){
    self.Tickets.tryCache();
  };
  if (localStorage.ticketCache) self.Tickets.ticketArray = JSON.parse(localStorage.ticketCache);
}
<commit_msg>Update dashboard.js<commit_after>/* call using this enclosure
  (function(){
    var url = 'https://rawgit.com/jamesona/SEO-Tools/master/am-dashboard/dashboard.js';
    document.head.appendChild(document.createElement('script')).src=url;
    function initialize(){
      if (typeof(Dashboard) !== 'undefined' && typeof(ko) !== 'undefined' && ko.dataFor(app) !== undefined) {
          //console.log('Knockout:');console.log(ko);console.log('App:');console.log(ko.dataFor(app));
          db = new Dashboard(ko.dataFor(app))
      } else {
          setTimeout(function(){initialize()}, 100);
      }
    }
    initialize();
  })();
*/

function Dashboard(app) {
  var self = this;
  this.app = app;
  this.Tools = {
    bobCal: function(){},
    openClient: function(client) {
      self.app.showManageCustomer(client);
    },
    closeClient: function() {
      var buttons = document.getElementsByClassName('close'),
      i = buttons.length - 1;
      if (i >= 1) buttons[i - 1].click();
    },
    createElement: function(parent, tag, attributes) {
      var element = parent.appendChild(document.createElement(tag));
      for (var attribute in attributes) {
        if (attributes.hasOwnProperty(attribute)) {
          element[attribute] = attributes[attribute];
        }
      }
      return element;
    },
    bobParse: function(raw){
      var clients = [], data = {};
      // exit on null entry
      if ( raw == null ) return;
      for (var cells = raw.replace(/Basic[\r\n\s\ta-z]*Partner ID[\t\s]+/i, '').split(/\t/),
        client = {}, cols = ['Account ID',	'Account Start Date',	'Account Bucket',	'Account Spend',
        'Date of Next Ticket',	'Engaged Status',	'Timezone',	'Welcome Call',	'Keyword Research',
        'Local Profile Tab',	'Obtain or Create Google Logins',	'Create and Verify Google Profile',
        'Obtain Site Access',	'Implement Onsite Edits',	'Create Yahoo Account',	'Create and Verify Yahoo Profile',
        'Create and Verify Bing Profile',	'Install Analytics',	'Company Name',	'Contact Name',	'Website URL',
        'Email Address',	'Phone Number',	'Partner ID',];
        cells.length>0;){
        keys = Object.keys(client).length;
        if (keys<cols.length-1){
          var param = cols[keys];
          client[param] = cells[0];
          cells.shift();
        } else {
          client.count = keys;
          clients.push(client);
          client = {};
        }
      }
      for (var i=0;i<clients.length;i++){
        var date = clients[i]['Date of Next Ticket']
        if (data[date] === undefined) data[date] = [];
        data[date].push(clients[i]);
      }
      return data;
    },
  };
  this.Tickets = {
    calendar: function(month, year, data) {
      console.log(data);
      if (typeof(month) == Object) {data = month, month = null;}
      this.current_date = new Date();
      this.day_labels = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
      this.month_labels = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
      this.month = (isNaN(month) || month === null) ? this.current_date.getMonth() : month;
      this.year = (isNaN(year) || year === null) ? this.current_date.getFullYear() : year;
      this.draw = function(ele){
          if (this.month > 11) {
            this.month -= 12;
            this.year += 1;
          } else if (month < 0) {
            this.month += 12;
            this.year -= 1;
          }
          // get dates
          var startingDay = new Date(this.year, this.month, 1).getDay(),
          endingDate = new Date(this.year, this.month + 1, 0),
          monthLength = endingDate.getDate(),
          inLastRow = 6 - endingDate.getDay();

          // generate header
          this.table = document.createElement('table');
          this.head = document.createElement('thead');
          this.prev = document.createElement('th');
          this.next = document.createElement('th');
          this.title = document.createElement('th');
          this.days = document.createElement('tr');
          this.body = document.createElement('tbody');
          this.cells = '';
          this.table.setAttribute('class', 'calendar');
          this.table.appendChild(this.head);
          this.head.appendChild(this.prev);
          this.prev.innerHTML = "«";
          this.prev.id = 'prev';
          this.head.appendChild(this.title);
          this.head.appendChild(this.next);
          this.next.innerHTML = "»";
          this.next.id = 'next';
          this.table.appendChild(this.days);
          this.title.innerHTML = this.month_labels[this.month] + " " + this.year;
          this.title.setAttribute('colspan', '5');
          this.days.setAttribute('class', 'header');
          for (var i = 0; i <= 6; i++ ) this.cells += '' + this.day_labels[i] + '	';
          this.days.innerHTML = this.cells;

          //generate calendar
          var html = '
';
          if ( startingDay ) html += '	';
          for (var day = 1; day <= monthLength; day++) {
          html += '
' + day + '
';
          //if data argument present, append key value for current day
          if (data) {
            var today = (this.month+1)+'/'+day+'/'+this.year;
            if (data[today]) html += '
'+Object.keys(data[today]).length+' Clients
';
          }
          html += '	';
          if ( (day + startingDay) % 7 === 0 && day != monthLength ) html += '

';
          }
          if ( inLastRow ) html += '	';
          html += '
';
          this.table.innerHTML += html;
          if (ele) {
            ele.innerHTML = this.table.outerHTML;
          } else {
            return this.table.outerHTML;
          }
          // save reference to dom node in object
          this.node = ele;
          // save reference to calendar object for enclosure scope
          var cal = this;
              (function(){
            // save calendar object reference for listeners
            var self = this;
                self.prev.addEventListener('click', function(){
              cal.month--;
                    cal.draw(cal.node);
                });
            self.next.addEventListener('click', function(){
                    cal.month++;
              cal.draw(cal.node);
                });
                document.onkeydown = function(e) {
                  e = e || window.event;
                    if (e.keyCode == '37') {
                    // left arrow
                    cal.month--;
                    cal.draw(cal.node);
                    } else if (e.keyCode == '39') {
                        // right arrow
                        cal.month++;
                    cal.draw(cal.node);
                    }
                };
              })();
        };
    },
    getTickets: function() {
      //get tickets
      try {
        if (typeof(self.app.contentViewModel().myTickets) === "function"){
          self.Tickets.ticketArray = self.app.contentViewModel().myTickets();
        } else if (localStorage.ticketCache) {
          self.Tickets.ticketArray = JSON.parse(localStorage.ticketCache);
        }
      } catch(err) {
        console.log(err.message);
      }
      //return results
      if (self.Tickets.ticketArray) {
        localStorage.ticketCache = JSON.stringify(self.Tickets.ticketArray);
        return self.Tickets.ticketArray;
      } else {
        alert('Unable to access tickets at this time!');
        return [];
      }
    },
    getCritical: function() {
      var tickets = this.getTickets(),
      critical = [];
      for (var i = 0; i < tickets.length; i++) {
        if (tickets[i].ScheduledEndDate < new Date()) {
          critical.push(tickets[i]);
        }
      }
      if (tickets.length > 0){
        return critical;
      } else {
        return false;
      }
    },
    countCritical: function() {
      var criticals = self.Tickets.getCritical();
      if (criticals) {
        return 'Critical Tickets: ' + criticals.length + '';
      } else {
        return 'Error loading tickets!';
      }
    },
    sortTickets: function(tickets){
      if (! tickets){
        tickets = this.getTickets();
      }
      var data = {};
      for (var i=0;i<tickets.length;i++){
        var ticket = tickets[i],
        date = new Date(ticket.ScheduledEndDate),
        day = date.getDate()+'/'+(date.getMonth()+1)+'/'+date.getFullYear();
        if (! data[day]){ data[day] = [];}
        data[day].push(ticket);
      }
      return data;
    },
    listTickets: function(tickets){
      var list = document.createElement('ul');
      for (var i=0;i<tickets.length;i++){
        var ticket = tickets[i],
        listItem = document.createElement('li'),
        text = ticket.CompanyName+': '+ticket.TicketTypeName;
        text += ' (Due: '+(ticket.ScheduledEndDate.getMonth()+1);
        text += '/'+ticket.ScheduledEndDate.getDate()+'/';
        text += ticket.ScheduledEndDate.getFullYear()+')';
        listItem.innerHTML = text;
        list.appendChild(listItem);
      }
      return list;
    },
    tryCache: function(){
      try {
        if (self.Tickets.ticketArray) {
          localStorage.ticketCache = JSON.stringify(self.Tickets.ticketArray);
        }
      } catch(err) {
        setTimeout(function(){self.Tickets.tryCache()}, 1000);
      }
    },
  };
  this.HTML = {};
  this.HTML.dashboard = this.Tools.createElement(document.body, 'div', {
        className: 'navbar navbar-inverse navbar-fixed-bottom',
        id: 'dashboard',
  });
  this.HTML.style = this.Tools.createElement(this.HTML.dashboard, 'link', {
    rel: 'stylesheet',
    type: 'text/css',
    href: 'https://rawgit.com/jamesona/SEO-Tools/master/am-dashboard/dashboard.css',
  }),
  this.HTML.nav = this.Tools.createElement(this.HTML.dashboard, 'ul', {
    className: 'nav navbar-nav',
  }),
  this.HTML.tools = this.Tools.createElement(this.HTML.nav, 'li', {
    innerHTML: 'Tools',
    className: 'dropup',
  }),
  this.HTML.toolsMenu = this.Tools.createElement(this.HTML.tools, 'ul', {
    className: 'dropdown-menu',
  }),
  this.HTML.tickets = this.Tools.createElement(this.HTML.nav, 'li', {
    innerHTML: 'Tickets',
    className: 'dropup',
  }),
  this.HTML.ticketsMenu = this.Tools.createElement(this.HTML.tickets, 'ul', {
    className: 'dropdown-menu',
  }),
  this.HTML.ticketCalendar = this.Tools.createElement(this.HTML.ticketsMenu, 'li', {
    innerHTML: 'Calendar',
    onclick: function(){
      var node = bootbox.alert('none')[0].children[0].children[0].children[0],
      data = self.Tickets.sortTickets(),
      calendar = new self.Tickets.calendar(data);
      calendar.draw(node);
    }
  }),
  this.HTML.critical = this.Tools.createElement(this.HTML.nav, 'li', {
    innerHTML: 'Click to show Critical',
    id: 'critical',
    onclick: self.Tickets.countCritical(),
  });

  window.beforeunload = function(){
    self.Tickets.tryCache();
  };
  window.onhashchange = function(){
    if (window.location.href == 'https://launchpad.boostability.com/#/customerservice/activetickets'){
      self.Tickets.tryCache();
    }
  };
  if (localStorage.ticketCache) self.Tickets.ticketArray = JSON.parse(localStorage.ticketCache);
}
<|endoftext|>


<commit_before>import Falcor from "falcor";
import React from "react";

export default function(config) {
	return function(component) {
		const Component = component;
		return class FalcorRoot extends React.Component {

			constructor(props) {
				super(props);
				if (typeof config === "function") {
					config = config();
				}
				this.state = { model: new Falcor.Model(config) };
			}

			static childContextTypes = {
				model: React.PropTypes.object.isRequired
			};

			getChildContext() {
				return { model: this.state.model };
			}

			render() {
				return <Component {...this.props} />;
			}

		};
	};
}
<commit_msg>Removed support for root initialization through a function<commit_after>import Falcor from "falcor";
import React from "react";

export default function(config) {
	return function(component) {
		const Component = component;
		return class FalcorRoot extends React.Component {

			constructor(props) {
				super(props);
				this.state = { model: new Falcor.Model(config) };
			}

			static childContextTypes = {
				model: React.PropTypes.object.isRequired
			};

			getChildContext() {
				return { model: this.state.model };
			}

			render() {
				return <Component {...this.props} />;
			}

		};
	};
}
<|endoftext|>


<commit_before>(function(exports) {
  var mapMarkers = []

  exports.fetchFusionTablesData = function(fusionTablesID, callback) {
    $.ajax({
      dataType: 'jsonp',
      url: 'https://fusiontables.googleusercontent.com/fusiontables/api/query?sql=SELECT+*+FROM+' + fusionTablesID + '&jsonCallback=?',
      success: function(data) {
        callback(false, exports.formatData(data))
      },
      error: function(err) {
        callback(err)
      }
    })
  }

  exports.fetchJSON = function(url, cb) {
    $.ajax({
      dataType: 'json',
      url: url,
      success: function(data) {
        cb(false, eval(data))
      },
      error: function(xhr, status, err) {
        cb(err)
      }
    })
  }

  // accepts data from fusion tables JSON API
  exports.formatData = function(data) {
    var cleaned = []
    data.table.rows.forEach(function(row) {
      var cleanRow = {}
      for (var i = 0; i < row.length - 1; i++) {
        cleanRow[data.table.cols[i]] = row[i]
      }
      cleaned.push(cleanRow)
    })
    return { venues: cleaned }
  }

  exports.showOnMap = function(map, objects) {
    mapMarkers.forEach(function(marker) { marker.setMap(null) })
    mapMarkers = objects.map(function(obj) {
      var pos = new google.maps.LatLng(obj.lat, obj.lon)
      var marker = new google.maps.Marker({map: map, position: pos})
      marker.setVisible(true)
      google.maps.event.addListener(marker, 'click', function() {
        var html = '
'
        Object.keys(obj).map(function(key) {
          if (key === 'lat' || key === 'lon') return
          html += '
' + key + '

' + obj[key] + '
'
        })
        html += '
'
        var infoWindow = new google.maps.InfoWindow()
        infoWindow.setContent(html)
        infoWindow.open(map, marker)
      })
      return marker
    })
  }

  exports.filter = function(objects, conditions) {
    var results = []
    conditions.map(function(condition) {
      objects.map(function(obj) {
        if (condition(object)) results.push(obj)
      })
    })
    return _.uniq(results)
  }

})(window)
<commit_msg>use .location.lat and .location.lng<commit_after>(function(exports) {
  var mapMarkers = []

  exports.fetchFusionTablesData = function(fusionTablesID, callback) {
    $.ajax({
      dataType: 'jsonp',
      url: 'https://fusiontables.googleusercontent.com/fusiontables/api/query?sql=SELECT+*+FROM+' + fusionTablesID + '&jsonCallback=?',
      success: function(data) {
        callback(false, exports.formatData(data))
      },
      error: function(err) {
        callback(err)
      }
    })
  }

  exports.fetchJSON = function(url, cb) {
    $.ajax({
      dataType: 'json',
      url: url,
      success: function(data) {
        cb(false, eval(data))
      },
      error: function(xhr, status, err) {
        cb(err)
      }
    })
  }

  // accepts data from fusion tables JSON API
  exports.formatData = function(data) {
    var cleaned = []
    data.table.rows.forEach(function(row) {
      var cleanRow = {}
      for (var i = 0; i < row.length - 1; i++) {
        cleanRow[data.table.cols[i]] = row[i]
      }
      cleaned.push(cleanRow)
    })
    return { venues: cleaned }
  }

  exports.showOnMap = function(map, objects) {
    mapMarkers.forEach(function(marker) { if (marker) marker.setMap(null) })
    mapMarkers = objects.map(function(obj) {
      if (!obj.location) return
      var pos = new google.maps.LatLng(obj.location.lat, obj.location.lng)
      var marker = new google.maps.Marker({map: map, position: pos})
      marker.setVisible(true)
      google.maps.event.addListener(marker, 'click', function() {
        var html = '
'
        Object.keys(obj).map(function(key) {
          if (key === 'lat' || key === 'lon') return
          html += '
' + key + '

' + obj[key] + '
'
        })
        html += '
'
        var infoWindow = new google.maps.InfoWindow()
        infoWindow.setContent(html)
        infoWindow.open(map, marker)
      })
      return marker
    })
  }

  exports.filter = function(objects, conditions) {
    var results = []
    conditions.map(function(condition) {
      objects.map(function(obj) {
        if (condition(object)) results.push(obj)
      })
    })
    return _.uniq(results)
  }

})(window)
<|endoftext|>


<commit_before>exports.constants = [[1,"frameMethod"],[2,"frameHeader"],[3,"frameBody"],[8,"frameHeartbeat"],[200,"replySuccess"],[206,"frameEnd"],[311,"contentTooLarge"],[313,"noConsumers"],[320,"connectionForced"],[402,"invalidPath"],[403,"accessRefused"],[404,"notFound"],[405,"resourceLocked"],[406,"preconditionFailed"],[501,"frameError"],[502,"syntaxError"],[503,"commandInvalid"],[504,"channelError"],[505,"unexpectedFrame"],[506,"resourceError"],[530,"notAllowed"],[540,"notImplemented"],[541,"internalError"],[4096,"frameMinSize"]];
exports.classes = [   {      "name":"connection",      "index":10,      "fields":[      ],      "methods":[         {            "name":"start",            "index":10,            "fields":[               {                  "name":"versionMajor",                  "domain":"octet"               },               {                  "name":"versionMinor",                  "domain":"octet"               },               {                  "name":"serverProperties",                  "domain":"table"               },               {                  "name":"mechanisms",                  "domain":"longstr"               },               {                  "name":"locales",                  "domain":"longstr"               }            ]         },         {            "name":"startOk",            "index":11,            "fields":[               {                  "name":"clientProperties",                  "domain":"table"               },               {                  "name":"mechanism",                  "domain":"shortstr"               },               {                  "name":"response",                  "domain":"longstr"               },               {                  "name":"locale",                  "domain":"shortstr"               }            ]         },         {            "name":"secure",            "index":20,            "fields":[               {                  "name":"challenge",                  "domain":"longstr"               }            ]         },         {            "name":"secureOk",            "index":21,            "fields":[               {                  "name":"response",                  "domain":"longstr"               }            ]         },         {            "name":"tune",            "index":30,            "fields":[               {                  "name":"channelMax",                  "domain":"short"               },               {                  "name":"frameMax",                  "domain":"long"               },               {                  "name":"heartbeat",                  "domain":"short"               }            ]         },         {            "name":"tuneOk",            "index":31,            "fields":[               {                  "name":"channelMax",                  "domain":"short"               },               {                  "name":"frameMax",                  "domain":"long"               },               {                  "name":"heartbeat",                  "domain":"short"               }            ]         },         {            "name":"open",            "index":40,            "fields":[               {                  "name":"virtualHost",                  "domain":"shortstr"               },               {                  "name":"reserved1",                  "domain":"shortstr"               },               {                  "name":"reserved2",                  "domain":"bit"               }            ]         },         {            "name":"openOk",            "index":41,            "fields":[               {                  "name":"reserved1",                  "domain":"shortstr"               }            ]         },         {            "name":"close",            "index":50,            "fields":[               {                  "name":"replyCode",                  "domain":"short"               },               {                  "name":"replyText",                  "domain":"shortstr"               },               {                  "name":"classId",                  "domain":"short"               },               {                  "name":"methodId",                  "domain":"short"               }            ]         },         {            "name":"closeOk",            "index":51,            "fields":[            ]         }      ]   },   {      "name":"channel",      "index":20,      "fields":[      ],      "methods":[         {            "name":"open",            "index":10,            "fields":[               {                  "name":"reserved1",                  "domain":"shortstr"               }            ]         },         {            "name":"openOk",            "index":11,            "fields":[               {                  "name":"reserved1",                  "domain":"longstr"               }            ]         },         {            "name":"flow",            "index":20,            "fields":[               {                  "name":"active",                  "domain":"bit"               }            ]         },         {            "name":"flowOk",            "index":21,            "fields":[               {                  "name":"active",                  "domain":"bit"               }            ]         },         {            "name":"close",            "index":40,            "fields":[               {                  "name":"replyCode",                  "domain":"short"               },               {                  "name":"replyText",                  "domain":"shortstr"               },               {                  "name":"classId",                  "domain":"short"               },               {                  "name":"methodId",                  "domain":"short"               }            ]         },         {            "name":"closeOk",            "index":41,            "fields":[            ]         }      ]   },   {      "name":"exchange",      "index":40,      "fields":[      ],      "methods":[         {            "name":"declare",            "index":10,            "fields":[               {                  "name":"reserved1",                  "domain":"short"               },               {                  "name":"exchange",                  "domain":"shortstr"               },               {                  "name":"type",                  "domain":"shortstr"               },               {                  "name":"passive",                  "domain":"bit"               },               {                  "name":"durable",                  "domain":"bit"               },               {                  "name":"autoDelete",                  "domain":"bit"               },               {                  "name":"reserved2",                  "domain":"bit"               },               {                  "name":"reserved3",                  "domain":"bit"               },               {                  "name":"noWait",                  "domain":"bit"               },               {                  "name":"arguments",                  "domain":"table"               }            ]         },         {            "name":"declareOk",            "index":11,            "fields":[            ]         },         {            "name":"delete",            "index":20,            "fields":[               {                  "name":"reserved1",                  "domain":"short"               },               {                  "name":"exchange",                  "domain":"shortstr"               },               {                  "name":"ifUnused",                  "domain":"bit"               },               {                  "name":"noWait",                  "domain":"bit"               }            ]         },         {            "name":"deleteOk",            "index":21,            "fields":[            ]         }      ]   },   {      "name":"queue",      "index":50,      "fields":[      ],      "methods":[         {            "name":"declare",            "index":10,            "fields":[               {                  "name":"reserved1",                  "domain":"short"               },               {                  "name":"queue",                  "domain":"shortstr"               },               {                  "name":"passive",                  "domain":"bit"               },               {                  "name":"durable",                  "domain":"bit"               },               {                  "name":"exclusive",                  "domain":"bit"               },               {                  "name":"autoDelete",                  "domain":"bit"               },               {                  "name":"noWait",                  "domain":"bit"               },               {                  "name":"arguments",                  "domain":"table"               }            ]         },         {            "name":"declareOk",            "index":11,            "fields":[               {                  "name":"queue",                  "domain":"shortstr"               },               {                  "name":"messageCount",                  "domain":"long"               },               {                  "name":"consumerCount",                  "domain":"long"               }            ]         },         {            "name":"bind",            "index":20,            "fields":[               {                  "name":"reserved1",                  "domain":"short"               },               {                  "name":"queue",                  "domain":"shortstr"               },               {                  "name":"exchange",                  "domain":"shortstr"               },               {                  "name":"routingKey",                  "domain":"shortstr"               },               {                  "name":"noWait",                  "domain":"bit"               },               {                  "name":"arguments",                  "domain":"table"               }            ]         },         {            "name":"bindOk",            "index":21,            "fields":[            ]         },         {            "name":"unbind",            "index":50,            "fields":[               {                  "name":"reserved1",                  "domain":"short"               },               {                  "name":"queue",                  "domain":"shortstr"               },               {                  "name":"exchange",                  "domain":"shortstr"               },               {                  "name":"routingKey",                  "domain":"shortstr"               },               {                  "name":"arguments",                  "domain":"table"               }            ]         },         {            "name":"unbindOk",            "index":51,            "fields":[            ]         },         {            "name":"purge",            "index":30,            "fields":[               {                  "name":"reserved1",                  "domain":"short"               },               {                  "name":"queue",                  "domain":"shortstr"               },               {                  "name":"noWait",                  "domain":"bit"               }            ]         },         {            "name":"purgeOk",            "index":31,            "fields":[               {                  "name":"messageCount",                  "domain":"long"               }            ]         },         {            "name":"delete",            "index":40,            "fields":[               {                  "name":"reserved1",                  "domain":"short"               },               {                  "name":"queue",                  "domain":"shortstr"               },               {                  "name":"ifUnused",                  "domain":"bit"               },               {                  "name":"ifEmpty",                  "domain":"bit"               },               {                  "name":"noWait",                  "domain":"bit"               }            ]         },         {            "name":"deleteOk",            "index":41,            "fields":[               {                  "name":"messageCount",                  "domain":"long"               }            ]         }      ]   },   {      "name":"basic",      "index":60,      "fields":[         {            "name":"contentType",            "domain":"shortstr"         },         {            "name":"contentEncoding",            "domain":"shortstr"         },         {            "name":"headers",            "domain":"table"         },         {            "name":"deliveryMode",            "domain":"octet"         },         {            "name":"priority",            "domain":"octet"         },         {            "name":"correlationId",            "domain":"shortstr"         },         {            "name":"replyTo",            "domain":"shortstr"         },         {            "name":"expiration",            "domain":"shortstr"         },         {            "name":"messageId",            "domain":"shortstr"         },         {            "name":"timestamp",            "domain":"timestamp"         },         {            "name":"type",            "domain":"shortstr"         },         {            "name":"userId",            "domain":"shortstr"         },         {            "name":"appId",            "domain":"shortstr"         },         {            "name":"reserved",            "domain":"shortstr"         }      ],      "methods":[         {            "name":"qos",            "index":10,            "fields":[               {                  "name":"prefetchSize",                  "domain":"long"               },               {                  "name":"prefetchCount",                  "domain":"short"               },               {                  "name":"global",                  "domain":"bit"               }            ]         },         {            "name":"qosOk",            "index":11,            "fields":[            ]         },         {            "name":"consume",            "index":20,            "fields":[               {                  "name":"reserved1",                  "domain":"short"               },               {                  "name":"queue",                  "domain":"shortstr"               },               {                  "name":"consumerTag",                  "domain":"shortstr"               },               {                  "name":"noLocal",                  "domain":"bit"               },               {                  "name":"noAck",                  "domain":"bit"               },               {                  "name":"exclusive",                  "domain":"bit"               },               {                  "name":"noWait",                  "domain":"bit"               },               {                  "name":"arguments",                  "domain":"table"               }            ]         },         {            "name":"consumeOk",            "index":21,            "fields":[               {                  "name":"consumerTag",                  "domain":"shortstr"               }            ]         },         {            "name":"cancel",            "index":30,            "fields":[               {                  "name":"consumerTag",                  "domain":"shortstr"               },               {                  "name":"noWait",                  "domain":"bit"               }            ]         },         {            "name":"cancelOk",            "index":31,            "fields":[               {                  "name":"consumerTag",                  "domain":"shortstr"               }            ]         },         {            "name":"publish",            "index":40,            "fields":[               {                  "name":"reserved1",                  "domain":"short"               },               {                  "name":"exchange",                  "domain":"shortstr"               },               {                  "name":"routingKey",                  "domain":"shortstr"               },               {                  "name":"mandatory",                  "domain":"bit"               },               {                  "name":"immediate",                  "domain":"bit"               }            ]         },         {            "name":"return",            "index":50,            "fields":[               {                  "name":"replyCode",                  "domain":"short"               },               {                  "name":"replyText",                  "domain":"shortstr"               },               {                  "name":"exchange",                  "domain":"shortstr"               },               {                  "name":"routingKey",                  "domain":"shortstr"               }            ]         },         {            "name":"deliver",            "index":60,            "fields":[               {                  "name":"consumerTag",                  "domain":"shortstr"               },               {                  "name":"deliveryTag",                  "domain":"longlong"               },               {                  "name":"redelivered",                  "domain":"bit"               },               {                  "name":"exchange",                  "domain":"shortstr"               },               {                  "name":"routingKey",                  "domain":"shortstr"               }            ]         },         {            "name":"get",            "index":70,            "fields":[               {                  "name":"reserved1",                  "domain":"short"               },               {                  "name":"queue",                  "domain":"shortstr"               },               {                  "name":"noAck",                  "domain":"bit"               }            ]         },         {            "name":"getOk",            "index":71,            "fields":[               {                  "name":"deliveryTag",                  "domain":"longlong"               },               {                  "name":"redelivered",                  "domain":"bit"               },               {                  "name":"exchange",                  "domain":"shortstr"               },               {                  "name":"routingKey",                  "domain":"shortstr"               },               {                  "name":"messageCount",                  "domain":"long"               }            ]         },         {            "name":"getEmpty",            "index":72,            "fields":[               {                  "name":"reserved1",                  "domain":"shortstr"               }            ]         },         {            "name":"ack",            "index":80,            "fields":[               {                  "name":"deliveryTag",                  "domain":"longlong"               },               {                  "name":"multiple",                  "domain":"bit"               }            ]         },         {            "name":"reject",            "index":90,            "fields":[               {                  "name":"deliveryTag",                  "domain":"longlong"               },               {                  "name":"requeue",                  "domain":"bit"               }            ]         },         {            "name":"recoverAsync",            "index":100,            "fields":[               {                  "name":"requeue",                  "domain":"bit"               }            ]         },         {            "name":"recover",            "index":110,            "fields":[               {                  "name":"requeue",                  "domain":"bit"               }            ]         },         {            "name":"recoverOk",            "index":111,            "fields":[            ]         }      ]   },   {      "name":"tx",      "index":90,      "fields":[      ],      "methods":[         {            "name":"select",            "index":10,            "fields":[            ]         },         {            "name":"selectOk",            "index":11,            "fields":[            ]         },         {            "name":"commit",            "index":20,            "fields":[            ]         },         {            "name":"commitOk",            "index":21,            "fields":[            ]         },         {            "name":"rollback",            "index":30,            "fields":[            ]         },         {            "name":"rollbackOk",            "index":31,            "fields":[            ]         }      ]   },   {      "name":"confirm",      "index":85,      "fields":[      ],      "methods":[         {            "name":"select",            "index":10,            "fields":[     {                  "name":"noWait",                  "domain":"bit"               }       ]         },         {            "name":"selectOk",            "index":11,            "fields":[            ]         }      ]   }];
<commit_msg>cleaned up the definitions<commit_after>exports.constants = [[1,"frameMethod"],[2,"frameHeader"],[3,"frameBody"],[8,"frameHeartbeat"],[200,"replySuccess"],[206,"frameEnd"],[311,"contentTooLarge"],[313,"noConsumers"],[320,"connectionForced"],[402,"invalidPath"],[403,"accessRefused"],[404,"notFound"],[405,"resourceLocked"],[406,"preconditionFailed"],[501,"frameError"],[502,"syntaxError"],[503,"commandInvalid"],[504,"channelError"],[505,"unexpectedFrame"],[506,"resourceError"],[530,"notAllowed"],[540,"notImplemented"],[541,"internalError"],[4096,"frameMinSize"]];
exports.classes = [{"name":"connection","index":10,"fields":[],"methods":[{"name":"start","index":10,"fields":[{"name":"versionMajor","domain":"octet"},{"name":"versionMinor","domain":"octet"},{"name":"serverProperties","domain":"table"},{"name":"mechanisms","domain":"longstr"},{"name":"locales","domain":"longstr"}]},{"name":"startOk","index":11,"fields":[{"name":"clientProperties","domain":"table"},{"name":"mechanism","domain":"shortstr"},{"name":"response","domain":"longstr"},{"name":"locale","domain":"shortstr"}]},{"name":"secure","index":20,"fields":[{"name":"challenge","domain":"longstr"}]},{"name":"secureOk","index":21,"fields":[{"name":"response","domain":"longstr"}]},{"name":"tune","index":30,"fields":[{"name":"channelMax","domain":"short"},{"name":"frameMax","domain":"long"},{"name":"heartbeat","domain":"short"}]},{"name":"tuneOk","index":31,"fields":[{"name":"channelMax","domain":"short"},{"name":"frameMax","domain":"long"},{"name":"heartbeat","domain":"short"}]},{"name":"open","index":40,"fields":[{"name":"virtualHost","domain":"shortstr"},{"name":"reserved1","domain":"shortstr"},{"name":"reserved2","domain":"bit"}]},{"name":"openOk","index":41,"fields":[{"name":"reserved1","domain":"shortstr"}]},{"name":"close","index":50,"fields":[{"name":"replyCode","domain":"short"},{"name":"replyText","domain":"shortstr"},{"name":"classId","domain":"short"},{"name":"methodId","domain":"short"}]},{"name":"closeOk","index":51,"fields":[]}]},{"name":"channel","index":20,"fields":[],"methods":[{"name":"open","index":10,"fields":[{"name":"reserved1","domain":"shortstr"}]},{"name":"openOk","index":11,"fields":[{"name":"reserved1","domain":"longstr"}]},{"name":"flow","index":20,"fields":[{"name":"active","domain":"bit"}]},{"name":"flowOk","index":21,"fields":[{"name":"active","domain":"bit"}]},{"name":"close","index":40,"fields":[{"name":"replyCode","domain":"short"},{"name":"replyText","domain":"shortstr"},{"name":"classId","domain":"short"},{"name":"methodId","domain":"short"}]},{"name":"closeOk","index":41,"fields":[]}]},{"name":"exchange","index":40,"fields":[],"methods":[{"name":"declare","index":10,"fields":[{"name":"reserved1","domain":"short"},{"name":"exchange","domain":"shortstr"},{"name":"type","domain":"shortstr"},{"name":"passive","domain":"bit"},{"name":"durable","domain":"bit"},{"name":"autoDelete","domain":"bit"},{"name":"reserved2","domain":"bit"},{"name":"reserved3","domain":"bit"},{"name":"noWait","domain":"bit"},{"name":"arguments","domain":"table"}]},{"name":"declareOk","index":11,"fields":[]},{"name":"delete","index":20,"fields":[{"name":"reserved1","domain":"short"},{"name":"exchange","domain":"shortstr"},{"name":"ifUnused","domain":"bit"},{"name":"noWait","domain":"bit"}]},{"name":"deleteOk","index":21,"fields":[]}]},{"name":"queue","index":50,"fields":[],"methods":[{"name":"declare","index":10,"fields":[{"name":"reserved1","domain":"short"},{"name":"queue","domain":"shortstr"},{"name":"passive","domain":"bit"},{"name":"durable","domain":"bit"},{"name":"exclusive","domain":"bit"},{"name":"autoDelete","domain":"bit"},{"name":"noWait","domain":"bit"},{"name":"arguments","domain":"table"}]},{"name":"declareOk","index":11,"fields":[{"name":"queue","domain":"shortstr"},{"name":"messageCount","domain":"long"},{"name":"consumerCount","domain":"long"}]},{"name":"bind","index":20,"fields":[{"name":"reserved1","domain":"short"},{"name":"queue","domain":"shortstr"},{"name":"exchange","domain":"shortstr"},{"name":"routingKey","domain":"shortstr"},{"name":"noWait","domain":"bit"},{"name":"arguments","domain":"table"}]},{"name":"bindOk","index":21,"fields":[]},{"name":"unbind","index":50,"fields":[{"name":"reserved1","domain":"short"},{"name":"queue","domain":"shortstr"},{"name":"exchange","domain":"shortstr"},{"name":"routingKey","domain":"shortstr"},{"name":"arguments","domain":"table"}]},{"name":"unbindOk","index":51,"fields":[]},{"name":"purge","index":30,"fields":[{"name":"reserved1","domain":"short"},{"name":"queue","domain":"shortstr"},{"name":"noWait","domain":"bit"}]},{"name":"purgeOk","index":31,"fields":[{"name":"messageCount","domain":"long"}]},{"name":"delete","index":40,"fields":[{"name":"reserved1","domain":"short"},{"name":"queue","domain":"shortstr"},{"name":"ifUnused","domain":"bit"},{"name":"ifEmpty","domain":"bit"},{"name":"noWait","domain":"bit"}]},{"name":"deleteOk","index":41,"fields":[{"name":"messageCount","domain":"long"}]}]},{"name":"basic","index":60,"fields":[{"name":"contentType","domain":"shortstr"},{"name":"contentEncoding","domain":"shortstr"},{"name":"headers","domain":"table"},{"name":"deliveryMode","domain":"octet"},{"name":"priority","domain":"octet"},{"name":"correlationId","domain":"shortstr"},{"name":"replyTo","domain":"shortstr"},{"name":"expiration","domain":"shortstr"},{"name":"messageId","domain":"shortstr"},{"name":"timestamp","domain":"timestamp"},{"name":"type","domain":"shortstr"},{"name":"userId","domain":"shortstr"},{"name":"appId","domain":"shortstr"},{"name":"reserved","domain":"shortstr"}],"methods":[{"name":"qos","index":10,"fields":[{"name":"prefetchSize","domain":"long"},{"name":"prefetchCount","domain":"short"},{"name":"global","domain":"bit"}]},{"name":"qosOk","index":11,"fields":[]},{"name":"consume","index":20,"fields":[{"name":"reserved1","domain":"short"},{"name":"queue","domain":"shortstr"},{"name":"consumerTag","domain":"shortstr"},{"name":"noLocal","domain":"bit"},{"name":"noAck","domain":"bit"},{"name":"exclusive","domain":"bit"},{"name":"noWait","domain":"bit"},{"name":"arguments","domain":"table"}]},{"name":"consumeOk","index":21,"fields":[{"name":"consumerTag","domain":"shortstr"}]},{"name":"cancel","index":30,"fields":[{"name":"consumerTag","domain":"shortstr"},{"name":"noWait","domain":"bit"}]},{"name":"cancelOk","index":31,"fields":[{"name":"consumerTag","domain":"shortstr"}]},{"name":"publish","index":40,"fields":[{"name":"reserved1","domain":"short"},{"name":"exchange","domain":"shortstr"},{"name":"routingKey","domain":"shortstr"},{"name":"mandatory","domain":"bit"},{"name":"immediate","domain":"bit"}]},{"name":"return","index":50,"fields":[{"name":"replyCode","domain":"short"},{"name":"replyText","domain":"shortstr"},{"name":"exchange","domain":"shortstr"},{"name":"routingKey","domain":"shortstr"}]},{"name":"deliver","index":60,"fields":[{"name":"consumerTag","domain":"shortstr"},{"name":"deliveryTag","domain":"longlong"},{"name":"redelivered","domain":"bit"},{"name":"exchange","domain":"shortstr"},{"name":"routingKey","domain":"shortstr"}]},{"name":"get","index":70,"fields":[{"name":"reserved1","domain":"short"},{"name":"queue","domain":"shortstr"},{"name":"noAck","domain":"bit"}]},{"name":"getOk","index":71,"fields":[{"name":"deliveryTag","domain":"longlong"},{"name":"redelivered","domain":"bit"},{"name":"exchange","domain":"shortstr"},{"name":"routingKey","domain":"shortstr"},{"name":"messageCount","domain":"long"}]},{"name":"getEmpty","index":72,"fields":[{"name":"reserved1","domain":"shortstr"}]},{"name":"ack","index":80,"fields":[{"name":"deliveryTag","domain":"longlong"},{"name":"multiple","domain":"bit"}]},{"name":"reject","index":90,"fields":[{"name":"deliveryTag","domain":"longlong"},{"name":"requeue","domain":"bit"}]},{"name":"recoverAsync","index":100,"fields":[{"name":"requeue","domain":"bit"}]},{"name":"recover","index":110,"fields":[{"name":"requeue","domain":"bit"}]},{"name":"recoverOk","index":111,"fields":[]}]},{"name":"tx","index":90,"fields":[],"methods":[{"name":"select","index":10,"fields":[]},{"name":"selectOk","index":11,"fields":[]},{"name":"commit","index":20,"fields":[]},{"name":"commitOk","index":21,"fields":[]},{"name":"rollback","index":30,"fields":[]},{"name":"rollbackOk","index":31,"fields":[]}]},{"name":"confirm","index":85,"fields":[],"methods":[{"name":"select","index":10,"fields":[{"name":"noWait","domain":"bit"}]},{"name":"selectOk","index":11,"fields":[]}]}];
<|endoftext|>


<commit_before>'use strict';

const CellXform = require('../../../../../lib/xlsx/xform/sheet/cell-xform');
const testXformHelper = require('./../test-xform-helper');

const SharedStringsXform = require('../../../../../lib/xlsx/xform/strings/shared-strings-xform');
const Enums = require('../../../../../lib/doc/enums');

const fakeStyles = {
  addStyleModel(style, effectiveType) {
    if (effectiveType === Enums.ValueType.Date) {
      return 1;
    }
    return 0;
  },
  getStyleModel(styleId) {
    switch (styleId) {
      case 1:
        return { numFmt: 'mm-dd-yy' };
      default:
        return null;
    }
  },
};

const fakeHyperlinkMap = {
  H1: 'http://www.foo.com',
};

const expectations = [
  {
    title: 'Styled Null',
    create() {
      return new CellXform();
    },
    preparedModel: { address: 'A1', type: Enums.ValueType.Null, styleId: 1 },
    xml: '<c r="A1" s="1" />',
    parsedModel: { address: 'A1', type: Enums.ValueType.Null, styleId: 1 },
    tests: ['render', 'renderIn', 'parse'],
  },
  {
    title: 'Number',
    create() {
      return new CellXform();
    },
    preparedModel: { address: 'A1', type: Enums.ValueType.Number, value: 5 },
    parsedModel: { address: 'A1', type: Enums.ValueType.Number, value: 5 },
    xml: '<c r="A1"><v>5</v></c>',
    tests: ['render', 'renderIn', 'parse'],
  },
  {
    title: 'Boolean',
    create() {
      return new CellXform();
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.Boolean,
      value: true,
    },
    parsedModel: { address: 'A1', type: Enums.ValueType.Boolean, value: true },
    xml: '<c r="A1" t="b"><v>1</v></c>',
    tests: ['render', 'renderIn', 'parse'],
  },
  {
    title: 'Error',
    create() {
      return new CellXform();
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.Error,
      value: { error: '#N/A' },
    },
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.Error,
      value: { error: '#N/A' },
    },
    xml: '<c r="A1" t="e"><v>#N/A</v></c>',
    tests: ['render', 'renderIn', 'parse'],
  },
  {
    title: 'String',
    create() {
      return new CellXform();
    },
    initialModel: { address: 'A1', type: Enums.ValueType.String, value: 'Foo' },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: 'Foo',
    },
    xml: '<c r="A1" t="str"><v>Foo</v></c>',
    parsedModel: { address: 'A1', type: Enums.ValueType.String, value: 'Foo' },
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: 'Foo',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: { hyperlinkMap: fakeHyperlinkMap, styles: fakeStyles },
  },
  {
    title: 'Inline String with plain text',
    create() {
      return new CellXform();
    },
    xml: '<c r="A1" t="inlineStr"><is><t>Foo</t></is></c>',
    parsedModel: { address: 'A1', type: Enums.ValueType.String, value: 'Foo' },
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: 'Foo',
    },
    tests: ['parse', 'reconcile'],
    options: { hyperlinkMap: fakeHyperlinkMap, styles: fakeStyles },
  },
  {
    title: 'Inline String with RichText',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: {
        richText: [
          { font: { color: { argb: 'FF0000' } }, text: 'red' },
          { font: { color: { argb: '00FF00' } }, text: 'green' },
        ],
      },
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: {
        richText: [
          { font: { color: { argb: 'FF0000' } }, text: 'red' },
          { font: { color: { argb: '00FF00' } }, text: 'green' },
        ],
      },
    },
    xml:
      '<c r="A1" t="inlineStr"><is><r><rPr><color rgb="FF0000"/></rPr><t>red</t></r><r><rPr><color rgb="00FF00"/></rPr><t>green</t></r></is></c>',
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: {
        richText: [
          { font: { color: { argb: 'FF0000' } }, text: 'red' },
          { font: { color: { argb: '00FF00' } }, text: 'green' },
        ],
      },
    },
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.RichText,
      value: {
        richText: [
          { font: { color: { argb: 'FF0000' } }, text: 'red' },
          { font: { color: { argb: '00FF00' } }, text: 'green' },
        ],
      },
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: { hyperlinkMap: fakeHyperlinkMap, styles: fakeStyles },
  },
  {
    title: 'Shared String',
    create() {
      return new CellXform();
    },
    initialModel: { address: 'A1', type: Enums.ValueType.String, value: 'Foo' },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: 'Foo',
      ssId: 0,
    },
    xml: '<c r="A1" t="s"><v>0</v></c>',
    parsedModel: { address: 'A1', type: Enums.ValueType.String, value: 0 },
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: 'Foo',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      sharedStrings: new SharedStringsXform(),
      hyperlinkMap: fakeHyperlinkMap,
      styles: fakeStyles,
    },
  },
  {
    title: 'Date',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'A1',
      type: Enums.ValueType.Date,
      value: new Date('2016-06-09T00:00:00.000Z'),
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.Date,
      value: new Date('2016-06-09T00:00:00.000Z'),
      styleId: 1,
    },
    xml: '<c r="A1" s="1"><v>42530</v></c>',
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.Number,
      value: 42530,
      styleId: 1,
    },
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.Date,
      value: new Date('2016-06-09T00:00:00.000Z'),
      style: { numFmt: 'mm-dd-yy' },
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      sharedStrings: new SharedStringsXform(),
      hyperlinks: [],
      hyperlinkMap: fakeHyperlinkMap,
      styles: fakeStyles,
    },
  },
  {
    title: 'Hyperlink',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'H1',
      type: Enums.ValueType.Hyperlink,
      hyperlink: 'http://www.foo.com',
      text: 'www.foo.com',
    },
    preparedModel: {
      address: 'H1',
      type: Enums.ValueType.Hyperlink,
      hyperlink: 'http://www.foo.com',
      text: 'www.foo.com',
      ssId: 0,
    },
    xml: '<c r="H1" t="s"><v>0</v></c>',
    parsedModel: { address: 'H1', type: Enums.ValueType.String, value: 0 },
    reconciledModel: {
      address: 'H1',
      type: Enums.ValueType.Hyperlink,
      text: 'www.foo.com',
      hyperlink: 'http://www.foo.com',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      sharedStrings: new SharedStringsXform(),
      hyperlinks: [],
      hyperlinkMap: fakeHyperlinkMap,
      styles: fakeStyles,
    },
  },
  {
    title: 'String Formula',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 'Foo',
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 'Foo',
    },
    xml: '<c r="A1" t="str"><f>A2</f><v>Foo</v></c>',
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 'Foo',
    },
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 'Foo',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      sharedStrings: new SharedStringsXform(),
      hyperlinks: [],
      hyperlinkMap: fakeHyperlinkMap,
      styles: fakeStyles,
      formulae: {},
      siFormulae: 0,
    },
  },
  {
    title: 'Number Formula',
    create() {
      return new CellXform();
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 7,
    },
    xml: '<c r="A1"><f>A2</f><v>7</v></c>',
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 7,
    },
    tests: ['render', 'renderIn', 'parse'],
    options: { formulae: {}, siFormulae: 0 },
  },
  {
    title: 'Shared Formula',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      sharedFormula: 'A1',
      result: 2,
    },
    preparedModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      sharedFormula: 'A1',
      result: 2,
      si: 0,
    },
    xml: '<c r="A2"><f t="shared" si="0" /><v>2</v></c>',
    parsedModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      result: 2,
      si: '0',
      sharedFormula: true,
    },
    reconciledModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      result: 2,
      sharedFormula: 'A1',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      styles: fakeStyles,
      hyperlinks: [],
      hyperlinkMap: fakeHyperlinkMap,
      formulae: {
        A1: {
          address: 'A1',
          type: Enums.ValueType.Formula,
          formula: 'ROW()',
          result: 1,
        },
        0: {
          address: 'A1',
          type: Enums.ValueType.Formula,
          formula: 'ROW()',
          result: 1,
          si: '0',
        },
      },
      siFormulae: 0,
    },
  },
  {
    title: 'Master Shared Formula',
    create() {
      return new CellXform();
    },
    preparedModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      formula: 'A1',
      result: 2,
      si: 0,
    },
    xml: '<c r="A2"><f t="shared" si="0">A1</f><v>2</v></c>',
    parsedModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      formula: 'A1',
      result: 2,
      si: '0',
      sharedFormula: true,
    },
    reconciledModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      formula: 'A1',
      result: 2,
    },
    tests: ['render', 'renderIn', 'parse', 'reconcile'],
    options: {
      styles: fakeStyles,
      hyperlinks: [],
      hyperlinkMap: fakeHyperlinkMap,
      formulae: {},
      siFormulae: 0,
    },
  },
];

describe('CellXform', () => {
  testXformHelper(expectations);
});
<commit_msg>Adding tests<commit_after>'use strict';

const CellXform = require('../../../../../lib/xlsx/xform/sheet/cell-xform');
const testXformHelper = require('./../test-xform-helper');

const SharedStringsXform = require('../../../../../lib/xlsx/xform/strings/shared-strings-xform');
const Enums = require('../../../../../lib/doc/enums');

const fakeStyles = {
  addStyleModel(style, effectiveType) {
    if (effectiveType === Enums.ValueType.Date) {
      return 1;
    }
    return 0;
  },
  getStyleModel(styleId) {
    switch (styleId) {
      case 1:
        return {numFmt: 'mm-dd-yy'};
      default:
        return null;
    }
  },
};

const fakeHyperlinkMap = {
  H1: 'http://www.foo.com',
};

const expectations = [
  {
    title: 'Styled Null',
    create() {
      return new CellXform();
    },
    preparedModel: {address: 'A1', type: Enums.ValueType.Null, styleId: 1},
    xml: '<c r="A1" s="1" />',
    parsedModel: {address: 'A1', type: Enums.ValueType.Null, styleId: 1},
    tests: ['render', 'renderIn', 'parse'],
  },
  {
    title: 'Number',
    create() {
      return new CellXform();
    },
    preparedModel: {address: 'A1', type: Enums.ValueType.Number, value: 5},
    parsedModel: {address: 'A1', type: Enums.ValueType.Number, value: 5},
    xml: '<c r="A1"><v>5</v></c>',
    tests: ['render', 'renderIn', 'parse'],
  },
  {
    title: 'Boolean',
    create() {
      return new CellXform();
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.Boolean,
      value: true,
    },
    parsedModel: {address: 'A1', type: Enums.ValueType.Boolean, value: true},
    xml: '<c r="A1" t="b"><v>1</v></c>',
    tests: ['render', 'renderIn', 'parse'],
  },
  {
    title: 'Error',
    create() {
      return new CellXform();
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.Error,
      value: {error: '#N/A'},
    },
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.Error,
      value: {error: '#N/A'},
    },
    xml: '<c r="A1" t="e"><v>#N/A</v></c>',
    tests: ['render', 'renderIn', 'parse'],
  },
  {
    title: 'String',
    create() {
      return new CellXform();
    },
    initialModel: {address: 'A1', type: Enums.ValueType.String, value: 'Foo'},
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: 'Foo',
    },
    xml: '<c r="A1" t="str"><v>Foo</v></c>',
    parsedModel: {address: 'A1', type: Enums.ValueType.String, value: 'Foo'},
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: 'Foo',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {hyperlinkMap: fakeHyperlinkMap, styles: fakeStyles},
  },
  {
    title: 'String with Invalid Number',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: '6E1000',
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: '6E1000',
    },
    xml: '<c r="A1" t="str"><v>6E1000</v></c>',
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: '6E1000',
    },
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: '6E1000',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      hyperlinkMap: fakeHyperlinkMap,
      styles: fakeStyles,
    },
  },
  {
    title: 'Inline String with plain text',
    create() {
      return new CellXform();
    },
    xml: '<c r="A1" t="inlineStr"><is><t>Foo</t></is></c>',
    parsedModel: {address: 'A1', type: Enums.ValueType.String, value: 'Foo'},
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: 'Foo',
    },
    tests: ['parse', 'reconcile'],
    options: {hyperlinkMap: fakeHyperlinkMap, styles: fakeStyles},
  },
  {
    title: 'Inline String with RichText',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: {
        richText: [
          {font: {color: {argb: 'FF0000'}}, text: 'red'},
          {font: {color: {argb: '00FF00'}}, text: 'green'},
        ],
      },
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: {
        richText: [
          {font: {color: {argb: 'FF0000'}}, text: 'red'},
          {font: {color: {argb: '00FF00'}}, text: 'green'},
        ],
      },
    },
    xml:
      '<c r="A1" t="inlineStr"><is><r><rPr><color rgb="FF0000"/></rPr><t>red</t></r><r><rPr><color rgb="00FF00"/></rPr><t>green</t></r></is></c>',
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: {
        richText: [
          {font: {color: {argb: 'FF0000'}}, text: 'red'},
          {font: {color: {argb: '00FF00'}}, text: 'green'},
        ],
      },
    },
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.RichText,
      value: {
        richText: [
          {font: {color: {argb: 'FF0000'}}, text: 'red'},
          {font: {color: {argb: '00FF00'}}, text: 'green'},
        ],
      },
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {hyperlinkMap: fakeHyperlinkMap, styles: fakeStyles},
  },
  {
    title: 'Shared String',
    create() {
      return new CellXform();
    },
    initialModel: {address: 'A1', type: Enums.ValueType.String, value: 'Foo'},
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: 'Foo',
      ssId: 0,
    },
    xml: '<c r="A1" t="s"><v>0</v></c>',
    parsedModel: {address: 'A1', type: Enums.ValueType.String, value: 0},
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.String,
      value: 'Foo',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      sharedStrings: new SharedStringsXform(),
      hyperlinkMap: fakeHyperlinkMap,
      styles: fakeStyles,
    },
  },
  {
    title: 'Date',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'A1',
      type: Enums.ValueType.Date,
      value: new Date('2016-06-09T00:00:00.000Z'),
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.Date,
      value: new Date('2016-06-09T00:00:00.000Z'),
      styleId: 1,
    },
    xml: '<c r="A1" s="1"><v>42530</v></c>',
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.Number,
      value: 42530,
      styleId: 1,
    },
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.Date,
      value: new Date('2016-06-09T00:00:00.000Z'),
      style: {numFmt: 'mm-dd-yy'},
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      sharedStrings: new SharedStringsXform(),
      hyperlinks: [],
      hyperlinkMap: fakeHyperlinkMap,
      styles: fakeStyles,
    },
  },
  {
    title: 'Hyperlink',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'H1',
      type: Enums.ValueType.Hyperlink,
      hyperlink: 'http://www.foo.com',
      text: 'www.foo.com',
    },
    preparedModel: {
      address: 'H1',
      type: Enums.ValueType.Hyperlink,
      hyperlink: 'http://www.foo.com',
      text: 'www.foo.com',
      ssId: 0,
    },
    xml: '<c r="H1" t="s"><v>0</v></c>',
    parsedModel: {address: 'H1', type: Enums.ValueType.String, value: 0},
    reconciledModel: {
      address: 'H1',
      type: Enums.ValueType.Hyperlink,
      text: 'www.foo.com',
      hyperlink: 'http://www.foo.com',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      sharedStrings: new SharedStringsXform(),
      hyperlinks: [],
      hyperlinkMap: fakeHyperlinkMap,
      styles: fakeStyles,
    },
  },
  {
    title: 'String Formula',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 'Foo',
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 'Foo',
    },
    xml: '<c r="A1" t="str"><f>A2</f><v>Foo</v></c>',
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 'Foo',
    },
    reconciledModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 'Foo',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      sharedStrings: new SharedStringsXform(),
      hyperlinks: [],
      hyperlinkMap: fakeHyperlinkMap,
      styles: fakeStyles,
      formulae: {},
      siFormulae: 0,
    },
  },
  {
    title: 'Number Formula',
    create() {
      return new CellXform();
    },
    preparedModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 7,
    },
    xml: '<c r="A1"><f>A2</f><v>7</v></c>',
    parsedModel: {
      address: 'A1',
      type: Enums.ValueType.Formula,
      formula: 'A2',
      result: 7,
    },
    tests: ['render', 'renderIn', 'parse'],
    options: {formulae: {}, siFormulae: 0},
  },
  {
    title: 'Shared Formula',
    create() {
      return new CellXform();
    },
    initialModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      sharedFormula: 'A1',
      result: 2,
    },
    preparedModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      sharedFormula: 'A1',
      result: 2,
      si: 0,
    },
    xml: '<c r="A2"><f t="shared" si="0" /><v>2</v></c>',
    parsedModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      result: 2,
      si: '0',
      sharedFormula: true,
    },
    reconciledModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      result: 2,
      sharedFormula: 'A1',
    },
    tests: ['prepare', 'render', 'renderIn', 'parse', 'reconcile'],
    options: {
      styles: fakeStyles,
      hyperlinks: [],
      hyperlinkMap: fakeHyperlinkMap,
      formulae: {
        A1: {
          address: 'A1',
          type: Enums.ValueType.Formula,
          formula: 'ROW()',
          result: 1,
        },
        0: {
          address: 'A1',
          type: Enums.ValueType.Formula,
          formula: 'ROW()',
          result: 1,
          si: '0',
        },
      },
      siFormulae: 0,
    },
  },
  {
    title: 'Master Shared Formula',
    create() {
      return new CellXform();
    },
    preparedModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      formula: 'A1',
      result: 2,
      si: 0,
    },
    xml: '<c r="A2"><f t="shared" si="0">A1</f><v>2</v></c>',
    parsedModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      formula: 'A1',
      result: 2,
      si: '0',
      sharedFormula: true,
    },
    reconciledModel: {
      address: 'A2',
      type: Enums.ValueType.Formula,
      formula: 'A1',
      result: 2,
    },
    tests: ['render', 'renderIn', 'parse', 'reconcile'],
    options: {
      styles: fakeStyles,
      hyperlinks: [],
      hyperlinkMap: fakeHyperlinkMap,
      formulae: {},
      siFormulae: 0,
    },
  },
];

describe('CellXform', () => {
  testXformHelper(expectations);
});
<|endoftext|>