Commit e49ef271d001d997847af254494af054a52075fd
1 parent
f70471e8
Exists in
dev
Add vue to render list of received&sent commands
Showing
6 changed files
with
99 additions
and
8 deletions
Show diff stats
CHANGELOG
src/core/pyros_django/api/serializers.py
... | ... | @@ -99,6 +99,10 @@ class FullSequenceSerializer(serializers.ModelSerializer): |
99 | 99 | extra_fields = ["pyros_user", "albums"] |
100 | 100 | |
101 | 101 | |
102 | +class AgentCmdSerializer(serializers.ModelSerializer): | |
103 | + class Meta: | |
104 | + model = AgentCmd | |
105 | + fields = "__all__" | |
102 | 106 | |
103 | 107 | class AgentSurveySerializer(serializers.ModelSerializer): |
104 | 108 | class Meta: | ... | ... |
src/core/pyros_django/api/urls.py
... | ... | @@ -12,6 +12,7 @@ router.register(r'full_sequences', views.FullSequenceViewSet) |
12 | 12 | router.register(r'scientific_programs', views.ScientificProgramViewSet) |
13 | 13 | router.register(r'sp_period', views.SPPeriodViewSet) |
14 | 14 | router.register(r'agent_survey', views.AgentSurveyViewSet) |
15 | +router.register(r'agent_cmd', views.AgentCmdViewSet) | |
15 | 16 | |
16 | 17 | urlpatterns = [ |
17 | 18 | path('', include(router.urls)), |
... | ... | @@ -19,4 +20,5 @@ urlpatterns = [ |
19 | 20 | path('api-token-auth/', obtain_auth_token, name='api_token_auth'), |
20 | 21 | path("submit_sequence", views.submit_sequence_with_json, |
21 | 22 | name="api_submit_sequence"), |
23 | + path("agent_cmd/<str:agent_name>",views.AgentCmdViewSet.as_view({'get': 'list'})) | |
22 | 24 | ] + router.urls | ... | ... |
src/core/pyros_django/api/views.py
... | ... | @@ -6,8 +6,8 @@ from rest_framework.permissions import IsAuthenticated, AllowAny |
6 | 6 | from rest_framework.decorators import api_view, permission_classes, action |
7 | 7 | from django.core.validators import ValidationError |
8 | 8 | from src.core.pyros_django.user_manager import views as user_views |
9 | -from api.serializers import AgentSurveySerializer, AlbumSerializer, FullSequenceSerializer, PlanSerializer, SPPeriodSerializer, ScientificProgramSerializer, SequenceSerializer, UserSerializer | |
10 | -from common.models import PyrosUser, SP_Period, ScientificProgram, Sequence, Album, Plan, UserLevel, SP_Period_User, AgentSurvey | |
9 | +from api.serializers import AgentSurveySerializer, AlbumSerializer, FullSequenceSerializer, PlanSerializer, SPPeriodSerializer, ScientificProgramSerializer, SequenceSerializer, UserSerializer, AgentCmdSerializer | |
10 | +from common.models import PyrosUser, SP_Period, ScientificProgram, Sequence, Album, Plan, UserLevel, SP_Period_User, AgentSurvey, AgentCmd | |
11 | 11 | from routine_manager.functions import check_sequence_file_validity |
12 | 12 | from rest_framework.request import Request |
13 | 13 | from django.db.models import Q |
... | ... | @@ -256,4 +256,32 @@ class AgentSurveyViewSet(viewsets.ModelViewSet): |
256 | 256 | date_minus_two_days = datetime_now - timedelta(days=2) |
257 | 257 | date_minus_two_days = date_minus_two_days.replace(tzinfo=timezone.utc) |
258 | 258 | agents = agents.exclude(updated__lt=date_minus_two_days) |
259 | - return agents | |
260 | 259 | \ No newline at end of file |
260 | + return agents | |
261 | + | |
262 | +class AgentCmdViewSet(viewsets.ModelViewSet): | |
263 | + """ | |
264 | + API endpoint that allows users to view their sequences. | |
265 | + """ | |
266 | + queryset = AgentCmd.objects.all() | |
267 | + serializer_class = AgentCmdSerializer | |
268 | + permission_classes = [IsAuthenticated] | |
269 | + http_method_names = ["get"] | |
270 | + def get_queryset(self): | |
271 | + agent_name = self.request.query_params.get('agent_name') | |
272 | + number = self.request.query_params.get('number') | |
273 | + if agent_name is None: | |
274 | + if "agent_name" in self.kwargs: | |
275 | + agent_name = self.kwargs["agent_name"] | |
276 | + else: | |
277 | + agent_name = None | |
278 | + if agent_name is not None: | |
279 | + commands_sent_by_agent = AgentCmd.get_commands_sent_by_agent(agent_name) | |
280 | + commands_recivied_by_agent = AgentCmd.get_commands_sent_to_agent(agent_name) | |
281 | + agent_cmds = commands_sent_by_agent | commands_recivied_by_agent | |
282 | + agent_cmds = agent_cmds.exclude(full_name="get_specific_cmds") | |
283 | + agent_cmds = agent_cmds.order_by("-s_deposit_time") | |
284 | + if number: | |
285 | + number = int(number) | |
286 | + agent_cmds = agent_cmds[:number] | |
287 | + return agent_cmds | |
288 | + return AgentCmd.objects.all().order_by("-id") | |
261 | 289 | \ No newline at end of file | ... | ... |
src/core/pyros_django/dashboard/templates/dashboard/agent_detail.html
... | ... | @@ -131,6 +131,45 @@ |
131 | 131 | </div> |
132 | 132 | {% endif %} |
133 | 133 | <br><h2> Commands <span style="color:green;">received</span> & <span style="color:blue;">sent</span> </h2><br> |
134 | + <div> | |
135 | + <table | |
136 | + class="table table-bordered tablesorter" id="cmdtable"> | |
137 | + <thead> | |
138 | + <tr> | |
139 | + <th>Command</th> | |
140 | + <th>Sender</th> | |
141 | + <th>Recipient</th> | |
142 | + <th>Status </th> | |
143 | + <th>Deposit (UTC)</th> | |
144 | + <th>Read (UTC)</th> | |
145 | + <th>Validity (s)</th> | |
146 | + <th>Timeout (s)</th> | |
147 | + <th>Exec start (UTC)</th> | |
148 | + <th>Exec end (UTC)</th> | |
149 | + <th>Result</th> | |
150 | + </tr> | |
151 | + </thead> | |
152 | + <tbody> | |
153 | + | |
154 | + | |
155 | + <tr v-for="command in commands" v-bind:class="'{{agent_name}}' == command.sender ? 'blue' : 'green'"> | |
156 | + <td> [[ command.full_name ]] </td> | |
157 | + | |
158 | + <td v-if="command.sender.includes('@') || command.sender == 'System'">[[ command.sender]]</td> | |
159 | + <td v-else> <a v-bind:href="`/dashboard/agent_detail/${command.sender}`">[[ command.sender]]</a></td> | |
160 | + <td> <a v-bind:href="`/dashboard/agent_detail/${command.recipient}`">[[ command.recipient ]]</a></td> | |
161 | + <td> [[ command.state ]] </td> | |
162 | + <td> [[ command.s_deposit_time]] </td> | |
163 | + <td> [[ command.r_read_time]]</td> | |
164 | + <td> [[ command.validity_duration]] </td> | |
165 | + <td> [[ command.exec_timeout]] </td> | |
166 | + <td> [[ command.r_start_time]]</td> | |
167 | + <td> [[ command.r_end_time]]</td> | |
168 | + <td> [[ command.result ]] </td> | |
169 | + </tr> | |
170 | + </tbody> | |
171 | + </table> | |
172 | + {% comment %} | |
134 | 173 | {% if commands %} |
135 | 174 | <div> |
136 | 175 | <table |
... | ... | @@ -198,6 +237,7 @@ |
198 | 237 | <p> No commands has been send by this agent.</p> |
199 | 238 | {% endif %} |
200 | 239 | </div> |
240 | +{% endcomment %} | |
201 | 241 | {% if not error_message %} |
202 | 242 | <div> |
203 | 243 | <h2> Last logs : </h2> |
... | ... | @@ -281,7 +321,6 @@ |
281 | 321 | fetch("/api/agent_survey/"+agent_name+"?format=json").then(response => response.json()).then(function(data){ |
282 | 322 | agent_status.text(data.status); |
283 | 323 | agent_mode.text(data.mode); |
284 | - console.log(main_agent_status) | |
285 | 324 | if (main_agent_status == "EXITING"){ |
286 | 325 | document.getElementsByClassName("agent_status")[index].parentElement.children[3].querySelector("#startbtn").disabled = true; |
287 | 326 | document.getElementsByClassName("agent_status")[index].parentElement.children[3].querySelector("#stopbtn").disabled = true; |
... | ... | @@ -316,7 +355,13 @@ |
316 | 355 | function refresh_agent_info(){ |
317 | 356 | |
318 | 357 | fetch("/api/agent_survey/{{agent_name}}?format=json").then(response => response.json()).then(function(data){ |
319 | - app.agent = data; | |
358 | + app2.agent = data; | |
359 | + }); | |
360 | + } | |
361 | + function refresh_cmds_table(){ | |
362 | + | |
363 | + fetch("/api/agent_cmd/{{agent_name}}?format=json&number=20").then(response => response.json()).then(function(data){ | |
364 | + app.commands = data; | |
320 | 365 | }); |
321 | 366 | } |
322 | 367 | $(document).ready(function() { |
... | ... | @@ -324,13 +369,23 @@ |
324 | 369 | refresh_agent_info(); |
325 | 370 | //setInterval(refresh_command_column,5000); |
326 | 371 | setInterval(refresh_agent_info,4000); |
372 | + refresh_cmds_table(); | |
373 | + setInterval(refresh_cmds_table,10000); | |
327 | 374 | }); |
328 | 375 | var app = new Vue({ |
329 | 376 | delimiters:["[[","]]"], |
377 | + el: '#cmdtable', | |
378 | + data: { | |
379 | + commands: [], | |
380 | + is_sender: false, | |
381 | + } | |
382 | + }); | |
383 | + var app2 = new Vue({ | |
384 | + delimiters:["[[","]]"], | |
330 | 385 | el: '#agent_info', |
331 | 386 | data: { |
332 | 387 | agent: [] |
333 | 388 | } |
334 | - }) | |
389 | + }); | |
335 | 390 | </script> |
336 | 391 | {% endblock %} |
337 | 392 | \ No newline at end of file | ... | ... |
src/core/pyros_django/dashboard/templates/dashboard/agents_state.html