-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (44 loc) · 1.49 KB
/
app.js
File metadata and controls
51 lines (44 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(function () {
'use strict'
var app = angular.module('myApp', []);
app.controller('myController', myController);
app.service('GetLevelService', GetLevelService);
myController.$inject = ['$interval', 'GetLevelService'];
function myController($interval, GetLevelService) {
var ctrl = this;
// init variables
ctrl.changeInProgress = false;
ctrl.level = {};
ctrl.level.code = "";
ctrl.level.author = "";
ctrl.level.name = "";
$interval(checkIfLevelChange, 3000);
// FileWatch function call on every interval
function checkIfLevelChange() {
GetLevelService.getLevel().then(function (result) {
if (ctrl.changeInProgress) {
// load in new level
Object.assign(ctrl.level, result.data.level);
ctrl.changeInProgress = false;
}
if (ctrl.level.code !== result.data.level.code || ctrl.level.name !== result.data.level.name ||
ctrl.level.author !== result.data.level.author) {
// alert the view that a change is in progress
ctrl.changeInProgress = true;
}
});
}
ctrl.levelCodeAvailable = function() {
if (ctrl.level.code) return true;
}
}
GetLevelService.$inject = ['$http'];
function GetLevelService($http) {
var service = this;
service.getLevel = function () {
return $http({
url: "data/ocrLevel.json"
});
}
}
})();