In progress: offline fuel record creation
This commit is contained in:
		
							
								
								
									
										17
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								TODO.md
									
									
									
									
									
								
							@@ -6,13 +6,10 @@
 | 
				
			|||||||
- [ ] edit user data - change password, mail...
 | 
					- [ ] edit user data - change password, mail...
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Core of the app
 | 
					## Core of the app
 | 
				
			||||||
- [ ] header and navbar
 | 
					- [ ] intro tutorial when no car exist or just dont show anything
 | 
				
			||||||
- [ ] dashboard
 | 
					- [ ] change/set default car
 | 
				
			||||||
  - [x] css
 | 
					- [ ] specific car view - charts, fuel records
 | 
				
			||||||
  - [ ] its just plain
 | 
					- [ ] remove/edit fuel record
 | 
				
			||||||
  - [ ] graphs
 | 
					
 | 
				
			||||||
- [x] Habits list
 | 
					- [ ] IndexDB
 | 
				
			||||||
  - [ ] css
 | 
					  - [ ] 
 | 
				
			||||||
- [ ] Habits create
 | 
					 | 
				
			||||||
  - [ ] validate cron input
 | 
					 | 
				
			||||||
- [ ] Habits track
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@
 | 
				
			|||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        <a href="/refuel/create" class="btn-green">Add new refuel record!</a>
 | 
					        <a href="/refuel/create" class="btn-green">Add new refuel record!</a>
 | 
				
			||||||
        <a href="/vehicles" class="btn-primary">List all vehicles</a>
 | 
					        <a href="/vehicles" class="btn-primary">List all vehicles</a>
 | 
				
			||||||
 | 
					        <button class="btn-primary" id="btn-offline-add">Add new refuel record OFFLINE</button>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
    <div class="card-wrapper">
 | 
					    <div class="card-wrapper">
 | 
				
			||||||
        <section class="card latest">
 | 
					        <section class="card latest">
 | 
				
			||||||
@@ -60,3 +61,4 @@
 | 
				
			|||||||
        },
 | 
					        },
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					<script defer src="/js/offline-records.js"></script>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,7 @@ h1 {
 | 
				
			|||||||
	cursor: pointer;
 | 
						cursor: pointer;
 | 
				
			||||||
	border-radius: var(--border-radious);
 | 
						border-radius: var(--border-radious);
 | 
				
			||||||
	border: var(--borderWidth-thin) solid var(--clr-border);
 | 
						border: var(--borderWidth-thin) solid var(--clr-border);
 | 
				
			||||||
 | 
						color: white;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.btn-secondary {
 | 
					.btn-secondary {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										98
									
								
								public/js/offline-records.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								public/js/offline-records.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,98 @@
 | 
				
			|||||||
 | 
					async function checkOnline() {
 | 
				
			||||||
 | 
						if (!navigator.onLine) {
 | 
				
			||||||
 | 
							console.log("Offline (no network connection)");
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						try {
 | 
				
			||||||
 | 
							const response = await fetch(
 | 
				
			||||||
 | 
								"https://www.google.com/favicon.ico?" + new Date().getTime(),
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									mode: "no-cors",
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						} catch (error) {
 | 
				
			||||||
 | 
							console.log("Connected to network but no internet access");
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					setInterval(async () => {
 | 
				
			||||||
 | 
						const isOnline = await checkOnline();
 | 
				
			||||||
 | 
						if (!isOnline) {
 | 
				
			||||||
 | 
							console.log("OFFLINE!!!");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}, 5000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const offbtn = document.querySelector("#btn-offline-add");
 | 
				
			||||||
 | 
					offbtn.addEventListener("click", (e) => {
 | 
				
			||||||
 | 
						e.preventDefault();
 | 
				
			||||||
 | 
						document.querySelector("section.dashboard").style.display = "none";
 | 
				
			||||||
 | 
						const offline = document.createElement("div");
 | 
				
			||||||
 | 
						offline.classList.add("offline");
 | 
				
			||||||
 | 
						offline.innerHTML = `
 | 
				
			||||||
 | 
					    <b>You're Offline</b>
 | 
				
			||||||
 | 
					    <p>You can create an fuel record locally on your device and sync it later</p>
 | 
				
			||||||
 | 
					    <section class="form">
 | 
				
			||||||
 | 
					        <h1 class="header-form"><?= $this->get('title') ?></h1>
 | 
				
			||||||
 | 
					        <!-- <?php if ($this->get('error')): ?> -->
 | 
				
			||||||
 | 
					        <!--     <div class="error" style="color: red; margin-bottom: 1rem;"> -->
 | 
				
			||||||
 | 
					        <!--         <?= htmlspecialchars($this->get('error')) ?> -->
 | 
				
			||||||
 | 
					        <!--     </div> -->
 | 
				
			||||||
 | 
					        <!-- <?php endif; ?> -->
 | 
				
			||||||
 | 
					        <form method="POST" action="/refuel/create">
 | 
				
			||||||
 | 
					            <label for="vehicle">Vehicle</label>
 | 
				
			||||||
 | 
					            <select name="vehicle" id="vehicle">
 | 
				
			||||||
 | 
					            <!-- <?php foreach ($this->get('vehicles') as $vehicle): ?> -->
 | 
				
			||||||
 | 
					            <!--     <option value="<?= $vehicle['id'] ?>"><?= $vehicle['name'] . " | " . $vehicle['registration_plate'] ?></option> -->
 | 
				
			||||||
 | 
					            <!-- <?php endforeach; ?> -->
 | 
				
			||||||
 | 
					            </select>
 | 
				
			||||||
 | 
					            <!-- <?php if (isset($this->get('validationErrors')['vehicle'])): ?> -->
 | 
				
			||||||
 | 
					            <!--     <small class="error"><?= $this->get('validationErrors')['vehicle'] ?></small> -->
 | 
				
			||||||
 | 
					            <!-- <?php endif; ?> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <label for="fuel_type">Fuel type</label>
 | 
				
			||||||
 | 
					            <select name="fuel_type" id="fuel_type">
 | 
				
			||||||
 | 
					                <option value="Diesel">Diesel</option>
 | 
				
			||||||
 | 
					                <option value="Gasoline 95">Gasoline 95</option>
 | 
				
			||||||
 | 
					                <option value="Gasoline 98">Gasoline 98</option>
 | 
				
			||||||
 | 
					                <option value="Premium Diesel">Premium Diesel</option>
 | 
				
			||||||
 | 
					                <option value="Premium Gasoline 95">Premium Gasoline 95</option>
 | 
				
			||||||
 | 
					                <option value="Premium Gasoline 98">Premium Gasoline 98</option>
 | 
				
			||||||
 | 
					                <option value="Other">Other</option>
 | 
				
			||||||
 | 
					            </select>
 | 
				
			||||||
 | 
					            <!-- <?php if (isset($this->get('validationErrors')['fuel_type'])): ?> -->
 | 
				
			||||||
 | 
					            <!--     <small class="error"><?= $this->get('validationErrors')['fuel_type'] ?></small> -->
 | 
				
			||||||
 | 
					            <!-- <?php endif; ?> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <label for="liters">Liters</label>
 | 
				
			||||||
 | 
					            <input type="number" name="liters" id="liters" min="0" step=".01" value="<?= htmlspecialchars($_POST['liters'] ?? '0.0') ?>">
 | 
				
			||||||
 | 
					            <!-- <?php if (isset($this->get('validationErrors')['liters'])): ?> -->
 | 
				
			||||||
 | 
					            <!--     <small class="error"><?= $this->get('validationErrors')['liters'] ?></small> -->
 | 
				
			||||||
 | 
					            <!-- <?php endif; ?> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <label for="price_per_liter">Price per liter</label>
 | 
				
			||||||
 | 
					            <input type="number" name="price_per_liter" id="price_per_liter" min="0" step=".01" value="<?= htmlspecialchars($_POST['price_per_liter'] ?? '0.0') ?>">
 | 
				
			||||||
 | 
					            <!-- <?php if (isset($this->get('validationErrors')['price_per_liter'])): ?> -->
 | 
				
			||||||
 | 
					            <!--     <small class="error"><?= $this->get('validationErrors')['price_per_liter'] ?></small> -->
 | 
				
			||||||
 | 
					            <!-- <?php endif; ?> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <label for="total_price">Total price</label>
 | 
				
			||||||
 | 
					            <input type="number" name="total_price" id="total_price" min="0" step=".01" value="<?= htmlspecialchars($_POST['total_price'] ?? '0.0') ?>">
 | 
				
			||||||
 | 
					            <!-- <?php if (isset($this->get('validationErrors')['total_price'])): ?> -->
 | 
				
			||||||
 | 
					            <!--     <small class="error"><?= $this->get('validationErrors')['total_price'] ?></small> -->
 | 
				
			||||||
 | 
					            <!-- <?php endif; ?> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <label for="note">Note</label>
 | 
				
			||||||
 | 
					            <input type="text" name="note" id="note" value="<?= htmlspecialchars($_POST['note'] ?? '') ?>">
 | 
				
			||||||
 | 
					            <!-- <?php if (isset($this->get('validationErrors')['note'])): ?> -->
 | 
				
			||||||
 | 
					            <!--     <small class="error"><?= $this->get('validationErrors')['note'] ?></small> -->
 | 
				
			||||||
 | 
					            <!-- <?php endif; ?> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <input type="submit" value="Create fuel record">
 | 
				
			||||||
 | 
					        </form>
 | 
				
			||||||
 | 
					    </section>
 | 
				
			||||||
 | 
					  `;
 | 
				
			||||||
 | 
						document.querySelector("main").appendChild(offline);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
		Reference in New Issue
	
	Block a user