'use strict';

angular.module('checks').controller('ChecksController', ['$scope', 'Socket',
	function($scope, Socket) {

		Socket.on('checks.updated', function(data) {
    		console.log(data);
    		$scope.checks = data.checks;
    		$scope.lastUpdatedAt(data.lastUpdate);
    		console.log(data.checks);
		});

		$scope.lastUpdatedAt = function(timestamp){
			$scope.time = timestamp;
		}
	}
]);
'use strict';

angular.module('checks').controller('ChecksController', ['$scope', '$http', 'Socket',
	function($scope, $http, Socket) {

		this.init = function(){
			this.fetchChecks();
		};

		this.fetchChecks = function(){
			$http.get('/api').
			success(function(data, status, headers, config) {
				$scope.lastUpdatedAt(data.lastUpdate);
    			$scope.checks = data.checks;
			}).
			error(function(data, status, headers, config) {
				console.error('Error! Something went wrong');
				console.error(data);
			});
		};

		Socket.on('checks.updated', function(data) {
    		$scope.checks = data.checks;
    		$scope.lastUpdatedAt(data.lastUpdate);
    		console.log('>>> Updated the checks')
		});

		$scope.lastUpdatedAt = function(timestamp){
			$scope.time = timestamp;
		}

		this.init();
	}
]);
Load last saved checks on page load
Load last saved checks on page load
