Code coverage report for src/components/course-listing.cjsx

Statements: 84.62% (55 / 65)      Branches: 67.39% (31 / 46)      Functions: 88.89% (8 / 9)      Lines: 84.62% (55 / 65)      Ignored: none     

All files » src/components/ » course-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                                                       10×                         15× 15× 15× 15×   15× 19×   15×                                                                 15× 15×                                              
var BS, CourseDataMixin, CourseListing, CourseListingActions, CourseListingStore, DisplayOrRedirect, React, RefreshButton, Router, WindowHelpers, _, ref;
 
_ = require('underscore');
 
React = require('react');
 
BS = require('react-bootstrap');
 
Router = require('react-router');
 
WindowHelpers = require('../helpers/window');
 
ref = require('../flux/course-listing'), CourseListingActions = ref.CourseListingActions, CourseListingStore = ref.CourseListingStore;
 
RefreshButton = require('openstax-react-components').RefreshButton;
 
CourseDataMixin = require('./course-data-mixin');
 
DisplayOrRedirect = function(transition, callback) {
  var conceptCoach, course, courses, ref1, roleType, view;
  courses = CourseListingStore.allCourses() || [];
  course = courses[0];
  if (courses.length === 1 && ((ref1 = course.roles) != null ? ref1.length : void 0) === 1) {
    roleType = courses[0].roles[0].type;
    conceptCoach = courses[0].is_concept_coach;
    if (roleType === 'student') {
      if (conceptCoach && course.webview_url) {
        WindowHelpers.replaceBrowserLocation(course.webview_url);
      } else {
        view = 'viewStudentDashboard';
      }
    } else Eif (roleType === 'teacher') {
      view = conceptCoach ? 'cc-dashboard' : 'taskplans';
    } else {
      throw new Error("BUG: Unrecognized role type " + roleType);
    }
    if (view) {
      transition.redirect(view, {
        courseId: _.first(courses).id
      });
    }
  }
  return callback();
};
 
CourseListing = React.createClass({
  displayName: 'CourseListing',
  contextTypes: {
    router: React.PropTypes.func
  },
  mixins: [CourseDataMixin],
  statics: {
    willTransitionTo: function(transition, params, query, callback) {
      if (CourseListingStore.isFailed()) {
        return callback();
      } else Iif (!CourseListingStore.isLoaded()) {
        if (!CourseListingStore.isLoading()) {
          CourseListingActions.load();
        }
        CourseListingStore.once('failed', callback);
        return CourseListingStore.once('loaded', function() {
          return DisplayOrRedirect(transition, callback);
        });
      } else {
        return DisplayOrRedirect(transition, callback);
      }
    }
  },
  renderCourses: function(courses) {
    return _.map(courses, (function(_this) {
      return function(course) {
        var altLink, courseDataProps, courseId, courseLink, isConceptCoach, isStudent, isTeacher, name, roles, to;
        courseId = course.id, name = course.name, roles = course.roles, isConceptCoach = course.is_concept_coach;
        isStudent = _.find(roles, function(role) {
          return role.type === 'student';
        });
        isTeacher = _.find(roles, function(role) {
          return role.type === 'teacher';
        });
        if (isTeacher) {
          Iif (typeof courseLink !== "undefined" && courseLink !== null) {
            altLink = React.createElement(Router.Link, {
              "className": 'tutor-course-alt-link',
              "to": 'taskplans',
              "params": {
                courseId: courseId
              }
            }, "View as Teacher");
          } else {
            to = isConceptCoach ? 'cc-dashboard' : 'taskplans';
            courseLink = React.createElement(Router.Link, {
              "className": 'tutor-course-item',
              "to": to,
              "params": {
                courseId: courseId
              }
            }, course.name);
          }
        } else Eif (isStudent) {
          if (isConceptCoach) {
            courseLink = React.createElement("a", {
              "className": 'tutor-course-item',
              "href": course.webview_url
            }, course.name);
          } else {
            courseLink = React.createElement(Router.Link, {
              "className": 'tutor-course-item',
              "to": 'viewStudentDashboard',
              "params": {
                courseId: courseId
              }
            }, course.name);
          }
        } else {
          if (typeof console.warn === "function") {
            console.warn("BUG: User is not a teacher or a student on course id: " + course.id);
          }
          return null;
        }
        courseDataProps = _this.getCourseDataProps(courseId);
        return React.createElement(BS.Row, {
          "key": "course-" + courseId
        }, React.createElement(BS.Col, React.__spread({}, courseDataProps, {
          "className": 'tutor-booksplash-course-item',
          "xs": 12.
        }), courseLink, altLink));
      };
    })(this));
  },
  render: function() {
    var body, courses, refreshBtn;
    courses = CourseListingStore.allCourses() || [];
    body = courses.length ? React.createElement("div", {
      "className": '-course-list'
    }, this.renderCourses(courses)) : React.createElement("div", {
      "className": '-course-list-empty'
    }, "No Courses");
    if (!CourseListingStore.isLoaded()) {
      refreshBtn = React.createElement(RefreshButton, null);
    }
    return React.createElement("div", {
      "className": 'course-listing '
    }, body, refreshBtn);
  }
});
 
module.exports = {
  CourseListing: CourseListing
};