Skip to content

Commit 66a00fb

Browse files
committed
Added alot of stuff
1 parent 7322bd1 commit 66a00fb

File tree

13 files changed

+230
-28
lines changed

13 files changed

+230
-28
lines changed

application/config.py

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
addLocationConfig_path = getAbsolutePath('config/locations.yaml')
3939
addLocationConfig = Configuration.from_file(addLocationConfig_path).configure()
4040

41+
# Populates database with all locations added to reports.yaml
42+
reportConfig_path = getAbsolutePath('config/reports.yaml')
43+
reportConfig = Configuration.from_file(reportConfig_path).configure()
44+
4145
# This adds the application's base directory to the
4246
# configuration object, so that the rest of the application
4347
# can reference it.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
from application import app
22
from application.config import *
3+
from application.models import *
4+
from application.models.floorsModel import *
5+
from application.models.roomsModel import *
6+
from application.models.storagesModel import *
37
from application.logic.getAuthUser import AuthorizedUser
48
from application.logic.excelMaker import *
9+
from playhouse.shortcuts import model_to_dict, dict_to_model
510

611

712
from flask import render_template, \
813
request, \
914
flash, \
1015
redirect, \
11-
url_for
16+
url_for, \
17+
jsonify
1218

1319
@app.route('/Report/', methods = ['GET', 'POST'])
1420
def report():
@@ -18,10 +24,37 @@ def report():
1824

1925
if userLevel == 'admin':
2026
if request.method == "GET":
27+
allBuild = getBuildings()
2128
return render_template("views/ReportView.html",
2229
authLevel = userLevel,
23-
config = config)
30+
config = config,
31+
reportConfig = reportConfig,
32+
allBuild = allBuild)
2433
else:
2534
data = request.form
26-
genLocationReport(data['test'])
35+
print data
36+
locData = genLocationReport(data)
37+
#print addReportsConfig["locationQuantity"]["row_title"]
38+
#exportExcel("Test", reportConfig["locationQuantity"]["row_title"], reportConfig["locationQuantity"]["queries"], )
2739
return redirect(url_for("report"))
40+
41+
@app.route('/locationData/', methods = ['GET'])
42+
def locationData():
43+
locId = request.args.get('locId')
44+
locType = request.args.get('locType')
45+
print locType
46+
if locType == "Building":
47+
locObject = getFloors(locId)
48+
objectType = "Floor"
49+
elif locType == "Floor":
50+
locObject = getRooms(locId)
51+
objectType = "Room"
52+
elif locType == "Room":
53+
locObject = getStorages(locId)
54+
objectType = "Storage"
55+
locs = list()
56+
for loc in locObject:
57+
locs.append(model_to_dict(loc))
58+
return jsonify({'status':'OK',
59+
'locObject' : locs,
60+
'objectType' : objectType})

application/logic/\

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from openpyxl import Workbook
2+
import datetime
3+
from application import app
4+
from application.config import *
5+
from application.queries.locationReportQueries import *
6+
from application.queries.hazardReportQueries import *
7+
8+
def exportExcel(title, row_headers, indexes, objects):
9+
book = Workbook()
10+
sheet = book.active
11+
sheet.title = title
12+
sheet.append(row_headers)
13+
book.save(filename = config["export"]["path"])
14+
15+
def genLocationReport(loc_id):
16+
"""
17+
Returns a file of all chemicals and containers in a location
18+
"""
19+
print loc_id
20+
#for cont in getChemInStor(loc_id):
21+
# print cont.chemId.name
22+
#for cont in getChemInRoom(loc_id):
23+
# print cont.barcodeId
24+
#for cont in getChemInFloor(loc_id):
25+
# print cont.barcodeId
26+
#for cont in getChemInBuild(loc_id):
27+
# print cont.barcodeId
28+
for cont in getIBFlamLiquids():
29+
print cont.barcodeId
30+
return 0
31+
32+
def genHazardReport(building):
33+
"""
34+
Returns the quantity of each hazard by floor in building
35+
"""
36+
return 0
37+
38+
def genSpecialHazardList():
39+
"""
40+
Returns all special hazards (Peroxide, Pressure, Toxin/Time, Req_Stabalizer)
41+
"""
42+
return 0

application/logic/excelMaker.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,24 @@
55
from application.queries.locationReportQueries import *
66
from application.queries.hazardReportQueries import *
77

8-
def exportExcel(title):
8+
def exportExcel(title, row_headers, indexes, objects):
99
book = Workbook()
1010
sheet = book.active
1111
sheet.title = title
12-
sheet.append(['Row1', 'Row2', 'Row3'])
12+
sheet.append(row_headers)
13+
for row in range(len(objects)):
14+
for col in range(len(row_headers)):
15+
##Writes out each cell with the correct value, objects found in yaml
16+
sheet.cell(column=col+1, row=row+2, value = eval(indexes[row_headers[col].replace(" ", "_")]))
1317
book.save(filename = config["export"]["path"])
1418

15-
def genLocationReport(loc_id):
19+
def genLocationReport(locData):
1620
"""
1721
Returns a file of all chemicals and containers in a location
1822
"""
19-
print loc_id
20-
#for cont in getChemInStor(loc_id):
21-
# print cont.chemId.name
22-
#for cont in getChemInRoom(loc_id):
23-
# print cont.barcodeId
24-
#for cont in getChemInFloor(loc_id):
25-
# print cont.barcodeId
26-
#for cont in getChemInBuild(loc_id):
27-
# print cont.barcodeId
28-
for cont in getIBFlamLiquids():
29-
print cont.barcodeId
30-
return 0
23+
for cont in getChemInLoc(locData):
24+
print cont.chemId.name
25+
return getChemInLoc(locData)
3126

3227
def genHazardReport(building):
3328
"""

application/queries/locationReportQueries.py

+21
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@
77
from application.models.buildingsModel import *
88
from application.models.historiesModel import *
99

10+
def getChemInLoc(loc_data):
11+
##Returns all containers, chem in Storages and rooms and floors in build
12+
conditionals = {"Building":"Buildings.bId == loc_data['Building']", "Floor":"Floors.fId == loc_data['Floor']", "Room":"Rooms.rId == loc_data['Room']", "Storage":"Storages.sId == loc_data['Storage']"}
13+
if loc_data["Building"] != "*":
14+
wheres = eval(conditionals["Building"])
15+
for value in loc_data:
16+
if value == "Building":
17+
pass
18+
elif loc_data[value] != "*":
19+
wheres &= eval(conditionals[value])
20+
else:
21+
wheres = Buildings.name == Buildings.name
22+
conts = (Containers.select() \
23+
.join(Storages, on = (Containers.storageId == Storages.sId)) \
24+
.join(Rooms, on = (Rooms.rId == Storages.roomId)) \
25+
.join(Floors, on = (Floors.fId == Rooms.floorId)) \
26+
.join(Buildings, on = (Buildings.bId == Floors.buildId)) \
27+
.where(wheres)\
28+
.switch(Containers))
29+
return conts
30+
1031
def getChemInStor(s_id):
1132
##Done cont.storageId.roomId.floorId.buildId.name
1233
conts = (Containers.select() \

application/reports/Report.xlsx

512 Bytes
Binary file not shown.

application/static/js/local/Checkin.js

-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ function CheckInModal(name,barcode,lastroom,newQuantity,newroom){
33
var check = checkValues(list);
44
if (check == true) {
55
printdata(name,barcode,lastroom,newQuantity,newroom);
6-
76
}
8-
97
}
108

119
function checkValues(list){
@@ -32,6 +30,3 @@ function printdata(name,barcode,lastroom,newQuantity,newroom){
3230
$('.chemdata').append("<li>NewRoom:" +newroomy+"</li>")
3331
$("#myModal").modal('show');
3432
}
35-
36-
37-

application/static/js/local/changeForm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ function getData(barcodeId, formAction){
4747
console.log(data['status']) //TODO: change to write to a log file as well as console.
4848
}
4949
});
50-
}
50+
}
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
function getLocation(loc_type){
2+
var locId = document.getElementById(loc_type).value;
3+
if(locId == "*"){
4+
reset_fields(loc_type)
5+
}
6+
else{
7+
getData(locId, loc_type)
8+
}
9+
}
10+
11+
function reset_fields(loc_type){
12+
if (loc_type == "Building"){
13+
var locToDisable = ['#Floor', '#Room', '#Storage']
14+
}
15+
else if (loc_type == "Floor"){
16+
var locToDisable = ['#Room', '#Storage']
17+
}
18+
else if (loc_type == "Room"){
19+
var locToDisable = ['#Storage']
20+
}
21+
for(var i =0; i < locToDisable.length; i++){
22+
$(locToDisable[i]).children('.default').prop('selected', true);
23+
$(locToDisable[i]).prop('disabled', true);
24+
}
25+
}
26+
27+
function getData(locId, locType){
28+
$.ajax({ //AJAX call to url "/getLocation/" to get location children
29+
url: "/locationData/",
30+
data: {locId : locId, locType : locType},
31+
type: "GET",
32+
success: function(data) {
33+
if (data['status'] === 'OK'){
34+
$('[name=' + data["objectType"] + ']').prop('disabled', false);
35+
var options = "<option class='default' value='*'>All " + data["objectType"] + "s</option>"
36+
for(var i = 0; i < data['locObject'].length; i++){
37+
if (data['objectType'] == "Floor"){
38+
options += '<option value="' + data['locObject'][i].fId + '">' + data['locObject'][i].name + '</option>';
39+
}
40+
else if (data['objectType'] == "Room"){
41+
options += '<option value="' + data['locObject'][i].rId + '">' + data['locObject'][i].name + '</option>';
42+
}
43+
else if (data['objectType'] == "Storage"){
44+
options += '<option value="' + data['locObject'][i].sId + '">' + data['locObject'][i].name + '</option>';
45+
}
46+
}
47+
$("select#" + data["objectType"]).html(options);
48+
}
49+
}
50+
})
51+
}
52+
53+
function enableFields(){
54+
//This enables all fields on form so they get submitted
55+
$('select:disabled').prop('disabled', false);
56+
}
+21-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
<script src="/static/js/local/reportFill.js"></script>
12
<div class="form container text-center">
2-
<form name="report" method="post" class="form-group">
3-
<p>Reports</p>
4-
<input id="test" name="test" type="text" class="form-control" value="">
3+
<form name="report" method="post" class="form-group" onsubmit="enableFields()">
4+
{# Report Type Selection #}
5+
<div class="reportTypes form-group row">
6+
{% for report in reportConfig.ReportTypes.Inputs %}
7+
{% if report == "Building" %}
8+
<label class="co-xs-6">{{ report }}</label>
9+
<select id="{{report}}" name="{{report}}" class="form-control" onchange="getLocation('{{report}}')">
10+
<option selected disable value="*">All {{report}}s</option>
11+
{% for build in allBuild%}
12+
<option value={{build.bId}}>{{ build.name }}</option>
13+
{% endfor %}
14+
</select>
15+
{% else %}
16+
<label class="co-xs-6">{{ report }}</label>
17+
<select id="{{report}}" name="{{report}}" class="form-control" onchange="getLocation('{{report}}')" required disabled>
18+
<option selected value="*">All {{report}}s</option>
19+
</select>
20+
{% endif %}
21+
{% endfor %}
22+
</div>
523
<input class="btn btn-primary btn-lg" id="requestReport" type="submit" value="Submit">
624
</form>
725
</div>

config/default

Whitespace-only changes.

config/reports.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ReportTypes:
2+
Inputs:
3+
Building: "bId"
4+
Floor: "fId"
5+
Room: "rId"
6+
Storage: "sId"
7+
Hazard: "hId"
8+
LocationBased:
9+
name: "Location"
10+
id: "loc"
11+
LocationQuantity:
12+
options:
13+
- Building
14+
- Floor
15+
- Room
16+
- Storage
17+
- Hazard
18+
row_title:
19+
- Building
20+
- Floor
21+
- Room
22+
- Storage
23+
- Barcode
24+
- Chemical Name
25+
- Current Quantity
26+
- Current Unit
27+
queries:
28+
Building: objects[row].storageId.roomId.floorId.buildId.name
29+
Floor: objects[row].storageId.roomId.floorId.name
30+
Room: objects[row].storageId.roomId.name
31+
Storage: objects[row].storageId.name
32+
Chemical_Name: objects[row].chemId.name
33+
Primary_Hazard: objects[row].chemId.primaryHazard
34+
Barcode: objects[row].barcodeId
35+
Current_Quantity: objects[row].currentQuantity
36+
Current_Unit: objects[row].currentQuantityUnit
37+
Container_Capacity: objects[row].capacity
38+
Container_Capacity_Unit: objects[row].capacityUnit
39+
Manufacturer: objects[row].manufacturer

locationPop.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from application.models.storagesModel import *
99
from application.models.historiesModel import *
1010
from application.models.usersModel import *
11-
from application.config import *
1211
import random
1312
import datetime
1413

0 commit comments

Comments
 (0)