Last active
September 13, 2015 00:02
-
-
Save fbarbalho/a80db35c783a31e869dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* O use strict é uma nova funcionalidade do ECMAScript 5, que basicamente permite-nos melhorar a qualidade do nosso código JavaScript, | |
fazendo com que sejam lançadas excepções quando tentamos fazer algo que não deveríamos fazer*/ | |
'use strict' | |
/* APP Module */ | |
var avaliacaoApp = angular.module('avaliacaoApp', [ | |
'ngRoute', | |
'ui.bootstrap', | |
'blogControllers', | |
'blogServices', | |
/* 'autenticacaoControllers',*/ | |
/* 'avaliacaoServices',*/ | |
'businessServices' | |
]); | |
avaliacaoApp.config(['$routeProvider', '$locationProvider', | |
function($routeProvider, $locationProvider) { | |
$routeProvider | |
.when('/', { | |
templateUrl: 'views/lista.html', | |
controller: 'ListaCtrl' | |
}) | |
.when('/lista', { | |
templateUrl: 'views/lista.html', | |
controller: 'ListaCtrl' | |
}) | |
.when('/detalhe/:codigo', { | |
templateUrl: 'views/detalhe.html', | |
controller: 'ListaCtrl' | |
}) | |
.when('/login', { | |
templateUrl: 'views/login.html', | |
controller: 'LoginCtrl' | |
}) | |
.when('/logout', { | |
templateUrl: 'views/signup.html', | |
controller: 'LogoutCtrl' | |
}); | |
$locationProvider.html5Mode(false).hashPrefix('!'); | |
}]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
/* Controlers*/ | |
/*Login */ | |
var blogControllers = angular.module('blogControllers', []); | |
blogControllers.controller('LoginCtrl', ['$scope', 'Service', '$location', 'Login', 'setCreds', | |
function LoginCtrl($scope, Service, $location, Login, setCreds) { | |
// Instantiate an object to store your scope data in (Best Practices) | |
//$scope.lista = {}; | |
$scope.submit = function () { | |
$scope.sub = true; | |
var postData = { | |
"username": $scope.username, | |
"password": $scope.password | |
}; | |
Login.login({}, postData, | |
function success(response) { | |
console.log("Success:" + JSON.stringify(response)) | |
setCreds($scope.username, $scope.password) | |
Service.data = response.avaliacoes | |
/*$scope.lista.items = response.avaliacoes*/ | |
$location.path('/lista'); | |
}, | |
function error(errorResponse) { | |
console.log("Error:" + JSON.stringify(errorResponse)) | |
$scope.error = "Não foi possível realizar o login."; | |
} | |
); | |
}; | |
}]); | |
// Lista Controle | |
blogControllers.controller('ListaCtrl', ['$scope', 'Service', '$location', | |
function ListaCtrl($scope, $location, Service) { | |
$scope.lista = Service.data; | |
console.log("Service: " + JSON.stringify($scope.lista)) | |
}]); | |
/* Logout*/ | |
blogControllers.controller('LogoutCtrl', ['$location', 'deleteCreds', | |
function LogoutCtrl($location, deleteCreds) { | |
deleteCreds(); | |
$location.path('/login'); | |
}]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-controller="ListaCtrl"> | |
<ul> | |
<li ng-repeat="item in lista"> | |
<p>Item: {{ item.id }}</p> | |
<p>Situação: {{ item.situacao }}</p> | |
<p>{{ item.dataAvaliacao | date:'MMM d, y h:mm:ss a' }}</p> | |
</li> | |
</ul> | |
</div> | |
<div class="col-sm-10 form-group" ng-controller="ListaCtrl"> | |
<h2> Avaliações </h2> | |
<li ng-repeat="item in lista"> | |
<div class="panel panel-default" style="width:250px"> | |
<div class="panel-heading"> | |
<h2>{{item.id}}</h2> | |
</div> | |
<div class="panel-body"> | |
<p>Data: {{item.dataAvaliacao | date:'medium'}}</p> | |
<p><a class="btn btn-primary pull-right"> Ver Detalhes </a></p> | |
</div> | |
</div> | |
</li> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*/ json example*/ | |
[ | |
{ | |
"id":1, | |
"dataAvaliacao":1440730800000, | |
"situacao":"A", | |
"dataCriacao":1439082060000, | |
"dataAlteracao":null | |
}, | |
{ | |
"id":2, | |
"dataAvaliacao":1442026800000, | |
"situacao":"A", | |
"dataCriacao":1442088547690, | |
"dataAlteracao":null | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* Services */ | |
/*Login*/ | |
var blogServices = angular.module('blogServices', ['ngResource']); | |
blogServices.factory('Login', ['$resource', | |
function($resource) { | |
return $resource("http://localhost:8080/new-flag/rest/usuario/login", {}, { | |
login: {method: 'POST', | |
cache: false, | |
isArray: false, | |
headers: {'Content-Type': 'application/json' }} | |
}); | |
}]); | |
blogServices.factory('Service', function() { | |
var Service = { | |
data: '' | |
}; | |
return Service; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment