Code coverage report for src/flux/course.coffee

Statements: 52.11% (37 / 71)      Branches: 44.44% (16 / 36)      Functions: 44.44% (12 / 27)      Lines: 52.11% (37 / 71)      Ignored: none     

All files » src/flux/ » course.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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154                                                                                 156×     39× 39× 39× 39×                                         13× 13×                                                           118× 118×     113× 113×     105× 105× 105×     67× 67×     38× 38×                                    
var CourseConfig, CrudConfig, DEFAULT_COURSE_TIMEZONE, PeriodHelper, TaskActions, TaskStore, _, actions, extendConfig, makeSimpleStore, ref, ref1, ref2, store;
 
_ = require('underscore');
 
ref = require('./task'), TaskActions = ref.TaskActions, TaskStore = ref.TaskStore;
 
ref1 = require('./helpers'), CrudConfig = ref1.CrudConfig, makeSimpleStore = ref1.makeSimpleStore, extendConfig = ref1.extendConfig;
 
PeriodHelper = require('../helpers/period');
 
DEFAULT_COURSE_TIMEZONE = 'US/Central';
 
CourseConfig = {
  _practices: {},
  _asyncStatusPractices: {},
  _isPractice: function(obj) {
    return obj.steps != null;
  },
  createPractice: function(courseId, params) {},
  createdPractice: function(obj, courseId, params) {
    obj.created_for = params;
    return this._loadedPractice(obj, courseId);
  },
  _guides: {},
  _asyncStatusGuides: {},
  loadGuide: function(courseId) {
    delete this._guides[courseId];
    this._asyncStatusGuides[courseId] = 'loading';
    return this.emitChange();
  },
  loadedGuide: function(obj, courseId) {
    this._guides[courseId] = obj;
    this._asyncStatusGuides[courseId] = 'loaded';
    return this.emitChange();
  },
  loadPractice: function(courseId) {
    delete this._practices[courseId];
    this._asyncStatusPractices[courseId] = 'loading';
    return this.emitChange();
  },
  loadedPractice: function(obj, courseId) {
    this._loadedPractice(obj, courseId);
    this._asyncStatusPractices[courseId] = 'loaded';
    return this.emitChange();
  },
  _loadedPractice: function(obj, courseId) {
    Iif (obj.type == null) {
      obj.type = 'practice';
    }
    this._practices[courseId] = obj;
    TaskActions.loaded(obj, obj.id);
    return this.emit('practice.loaded', obj.id);
  },
  _loaded: function(obj, id) {
    return this.emit('course.loaded', obj.id);
  },
  _reset: function() {
    this._guides = {};
    this._asyncStatusGuides = {};
    this._practices = {};
    return this._asyncStatusPractices = {};
  },
  exports: {
    getGuide: function(courseId) {
      return this._guides[courseId] || (function() {
        throw new Error('BUG: Not loaded yet');
      })();
    },
    isGuideLoading: function(courseId) {
      return this._asyncStatusGuides[courseId] === 'loading';
    },
    isGuideLoaded: function(courseId) {
      return !!this._guides[courseId];
    },
    isPracticeLoading: function(courseId) {
      return this._asyncStatusPractices[courseId] === 'loading';
    },
    isPracticeLoaded: function(courseId) {
      return !!this._practices[courseId];
    },
    getPracticeId: function(courseId) {
      var ref2;
      return (ref2 = this._practices[courseId]) != null ? ref2.id : void 0;
    },
    getPracticePageIds: function(courseId) {
      var ref2, ref3;
      return (ref2 = this._practices[courseId]) != null ? (ref3 = ref2.created_for) != null ? ref3.page_ids : void 0 : void 0;
    },
    hasPractice: function(courseId) {
      return this._practices[courseId] != null;
    },
    getPractice: function(courseId) {
      var id, task;
      if (this._practices[courseId] != null) {
        id = this._practices[courseId].id;
        task = TaskStore.get(id);
      }
      return task;
    },
    validateCourseName: function(name, courses, active) {
      var course, i, len;
      for (i = 0, len = courses.length; i < len; i++) {
        course = courses[i];
        if (course.name === name) {
          if (name !== active) {
            return ['courseNameExists'];
          }
        }
        if ((name == null) || name === '') {
          return ['required'];
        }
      }
    },
    getAppearanceCode: function(courseId) {
      var ref2;
      return ((ref2 = this._get(courseId)) != null ? ref2.appearance_code : void 0) || 'default';
    },
    getName: function(courseId) {
      var ref2;
      return ((ref2 = this._get(courseId)) != null ? ref2.name : void 0) || "";
    },
    getPeriods: function(courseId) {
      var periods, sortedPeriods;
      periods = this._get(courseId).periods || [];
      return sortedPeriods = PeriodHelper.sort(periods);
    },
    getTimezone: function(courseId) {
      var ref2;
      return ((ref2 = this._get(courseId)) != null ? ref2.timezone : void 0) || DEFAULT_COURSE_TIMEZONE;
    },
    isTeacher: function(courseId) {
      var ref2;
      return !!_.findWhere((ref2 = this._get(courseId)) != null ? ref2.roles : void 0, {
        type: 'teacher'
      });
    },
    getByEcosystemId: function(ecosystemId) {
      return _.findWhere(this._local, {
        ecosystem_id: ecosystemId
      });
    }
  }
};
 
extendConfig(CourseConfig, new CrudConfig());
 
ref2 = makeSimpleStore(CourseConfig), actions = ref2.actions, store = ref2.store;
 
module.exports = {
  CourseActions: actions,
  CourseStore: store
};