-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working extension, ai generation, storage, web app
- Loading branch information
1 parent
3a345fa
commit d627997
Showing
6 changed files
with
201 additions
and
22 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Notes Manager</title> | ||
<style> | ||
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; } | ||
.note { border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; } | ||
form { margin-bottom: 20px; } | ||
input, textarea { width: 100%; padding: 5px; margin-bottom: 10px; } | ||
button { padding: 5px 10px; } | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Notes Manager</h1> | ||
|
||
<form action="{{ url_for('add_note') }}" method="post"> | ||
<input type="text" name="title" placeholder="Title" required> | ||
<textarea name="content" placeholder="Note content" required></textarea> | ||
<input type="text" name="category" placeholder="Category"> | ||
<button type="submit">Add Note</button> | ||
</form> | ||
|
||
<h2>Your Notes</h2> | ||
{% for note in notes %} | ||
<div class="note" data-note-id="{{ note['id'] }}"> | ||
<h3>{{ note['title'] }}</h3> | ||
<p>{{ note['content'] }}</p> | ||
<p><strong>Category:</strong> {{ note['category'] }}</p> | ||
<p><strong>Date:</strong> {{ note['date'] }}</p> | ||
<form action="{{ url_for('delete_note', id=note['id']) }}" method="post" style="display:inline;"> | ||
<button type="submit">Delete</button> | ||
</form> | ||
<button class="edit-button">Edit</button> | ||
</div> | ||
{% endfor %} | ||
|
||
<script> | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const editButtons = document.querySelectorAll('.edit-button'); | ||
editButtons.forEach(button => { | ||
button.addEventListener('click', function() { | ||
const noteId = this.closest('.note').dataset.noteId; | ||
editNote(noteId); | ||
}); | ||
}); | ||
}); | ||
|
||
function editNote(id) { | ||
fetch(`/get_note/${id}`) | ||
.then(response => response.json()) | ||
.then(note => { | ||
document.querySelector('input[name="title"]').value = note.title; | ||
document.querySelector('textarea[name="content"]').value = note.content; | ||
document.querySelector('input[name="category"]').value = note.category; | ||
// You might want to add a hidden input for the note id and change the form action for editing | ||
}); | ||
} | ||
</script> | ||
</body> | ||
</html> |
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,51 @@ | ||
from flask import Flask, render_template, request, redirect, url_for, jsonify | ||
from flask_cors import CORS | ||
import sqlite3 | ||
from datetime import datetime | ||
|
||
app = Flask(__name__) | ||
CORS(app) | ||
|
||
def get_db_connection(): | ||
conn = sqlite3.connect('notes.db') | ||
conn.row_factory = sqlite3.Row | ||
return conn | ||
|
||
@app.route('/') | ||
def index(): | ||
conn = get_db_connection() | ||
notes = conn.execute('SELECT * FROM notes ORDER BY date DESC').fetchall() | ||
conn.close() | ||
return render_template('index.html', notes=notes) | ||
|
||
@app.route('/add_note', methods=['POST']) | ||
def add_note(): | ||
title = request.form['title'] | ||
content = request.form['content'] | ||
category = request.form['category'] | ||
date = datetime.now().isoformat() | ||
|
||
conn = get_db_connection() | ||
conn.execute('INSERT INTO notes (title, content, category, date) VALUES (?, ?, ?, ?)', | ||
(title, content, category, date)) | ||
conn.commit() | ||
conn.close() | ||
return redirect(url_for('index')) | ||
|
||
@app.route('/delete_note/<int:id>', methods=['POST']) | ||
def delete_note(id): | ||
conn = get_db_connection() | ||
conn.execute('DELETE FROM notes WHERE id = ?', (id,)) | ||
conn.commit() | ||
conn.close() | ||
return redirect(url_for('index')) | ||
|
||
@app.route('/get_note/<int:id>') | ||
def get_note(id): | ||
conn = get_db_connection() | ||
note = conn.execute('SELECT * FROM notes WHERE id = ?', (id,)).fetchone() | ||
conn.close() | ||
return jsonify(dict(note)) | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True, port=5001) |