Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Created March 9, 2014 14:21
Show Gist options
  • Save tarlepp/9448461 to your computer and use it in GitHub Desktop.
Save tarlepp/9448461 to your computer and use it in GitHub Desktop.
var travelBookingApplication = angular.module("travelBookingApplication", [
"ngRoute",
"angularSails.io",
"travelBookingControllers",
"travelBookingServices"
]);
travelBookingApplication.factory("sailsSocket", function(sailsSocketFactory) {
return sailsSocketFactory();
});
travelBookingApplication.config(["$routeProvider", "$locationProvider",
function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when("/", {
templateUrl: "templates/main.html",
controller: "mainController"
})
.otherwise({
redirectTo: '/'
});
}]);
var travelBookingControllers = angular.module("travelBookingControllers", []);
travelBookingControllers.controller("mainController", ["$scope", "$routeParams", "sailsSocket",
function($scope, $routeParams, $sailsSocket) {
// Fetch cities via sails socket connection
$sailsSocket
.get("/city")
.then(function(cities) {
$scope.cities = cities;
});
$scope.updateRoute = function() {
var parameters = {
where: {}
};
if ($scope.selectedCityFrom) {
parameters.where["from"] = $scope.selectedCityFrom.id;
}
if ($scope.selectedCityTo) {
parameters.where["to"] = $scope.selectedCityTo.id;
}
if ($scope.selectedCityFrom || $scope.selectedCityTo) {
$sailsSocket
.get("/route", parameters)
.then(function(routes) {
$scope.routes = routes;
});
} else {
$scope.routes = null;
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment