var app = angular.module('spoofcheck', ['ngRoute', 'ngAnimate', 'ngWebSocket']);

app.config( ['$routeProvider', '$locationProvider',
        function($routeProvider, $locationProvider) {
            $routeProvider.when(
                '/', {
                    templateUrl: '/static/ng-app/home.html',
                    controller: 'HomeController'
                }
            ).when(
                '/watch', {
                    templateUrl: '/static/ng-app/watch.html',
                    controller: 'WatchController'
                }
            ).when(
                '/report', {
                    templateUrl: '/static/ng-app/report.html',
                    controller: 'ReportController'
                }
            )
            ;
        }

])
    .constant('EVENTS', {
        output: 'output',
        sent: 'sent'
    })
;

app
    .factory('MonitorWebSocket', ['$websocket', 'EVENTS', '$rootScope',
        function($websocket, EVENTS, $rootScope) {
            console.log("Activated websocket");
            var ws = $websocket("ws://" + location.host + "/connect/monitor");
            var output = [];

            ws.onMessage(function(message) {
                var data = JSON.parse(message.data);
                console.log(message);

                // Routing
                if (data.opcode != "Error") {
                    output.push(data.message);
                    $rootScope.$broadcast(EVENTS.output);
                    console.log(output);
                }

            });

            return {
                output: output,
                checkDomain: function(domain) {
                    ws.send(JSON.stringify(
                        {
                            opcode: 'check',
                            domain: domain
                        }
                    ));
                }
            };


        }
    ])
;

app
    .controller('HomeController', ['$scope', '$rootScope', 'MonitorWebSocket', '$location', 'EVENTS',
        function($scope, $rootScope, MonitorWebSocket, $location, EVENTS) {
            $rootScope.domain = undefined;

            $scope.checkDomain = function(domain) {
                console.log("Firing checkDomain with " + domain);
                $rootScope.domain = domain;
                $rootScope.ws = MonitorWebSocket;

                $rootScope.$on(EVENTS.output, function(evt, data) {
                    console.log(evt);
                    $location.path("/report").replace();
                });

                $rootScope.ws.checkDomain(domain);

                $location.path("/watch");
                $rootScope.$broadcast(EVENTS.sent);
            }
        }
    ])

    .controller('WatchController', ['$scope', '$rootScope', '$location', 'EVENTS',
        function($scope, $rootScope, $location, EVENTS) {
            console.log("Loading watch controller");
            if ($rootScope.ws === undefined || $rootScope.domain === undefined) {
                $location.path("/");
            }


        }
    ])

    .controller('ReportController', ["$scope", '$rootScope', "$location",
        function($scope, $rootScope, $location) {
            if ($rootScope.ws === undefined || $rootScope.domain === undefined) {
                $location.path("/");
            } else {
                $scope.message = $rootScope.ws.output[$rootScope.ws.output.length - 1];
            }
        }
    ])
;
@@ -587,16 +587,24 @@
 '/report
+/:domain
 ', %7B%0A   
@@ -2485,17 +2485,38 @@
 %22/report
-%22
+/%22 + $rootScope.domain
 ).replac
@@ -3139,16 +3139,62 @@
 cation%22,
+ %22$routeParams%22, %22MonitorWebSocket%22, %22EVENTS%22,
 %0A       
@@ -3232,16 +3232,56 @@
 location
+, $routeParams, MonitorWebSocket, EVENTS
 ) %7B%0A    
@@ -3358,49 +3358,613 @@
 ined
-) %7B%0A                $location.path(%22/%22);%0A
+%0A                %7C%7C $rootScope.domain !== $routeParams.domain) %7B%0A                if ($routeParams.domain !== null && $routeParams.domain !== undefined) %7B%0A                    $rootScope.domain = $routeParams.domain;%0A                    $rootScope.ws = MonitorWebSocket;%0A                    $rootScope.ws.checkDomain($rootScope.domain);%0A                    $rootScope.$on(EVENTS.output, function(evt, data) %7B%0A                        console.log(evt);%0A                        $location.path(%22/report/%22 + $rootScope.domain).replace();%0A                    %7D);%0A                    $location.path(%22/watch%22);%0A    
     
@@ -3980,20 +3980,89 @@
  else %7B%0A
+    
     
+            $location.path(%22/%22);%0A                %7D%0A            %7D%0A
         
@@ -4137,30 +4137,16 @@
 h - 1%5D;%0A
-            %7D%0A
         

Add ability to specify domain in URL