diff --git a/back-end/controllers/celery_controller/celery_tasks.py b/back-end/controllers/celery_controller/celery_tasks.py index d9d5277..b8d3088 100755 --- a/back-end/controllers/celery_controller/celery_tasks.py +++ b/back-end/controllers/celery_controller/celery_tasks.py @@ -212,7 +212,6 @@ def toggle_tiles(self, markers, userid, folderid, polygonfeatures): status_code = 0 session = Session() try: - file_editfile_link_set = set() user_folder = folder_ops.get_folder_with_id(userid=userid, folderid=folderid, session=session) if user_folder: # Process each polygon feature @@ -227,18 +226,24 @@ def toggle_tiles(self, markers, userid, folderid, polygonfeatures): new_editfile = editfile_ops.create_editfile(filename=editfile_name, content=feature_binary, folderid=folderid, session=session) session.commit() - # Link this editfile with relevant files + file_ids = set() + if markers[index]: + for filename in markers[index][0]['editedFile']: + fileVal = file_ops.get_file_with_name(filename=filename, folderid=user_folder.id, session=session) + file_ids.add( + fileVal.id + ) + + for file_id in file_ids: + file_editfile_link_ops.link_file_and_editfile(file_id, new_editfile.id, session) + for marker in markers[index]: # Query kml_data_entries based on location_id and filenames from editedFile for filename in marker['editedFile']: kml_data_entries = session.query(kml_data).join(file).filter(kml_data.location_id == marker['id'], file.folder_id == user_folder.id, file.name == filename).all() for entry in kml_data_entries: - file_instance = session.query(file).filter_by(id=entry.file_id).first() - if file_instance: - if (file_instance.id, new_editfile.id) not in file_editfile_link_set: - file_editfile_link_ops.link_file_and_editfile(file_instance.id, new_editfile.id, session) - file_editfile_link_set.add((file_instance.id, new_editfile.id)) session.delete(entry) + session.commit() else: diff --git a/back-end/controllers/database_controller/file_editfile_link_ops.py b/back-end/controllers/database_controller/file_editfile_link_ops.py index c653d77..019418e 100644 --- a/back-end/controllers/database_controller/file_editfile_link_ops.py +++ b/back-end/controllers/database_controller/file_editfile_link_ops.py @@ -8,6 +8,19 @@ def link_file_and_editfile(file_id, editfile_id, session): session.commit() return new_link +def unlink_file_and_editfile(file_id, editfile_id, session): + # Query to find the existing link between the file and editfile + link = session.query(file_editfile_link).filter( + file_editfile_link.file_id == file_id, + file_editfile_link.editfile_id == editfile_id + ).first() + + # If a link exists, delete it from the session and commit the change + if link: + session.delete(link) + session.commit() + + def get_editfiles_for_file(file_id, session): file_instance = session.query(file).filter_by(id=file_id).one() diff --git a/back-end/controllers/database_controller/file_ops.py b/back-end/controllers/database_controller/file_ops.py index 9bb8545..5b8fba0 100755 --- a/back-end/controllers/database_controller/file_ops.py +++ b/back-end/controllers/database_controller/file_ops.py @@ -1,6 +1,6 @@ import psycopg2 from database.sessions import ScopedSession, Session -from database.models import file, kml_data +from database.models import file, kml_data, file_editfile_link from threading import Lock from datetime import datetime from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound @@ -216,33 +216,20 @@ def delete_file(fileid, session=None): owns_session = True try: + file_to_del = get_file_with_id(fileid, session) file_to_del = get_file_with_id(fileid, session) if file_to_del: - # Split name and extension - base_name, ext = file_to_del.name.rsplit('.', 1) - - # Check if the file is an edit file with the new naming scheme - if re.match(".*-edit\d*/$", ext): - orig_file_ext = ext.split('-edit')[0] - kml_entries = session.query(kml_data).filter(kml_data.file_id == fileid).all() - orig_file = get_file_with_name(base_name + '.' + orig_file_ext, file_to_del.folder_id, session) - if orig_file: - for kml_entry in kml_entries: - kml_entry.file_id = orig_file.id - kml_entry.served = True - kml_entry.coveredLocations = orig_file.name - session.add(kml_entry) - session.commit() - # If not an edit file, check for related edits - elif ext in ['.kml', '.geojson']: - related_edits = get_files_with_prefix(file_to_del.folder_id, f"{base_name + ext}-edit", session) - for edit in related_edits: - session.delete(edit) - + # Delete all associated editfile links first + links = session.query(file_editfile_link).filter(file_editfile_link.file_id == fileid).all() + for link in links: + session.delete(link) + + # Proceed to delete the file session.delete(file_to_del) if owns_session: session.commit() + except SQLAlchemyError as e: if owns_session: session.rollback() diff --git a/front-end/components/Editmap.js b/front-end/components/Editmap.js index b5ef085..79a5c7a 100755 --- a/front-end/components/Editmap.js +++ b/front-end/components/Editmap.js @@ -606,7 +606,6 @@ function Editmap() { allPoints.forEach(point => { const editedFile = Array.from(point.coveredBy).filter(file => checkedState[Array.from(point.coveredBy).sort().join(", ")]?.[file]); point.editedFile = new Set(editedFile); - console.log(point.editedFile); // Update feature state on the map for each point map.current.setFeatureState({ source: "custom", @@ -623,7 +622,6 @@ function Editmap() { selectedPolygonsRef.current.push(updatedPoints); setSelectedPolygons(selectedPolygonsRef.current); - console.log(polygonFeature); setSelectedPolygonsArea((prevAreas) => [ ...prevAreas, polygonFeature ]); diff --git a/front-end/components/Upload.js b/front-end/components/Upload.js index 3a98d15..168353a 100755 --- a/front-end/components/Upload.js +++ b/front-end/components/Upload.js @@ -159,9 +159,9 @@ export default function Upload() { event.preventDefault(); const formData = new FormData(); - formData.append("deadline", `${newDeadline.year}-${newDeadline.month}-01`); + formData.append("deadline", `${newDeadline.year}-${newDeadline.month}-03`); files.forEach((fileDetails) => { - const allowedExtensions = ["kml", "geojson", "csv", "kmz"]; + const allowedExtensions = ["kml", "geojson", "csv"]; const fileExtension = fileDetails.file.name .split(".") .pop() @@ -169,7 +169,7 @@ export default function Upload() { if (!allowedExtensions.includes(fileExtension)) { toast.error( - "Invalid File Format. Please upload a KML, GeoJSON, CSV, or KMZ file.", + "Invalid File Format. Please upload a KML, GeoJSON, or CSV file.", { position: toast.POSITION.TOP_RIGHT, autoClose: 10000, @@ -325,14 +325,10 @@ export default function Upload() { const handleNewDeadlineChange = ({ month, year }) => { - const formattedDeadline = `${month}/${year}`; - // Check if the deadline exists - const exists = folders.some(folder => folder.deadline === formattedDeadline); - if (exists) { - setOpenConfirmDialog(true); // Open confirmation dialog if exists - } else { - setNewDeadline({ month, year }); - } + + + setNewDeadline({ month, year }); + }; const confirmCreation = () => { @@ -470,16 +466,6 @@ export default function Upload() { > )} - setOpenConfirmDialog(false)}> - Confirm - - A filing for this deadline already exists. Are you sure you want to create another? - - - setOpenConfirmDialog(false)}>Cancel - Confirm - -