Skip to content

Instantly share code, notes, and snippets.

@yeukhon
Created August 20, 2013 23:24
Show Gist options
  • Select an option

  • Save yeukhon/6288632 to your computer and use it in GitHub Desktop.

Select an option

Save yeukhon/6288632 to your computer and use it in GitHub Desktop.
app.controller("HomeController", function($scope, $http, $location, $timeout) {
$scope.promise = 0;
$scope.groups = []
$scope.group_name = ""
$http.get("/api/profile").success(function(response, status, headers, config) {
if (response.success) {
for (index in response.data["groups"])
$scope.groups.push({"name": response.data["groups"][index]})
}
});
$scope.get = function() {
if ($location.path() == "/home/sites" || $location.path() == "/") {
var api_url = "/api/sites"
if ($scope.group_name != "") {
var api_url = api_url + "?group_name=" + $scope.group_name.name;
}
$http.get(api_url).success(function(response, status, headers, config){
_.each(response.data, function (r, idx) {
r.label = r.target;
if (idx > 0) {
if (r.target === response.data[idx-1].target) {
r.label = "";
}
}
});
$scope.report = response.data;
if ($scope.report && $scope.report.length > 0) {
$scope.reload();
}
});
}};
$scope.reload = function() {
$scope.promise = $timeout($scope.get, 500);
};
$scope.cancel = function() {
console.log("inside cancel")
$timeout.cancel($scope.promise);
};
$scope.$on('$viewContentLoaded', function() {
$scope.reload();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment