{"size": 1119, "ext": "js", "max_stars_repo_path": "public/js/app/chat/chat.component.js", "max_stars_repo_name": "agustinlamenza/angular-socket-io", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/js/app/chat/chat.component.js", "max_issues_repo_name": "agustinlamenza/angular-socket-io", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/js/app/chat/chat.component.js", "max_forks_repo_name": "agustinlamenza/angular-socket-io", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 16.7014925373, "max_line_length": 50, "alphanum_fraction": 0.5504915103}
(function () {
	'use strict';

	angular
		.module('app.chat')
		.directive('chatApp', chatApp);

	chatApp.$inject = ['hubService'];

	function chatApp(hub) {
		var component = {
			restrict: 'E',
			templateUrl: '/js/app/chat/chat.template.html',
			controller: Chat,
			controllerAs: 'vm',
			scope: {},
			bindToController: {
				title: '@'
			}
		};

		return component;

		function Chat() {
			var vm = this;

			vm.author = 'Agustín G.L.';
			vm.name = '';
			vm.message = '';
			vm.messages = [];

			vm.send = send;

			function send() {
				hub.send(message({
					name: vm.name,
					message: vm.message,
					date: new Date()
				}));

				vm.message = '';
			}

			hub.recive(function (data) {
				vm.messages.push(message(data).description());
			});
		}

		function message(spec) {
			var name = spec.name || 'computer',
				message = spec.message || 'nothing',
				date = spec.date || new Date();

			var description = function () {
				return date + ' | ' + name + ' => ' + message;
			};

			return {
				name: name,
				message: message,
				date: date,
				description: description
			};
		}
	}
})();
