{"size": 1024, "ext": "js", "max_stars_repo_path": "escola/js/controllers/rooms.js", "max_stars_repo_name": "iuriimattos/iuriimattos.github.io", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "escola/js/controllers/rooms.js", "max_issues_repo_name": "iuriimattos/iuriimattos.github.io", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "escola/js/controllers/rooms.js", "max_forks_repo_name": "iuriimattos/iuriimattos.github.io", "max_forks_repo_forks_event_min_datetime": "2021-02-16T03:02:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-16T03:02:22.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 22.7555555556, "max_line_length": 97, "alphanum_fraction": 0.6201171875}
escola.controller('RoomsCtrl', ['$scope', '$rootScope', 'RoomsService', 'GlobalService',
	function($scope, $rootScope, RoomsService, GlobalService) {
		RoomsService.listAll();
		$scope.rooms = RoomsService.rooms;

		setInterval(function() {
			$scope.$digest();
		}, 500);

		function add() {
			var name = $scope.name;
			var capacity = $scope.capacity;

			RoomsService.insert({
				name: name,
				capacity: capacity
			}, function(obj) {
				$scope.rooms.push(obj)
			});

			$scope.name = '';
			$scope.capacity = '';
		};

		function remove(id) {
			var accept = confirm("Você tem certeza que deseja excluir este registro?")
			if (accept) {
				RoomsService.remove(id);

				$scope.rooms.forEach(function(room, index) {
					if (room.id == id) {
						$scope.rooms.splice(index, 1);
					}
				});
			}
		};

		$scope.add = add;
		$scope.remove = remove;

		$rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) {
			$scope.menuActive = toState.name.split('.')[0];
		});
	}
]);