20 }) |
20 }) |
21 .service('dataModel', function(dataApi) { |
21 .service('dataModel', function(dataApi) { |
22 //console.log('dataModel',this,dataApi); |
22 //console.log('dataModel',this,dataApi); |
23 this.data = dataApi.dataResource.get(); |
23 this.data = dataApi.dataResource.get(); |
24 }) |
24 }) |
25 .controller('homeCtrl', function($scope, $location, dataModel, context){ |
25 .controller('homeCtrl', function($scope, $location, dataModel, context, $interval){ |
26 //console.log('homeCtrl 1', $scope, $location, context); |
26 //console.log('homeCtrl 1', $scope, $location, context); |
27 console.log('homeCtrl 2', context); |
27 console.log('homeCtrl 2', context); |
28 $scope.data = dataModel.data; |
28 $scope.data = dataModel.data; |
29 |
29 |
30 dataModel.data.$promise.then(function(data) { |
30 dataModel.data.$promise.then(function(data) { |
43 $scope.allCatLabels = cats; |
43 $scope.allCatLabels = cats; |
44 } |
44 } |
45 }); |
45 }); |
46 |
46 |
47 $scope.selectedlevel = false; |
47 $scope.selectedlevel = false; |
48 |
48 |
|
49 $scope.currentInterval = false; |
|
50 $scope.showSuccessAlert = false; |
|
51 $scope.showAlertDiv = false; |
|
52 function showAlert(m, success){ |
|
53 $scope.alertMessage = m; |
|
54 $scope.showSuccessAlert = success; |
|
55 $scope.showAlertDiv = true; |
|
56 if(!$scope.$$phase) { |
|
57 $scope.$apply(); |
|
58 } |
|
59 if($scope.currentInterval){ |
|
60 $interval.cancel($scope.currentInterval); |
|
61 $scope.currentInterval = false; |
|
62 } |
|
63 $scope.currentInterval = $interval(function(){ console.log('fin interval !'); $interval.cancel($scope.currentInterval); $scope.showAlertDiv = false; }, 2000, 1); |
|
64 } |
49 |
65 |
50 |
66 |
51 |
67 |
52 // Socket management |
68 // Socket management |
53 var sock = null; |
69 var sock = null; |
77 if(context.logging===true){ |
93 if(context.logging===true){ |
78 log('Browser does not support WebSocket!'); |
94 log('Browser does not support WebSocket!'); |
79 } |
95 } |
80 window.location = 'http://autobahn.ws/unsupportedbrowser'; |
96 window.location = 'http://autobahn.ws/unsupportedbrowser'; |
81 } |
97 } |
82 console.log('socket in controller = ', sock); |
98 |
83 if (sock) { |
99 if (sock) { |
84 sock.onopen = function() { |
100 sock.onopen = function() { |
85 if(context.logging===true){ |
101 if(context.logging===true){ |
86 log('Connected to ' + wsuri); |
102 log('Connected to ' + wsuri); |
87 } |
103 } |
89 |
105 |
90 sock.onclose = function(e) { |
106 sock.onclose = function(e) { |
91 if(context.logging===true){ |
107 if(context.logging===true){ |
92 log('Connection closed (wasClean = ' + e.wasClean + ', code = ' + e.code + ', reason = ' + e.reason + ')'); |
108 log('Connection closed (wasClean = ' + e.wasClean + ', code = ' + e.code + ', reason = ' + e.reason + ')'); |
93 } |
109 } |
94 alert('Communication interrompue : la socket vient de se fermer.'); |
110 showAlert('Communication interrompue : la socket vient de se fermer.', false); |
95 sock = null; |
111 sock = null; |
96 }; |
112 }; |
97 |
113 |
98 sock.onmessage = function(e) { |
114 sock.onmessage = function(e) { |
99 if(context.logging===true){ |
115 if(context.logging===true){ |
100 log('Got message: ' + e.data); |
116 log('Got message: ' + e.data); |
101 } |
117 } |
102 alert('Annotation bien reçue.'); |
118 showAlert('Annotation bien reçue.', true); |
103 }; |
119 }; |
104 } |
120 } |
105 |
121 |
106 $scope.sendAnnotation = function(eventCode){ |
122 $scope.sendAnnotation = function(eventCode){ |
107 if($scope.username==='' || typeof $scope.username==='undefined'){ |
123 if($scope.username==='' || typeof $scope.username==='undefined'){ |
108 alert('Vous devez indiquer un nom d\'utilisateur.'); |
124 showAlert('Vous devez indiquer un nom d\'utilisateur.', false); |
109 return; |
125 return; |
110 } |
126 } |
111 if(eventCode==='' || typeof eventCode==='undefined'){ |
127 if(eventCode==='' || typeof eventCode==='undefined'){ |
112 alert('Vous devez indiquer un nom de catégorie.'); |
128 showAlert('Vous devez indiquer un nom de catégorie.', false); |
113 return; |
129 return; |
114 } |
130 } |
115 // Send query |
131 // Send query |
116 if (sock) { |
132 if (sock) { |
117 var new_annot = { |
133 var new_annot = { |
121 sock.send(JSON.stringify(new_annot)); |
137 sock.send(JSON.stringify(new_annot)); |
122 if(context.logging===true){ |
138 if(context.logging===true){ |
123 log('Sent: ' + JSON.stringify(new_annot)); |
139 log('Sent: ' + JSON.stringify(new_annot)); |
124 } |
140 } |
125 } else { |
141 } else { |
126 alert('La socket ne fonctionne pas.'); |
142 showAlert('La socket ne fonctionne pas.', false); |
127 if(context.logging===true){ |
143 if(context.logging===true){ |
128 log('Not connected.'); |
144 log('Not connected.'); |
129 } |
145 } |
130 } |
146 } |
131 }; |
147 }; |