Code coverage report for src/components/task-plan/teacher-task-plans-listing.cjsx

Statements: 70.42% (50 / 71)      Branches: 50% (8 / 16)      Functions: 72.73% (8 / 11)      Lines: 70.42% (50 / 71)      Ignored: none     

All files » src/components/task-plan/ » teacher-task-plans-listing.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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169                                                                                                                                                         26× 26× 26× 26×           26× 13× 13× 13× 13×   13×       13×       13× 13× 13×     13× 13× 13×     17× 17× 17× 17×   17×     17× 17× 17× 17× 17× 17×         17×                   39×                      
var BS, CourseCalendar, CourseDataMixin, CourseStore, DATE_FORMAT, LoadableItem, React, Router, TaskPlanActions, TaskPlanStore, TeacherTaskPlanActions, TeacherTaskPlanListing, TeacherTaskPlanStore, TeacherTaskPlans, TimeHelper, TimeStore, _, moment, ref, ref1;
 
React = require('react');
 
moment = require('moment-timezone');
 
BS = require('react-bootstrap');
 
Router = require('react-router');
 
_ = require('underscore');
 
LoadableItem = require('../loadable-item');
 
ref = require('../../flux/teacher-task-plan'), TeacherTaskPlanStore = ref.TeacherTaskPlanStore, TeacherTaskPlanActions = ref.TeacherTaskPlanActions;
 
ref1 = require('../../flux/task-plan'), TaskPlanStore = ref1.TaskPlanStore, TaskPlanActions = ref1.TaskPlanActions;
 
CourseStore = require('../../flux/course').CourseStore;
 
TimeStore = require('../../flux/time').TimeStore;
 
TimeHelper = require('../../helpers/time');
 
DATE_FORMAT = 'YYYY-MM-DD';
 
CourseCalendar = require('../course-calendar');
 
CourseDataMixin = require('../course-data-mixin');
 
TeacherTaskPlans = React.createClass({displayName: "TeacherTaskPlans",
  contextTypes: {
    router: React.PropTypes.func
  },
  onEditPlan: function() {
    var courseId, id, plan, ref2, type;
    ref2 = this.props, courseId = ref2.courseId, plan = ref2.plan;
    id = plan.id, type = plan.type;
    if (type === 'reading') {
      return this.context.router.transitionTo('editReading', {
        courseId: courseId,
        id: id
      });
    } else if (type === 'homework') {
      return this.context.router.transitionTo('editHomework', {
        courseId: courseId,
        id: id
      });
    }
  },
  onViewStats: function() {
    var courseId, id, plan, ref2;
    ref2 = this.props, courseId = ref2.courseId, plan = ref2.plan;
    id = this.props.plan.id;
    return this.context.router.transitionTo('viewStats', {
      courseId: courseId,
      id: id
    });
  },
  render: function() {
    var duration, ending, plan, start;
    plan = this.props.plan;
    start = moment(plan.opens_at);
    ending = moment(plan.due_at);
    duration = moment.duration(ending.diff(start)).humanize();
    return React.createElement("div", {
      "className": '-list-item'
    }, React.createElement(BS.ListGroupItem, {
      "header": plan.title,
      "onClick": this.onEditPlan
    }, start.fromNow(), " (", duration, ")"), React.createElement(BS.Button, {
      "bsStyle": 'link',
      "className": '-tasks-list-stats-button',
      "onClick": this.onViewStats
    }, "View Stats"));
  }
});
 
TeacherTaskPlanListing = React.createClass({
  displayName: 'TeacherTaskPlanListing',
  contextTypes: {
    router: React.PropTypes.func
  },
  propTypes: {
    dateFormat: React.PropTypes.string
  },
  getDefaultProps: function() {
    return {
      dateFormat: DATE_FORMAT
    };
  },
  mixins: [CourseDataMixin],
  statics: {
    willTransitionTo: function(transition, params, query, callback) {
      var course, courseId, date, planId;
      date = params.date, planId = params.planId, courseId = params.courseId;
      course = CourseStore.get(courseId);
      Iif (course.is_concept_coach) {
        transition.redirect('cc-dashboard', {
          courseId: courseId
        });
        return callback();
      }
      if (!((date != null) && moment(date, DATE_FORMAT).isValid())) {
        date = moment(TimeStore.getNow());
        params.date = date.format(DATE_FORMAT);
        transition.redirect('calendarByDate', params);
        return callback();
      }
      Iif ((planId != null) && TaskPlanStore.isDeleteRequested(planId)) {
        transition.redirect('calendarByDate', _.omit(params, 'planId'));
        return callback();
      }
      return callback();
    }
  },
  componentWillMount: function() {
    var courseId;
    courseId = this.context.router.getCurrentParams().courseId;
    return TimeHelper.syncCourseTimezone(courseId);
  },
  componentWillUnmount: function() {
    var courseId;
    courseId = this.context.router.getCurrentParams().courseId;
    return TimeHelper.unsyncCourseTimezone(courseId);
  },
  getDateFromParams: function() {
    var date;
    date = this.context.router.getCurrentParams().date;
    Eif (date != null) {
      date = TimeHelper.getMomentPreserveDate(date, this.props.dateFormat);
    }
    return date;
  },
  render: function() {
    var courseDataProps, courseId, date, loadPlansList, loadedCalendarProps;
    courseId = this.context.router.getCurrentParams().courseId;
    courseDataProps = this.getCourseDataProps(courseId);
    date = this.getDateFromParams();
    loadPlansList = _.partial(TeacherTaskPlanStore.getActiveCoursePlans, courseId);
    loadedCalendarProps = {
      loadPlansList: loadPlansList,
      courseId: courseId,
      date: date
    };
    return React.createElement("div", React.__spread({}, courseDataProps, {
      "className": "tutor-booksplash-background"
    }), React.createElement(BS.Panel, {
      "className": 'list-courses',
      "bsStyle": 'primary'
    }, React.createElement(LoadableItem, {
      "store": TeacherTaskPlanStore,
      "actions": TeacherTaskPlanActions,
      "id": courseId,
      "renderItem": (function() {
        return React.createElement(CourseCalendar, React.__spread({}, loadedCalendarProps));
      }),
      "renderLoading": (function() {
        return React.createElement(CourseCalendar, {
          "className": 'calendar-loading'
        });
      })
    })));
  }
});
 
module.exports = TeacherTaskPlanListing;