diff --git a/database_implementation/__pycache__/sqlite_api.cpython-312.pyc b/database_implementation/__pycache__/sqlite_api.cpython-312.pyc index a7790301ef527d8df1011e480fe45ef6a185d826..c0e9c6d8dfc4c6426ca79c99e16a7aebd115cb60 100644 Binary files a/database_implementation/__pycache__/sqlite_api.cpython-312.pyc and b/database_implementation/__pycache__/sqlite_api.cpython-312.pyc differ diff --git a/database_implementation/sqlite_api.py b/database_implementation/sqlite_api.py index 5ab59fb81e0107eeb95352106ae0c04841268a89..aa310494f1a68a56b215e90ce13fafa441827b05 100644 --- a/database_implementation/sqlite_api.py +++ b/database_implementation/sqlite_api.py @@ -57,6 +57,20 @@ class SqliteDatabaseAPI(database_api.CrisisEventsDatabase): self._disconnect(connection, cur) return collection_id + def delete_collection(self, collection_name): + connection, cur = self._connect() + cur.execute("DELETE FROM event_collections WHERE collection_name = ?", (collection_name,)) + + # Check if any row was affected + if cur.rowcount > 0: + print(f"Deleted collection '{collection_name}'") + self._disconnect(connection, cur) + return True + else: + print(f"Collection '{collection_name}' not found") + self._disconnect(connection, cur) + return False + def create_raw_text_file(self,collection_id,path): connection, cur = self._connect() cur.execute("INSERT INTO raw_text_files VALUES (NULL, ?, ?)", (collection_id,path,)) diff --git a/flask_backend.py b/flask_backend.py index 457bfcfd923c07ff91dfc461cfddc13e5bab3592..5e8c2aeebf3d41794bfd8969a24acf27f0b37a71 100644 --- a/flask_backend.py +++ b/flask_backend.py @@ -186,6 +186,28 @@ def v1_create_collection(): "collection_id":id }, 200 +@app.route('/api/v1/delete_collection', methods=['DELETE']) +def v1_delete_collection(): + data = request.json + + if "collection_info" not in data: + abort(400) + + collection_info = data["collection_info"] + + if "collection_name" not in collection_info: + abort(400) + + collection_name = collection_info["collection_name"] + + # Call the database function to delete the collection + success = database.delete_collection(collection_name) + + if success: + return jsonify({"status": "success", "message": f"Collection '{collection_name}' deleted"}), 200 + else: + abort(404, f"Collection '{collection_name}' not found") + @app.route('/api/v1/update_collection_glob', methods=['POST']) def v1_update_collection_glob(): diff --git a/frontend/crisis-events-text-summarization-frontend/src/App.js b/frontend/crisis-events-text-summarization-frontend/src/App.js index 1c4c102ed4b8d16aa933462df0af2ba6f04a4b8b..9fb57f9db089e2f40975222b060b55a0262462d7 100644 --- a/frontend/crisis-events-text-summarization-frontend/src/App.js +++ b/frontend/crisis-events-text-summarization-frontend/src/App.js @@ -127,6 +127,11 @@ function App() { updateFileLists(); } + const handleDeletedCollection = () => { + setSelectedCollection(null); + showEditor(); + } + const logoutFunction = () => { setAuthenticated(false); sessionStorage.setItem('authenticated', 'false'); @@ -192,7 +197,7 @@ function App() { {/* <Box sx={{border: '1px dashed grey', padding:1}}> */} <Grid container spacing={2}> <Grid item xs={2}> - <CollectionList collections={loadedCollections} onSelectCollection={setSelectedCollection} onListUpdate={updateCollectionList} onFileSelect={onFileSelect} collectionFileCache={collectionFileCache}/> + <CollectionList collections={loadedCollections} onSelectCollection={setSelectedCollection} onListUpdate={updateCollectionList} onFileSelect={onFileSelect} collectionFileCache={collectionFileCache} onDeletedCollection={handleDeletedCollection}/> </Grid> <Grid item xs={10}> { diff --git a/frontend/crisis-events-text-summarization-frontend/src/collection_list.js b/frontend/crisis-events-text-summarization-frontend/src/collection_list.js index 727ccea87883164018d48e56947bb0da95ec3547..79198b654354e6e41de0ce89afde34b7a2d28d12 100644 --- a/frontend/crisis-events-text-summarization-frontend/src/collection_list.js +++ b/frontend/crisis-events-text-summarization-frontend/src/collection_list.js @@ -1,6 +1,6 @@ import * as React from 'react' import './Sidebar.css' -import {dbCreateCollection, dbGetCollection, dbUploadRawTextFiles, dbUploadUrlFile, dbUploadRawHTMLFiles} from './database_util' +import {dbCreateCollection, dbGetCollection, dbUploadRawTextFiles, dbUploadUrlFile, dbUploadRawHTMLFiles, dbDeleteCollection} from './database_util' //General MUI imports @@ -85,6 +85,18 @@ const CollectionList = (props) => { props.onSelectCollection(detailCollection); } + const handleDelete = async (collectionName) => { + const isDeleted = await dbDeleteCollection(collectionName); + if (isDeleted) { + console.log(`Collection "${collectionName}" deleted successfully`); + props.onDeletedCollection(true); + props.onListUpdate(); + } else { + console.error(`Failed to delete collection "${collectionName}"`); + } + handleDeleteClose(); + } + return ( <div className="sidebar-container"> <aside id="aside" className="sidebar"> @@ -184,7 +196,7 @@ const CollectionList = (props) => { </DialogContent> <DialogActions> <Button onClick={handleDeleteClose}>Cancel</Button> - <Button >Delete</Button> + <Button onClick={() => handleDelete(displayedCollection)}>Delete</Button> </DialogActions> </Dialog> </div> diff --git a/frontend/crisis-events-text-summarization-frontend/src/database_util.js b/frontend/crisis-events-text-summarization-frontend/src/database_util.js index bb01c3f90335ec6d043ed45d6cb63de9a3316240..a77d277730519fd7cc2b25ea623886101e174929 100644 --- a/frontend/crisis-events-text-summarization-frontend/src/database_util.js +++ b/frontend/crisis-events-text-summarization-frontend/src/database_util.js @@ -29,6 +29,31 @@ export const dbCreateCollection = async (newCollectionName, newCollectionType) return result }; +export const dbDeleteCollection = async (collectionName) => { + console.log("dbDeleteCollection"); + const response = await fetch( + "http://127.0.0.1:5000/api/v1/delete_collection", + { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + "collection_info": { "collection_name": collectionName } + }), + } + ); + + const responseData = await response.json(); + if (responseData.status === "success") { + console.log("dbDeleteCollection Success"); + return true; + } else { + console.error("dbDeleteCollection Failed"); + return false; + } +}; + export const dbGetCollection = async (collection_id) => { console.log("dbGetCollection"); let result = await fetch("http://127.0.0.1:5000//api/v1/get_collection?collection=" + collection_id,)