-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- use module - use web component to render the form Signed-off-by: yzamir <kobi.zamir@gmail.com>
- Loading branch information
Showing
4 changed files
with
159 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
.form { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.form-group { | ||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
margin-bottom: 15px; | ||
} | ||
|
||
.label { | ||
font-size: 1.2em; | ||
} | ||
|
||
.input-field { | ||
flex-grow: 1; | ||
margin-left: 10px; | ||
padding: 10px; | ||
font-size: 1em; | ||
border-radius: 5px; | ||
border: 1px solid #34495e; | ||
background-color: #ecf0f1; | ||
color: #2c3e50; | ||
} | ||
|
||
.submit-button { | ||
background-color: #3498db; | ||
color: #ecf0f1; | ||
font-size: 1.2em; | ||
padding: 15px 30px; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
transition: background-color 0.2s; | ||
} | ||
|
||
.submit-button:hover { | ||
background-color: #2980b9; | ||
} | ||
|
||
.cancel-button { | ||
background-color: #e74c3c; /* Red color for cancel */ | ||
color: #fff; | ||
font-size: 1.2em; | ||
padding: 15px 30px; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
transition: background-color 0.2s; | ||
} | ||
|
||
.cancel-button:hover { | ||
background-color: #c0392b; /* Darker shade on hover */ | ||
} | ||
|
||
.form-group { | ||
display: flex; | ||
justify-content: center; /* Adjust as needed; this will space the two buttons evenly apart */ | ||
} | ||
|
||
/* Assuming you want some spacing between the two buttons */ | ||
.submit-button, .cancel-button { | ||
margin: 0 5px; /* Adds 5px margin on both sides of each button */ | ||
} | ||
|
||
.error-message { | ||
color: red; | ||
margin-top: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
class SettingsForm extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: 'open' }); | ||
} | ||
|
||
connectedCallback() { | ||
this.render(); | ||
this.loadDrivers(); | ||
this.shadowRoot.querySelector('#submit-button').addEventListener('click', this.sendDrivers.bind(this)); | ||
this.shadowRoot.querySelector('#cancel-button').addEventListener('click', this.cancelSetting.bind(this)); | ||
} | ||
|
||
render() { | ||
this.shadowRoot.innerHTML = ` | ||
<link rel="stylesheet" href="./settings-form.css"> | ||
<form class="form"> | ||
<div class="form-group"> | ||
<label for="driver1" class="label">Driver 1:</label> | ||
<input type="text" id="driver1" name="driver1" placeholder="http://driver.student.svc.cluster.local:8081" class="input-field"> | ||
</div> | ||
<div class="form-group"> | ||
<label for="driver2" class="label">Driver 2:</label> | ||
<input type="text" id="driver2" name="driver2" class="input-field"> | ||
</div> | ||
<div class="form-group"> | ||
<button type="button" id="submit-button" class="submit-button">Send</button> | ||
<button type="button" id="cancel-button" class="cancel-button">Cancel</button> | ||
</div> | ||
</form> | ||
<div class="error-message" id="error-message"></div> | ||
`; | ||
} | ||
|
||
displayError(message) { | ||
const errorMessageElement = this.shadowRoot.getElementById('error-message'); | ||
errorMessageElement.textContent = message; | ||
} | ||
|
||
async loadDrivers() { | ||
try { | ||
const response = await fetch('/admin', { method: 'POST' }); | ||
const data = await response.json(); | ||
|
||
if (data.drivers && data.drivers.length > 0) { | ||
this.shadowRoot.getElementById('driver1').value = data.drivers[0] ?? ""; | ||
this.shadowRoot.getElementById('driver2').value = data.drivers[1] ?? ""; | ||
} | ||
} catch (error) { | ||
this.displayError('Error loading drivers: ' + error.message); | ||
} | ||
} | ||
|
||
async sendDrivers(event) { | ||
event.preventDefault(); | ||
|
||
const driver1 = this.shadowRoot.getElementById('driver1').value; | ||
const driver2 = this.shadowRoot.getElementById('driver2').value; | ||
|
||
const params = new URLSearchParams(); | ||
params.append('drivers', `${driver1},${driver2}`); | ||
|
||
try { | ||
const response = await fetch(`/admin?${params}`, { method: 'POST' }); | ||
|
||
if (response.ok) { | ||
window.location.href = "index.html"; | ||
} else { | ||
this.displayError('Error sending drivers: ' + response.statusText); | ||
} | ||
} catch (error) { | ||
this.displayError('Error sending drivers: ' + error.message); | ||
} | ||
} | ||
|
||
cancelSetting(event) { | ||
event.preventDefault(); | ||
window.location.href = "index.html"; | ||
} | ||
} | ||
|
||
customElements.define('settings-form', SettingsForm); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters