Created
September 13, 2016 16:01
-
-
Save FelixMalfait/fa42ea4d237a6c2a5cf44c738d94ddb2 to your computer and use it in GitHub Desktop.
Front App plugin
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
var siteUrl = 'https://luckey.herokuapp.com/'; | |
var apiUrl = 'https://luckey.herokuapp.com/api/v1/'; | |
angular | |
.module('luckey-plugin', ['ngResource', 'ui.router', 'satellizer', 'templates', 'algoliasearch', 'uiGmapgoogle-maps']) | |
.config(['$stateProvider', '$urlRouterProvider', '$authProvider', function($stateProvider, $urlRouterProvider, $authProvider) { | |
// Satellizer configuration that specifies which API | |
// route the JWT should be retrieved from | |
$authProvider.loginUrl = apiUrl + 'authenticate'; | |
$authProvider.storageType = 'localStorage'; | |
// Redirect to the auth state if any other states | |
// are requested other than users | |
$urlRouterProvider.otherwise('/home'); | |
}]) | |
.config(['$stateProvider', '$urlRouterProvider', '$authProvider', '$httpProvider', '$provide', function($stateProvider, $urlRouterProvider, $authProvider, $httpProvider, $provide) { | |
function redirectWhenLoggedOut($q, $injector) { | |
return { | |
responseError: function (rejection) { | |
var $state = $injector.get('$state'); | |
var rejectionReasons = ['token_not_provided', 'token_expired', 'token_absent', 'token_invalid']; | |
angular.forEach(rejectionReasons, function (value, key) { | |
if (rejection.data.error === value) { | |
$state.go('auth'); | |
} | |
}); | |
return $q.reject(rejection); | |
} | |
}; | |
} | |
$provide.factory('redirectWhenLoggedOut', ['$q', '$injector', redirectWhenLoggedOut]); | |
$httpProvider.interceptors.push('redirectWhenLoggedOut'); | |
}]) | |
.config(['$locationProvider', function ($locationProvider) { | |
$locationProvider.html5Mode(true); | |
}]) | |
.run(['$rootScope', '$state',function($rootScope, $state) { | |
Front.setPanelWidth(360); | |
Front.on('conversation', function (event) { | |
console.log('Conversation', event.conversation); | |
console.log('Contact', event.contact); | |
console.log('Message', event.message); | |
console.log('OtherMessages', event.otherMessages); | |
conversation = event.conversation; | |
if(conversation.inboxes.indexOf("airbnb2") > -1) { | |
var booking_id_pattern = new RegExp(/\[([0-9]+)\]/); | |
$state.go('conversation.simple', {id: booking_id_pattern.exec(event.conversation.subject)[1]}); | |
} | |
else { | |
$state.go('home'); | |
} | |
}); | |
}]) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment