Skip to content

Commit

Permalink
🔧 lab enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
worthant committed Sep 12, 2023
1 parent bffdd66 commit da945a7
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 63 deletions.
75 changes: 59 additions & 16 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<!-- <link rel="stylesheet" href="styles.css"> -->
<link rel="icon" type="image/png" href="images/favicon.png">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
<title>Web programming laboratory work no. 1</title>

<style>
Expand Down Expand Up @@ -62,10 +63,11 @@
.container {
display: grid;
grid-template-columns: 10% 1fr 1fr 10%;
grid-template-rows: 5% 50% 80%;
gap: 2%;
grid-template-rows: min-content minmax(0, 1fr);
gap: 20px;
}


.graph,
.form {
border-radius: 10px;
Expand All @@ -78,6 +80,7 @@
backdrop-filter: blur(7px);
box-shadow: 0px 0px 3px white;

max-height: 700px;
}

.graph {
Expand Down Expand Up @@ -106,10 +109,13 @@
justify-content: center;
}

input {
padding: 1em;
}

input[type="text"],
select {
padding: 0.5em;
padding: 0.5em; /* каскадирование */
border-radius: 4px;
border: 1px solid #ccc;
}
Expand All @@ -118,7 +124,7 @@
.check-btn {
display: flex;
justify-content: center;
margin-top: 3em;
margin-top: 1em;
}

input[type="submit"] {
Expand Down Expand Up @@ -146,6 +152,11 @@
border-radius: 20px 20px 0 0;
}

/* .scrollable-body {
overflow-y: auto;
display: block;
} */

table {
width: 100%;
border-collapse: collapse;
Expand All @@ -156,28 +167,46 @@
padding: 10px;
}

#resultTable tr th:first-child {
.resultTable tr th:first-child {
border-radius: 20px 0 0 0;

}

#resultTable tr th:last-child {
.resultTable tr th:last-child {
border-radius: 0 10px 0 0;

}

#resultTable tr th:not(:first-child):not(:last-child) {
.resultTable tr th:not(:first-child):not(:last-child) {
border-left: 1px solid white;
border-right: 1px solid white;
}

/* .result-cell-in, .result-cell-out{
text-align: center;
border-left: 1px solid white;
border-right: 1px solid white;
} */

.result-cell-in{
color: green;
}

.result-cell-out{
color: red;
}

thead {
border-bottom: 1px solid white;
}

</style>
</head>

<body>
<header>
<div class="githubIcon">
<a href="https://github.com/worthant">
<a href="https://github.com/worthant/simple-one-page-website">
<img src="images/github.png" class="icon">
</a>
</div>
Expand Down Expand Up @@ -241,10 +270,14 @@ <h1 class="info">var 1204 | Dvorkin Boris Alexandrovich | P3131</h1>
</svg>
</div>

<div class="form">
<form action="script.php" method="get" onsubmit="return validateForm()">
<div class="form" id="input-form">
<form>
<div class="input-group">
<p>X:</p>
<form>
<p> abcd </p>
<button> submit </button>
</form>
<div id="x" class="radio-group">
<label><input type="radio" name="x" value="-3">-3</label>
<label><input type="radio" name="x" value="-2">-2</label>
Expand All @@ -259,7 +292,7 @@ <h1 class="info">var 1204 | Dvorkin Boris Alexandrovich | P3131</h1>
</div>
<div class="input-group">
<label for="y">Y:</label>
<input type="text" id="y" name="y">
<input type="text" id="y" name="y" maxlength="8">
</div>
<div class="input-group">
<label for="r">R:</label>
Expand All @@ -278,19 +311,27 @@ <h1 class="info">var 1204 | Dvorkin Boris Alexandrovich | P3131</h1>
</div>

<div class="table">
<table id="resultTable">
<table class="resultTable">
<thead>
<tr>
<th>x</th>
<th>y</th>
<th>r</th>
<th>target hit or not</th>
<th>time and date of the request</th>
<th>current time</th>
<th>duration of script.php running</th>
</tr>
</thead>
<tbody>
<!-- The rows will be populated here by JavaScript -->
<tbody id="output">
<!-- The rows here will be populated by JavaScript -->
<tr>
<td>Data for x</td>
<td>Data for y</td>
<td>Data for r</td>
<td>Data for hit or not</td>
<td>Data for current time</td>
<td>Data for duration</td>
</tr>
</tbody>
</table>
</div>
Expand All @@ -299,7 +340,9 @@ <h1 class="info">var 1204 | Dvorkin Boris Alexandrovich | P3131</h1>
<audio id="background-music" loop>
<source src="nostalgic.mp3" type="audio/mp3">
</audio>
<script src="script.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
<script type="text/javascript" src="addToTable.js"></script>
<script type="module" src="main.js"></script>
</body>

</html>
27 changes: 27 additions & 0 deletions client/inputValidator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export default class inputValidator{
constructor(responseCode, message) {
this.responseCode = responseCode;
this.message = message;
}
validate(xVal, yVal, rVal){
if (![-3, -2, -1, 0, 1, 2, 3, 4, 5].includes(xVal)) {
this.message = "The X value should be something from this array: [-3, -2, -1, 0, 1, 2, 3, 4, 5]";
this.responseCode = 0;
} else if (!(-5 < yVal && yVal < 5)){
this.message = "The Y value should be in (-5, 5) interval";
this.responseCode = 0;
} else if (![1, 1.5, 2, 2.5, 3].includes(rVal)){
this.message = "The R value should be something from this array: [1, 1.5, 2, 2.5, 3]";
this.responseCode = 0;
} else {
this.responseCode = 1;
}
}

getResponseCode(){
return this.responseCode;
}
getMessage(){
return this.message;
}
}
100 changes: 100 additions & 0 deletions client/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import inputValidator from "./inputValidator.js";

"use strict";

document.addEventListener("DOMContentLoaded", () => {
// Update Date and Time Function
function updateDateTime() {
const now = new Date();
document.getElementById("date").innerText = now.toDateString();
document.getElementById("time").innerText = now.toTimeString().substring(0, 8);
}

// Initial Date Time Update
updateDateTime();
setInterval(updateDateTime, 1000);
});

window.onload = function () {
// const savedData = JSON.parse(localStorage.getItem('tableData')) || [];
// savedData.forEach(data => {
// addToTable(data.x, data.y, data.r, data.result, data.curr_time, data.exec_time);
// })
console.log(localStorage.getItem("session"));
document.getElementById("output").innerHTML = localStorage.getItem("session");
}

const mainForm = document.querySelector('#input-form');
mainForm.addEventListener('submit', function (e) {
// default action is to send the form data to the server and reload the page
// by calling .preventDefault() i am stopping the browser from doing this,
// which allows me to handle the form submission programmatically in your JavaScript code instead.
e.preventDefault();

const xElement = document.querySelector('input[name="x"]:checked');
const yElement = document.querySelector('#y');
const rElement = document.querySelector('#r');

if (xElement && yElement && rElement) {
const xVal = parseFloat(xElement.value);
const yVal = parseFloat(yElement.value.substring(0, 8));
const rVal = parseFloat(rElement.value);
console.log(`X: ${xVal}, Y: ${yVal}, R: ${rVal}`);

const validator = new inputValidator();
validator.validate(xVal, yVal, rVal);

if (validator.getResponseCode() === 1) {
console.log(`everything is ok`);

fetch(`./script.php?xVal=${xVal}&yVal=${yVal}&rVal=${rVal}`, {
method: 'GET',
})
.then(response => {
if (!response.ok) {
throw new Error(`Server responded with bad getaway status: ${response.status}`);
}
return response.text();
})
.then(function (serverAnswer) {
localStorage.setItem("session", serverAnswer);
document.getElementById("output").innerHTML = serverAnswer;
// addToTable(xVal, yVal, rVal, responseData.result, responseData.curr_time, responseData.exec_time);
// saveToLocalStorage(xVal, yVal, rVal, responseData.result, responseData.curr_time, responseData.exec_time);
})
.catch(error => {
alert(`There was an error processing your request: ${error.message}`)
})
} else {
Toastify({
text: validator.getMessage(),
className: "info",
style: {
background: "linear-gradient(to right, #00b09b, #96c93d)",
border: "1px solid white"
},
offset: {
x: 240,
y: 60
},
position: "right",
}).showToast();
}
} else {
Toastify({
text: "You should fill the form before submitting it :)",
className: "info",
style: {
background: "linear-gradient(to right, #00b09b, #96c93d)",
border: "1px solid white"
},
offset: {
x: 240,
y: 60
},
position: "right",
}).showToast();
}
});


29 changes: 0 additions & 29 deletions client/script.js

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"php": "^1.0.2"
},
"scripts": {
"dev": "lite-server"
"dev": "lite-server",
"deploy": "./deploy.sh"
},
"name": "simple-one-page-website",
"version": "1.0.0",
Expand Down
Loading

0 comments on commit da945a7

Please sign in to comment.