'use strict';

(function() {
  angular.module('ncsaas')
    .service('resourcesService', ['RawResource', 'RawProject', 'currentStateService', '$q', resourcesService]);

  function resourcesService(RawResource, RawProject, currentStateService, $q) {
    /*jshint validthis: true */
    var vm = this;
    vm.getResourcesList = getResourcesList;
    vm.getRawResourcesList = getRawResourcesList;

    function getRawResourcesList() {
      return RawResource.query();
    }
    function getResourcesList() {
      var deferred = $q.defer();
      currentStateService.getCustomer().then(function(response) {
        var customerName = response.name,
        /*jshint camelcase: false */
            resources = RawResource.query({customer_name: customerName}, init);

            function init(resources) {
              for (var i = 0; i < resources.length; i++) {
                initResourceProject(resources[i]);
              }
            }

            function initResourceProject(resource) {
              return RawProject.query(init);
              function init(projects) {
                for (var i = 0; i < projects.length; i++) {
                  if (projects[i].name === resource.project_name) {
                    var new_project = projects[i];
                  }
                }
                resource.project = new_project;
              }
            }

        deferred.resolve(resources);
      }, function(err) {
        deferred.reject(err);
      });
      return deferred.promise;
    }

  }
})();

(function() {
  angular.module('ncsaas')
    .factory('RawResource', ['ENV', '$resource', RawResource]);

  function RawResource(ENV, $resource) {
    return $resource(
      ENV.apiEndpoint + 'api/resources/', {},
      {
      }
    );
  }
})();

@@ -677,36 +677,32 @@
 alse */%0A        
-    
 resources = RawR
@@ -748,631 +748,10 @@
 ame%7D
-, init);%0A%0A            function init(resources) %7B%0A              for (var i = 0; i %3C resources.length; i++) %7B%0A                initResourceProject(resources%5Bi%5D);%0A              %7D%0A            %7D%0A%0A            function initResourceProject(resource) %7B%0A              return RawProject.query(init);%0A              function init(projects) %7B%0A                for (var i = 0; i %3C projects.length; i++) %7B%0A                  if (projects%5Bi%5D.name === resource.project_name) %7B%0A                    var new_project = projects%5Bi%5D;%0A                  %7D%0A                %7D%0A                resource.project = new_project;%0A              %7D%0A            %7D%0A
+);
 %0A   

Remove init function from resource service, project uuid gives API.