Code coverage report for src/components/qa/exercises.cjsx

Statements: 32.61% (15 / 46)      Branches: 0% (0 / 14)      Functions: 0% (0 / 13)      Lines: 32.61% (15 / 46)      Ignored: none     

All files » src/components/qa/ » exercises.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 131 132 133 134 135                                                                                                                                                                                                                                                
var BS, BindStoreMixin, EcosystemsStore, ExerciseActions, ExerciseCard, ExerciseStore, MultiSelect, QAExercises, React, ReferenceBookStore, SpyMode, String, _, classnames, ref;
 
_ = require('underscore');
 
BS = require('react-bootstrap');
 
React = require('react');
 
classnames = require('classnames');
 
SpyMode = require('openstax-react-components').SpyMode;
 
ReferenceBookStore = require('../../flux/reference-book').ReferenceBookStore;
 
ref = require('../../flux/exercise'), ExerciseStore = ref.ExerciseStore, ExerciseActions = ref.ExerciseActions;
 
EcosystemsStore = require('../../flux/ecosystems').EcosystemsStore;
 
String = require('../../helpers/string');
 
BindStoreMixin = require('../bind-store-mixin');
 
ExerciseCard = require('./exercise-card');
 
MultiSelect = require('../multi-select');
 
QAExercises = React.createClass({displayName: "QAExercises",
  propTypes: {
    cnxId: React.PropTypes.string.isRequired,
    ecosystemId: React.PropTypes.string.isRequired,
    section: React.PropTypes.string.isRequired
  },
  getInitialState: function() {
    return {
      pageId: 0,
      ignored: {}
    };
  },
  mixins: [BindStoreMixin],
  bindStore: ExerciseStore,
  componentWillMount: function() {
    return this.loadPage(this.props);
  },
  componentWillReceiveProps: function(nextProps) {
    if (nextProps.cnxId !== this.props.cnxId) {
      return this.loadPage(nextProps);
    }
  },
  loadPage: function(props) {
    var page;
    page = ReferenceBookStore.getPageInfo(props);
    this.setState({
      pageId: page.id
    });
    if (page && !ExerciseStore.isLoaded([page.id])) {
      return ExerciseActions.load(this.props.ecosystemId, [page.id], '');
    }
  },
  renderSpyInfo: function() {
    var book;
    book = EcosystemsStore.getBook(this.props.ecosystemId);
    return React.createElement(SpyMode.Content, {
      "className": "ecosystem-info"
    }, "Page: ", this.props.cnxId, " :: Book: ", book.uuid, "@", book.version);
  },
  onSelectPoolType: function(selection) {
    var ignored;
    ignored = _.clone(this.state.ignored);
    ignored[selection.id] = !ignored[selection.id];
    return this.setState({
      ignored: ignored
    });
  },
  on2StepPreviewChange: function(ev) {
    return this.setState({
      isShowing2StepPreview: ev.target.checked
    });
  },
  renderExerciseContent: function(exercises) {
    var classNames, selections;
    exercises = _.map(exercises, (function(_this) {
      return function(exercise) {
        var hideAnswers;
        hideAnswers = _this.state.isShowing2StepPreview && ExerciseStore.hasQuestionWithFormat('free-response', {
          exercise: exercise
        });
        return React.createElement(ExerciseCard, {
          "key": exercise.id,
          "exercise": exercise,
          "hideAnswers": hideAnswers,
          "ignoredPoolTypes": _this.state.ignored
        });
      };
    })(this));
    selections = _.map(ExerciseStore.getPagePoolTypes(this.state.pageId), (function(_this) {
      return function(pt) {
        return {
          id: pt,
          title: String.titleize(pt),
          selected: !_this.state.ignored[pt]
        };
      };
    })(this));
    classNames = classnames("exercises", {
      'show-2step': this.state.isShowing2StepPreview
    });
    return React.createElement("div", {
      "className": classNames
    }, React.createElement("div", {
      "className": "heading"
    }, React.createElement("label", null, "Show 2-Step Preview", React.createElement("input", {
      "type": 'checkbox',
      "className": 'preview2step',
      "checked": this.state.isShowing2StepPreview,
      "onChange": this.on2StepPreviewChange
    })), React.createElement(MultiSelect, {
      "title": 'Exercise Types',
      "selections": selections,
      "onSelect": this.onSelectPoolType
    })), exercises);
  },
  render: function() {
    var content, exercises;
    content = ExerciseStore.isLoaded([this.state.pageId]) ? (exercises = ExerciseStore.allForPage(this.state.pageId), _.isEmpty(exercises) ? React.createElement("h3", null, "No exercises found for section ", this.props.section) : this.renderExerciseContent(exercises)) : React.createElement("h3", null, "Loading...");
    return React.createElement("div", {
      "className": "page-wrapper"
    }, React.createElement("div", {
      "className": "exercises center-panel"
    }, content, (this.state.pageId ? this.renderSpyInfo() : void 0)));
  }
});
 
module.exports = QAExercises;