Advertisement
Guest User

Untitled

a guest
Apr 17th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. angular.module('datasid.staging_area', ['ngAnimate']).
  4.     config(function($stateProvider, $httpProvider, $urlRouterProvider) {
  5.  
  6.         // Allow trailing slash optional for all routes defined IN THIS MODULE
  7.         // Unfortunately we have to copy and paste this piece of code in every
  8.         // mode we want this feature. There is a question on stackoverflow
  9.         // about it, could you check to see if someone has a better solution?
  10.         // http://stackoverflow.com/questions/26551186/how-to-apply-urlrouterprovider-rule-in-all-modules-of-my-app
  11.         $urlRouterProvider.rule(function ($injector, $location) {
  12.             var path = $location.url();
  13.  
  14.             // check to see if the path has a trailing slash
  15.             if ('/' === path[path.length - 1]) {
  16.                 return path.replace(/\/$/, '');
  17.             }
  18.  
  19.             if (path.indexOf('/?') > 0) {
  20.                 return path.replace('/?', '?');
  21.             }
  22.  
  23.             return false;
  24.         });
  25.  
  26.         $stateProvider.
  27.             state('staging_area', {
  28.                 url: '/staging_area',
  29.                 templateUrl: 'partials/staging.area.html',
  30.                 controller: 'StagingAreaCtrl',
  31.                 section: 'staging_area',
  32.                 label: "Área Temporária",
  33.                 secure: true
  34.             }).
  35.  
  36.             state('staging_area.never_contacted', {
  37.                 url: '/new_points',
  38.                 templateUrl: 'partials/staging.area.never.contacted.html',
  39.                 controller: 'NeverContactedCtrl',
  40.                 section: 'staging_area',
  41.                 secure: true
  42.             }).
  43.  
  44.             state('staging_area.return_to_contact', {
  45.                 url: '/return_to_contact',
  46.                 templateUrl: 'partials/staging.area.return.contact.html',
  47.                 controller: 'ReturnToContactCtrl',
  48.                 section: 'staging_area',
  49.                 secure: true
  50.             }).
  51.  
  52.             state('staging_area.ips_rejected', {
  53.                 url: '/ips_rejected',
  54.                 templateUrl: 'partials/staging.area.ips.rejected.html',
  55.                 controller: 'IpsRejectedCtrl',
  56.                 section: 'staging_area',
  57.                 secure: true
  58.             });
  59.     }).
  60.  
  61.     factory('FirstContactFactory', function($resource) {
  62.         return $resource('/api/staging_area/new_points');
  63.     }).
  64.  
  65.     factory('RedToGreenFactory', function($resource) {
  66.         return $resource('/api/staging_area/red_to_green');
  67.     }).
  68.  
  69.     factory('IpsRejectedFactory', function($resource) {
  70.         return $resource('/api/staging_area/ips_rejected');
  71.     }).
  72.  
  73.     controller('StagingAreaCtrl', function ($scope, $rootScope, $state, $interval) {
  74.         $scope.tabs = [
  75.             {
  76.                 title: 'Novos pontos', //trocar nome
  77.                 state: 'staging_area.never_contacted'
  78.             },
  79.  
  80.             {
  81.                 title: 'Pontos que voltaram a se comunicar', //trocar nome
  82.                 state: 'staging_area.return_to_contact'
  83.             },
  84.             {
  85.                 title: 'ips rejeitados',
  86.                 state: 'staging_area.ips_rejected'
  87.             }
  88.  
  89.         ];
  90.  
  91.         $scope.currentTabState = $state.current.name;
  92.         $state.go($scope.tabs[0].state);
  93.  
  94.         $scope.changeState = function(state) {
  95.             $state.go(state, $state.params, {reload:false});
  96.         };
  97.  
  98.         function setupTimer() {
  99.             if ($scope.timer) {
  100.                 $interval.cancel($scope.timer);
  101.             }
  102.             $scope.timer = $interval( function () {
  103.                 $scope.$broadcast('refreshData');
  104.             }, 60000);
  105.         }
  106.  
  107.         $scope.refreshData = function () {
  108.             $scope.$broadcast('refreshData');
  109.             setupTimer();
  110.         };
  111.  
  112.     }).
  113.  
  114.     controller('NeverContactedCtrl', function ($scope, $rootScope, $state, $alert, $interval, $filter, FirstContactFactory) {
  115.  
  116.         $scope.reports = {
  117.             first_contact: []
  118.         };
  119.  
  120.         $scope.sorting = {
  121.                 attribute: "name",
  122.                 reverse : false
  123.         };
  124.  
  125.         $scope.loading = true;
  126.         $scope.error = false;
  127.  
  128.         $scope.setSorting = function (column) {
  129.             var sorting = $scope.sorting;
  130.  
  131.             if (sorting.attribute === column)
  132.                 sorting.reverse = !sorting.reverse;
  133.             else
  134.                 sorting.reverse = false;
  135.  
  136.             sorting.attribute = column;
  137.         };
  138.  
  139.         $scope.$on('refreshData', function(){
  140.             $scope.updateSearch();
  141.         });
  142.  
  143.         $scope.updateSearch = function () {
  144.             $scope.loading = true;
  145.             FirstContactFactory.save(null, null, function (result) {
  146.                 $scope.reports.first_contact = result.first_contact;
  147.             }, function(err){
  148.                 $alert.error("Falha ao carregar os dados");
  149.                 $scope.error = true;
  150.  
  151.             });
  152.         }
  153.  
  154.         FirstContactFactory.save(null, null, function (result) {
  155.             $scope.reports = result;
  156.             $scope.loading = false;
  157.         }, function(err){
  158.             $alert.error("Falha ao carregar os dados");
  159.             $scope.error = true;
  160.         });
  161.  
  162.  
  163.         // Used by the orderBy to ignore accents and upper case
  164.         $scope.normalizedName = {
  165.             first_use : function(item) {
  166.                 if (item.name == null)
  167.                     return;
  168.                 return normalize(item[$scope.sorting.first_use.attribute]);
  169.             }
  170.         };
  171.  
  172.         $scope.getOrder = function(attribute) {
  173.             if ($scope.sorting.attribute == attribute)
  174.                 return $scope.sorting.reverse;
  175.             return undefined;
  176.         }
  177.  
  178.  
  179.         $scope.$on("$destroy", function() {
  180.             if ($scope.timer)
  181.                 $interval.cancel($scope.timer);
  182.         });
  183.     }).
  184.  
  185.     controller('ReturnToContactCtrl', function ($scope, $rootScope, $state, $alert, $interval, $filter, RedToGreenFactory) {
  186.  
  187.         $scope.reports = {
  188.             red_to_green: []
  189.         };
  190.  
  191.         $scope.sorting = {
  192.             attribute: "name",
  193.             reverse : false
  194.         };
  195.  
  196.         $scope.loading = true;
  197.         $scope.error = false;
  198.  
  199.         $scope.setSorting = function (column) {
  200.             var sorting = $scope.sorting;
  201.  
  202.             if (sorting.attribute === column)
  203.                 sorting.reverse = !sorting.reverse;
  204.             else
  205.                 sorting.reverse = false;
  206.  
  207.             sorting.attribute = column;
  208.         };
  209.  
  210.         $scope.$on('refreshData', function(){
  211.             $scope.updateSearch();
  212.         });
  213.  
  214.         $scope.updateSearch = function () {
  215.             $scope.loading = true;
  216.             RedToGreenFactory.save(null, null, function (result) {
  217.                 $scope.reports.red_to_green = result.red_to_green;
  218.                 $scope.loading = false;
  219.             }, function(err){
  220.                 $alert.error("Falha ao carregar os dados");
  221.                 $scope.error = true;
  222.  
  223.             });
  224.         }
  225.  
  226.         RedToGreenFactory.save(null, null, function (result) {
  227.             $scope.reports = result;
  228.             $scope.loading = false;
  229.         }, function(err){
  230.             $alert.error("Falha ao carregar os dados");
  231.             $scope.error = true;
  232.         });
  233.  
  234.         // Used by the orderBy to ignore accents and upper case
  235.         $scope.normalizedName = {
  236.             red_to_green : function(item) {
  237.                 return normalize(item[$scope.sorting.attribute]);
  238.             }
  239.         };
  240.  
  241.         $scope.getOrder = function(attribute) {
  242.             if ($scope.sorting.attribute == attribute)
  243.                 return $scope.sorting.reverse;
  244.             return undefined;
  245.         }
  246.  
  247.         $scope.$on("$destroy", function() {
  248.             if ($scope.timer)
  249.                 $interval.cancel($scope.timer);
  250.         });
  251.     }).
  252.  
  253.     controller('IpsRejectedCtrl', function ($scope, $rootScope, $state, $alert, $interval, $filter, IpsRejectedFactory) {
  254.  
  255.         $scope.reports = {
  256.             IPs_rejected: []
  257.         };
  258.  
  259.         $scope.sorting = {
  260.             attribute: "name",
  261.             reverse : false
  262.         };
  263.  
  264.         $scope.loading = true;
  265.         $scope.error = false;
  266.  
  267.         $scope.setSorting = function (column) {
  268.             var sorting = $scope.sorting;
  269.  
  270.             if (sorting.attribute === column)
  271.                 sorting.reverse = !sorting.reverse;
  272.             else
  273.                 sorting.reverse = false;
  274.  
  275.             sorting.attribute = column;
  276.         };
  277.  
  278.         $scope.$on('refreshData', function(){
  279.             $scope.updateSearch();
  280.         });
  281.  
  282.         $scope.updateSearch = function () {
  283.             $scope.loading = true;
  284.             IpsRejectedFactory.save(null, null, function (result) {
  285.                 $scope.reports.ips_rejected = result.ips_rejected;
  286.                 $scope.loading = false;
  287.             }, function(err){
  288.                 $alert.error("Falha ao carregar os dados");
  289.                 $scope.error = true;
  290.  
  291.             });
  292.  
  293.         IpsRejectedFactory.save(null, null, function (result) {
  294.             $scope.reports = result;
  295.             $scope.loading = false;
  296.         }, function(err){
  297.             $alert.error("Falha ao carregar os dados");
  298.             $scope.error = true;
  299.         });
  300.  
  301.         // Used by the orderBy to ignore accents and upper case
  302.         $scope.normalizedName = {
  303.             ips_rejected : function(item){
  304.                 if (item.name == null)
  305.                     return;
  306.                 return normalize(item[$scope.sorting]);
  307.             }
  308.         };
  309.  
  310.         $scope.getOrder = function(attribute) {
  311.             if ($scope.sorting.attribute == attribute)
  312.                 return $scope.sorting.reverse;
  313.             return undefined;
  314.         }
  315.  
  316.         $scope.$on("$destroy", function() {
  317.             if ($scope.timer)
  318.                 $interval.cancel($scope.timer);
  319.         });
  320.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement