Code coverage report for src/flux/reference-book.coffee

Statements: 80.77% (63 / 78)      Branches: 54.17% (26 / 48)      Functions: 72.73% (8 / 11)      Lines: 80.77% (63 / 78)      Ignored: none     

All files » src/flux/ » reference-book.coffee
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133       1365× 1365× 1365× 808×   1365× 335× 335× 1311× 1311× 1311× 1616× 1616×       1365×     642× 642× 226×   416× 376× 376× 416× 416× 376×       40×         54×                           38× 38× 38× 64×   38× 38× 38× 38× 12×   26×             188× 188× 188×     188× 188×   188× 188× 312×   188×                     54× 54× 54× 54×     54× 54× 54× 62× 62× 54×                                
var CrudConfig, ReferenceBookConfig, _, actions, extendConfig, findAllPages, findChapterSection, makeSimpleStore, ref, ref1, store;
 
ref = require('./helpers'), CrudConfig = ref.CrudConfig, makeSimpleStore = ref.makeSimpleStore, extendConfig = ref.extendConfig;
 
_ = require('underscore');
 
findAllPages = function(section) {
  var child, i, j, len, len1, page, pages, ref1, ref2;
  pages = [];
  if (section.cnx_id && "page" === section.type) {
    pages.push(section);
  }
  if (section.children) {
    ref1 = section.children;
    for (i = 0, len = ref1.length; i < len; i++) {
      child = ref1[i];
      ref2 = findAllPages(child);
      for (j = 0, len1 = ref2.length; j < len1; j++) {
        page = ref2[j];
        pages.push(page);
      }
    }
  }
  return pages;
};
 
findChapterSection = function(section, chapter_section) {
  var child, found, i, len, ref1;
  if (_.isEqual(section.chapter_section, chapter_section)) {
    return section;
  }
  if (section.children) {
    ref1 = section.children;
    for (i = 0, len = ref1.length; i < len; i++) {
      child = ref1[i];
      if (found = findChapterSection(child, chapter_section)) {
        return found;
      }
    }
  }
  return null;
};
 
ReferenceBookConfig = {
  exports: {
    getToc: function(ecosystemId) {
      return this._get(ecosystemId)['0'];
    },
    getFirstSection: function(ecosystemId) {
      var children, ref1, ref2, toc;
      toc = (ref1 = this._get(ecosystemId)) != null ? ref1['0'] : void 0;
      if ((toc != null ? toc.children : void 0) == null) {
        return null;
      }
      children = toc.children;
      return (ref2 = _.chain(children).sortBy(function(child) {
        return child.chapter_section;
      }).first().value()) != null ? ref2.chapter_section : void 0;
    },
    getChapterSectionPage: function(arg) {
      var ecosystemId, parts, ref1, section, toc;
      ecosystemId = arg.ecosystemId, section = arg.section;
      parts = _.isArray(section) ? section : _.map(section.split('.'), function(part) {
        return parseInt(part, 10);
      });
      toc = (ref1 = this._get(ecosystemId)) != null ? ref1['0'] : void 0;
      section = findChapterSection(toc, parts);
      Eif (section) {
        if (section.type === "part") {
          return _.first(section != null ? section.children : void 0);
        } else {
          return section;
        }
      } else {
        return null;
      }
    },
    getPageTitle: function(arg) {
      var ecosystemId, ref1, ref2, section, toc;
      ecosystemId = arg.ecosystemId, section = arg.section;
      Iif (section == null) {
        return null;
      }
      Eif (!_.isArray(section)) {
        section = section.split('.');
      }
      toc = (ref1 = this._get(ecosystemId)) != null ? ref1['0'] : void 0;
      section = _.map(section, function(n) {
        return parseInt(n);
      });
      return (ref2 = findChapterSection(toc, section)) != null ? ref2.title : void 0;
    },
    getPages: function(ecosystemId) {
      var ref1, toc;
      toc = (ref1 = this._get(ecosystemId)) != null ? ref1['0'] : void 0;
      if (!toc) {
        return [];
      }
      return findAllPages(toc);
    },
    getPageInfo: function(arg) {
      var cnxId, ecosystemId, i, index, lastPage, len, page, pages, ref1, toc;
      ecosystemId = arg.ecosystemId, cnxId = arg.cnxId;
      toc = (ref1 = this._get(ecosystemId)) != null ? ref1['0'] : void 0;
      Iif (!toc) {
        return {};
      }
      pages = findAllPages(toc);
      lastPage = null;
      for (index = i = 0, len = pages.length; i < len; index = ++i) {
        page = pages[index];
        if (-1 !== page.cnx_id.indexOf(cnxId)) {
          return _.extend(_.clone(page), {
            prev: lastPage,
            next: pages[index + 1]
          });
        }
        lastPage = page;
      }
    }
  }
};
 
extendConfig(ReferenceBookConfig, new CrudConfig());
 
ref1 = makeSimpleStore(ReferenceBookConfig), actions = ref1.actions, store = ref1.store;
 
module.exports = {
  ReferenceBookActions: actions,
  ReferenceBookStore: store
};