Code coverage report for src/helpers/plan.coffee

Statements: 100% (33 / 33)      Branches: 93.75% (30 / 32)      Functions: 100% (2 / 2)      Lines: 100% (33 / 33)      Ignored: none     

All files » src/helpers/ » plan.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             420× 420× 42×   420× 420× 418× 57× 361×   420×     42× 42× 42× 42× 42× 42×     42× 42×     42×                
var PlanHelper, PlanPublishActions, PlanPublishStore, TimeActions, TimeStore, _, moment, ref, ref1;
 
moment = require('moment');
 
_ = require('underscore');
 
ref = require('../flux/plan-publish'), PlanPublishStore = ref.PlanPublishStore, PlanPublishActions = ref.PlanPublishActions;
 
ref1 = require('../flux/time'), TimeStore = ref1.TimeStore, TimeActions = ref1.TimeActions;
 
PlanHelper = {
  isPublishing: function(plan, recentTolerance) {
    var isPublishing, recent;
    if (recentTolerance == null) {
      recentTolerance = 3600000;
    }
    isPublishing = ((plan.is_publish_requested != null) && plan.is_publish_requested) || (plan.publish_last_requested_at != null);
    if ((plan.published_at != null) && (plan.publish_last_requested_at != null)) {
      isPublishing = moment(plan.publish_last_requested_at).diff(plan.published_at) > 0;
    } else if ((plan.published_at != null) && (plan.publish_last_requested_at == null)) {
      isPublishing = false;
    } else if (plan.publish_last_requested_at != null) {
      recent = moment(TimeStore.getNow()).diff(plan.publish_last_requested_at) < recentTolerance;
      isPublishing = isPublishing && recent;
    }
    return isPublishing;
  },
  subscribeToPublishing: function(plan, callback) {
    var id, isPublishing, isPublishingInStore, jobId, publishStatus, ref2;
    ref2 = PlanPublishStore._getIds(plan), jobId = ref2.jobId, id = ref2.id;
    isPublishing = PlanHelper.isPublishing(plan);
    publishStatus = PlanPublishStore.getAsyncStatus(id);
    isPublishingInStore = PlanPublishStore.isPublishing(id);
    if (isPublishing && !isPublishingInStore && !PlanPublishStore.isPublished(id)) {
      Eif (jobId) {
        PlanPublishActions.queued(plan, id);
      }
    }
    isPublishing = isPublishing || isPublishingInStore;
    if (isPublishing) {
      PlanPublishActions.startChecking(id, jobId);
      Eif ((callback != null) && _.isFunction(callback)) {
        PlanPublishStore.on("progress." + id + ".*", callback);
      }
    }
    return {
      isPublishing: isPublishing,
      publishStatus: publishStatus
    };
  }
};
 
module.exports = PlanHelper;