Commit e5b0eff0ea47e422c2c90fb7ae5dceaec577f3db
1 parent
333c7070
Exists in
dev
Add check visibility button on sequence edit view
Showing
3 changed files
with
77 additions
and
3 deletions
Show diff stats
src/core/pyros_django/routine_manager/templates/routine_manager/view_sequence.html
... | ... | @@ -3,6 +3,11 @@ |
3 | 3 | {% block section_title %} |
4 | 4 | SEQUENCE - {{ seq.name }} |
5 | 5 | {% endblock %} |
6 | +{% block head %} | |
7 | + | |
8 | + {% load static %} | |
9 | + <link rel="stylesheet" type="text/css" href="{% static '/css/global.css' %}"> | |
10 | +{% endblock head %} | |
6 | 11 | |
7 | 12 | {% block fields %} |
8 | 13 | <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> |
... | ... | @@ -32,6 +37,7 @@ |
32 | 37 | </table> |
33 | 38 | <div> |
34 | 39 | </div> |
40 | + | |
35 | 41 | {% if edit == True %} |
36 | 42 | <br> |
37 | 43 | |
... | ... | @@ -42,6 +48,8 @@ |
42 | 48 | <td> </td> |
43 | 49 | <td><button type="submit" class="btn btn-success" name="action" id="save_btn" value="save">Save and finish later</button></td> |
44 | 50 | <td> </td> |
51 | + <td><button type="submit" class="btn btn-success" name="action" value="check_visibility">Check target visibility</button></td> | |
52 | + <td> </td> | |
45 | 53 | <td><button type="submit" class="btn btn-success" name="action" value="check_validity">Check validity</button></td> |
46 | 54 | <td> </td> |
47 | 55 | {% if seq.complete and seq.scientific_program in request.user.get_scientific_programs and seq.status == "DRAFT" %} |
... | ... | @@ -68,7 +76,26 @@ |
68 | 76 | </div> |
69 | 77 | {% endif %} |
70 | 78 | </form> |
71 | - | |
79 | +<div class="modal" id="visibilityModal" role="dialog"> | |
80 | + <div class="modal-dialog modal-lg" role="document"> | |
81 | + <div class="modal-content"> | |
82 | + <div class="modal-header"> | |
83 | + <h5 id="#importResponseModal_title" class="modal-title">Check target visibility</h5> | |
84 | + <button type="button" class="close" onclick="$('#visibilityModal').hide();" aria-label="Close"> | |
85 | + <span aria-hidden="true">×</span> | |
86 | + </button> | |
87 | + </div> | |
88 | + <div class="modal-body"> | |
89 | + <div> | |
90 | + <p id="visibility_message">{{visibility_message}}</p> | |
91 | + </div> | |
92 | + </div> | |
93 | + <div class="modal-footer"> | |
94 | + <button type="button" class="btn btn-secondary" onclick="$('#visibilityModal').hide();">Close</button> | |
95 | + </div> | |
96 | + </div> | |
97 | + </div> | |
98 | +</div> | |
72 | 99 | |
73 | 100 | <script src="https://code.jquery.com/jquery-1.12.4.js"></script> |
74 | 101 | <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> |
... | ... | @@ -102,6 +129,26 @@ $(function(){ |
102 | 129 | {% if edit %} |
103 | 130 | <script> |
104 | 131 | var $=jQuery.noConflict(); |
132 | + | |
133 | + // info modal before delete | |
134 | + | |
135 | + var modal = document.getElementById('visibilityModal'); | |
136 | + if (document.getElementById('visibility_message').textContent != ""){ | |
137 | + modal.style.display = "block"; | |
138 | + } | |
139 | + if (modal != null) { | |
140 | + // When the user clicks anywhere outside of the modal, close it | |
141 | + window.onclick = function(event) { | |
142 | + if (event.target == modal) { | |
143 | + modal.style.display = "none"; | |
144 | + } | |
145 | + } | |
146 | + | |
147 | + document.querySelector("#visibilityModal").addEventListener("click", event => { | |
148 | + modal.style.display = "none"; | |
149 | + }); | |
150 | + } | |
151 | + | |
105 | 152 | current_layout = $("input[name='layout']:checked"); |
106 | 153 | if(current_layout.length == 0){ |
107 | 154 | // No layout selected | ... | ... |
src/core/pyros_django/routine_manager/urls.py
... | ... | @@ -19,6 +19,8 @@ urlpatterns = [ |
19 | 19 | views.action_sequence, name="action_sequence"), |
20 | 20 | re_path(r'^action_sequence/(?P<seq_id>\d+)/(?P<action>[a-z_]{1,20})/(?P<status>-?\d)/(?P<message>.+)$', |
21 | 21 | views.action_sequence, name="action_sequence_message"), |
22 | + re_path(r'^action_sequence/(?P<seq_id>\d+)/(?P<action>[a-z_]{1,20})/(?P<visibility_message>.+)$', | |
23 | + views.action_sequence, name="action_sequence_visibility_message"), | |
22 | 24 | |
23 | 25 | re_path(r'^action_album/(?P<alb_id>\d+)/(?P<action>[a-z_]{1,20})$', |
24 | 26 | views.action_album, name="action_album"), | ... | ... |
src/core/pyros_django/routine_manager/views.py
... | ... | @@ -39,10 +39,13 @@ from .functions import check_sequence_file_validity_and_save, create_sequence_pi |
39 | 39 | from .RequestSerializer import RequestSerializer |
40 | 40 | import scheduler |
41 | 41 | |
42 | +import numpy | |
43 | + | |
42 | 44 | # guitastro import |
43 | 45 | |
44 | 46 | import vendor.guitastro.src.guitastro as guitastro |
45 | - | |
47 | +# silk import | |
48 | +#from silk.profiling.profiler import silk_profile | |
46 | 49 | """ logger """ |
47 | 50 | # "import utils.Logger as l |
48 | 51 | # "log = l.setupLogger("routine_manager-views", "routine_manager-views") |
... | ... | @@ -185,7 +188,7 @@ def request_validate(request, req_id): |
185 | 188 | |
186 | 189 | @login_required |
187 | 190 | @level_required("Admin", "Unit-PI", "Observer") |
188 | -def action_sequence(request, seq_id, action, status=0, message=""): | |
191 | +def action_sequence(request, seq_id, action, visibility_message="", status=0, message=""): | |
189 | 192 | """ |
190 | 193 | Apply actions (view, edit, delete) on a given sequence |
191 | 194 | """ |
... | ... | @@ -298,6 +301,27 @@ def sequence_validate(request, seq_id): |
298 | 301 | return redirect(sequences_list) |
299 | 302 | elif action == "delete": |
300 | 303 | return redirect(action_sequence, seq_id, "delete") |
304 | + elif action == "check_visibility": | |
305 | + seq = form.save() | |
306 | + eph = guitastro.Ephemeris() | |
307 | + eph.set_home(home) | |
308 | + # duskelev a parametrer dans obsconfig (yml) | |
309 | + duskelev = -7 | |
310 | + message = "" | |
311 | + try: | |
312 | + # TODO remplacer les none par les fichiers pickle de ephem_sun & ephem_moon | |
313 | + ephem = eph.target2night(seq.config_attributes.get("target"), seq.night_id, None, None, preferance=seq.start_expo_pref, duskelev=duskelev) | |
314 | + except ValueError: | |
315 | + message += "Target value is not valid" | |
316 | + except guitastro.ephemeris.EphemerisException as ephemException: | |
317 | + message += str(ephemException) | |
318 | + if len(message) == 0: | |
319 | + if numpy.sum(ephem["visibility"]) == 0 : | |
320 | + message = "Target not visible" | |
321 | + else: | |
322 | + message = "Target visible" | |
323 | + visibility_message = message | |
324 | + return redirect(action_sequence, seq_id, "edit", visibility_message) | |
301 | 325 | elif action == "check_validity": |
302 | 326 | seq.save() |
303 | 327 | is_seq_valid = check_sequence_validity(seq) |
... | ... | @@ -836,6 +860,7 @@ def import_request(request): |
836 | 860 | @login_required |
837 | 861 | @csrf_exempt |
838 | 862 | @level_required("Admin", "Unit-PI", "Observer") |
863 | +#@silk_profile(name="import_sequence") | |
839 | 864 | def import_sequence(request): |
840 | 865 | """ |
841 | 866 | Ask for a YAML file, parse it and create a request in DB | ... | ... |