add viewing of headset details maybe
parent
79ff48915d
commit
af8e820c8e
|
|
@ -10,7 +10,6 @@ from random import random
|
||||||
bp = Blueprint('api', __name__)
|
bp = Blueprint('api', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/', methods=['GET'])
|
@bp.route('/', methods=['GET'])
|
||||||
@require_api_key(0)
|
@require_api_key(0)
|
||||||
def api_home():
|
def api_home():
|
||||||
|
|
@ -23,7 +22,6 @@ def api_spec():
|
||||||
return send_from_directory('static', 'api_spec.json')
|
return send_from_directory('static', 'api_spec.json')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/get_all_headsets', methods=['GET'])
|
@bp.route('/get_all_headsets', methods=['GET'])
|
||||||
@require_api_key(0)
|
@require_api_key(0)
|
||||||
def get_all_headsets():
|
def get_all_headsets():
|
||||||
|
|
@ -87,22 +85,49 @@ def update_paring_code():
|
||||||
return 'Success'
|
return 'Success'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/get_headset_details/<hw_id>', methods=['GET'])
|
@bp.route('/get_headset_details/<hw_id>', methods=['GET'])
|
||||||
@require_api_key(10)
|
@require_api_key(10)
|
||||||
def get_headset_details(hw_id):
|
def get_headset_details(hw_id):
|
||||||
return jsonify(get_headset_details_db(hw_id))
|
values = get_headset_details_db(hw_id)
|
||||||
|
if len(values) == 1:
|
||||||
|
return jsonify(values[0])
|
||||||
|
else:
|
||||||
|
return jsonify({'error', "Can't find headset with that id."}), 400
|
||||||
|
|
||||||
|
|
||||||
def get_headset_details_db(hw_id):
|
def get_headset_details_db(hw_id):
|
||||||
conn, curr = connectToDB()
|
conn, curr = connectToDB()
|
||||||
query = """
|
query = """
|
||||||
SELECT * FROM `Headset` WHERE hw_id=%(hw_id)s;
|
SELECT * FROM `Headset` WHERE `hw_id`=%(hw_id)s;
|
||||||
"""
|
"""
|
||||||
curr.execute(query, {'hw_id': hw_id})
|
curr.execute(query, {'hw_id': hw_id})
|
||||||
values = [dict(row) for row in curr.fetchall()]
|
values = [dict(row) for row in curr.fetchall()]
|
||||||
curr.close()
|
curr.close()
|
||||||
return jsonify(values)
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/set_headset_details/<hw_id>', methods=['POST'])
|
||||||
|
@require_api_key(10)
|
||||||
|
def set_headset_details(hw_id):
|
||||||
|
return set_headset_details_db(hw_id, request.json)
|
||||||
|
|
||||||
|
|
||||||
|
def set_headset_details_db(hw_id, data):
|
||||||
|
conn, curr = connectToDB()
|
||||||
|
query = """
|
||||||
|
INSERT INTO `Headset`(
|
||||||
|
`hw_id`,
|
||||||
|
`current_room`
|
||||||
|
) VALUES(
|
||||||
|
%(hw_id)s,
|
||||||
|
%(current_room)s
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
data['hw_id'] = hw_id
|
||||||
|
curr.execute(query, data)
|
||||||
|
conn.commit()
|
||||||
|
curr.close()
|
||||||
|
return 'Success'
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/get_room_details/<room_id>', methods=['GET'])
|
@bp.route('/get_room_details/<room_id>', methods=['GET'])
|
||||||
|
|
@ -122,13 +147,13 @@ def get_room_details_db(room_id):
|
||||||
return jsonify(values)
|
return jsonify(values)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/update_room/<room_id>', methods=['POST'])
|
@bp.route('/set_room_details/<room_id>', methods=['POST'])
|
||||||
@require_api_key(10)
|
@require_api_key(10)
|
||||||
def update_room(room_id):
|
def set_room_details(room_id):
|
||||||
return jsonify(update_room_db(room_id, request.json))
|
return jsonify(set_room_details_db(room_id, request.json))
|
||||||
|
|
||||||
|
|
||||||
def update_room_db(room_id, data):
|
def set_room_details_db(room_id, data):
|
||||||
room_id = random.randint(0, 9999)
|
room_id = random.randint(0, 9999)
|
||||||
conn, curr = connectToDB()
|
conn, curr = connectToDB()
|
||||||
query = """
|
query = """
|
||||||
|
|
|
||||||
|
|
@ -29,3 +29,34 @@ function getCookie(cname) {
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function writeClass(className, data) {
|
||||||
|
if (data == undefined || data == null || data.toString() == 'undefined') {
|
||||||
|
data = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
let elements = document.getElementsByClassName(className);
|
||||||
|
Array.from(elements).forEach(e => {
|
||||||
|
e.innerHTML = data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeId(idName, data) {
|
||||||
|
if (data == undefined || data == null || data.toString() == 'undefined') {
|
||||||
|
data = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById(idName).innerHTML = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function writeSrc(className, data) {
|
||||||
|
if (data == undefined || data == null || data.toString() == 'undefined') {
|
||||||
|
data = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
let elements = document.getElementsByClassName(className);
|
||||||
|
Array.from(elements).forEach(e => {
|
||||||
|
e.src = data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -34,12 +34,41 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
<div id="loading" class="loading loading-lg"></div>
|
<div id="loading" class="loading loading-lg"></div>
|
||||||
<div id="failure">☹️</div>
|
<div id="failure" style="display: none;">☹️</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="headset_details" style="display: none;">
|
<div id="headset_details" style="display: none;">
|
||||||
<h2>HW ID</h2>
|
<div class="panel">
|
||||||
<p id="hw_id"></p>
|
<div class="panel-header text-center">
|
||||||
|
<figure class="avatar avatar-lg"><img src="static/favicon/android-chrome-192x192.png" alt="Avatar"></figure>
|
||||||
|
<div class="panel-title h5 mt-10">Headset Info</div>
|
||||||
|
<div class="panel-subtitle hw_id">---</div>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="tile tile-centered">
|
||||||
|
<div class="tile-content">
|
||||||
|
<div class="tile-title text-bold">Current Room</div>
|
||||||
|
<input class="btn" type="text" id="current_room" placeholder="----">
|
||||||
|
</div>
|
||||||
|
<div class="tile-action">
|
||||||
|
<button class="btn btn-link btn-action btn-lg tooltip tooltip-left"
|
||||||
|
data-tooltip="Set Room ID"><i class="icon icon-send"></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="tile tile-centered">
|
||||||
|
<div class="tile-content">
|
||||||
|
<div class="tile-title text-bold">First Added</div>
|
||||||
|
<div class="tile-subtitle date_created">---</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="tile tile-centered">
|
||||||
|
<div class="tile-content">
|
||||||
|
<div class="tile-title text-bold">Last Used</div>
|
||||||
|
<div class="tile-subtitle last_used">---</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -62,9 +91,12 @@
|
||||||
httpGetAsync('/api/get_headset_details/' + hw_id, (resp) => {
|
httpGetAsync('/api/get_headset_details/' + hw_id, (resp) => {
|
||||||
console.log(resp);
|
console.log(resp);
|
||||||
let respData = JSON.parse(resp);
|
let respData = JSON.parse(resp);
|
||||||
if (respData['hw_id'] != '') {
|
|
||||||
hw_id_field.innerText = respData['hw_id'];
|
writeClass('hw_id', respData['hw_data']);
|
||||||
}
|
writeClass('current_room', respData['current_room']);
|
||||||
|
writeClass('date_created', respData['date_created']);
|
||||||
|
writeClass('last_used', respData['last_used']);
|
||||||
|
|
||||||
headset_details.style.display = "block";
|
headset_details.style.display = "block";
|
||||||
}, (status) => {
|
}, (status) => {
|
||||||
failure.style.display = "block";
|
failure.style.display = "block";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue