diff --git a/app.py b/app.py index 9781c0a..d651a80 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, render_template, request, redirect +from flask import Flask, render_template, request, redirect, jsonify, Response import sqlite3 from flask_sqlalchemy import SQLAlchemy @@ -274,7 +274,7 @@ def edit_employee(id): employee = Employee.query.get(id) if request.method == 'GET': return render_template('edit_employee.html', employee=employee, locations=locations) - + if request.method == 'POST': employee.employee_name = request.form['employee_name'] employee.gender = request.form['gender'] @@ -286,7 +286,7 @@ def edit_employee(id): db.session.commit() return redirect('/employee') -@app.route('/edit_equipment', methods=['GET' ,'POST' ]) +@app.route('/edit_equipment', methods=['GET' ,'POST' ]) def edit_equipment(barcode_number): locations = Location.query.all() employees = Employee.query.all() @@ -336,5 +336,40 @@ def employee_index(): employees = Employee.query.all() return render_template ('employeeList.html', employees = employees) +@app.route('/search', methods=['GET']) +def search(): + res = None + entity = request.args.get('entity') + query = request.args.get('query') + + if entity == 'location': + data = Location.query.filter(Location.location_name.contains(query)).all() + res = jsonify([{ + "location_name": r.location_name, "number_of_offices": r.number_of_offices, "head_quater_contact": r.number_of_offices + } for r in data]) + + elif entity == 'employee': + data = Employee.query.filter(Employee.employee_name.contains(query)).all() + res = jsonify([{ + "employee_name": r.employee_name, "gender": r.gender, "title": r.title, "type": r.type, "phone_number": r.phone_number, "department": r.department, "location_id": r.location_id + } for r in data]) + + elif entity == 'equipment': + data = Equipment.query.filter(Equipment.type.contains(query)).all() + res = jsonify([{ + "type": r.type, "serial_number": r.serial_number, "model_number": r.model_number, "purchase_date": r.purchase_date, "employee": r.employee, "location_id": r.location_id + } for r in data]) + + elif entity == 'purchase': + data = Purchases.query.filter(Purchases.store.contains(query)).all() + res = jsonify([{ + "date": r.date, "store": r.store, "warranty_period": r.warranty_period, + } for r in data]) + + else: + res = Response("Invalid entity", status=400) + + return res + if __name__ == '__main__': app.run(host='localhost', port=8080, debug=True) diff --git a/instance/OIS.db b/instance/OIS.db deleted file mode 100644 index f521d4e..0000000 Binary files a/instance/OIS.db and /dev/null differ diff --git a/static/index.js b/static/index.js index 4960648..6fbdbf0 100644 --- a/static/index.js +++ b/static/index.js @@ -1,3 +1,24 @@ +$(document).ready(function() { + $('#search-button').click(function() { + var query = $('#query').val(); + $.ajax({ + url: '/search', + type: 'GET', + data: { query: query }, + success: function(response) { + var results = response; + var resultsHtml = ''; + for (var i = 0; i < results.length; i++) { + resultsHtml += '

' + results[i] + '

'; + } + $('#search-results').html(resultsHtml); + }, + error: function(error) { + console.log('Search request failed:', error); + } + }); + }); + }); // javascript code // function updateLocationCount() { @@ -12,3 +33,4 @@ // // Call the updateLocationCount function every 5 seconds // setInterval(updateLocationCount, 1000); + diff --git a/templates/employeeList.html b/templates/employeeList.html index 3df2410..a3889ef 100644 --- a/templates/employeeList.html +++ b/templates/employeeList.html @@ -8,12 +8,41 @@ rel="stylesheet" href="{{ url_for('static', filename='main.css') }}" /> + - + + + -
- - +
+ +
@@ -53,7 +82,7 @@

Welcome To Our Online Inventory System

Actions - + {% for employee in employees %} {{ employee.employee_name }} diff --git a/templates/equipmentList.html b/templates/equipmentList.html index 04c4f8d..0958edd 100644 --- a/templates/equipmentList.html +++ b/templates/equipmentList.html @@ -8,12 +8,40 @@ rel="stylesheet" href="{{ url_for('static', filename='main.css') }}" /> + + +
- - + +
@@ -52,7 +80,7 @@

Welcome To Our Online Inventory System

Actions - + {% for equip in equipment %} {{ equip.type }} diff --git a/templates/locationList.html b/templates/locationList.html index 1825a67..54e8ac8 100644 --- a/templates/locationList.html +++ b/templates/locationList.html @@ -4,16 +4,41 @@ Online Inventory System + + +
- - + +
@@ -37,6 +62,7 @@

Welcome To Our Online Inventory System

-->

Welcome To Our Online Inventory System

+
Add Location @@ -49,7 +75,7 @@

Welcome To Our Online Inventory System

Actions - + {% for location in locations %} {{ location.location_name }} diff --git a/templates/purchaseList.html b/templates/purchaseList.html index 8c269f0..e318bbc 100644 --- a/templates/purchaseList.html +++ b/templates/purchaseList.html @@ -8,12 +8,37 @@ rel="stylesheet" href="{{ url_for('static', filename='main.css') }}" /> + + +
- - + +
@@ -49,7 +74,7 @@

Welcome To Our Online Inventory System

Actions - + {% for purchase in purchases %} {{ purchase.date }}