Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions python/PiFinder/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,40 @@ def equipment_delete_eyepiece(eyepiece_id: int):
success_message="Eyepiece Deleted, restart your PiFinder to remove from menu",
)

@app.route("/equipment/reorder_eyepieces", method="post")
@auth_required
def equipment_reorder_eyepieces():
cfg = config.Config()
try:
# Get the new order from the request body
data = request.json
new_order = data.get("order", [])

# Validate the order
if len(new_order) != len(cfg.equipment.eyepieces):
return {"success": False, "error": "Invalid order length"}

# Reorder the eyepieces based on the new indices
reordered_eyepieces = [
cfg.equipment.eyepieces[idx] for idx in new_order
]
cfg.equipment.eyepieces = reordered_eyepieces

# Update active eyepiece index if needed
if cfg.equipment.active_eyepiece_index >= 0:
# Find where the active eyepiece moved to
old_active_idx = cfg.equipment.active_eyepiece_index
new_active_idx = new_order.index(old_active_idx)
cfg.equipment.active_eyepiece_index = new_active_idx

# Save the new order
cfg.save_equipment()
self.ui_queue.put("reload_config")

return {"success": True}
except Exception as e:
return {"success": False, "error": str(e)}

@app.route("/equipment/edit_instrument/<instrument_id:int>")
@auth_required
def edit_instrument(instrument_id: int):
Expand Down
1 change: 0 additions & 1 deletion python/PiFinder/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from time import perf_counter as precision_timestamp
import os
import threading
from PIL import Image

from PiFinder import state_utils
from PiFinder import utils
Expand Down
75 changes: 63 additions & 12 deletions python/views/equipment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,24 @@
% end
</table>

<h5 class="grey-text">Eyepieces</h5>
<h5 class="grey-text">Eyepieces <span class="grey-text text-lighten-1" style="font-size: 14px;">(drag to reorder)</span></h5>
<table class="grey darken-2 grey-text z-depth-1">
<tr>
<th>Make</th>
<th>Name</th>
<th>Focal Length (mm)</th>
<th>Apparent FOV</th>
<th>Field Stop</th>
<th>Active</th>
<th>Actions</th>
</tr>

<thead>
<tr>
<th style="width: 30px;"></th>
<th>Make</th>
<th>Name</th>
<th>Focal Length (mm)</th>
<th>Apparent FOV</th>
<th>Field Stop</th>
<th>Active</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="eyepiece-list">
% for eyepiece in equipment.eyepieces:
<tr>
<tr data-eyepiece-index="{{equipment.eyepieces.index(eyepiece)}}" style="cursor: move;">
<td class="drag-handle"><i class="material-icons grey-text text-lighten-1">drag_indicator</i></td>
<td>{{eyepiece.make}}</td>
<td>{{eyepiece.name}}</td>
<td>{{eyepiece.focal_length_mm}}</td>
Expand All @@ -147,10 +151,12 @@
</td>
</tr>
% end
</tbody>
</table>

<br/>

<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
let elems = document.querySelectorAll('select');
Expand All @@ -165,6 +171,51 @@
function set_instrument_id(id) {
let instrument_id = id;
}

// Initialize drag-and-drop for eyepieces
document.addEventListener('DOMContentLoaded', function () {
const eyepieceList = document.getElementById('eyepiece-list');
if (eyepieceList) {
Sortable.create(eyepieceList, {
handle: '.drag-handle',
animation: 150,
ghostClass: 'grey',
onEnd: function (evt) {
// Get the new order of eyepiece indices
const rows = eyepieceList.querySelectorAll('tr');
const newOrder = Array.from(rows).map(row =>
parseInt(row.getAttribute('data-eyepiece-index'))
);

// Send the new order to the server
fetch('/equipment/reorder_eyepieces', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ order: newOrder })
})
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('Eyepiece order saved successfully');
// Update the data-eyepiece-index attributes to reflect new positions
rows.forEach((row, index) => {
row.setAttribute('data-eyepiece-index', index);
});
} else {
console.error('Failed to save eyepiece order');
M.toast({html: 'Failed to save eyepiece order', classes: 'red'});
}
})
.catch(error => {
console.error('Error saving eyepiece order:', error);
M.toast({html: 'Error saving eyepiece order', classes: 'red'});
});
}
});
}
});
</script>

% include("footer.tpl")
Expand Down