commit 21/01/2026
This commit is contained in:
15
html/assets/js/home.js
Normal file
15
html/assets/js/home.js
Normal file
@@ -0,0 +1,15 @@
|
||||
$(document).ready(function() {
|
||||
// Your code here
|
||||
console.log("home.js is loaded and ready.");
|
||||
$('#logoutbtn').on('click', function() {
|
||||
// Clear session storage on logout
|
||||
fetch('/logout').then(() => {
|
||||
window.location.href = '/login.html';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$(window).on('beforeunload', function() {
|
||||
console.log("User is leaving home.html");
|
||||
// Your cleanup code here
|
||||
});
|
||||
15
html/assets/js/log.js
Normal file
15
html/assets/js/log.js
Normal file
@@ -0,0 +1,15 @@
|
||||
$(document).ready(function() {
|
||||
// Your code here
|
||||
console.log("log.js is loaded and ready.");
|
||||
$('#logoutbtn').on('click', function() {
|
||||
// Clear session storage on logout
|
||||
fetch('/logout').then(() => {
|
||||
window.location.href = '/login.html';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$(window).on('beforeunload', function() {
|
||||
console.log("User is leaving log.html");
|
||||
// Your cleanup code here
|
||||
});
|
||||
13
html/assets/js/login.js
Normal file
13
html/assets/js/login.js
Normal file
@@ -0,0 +1,13 @@
|
||||
$(document).ready(function() {
|
||||
// Your code here
|
||||
console.log("login.js is loaded and ready.");
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (params.get("error")) {
|
||||
alert("Login failed. Please try again.");
|
||||
}
|
||||
});
|
||||
|
||||
$(window).on('beforeunload', function() {
|
||||
console.log("User is leaving login.html");
|
||||
// Your cleanup code here
|
||||
});
|
||||
77
html/assets/js/script.js
Normal file
77
html/assets/js/script.js
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Checks if a string is valid (not null and not empty)
|
||||
* @param {string} str
|
||||
* @returns true if valid, false otherwise
|
||||
*/
|
||||
function ValidString(str) {
|
||||
if (str) {
|
||||
if (str.length > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a POST request to the specified URL with the given data.
|
||||
* @param {string} url Service endpoint URL
|
||||
* @param {object} data Data to be sent in the request body
|
||||
* @param {function} onSuccess callback for successful response
|
||||
* @param {function} onError callback for error response
|
||||
*/
|
||||
function Post(url, data, onSuccess, onError) {
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data)
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
let str = `POST request to ${url} failed. Status: ${response.statusText}`;
|
||||
throw new Error(str);
|
||||
}
|
||||
}).then(data => {
|
||||
if (onSuccess) {
|
||||
onSuccess(data);
|
||||
}
|
||||
}).catch(error => {
|
||||
if (ValidString(error.message)) {
|
||||
if (onError) {
|
||||
onError(error.message);
|
||||
} else {
|
||||
console.error(error.message);
|
||||
}
|
||||
} else console.log("An unknown error occurred during POST request.");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a GET request to the specified URL.
|
||||
* @param {string} url Service endpoint URL
|
||||
* @param {function} onSuccess callback for successful response
|
||||
* @param {function} onError callback for error response
|
||||
*/
|
||||
function Get(url, onSuccess, onError) {
|
||||
fetch(url).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
let str = `GET request to ${url} failed. Status: ${response.statusText}`;
|
||||
throw new Error(str);
|
||||
}
|
||||
}).then(data => {
|
||||
if (onSuccess) {
|
||||
onSuccess(data);
|
||||
}
|
||||
}).catch(error => {
|
||||
if (ValidString(error.message)) {
|
||||
if (onError) {
|
||||
onError(error.message);
|
||||
} else {
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
else console.log("An unknown error occurred during GET request.");
|
||||
});
|
||||
}
|
||||
168
html/assets/js/setting.js
Normal file
168
html/assets/js/setting.js
Normal file
@@ -0,0 +1,168 @@
|
||||
$(document).ready(function () {
|
||||
// Your code here
|
||||
console.log("setting.js is loaded and ready.");
|
||||
|
||||
loadSetting();
|
||||
|
||||
$('#logoutbtn').on('click', function () {
|
||||
// Clear session storage on logout
|
||||
fetch('/logout').then(() => {
|
||||
window.location.href = '/login.html';
|
||||
});
|
||||
});
|
||||
|
||||
$('#savefarm').on('click', function () {
|
||||
saveFarmParameter();
|
||||
});
|
||||
|
||||
$('#saveaas').on('click', function () {
|
||||
saveAASParameter();
|
||||
});
|
||||
});
|
||||
|
||||
$(window).on('beforeunload', function () {
|
||||
console.log("User is leaving setting.html");
|
||||
// Your cleanup code here
|
||||
});
|
||||
|
||||
function loadSetting() {
|
||||
Get("getSetting", function (data) {
|
||||
if (data) {
|
||||
if (data.farm) {
|
||||
if (data.aas1) {
|
||||
if (data.aas2) {
|
||||
if (data.aas3) {
|
||||
// all good
|
||||
$('#brokerurl').val(data.farm.url);
|
||||
$('#brokerusername').val(data.farm.username);
|
||||
$('#brokerpassword').val(data.farm.password);
|
||||
$('#brokerqueue').val(data.farm.queue);
|
||||
$('#aas1url').val(data.aas1.url);
|
||||
$('#aas1username').val(data.aas1.username);
|
||||
$('#aas1password').val(data.aas1.password);
|
||||
$('#aas2url').val(data.aas2.url);
|
||||
$('#aas2username').val(data.aas2.username);
|
||||
$('#aas2password').val(data.aas2.password);
|
||||
$('#aas3url').val(data.aas3.url);
|
||||
$('#aas3username').val(data.aas3.username);
|
||||
$('#aas3password').val(data.aas3.password);
|
||||
} else console.log("No AAS 3 data received");
|
||||
} else console.log("No AAS 2 data received");
|
||||
} else console.log("No AAS 1 data received");
|
||||
} else console.log("No FARM data received");
|
||||
} else console.log("No data received");
|
||||
|
||||
}, function (error) {
|
||||
alert(error);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function saveFarmParameter() {
|
||||
let url = $('#brokerurl').val();
|
||||
let username = $('#brokerusername').val();
|
||||
let password = $('#brokerpassword').val();
|
||||
let queue = $('#brokerqueue').val();
|
||||
|
||||
if (ValidString(url) == false) {
|
||||
alert("FARM Broker URL is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(username) == false) {
|
||||
alert("FARM Broker Username is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(password) == false) {
|
||||
alert("FARM Broker Password is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(queue) == false) {
|
||||
alert("FARM Broker Queue is required.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Post("saveFARM", {
|
||||
farm: {
|
||||
url: url,
|
||||
username: username,
|
||||
password: password,
|
||||
queue: queue
|
||||
}
|
||||
|
||||
}, function (data) {
|
||||
alert(data.message);
|
||||
}, function (error) {
|
||||
alert(error);
|
||||
});
|
||||
|
||||
}
|
||||
function saveAASParameter() {
|
||||
let aas1URL = $('#aas1url').val();
|
||||
let aas1username = $('#aas1username').val();
|
||||
let aas1password = $('#aas1password').val();
|
||||
let aas2URL = $('#aas2url').val();
|
||||
let aas2username = $('#aas2username').val();
|
||||
let aas2password = $('#aas2password').val();
|
||||
let aas3URL = $('#aas3url').val();
|
||||
let aas3username = $('#aas3username').val();
|
||||
let aas3password = $('#aas3password').val();
|
||||
|
||||
if (ValidString(aas1URL) == false) {
|
||||
alert("AAS1 URL is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas1username) == false) {
|
||||
alert("AAS1 Username is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas1password) == false) {
|
||||
alert("AAS1 Password is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas2URL) == false) {
|
||||
alert("AAS2 URL is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas2username) == false) {
|
||||
alert("AAS2 Username is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas2password) == false) {
|
||||
alert("AAS2 Password is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas3URL) == false) {
|
||||
alert("AAS3 URL is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas3username) == false) {
|
||||
alert("AAS3 Username is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas3password) == false) {
|
||||
alert("AAS3 Password is required.");
|
||||
return;
|
||||
}
|
||||
Post("saveAAS", {
|
||||
aas1: {
|
||||
url: aas1URL,
|
||||
username: aas1username,
|
||||
password: aas1password
|
||||
},
|
||||
aas2: {
|
||||
url: aas2URL,
|
||||
username: aas2username,
|
||||
password: aas2password
|
||||
},
|
||||
aas3: {
|
||||
url: aas3URL,
|
||||
username: aas3username,
|
||||
password: aas3password
|
||||
}
|
||||
}, function (data) {
|
||||
alert(data.message);
|
||||
}, function (error) {
|
||||
alert(error)
|
||||
});
|
||||
}
|
||||
@@ -15,9 +15,9 @@
|
||||
<div class="collapse navbar-collapse" id="navcol-1">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item"><a class="nav-link active" href="#">Overview</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#">Setting</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#">Log</a></li>
|
||||
</ul><button class="btn btn-primary" type="button">Logout</button>
|
||||
<li class="nav-item"><a class="nav-link" href="setting.html">Setting</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="log.html">Log</a></li>
|
||||
</ul><button class="btn btn-primary" id="logoutbtn" type="button">Logout</button>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -30,6 +30,8 @@
|
||||
<div class="row"></div>
|
||||
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script src="assets/js/jquery-3.7.1.min.js"></script>
|
||||
<script src="assets/js/home.js"></script>
|
||||
<script src="assets/js/script.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -14,10 +14,10 @@
|
||||
<div class="container"><a class="navbar-brand d-flex align-items-center" href="#"><span class="bs-icon-sm bs-icon-rounded bs-icon-primary d-flex justify-content-center align-items-center me-2 bs-icon"><img class="img-fluid" width="80" height="80" src="assets/img/gtc%20icon%2080x80.png"></span><span>Farm To AAS</span></a><button data-bs-toggle="collapse" class="navbar-toggler" data-bs-target="#navcol-1"><span class="visually-hidden">Toggle navigation</span><span class="navbar-toggler-icon"></span></button>
|
||||
<div class="collapse navbar-collapse" id="navcol-1">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item"><a class="nav-link" href="#">Overview</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#">Setting</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="home.html">Overview</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="setting.html">Setting</a></li>
|
||||
<li class="nav-item"><a class="nav-link active" href="#">Log</a></li>
|
||||
</ul><button class="btn btn-primary" type="button">Logout</button>
|
||||
</ul><button class="btn btn-primary" id="logoutbtn" type="button">Logout</button>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -45,6 +45,8 @@
|
||||
</div>
|
||||
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script src="assets/js/jquery-3.7.1.min.js"></script>
|
||||
<script src="assets/js/log.js"></script>
|
||||
<script src="assets/js/script.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -28,7 +28,6 @@
|
||||
<div class="mb-3"><input class="form-control" type="text" name="username" placeholder="Username"></div>
|
||||
<div class="mb-3"><input class="form-control" type="password" name="password" placeholder="Password"></div>
|
||||
<div class="mb-3"><button class="btn btn-primary w-100 d-block" type="submit">Login</button></div>
|
||||
<p class="text-muted">Forgot your password?</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -38,6 +37,8 @@
|
||||
</section>
|
||||
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script src="assets/js/jquery-3.7.1.min.js"></script>
|
||||
<script src="assets/js/login.js"></script>
|
||||
<script src="assets/js/script.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -14,10 +14,10 @@
|
||||
<div class="container"><a class="navbar-brand d-flex align-items-center" href="#"><span class="bs-icon-sm bs-icon-rounded bs-icon-primary d-flex justify-content-center align-items-center me-2 bs-icon"><img class="img-fluid" width="80" height="80" src="assets/img/gtc%20icon%2080x80.png"></span><span>Farm To AAS</span></a><button data-bs-toggle="collapse" class="navbar-toggler" data-bs-target="#navcol-1"><span class="visually-hidden">Toggle navigation</span><span class="navbar-toggler-icon"></span></button>
|
||||
<div class="collapse navbar-collapse" id="navcol-1">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item"><a class="nav-link" href="#">Overview</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="home.html">Overview</a></li>
|
||||
<li class="nav-item"><a class="nav-link active" href="#">Setting</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#">Log</a></li>
|
||||
</ul><button class="btn btn-primary" type="button">Logout</button>
|
||||
<li class="nav-item"><a class="nav-link" href="log.html">Log</a></li>
|
||||
</ul><button class="btn btn-primary" id="logoutbtn" type="button">Logout</button>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -49,25 +49,27 @@
|
||||
<h4 class="card-title">AAS Setting</h4>
|
||||
<div class="col">
|
||||
<div class="row mb-1">
|
||||
<div class="col-6"><input class="w-100 h-100 ms-1 me-1" type="text" placeholder="AAS IP 1"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="text" placeholder="DB Username"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="password" placeholder="DB Password"></div>
|
||||
<div class="col-6"><input class="w-100 h-100 ms-1 me-1" type="text" id="aas1url" placeholder="AAS IP 1"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="text" id="aas1username" placeholder="DB Username"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="password" id="aas1password" placeholder="DB Password"></div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<div class="col-6"><input class="w-100 h-100 ms-1 me-1" type="text" placeholder="AAS IP 2"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="text" placeholder="DB Username"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="password" placeholder="DB Password"></div>
|
||||
<div class="col-6"><input class="w-100 h-100 ms-1 me-1" type="text" id="aas2url" placeholder="AAS IP 2"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="text" id="aas2username" placeholder="DB Username"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="password" id="aas2password" placeholder="DB Password"></div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<div class="col-6"><input class="w-100 h-100 ms-1 me-1" type="text" placeholder="AAS IP 3"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="text" placeholder="DB Username"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="password" placeholder="DB Password"></div>
|
||||
<div class="col-6"><input class="w-100 h-100 ms-1 me-1" type="text" id="aas3url" placeholder="AAS IP 3"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="text" id="aas3username" placeholder="DB Username"></div>
|
||||
<div class="col-3"><input class="w-100 h-100 ms-1 me-1" type="password" id="aas3password" placeholder="DB Password"></div>
|
||||
</div>
|
||||
</div><button class="btn btn-primary btn-lg mt-2" id="saveaas" type="button">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script src="assets/js/jquery-3.7.1.min.js"></script>
|
||||
<script src="assets/js/script.js"></script>
|
||||
<script src="assets/js/setting.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user