pagina logger interattiva e contestuale
This commit is contained in:
+27
-11
@@ -151,23 +151,39 @@ def api_channels_current():
|
||||
# restituisce in formato json i dati letti da redis
|
||||
return jsonify(result)
|
||||
|
||||
# elenco file nella directory
|
||||
@flaskApp.route("/api/v1/folders/list", methods=['GET'])
|
||||
def api_get_folders():
|
||||
folderList = os.listdir(dataDir)
|
||||
lista = []
|
||||
idx=0
|
||||
# for item in sorted(data):
|
||||
for item in folderList:
|
||||
current = {"Cartelle": item}
|
||||
lista.append(current)
|
||||
idx=idx+1
|
||||
return jsonify(folderTable = lista)
|
||||
|
||||
# elenco file nella directory
|
||||
@flaskApp.route("/api/v1/files/list", methods=['GET'])
|
||||
def api_get_files():
|
||||
currentFolder = getRedisVal('SETTINGS:FOLDER:CURRENT')
|
||||
workingDirectory = (dataDir+currentFolder)
|
||||
fileList = os.listdir(workingDirectory)
|
||||
lista = []
|
||||
idx=0
|
||||
if workingDirectory == dataDir:
|
||||
return "OK"
|
||||
else:
|
||||
fileList = os.listdir(workingDirectory)
|
||||
lista = []
|
||||
idx=0
|
||||
# for item in sorted(data):
|
||||
for item in fileList:
|
||||
t_obj = time.strptime(time.ctime(os.path.getctime(workingDirectory+"/"+item)))
|
||||
# Transforming the time object to a timestamp
|
||||
T_stamp = time.strftime("%Y-%m-%d %H:%M:%S", t_obj)
|
||||
current = {"name": item,"size": os.path.getsize(workingDirectory+"/"+item), "date":T_stamp}
|
||||
lista.append(current)
|
||||
idx=idx+1
|
||||
return jsonify(fileTable = lista)
|
||||
for item in fileList:
|
||||
t_obj = time.strptime(time.ctime(os.path.getctime(workingDirectory+"/"+item)))
|
||||
# Transforming the time object to a timestamp
|
||||
T_stamp = time.strftime("%Y-%m-%d %H:%M:%S", t_obj)
|
||||
current = {"Nome file": item, "Size (bytes)": os.path.getsize(workingDirectory+"/"+item), "Data modifica":T_stamp}
|
||||
lista.append(current)
|
||||
idx=idx+1
|
||||
return jsonify(fileTable = lista)
|
||||
|
||||
# Route di comando x LOG: start e stop
|
||||
@flaskApp.route("/api/v1/log/start", methods=['PUT'])
|
||||
|
||||
@@ -7,22 +7,12 @@
|
||||
var intTime=200;
|
||||
|
||||
// fix visualizzazioni
|
||||
fixDisplay();
|
||||
fixFileTable();
|
||||
fixFolderTable();
|
||||
fixFileTable();
|
||||
dataRefresh();
|
||||
|
||||
// avvio timer
|
||||
var timeout = setTimeout(dataRefresh, intTime);
|
||||
var fileTable = [
|
||||
{
|
||||
"name": "-",
|
||||
"size": "0",
|
||||
"date": "2021/04/01 12:34:56"
|
||||
}
|
||||
]
|
||||
|
||||
function fixDisplay(){
|
||||
$("#divNewFile").toggle();
|
||||
};
|
||||
|
||||
function dataRefresh() {
|
||||
// scarico i dati aggioranti
|
||||
@@ -46,6 +36,22 @@
|
||||
$("#ServerTime").html(result.timeSrv);
|
||||
$("#LastSessionName").html(result.LastSessionName);
|
||||
$("#CurrentFolder").html(result.CurrentWorkFolder);
|
||||
if(result.CurrentWorkFolder == "")
|
||||
{
|
||||
$("#Div6").hide();
|
||||
$("#Div8").hide();
|
||||
$("#Div10").hide();
|
||||
$("#Div12").hide();
|
||||
$("#Div9").show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#Div6").show();
|
||||
$("#Div8").show();
|
||||
$("#Div10").show();
|
||||
$("#Div12").show();
|
||||
$("#Div9").hide();
|
||||
}
|
||||
}});
|
||||
|
||||
timeout = setTimeout(dataRefresh, intTime);
|
||||
@@ -100,6 +106,7 @@
|
||||
$("#btnStop").show();
|
||||
// fix table
|
||||
fixFileTable();
|
||||
fixFolderTable();
|
||||
dataRefresh();
|
||||
};
|
||||
|
||||
@@ -114,6 +121,7 @@
|
||||
$("#btnStop").hide();
|
||||
// fix table
|
||||
fixFileTable();
|
||||
fixFolderTable();
|
||||
dataRefresh();
|
||||
};
|
||||
|
||||
@@ -125,6 +133,7 @@
|
||||
})
|
||||
// fix table
|
||||
fixFileTable();
|
||||
fixFolderTable();
|
||||
dataRefresh();
|
||||
};
|
||||
|
||||
@@ -137,6 +146,7 @@
|
||||
})
|
||||
// fix table
|
||||
fixFileTable();
|
||||
fixFolderTable();
|
||||
dataRefresh();
|
||||
};
|
||||
|
||||
@@ -149,17 +159,61 @@
|
||||
,url: "/api/v1/data/delete"
|
||||
,data: ""
|
||||
})
|
||||
fixDisplay();
|
||||
fixFolderTable();
|
||||
fixFileTable();
|
||||
dataRefresh();
|
||||
}
|
||||
else{
|
||||
fixDisplay();
|
||||
fixFolderTable();
|
||||
fixFileTable();
|
||||
dataRefresh();
|
||||
}
|
||||
};
|
||||
|
||||
function fixFolderTable(){
|
||||
// scarico i dati aggioranti
|
||||
$.ajax({url: "/api/v1/folders/list", success: function(result){
|
||||
folderTable = result.folderTable;
|
||||
// fix file
|
||||
UpdateFolderTable(folderTable);
|
||||
}});
|
||||
}
|
||||
|
||||
function UpdateFolderTable(folderTable) {
|
||||
// EXTRACT VALUE FOR HTML HEADER.
|
||||
var col = [];
|
||||
for (var i = 0; i < folderTable.length; i++) {
|
||||
for (var key in folderTable[i]) {
|
||||
if (col.indexOf(key) === -1) {
|
||||
col.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
// CREATE DYNAMIC TABLE.
|
||||
var tableF = document.createElement("table");
|
||||
// CREATE HTML TABLE HEADER ROW USING THE EXTRACTED HEADERS ABOVE.
|
||||
// TABLE ROW.
|
||||
var tr = tableF.insertRow(-1);
|
||||
// TABLE HEADER.
|
||||
for (var i = 0; i < col.length; i++) {
|
||||
var th = document.createElement("th");
|
||||
th.innerHTML = col[i];
|
||||
tr.appendChild(th);
|
||||
}
|
||||
// ADD JSON DATA TO THE TABLE AS ROWS.
|
||||
for (var i = 0; i < folderTable.length; i++) {
|
||||
tr = tableF.insertRow(-1);
|
||||
for (var j = 0; j < col.length; j++) {
|
||||
var tabCell = tr.insertCell(-1);
|
||||
tabCell.innerHTML = folderTable[i][col[j]];
|
||||
}
|
||||
}
|
||||
// FINALLY ADD THE NEWLY CREATED TABLE WITH JSON DATA TO A CONTAINER.
|
||||
var divContainer = document.getElementById("showFolders");
|
||||
divContainer.innerHTML = "";
|
||||
divContainer.appendChild(tableF);
|
||||
}
|
||||
|
||||
function fixFileTable(){
|
||||
// scarico i dati aggioranti
|
||||
$.ajax({url: "/api/v1/files/list", success: function(result){
|
||||
@@ -168,7 +222,7 @@
|
||||
UpdateFileTable(fileTable);
|
||||
}});
|
||||
}
|
||||
|
||||
|
||||
function UpdateFileTable(fileTable) {
|
||||
// EXTRACT VALUE FOR HTML HEADER.
|
||||
var col = [];
|
||||
@@ -181,7 +235,6 @@
|
||||
}
|
||||
// CREATE DYNAMIC TABLE.
|
||||
var table = document.createElement("table");
|
||||
|
||||
// CREATE HTML TABLE HEADER ROW USING THE EXTRACTED HEADERS ABOVE.
|
||||
// TABLE ROW.
|
||||
var tr = table.insertRow(-1);
|
||||
@@ -239,7 +292,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-secondary text-center py-2 m-2 row">
|
||||
<div id="Div6" class="table-secondary text-center py-2 m-2 row">
|
||||
<!-- <div class="text-center my-2 row"> -->
|
||||
<div class="col-6">
|
||||
<button id="btnStart" type="button" class="btn btn-success btn-block" onclick="startLog()">Start Log</button>
|
||||
@@ -250,31 +303,38 @@
|
||||
</div>
|
||||
<div class="card my-2">
|
||||
<div class="card-header">
|
||||
<div class="row">
|
||||
<div class="col-6"><strong>Cartella attuale: </strong> <h5>/data/<span id="CurrentFolder"></span></h5></div>
|
||||
<div class="row" id="Div8"> <!--Div8 ovvero cartella attuale e sessione attuale-->
|
||||
<div class="col-6"><strong>Cartella attuale: </strong> <h5>/<span id="CurrentFolder"></span></h5></div>
|
||||
<div class="col-6"><strong>Sessione attuale: </strong> <h5>/<span id="LastSessionName"></span></h5></div>
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="col-4">
|
||||
<button type="button" class="btn btn-info btn-block" onclick="goBack()">Torna a /data/</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button type="button" class="btn btn-primary btn-block" onclick="exportData()">Esporta Cartella</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button type="button" class="btn btn-danger btn-block" onclick="deleteData()">Cancella Cartella</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="Div9">
|
||||
<p id="showFolders"></p>
|
||||
<form method="POST" action="/api/v1/setup/workingtree">
|
||||
<div class="input-group my-2">
|
||||
<span class="input-group-text col-4">Seleziona cartella: </span>
|
||||
<input type="text" class="form-control col-6" id="NewFolder" name="NewFolder"></input>
|
||||
<span class="input-group-text col-2">Cartella: </span>
|
||||
<input type="text" class="form-control col-8" id="NewFolder" name="NewFolder"></input>
|
||||
<input type="submit" value="INVIO" class="btn btn-success col-2"></input>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div id="Div10"> <!--Div10 ovvero 3 pulsanti logger-->
|
||||
<div class="row mt-2">
|
||||
<div class="col-4">
|
||||
<button type="button" class="btn btn-info btn-block" onclick="goBack()">Torna a /data/</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button type="button" class="btn btn-primary btn-block" onclick="exportData()">Esporta Cartella</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button type="button" class="btn btn-danger btn-block" onclick="deleteData()">Cancella Cartella</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="text-center" id="showData"></p>
|
||||
<div id="Div12"> <!--Div12 ovvero elenco files-->
|
||||
<p class="text-center" id="showData"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user