From d771d4c53787f787ba1d4fbc3a463f75be791c71 Mon Sep 17 00:00:00 2001 From: kaidux22 Date: Mon, 23 Dec 2024 17:53:48 +0300 Subject: [PATCH] import_alert --- backend/app/routes.py | 7 ++++++- frontend/src/app/dbases/dbases.component.html | 2 +- frontend/src/app/dbases/dbases.component.ts | 10 ++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/app/routes.py b/backend/app/routes.py index cf57c7f..08ff751 100644 --- a/backend/app/routes.py +++ b/backend/app/routes.py @@ -317,6 +317,11 @@ def import_dump(): file_path = os.path.join('/backend/app/models/dumps', file.filename) file.save(file_path) + with open(file_path, 'r') as csvfile: + reader = csv.reader(csvfile) + row_count = sum(1 for row in reader) - 1 + + query_string = "MATCH(p) DETACH DELETE p" conn.query(query_string) @@ -406,7 +411,7 @@ def import_dump(): if result is None: return jsonify({"Error": f"error loading the database dump: {query_string}"}), 400 - return jsonify({"Success": f"File uploaded successfully"}), 200 + return jsonify({"Success": f"File uploaded successfully", "total_enters": row_count}), 200 @app.route('/api/export_dump', methods=['POST']) def export_dump(): diff --git a/frontend/src/app/dbases/dbases.component.html b/frontend/src/app/dbases/dbases.component.html index 69e6875..738b85d 100644 --- a/frontend/src/app/dbases/dbases.component.html +++ b/frontend/src/app/dbases/dbases.component.html @@ -8,7 +8,7 @@

Б
-

Общее количество записей: {{items.length}}

+

Количество записей: {{items.length}}


diff --git a/frontend/src/app/dbases/dbases.component.ts b/frontend/src/app/dbases/dbases.component.ts index 6d7b7bd..5db752c 100644 --- a/frontend/src/app/dbases/dbases.component.ts +++ b/frontend/src/app/dbases/dbases.component.ts @@ -23,6 +23,7 @@ export class DbasesComponent { items: any = []; idx: number = 0; req: any; + temp: any; page: number = 1; currect_enters: any = []; @@ -381,15 +382,16 @@ export class DbasesComponent { const formData = new FormData(); formData.append('file', file); - this.http.post('http://127.0.0.1:5000/api/import_dump', formData).subscribe( - response => { + this.http.post('http://127.0.0.1:5000/api/import_dump', formData).subscribe({ + next: (response: any) => { console.log('File uploaded successfully', response); + alert(`Импорт успешно произведён!\nКоличество произведённых записей: ${response['total_enters']}`) this.MakePostReq(this.type); }, - error => { + error: error => { console.error('Error uploading file', error); } - ); + }); } }