Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- angular.module('datasid.staging_area', ['ngAnimate']).
- config(function($stateProvider, $httpProvider, $urlRouterProvider) {
- // Allow trailing slash optional for all routes defined IN THIS MODULE
- // Unfortunately we have to copy and paste this piece of code in every
- // mode we want this feature. There is a question on stackoverflow
- // about it, could you check to see if someone has a better solution?
- // http://stackoverflow.com/questions/26551186/how-to-apply-urlrouterprovider-rule-in-all-modules-of-my-app
- $urlRouterProvider.rule(function ($injector, $location) {
- var path = $location.url();
- // check to see if the path has a trailing slash
- if ('/' === path[path.length - 1]) {
- return path.replace(/\/$/, '');
- }
- if (path.indexOf('/?') > 0) {
- return path.replace('/?', '?');
- }
- return false;
- });
- $stateProvider.
- state('staging_area', {
- url: '/staging_area',
- templateUrl: 'partials/staging.area.html',
- controller: 'StagingAreaCtrl',
- section: 'staging_area',
- label: "Área Temporária",
- secure: true
- }).
- state('staging_area.never_contacted', {
- url: '/new_points',
- templateUrl: 'partials/staging.area.never.contacted.html',
- controller: 'NeverContactedCtrl',
- section: 'staging_area',
- secure: true
- }).
- state('staging_area.return_to_contact', {
- url: '/return_to_contact',
- templateUrl: 'partials/staging.area.return.contact.html',
- controller: 'ReturnToContactCtrl',
- section: 'staging_area',
- secure: true
- }).
- state('staging_area.ips_rejected', {
- url: '/ips_rejected',
- templateUrl: 'partials/staging.area.ips.rejected.html',
- controller: 'IpsRejectedCtrl',
- section: 'staging_area',
- secure: true
- });
- }).
- factory('FirstContactFactory', function($resource) {
- return $resource('/api/staging_area/new_points');
- }).
- factory('RedToGreenFactory', function($resource) {
- return $resource('/api/staging_area/red_to_green');
- }).
- factory('IpsRejectedFactory', function($resource) {
- return $resource('/api/staging_area/ips_rejected');
- }).
- controller('StagingAreaCtrl', function ($scope, $rootScope, $state, $interval) {
- $scope.tabs = [
- {
- title: 'Novos pontos', //trocar nome
- state: 'staging_area.never_contacted'
- },
- {
- title: 'Pontos que voltaram a se comunicar', //trocar nome
- state: 'staging_area.return_to_contact'
- },
- {
- title: 'ips rejeitados',
- state: 'staging_area.ips_rejected'
- }
- ];
- $scope.currentTabState = $state.current.name;
- $state.go($scope.tabs[0].state);
- $scope.changeState = function(state) {
- $state.go(state, $state.params, {reload:false});
- };
- function setupTimer() {
- if ($scope.timer) {
- $interval.cancel($scope.timer);
- }
- $scope.timer = $interval( function () {
- $scope.$broadcast('refreshData');
- }, 60000);
- }
- $scope.refreshData = function () {
- $scope.$broadcast('refreshData');
- setupTimer();
- };
- }).
- controller('NeverContactedCtrl', function ($scope, $rootScope, $state, $alert, $interval, $filter, FirstContactFactory) {
- $scope.reports = {
- first_contact: []
- };
- $scope.sorting = {
- attribute: "name",
- reverse : false
- };
- $scope.loading = true;
- $scope.error = false;
- $scope.setSorting = function (column) {
- var sorting = $scope.sorting;
- if (sorting.attribute === column)
- sorting.reverse = !sorting.reverse;
- else
- sorting.reverse = false;
- sorting.attribute = column;
- };
- $scope.$on('refreshData', function(){
- $scope.updateSearch();
- });
- $scope.updateSearch = function () {
- $scope.loading = true;
- FirstContactFactory.save(null, null, function (result) {
- $scope.reports.first_contact = result.first_contact;
- }, function(err){
- $alert.error("Falha ao carregar os dados");
- $scope.error = true;
- });
- }
- FirstContactFactory.save(null, null, function (result) {
- $scope.reports = result;
- $scope.loading = false;
- }, function(err){
- $alert.error("Falha ao carregar os dados");
- $scope.error = true;
- });
- // Used by the orderBy to ignore accents and upper case
- $scope.normalizedName = {
- first_use : function(item) {
- if (item.name == null)
- return;
- return normalize(item[$scope.sorting.first_use.attribute]);
- }
- };
- $scope.getOrder = function(attribute) {
- if ($scope.sorting.attribute == attribute)
- return $scope.sorting.reverse;
- return undefined;
- }
- $scope.$on("$destroy", function() {
- if ($scope.timer)
- $interval.cancel($scope.timer);
- });
- }).
- controller('ReturnToContactCtrl', function ($scope, $rootScope, $state, $alert, $interval, $filter, RedToGreenFactory) {
- $scope.reports = {
- red_to_green: []
- };
- $scope.sorting = {
- attribute: "name",
- reverse : false
- };
- $scope.loading = true;
- $scope.error = false;
- $scope.setSorting = function (column) {
- var sorting = $scope.sorting;
- if (sorting.attribute === column)
- sorting.reverse = !sorting.reverse;
- else
- sorting.reverse = false;
- sorting.attribute = column;
- };
- $scope.$on('refreshData', function(){
- $scope.updateSearch();
- });
- $scope.updateSearch = function () {
- $scope.loading = true;
- RedToGreenFactory.save(null, null, function (result) {
- $scope.reports.red_to_green = result.red_to_green;
- $scope.loading = false;
- }, function(err){
- $alert.error("Falha ao carregar os dados");
- $scope.error = true;
- });
- }
- RedToGreenFactory.save(null, null, function (result) {
- $scope.reports = result;
- $scope.loading = false;
- }, function(err){
- $alert.error("Falha ao carregar os dados");
- $scope.error = true;
- });
- // Used by the orderBy to ignore accents and upper case
- $scope.normalizedName = {
- red_to_green : function(item) {
- return normalize(item[$scope.sorting.attribute]);
- }
- };
- $scope.getOrder = function(attribute) {
- if ($scope.sorting.attribute == attribute)
- return $scope.sorting.reverse;
- return undefined;
- }
- $scope.$on("$destroy", function() {
- if ($scope.timer)
- $interval.cancel($scope.timer);
- });
- }).
- controller('IpsRejectedCtrl', function ($scope, $rootScope, $state, $alert, $interval, $filter, IpsRejectedFactory) {
- $scope.reports = {
- IPs_rejected: []
- };
- $scope.sorting = {
- attribute: "name",
- reverse : false
- };
- $scope.loading = true;
- $scope.error = false;
- $scope.setSorting = function (column) {
- var sorting = $scope.sorting;
- if (sorting.attribute === column)
- sorting.reverse = !sorting.reverse;
- else
- sorting.reverse = false;
- sorting.attribute = column;
- };
- $scope.$on('refreshData', function(){
- $scope.updateSearch();
- });
- $scope.updateSearch = function () {
- $scope.loading = true;
- IpsRejectedFactory.save(null, null, function (result) {
- $scope.reports.ips_rejected = result.ips_rejected;
- $scope.loading = false;
- }, function(err){
- $alert.error("Falha ao carregar os dados");
- $scope.error = true;
- });
- IpsRejectedFactory.save(null, null, function (result) {
- $scope.reports = result;
- $scope.loading = false;
- }, function(err){
- $alert.error("Falha ao carregar os dados");
- $scope.error = true;
- });
- // Used by the orderBy to ignore accents and upper case
- $scope.normalizedName = {
- ips_rejected : function(item){
- if (item.name == null)
- return;
- return normalize(item[$scope.sorting]);
- }
- };
- $scope.getOrder = function(attribute) {
- if ($scope.sorting.attribute == attribute)
- return $scope.sorting.reverse;
- return undefined;
- }
- $scope.$on("$destroy", function() {
- if ($scope.timer)
- $interval.cancel($scope.timer);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement