Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * myApp
- */
- var myApp = angular.module('myApp', ['ngMaterial', 'ngAnimate', 'ngRoute']);
- myApp.run(function($rootScope){
- $rootScope.snavbar = "";
- $rootScope.iconBack = "";
- var user = JSON.parse(localStorage.getItem('userPrime'));
- if(user)
- $rootScope.is_log = "true";
- else
- $rootScope.is_log = "";
- // Lista de filmes
- // Pegar dinamicamente da DB
- $rootScope.movies = [];
- /*,
- {
- 'id' : 2,
- 'name' : 'Outro',
- 'rating': 2,
- 'poster': 'example.png'
- },
- {
- 'id' : 3,
- 'name' : 'Lorem ipsAção',
- 'rating': 1,
- 'poster': 'example.png'
- },
- {
- 'id' : 4,
- 'name' : 'MASODASDM',
- 'rating': 4,
- 'poster': 'example.png'
- }];
- */
- });
- /*
- * Estrutura de requisição para usar de modelo
- * nas próximas requisições que precisar
- myApp.service('myMovies', function($http, $q){
- return ({
- get:myChoice,
- });
- function myChoice(){
- return $http.get("http://127.0.0.1/tests/webservice/movies.php").then(function(response){
- return response.data
- });
- }
- });
- */
- // montar para para compartilhar infos do filme
- myApp.service('share',function($http){
- return ({
- getInformation:shareBox
- });
- function shareBox(name,desc,image){
- return $http.get("http://api.localhost:8080/api/share?name="+name+"&desc="+desc+"&image="+image).then(function(response){
- return response;
- });
- }
- });
- //webservice para trazer histórico
- // com nome do filme e do cinema
- myApp.service('history',function($http){
- return ({
- getHystory:getListHistory
- });
- function getListHistory( userID){
- return $http.get("http://primepassclub.com.br/api/history?user_id="+userID).then(function(response){
- return response.data;
- });
- }
- });
- //webservice de funções do cartão
- // carregar e ver saldo
- myApp.service('card',function($http){
- return ({
- getBallance:ballance,
- getRecharge:recharge,
- });
- function ballance( userID , sessionID ){
- return $http.get("http://primepassclub.com.br/api/cartao/saldo?id=" + userID + "&show_id=" + sessionID).then(function(response){
- return response.data;
- });
- }
- function recharge( userID , sessionID ){
- return $http.get("http://primepassclub.com.br/api/cartao/recarga?id=" + userID + "&show_id=" + sessionID).then(function(response){
- return response.data;
- });
- }
- });
- // webservice para trazer toda lista de cinemas
- myApp.service('cinemas',function($http){
- return ({
- getList:getCinemasList,
- getMetters:getDistance,
- getPosition: geoPositions
- });
- function geoPositions(callback){
- navigator.geolocation.getCurrentPosition(function(pos){
- callback(pos);
- },errorPosition);
- }
- // caso haja erros
- function errorPosition(error){
- console.log("Error: "+ error);
- }
- /*
- * Pega posição atual do usuario
- * e faz o calculo da distancia entre ele e o cinema indexado no foreach
- */
- function getDistance( lat , lng, callback ){
- geoPositions(function(pos){
- var userLocation = new google.maps.LatLng(pos.coords.latitude , pos.coords.longitude);
- var targetLocation = new google.maps.LatLng(lat, lng);
- var calculateDistance = parseInt(google.maps.geometry.spherical.computeDistanceBetween(userLocation, targetLocation)).toFixed(2);
- callback(calculateDistance);
- });
- }
- /*
- * Caso haja erros
- */
- function errorPosition(err){
- console.warn('ERROR(' + err.code + '): ' + err.message);
- }
- /*
- * Recebe lista dinâmica de todos cinemas
- * retornar desta forma:
- * {name,latitude,longitude,endereço}
- */
- function getCinemasList(){
- return $http.get("http://primepassclub.com.br/api/cinemas").then(function(response){
- return response.data;
- });
- }
- });
- // GoogleMaps latitude service
- myApp.service('maps', function(){
- return ({
- checkDistance: _checkDistance
- });
- /*
- * Pega a posição atual do usuario
- * Caso nao consiga, chama _error
- * Caso consiga, faz um callback e manda as position
- */
- function getGeoLocation(callback) {
- var options = { timeout: 31000, enableHighAccuracy: true, maximumAge: 90000 };
- navigator.geolocation.getCurrentPosition(function(positions){
- callback(positions);
- }, _error, options);
- }
- /*
- * Caso haja erros, exibve a mensagem abaixo no console
- */
- function _error(error){
- console.log("Error: "+ error);
- }
- /*
- * Verifica se está na distancia de 100 metros do cinema
- */
- function _checkDistance(targetLat, targetLon, callback){
- // Acessamos a localizaçao do usuario
- getGeoLocation(function(position){
- var userLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
- var targetLocation = new google.maps.LatLng(targetLat, targetLon);
- var calculateDistance = parseInt(google.maps.geometry.spherical.computeDistanceBetween(userLocation, targetLocation)).toFixed(2);
- callback(calculateDistance);
- });
- }
- });
- //service to check login to access app
- //
- myApp.service('user',function($http){
- return ({
- login:getLogin
- });
- // ----------
- // -- Login
- // ----------
- function getLogin(login,pass){
- return $http.get("http://primepassclub.com.br/api/user/auth?email="+login+"&pass="+pass).then(function(response){
- return response.data;
- });
- }
- });
- //service to get
- // all current movie
- myApp.service('movies',function($http){
- return ({
- all:getMovies
- });
- function getMovies(){
- return $http.get("http://primepassclub.com.br/api/movies").then(function(response){
- return response.data;
- });
- }
- });
- // get specific data
- // of chosen moovies
- myApp.service('shows', function($http){
- return ({
- get: getShows,
- });
- // -----------------
- // -- Public
- // -----------------
- function getShows( movie_id ){
- return $http.get("http://primepassclub.com.br/api/movie/"+movie_id).then(function(response){
- return response.data;
- });
- }
- });
- //service to use youtube api
- myApp.service('youtubeAPI',function($window,$q){
- return({
- showMovie:loadPlayer,
- });
- function getArtistId( id ) {
- return id;
- }
- function loadPlayer( video_id) {
- if (typeof(YT) == 'undefined' || typeof(YT.Player) == 'undefined') {
- //console.log('aqui');
- var tag = document.createElement('script');
- tag.src = "https://www.youtube.com/iframe_api";
- var firstScriptTag = document.getElementsByTagName('script')[0];
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
- window.onYouTubePlayerAPIReady = function() {
- onYouTubePlayer( video_id );
- };
- }else{
- onYouTubePlayer( video_id );
- }
- }
- function onYouTubePlayer( video_id) {
- player = new YT.Player('player', {
- height: '220',
- width: '320',
- videoId: getArtistId(video_id),
- playerVars: { controls:0, showinfo: 0, rel: 0, showsearch: 0, iv_load_policy: 3, autohide: 1 },
- events: {
- 'onStateChange': onPlayerStateChange,
- }
- });
- }
- var player,iframe;
- var done = false;
- function onPlayerStateChange(event) {
- if (event.data == YT.PlayerState.PLAYING && !done) {
- stopVideo();
- done = true;
- }
- else if(event.data == YT.PlayerState.ENDED){
- location.reload();
- }
- }
- function stopVideo() {
- player.stopVideo();
- }
- });
- //obter sessões do filme clicado
- myApp.service('GetSessions',function($http){
- return ({
- getSession:getSessionList
- });
- function getSessionList(id){
- id = id || 266;
- console.log(id);
- return $http.get("http://primepassclub.com.br/api/shows/"+id).then(function(response){
- return response.data;
- });
- }
- });
- // ---
- // PRIVATE METHODS.
- // ---
- // I transform the error response, unwrapping the application dta from
- // the API response payload.
- function handleError( response ) {
- console.log('error')
- }
- // I transform the successful response, unwrapping the application data
- // from the API response payload.
- function handleSuccess( response ) {
- return (response.data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement