Skip to content

Commit

Permalink
AngularJS 17
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigobranas committed May 28, 2016
1 parent ca39008 commit 996694f
Show file tree
Hide file tree
Showing 73 changed files with 37,399 additions and 0 deletions.
24 changes: 24 additions & 0 deletions AngularJS_17_Aumentando_a_Performance_Parte_2/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "AngularJS_17_Aumentando_a_Performance_Parte_2",
"homepage": "https://github.com/rodrigobranas/youtube",
"authors": [
"Rodrigo Branas <[email protected]>"
],
"description": "",
"main": "",
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular": "^1.5.6",
"angular-route": "^1.5.6",
"angular-i18n": "^1.5.6",
"angular-messages": "^1.5.6",
"bootstrap": "2.3.2"
}
}
43 changes: 43 additions & 0 deletions AngularJS_17_Aumentando_a_Performance_Parte_2/css/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.jumbotron {
width: 700px;
text-align: center;
margin-top: 20px;
margin-left: auto;
margin-right: auto;
position: relative;
padding-top: 60px;
}
h3 {
margin-bottom: 30px;
}
.table {
margin-top: 20px;
}
.form-control {
margin-bottom: 5px;
}
.selecionado {
background-color: yellow;
}
.negrito {
font-weight: bold;
}
hr {
border-color: #999;
}

.ribbon {
position: absolute;
top: 0px;
right: 30px;
width: 20px;
height: 40px;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent #EEE transparent;
cursor: pointer;
background-color: #EE0000;
}
.ribbon:hover {
height: 41px;
}
39 changes: 39 additions & 0 deletions AngularJS_17_Aumentando_a_Performance_Parte_2/css/ui.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.ui-alert {
background-color: #F2DEDE;
padding: 20px;
border-radius: 5px;
margin-top: 20px;
margin-bottom: 20px;
}

.ui-alert-title {
color: #AF4341;
font-weight: bold;
font-size: 24px;
}

.ui-alert-message {
color: #AF4341;
}

.ui-accordion-title {
border: 1px solid #CCCCCC;
cursor: pointer;
background: -moz-linear-gradient(top, #CCCCCC, #EEEEEE);
padding: 10px;
font-size: 16px;
font-weight: bold;
border-radius: 5px 5px 0px 0px;
margin-top: 10px;
text-align: left;
}
.ui-accordion-content {
border: 1px dashed #CCCCCC;
border-top: 0px;
border-radius: 0px 0px 5px 5px;
background-color: #FFFFFF;
padding: 10px;
margin-bottom: 10px;
font-size: 14px;
text-align: left;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions AngularJS_17_Aumentando_a_Performance_Parte_2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<html ng-app="listaTelefonica">
<head>
<meta charset="UTF-8">
<title>Lista Telefonica</title>
<link rel="stylesheet" type="text/css" href="lib/bootstrap/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/app.css">
<link rel="stylesheet" type="text/css" href="css/ui.css">
<script src="lib/angular/angular.js"></script>
<script src="lib/angular/angular-route.js"></script>
<script src="lib/angular/angular-messages.js"></script>
<script src="lib/angular/angular-locale_pt-br.js"></script>
<script src="lib/serialGenerator/serialGenerator.js"></script>
<script src="lib/ui/ui.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/listaTelefonicaCtrl.js"></script>
<script src="js/controllers/novoContatoCtrl.js"></script>
<script src="js/controllers/detalhesContatoCtrl.js"></script>
<script src="js/services/contatosAPIService.js"></script>
<script src="js/services/operadorasAPIService.js"></script>
<script src="js/config/serialGeneratorConfig.js"></script>
<script src="js/config/routeConfig.js"></script>
<script src="js/value/configValue.js"></script>
<script src="js/filters/nameFilter.js"></script>
<script src="js/filters/ellipsisFilter.js"></script>
<script src="js/filters/upperFilter.js"></script>
<script src="js/directives/uiAlertDirective.js"></script>
<script src="js/directives/uiDateDirective.js"></script>
<script src="js/interceptors/timestampInterceptor.js"></script>
<script src="js/interceptors/errorInterceptor.js"></script>
<script src="js/interceptors/loadingInterceptor.js"></script>
<script src="js/config/interceptorsConfig.js"></script>
</head>
<body>
<div class="jumbotron" ng-show="loading">
<h5>Carregando, por favor aguarde...</h5>
</div>
<div ng-hide="loading">
<div ng-view></div>
<div ng-include="'view/footer.html'"></div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions AngularJS_17_Aumentando_a_Performance_Parte_2/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
angular.module("listaTelefonica", ["ngMessages", "serialGenerator", "ui", "ngRoute"]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
angular.module("listaTelefonica").config(function ($httpProvider) {
$httpProvider.interceptors.push("timestampInterceptor");
$httpProvider.interceptors.push("errorInterceptor");
$httpProvider.interceptors.push("loadingInterceptor");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
angular.module("listaTelefonica").config(function ($routeProvider) {
$routeProvider.when("/contatos", {
templateUrl: "view/contatos.html",
controller: "listaTelefonicaCtrl",
resolve: {
contatos: function (contatosAPI) {
return contatosAPI.getContatos();
},
operadoras: function (operadorasAPI) {
return operadorasAPI.getOperadoras();
}
}
});
$routeProvider.when("/novoContato", {
templateUrl: "view/novoContato.html",
controller: "novoContatoCtrl",
resolve: {
operadoras: function (operadorasAPI) {
return operadorasAPI.getOperadoras();
}
}
});
$routeProvider.when("/detalhesContato/:id", {
templateUrl: "view/detalhesContato.html",
controller: "detalhesContatoCtrl",
resolve: {
contato: function (contatosAPI, $route) {
return contatosAPI.getContato($route.current.params.id);
}
}
});
$routeProvider.when("/error", {
templateUrl: "view/error.html"
});
$routeProvider.otherwise({redirectTo: "/contatos"});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
angular.module("listaTelefonica").config(function (serialGeneratorProvider) {
serialGeneratorProvider.setLength(5);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
angular.module("listaTelefonica").controller("detalhesContatoCtrl", function ($scope, $routeParams, contato) {

$scope.contato = contato.data;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
angular.module("listaTelefonica").controller("listaTelefonicaCtrl", function ($scope, contatos, operadoras, serialGenerator, $filter) {
$scope.app = $filter('upper')("Lista Telefonica");
$scope.contatos = contatos.data;
$scope.operadoras = operadoras.data;

var init = function () {
calcularImpostos($scope.contatos);
generateSerial($scope.contatos);
};

var calcularImpostos = function (contatos) {
contatos.forEach(function (contato) {
contato.operadora.precoComImposto = calcularImposto(contato.operadora.preco);
});
};

var generateSerial = function (contatos) {
contatos.forEach(function (item) {
item.serial = serialGenerator.generate();
});
};

$scope.adicionarContato = function (contato) {
contato.serial = serialGenerator.generate();
contatosAPI.saveContato(contato).success(function (data) {
delete $scope.contato;
$scope.contatoForm.$setPristine();
carregarContatos();
});
};
$scope.apagarContatos = function (contatos) {
$scope.contatos = contatos.filter(function (contato) {
if (!contato.selecionado) return contato;
});
$scope.verificarContatoSelecionado($scope.contatos);
};
$scope.verificarContatoSelecionado = function (contatos) {
$scope.hasContatoSelecionado = contatos.some(function (contato) {
return contato.selecionado;
});
};
$scope.ordenarPor = function (campo) {
$scope.criterioDeOrdenacao = campo;
$scope.direcaoDaOrdenacao = !$scope.direcaoDaOrdenacao;
};

var calcularImposto = function (preco) {
var imposto = 1.2;
return preco * imposto;
};

$scope.reset = function () {
$scope.contatos = angular.copy($scope.contatos);
};

init();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
angular.module("listaTelefonica").controller("novoContatoCtrl", function ($scope, contatosAPI, serialGenerator, $location, operadoras) {
$scope.operadoras = operadoras.data;

$scope.adicionarContato = function (contato) {
contato.serial = serialGenerator.generate();
contatosAPI.saveContato(contato).success(function (data) {
delete $scope.contato;
$scope.contatoForm.$setPristine();
$location.path("/contatos");
});
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
angular.module("listaTelefonica").directive("uiAlert", function () {
return {
templateUrl: "view/alert.html",
replace: true,
restrict: "AE",
scope: {
title: "@"
},
transclude: true
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
angular.module("listaTelefonica").directive("uiDate", function ($filter) {
return {
require: "ngModel",
link: function (scope, element, attrs, ctrl) {
var _formatDate = function (date) {
if (!date) return date;
date = date.replace(/[^0-9]+/g, "");
if(date.length > 2) {
date = date.substring(0,2) + "/" + date.substring(2);
}
if(date.length > 5) {
date = date.substring(0,5) + "/" + date.substring(5,9);
}
return date;
};

element.bind("keyup", function () {
ctrl.$setViewValue(_formatDate(ctrl.$viewValue));
ctrl.$render();
});

ctrl.$parsers.push(function (value) {
if (value.length === 10) {
var dateArray = value.split("/");
return new Date(dateArray[2], dateArray[1]-1, dateArray[0]).getTime();
}
});

ctrl.$formatters.push(function (value) {
return $filter("date")(value, "dd/MM/yyyy");
});
}
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
angular.module("listaTelefonica").filter("ellipsis", function () {
return function (input, size) {
if (input.length <= size) return input;
var output = input.substring(0,(size || 2)) + "...";
return output;
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
angular.module("listaTelefonica").filter("name", function () {
return function (input) {
var listaDeNomes = input.split(" ");
var listaDeNomesFormatada = listaDeNomes.map(function (nome) {
if (/(da|de)/.test(nome)) return nome;
return nome.charAt(0).toUpperCase() + nome.substring(1).toLowerCase();
});
return listaDeNomesFormatada.join(" ");
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
angular.module("listaTelefonica").filter("upper", function () {
var counter = 0;
return function (input) {
console.log(counter++);
if (!input) return;
return input.toUpperCase();
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
angular.module("listaTelefonica").factory("errorInterceptor", function ($q, $location) {
return {
responseError: function (rejection) {
if (rejection.status === 404) {
$location.path("/error");
}
return $q.reject(rejection);
}
};
});
Loading

0 comments on commit 996694f

Please sign in to comment.