things
This commit is contained in:
@ -1,100 +1,218 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<title>{% block title %}Nature In Pots Community{% endblock %}</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
}
|
||||
main {
|
||||
flex: 1;
|
||||
}
|
||||
footer {
|
||||
background-color: #f8f9fa;
|
||||
padding: 1rem 0;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}Nature In Pots Community{% endblock %}</title>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css"
|
||||
rel="stylesheet"
|
||||
>
|
||||
<style>
|
||||
body { display: flex; flex-direction: column; min-height: 100vh; }
|
||||
main { flex: 1; }
|
||||
footer { background: #f8f9fa; padding: 1rem 0; text-align: center; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm mb-4">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="{{ url_for('core_ui.home') }}">Nature In Pots</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('core_ui.home') }}">Home</a>
|
||||
</li>
|
||||
{% if current_user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('plant.index') }}">Plants</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('utility.upload') }}">Import</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('plant.index') }}#plantContainer">Grow Logs</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('submission.list_submissions') }}">Submissions</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('utility.export_data') }}">Export</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if current_user.is_authenticated and current_user.role == 'admin' %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-danger" href="{{ url_for('admin.admin_dashboard') }}">
|
||||
Admin Dashboard
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% block plugin_links %}{% endblock %}
|
||||
<a class="navbar-brand fw-bold" href="{{ url_for('core_ui.home') }}">
|
||||
Nature In Pots
|
||||
</a>
|
||||
<button
|
||||
class="navbar-toggler"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#mainNav"
|
||||
>
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="mainNav">
|
||||
<!-- Left links -->
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item me-2">
|
||||
<a class="nav-link" href="{{ url_for('core_ui.home') }}">Home</a>
|
||||
</li>
|
||||
{% if current_user.is_authenticated %}
|
||||
<li class="nav-item me-2">
|
||||
<a class="nav-link" href="{{ url_for('plant.index') }}">Plants</a>
|
||||
</li>
|
||||
<li class="nav-item me-2">
|
||||
<a class="nav-link" href="{{ url_for('growlog.list_logs') }}">Grow Logs</a>
|
||||
</li>
|
||||
<li class="nav-item me-2">
|
||||
<a class="nav-link" href="{{ url_for('submission.list_submissions') }}">
|
||||
Submissions
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
<!-- New-item + Admin + Plugins -->
|
||||
{% if current_user.is_authenticated %}
|
||||
<div class="d-flex align-items-center">
|
||||
<!-- + New dropdown -->
|
||||
<div class="btn-group me-3">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-success"
|
||||
onclick="location.href='{{ url_for('plant.create') }}'"
|
||||
>
|
||||
<i class="bi bi-plus-lg"></i>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-success dropdown-toggle dropdown-toggle-split"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-expanded="false"
|
||||
>
|
||||
<span class="visually-hidden">Toggle menu</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for('plant.create') }}">
|
||||
New Plant
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for('growlog.add_log') }}">
|
||||
New Grow Log
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
class="dropdown-item"
|
||||
href="{{ url_for('submission.new_submission') }}"
|
||||
>
|
||||
New Submission
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav align-items-center">
|
||||
{% if current_user.is_authenticated %}
|
||||
<li class="nav-item ms-3">
|
||||
<a class="nav-link" href="{{ url_for('auth.logout') }}">Logout</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item ms-3">
|
||||
<a class="nav-link" href="{{ url_for('auth.login') }}">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('auth.register') }}">Register</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Admin link -->
|
||||
{% if current_user.role == 'admin' %}
|
||||
<a
|
||||
class="btn btn-outline-danger me-3"
|
||||
href="{{ url_for('admin.admin_dashboard') }}"
|
||||
>
|
||||
Admin Dashboard
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<!-- Plugins dropdown -->
|
||||
<div class="dropdown me-3">
|
||||
<a
|
||||
class="btn btn-outline-secondary dropdown-toggle"
|
||||
href="#"
|
||||
id="pluginsDropdown"
|
||||
role="button"
|
||||
data-bs-toggle="dropdown"
|
||||
>
|
||||
Plugins
|
||||
</a>
|
||||
<ul
|
||||
class="dropdown-menu dropdown-menu-end"
|
||||
aria-labelledby="pluginsDropdown"
|
||||
>
|
||||
<li><a class="dropdown-item" href="#">Materials</a></li>
|
||||
<li><a class="dropdown-item" href="#">Ledger</a></li>
|
||||
<li><a class="dropdown-item" href="#">Inventory</a></li>
|
||||
<li><a class="dropdown-item" href="#">Collectives</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Profile dropdown -->
|
||||
<div class="dropdown">
|
||||
<a
|
||||
class="d-flex align-items-center text-decoration-none dropdown-toggle"
|
||||
href="#"
|
||||
id="profileDropdown"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-expanded="false"
|
||||
>
|
||||
<i class="bi bi-person-circle fs-4 me-1"></i>
|
||||
<span>{{ current_user.username }}</span>
|
||||
</a>
|
||||
<ul
|
||||
class="dropdown-menu dropdown-menu-end text-small"
|
||||
aria-labelledby="profileDropdown"
|
||||
>
|
||||
<li><a class="dropdown-item" href="#">My Profile</a></li>
|
||||
<li><a class="dropdown-item" href="#">Settings</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for('utility.upload') }}">
|
||||
Import
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for('utility.export_data') }}">
|
||||
Export
|
||||
</a>
|
||||
</li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<a
|
||||
class="dropdown-item text-danger"
|
||||
href="{{ url_for('auth.logout') }}"
|
||||
>
|
||||
<i class="bi bi-box-arrow-right me-1"></i> Logout
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<main class="container">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
<div class="container mt-3">
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
|
||||
{{ message }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<!-- Login / Register buttons -->
|
||||
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item me-2">
|
||||
<a class="btn btn-outline-primary" href="{{ url_for('auth.login') }}">
|
||||
Login
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-primary" href="{{ url_for('auth.register') }}">
|
||||
Register
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="container">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
<div class="mt-3">
|
||||
{% for category, message in messages %}
|
||||
<div
|
||||
class="alert alert-{{ category }} alert-dismissible fade show"
|
||||
role="alert"
|
||||
>
|
||||
{{ message }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
<footer>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
© {{ current_year | default(2025) }} Nature In Pots Community. All rights reserved.
|
||||
</footer>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</footer>
|
||||
|
||||
<script
|
||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
|
||||
></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,6 +1,55 @@
|
||||
{% extends 'core_ui/base.html' %}
|
||||
{% block title %}Home | Nature In Pots{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1 class="mb-4">Welcome to Nature In Pots 🌿</h1>
|
||||
<p>This is the community hub for plant tracking, propagation history, and price sharing.</p>
|
||||
<!-- Hero Section -->
|
||||
<div class="py-5 text-center bg-light rounded-3">
|
||||
<h1 class="display-5 fw-bold">Welcome to Nature In Pots</h1>
|
||||
<p class="fs-5 text-muted mb-4">
|
||||
Your internal platform for comprehensive plant tracking, propagation history, and collaborative logging.
|
||||
</p>
|
||||
<p class="mb-0">
|
||||
<strong class="text-success">Free to use for the time being</strong><br>
|
||||
(A future subscription or licensing model may be introduced as needed.)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Features Overview -->
|
||||
<div class="row mt-5 gy-4">
|
||||
<div class="col-md-4">
|
||||
<h3>Plant Profiles</h3>
|
||||
<p>Quickly create and manage detailed records—type, names, lineage, notes, and custom slugs for easy sharing.</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h3>Grow Logs</h3>
|
||||
<p>Maintain a timeline of growth metrics, health events, substrate mixes, and propagation notes.</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h3>Image Gallery</h3>
|
||||
<p>Upload, rotate, and feature photos for each plant. Community voting and one-click “featured” selection.</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h3>Lineage Tracking</h3>
|
||||
<p>Visualize parent–child relationships with a graph powered by Neo4j—track every cutting, seed, and division.</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h3>Pricing & Transfers</h3>
|
||||
<p>Securely log acquisition costs, resale prices, and ownership changes—with history retained and protected.</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h3>Import & Export</h3>
|
||||
<p>Bulk-import plants and media via CSV/ZIP. Export your entire dataset and images for backups or reporting.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Call to Action -->
|
||||
<div class="text-center mt-5">
|
||||
{% if current_user.is_authenticated %}
|
||||
<a href="{{ url_for('plant.index') }}" class="btn btn-primary btn-lg me-2">View My Plants</a>
|
||||
<a href="{{ url_for('utility.upload') }}" class="btn btn-outline-secondary btn-lg">Import Data</a>
|
||||
{% else %}
|
||||
<a href="{{ url_for('auth.register') }}" class="btn btn-success btn-lg me-2">Register Now</a>
|
||||
<a href="{{ url_for('auth.login') }}" class="btn btn-outline-primary btn-lg">Log In</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -1,8 +1,16 @@
|
||||
# plugins/growlog/forms.py
|
||||
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import TextAreaField, SelectField, SubmitField
|
||||
from wtforms import SelectField, StringField, TextAreaField, BooleanField, SubmitField
|
||||
from wtforms.validators import DataRequired, Length
|
||||
|
||||
class GrowLogForm(FlaskForm):
|
||||
plant_uuid = SelectField(
|
||||
'Plant',
|
||||
choices=[], # injected in view
|
||||
validators=[DataRequired()]
|
||||
)
|
||||
|
||||
event_type = SelectField('Event Type', choices=[
|
||||
('water', 'Watered'),
|
||||
('fertilizer', 'Fertilized'),
|
||||
@ -11,5 +19,7 @@ class GrowLogForm(FlaskForm):
|
||||
('pest', 'Pest Observed')
|
||||
], validators=[DataRequired()])
|
||||
|
||||
note = TextAreaField('Notes', validators=[Length(max=1000)])
|
||||
submit = SubmitField('Add Log')
|
||||
title = StringField('Title', validators=[Length(max=255)])
|
||||
notes = TextAreaField('Notes', validators=[Length(max=1000)])
|
||||
is_public = BooleanField('Public?')
|
||||
submit = SubmitField('Add Log')
|
||||
|
@ -7,6 +7,7 @@ class GrowLog(db.Model):
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
plant_id = db.Column(db.Integer, db.ForeignKey("plant.id"), nullable=False)
|
||||
event_type = db.Column(db.String(50), nullable=False)
|
||||
title = db.Column(db.String(255), nullable=True)
|
||||
notes = db.Column(db.Text, nullable=True)
|
||||
is_public = db.Column(db.Boolean, default=False, nullable=False)
|
||||
|
@ -1,31 +1,176 @@
|
||||
from flask import Blueprint, render_template, redirect, url_for, request
|
||||
from flask_login import login_required
|
||||
from uuid import UUID as _UUID
|
||||
from werkzeug.exceptions import NotFound
|
||||
from flask import (
|
||||
Blueprint, render_template, abort, redirect, url_for, request, flash
|
||||
)
|
||||
from flask_login import login_required, current_user
|
||||
from app import db
|
||||
from .models import GrowLog
|
||||
from .forms import GrowLogForm
|
||||
from plugins.plant.models import Plant
|
||||
from plugins.plant.models import Plant, PlantCommonName
|
||||
|
||||
bp = Blueprint('growlog', __name__, template_folder='templates')
|
||||
|
||||
@bp.route('/plants/<int:plant_id>/logs')
|
||||
bp = Blueprint(
|
||||
'growlog',
|
||||
__name__,
|
||||
url_prefix='/growlogs',
|
||||
template_folder='templates',
|
||||
)
|
||||
|
||||
|
||||
def _get_plant_by_uuid(uuid_val):
|
||||
"""
|
||||
uuid_val may already be a uuid.UUID (from a <uuid:> route converter)
|
||||
or a string (from form POST). Normalize & validate it, then lookup.
|
||||
"""
|
||||
# 1) If Flask route gave us a UUID instance, just stringify it
|
||||
if isinstance(uuid_val, _UUID):
|
||||
val = str(uuid_val)
|
||||
else:
|
||||
# 2) Otherwise try to parse it as a hex string
|
||||
try:
|
||||
val = str(_UUID(uuid_val))
|
||||
except (ValueError, TypeError):
|
||||
# invalid format → 404
|
||||
abort(404)
|
||||
|
||||
# 3) Only return plants owned by current_user
|
||||
return (
|
||||
Plant.query
|
||||
.filter_by(uuid=val, owner_id=current_user.id)
|
||||
.first_or_404()
|
||||
)
|
||||
|
||||
|
||||
def _user_plant_choices():
|
||||
# join to the common‐name table and sort by its name
|
||||
plants = (
|
||||
Plant.query
|
||||
.filter_by(owner_id=current_user.id)
|
||||
.join(PlantCommonName, Plant.common_id == PlantCommonName.id)
|
||||
.order_by(PlantCommonName.name)
|
||||
.all()
|
||||
)
|
||||
return [
|
||||
(p.uuid, f"{p.common_name.name} – {p.uuid}")
|
||||
for p in plants
|
||||
]
|
||||
|
||||
|
||||
@bp.route('/add', methods=['GET','POST'])
|
||||
@bp.route('/<uuid:plant_uuid>/add', methods=['GET','POST'])
|
||||
@login_required
|
||||
def view_logs(plant_id):
|
||||
plant = Plant.query.get_or_404(plant_id)
|
||||
logs = GrowLog.query.filter_by(plant_id=plant.id).order_by(GrowLog.timestamp.desc()).all()
|
||||
return render_template('growlog/log_list.html', plant=plant, logs=logs)
|
||||
|
||||
@bp.route('/plants/<int:plant_id>/logs/add', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def add_log(plant_id):
|
||||
plant = Plant.query.get_or_404(plant_id)
|
||||
def add_log(plant_uuid=None):
|
||||
form = GrowLogForm()
|
||||
# 1) always populate the dropdown behind the scenes
|
||||
form.plant_uuid.choices = _user_plant_choices()
|
||||
|
||||
plant = None
|
||||
hide_select = False
|
||||
|
||||
# 2) if URL had a plant_uuid, load & pre-select it, hide dropdown
|
||||
if plant_uuid:
|
||||
plant = _get_plant_by_uuid(plant_uuid)
|
||||
form.plant_uuid.data = str(plant_uuid)
|
||||
hide_select = True
|
||||
|
||||
if form.validate_on_submit():
|
||||
# 3) on POST, resolve via form.plant_uuid
|
||||
plant = _get_plant_by_uuid(form.plant_uuid.data)
|
||||
log = GrowLog(
|
||||
plant_id=plant.id,
|
||||
event_type=form.event_type.data,
|
||||
note=form.note.data
|
||||
plant_id = plant.id,
|
||||
event_type = form.event_type.data,
|
||||
title = form.title.data,
|
||||
notes = form.notes.data,
|
||||
is_public = form.is_public.data,
|
||||
)
|
||||
db.session.add(log)
|
||||
db.session.commit()
|
||||
return redirect(url_for('growlog.view_logs', plant_id=plant.id))
|
||||
return render_template('growlog/log_form.html', form=form, plant=plant)
|
||||
flash('Grow log added.', 'success')
|
||||
return redirect(
|
||||
url_for('growlog.list_logs', plant_uuid=plant.uuid)
|
||||
)
|
||||
|
||||
return render_template(
|
||||
'growlog/log_form.html',
|
||||
form = form,
|
||||
plant = plant,
|
||||
hide_plant_select = hide_select
|
||||
)
|
||||
|
||||
|
||||
@bp.route('/', defaults={'plant_uuid': None})
|
||||
@bp.route('/<uuid:plant_uuid>')
|
||||
@login_required
|
||||
def list_logs(plant_uuid):
|
||||
# how many to show?
|
||||
limit = request.args.get('limit', default=10, type=int)
|
||||
|
||||
if plant_uuid:
|
||||
# logs for a single plant
|
||||
plant = _get_plant_by_uuid(plant_uuid)
|
||||
query = GrowLog.query.filter_by(plant_id=plant.id)
|
||||
else:
|
||||
# logs for all your plants
|
||||
plant = None
|
||||
query = (
|
||||
GrowLog.query
|
||||
.join(Plant, GrowLog.plant_id == Plant.id)
|
||||
.filter(Plant.owner_id == current_user.id)
|
||||
)
|
||||
|
||||
logs = (
|
||||
query
|
||||
.order_by(GrowLog.created_at.desc())
|
||||
.limit(limit)
|
||||
.all()
|
||||
)
|
||||
|
||||
return render_template(
|
||||
'growlog/log_list.html',
|
||||
plant=plant,
|
||||
logs=logs,
|
||||
limit=limit
|
||||
)
|
||||
|
||||
|
||||
@bp.route('/<uuid:plant_uuid>/edit/<int:log_id>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def edit_log(plant_uuid, log_id):
|
||||
plant = _get_plant_by_uuid(plant_uuid)
|
||||
log = GrowLog.query.filter_by(id=log_id, plant_id=plant.id).first_or_404()
|
||||
form = GrowLogForm(obj=log)
|
||||
|
||||
# Lock the dropdown to this one plant
|
||||
form.plant_uuid.choices = [(plant.uuid, plant.common_name.name)]
|
||||
form.plant_uuid.data = plant.uuid
|
||||
|
||||
if form.validate_on_submit():
|
||||
log.event_type = form.event_type.data
|
||||
log.title = form.title.data
|
||||
log.notes = form.notes.data
|
||||
log.is_public = form.is_public.data
|
||||
db.session.commit()
|
||||
|
||||
flash('Grow log updated.', 'success')
|
||||
return redirect(url_for('growlog.list_logs', plant_uuid=plant_uuid))
|
||||
|
||||
return render_template(
|
||||
'growlog/log_form.html',
|
||||
form=form,
|
||||
plant_uuid=plant_uuid,
|
||||
plant=plant,
|
||||
log=log
|
||||
)
|
||||
|
||||
|
||||
@bp.route('/<uuid:plant_uuid>/delete/<int:log_id>', methods=['POST'])
|
||||
@login_required
|
||||
def delete_log(plant_uuid, log_id):
|
||||
plant = _get_plant_by_uuid(plant_uuid)
|
||||
log = GrowLog.query.filter_by(id=log_id, plant_id=plant.id).first_or_404()
|
||||
db.session.delete(log)
|
||||
db.session.commit()
|
||||
|
||||
flash('Grow log deleted.', 'warning')
|
||||
return redirect(url_for('growlog.list_logs', plant_uuid=plant_uuid))
|
||||
|
@ -1,10 +1,41 @@
|
||||
{% extends 'core_ui/base.html' %}
|
||||
{% block title %}Add Grow Log{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Add Log for Plant #{{ plant.id }}</h2>
|
||||
<form method="POST">
|
||||
{{ form.hidden_tag() }}
|
||||
<p>{{ form.event_type.label }}<br>{{ form.event_type() }}</p>
|
||||
<p>{{ form.note.label }}<br>{{ form.note(rows=4) }}</p>
|
||||
<p>{{ form.submit() }}</p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
<h2>Add Grow Log{% if plant %} for {{ plant.common_name.name }}{% endif %}</h2>
|
||||
<form method="POST">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
{# only show this when not pre-selecting via URL #}
|
||||
{% if not hide_plant_select %}
|
||||
<div class="mb-3">
|
||||
{{ form.plant_uuid.label(class="form-label") }}
|
||||
{{ form.plant_uuid(class="form-select") }}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.plant_uuid(type="hidden") }}
|
||||
{% endif %}
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.event_type.label(class="form-label") }}
|
||||
{{ form.event_type(class="form-select") }}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.title.label(class="form-label") }}
|
||||
{{ form.title(class="form-control") }}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.notes.label(class="form-label") }}
|
||||
{{ form.notes(class="form-control", rows=4) }}
|
||||
</div>
|
||||
|
||||
<div class="mb-3 form-check">
|
||||
{{ form.is_public(class="form-check-input") }}
|
||||
{{ form.is_public.label(class="form-check-label") }}
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">{{ form.submit.label.text }}</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
@ -1,36 +1,104 @@
|
||||
{# plugins/growlog/templates/growlog/log_list.html #}
|
||||
{% import 'core_ui/_media_macros.html' as media %}
|
||||
{% extends 'core_ui/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Logs for Plant #{{ plant.id }}</h2>
|
||||
<a href="{{ url_for('growlog.add_log', plant_id=plant.id) }}">Add New Log</a>
|
||||
|
||||
<ul>
|
||||
{% for log in logs %}
|
||||
<li class="mb-3">
|
||||
<strong>{{ log.timestamp.strftime('%Y-%m-%d') }}:</strong>
|
||||
{{ log.event_type }} – {{ log.note }}
|
||||
{% if log.media_items %}
|
||||
<br><em>Images:</em>
|
||||
<ul class="list-unstyled ps-3">
|
||||
{% for image in log.media_items %}
|
||||
<li class="mb-2">
|
||||
<img
|
||||
src="{{ generate_image_url(image) }}"
|
||||
width="150"
|
||||
class="img-thumbnail"
|
||||
alt="Log image"
|
||||
><br>
|
||||
{{ image.caption or "No caption" }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{# Use shared macro for any remaining media lists #}
|
||||
{{ media.render_media_list(logs|map(attribute='media_items')|sum, thumb_width=150, current_user=current_user) }}
|
||||
{% block title %}
|
||||
{% if plant %}
|
||||
Logs for {{ plant.common_name.name }}
|
||||
{% else %}
|
||||
Recent Grow Logs
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h2 class="mb-0">
|
||||
{% if plant %}
|
||||
Grow Logs for {{ plant.common_name.name }}
|
||||
{% else %}
|
||||
Recent Grow Logs
|
||||
{% endif %}
|
||||
</h2>
|
||||
{# “Add” button: carry plant_uuid when in single-plant view #}
|
||||
<a
|
||||
href="{% if plant %}{{ url_for('growlog.add_log', plant_uuid=plant.uuid) }}{% else %}{{ url_for('growlog.add_log') }}{% endif %}"
|
||||
class="btn btn-success">
|
||||
<i class="bi bi-plus-lg"></i> Add Log
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if logs %}
|
||||
<div class="list-group">
|
||||
{% for log in logs %}
|
||||
<div class="list-group-item mb-3">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div>
|
||||
<h5 class="mb-1">{{ log.title or 'Untitled' }}</h5>
|
||||
<small class="text-muted">
|
||||
{{ log.created_at.strftime('%Y-%m-%d %H:%M') }}
|
||||
</small>
|
||||
</div>
|
||||
{% if not plant %}
|
||||
{# Show which plant this log belongs to when listing across all plants #}
|
||||
<div class="ms-auto text-end">
|
||||
<small class="text-secondary">Plant:</small><br>
|
||||
<a href="{{ url_for('growlog.list_logs', plant_uuid=log.plant.uuid) }}">
|
||||
{{ log.plant.common_name.name }}
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<p class="mt-2 mb-1">{{ log.notes or '—' }}</p>
|
||||
|
||||
<span class="badge {% if log.is_public %}bg-info text-dark{% else %}bg-secondary{% endif %}">
|
||||
{% if log.is_public %}Public{% else %}Private{% endif %}
|
||||
</span>
|
||||
|
||||
{% if log.media_items.count() %}
|
||||
<div class="mt-3 d-flex flex-wrap gap-2">
|
||||
{% for media in log.media_items %}
|
||||
<img
|
||||
src="{{ generate_image_url(media) }}"
|
||||
class="img-thumbnail"
|
||||
style="max-width:100px;"
|
||||
alt="{{ media.caption or '' }}"
|
||||
>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="mt-3">
|
||||
<a
|
||||
href="{{ url_for(
|
||||
'growlog.edit_log',
|
||||
plant_uuid=plant.uuid if plant else log.plant.uuid,
|
||||
log_id=log.id
|
||||
) }}"
|
||||
class="btn btn-sm btn-outline-primary me-2">
|
||||
Edit
|
||||
</a>
|
||||
<form
|
||||
method="POST"
|
||||
action="{{ url_for(
|
||||
'growlog.delete_log',
|
||||
plant_uuid=plant.uuid if plant else log.plant.uuid,
|
||||
log_id=log.id
|
||||
) }}"
|
||||
class="d-inline"
|
||||
onsubmit="return confirm('Delete this log?');">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button class="btn btn-sm btn-outline-danger">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-muted">
|
||||
No grow logs found{% if plant %} for {{ plant.common_name.name }}{% endif %}.
|
||||
<a href="{% if plant %}{{ url_for('growlog.add_log', plant_uuid=plant.uuid) }}{% else %}{{ url_for('growlog.add_log') }}{% endif %}">
|
||||
Add one now
|
||||
</a>.
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
@ -40,44 +40,74 @@ def inject_image_helper():
|
||||
@bp.route('/', methods=['GET'])
|
||||
@login_required
|
||||
def index():
|
||||
plants = (
|
||||
# ── 1) Read query-params ───────────────────────────────────────────
|
||||
page = request.args.get('page', 1, type=int)
|
||||
per_page = request.args.get(
|
||||
'per_page',
|
||||
current_app.config.get('PLANTS_PER_PAGE', 12),
|
||||
type=int
|
||||
)
|
||||
view_mode = request.args.get('view', 'grid', type=str) # 'grid' or 'list'
|
||||
q = request.args.get('q', '', type=str).strip()
|
||||
type_filter= request.args.get('type', '', type=str).strip().lower()
|
||||
|
||||
# ── 2) Build base SQLAlchemy query ────────────────────────────────
|
||||
qry = (
|
||||
Plant.query
|
||||
.options(joinedload(Plant.media_items))
|
||||
.filter_by(owner_id=current_user.id)
|
||||
.order_by(Plant.id.desc())
|
||||
.all()
|
||||
.options(joinedload(Plant.media_items))
|
||||
.filter_by(owner_id=current_user.id)
|
||||
)
|
||||
|
||||
user_plants_count = Plant.query.filter_by(owner_id=current_user.id).count()
|
||||
user_images_count = Media.query.filter_by(uploader_id=current_user.id).count()
|
||||
total_plants_count = Plant.query.count()
|
||||
total_images_count = Media.query.count()
|
||||
# ── 3) Optional name search ───────────────────────────────────────
|
||||
if q:
|
||||
qry = qry.join(PlantCommonName).filter(
|
||||
PlantCommonName.name.ilike(f'%{q}%')
|
||||
)
|
||||
|
||||
# ── 4) Optional type filter ───────────────────────────────────────
|
||||
if type_filter:
|
||||
qry = qry.filter(Plant.plant_type.ilike(type_filter))
|
||||
|
||||
# ── 5) Apply ordering + paginate ─────────────────────────────────
|
||||
pagination = (
|
||||
qry.order_by(Plant.id.desc())
|
||||
.paginate(page=page, per_page=per_page, error_out=False)
|
||||
)
|
||||
plants = pagination.items
|
||||
|
||||
# ── 6) Gather stats and distinct types as before ─────────────────
|
||||
stats = {
|
||||
'user_plants': Plant.query.filter_by(owner_id=current_user.id).count(),
|
||||
'user_images': Media.query.filter_by(uploader_id=current_user.id).count(),
|
||||
'total_plants': Plant.query.count(),
|
||||
'total_images': Media.query.count(),
|
||||
}
|
||||
|
||||
plant_types = [
|
||||
pt[0]
|
||||
for pt in (
|
||||
db.session.query(Plant.plant_type)
|
||||
.filter_by(owner_id=current_user.id)
|
||||
.distinct()
|
||||
.all()
|
||||
row[0]
|
||||
for row in (
|
||||
db.session
|
||||
.query(Plant.plant_type)
|
||||
.filter_by(owner_id=current_user.id)
|
||||
.distinct()
|
||||
.all()
|
||||
)
|
||||
]
|
||||
|
||||
stats = {
|
||||
'user_plants': user_plants_count,
|
||||
'user_images': user_images_count,
|
||||
'total_plants': total_plants_count,
|
||||
'total_images': total_images_count,
|
||||
}
|
||||
|
||||
# ── 7) Render, passing both pagination AND per-page items ─────────
|
||||
return render_template(
|
||||
'plant/index.html',
|
||||
plants=plants,
|
||||
plant_types=plant_types,
|
||||
stats=stats,
|
||||
plants = plants,
|
||||
pagination = pagination,
|
||||
view_mode = view_mode,
|
||||
q = q,
|
||||
type_filter = type_filter,
|
||||
per_page = per_page,
|
||||
plant_types = plant_types,
|
||||
stats = stats
|
||||
)
|
||||
|
||||
@bp.route('/', methods=['GET', 'POST'])
|
||||
@bp.route('/create', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def create():
|
||||
form = PlantForm()
|
||||
|
@ -14,7 +14,114 @@
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<!-- Stats container (desktop only, collapsed by default) -->
|
||||
<h2 class="mb-4">View Entries</h2>
|
||||
|
||||
{# ── Import / Export, Stats, Filters & View Toggle ─────────────────────── #}
|
||||
<div class="mb-3 d-flex flex-wrap justify-content-between align-items-center">
|
||||
<!-- Left: import/export & stats toggle -->
|
||||
<div class="d-flex align-items-center mb-2">
|
||||
<button class="btn btn-primary me-2" data-bs-toggle="modal" data-bs-target="#importModal">
|
||||
Import CSV
|
||||
</button>
|
||||
<a href="{{ url_for('utility.export_data') }}" class="btn btn-secondary me-2">
|
||||
Export My Data
|
||||
</a>
|
||||
<button
|
||||
class="btn btn-secondary me-2 d-inline-block d-md-none"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#statsModal">
|
||||
Stats
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-secondary me-2 d-none d-md-inline-block"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#statsBox"
|
||||
aria-expanded="false"
|
||||
aria-controls="statsBox"
|
||||
id="statsToggle">
|
||||
Stats <i class="bi bi-chevron-down"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Right: filter form + view toggle -->
|
||||
<form
|
||||
method="get"
|
||||
action="{{ url_for('plant.index') }}"
|
||||
class="d-flex flex-wrap align-items-center mb-2"
|
||||
>
|
||||
<div class="input-group me-2" style="min-width:200px;">
|
||||
<span class="input-group-text">Search</span>
|
||||
<input
|
||||
type="search"
|
||||
name="q"
|
||||
value="{{ q }}"
|
||||
class="form-control"
|
||||
placeholder="by name…"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<select
|
||||
name="type"
|
||||
class="form-select me-2"
|
||||
style="min-width:140px;"
|
||||
onchange="this.form.submit()"
|
||||
>
|
||||
<option value="">All Types</option>
|
||||
{% for t in plant_types %}
|
||||
<option
|
||||
value="{{ t|lower }}"
|
||||
{% if t|lower == type_filter %}selected{% endif %}
|
||||
>{{ t }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
<select
|
||||
name="per_page"
|
||||
class="form-select me-2"
|
||||
style="min-width:140px;"
|
||||
onchange="this.form.submit()"
|
||||
>
|
||||
{% for size in [6,12,18,24] %}
|
||||
<option value="{{ size }}" {% if per_page == size %}selected{% endif %}>
|
||||
{{ size }} per page
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
{# keep the current view so Apply doesn’t reset it #}
|
||||
<input type="hidden" name="view" value="{{ view_mode }}" />
|
||||
|
||||
<button type="submit" class="btn btn-primary me-2">Apply</button>
|
||||
|
||||
<div class="btn-group" role="group" aria-label="View mode">
|
||||
<a
|
||||
href="{{ url_for('plant.index',
|
||||
page=pagination.page,
|
||||
per_page=per_page,
|
||||
q=q,
|
||||
type=type_filter,
|
||||
view='grid'
|
||||
) }}"
|
||||
class="btn btn-outline-secondary {% if view_mode=='grid' %}active{% endif %}"
|
||||
title="Card View"
|
||||
><i class="bi bi-grid-3x3-gap-fill"></i></a>
|
||||
|
||||
<a
|
||||
href="{{ url_for('plant.index',
|
||||
page=pagination.page,
|
||||
per_page=per_page,
|
||||
q=q,
|
||||
type=type_filter,
|
||||
view='list'
|
||||
) }}"
|
||||
class="btn btn-outline-secondary {% if view_mode=='list' %}active{% endif %}"
|
||||
title="List View"
|
||||
><i class="bi bi-list-ul"></i></a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Stats container (desktop only) -->
|
||||
<div class="collapse mb-3" id="statsBox">
|
||||
<div class="d-none d-md-block p-3 bg-light border rounded">
|
||||
<h5 class="text-center">Statistics</h5>
|
||||
@ -95,214 +202,168 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>View Entries</h2>
|
||||
|
||||
<!-- Import / Export & Filter bar -->
|
||||
<div class="mb-3 d-flex flex-wrap justify-content-between align-items-center">
|
||||
<div class="mb-2 d-flex align-items-center">
|
||||
<button class="btn btn-primary me-2" data-bs-toggle="modal" data-bs-target="#importModal">
|
||||
Import CSV
|
||||
</button>
|
||||
<a href="{{ url_for('utility.export_data') }}" class="btn btn-secondary me-2">Export My Data</a>
|
||||
<button
|
||||
class="btn btn-secondary me-2 d-inline-block d-md-none"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#statsModal">
|
||||
Stats
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-secondary me-2 d-none d-md-inline-block"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#statsBox"
|
||||
aria-expanded="false"
|
||||
aria-controls="statsBox"
|
||||
id="statsToggle">
|
||||
Stats <i class="bi bi-chevron-down"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="d-flex flex-wrap flex-md-nowrap align-items-center">
|
||||
<div class="input-group me-2 mb-2 mb-md-0" style="min-width:200px;">
|
||||
<span class="input-group-text">Search</span>
|
||||
<input id="searchInput" type="text" class="form-control" placeholder="by name…">
|
||||
</div>
|
||||
<select id="typeFilter" class="form-select me-2 mb-2 mb-md-0" style="min-width:140px;">
|
||||
<option value="">All Types</option>
|
||||
{% for t in plant_types %}
|
||||
<option value="{{ t|lower }}">{{ t }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="pageSizeSelect" class="form-select me-2 mb-2 mb-md-0" style="min-width:140px;">
|
||||
{% for size in [6,12,18,24] %}
|
||||
<option value="{{ size }}" {% if size == 12 %}selected{% endif %}>
|
||||
{{ size }} per page
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Plant cards -->
|
||||
<div class="row row-cols-1 row-cols-lg-3 g-3" id="plantContainer">
|
||||
{% for plant in plants %}
|
||||
<div class="col plant-card"
|
||||
data-name="{{ plant.common_name.name|lower }}"
|
||||
data-type="{{ plant.plant_type|lower }}">
|
||||
<div class="card h-100">
|
||||
{# Determine featured image: first any marked featured, else first media #}
|
||||
{% set featured = plant.media|selectattr('featured')|first %}
|
||||
{% if not featured and plant.media %}
|
||||
{% set featured = plant.media[0] %}
|
||||
{% endif %}
|
||||
|
||||
<a href="{{ url_for('plant.detail', uuid_val=plant.uuid) }}">
|
||||
<img
|
||||
src="{{ generate_image_url(featured) }}"
|
||||
class="card-img-top"
|
||||
style="height:200px;object-fit:cover;"
|
||||
alt="Image for {{ plant.common_name.name }}">
|
||||
</a>
|
||||
|
||||
<div class="card-body d-flex flex-column">
|
||||
<h5 class="card-title">
|
||||
{# ── Results (list vs grid) ──────────────────────────────────────────── #}
|
||||
{% if view_mode=='list' %}
|
||||
<div class="list-group">
|
||||
{% for plant in plants %}
|
||||
<div class="list-group-item py-3">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-auto">
|
||||
{%- set f = (plant.media_items|selectattr('featured')|first)
|
||||
or (plant.media_items|first) -%}
|
||||
<a href="{{ url_for('plant.detail', uuid_val=plant.uuid) }}">
|
||||
{{ plant.common_name.name }}
|
||||
<img
|
||||
src="{{ generate_image_url(f) }}"
|
||||
class="img-thumbnail"
|
||||
style="width:80px;height:80px;object-fit:cover;"
|
||||
alt="Image for {{ plant.common_name.name }}"
|
||||
>
|
||||
</a>
|
||||
</h5>
|
||||
<h6 class="text-muted">{{ plant.uuid }}</h6>
|
||||
<p class="mb-1"><strong>Type:</strong> {{ plant.plant_type }}</p>
|
||||
<p class="mb-1"><strong>Scientific Name:</strong> {{ plant.scientific_name.name }}</p>
|
||||
{% if plant.mother_uuid %}
|
||||
<p class="mb-1">
|
||||
<strong>Mother:</strong>
|
||||
<a href="{{ url_for('plant.detail', uuid_val=plant.mother_uuid) }}">
|
||||
{{ plant.mother_uuid }}
|
||||
</div>
|
||||
<div class="col">
|
||||
<h5 class="mb-1">
|
||||
<a href="{{ url_for('plant.detail', uuid_val=plant.uuid) }}">
|
||||
{{ plant.common_name.name }}
|
||||
</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<div class="mt-auto">
|
||||
<a href="{{ url_for('plant.detail', uuid_val=plant.uuid) }}"
|
||||
class="btn btn-sm btn-primary me-1">View</a>
|
||||
<a href="{{ url_for('plant.edit', uuid_val=plant.uuid) }}"
|
||||
class="btn btn-sm btn-secondary me-1">Edit</a>
|
||||
<a href="{{ url_for('utility.download_qr', uuid_val=plant.uuid) }}"
|
||||
class="btn btn-sm btn-outline-primary me-1">Direct QR</a>
|
||||
<a href="{{ url_for('utility.download_qr_card', uuid_val=plant.uuid) }}"
|
||||
class="btn btn-sm btn-outline-secondary">Card QR</a>
|
||||
</h5>
|
||||
<small class="text-muted">{{ plant.uuid }}</small>
|
||||
<div class="mt-1">
|
||||
<span class="badge bg-secondary">{{ plant.plant_type }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto text-nowrap">
|
||||
<a
|
||||
href="{{ url_for('plant.detail', uuid_val=plant.uuid) }}"
|
||||
class="btn btn-sm btn-primary me-1"
|
||||
>View</a>
|
||||
<a
|
||||
href="{{ url_for('plant.edit', uuid_val=plant.uuid) }}"
|
||||
class="btn btn-sm btn-secondary"
|
||||
>Edit</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
|
||||
{% for plant in plants %}
|
||||
<div class="col">
|
||||
<div class="card h-100">
|
||||
{%- set f = (plant.media_items|selectattr('featured')|first)
|
||||
or (plant.media_items|first) -%}
|
||||
<a href="{{ url_for('plant.detail', uuid_val=plant.uuid) }}">
|
||||
<img
|
||||
src="{{ generate_image_url(f) }}"
|
||||
class="card-img-top"
|
||||
style="height:200px;object-fit:cover;"
|
||||
alt="Image for {{ plant.common_name.name }}"
|
||||
>
|
||||
</a>
|
||||
<div class="card-body d-flex flex-column">
|
||||
<h5 class="card-title mb-1">
|
||||
<a href="{{ url_for('plant.detail', uuid_val=plant.uuid) }}">
|
||||
{{ plant.common_name.name }}
|
||||
</a>
|
||||
</h5>
|
||||
<small class="text-muted mb-2">{{ plant.uuid }}</small>
|
||||
<div class="mt-auto">
|
||||
<a
|
||||
href="{{ url_for('plant.detail', uuid_val=plant.uuid) }}"
|
||||
class="btn btn-sm btn-primary me-1"
|
||||
>View</a>
|
||||
<a
|
||||
href="{{ url_for('plant.edit', uuid_val=plant.uuid) }}"
|
||||
class="btn btn-sm btn-secondary"
|
||||
>Edit</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- pagination controls -->
|
||||
<nav aria-label="Page navigation" class="mt-4 mb-5">
|
||||
<ul class="pagination justify-content-center" id="pagination"></ul>
|
||||
{# ── Pagination ─────────────────────────────────────────────────────── #}
|
||||
<nav aria-label="Page navigation" class="mt-4">
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item {% if not pagination.has_prev %}disabled{% endif %}">
|
||||
<a
|
||||
class="page-link"
|
||||
href="{{ url_for('plant.index',
|
||||
page=1,
|
||||
per_page=per_page,
|
||||
q=q,
|
||||
type=type_filter,
|
||||
view=view_mode
|
||||
) }}"
|
||||
>« First</a>
|
||||
</li>
|
||||
<li class="page-item {% if not pagination.has_prev %}disabled{% endif %}">
|
||||
<a
|
||||
class="page-link"
|
||||
href="{{ url_for('plant.index',
|
||||
page=pagination.prev_num or 1,
|
||||
per_page=per_page,
|
||||
q=q,
|
||||
type=type_filter,
|
||||
view=view_mode
|
||||
) }}"
|
||||
>‹ Prev</a>
|
||||
</li>
|
||||
|
||||
{% set total = pagination.pages %}
|
||||
{% set curr = pagination.page %}
|
||||
{% set w = 3 %}
|
||||
{% for p in range(1, total+1) %}
|
||||
{% if p <= w or p > total-w or (p >= curr-1 and p <= curr+1) %}
|
||||
<li class="page-item {% if p==curr %}active{% endif %}">
|
||||
<a
|
||||
class="page-link"
|
||||
href="{{ url_for('plant.index',
|
||||
page=p,
|
||||
per_page=per_page,
|
||||
q=q,
|
||||
type=type_filter,
|
||||
view=view_mode
|
||||
) }}"
|
||||
>{{ p }}</a>
|
||||
</li>
|
||||
{% elif p == w+1 or p == total-w %}
|
||||
<li class="page-item disabled"><span class="page-link">…</span></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
<li class="page-item {% if not pagination.has_next %}disabled{% endif %}">
|
||||
<a
|
||||
class="page-link"
|
||||
href="{{ url_for('plant.index',
|
||||
page=pagination.next_num or total,
|
||||
per_page=per_page,
|
||||
q=q,
|
||||
type=type_filter,
|
||||
view=view_mode
|
||||
) }}"
|
||||
>Next ›</a>
|
||||
</li>
|
||||
<li class="page-item {% if not pagination.has_next %}disabled{% endif %}">
|
||||
<a
|
||||
class="page-link"
|
||||
href="{{ url_for('plant.index',
|
||||
page=total,
|
||||
per_page=per_page,
|
||||
q=q,
|
||||
type=type_filter,
|
||||
view=view_mode
|
||||
) }}"
|
||||
>Last »</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
{% endblock %}
|
||||
|
||||
<!-- client-side filtering & pagination script -->
|
||||
<script>
|
||||
(function() {
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
const typeFilter = document.getElementById('typeFilter');
|
||||
const pageSizeSelect = document.getElementById('pageSizeSelect');
|
||||
const container = document.getElementById('plantContainer');
|
||||
const pagination = document.getElementById('pagination');
|
||||
const cards = Array.from(container.querySelectorAll('.plant-card'));
|
||||
let currentPage = 1;
|
||||
let pageSize = parseInt(pageSizeSelect.value, 10);
|
||||
|
||||
function filterAndPaginate() {
|
||||
const q = searchInput.value.trim().toLowerCase();
|
||||
const type = typeFilter.value;
|
||||
const filtered = cards.filter(card => {
|
||||
return card.dataset.name.includes(q) &&
|
||||
(!type || card.dataset.type === type);
|
||||
});
|
||||
|
||||
const totalPages = Math.max(1, Math.ceil(filtered.length / pageSize));
|
||||
if (currentPage > totalPages) currentPage = totalPages;
|
||||
|
||||
cards.forEach(c => c.style.display = 'none');
|
||||
const start = (currentPage - 1) * pageSize;
|
||||
filtered.slice(start, start + pageSize)
|
||||
.forEach(c => c.style.display = '');
|
||||
|
||||
pagination.innerHTML = '';
|
||||
|
||||
// Prev button
|
||||
const prevLi = document.createElement('li');
|
||||
prevLi.className = 'page-item' + (currentPage === 1 ? ' disabled' : '');
|
||||
prevLi.innerHTML = `<a class="page-link" href="#">Prev</a>`;
|
||||
prevLi.onclick = e => {
|
||||
e.preventDefault();
|
||||
if (currentPage > 1) { currentPage--; filterAndPaginate(); }
|
||||
};
|
||||
pagination.appendChild(prevLi);
|
||||
|
||||
// Page numbers
|
||||
if (totalPages <= 5) {
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
const li = document.createElement('li');
|
||||
li.className = 'page-item' + (i === currentPage ? ' active' : '');
|
||||
li.innerHTML = `<a class="page-link" href="#">${i}</a>`;
|
||||
li.onclick = e => {
|
||||
e.preventDefault();
|
||||
currentPage = i;
|
||||
filterAndPaginate();
|
||||
};
|
||||
pagination.appendChild(li);
|
||||
}
|
||||
} else {
|
||||
[1,2,3].forEach(n => {
|
||||
const li = document.createElement('li');
|
||||
li.className = 'page-item' + (n === currentPage ? ' active' : '');
|
||||
li.innerHTML = `<a class="page-link" href="#">${n}</a>`;
|
||||
li.onclick = e => {
|
||||
e.preventDefault();
|
||||
currentPage = n;
|
||||
filterAndPaginate();
|
||||
};
|
||||
pagination.appendChild(li);
|
||||
});
|
||||
const ell = document.createElement('li');
|
||||
ell.className = 'page-item disabled';
|
||||
ell.innerHTML = `<span class="page-link">…</span>`;
|
||||
pagination.appendChild(ell);
|
||||
const lastLi = document.createElement('li');
|
||||
lastLi.className = 'page-item' + (totalPages === currentPage ? ' active' : '');
|
||||
lastLi.innerHTML = `<a class="page-link" href="#">${totalPages}</a>`;
|
||||
lastLi.onclick = e => {
|
||||
e.preventDefault();
|
||||
currentPage = totalPages;
|
||||
filterAndPaginate();
|
||||
};
|
||||
pagination.appendChild(lastLi);
|
||||
}
|
||||
|
||||
// Next button
|
||||
const nextLi = document.createElement('li');
|
||||
nextLi.className = 'page-item' + (currentPage === totalPages ? ' disabled' : '');
|
||||
nextLi.innerHTML = `<a class="page-link" href="#">Next</a>`;
|
||||
nextLi.onclick = e => {
|
||||
e.preventDefault();
|
||||
if (currentPage < totalPages) { currentPage++; filterAndPaginate(); }
|
||||
};
|
||||
pagination.appendChild(nextLi);
|
||||
}
|
||||
|
||||
// Initialize and bind events
|
||||
filterAndPaginate();
|
||||
searchInput.addEventListener('input', () => { currentPage = 1; filterAndPaginate(); });
|
||||
typeFilter.addEventListener('change', () => { currentPage = 1; filterAndPaginate(); });
|
||||
pageSizeSelect.addEventListener('change',() => {
|
||||
pageSize = parseInt(pageSizeSelect.value, 10);
|
||||
currentPage = 1; filterAndPaginate();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
{% block scripts %}
|
||||
{{ super() }}
|
||||
<script>
|
||||
// Toggle chevron icon on desktop collapse
|
||||
const statsBox = document.getElementById('statsBox');
|
||||
|
Reference in New Issue
Block a user