A lot of work has been done on Messages and Malfunction reporting. Messages, in particular, are done in the backend.
This commit is contained in:
parent
8194fd0f8b
commit
2582c4c4ee
|
@ -130,7 +130,7 @@ def setFitness():
|
||||||
|
|
||||||
# Cyberware management
|
# Cyberware management
|
||||||
cyberware = []
|
cyberware = []
|
||||||
newCyberwareTemplate = { "uuid": None, "name": None, "hotpluggable": False, "lastMalfunction": None, "canSet": [], "battery": None, "messages": [] }
|
newCyberwareTemplate = { "uuid": None, "name": None, "hotpluggable": False, "lastMalfunction": None, "canSet": None, "battery": None, "messages": None }
|
||||||
newMessageTemplate = { "title": None, "message": None, "progress": None }
|
newMessageTemplate = { "title": None, "message": None, "progress": None }
|
||||||
# Messages: { Title, Message, Progress }
|
# Messages: { Title, Message, Progress }
|
||||||
# Title, Message, and Progress are all technically optional. It's up to the frontend to make heads or tails of what's happening.
|
# Title, Message, and Progress are all technically optional. It's up to the frontend to make heads or tails of what's happening.
|
||||||
|
@ -169,6 +169,7 @@ def addCyberware():
|
||||||
tempNewCyberware['name'] = tempName
|
tempNewCyberware['name'] = tempName
|
||||||
tempNewCyberware['hotpluggable'] = tempHotpluggable
|
tempNewCyberware['hotpluggable'] = tempHotpluggable
|
||||||
|
|
||||||
|
|
||||||
cyberware.append(tempNewCyberware)
|
cyberware.append(tempNewCyberware)
|
||||||
except:
|
except:
|
||||||
return 'Incorrect usage.\nUsage: { name: STRING, hotpluggable: BOOL, canSet: ARRAY }\n', 400
|
return 'Incorrect usage.\nUsage: { name: STRING, hotpluggable: BOOL, canSet: ARRAY }\n', 400
|
||||||
|
@ -226,8 +227,35 @@ def getCyberwareMessages():
|
||||||
if c['messages'] != None:
|
if c['messages'] != None:
|
||||||
returnArr.append({ 'name': c['name'], 'messages': c['messages'] })
|
returnArr.append({ 'name': c['name'], 'messages': c['messages'] })
|
||||||
resetMessages()
|
resetMessages()
|
||||||
|
print(returnArr)
|
||||||
return jsonify(returnArr), 200
|
return jsonify(returnArr), 200
|
||||||
|
|
||||||
|
# Arguments { uuid: STRING, message:{ title: STRING, message: STRING, progress: INT } }
|
||||||
|
@app.route('/api/cyberware/messages', methods=['POST'])
|
||||||
|
def setCyberwareMessages():
|
||||||
|
global cyberware
|
||||||
|
json = request.get_json()
|
||||||
|
|
||||||
|
try:
|
||||||
|
desiredId = json['uuid']
|
||||||
|
message = json['message']
|
||||||
|
|
||||||
|
# Test message validity
|
||||||
|
testTitle = message["title"]
|
||||||
|
testMessage = message["message"]
|
||||||
|
testProgress = message["progress"]
|
||||||
|
|
||||||
|
requestedCyberware = getCyberwareHelper(desiredId)
|
||||||
|
|
||||||
|
if (requestedCyberware != None):
|
||||||
|
if (requestedCyberware["messages"] == None):
|
||||||
|
requestedCyberware["messages"] = []
|
||||||
|
requestedCyberware["messages"].append(message)
|
||||||
|
return '', 204
|
||||||
|
except:
|
||||||
|
return "Incorrect usage.\nUsage: { uuid: STRING, message:{ title: STRING, message: STRING, progress: INT } }\n", 400
|
||||||
|
return "UUID Invalid\n", 400
|
||||||
|
|
||||||
@app.route('/api/cyberware/get', methods=['POST'])
|
@app.route('/api/cyberware/get', methods=['POST'])
|
||||||
def getCyberwareSpecific():
|
def getCyberwareSpecific():
|
||||||
json = request.get_json()
|
json = request.get_json()
|
||||||
|
@ -243,7 +271,7 @@ def getCyberwareSpecific():
|
||||||
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
return 'Incorrect usage.\nUsage: { uuid: STRING }\n', 400
|
||||||
return 'UUID Invalid\n', 400
|
return 'UUID Invalid\n', 400
|
||||||
|
|
||||||
# Arguments { uuid: INT }
|
# Arguments { uuid: STRING }
|
||||||
@app.route('/api/cyberware/battery')
|
@app.route('/api/cyberware/battery')
|
||||||
def getCyberwareBattery():
|
def getCyberwareBattery():
|
||||||
json = request.get_json()
|
json = request.get_json()
|
||||||
|
@ -262,6 +290,7 @@ def getCyberwareBattery():
|
||||||
# Arguments { uuid: STRING, battery: INT }
|
# Arguments { uuid: STRING, battery: INT }
|
||||||
@app.route('/api/cyberware/battery', methods=['POST'])
|
@app.route('/api/cyberware/battery', methods=['POST'])
|
||||||
def setCyberwareBattery():
|
def setCyberwareBattery():
|
||||||
|
global cyberware
|
||||||
json = request.get_json()
|
json = request.get_json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -284,6 +313,7 @@ def resetAllCyberwareMalfunction():
|
||||||
# Arguments { uuid: STRING }
|
# Arguments { uuid: STRING }
|
||||||
@app.route('/api/cyberware/reset_malfunction', methods=['POST'])
|
@app.route('/api/cyberware/reset_malfunction', methods=['POST'])
|
||||||
def resetCyberwareMalfunction():
|
def resetCyberwareMalfunction():
|
||||||
|
global cyberware
|
||||||
json = request.get_json()
|
json = request.get_json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -299,22 +329,29 @@ def resetCyberwareMalfunction():
|
||||||
return 'UUID Invalid\n', 400
|
return 'UUID Invalid\n', 400
|
||||||
|
|
||||||
def resetMalfunctions():
|
def resetMalfunctions():
|
||||||
|
global cyberware
|
||||||
for c in cyberware:
|
for c in cyberware:
|
||||||
c['lastMalfunction'] = None
|
c['lastMalfunction'] = None
|
||||||
|
|
||||||
def resetMessages():
|
def resetMessages():
|
||||||
|
global cyberware
|
||||||
for c in cyberware:
|
for c in cyberware:
|
||||||
newMessageList = []
|
if c['messages'] != None:
|
||||||
for m in c['messages']:
|
newMessageList = []
|
||||||
if(m['progress'] == None): # Unless we're FULLY resetting messages, we want to keep messages with a progress bar attached.
|
for m in c['messages']:
|
||||||
newMessageList.append(m)
|
if(m['progress'] != None): # Unless we're FULLY resetting messages, we want to keep messages with a progress bar attached.
|
||||||
c['messages'] = newMessageList
|
newMessageList.append(m)
|
||||||
|
if newMessageList == []:
|
||||||
|
c['messages'] = None
|
||||||
|
else:
|
||||||
|
c['messages'] = newMessageList
|
||||||
|
|
||||||
def resetMessagesFull():
|
def resetMessagesFull():
|
||||||
|
global cyberware
|
||||||
for c in cyberware:
|
for c in cyberware:
|
||||||
c['messages'] = None
|
c['messages'] = None
|
||||||
|
|
||||||
def getCyberwareHelper(uuid):
|
def getCyberwareHelper(desiredId):
|
||||||
i = 0
|
i = 0
|
||||||
for c in cyberware:
|
for c in cyberware:
|
||||||
if c['uuid'] == desiredId:
|
if c['uuid'] == desiredId:
|
||||||
|
|
|
@ -218,16 +218,32 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// TODO: Make baseUrl be set by Flask
|
// TODO: Make baseUrl be set by Flask
|
||||||
var baseUrl = "http://localhost:5000";
|
var baseUrl = "http://localhost:5000";
|
||||||
var vitalsUrl = baseUrl + "/api/vitals";
|
var vitalsUrl = baseUrl + "/api/vitals";
|
||||||
var environmentUrl = baseUrl + "/api/environment";
|
var environmentUrl = baseUrl + "/api/environment";
|
||||||
|
var malfunctionUrl = baseUrl + "/api/cyberware/malfunctions";
|
||||||
|
var messageUrl = baseUrl + "/api/cyberware/messages";
|
||||||
|
|
||||||
// Malfunction Messages (human-friendly)
|
// Malfunction Messages (human-friendly)
|
||||||
malfunctionMessage = [ "API Malfunction" ]
|
malfunctionOrigin = [ "API Malfunction" ];
|
||||||
|
malfunctionMessage = [ "API Malfunction" ];
|
||||||
|
|
||||||
apiMalfunctionI = 0
|
// O - Origin
|
||||||
|
// I - Index
|
||||||
|
apiMalfunctionOI = 0;
|
||||||
|
apiMalfunctionI = 0;
|
||||||
|
|
||||||
function displayMalfunction(malfunction) {
|
function displayMalfunction(malfunctionOrigin, malfunctionMessage) {
|
||||||
console.log(malfunction);
|
console.log("MALFUNCTION [ " + malfunctionOrigin + "] " + malfunctionMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayMessage(title, message, progress) {
|
||||||
|
console.log("Message [" + title + "] " + message + " | " + progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayMessageList(name, messages) {
|
||||||
|
for(var message in messages) {
|
||||||
|
displayMessage(messages[0]["title"], messages[0]["message"], messages[0]["progress"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setVitals(vitalsData) {
|
function setVitals(vitalsData) {
|
||||||
|
@ -265,8 +281,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function setEnvironment(environmentData) {
|
function setEnvironment(environmentData) {
|
||||||
temperature = environmentData["0"]["temperature"];
|
temperature = environmentData[0]["temperature"];
|
||||||
humidity = environmentData["0"]["humidity"];
|
humidity = environmentData[0]["humidity"];
|
||||||
|
|
||||||
setEnvironmentTemperature(temperature);
|
setEnvironmentTemperature(temperature);
|
||||||
setEnvironmentHumidity(humidity);
|
setEnvironmentHumidity(humidity);
|
||||||
|
@ -284,12 +300,26 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Malfunction handling
|
||||||
|
function handleMalfunctions(malfunctions) {
|
||||||
|
for (var cyberware in malfunctions) {
|
||||||
|
displayMalfunction(messages[cyberware]["name"], messages[cyberware]["lastMalfunction"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message handling
|
||||||
|
function handleMessages(messages) {
|
||||||
|
for (var cyberware in messages) {
|
||||||
|
displayMessageList(messages[cyberware]["name"], messages[cyberware]["messages"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function updateAll() {
|
function updateAll() {
|
||||||
$.get(vitalsUrl, (data, status) => {
|
$.get(vitalsUrl, (data, status) => {
|
||||||
if(status == "success") {
|
if(status == "success") {
|
||||||
setVitals(data);
|
setVitals(data);
|
||||||
} else {
|
} else {
|
||||||
displayMalfunction(malfunctionMessage[apiMalfunctionI] + ": " + status);
|
displayMalfunction(malfunctionOrigin[apiMalfunctionOI], malfunctionMessage[apiMalfunctionI] + ": " + status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -297,7 +327,23 @@
|
||||||
if(status == "success") {
|
if(status == "success") {
|
||||||
setEnvironment(data);
|
setEnvironment(data);
|
||||||
} else {
|
} else {
|
||||||
displayMalfunction(malfunctionMessage[apiMalfunctionI] + ": " + status);
|
displayMalfunction(malfunctionOrigin[apiMalfunctionOI], malfunctionMessage[apiMalfunctionI] + ": " + status);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$.get(malfunctionUrl, (data, status) => {
|
||||||
|
if(status == "success") {
|
||||||
|
handleMalfunctions(data)
|
||||||
|
} else {
|
||||||
|
displayMalfunction(malfunctionOrigin[apiMalfunctionOI], malfunctionMessage[apiMalfunctionI] + ": " + status);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$.get(messageUrl, (data, status) => {
|
||||||
|
if(status == "success") {
|
||||||
|
handleMessages(data)
|
||||||
|
} else {
|
||||||
|
displayMalfunction(malfunctionOrigin[apiMalfunctionOI], malfunctionMessage[apiMalfunctionI] + ": " + status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//stopInterval(t)
|
//stopInterval(t)
|
||||||
|
|
Loading…
Reference in a new issue