feat(web): add TFM settings page
Only setting TFM database name by now
This commit is contained in:
parent
9c07702409
commit
243621f3b2
@ -121,6 +121,10 @@ form {
|
||||
color: #bbb !important;
|
||||
}
|
||||
|
||||
td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.button-flex {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
var db_name = localStorage["tfm_db_name"];
|
||||
if (db_name == null) {
|
||||
location.href = "/tfm/settings";
|
||||
}
|
||||
|
||||
$(document).on("click", "#btn-save", function (e) {
|
||||
e.preventDefault();
|
||||
let resp = tdb_query("$TFM", 4, "");
|
||||
let resp = tdb_query(db_name, 4, "");
|
||||
if (resp.status) {
|
||||
alert("Successfully saved!");
|
||||
} else {
|
||||
@ -13,7 +18,7 @@ $(document).on("click", "#btn-discard", function (e) {
|
||||
if (!confirm("All unsaved changes will be lost permanently. Are you sure?")) {
|
||||
return;
|
||||
}
|
||||
let resp = tdb_query("$TFM", 2, "");
|
||||
let resp = tdb_query(db_name, 2, "");
|
||||
if (resp.status) {
|
||||
alert("Successfully reloaded database!");
|
||||
} else {
|
||||
|
||||
@ -20,7 +20,7 @@ $(window).on("load", function () {
|
||||
|
||||
$(document).on("submit", "#menu-add form", function (e) {
|
||||
e.preventDefault();
|
||||
let resp = tdb_query("$TFM", 18, $("#new-name").val());
|
||||
let resp = tdb_query(db_name, 18, $("#new-name").val());
|
||||
if (!resp.status) {
|
||||
alert("Something went wrong!");
|
||||
return;
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
var db_name = localStorage["tfm_db_name"];
|
||||
if (db_name == null) {
|
||||
location.href = "/tfm/settings";
|
||||
}
|
||||
var sasahyou = null, sappyou = null, shoppyou = null;
|
||||
if (localStorage["sasahyou"] != null) {
|
||||
sasahyou = JSON.parse(localStorage["sasahyou"]);
|
||||
@ -23,13 +27,13 @@ var current_sasa_index = -1;
|
||||
var menu_count = 0;
|
||||
|
||||
function sasahyou_load() {
|
||||
let db_info = tdb_query("$TFM", 0, "");
|
||||
let db_info = tdb_query(db_name, 0, "");
|
||||
if (db_info == null || !db_info.status) {
|
||||
alert("Failed to fetch TFM database");
|
||||
throw new Error("Failed to fetch TFM database");
|
||||
}
|
||||
if (sasahyou == null || sasahyou_mts !== db_info.data[0].sasahyou.mts) {
|
||||
let resp = tdb_query("$TFM", 16, "");
|
||||
let resp = tdb_query(db_name, 16, "");
|
||||
if (resp == null || !resp.status) {
|
||||
alert("Failed to get sasahyou");
|
||||
throw new Error("Failed to get sasahyou");
|
||||
@ -42,13 +46,13 @@ function sasahyou_load() {
|
||||
}
|
||||
|
||||
function sappyou_load() {
|
||||
let db_info = tdb_query("$TFM", 0, "");
|
||||
let db_info = tdb_query(db_name, 0, "");
|
||||
if (db_info == null || !db_info.status) {
|
||||
alert("Failed to fetch TFM database");
|
||||
throw new Error("Failed to fetch TFM database");
|
||||
}
|
||||
if (sappyou == null || sappyou_mts !== db_info.data[0].sappyou.mts) {
|
||||
let resp = tdb_query("$TFM", 32, "");
|
||||
let resp = tdb_query(db_name, 32, "");
|
||||
if (resp == null || !resp.status) {
|
||||
alert("Failed to get sappyou");
|
||||
throw new Error("Failed to get sappyou");
|
||||
@ -61,13 +65,13 @@ function sappyou_load() {
|
||||
}
|
||||
|
||||
function shoppyou_load() {
|
||||
let db_info = tdb_query("$TFM", 0, "");
|
||||
let db_info = tdb_query(db_name, 0, "");
|
||||
if (db_info == null || !db_info.status) {
|
||||
alert("Failed to fetch TFM database");
|
||||
throw new Error("Failed to fetch TFM database");
|
||||
}
|
||||
if (shoppyou == null || shoppyou_mts !== db_info.data[0].shoppyou.mts) {
|
||||
let resp = tdb_query("$TFM", 8, "");
|
||||
let resp = tdb_query(db_name, 8, "");
|
||||
if (resp == null || !resp.status) {
|
||||
alert("Failed to get shoppyou");
|
||||
throw new Error("Failed to get shoppyou");
|
||||
@ -90,7 +94,7 @@ function menu_view_file_open() {
|
||||
$("#file-name").val(decodeURI(current_sasa.path));
|
||||
$("#menu-file-view .list-item").css("display", "");
|
||||
$("#btn-full").attr("href", "/files/" + current_sasa.path);
|
||||
let resp = tdb_query("$TFM", 24, '' + current_sasa.id);
|
||||
let resp = tdb_query(db_name, 24, '' + current_sasa.id);
|
||||
if (!resp.status) {
|
||||
alert("Something went wrong!");
|
||||
return;
|
||||
@ -122,7 +126,7 @@ function menu_view_tag_open() {
|
||||
$("#menu-tag-view").css("display", "flex");
|
||||
$("#menu-tag-view .list-item").css("display", "");
|
||||
$("#tag-name").val(decodeURI(current_tanzaku.name));
|
||||
let resp = tdb_query("$TFM", 40, '' + current_tanzaku.id);
|
||||
let resp = tdb_query(db_name, 40, '' + current_tanzaku.id);
|
||||
if (!resp.status) {
|
||||
alert("Something went wrong!");
|
||||
return;
|
||||
@ -324,7 +328,7 @@ $(document).on("reset", "#menu-add form", function (e) {
|
||||
|
||||
$(document).on("submit", "#menu-file-view form", function (e) {
|
||||
e.preventDefault();
|
||||
let resp = tdb_query("$TFM", 24, '' + current_sasa.id);
|
||||
let resp = tdb_query(db_name, 24, '' + current_sasa.id);
|
||||
if (!resp.status) {
|
||||
alert("Something went wrong!");
|
||||
return;
|
||||
@ -332,7 +336,7 @@ $(document).on("submit", "#menu-file-view form", function (e) {
|
||||
resp.data.forEach(tanzaku => {
|
||||
let current = $(`.list-item[tid="${tanzaku.id}"]`);
|
||||
if (!current.hasClass("selected") &&
|
||||
!tdb_query("$TFM", 9, '' + current_sasa.id + ' ' + tanzaku.id).status) {
|
||||
!tdb_query(db_name, 9, '' + current_sasa.id + ' ' + tanzaku.id).status) {
|
||||
console.log("ERROR: failed to remove kazari: " + current_sasa.id + '-' + tanzaku.id);
|
||||
}
|
||||
});
|
||||
@ -341,7 +345,7 @@ $(document).on("submit", "#menu-file-view form", function (e) {
|
||||
if (resp.data.find(t => t.id === tid) != null) {
|
||||
return;
|
||||
}
|
||||
if (!tdb_query("$TFM", 10, '' + current_sasa.id + ' ' + tid)) {
|
||||
if (!tdb_query(db_name, 10, '' + current_sasa.id + ' ' + tid)) {
|
||||
console.log("ERROR: failed to add kazari: " + current_sasa.id + '-' + tid);
|
||||
}
|
||||
});
|
||||
@ -350,7 +354,7 @@ $(document).on("submit", "#menu-file-view form", function (e) {
|
||||
|
||||
$(document).on("submit", "#menu-tag-view form", function (e) {
|
||||
e.preventDefault();
|
||||
let resp = tdb_query("$TFM", 40, '' + current_tanzaku.id);
|
||||
let resp = tdb_query(db_name, 40, '' + current_tanzaku.id);
|
||||
if (!resp.status) {
|
||||
alert("Something went wrong!");
|
||||
return;
|
||||
@ -358,7 +362,7 @@ $(document).on("submit", "#menu-tag-view form", function (e) {
|
||||
resp.data.forEach(sasa => {
|
||||
let current = $(`.list-item[sid="${sasa.id}"]`);
|
||||
if (!current.hasClass("selected") &&
|
||||
!tdb_query("$TFM", 9, '' + sasa.id + ' ' + current_tanzaku.id).status) {
|
||||
!tdb_query(db_name, 9, '' + sasa.id + ' ' + current_tanzaku.id).status) {
|
||||
console.log("ERROR: failed to remove kazari: " + sasa.id + '-' + current_tanzaku.id);
|
||||
}
|
||||
});
|
||||
@ -367,7 +371,7 @@ $(document).on("submit", "#menu-tag-view form", function (e) {
|
||||
if (resp.data.find(s => s.id === sid) != null) {
|
||||
return;
|
||||
}
|
||||
if (!tdb_query("$TFM", 10, '' + sid + ' ' + current_tanzaku.id)) {
|
||||
if (!tdb_query(db_name, 10, '' + sid + ' ' + current_tanzaku.id)) {
|
||||
console.log("ERROR: failed to add kazari: " + sid + '-' + current_tanzaku.id);
|
||||
}
|
||||
});
|
||||
@ -379,7 +383,7 @@ $(document).on("click", "#btn-remove", function (e) {
|
||||
if (!confirm("This tag will be removed permanently. Are you sure?")) {
|
||||
return;
|
||||
}
|
||||
let resp = tdb_query("$TFM", 33, '' + current_tanzaku.id);
|
||||
let resp = tdb_query(db_name, 33, '' + current_tanzaku.id);
|
||||
if (!resp.status) {
|
||||
alert("Something went wrong!");
|
||||
return;
|
||||
|
||||
67
web/public/js/tfm-settings.js
Normal file
67
web/public/js/tfm-settings.js
Normal file
@ -0,0 +1,67 @@
|
||||
var db_name = localStorage["tfm_db_name"],
|
||||
sort_files = localStorage["sort_files"],
|
||||
sort_tags = localStorage["sort_tags"];
|
||||
if (sort_files == null) {
|
||||
sort_files = "id";
|
||||
}
|
||||
if (sort_tags == null) {
|
||||
sort_tags = "id";
|
||||
}
|
||||
|
||||
function settings_load() {
|
||||
if (db_name != null) {
|
||||
$("#db_name").val(db_name);
|
||||
}
|
||||
if (sort_files != null) {
|
||||
if (sort_files[0] === '-') {
|
||||
$("#files-reverse").prop("checked", true);
|
||||
sort_files = sort_files.slice(1);
|
||||
}
|
||||
$(`#files-by-${sort_files}`).prop("checked", true);
|
||||
}
|
||||
if (sort_tags != null) {
|
||||
if (sort_tags[0] === '-') {
|
||||
$("#tags-reverse").prop("checked", true);
|
||||
sort_tags = sort_tags.slice(1);
|
||||
}
|
||||
$(`#tags-by-${sort_tags}`).prop("checked", true);
|
||||
}
|
||||
}
|
||||
|
||||
$(window).on("load", function () {
|
||||
settings_load();
|
||||
});
|
||||
|
||||
$(document).on("reset", "#settings", function (e) {
|
||||
e.preventDefault();
|
||||
settings_load();
|
||||
});
|
||||
|
||||
$(document).on("submit", "#settings", function (e) {
|
||||
e.preventDefault();
|
||||
let db_name_input = $("#db_name");
|
||||
let db_name_val = db_name_input.val();
|
||||
if (db_name_val !== db_name) {
|
||||
let resp = tdb_query("", 0, "");
|
||||
if (!resp.status) {
|
||||
alert("Failed to fetch databases");
|
||||
return;
|
||||
}
|
||||
let found = false;
|
||||
resp.data.every(db => {
|
||||
if (db.name === db_name_val) {
|
||||
db_name = db_name_val;
|
||||
localStorage["tfm_db_name"] = db_name;
|
||||
found = true;
|
||||
db_name_input.removeClass("is-invalid");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (!found) {
|
||||
db_name_input.addClass("is-invalid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
alert("Successfully updated settings!");
|
||||
});
|
||||
@ -29,7 +29,7 @@ $(document).on("input", "#text-filter-all", function (e) {
|
||||
|
||||
$(document).on("submit", "#menu-add form", function (e) {
|
||||
e.preventDefault();
|
||||
let resp = tdb_query("$TFM", 34, $("#new-name").val() + '\n' + $("#new-description").val());
|
||||
let resp = tdb_query(db_name, 34, $("#new-name").val() + '\n' + $("#new-description").val());
|
||||
if (!resp.status) {
|
||||
alert("Something went wrong!");
|
||||
return;
|
||||
|
||||
@ -36,8 +36,9 @@
|
||||
<a href="/" class="btn btn-outline-secondary">Home</a>
|
||||
</div>
|
||||
<div class="contents-wrapper">
|
||||
<button class="btn btn-success" id="btn-save">Save changes</button>
|
||||
<button class="btn btn-danger" id="btn-discard">Discard changes</button>
|
||||
<button class="btn btn-success" id="btn-save">Save database</button>
|
||||
<a href="/tfm/settings" class="btn btn-secondary">Settings</a>
|
||||
<button class="btn btn-danger" id="btn-discard">Reload database</button>
|
||||
</div>
|
||||
</main>
|
||||
<script src="/js/tfm-database.js"></script>
|
||||
|
||||
108
web/public/tfm/settings.html
Normal file
108
web/public/tfm/settings.html
Normal file
@ -0,0 +1,108 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Settings | Tanabata File Manager</title>
|
||||
<link rel="apple-touch-icon" sizes="57x57" href="/images/apple-icon-57x57.png">
|
||||
<link rel="apple-touch-icon" sizes="60x60" href="/images/apple-icon-60x60.png">
|
||||
<link rel="apple-touch-icon" sizes="72x72" href="/images/apple-icon-72x72.png">
|
||||
<link rel="apple-touch-icon" sizes="76x76" href="/images/apple-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" sizes="114x114" href="/images/apple-icon-114x114.png">
|
||||
<link rel="apple-touch-icon" sizes="120x120" href="/images/apple-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" sizes="144x144" href="/images/apple-icon-144x144.png">
|
||||
<link rel="apple-touch-icon" sizes="152x152" href="/images/apple-icon-152x152.png">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-icon-180x180.png">
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="/images/android-icon-192x192.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="96x96" href="/images/favicon-96x96.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
|
||||
<link rel="manifest" href="/tanabata.webmanifest">
|
||||
<meta name="msapplication-TileColor" content="#615880">
|
||||
<meta name="msapplication-TileImage" content="/images/ms-icon-144x144.png">
|
||||
<meta name="theme-color" content="#615880">
|
||||
<link rel="stylesheet" href="/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="/css/general.css">
|
||||
<script src="/js/jquery-3.6.0.min.js"></script>
|
||||
<script src="/js/tdbms.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>TFM: Settings</h1>
|
||||
<main>
|
||||
<div class="contents-wrapper">
|
||||
<form id="settings">
|
||||
<div class="form-group">
|
||||
<label for="db_name">Database name</label>
|
||||
<input type="text" name="db_name" class="form-control" id="db_name" placeholder="Enter TFM database name">
|
||||
<div class="invalid-feedback">Database not found</div>
|
||||
</div>
|
||||
<table class="form-group">
|
||||
<tr>
|
||||
<td>
|
||||
<fieldset class="form-group">
|
||||
<legend>Files sorting</legend>
|
||||
<div class="form-check">
|
||||
<input type="radio" name="sort-files" id="files-by-id">
|
||||
<label for="files-by-id">By ID</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" name="sort-files" id="files-by-ctime">
|
||||
<label for="files-by-ctime">By ctime</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" name="sort-files" id="files-by-name">
|
||||
<label for="files-by-name">By name</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
</td>
|
||||
<td>
|
||||
<fieldset class="form-group">
|
||||
<legend>Tags sorting</legend>
|
||||
<div class="form-check">
|
||||
<input type="radio" name="sort-tags" id="tags-by-id">
|
||||
<label for="tags-by-id">By ID</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" name="sort-tags" id="tags-by-ctime">
|
||||
<label for="tags-by-ctime">By ctime</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" name="sort-tags" id="tags-by-mtime">
|
||||
<label for="tags-by-mtime">By mtime</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" name="sort-tags" id="tags-by-name">
|
||||
<label for="tags-by-name">By name</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" name="sort-tags" id="tags-by-nfiles">
|
||||
<label for="tags-by-nfiles">By kazari count</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="form-group form-check">
|
||||
<input type="checkbox" name="sort-files-reverse" class="form-check-input" id="files-reverse">
|
||||
<label class="form-check-label" for="files-reverse">Reverse sorting</label>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="form-group form-check">
|
||||
<input type="checkbox" name="sort-tags-reverse" class="form-check-input" id="tags-reverse">
|
||||
<label class="form-check-label" for="tags-reverse">Reverse sorting</label>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="button-flex">
|
||||
<button type="submit" class="btn btn-primary">Apply</button>
|
||||
<a href="/tfm" class="btn btn-outline-secondary">TFM home</a>
|
||||
<button type="reset" class="btn btn-danger">Reset</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
<script src="/js/tfm-settings.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -159,7 +159,7 @@ func HandlerTDBMS(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
log.Println("Got TDBMS response")
|
||||
if request.TRDB == "$TFM" && (request.TRC == 0b10000 || request.TRC == 0b101000) {
|
||||
if strings.HasPrefix(strings.ToLower(request.TRDB), "tfm") && (request.TRC == 0b10000 || request.TRC == 0b101000) {
|
||||
var json_response JSON
|
||||
err = json.Unmarshal(response, &json_response)
|
||||
if err != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user