Commit f2eeeb3758c4358e8aad5abbbff4e2110322776a
1 parent
9ac4dcf4
Exists in
dev
Add send command to agent from website (generic commands)
Showing
4 changed files
with
30 additions
and
1 deletions
Show diff stats
CHANGELOG
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | - Renabling print when pulling git repo of guitastro |
4 | 4 | - Update guiastro url |
5 | 5 | - Fixing guiastro siteobs in get_sun_elev() |
6 | + - Add send command to agent from website (generic commands) | |
6 | 7 | |
7 | 8 | 16-08-2022 (AKo): v0.5.1.0 |
8 | 9 | - Adding compilation of guitastro requirements.in file into Dockerfile | ... | ... |
src/core/pyros_django/dashboard/templates/dashboard/agent_detail.html
... | ... | @@ -22,6 +22,19 @@ |
22 | 22 | } |
23 | 23 | </style> |
24 | 24 | <div> |
25 | + <div><h1> Send command to {{agent_name}}</h1> | |
26 | + <form id="send_cmd_form" method="post" action="{% url 'send_cmd_agent' %}"> | |
27 | + {% csrf_token %} | |
28 | + <select name="cmd_name" id="cmd_name"> | |
29 | + {% for command in agent_general_commands %} | |
30 | + <option value="{{command}}">{{command}}</option> | |
31 | + {% endfor %} | |
32 | + </select> | |
33 | + <input type="hidden" name="agent_name" value="{{agent_name}}"/> | |
34 | + <input type="text" name="cmd_args" id="cmd_args"></input> | |
35 | + <input type="submit" value="Send command"></input> | |
36 | + </form> | |
37 | + </div> | |
25 | 38 | <h1> Commands of agent {{agent_name}} </h1> |
26 | 39 | {% if commands %} |
27 | 40 | <div> | ... | ... |
src/core/pyros_django/dashboard/urls.py
... | ... | @@ -52,4 +52,5 @@ urlpatterns = [ |
52 | 52 | path('agents_state', views.agents_state, name="agents_state"), |
53 | 53 | path('agent_detail/<str:agent_name>', views.agent_detail, name="agent_detail"), |
54 | 54 | path('retrieve_log_content', views.retrieve_log_content, name="retrieve_log_content"), |
55 | + path('send_cmd_agent',views.send_agent_cmd,name="send_cmd_agent"), | |
55 | 56 | ] | ... | ... |
src/core/pyros_django/dashboard/views.py
... | ... | @@ -201,7 +201,7 @@ def agent_detail(request, agent_name): |
201 | 201 | commands_sent_by_agent = AgentCmd.get_commands_sent_by_agent(agent_name) |
202 | 202 | commands_recivied_by_agent = AgentCmd.get_commands_sent_to_agent(agent_name) |
203 | 203 | commands_of_agent = commands_sent_by_agent | commands_recivied_by_agent |
204 | - commands_of_agent = commands_of_agent.order_by("s_deposit_time") | |
204 | + commands_of_agent = commands_of_agent.order_by("-s_deposit_time") | |
205 | 205 | paginator = Paginator(commands_of_agent, pyros_settings.NB_ELEMENT_PER_PAGE) |
206 | 206 | page_number = request.GET.get("page",1) |
207 | 207 | agent_general_commands = AgentCmd._AGENT_GENERAL_COMMANDS |
... | ... | @@ -213,6 +213,20 @@ def agent_detail(request, agent_name): |
213 | 213 | commands = paginator.page(paginator.num_pages) |
214 | 214 | return render(request, "dashboard/agent_detail.html", locals()) |
215 | 215 | |
216 | +def send_agent_cmd(request): | |
217 | + if request.POST: | |
218 | + reciever = request.POST.get("agent_name") | |
219 | + cmd_name = request.POST.get("cmd_name") | |
220 | + cmd_args = request.POST.get("cmd_args") | |
221 | + print(request.POST) | |
222 | + new_cmd = AgentCmd.send_cmd_from_to("Operator",reciever,cmd_name,cmd_args) | |
223 | + print(new_cmd) | |
224 | + if new_cmd != None: | |
225 | + messages.add_message(request, messages.INFO, f"Command sended !") | |
226 | + else: | |
227 | + messages.add_message(request, messages.INFO, f"Error while creating command, please try again.") | |
228 | + return redirect(agent_detail,agent_name=reciever) | |
229 | + | |
216 | 230 | def retrieve_log_content(request): |
217 | 231 | if request.POST: |
218 | 232 | agent_name = request.POST.get("agent_name") | ... | ... |