Skip to content

Commit

Permalink
import_alert
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidux22 committed Dec 23, 2024
1 parent d067e52 commit d771d4c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion backend/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/dbases/dbases.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h2 (click)="GoToDB('patients')" [ngClass]="{'active': type === 'patients'}">Б
<div class="dbases">

<div class="filter">
<h3>Общее количество записей: <i>{{items.length}}</i></h3>
<h3>Количество записей: <i>{{items.length}}</i></h3>
<div *ngIf="type === 'patients'">
<label for="name">ФИО</label>
<br>
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/app/dbases/dbases.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class DbasesComponent {
items: any = [];
idx: number = 0;
req: any;
temp: any;

page: number = 1;
currect_enters: any = [];
Expand Down Expand Up @@ -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);
}
);
});
}
}

Expand Down

0 comments on commit d771d4c

Please sign in to comment.