/api/todos/write

This commit is contained in:
samerbam 2023-08-24 18:18:10 -04:00
parent c198341999
commit 1b7dea8388
4 changed files with 46 additions and 1 deletions

View File

@ -19,6 +19,7 @@ auth = VerifyToken()
data = TodoDatabase() data = TodoDatabase()
printer = ThermalPrinter(data) printer = ThermalPrinter(data)
# printer.print_default() #temp debug # printer.print_default() #temp debug
printer.print_qrcode()
@ -28,7 +29,7 @@ class Todo(BaseModel):
recurring: bool recurring: bool
class TodoList(BaseModel): class TodoList(BaseModel):
date: str #Always current date OLD TEXT: #Either current date in %Y-%m-%d format or "recurring" for a recurring task date: str #Always selected date OLD TEXT: #Either current date in %Y-%m-%d format or "recurring" for a recurring task
todos: list[Todo] todos: list[Todo]

BIN
application/qrcode.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -254,6 +254,16 @@ function addTask(defaultTimeRange="", defaultTaskText="New Task", editable=true)
timeButtonDisplay.innerHTML = defaultTimeRange timeButtonDisplay.innerHTML = defaultTimeRange
timePickerWindowButton.appendChild(timeButtonDisplay) timePickerWindowButton.appendChild(timeButtonDisplay)
let recButtonDiv = document.createElement("div")
recButtonDiv.className = "recurringButton hover:bg-slate-200 cursor-pointer rounded-md flex flex-row space-x-1 items-center"
secondContainer.appendChild(recButtonDiv)
let recButtonSpan = document.createElement("span")
recButtonSpan.className = "w-8 h-8 flex space-x-2 space-y-2 items-center justify-center"
recButtonSpan.innerHTML += "<svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' class='w-6 h-6 text-black'><path stroke-linecap='round' stroke-linejoin='round' d='M19.5 12c0-1.232-.046-2.453-.138-3.662a4.006 4.006 0 00-3.7-3.7 48.678 48.678 0 00-7.324 0 4.006 4.006 0 00-3.7 3.7c-.017.22-.032.441-.046.662M19.5 12l3-3m-3 3l-3-3m-12 3c0 1.232.046 2.453.138 3.662a4.006 4.006 0 003.7 3.7 48.656 48.656 0 007.324 0 4.006 4.006 0 003.7-3.7c.017-.22.032-.441.046-.662M4.5 12l3 3m-3-3l-3 3' /></svg>"
recButtonDiv.appendChild(recButtonSpan)
row.appendChild(secondContainer) row.appendChild(secondContainer)
@ -566,6 +576,36 @@ function savePrintButtonListener(e) {
if (spbt.innerHTML === "Save") { if (spbt.innerHTML === "Save") {
setsavePrintButton(save=false) setsavePrintButton(save=false)
let todo_list = []
for (let row of document.getElementsByClassName("task-row")) {
todos_list.push({"time": row.querySelector("#timeButtonDisplay").innerHTML, "task": row.querySelector("#task").innerHTML, "recurring": row.dataset.recurring})
}
fetch("/api/todos/write", {
method: "post",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': "Bearer " + jToken
},
//make sure to serialize your JSON body
body: JSON.stringify({
"date": dayjs(document.getElementById("date-view").innerHTML.slice(4), "MMM D, YYYY").format("YYYY-MM-DD"),
"todos": todo_list
})
})
.then( (response) => {
response.json().then(r => {
console.log(r.status)
})
//do something awesome that makes the world a better place
});
//TODO: send api request to save todos to database //TODO: send api request to save todos to database
} else if (spbt.innerHTML === "Print") { } else if (spbt.innerHTML === "Print") {

View File

@ -233,6 +233,10 @@ class ThermalPrinter():
def finished_printing(self): def finished_printing(self):
self.p.cut() #move paper up enough to tear off (probably a better way, but this works.) self.p.cut() #move paper up enough to tear off (probably a better way, but this works.)
def print_qrcode(self):
self.p.text("\n")
self.p.set(align="center")
self.p.image("application/qrcode.png")
# class SyncData(): # class SyncData():
# def __init__(self): # def __init__(self):