all files / app/components/loading/ loadingHelper.service.js

100% Statements 14/14
100% Branches 0/0
100% Functions 5/5
100% Lines 14/14
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                          182×                                 187×         187× 177× 177× 177×   187× 10× 10× 10×                          
/**
 * @ngdoc service
 * @name app.components.loadingHelper
 * @description
 * Adds loading functionality to a controller
 *
 */
(function () {
  'use strict';
 
  angular
    .module('app.components')
    .factory('loadingHelper', factory);
 
  /** @ngInject */
  function factory() {
    return activate;
 
    /**
     * @ngdoc function
     * @name activate
     * @methodOf app.components.loadingHelper
     * @description
     * Adds members to a controller:
     * * loading.loading
     * * loading.failed
     * * loading.error
     * * loading.hasFailed()
     * * loading.hasCompleted()
     *
     * @param {Object} vm
     * Controller instance
     */
    function activate(vm) {
      vm.loading = {
        loading: true,
        failed: false,
        error: null
      };
      vm.loading.hasCompleted = function () {
        vm.loading.loading = false;
        vm.loading.failed = false;
        vm.error = null;
      };
      vm.loading.hasFailed = function (response) {
        vm.loading.loading = false;
        vm.loading.failed = true;
        vm.loading.error = {
          statusText: response.statusText,
          status: response.status,
          data: response.data
        };
      };
    }
  }
})();