Did some more of the modify fields
This commit is contained in:
parent
d6f21b0561
commit
064ff5f534
62
app.py
62
app.py
|
|
@ -137,12 +137,66 @@ def add_card():
|
||||||
else:
|
else:
|
||||||
return "failure"
|
return "failure"
|
||||||
|
|
||||||
@app.route("/modify_asset")
|
@app.route("/modify_asset", methods=['POST'])
|
||||||
def modify_asset():
|
def modify_asset():
|
||||||
return None
|
lookup = {'tag':'asset_id',
|
||||||
@app.route("/modify_user")
|
'serial':'serial',
|
||||||
|
'model':'model',
|
||||||
|
'category':'category'}
|
||||||
|
|
||||||
|
segments = []
|
||||||
|
parameters = []
|
||||||
|
data = request.json
|
||||||
|
|
||||||
|
for entry in data:
|
||||||
|
if entry == 'tag':
|
||||||
|
continue
|
||||||
|
if data[entry]:
|
||||||
|
segments.append(f'{lookup[entry]}=%s')
|
||||||
|
parameters.append(data[entry])
|
||||||
|
|
||||||
|
parameters.append(data['tag'])
|
||||||
|
query = f'''
|
||||||
|
update assets
|
||||||
|
SET {','.join(segments)}
|
||||||
|
WHERE asset_id = %s
|
||||||
|
'''
|
||||||
|
result = sql_utils.send_query(connection,query,parameters)
|
||||||
|
if result:
|
||||||
|
return "fuck you"
|
||||||
|
else:
|
||||||
|
return "fuck you too"
|
||||||
|
|
||||||
|
@app.route("/modify_user", methods=['POST'])
|
||||||
def modify_user():
|
def modify_user():
|
||||||
return None
|
lookup = {'id':'id_num',
|
||||||
|
'name':'name',
|
||||||
|
'asset':'assigned_asset',
|
||||||
|
'card':'assigned_card'}
|
||||||
|
|
||||||
|
segments = []
|
||||||
|
parameters = []
|
||||||
|
data = request.json
|
||||||
|
|
||||||
|
for entry in data:
|
||||||
|
if entry == 'tag':
|
||||||
|
continue
|
||||||
|
if data[entry]:
|
||||||
|
segments.append(f'{lookup[entry]}=%s')
|
||||||
|
parameters.append(data[entry])
|
||||||
|
|
||||||
|
parameters.append(data['id'])
|
||||||
|
query = f'''
|
||||||
|
update users
|
||||||
|
SET {','.join(segments)}
|
||||||
|
WHERE id_num = %s
|
||||||
|
'''
|
||||||
|
result = sql_utils.send_query(connection,query,parameters)
|
||||||
|
if result:
|
||||||
|
return "fuck you"
|
||||||
|
else:
|
||||||
|
return "fuck you too"
|
||||||
|
|
||||||
@app.route("/modify_card")
|
@app.route("/modify_card")
|
||||||
def modify_card():
|
def modify_card():
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
|
|
@ -132,12 +132,89 @@ async function add_card() {
|
||||||
await get_next_card();
|
await get_next_card();
|
||||||
}
|
}
|
||||||
|
|
||||||
function post_data_format(argsObject) {
|
async function modify_asset() {
|
||||||
args = []
|
let serial = document.getElementById("modify-asset-serial");
|
||||||
for (let property in argsObject) {
|
let tag = document.getElementById("modify-asset-tag");
|
||||||
args.push(`${property}=${argsObject[property]}`)
|
let category = document.getElementById("modify-asset-category");
|
||||||
|
let model = document.getElementById("modify-asset-model");
|
||||||
|
|
||||||
|
if (tag.value == "") {
|
||||||
|
alert("Modify asset error:\nThe tag field cannot be empty!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return "?" + args.join('&');
|
|
||||||
|
let serial_data = (serial.value == "") ? null : serial.value;
|
||||||
|
let tag_data = (tag.value == "") ? null : tag.value;
|
||||||
|
let category_data = (category.value == "N/A") ? null : category.value;
|
||||||
|
let model_data = (model.value == "N/A") ? null : model.value;
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
"tag": tag_data,
|
||||||
|
"serial": serial_data,
|
||||||
|
"category": category_data,
|
||||||
|
"model": model_data
|
||||||
|
}
|
||||||
|
|
||||||
|
await fetch("/modify_asset", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
})
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(data => {
|
||||||
|
console.log(data);
|
||||||
|
})
|
||||||
|
|
||||||
|
serial.value = "";
|
||||||
|
tag.value = "";
|
||||||
|
category.value = "N/A";
|
||||||
|
model.value = "N/A";
|
||||||
|
}
|
||||||
|
|
||||||
|
async function modify_user() {
|
||||||
|
let id = document.getElementById("modify-user-id");
|
||||||
|
let username = document.getElementById("modify-user-name");
|
||||||
|
let asset = document.getElementById("modify-assigned-asset");
|
||||||
|
let card = document.getElementById("modify-assigned-card");
|
||||||
|
|
||||||
|
if (id.value == "") {
|
||||||
|
alert("modify user error:\nUser ID field cannot be null!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let id_data = (id.value == "") ? null : id.value;
|
||||||
|
let username_data = (username.value == "") ? null : username.value;
|
||||||
|
let asset_data = (asset.value == "null") ? null : asset.value;
|
||||||
|
let card_data = (card.value == "null") ? null : card.value;
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
"id": id_data,
|
||||||
|
"name": username_data,
|
||||||
|
"asset": asset_data,
|
||||||
|
"card": card_data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
await fetch("/modify_user", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
})
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(data => {
|
||||||
|
console.log(data);
|
||||||
|
})
|
||||||
|
|
||||||
|
id.value = "";
|
||||||
|
username.value = "";
|
||||||
|
asset.value = "";
|
||||||
|
card.value = "";
|
||||||
|
|
||||||
|
await populate_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function populate_available_assets() {
|
async function populate_available_assets() {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h1>Assets</h1>
|
<h1>Assets</h1>
|
||||||
<button type="button" onclick="get_assets()">Get assets</button>
|
<button type="button" onclick="get_assets()">Get assets</button>
|
||||||
|
<button type="button" onclick="clear_asset_list()">Clear List</button>
|
||||||
<table id="asset_table">
|
<table id="asset_table">
|
||||||
<tr>
|
<tr>
|
||||||
<td>Asset tag</td>
|
<td>Asset tag</td>
|
||||||
|
|
@ -142,6 +143,13 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clear_asset_list() {
|
||||||
|
let elements = document.getElementsByClassName("asset_data");
|
||||||
|
while (elements[0]) {
|
||||||
|
elements[0].remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function get_assets() {
|
async function get_assets() {
|
||||||
let elements = document.getElementsByClassName("asset_data");
|
let elements = document.getElementsByClassName("asset_data");
|
||||||
while (elements[0]) {
|
while (elements[0]) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue