Code coverage report for src/components/task/crumb-mixin.cjsx

Statements: 96.88% (62 / 64)      Branches: 80% (16 / 20)      Functions: 100% (15 / 15)      Lines: 96.88% (62 / 64)      Ignored: none     

All files » src/components/task/ » crumb-mixin.cjsx
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           2297× 2297× 2297× 2297× 2297× 129× 129×         2297×     2197× 2197× 2197× 2197× 2197×     2197× 2197×     2197×     1678× 1678×     1678×     1282×   1678×     396× 396× 396× 396× 396× 1678×                   396× 396×             396×     396× 396× 396× 396× 396× 396×     396× 396× 396× 138× 276×   138× 123× 123×                 123× 123× 861×           396× 396× 396×     172× 172× 172×         24× 24× 24× 135×          
var TaskStepStore, TaskStore, _;
 
_ = require('underscore');
 
TaskStore = require('../../flux/task').TaskStore;
 
TaskStepStore = require('../../flux/task-step').TaskStepStore;
 
module.exports = {
  getDefaultCurrentStep: function() {
    var defaultIndex, id, steps;
    id = this.props.id;
    defaultIndex = TaskStore.getDefaultStepIndex(id);
    steps = TaskStore.getSteps(id);
    if (defaultIndex === -1) {
      Eif (TaskStore.isTaskCompleted(id)) {
        defaultIndex = steps.length;
      } else {
        defaultIndex = 0;
      }
    }
    return defaultIndex;
  },
  _shouldStepCrumb: function(index) {
    var doesAllowSeeAhead, id, latestIndex;
    id = this.props.id;
    latestIndex = this.getDefaultCurrentStep();
    doesAllowSeeAhead = TaskStore.doesAllowSeeAhead(id);
    return doesAllowSeeAhead || index <= latestIndex;
  },
  _getStepListeners: function(stepType) {
    var listeners;
    listeners = {
      placeholder: 3
    };
    return listeners[stepType] || 1;
  },
  _buildSectionLabel: function(chapter_section, crumbs) {
    var sectionLabel;
    Iif (chapter_section != null) {
      sectionLabel = typeof this.sectionFormat === "function" ? this.sectionFormat(chapter_section, this.props.sectionSeparator) : void 0;
    }
    if (_.findWhere(crumbs, {
      sectionLabel: sectionLabel
    }) != null) {
      sectionLabel = null;
    }
    return sectionLabel;
  },
  _generateCrumbsFromSteps: function(task, steps) {
    var crumbType, crumbs;
    crumbs = [];
    task.is_completed = TaskStore.isTaskCompleted(task.id);
    _.each(steps, (function(_this) {
      return function(step, index) {
        return crumbs.push({
          key: index,
          data: step,
          crumb: _this._shouldStepCrumb(index),
          sectionLabel: _this._buildSectionLabel(step.chapter_section, crumbs),
          type: 'step',
          listeners: _this._getStepListeners(step.type)
        });
      };
    })(this));
    crumbType = 'end';
    crumbs.push({
      key: steps.length,
      data: task,
      crumb: this._shouldStepCrumb(steps.length),
      type: crumbType,
      listeners: this._getStepListeners(crumbType)
    });
    return crumbs;
  },
  _generateCrumbs: function(id) {
    var crumbs, steps, task;
    task = TaskStore.get(id);
    steps = TaskStore.getSteps(id);
    crumbs = this._generateCrumbsFromSteps(task, steps);
    this._modifyCrumbs(task, crumbs);
    return crumbs;
  },
  _modifyCrumbs: function(task, crumbs) {
    var crumbType, currentStep, notCore, spacerCrumb;
    currentStep = this.props.currentStep;
    if (task.type === 'reading') {
      notCore = _.find(crumbs, function(crumb) {
        return (crumb.type === 'step') && !TaskStepStore.isCore(crumb.data.id);
      });
      if (notCore != null) {
        crumbType = 'spacer';
        spacerCrumb = {
          data: {
            task_id: task.id,
            type: 'coach'
          },
          crumb: this._shouldStepCrumb(notCore.key),
          type: crumbType,
          listeners: this._getStepListeners(crumbType)
        };
        crumbs.splice(notCore.key, 0, spacerCrumb);
        return _.each(crumbs, function(crumb, index) {
          return crumb.key = index;
        });
      }
    }
  },
  generateCrumbs: function() {
    var id;
    id = this.props.id;
    return this._generateCrumbs(id);
  },
  getCrumableCrumbs: function() {
    var allCrumbs, crumbableCrumbs;
    allCrumbs = this.generateCrumbs();
    return crumbableCrumbs = _.where(allCrumbs, {
      crumb: true
    });
  },
  getMaxListeners: function() {
    var crumbs, listeners;
    crumbs = this.generateCrumbs();
    return listeners = _.reduce(crumbs, function(memo, crumb) {
      return memo + crumb.listeners;
    }, 0);
  }
};