Skip to content

Commit 3b97270

Browse files
author
Julie Pitt
committed
Making it so that the status shows up right away
1 parent d050c39 commit 3b97270

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

app/assets/javascripts/status-controller.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
var statusController = angular.module('StatusController', []);
22

33
function mainController($scope, $http) {
4-
$scope.status = "unknown";
54

6-
var wsUrl = jsRoutes.controllers.Application.crawlerStatusWs().webSocketURL()
5+
$scope.status = "retrieving";
76

8-
$scope.socket = new WebSocket(wsUrl)
7+
function doWebSocket() {
8+
var wsUrl = jsRoutes.controllers.Application.crawlerStatusWs().webSocketURL()
9+
10+
$scope.socket = new WebSocket(wsUrl)
11+
12+
$scope.socket.onmessage = function (msg) {
13+
$scope.$apply( function() {
14+
console.log("received : #{msg}");
15+
$scope.status = msg.data;
16+
})
17+
}
18+
}
19+
20+
$http.get(jsRoutes.controllers.Application.crawlerStatus().url)
21+
.success(function(data) {
22+
$scope.status = data;
23+
doWebSocket();
24+
})
25+
.error(function(data) {
26+
doWebSocket();
27+
});
28+
}
929

10-
$scope.socket.onmessage = function (msg) {
11-
$scope.$apply( function() {
12-
console.log("received : #{msg}");
13-
$scope.status = msg.data;
14-
})
15-
}
16-
}

app/controllers/Application.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ object Application extends Controller {
2727
val stateResponse = crawlControlActor ? CrawlState
2828
stateResponse.map {
2929
case status: ControllerState =>
30-
Ok(status.toString)
30+
val json = Map("state" -> status.toString)
31+
val out: JsValue = Json.toJson(json)
32+
33+
Ok(out.toString)
3134
case _ =>
3235
InternalServerError("Unknown Error")
3336
} recover {
@@ -66,7 +69,8 @@ object Application extends Controller {
6669
implicit request =>
6770
Ok(
6871
Routes.javascriptRouter("jsRoutes")(
69-
routes.javascript.Application.crawlerStatusWs
72+
routes.javascript.Application.crawlerStatusWs,
73+
routes.javascript.Application.crawlerStatus
7074
)
7175
).as("text/javascript")
7276
}

0 commit comments

Comments
 (0)