Compare commits
2 Commits
af89ca96a1
...
d06b32c1b7
| Author | SHA256 | Date | |
|---|---|---|---|
| d06b32c1b7 | |||
| 212dea6a7d |
10
TODO.md
10
TODO.md
@@ -25,17 +25,13 @@ This template outlines the current state of the project files and future tasks t
|
||||
|
||||
### Future Tasks
|
||||
|
||||
1. **Refactor Save Plan Features:**
|
||||
- Move all save plan-related functions into a new TypeScript file (`planStorage.ts`).
|
||||
- Ensure seamless integration with the existing `roast.ts` functionality.
|
||||
|
||||
2. **Enhance User Interface:**
|
||||
1. **Enhance User Interface:**
|
||||
- Update visual styling for better user experience in `roast.css`.
|
||||
|
||||
3. **Expand Functionality:**
|
||||
2. **Expand Functionality:**
|
||||
- Add info about rate of rise
|
||||
- Capture info about the roast (start/end weight)
|
||||
|
||||
5. **Documentation and Testing:**
|
||||
3. **Documentation and Testing:**
|
||||
- Create comprehensive documentation for all features.
|
||||
- Develop test cases to ensure robustness of functionality.
|
||||
|
||||
74
src/planStorage.ts
Normal file
74
src/planStorage.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
// planStorage.ts
|
||||
|
||||
/**
|
||||
* Saves a roast plan to local storage.
|
||||
*
|
||||
* @param name The name of the plan.
|
||||
* @param temperatures A comma-separated string of temperature targets.
|
||||
*/
|
||||
export function savePlan(name: string, temperatures: string): void {
|
||||
if (!name) {
|
||||
throw new Error("Please provide a valid name for the roast plan.");
|
||||
}
|
||||
|
||||
const trimmedTemperatures = temperatures.trim();
|
||||
if (!trimmedTemperatures) {
|
||||
throw new Error("Temperature list is empty.");
|
||||
}
|
||||
|
||||
// Parse and validate temperature input
|
||||
const parsedTemps = trimmedTemperatures.split(',').map(x => x.trim()).map(Number);
|
||||
if (parsedTemps.some(val => isNaN(val))) {
|
||||
throw new Error("Invalid temperature list. Please enter comma-separated numbers.");
|
||||
}
|
||||
|
||||
localStorage.setItem(`roastplan_${name}`, trimmedTemperatures);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a saved roast plan from local storage.
|
||||
*
|
||||
* @param name The name of the plan to load.
|
||||
* @returns A string containing the temperature targets, or null if not found.
|
||||
*/
|
||||
export function retrievePlan(name: string): string | null {
|
||||
if (!name) return null;
|
||||
|
||||
const stored = localStorage.getItem(`roastplan_${name}`);
|
||||
return stored || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all saved roast plans from local storage.
|
||||
*/
|
||||
export function clearAllPlans(): void {
|
||||
const keysToRemove: string[] = [];
|
||||
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key && key.startsWith("roastplan_")) {
|
||||
keysToRemove.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
keysToRemove.forEach(key => localStorage.removeItem(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all saved roast plan names from local storage.
|
||||
*
|
||||
* @returns An array of strings representing the names of saved plans.
|
||||
*/
|
||||
export function listSavedPlans(): string[] {
|
||||
const savedPlanNames: string[] = [];
|
||||
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key && key.startsWith("roastplan_")) {
|
||||
const planName = key.replace("roastplan_", "");
|
||||
savedPlanNames.push(planName);
|
||||
}
|
||||
}
|
||||
|
||||
return savedPlanNames;
|
||||
}
|
||||
79
src/roast.ts
79
src/roast.ts
@@ -1,4 +1,5 @@
|
||||
import { loadGraph } from './tempgraph.ts';
|
||||
import { savePlan, retrievePlan, clearAllPlans, listSavedPlans } from './planStorage.ts';
|
||||
|
||||
let timer = 0;
|
||||
let isRunning = false;
|
||||
@@ -275,53 +276,61 @@ function saveCurrentPlan(): void {
|
||||
const planName = nameInput.value.trim();
|
||||
const rawInput = (document.getElementById("plan-input") as HTMLInputElement).value.trim();
|
||||
|
||||
if (!planName) {
|
||||
alert("Please enter a name to save the plan.");
|
||||
return;
|
||||
try {
|
||||
savePlan(planName, rawInput);
|
||||
alert(`Plan "${planName}" saved successfully.`);
|
||||
} catch (error) {
|
||||
alert(error.message);
|
||||
}
|
||||
|
||||
if (!rawInput) {
|
||||
alert("Temperature list is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
const parsed = rawInput.split(',').map(x => x.trim()).map(Number);
|
||||
if (parsed.some(val => isNaN(val))) {
|
||||
alert("Invalid temperature list. Please enter comma-separated numbers.");
|
||||
return;
|
||||
}
|
||||
|
||||
const tempStr = parsed.join(",");
|
||||
localStorage.setItem(`roastplan_${planName}`, tempStr);
|
||||
nameInput.value = "";
|
||||
updateSavedPlansDropdown();
|
||||
}
|
||||
|
||||
|
||||
function loadSavedPlan(name: string): void {
|
||||
if (!name) return;
|
||||
const stored = localStorage.getItem(`roastplan_${name}`);
|
||||
const stored = retrievePlan(name);
|
||||
if (stored) {
|
||||
targets = stored.split(",").map(Number);
|
||||
currentTargetIndex = 0;
|
||||
document.getElementById("controls")!.classList.remove("hidden");
|
||||
document.getElementById("create-plan")!.classList.add("hidden");
|
||||
|
||||
// Set the plan in the text box
|
||||
console.log("Set plan: " +stored);
|
||||
const planInput = document.getElementById("plan-input") as HTMLInputElement;
|
||||
const savedName = document.getElementById("save-name") as HTMLInputElement;
|
||||
planInput.value = stored;
|
||||
savedName.value = name;
|
||||
|
||||
generateTempButtons();
|
||||
|
||||
// Reset the input dropdown to the first (choose prompt) entry
|
||||
updateSavedPlansDropdown();
|
||||
} else {
|
||||
alert(`No plan found with the name "${name}".`);
|
||||
}
|
||||
}
|
||||
|
||||
function updateSavedPlansDropdown(): void {
|
||||
const dropdown = document.getElementById("saved-plans") as HTMLSelectElement;
|
||||
dropdown.innerHTML = '<option value="">-- Select saved plan --</option>';
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key && key.startsWith("roastplan_")) {
|
||||
const name = key.replace("roastplan_", "");
|
||||
const option = document.createElement("option");
|
||||
option.value = name;
|
||||
option.textContent = name;
|
||||
dropdown.appendChild(option);
|
||||
}
|
||||
|
||||
// Retrieve saved plans from planStorage.ts
|
||||
const savedPlans = listSavedPlans();
|
||||
|
||||
// Reset to default prompt
|
||||
dropdown.innerHTML = '<option value="">-- Select Saved Plan --</option>';
|
||||
|
||||
// Populate the dropdown with saved plans
|
||||
savedPlans.forEach(planName => {
|
||||
const option = document.createElement('option');
|
||||
option.value = planName;
|
||||
option.textContent = planName;
|
||||
dropdown.appendChild(option);
|
||||
});
|
||||
|
||||
// Set the first entry as selected if available
|
||||
if (savedPlans.length > 0) {
|
||||
dropdown.selectedIndex = 0; // Index 1 corresponds to the first actual plan
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,16 +338,7 @@ function clearSavedPlans(): void {
|
||||
const confirmClear = confirm("Are you sure you want to delete all saved roast plans?");
|
||||
if (!confirmClear) return;
|
||||
|
||||
const keysToRemove: string[] = [];
|
||||
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key && key.startsWith("roastplan_")) {
|
||||
keysToRemove.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
keysToRemove.forEach(key => localStorage.removeItem(key));
|
||||
clearAllPlans();
|
||||
updateSavedPlansDropdown();
|
||||
alert("All saved roast plans have been deleted.");
|
||||
}
|
||||
@@ -364,5 +364,4 @@ if (typeof window !== 'undefined') {
|
||||
window.clearSavedPlans = clearSavedPlans;
|
||||
}
|
||||
|
||||
|
||||
export {};
|
||||
|
||||
Reference in New Issue
Block a user