feat: add shared task assignments and quick win sorting
This commit is contained in:
@@ -76,7 +76,7 @@ def create_app(config_class: type[Config] = Config) -> Flask:
|
||||
(key, values["label"])
|
||||
for key, values in quick_task_config.items()
|
||||
]
|
||||
quick_wins = QuickWin.query.filter_by(active=True).order_by(QuickWin.id.asc()).all()
|
||||
quick_wins = QuickWin.query.filter_by(active=True).order_by(QuickWin.sort_order.asc(), QuickWin.id.asc()).all()
|
||||
def asset_version(filename: str) -> int:
|
||||
path = Path(app.static_folder) / filename
|
||||
try:
|
||||
|
||||
@@ -48,6 +48,7 @@ class TaskForm(FlaskForm):
|
||||
description = TextAreaField("Beschreibung", validators=[Optional(), Length(max=2000)])
|
||||
default_points = IntegerField("Punkte", validators=[DataRequired(), NumberRange(min=1, max=500)], default=10)
|
||||
assigned_user_id = SelectField("Zugewiesen an", coerce=int, validators=[DataRequired()])
|
||||
assigned_user_secondary_id = SelectField("Zweite Person", coerce=int, validators=[Optional()], default=0)
|
||||
due_date = DateField("Fälligkeitsdatum", format="%Y-%m-%d", validators=[DataRequired()])
|
||||
recurrence_interval_value = IntegerField(
|
||||
"Intervallwert",
|
||||
@@ -74,6 +75,9 @@ class TaskForm(FlaskForm):
|
||||
if self.recurrence_interval_unit.data != "none" and not self.recurrence_interval_value.data:
|
||||
self.recurrence_interval_value.errors.append("Bitte gib einen Intervallwert an.")
|
||||
return False
|
||||
if self.assigned_user_secondary_id.data and self.assigned_user_secondary_id.data == self.assigned_user_id.data:
|
||||
self.assigned_user_secondary_id.errors.append("Bitte wähle hier eine andere Person oder keine zweite Person.")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -35,12 +35,24 @@ class User(UserMixin, TimestampMixin, db.Model):
|
||||
backref="default_assigned_user",
|
||||
lazy=True,
|
||||
)
|
||||
secondary_assigned_task_templates = db.relationship(
|
||||
"TaskTemplate",
|
||||
foreign_keys="TaskTemplate.default_assigned_user_secondary_id",
|
||||
backref="default_assigned_user_secondary",
|
||||
lazy=True,
|
||||
)
|
||||
assigned_tasks = db.relationship(
|
||||
"TaskInstance",
|
||||
foreign_keys="TaskInstance.assigned_user_id",
|
||||
backref="assigned_user",
|
||||
lazy=True,
|
||||
)
|
||||
secondary_assigned_tasks = db.relationship(
|
||||
"TaskInstance",
|
||||
foreign_keys="TaskInstance.assigned_user_secondary_id",
|
||||
backref="assigned_user_secondary",
|
||||
lazy=True,
|
||||
)
|
||||
completed_tasks = db.relationship(
|
||||
"TaskInstance",
|
||||
foreign_keys="TaskInstance.completed_by_user_id",
|
||||
@@ -87,6 +99,7 @@ class TaskTemplate(TimestampMixin, db.Model):
|
||||
description = db.Column(db.Text, nullable=True)
|
||||
default_points = db.Column(db.Integer, nullable=False, default=10)
|
||||
default_assigned_user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=True)
|
||||
default_assigned_user_secondary_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=True)
|
||||
recurrence_interval_value = db.Column(db.Integer, nullable=True)
|
||||
recurrence_interval_unit = db.Column(db.String(20), nullable=False, default="none")
|
||||
active = db.Column(db.Boolean, nullable=False, default=True)
|
||||
@@ -113,6 +126,7 @@ class QuickWin(TimestampMixin, db.Model):
|
||||
effort = db.Column(db.String(40), nullable=False, index=True)
|
||||
active = db.Column(db.Boolean, nullable=False, default=True)
|
||||
created_by_user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False, index=True)
|
||||
sort_order = db.Column(db.Integer, nullable=False, default=0, index=True)
|
||||
|
||||
|
||||
class TaskInstance(TimestampMixin, db.Model):
|
||||
@@ -121,6 +135,7 @@ class TaskInstance(TimestampMixin, db.Model):
|
||||
title = db.Column(db.String(160), nullable=False)
|
||||
description = db.Column(db.Text, nullable=True)
|
||||
assigned_user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=True, index=True)
|
||||
assigned_user_secondary_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=True, index=True)
|
||||
due_date = db.Column(db.Date, nullable=False, index=True)
|
||||
status = db.Column(db.String(20), nullable=False, default="open", index=True)
|
||||
completed_at = db.Column(db.DateTime, nullable=True, index=True)
|
||||
@@ -131,21 +146,50 @@ class TaskInstance(TimestampMixin, db.Model):
|
||||
def is_completed(self) -> bool:
|
||||
return self.completed_at is not None
|
||||
|
||||
@property
|
||||
def assigned_users(self) -> list[User]:
|
||||
users: list[User] = []
|
||||
if self.assigned_user:
|
||||
users.append(self.assigned_user)
|
||||
if self.assigned_user_secondary and self.assigned_user_secondary.id not in {user.id for user in users}:
|
||||
users.append(self.assigned_user_secondary)
|
||||
return users
|
||||
|
||||
@property
|
||||
def assigned_user_ids(self) -> list[int]:
|
||||
return [user.id for user in self.assigned_users]
|
||||
|
||||
@property
|
||||
def is_shared_assignment(self) -> bool:
|
||||
return self.assigned_user_id is not None and self.assigned_user_secondary_id is not None
|
||||
|
||||
@property
|
||||
def assignee_label(self) -> str:
|
||||
if not self.assigned_users:
|
||||
return "Ohne Person"
|
||||
return " & ".join(user.name for user in self.assigned_users)
|
||||
|
||||
def compute_status(self, reference_date: date | None = None) -> str:
|
||||
reference_date = reference_date or date.today()
|
||||
if self.completed_at:
|
||||
return "completed"
|
||||
if self.due_date < reference_date:
|
||||
return "overdue"
|
||||
if self.due_date <= reference_date + timedelta(days=2):
|
||||
return "soon"
|
||||
if self.due_date == reference_date:
|
||||
return "due_today"
|
||||
if self.due_date == reference_date + timedelta(days=1):
|
||||
return "due_tomorrow"
|
||||
if self.due_date == reference_date + timedelta(days=2):
|
||||
return "due_day_after_tomorrow"
|
||||
return "open"
|
||||
|
||||
@property
|
||||
def status_label(self) -> str:
|
||||
labels = {
|
||||
"open": "Offen",
|
||||
"soon": "Bald fällig",
|
||||
"due_today": "Bald fällig",
|
||||
"due_tomorrow": "Morgen fällig",
|
||||
"due_day_after_tomorrow": "Übermorgen fällig",
|
||||
"overdue": "Überfällig",
|
||||
"completed": "Erledigt",
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ from uuid import uuid4
|
||||
|
||||
from flask import Blueprint, current_app, flash, jsonify, redirect, render_template, request, url_for
|
||||
from flask_login import current_user, login_required
|
||||
from sqlalchemy import func
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from ..extensions import csrf, db
|
||||
@@ -109,6 +110,7 @@ def quick_wins():
|
||||
effort=quick_win_form.effort.data,
|
||||
active=True,
|
||||
created_by_user_id=current_user.id,
|
||||
sort_order=(db.session.query(func.max(QuickWin.sort_order)).scalar() or -1) + 1,
|
||||
)
|
||||
db.session.add(quick_win)
|
||||
db.session.commit()
|
||||
@@ -120,7 +122,7 @@ def quick_wins():
|
||||
quick_win_form=quick_win_form,
|
||||
quick_task_config_form=quick_task_config_form,
|
||||
quick_task_config=quick_task_config,
|
||||
quick_wins=QuickWin.query.filter_by(active=True).order_by(QuickWin.id.asc()).all(),
|
||||
quick_wins=QuickWin.query.filter_by(active=True).order_by(QuickWin.sort_order.asc(), QuickWin.id.asc()).all(),
|
||||
settings_tabs=_settings_tabs(),
|
||||
active_settings_tab="settings.quick_wins",
|
||||
)
|
||||
@@ -268,6 +270,31 @@ def update_quick_win(quick_win_id: int):
|
||||
return redirect(url_for("settings.quick_wins"))
|
||||
|
||||
|
||||
@bp.route("/quick-wins/reorder", methods=["POST"])
|
||||
@login_required
|
||||
@csrf.exempt
|
||||
def reorder_quick_wins():
|
||||
payload = request.get_json(silent=True) or {}
|
||||
raw_ids = payload.get("ids", [])
|
||||
ordered_ids = [int(item) for item in raw_ids if str(item).isdigit()]
|
||||
|
||||
quick_wins = QuickWin.query.filter_by(active=True).all()
|
||||
quick_wins_by_id = {quick_win.id: quick_win for quick_win in quick_wins}
|
||||
|
||||
for position, quick_win_id in enumerate(ordered_ids):
|
||||
quick_win = quick_wins_by_id.get(quick_win_id)
|
||||
if quick_win:
|
||||
quick_win.sort_order = position
|
||||
|
||||
used_ids = set(ordered_ids)
|
||||
remaining = [quick_win for quick_win in quick_wins if quick_win.id not in used_ids]
|
||||
for offset, quick_win in enumerate(sorted(remaining, key=lambda item: (item.sort_order, item.id)), start=len(ordered_ids)):
|
||||
quick_win.sort_order = offset
|
||||
|
||||
db.session.commit()
|
||||
return jsonify({"ok": True})
|
||||
|
||||
|
||||
@bp.route("/users/<int:user_id>/toggle-admin", methods=["POST"])
|
||||
@login_required
|
||||
def toggle_admin(user_id: int):
|
||||
@@ -308,7 +335,9 @@ def delete_user(user_id: int):
|
||||
return redirect(url_for("settings.index"))
|
||||
|
||||
TaskTemplate.query.filter_by(default_assigned_user_id=user.id).update({"default_assigned_user_id": None})
|
||||
TaskTemplate.query.filter_by(default_assigned_user_secondary_id=user.id).update({"default_assigned_user_secondary_id": None})
|
||||
TaskInstance.query.filter_by(assigned_user_id=user.id).update({"assigned_user_id": None})
|
||||
TaskInstance.query.filter_by(assigned_user_secondary_id=user.id).update({"assigned_user_secondary_id": None})
|
||||
TaskInstance.query.filter_by(completed_by_user_id=user.id).update({"completed_by_user_id": None})
|
||||
MonthlyScoreSnapshot.query.filter_by(user_id=user.id).delete()
|
||||
NotificationLog.query.filter_by(user_id=user.id).delete()
|
||||
|
||||
@@ -6,6 +6,7 @@ from datetime import date
|
||||
|
||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
||||
from flask_login import current_user, login_required
|
||||
from sqlalchemy import or_
|
||||
|
||||
from ..forms import QuickTaskForm, TaskForm
|
||||
from ..models import QuickWin, TaskInstance, User
|
||||
@@ -28,22 +29,44 @@ def _user_choices() -> list[tuple[int, str]]:
|
||||
return [(user.id, user.name) for user in User.query.order_by(User.name.asc()).all()]
|
||||
|
||||
|
||||
def _secondary_user_choices() -> list[tuple[int, str]]:
|
||||
return [(0, "Keine zweite Person")] + _user_choices()
|
||||
|
||||
|
||||
@bp.route("/my-tasks")
|
||||
@login_required
|
||||
def my_tasks():
|
||||
tasks = (
|
||||
TaskInstance.query.filter_by(assigned_user_id=current_user.id)
|
||||
TaskInstance.query.filter(
|
||||
or_(
|
||||
TaskInstance.assigned_user_id == current_user.id,
|
||||
TaskInstance.assigned_user_secondary_id == current_user.id,
|
||||
)
|
||||
)
|
||||
.order_by(TaskInstance.completed_at.is_(None).desc(), TaskInstance.due_date.asc())
|
||||
.all()
|
||||
)
|
||||
refresh_task_statuses(tasks)
|
||||
|
||||
sections = {"open": [], "soon": [], "overdue": [], "completed": []}
|
||||
sections = {
|
||||
"open": [],
|
||||
"due_today": [],
|
||||
"due_tomorrow": [],
|
||||
"due_day_after_tomorrow": [],
|
||||
"overdue": [],
|
||||
"completed": [],
|
||||
}
|
||||
for task in tasks:
|
||||
sections[task.status].append(task)
|
||||
|
||||
completed_count = len(sections["completed"])
|
||||
active_count = len(sections["open"]) + len(sections["soon"]) + len(sections["overdue"])
|
||||
active_count = (
|
||||
len(sections["open"])
|
||||
+ len(sections["due_today"])
|
||||
+ len(sections["due_tomorrow"])
|
||||
+ len(sections["due_day_after_tomorrow"])
|
||||
+ len(sections["overdue"])
|
||||
)
|
||||
completion_ratio = 0 if completed_count + active_count == 0 else round(completed_count / (completed_count + active_count) * 100)
|
||||
|
||||
return render_template(
|
||||
@@ -64,9 +87,19 @@ def all_tasks():
|
||||
sort = request.args.get("sort", "due")
|
||||
|
||||
if mine == "1":
|
||||
query = query.filter(TaskInstance.assigned_user_id == current_user.id)
|
||||
query = query.filter(
|
||||
or_(
|
||||
TaskInstance.assigned_user_id == current_user.id,
|
||||
TaskInstance.assigned_user_secondary_id == current_user.id,
|
||||
)
|
||||
)
|
||||
elif user_filter:
|
||||
query = query.filter(TaskInstance.assigned_user_id == user_filter)
|
||||
query = query.filter(
|
||||
or_(
|
||||
TaskInstance.assigned_user_id == user_filter,
|
||||
TaskInstance.assigned_user_secondary_id == user_filter,
|
||||
)
|
||||
)
|
||||
|
||||
if sort == "points":
|
||||
query = query.order_by(TaskInstance.points_awarded.desc(), TaskInstance.due_date.asc())
|
||||
@@ -79,7 +112,17 @@ def all_tasks():
|
||||
refresh_task_statuses(tasks)
|
||||
|
||||
if status != "all":
|
||||
status_map = {"completed": "completed", "overdue": "overdue", "open": "open", "soon": "soon"}
|
||||
if status == "soon":
|
||||
tasks = [task for task in tasks if task.status in {"due_today", "due_tomorrow", "due_day_after_tomorrow"}]
|
||||
else:
|
||||
status_map = {
|
||||
"completed": "completed",
|
||||
"overdue": "overdue",
|
||||
"open": "open",
|
||||
"today": "due_today",
|
||||
"tomorrow": "due_tomorrow",
|
||||
"day_after_tomorrow": "due_day_after_tomorrow",
|
||||
}
|
||||
selected = status_map.get(status)
|
||||
if selected:
|
||||
tasks = [task for task in tasks if task.status == selected]
|
||||
@@ -97,6 +140,7 @@ def all_tasks():
|
||||
def create():
|
||||
form = TaskForm()
|
||||
form.assigned_user_id.choices = _user_choices()
|
||||
form.assigned_user_secondary_id.choices = _secondary_user_choices()
|
||||
if request.method == "GET" and not form.due_date.data:
|
||||
form.due_date.data = today_local()
|
||||
|
||||
@@ -158,13 +202,15 @@ def edit(task_id: int):
|
||||
task = TaskInstance.query.get_or_404(task_id)
|
||||
form = TaskForm(obj=task.task_template)
|
||||
form.assigned_user_id.choices = _user_choices()
|
||||
form.assigned_user_secondary_id.choices = _secondary_user_choices()
|
||||
next_url = request.args.get("next") or request.form.get("next") or request.referrer or url_for("tasks.all_tasks")
|
||||
|
||||
if request.method == "GET":
|
||||
form.title.data = task.title
|
||||
form.description.data = task.description
|
||||
form.default_points.data = task.points_awarded
|
||||
form.default_points.data = task.task_template.default_points
|
||||
form.assigned_user_id.data = task.assigned_user_id or _user_choices()[0][0]
|
||||
form.assigned_user_secondary_id.data = task.assigned_user_secondary_id or 0
|
||||
form.due_date.data = task.due_date
|
||||
form.recurrence_interval_value.data = task.task_template.recurrence_interval_value or 1
|
||||
form.recurrence_interval_unit.data = task.task_template.recurrence_interval_unit
|
||||
@@ -200,8 +246,15 @@ def complete(task_id: int):
|
||||
return redirect(request.referrer or url_for("tasks.my_tasks"))
|
||||
|
||||
completed_by_id = current_user.id
|
||||
if task.assigned_user_id and task.assigned_user_id != current_user.id and choice == "assigned":
|
||||
completed_by_id = task.assigned_user_id
|
||||
allowed_ids = {current_user.id}
|
||||
if task.assigned_user_id:
|
||||
allowed_ids.add(task.assigned_user_id)
|
||||
if task.assigned_user_secondary_id:
|
||||
allowed_ids.add(task.assigned_user_secondary_id)
|
||||
if choice != "me":
|
||||
selected_user_id = request.form.get("completed_for", type=int)
|
||||
if selected_user_id in allowed_ids:
|
||||
completed_by_id = selected_user_id
|
||||
|
||||
complete_task(task, completed_by_id)
|
||||
flash("Punkte verbucht. Gute Arbeit.", "success")
|
||||
|
||||
@@ -4,7 +4,7 @@ import json
|
||||
from collections import defaultdict
|
||||
from datetime import date, datetime, time, timedelta
|
||||
|
||||
from sqlalchemy import and_
|
||||
from sqlalchemy import and_, or_
|
||||
|
||||
from ..extensions import db
|
||||
from ..models import BadgeDefinition, MonthlyScoreSnapshot, TaskInstance, User, UserBadge
|
||||
@@ -92,7 +92,7 @@ def _completion_metrics(user: User) -> dict[str, int]:
|
||||
metrics["on_time_tasks_completed"] += 1
|
||||
if completion_day <= task.due_date - timedelta(days=1):
|
||||
metrics["early_tasks_completed"] += 1
|
||||
if task.assigned_user_id and task.assigned_user_id != user.id:
|
||||
if task.assigned_user_ids and user.id not in task.assigned_user_ids:
|
||||
metrics["foreign_tasks_completed"] += 1
|
||||
max_points = max(max_points, task.points_awarded)
|
||||
|
||||
@@ -127,7 +127,10 @@ def _user_had_clean_month(user_id: int, year: int, month: int) -> bool:
|
||||
start_date = date(year, month, 1)
|
||||
end_date = (month_bounds(year, month)[1] - timedelta(days=1)).date()
|
||||
tasks = TaskInstance.query.filter(
|
||||
or_(
|
||||
TaskInstance.assigned_user_id == user_id,
|
||||
TaskInstance.assigned_user_secondary_id == user_id,
|
||||
),
|
||||
TaskInstance.due_date >= start_date,
|
||||
TaskInstance.due_date <= end_date,
|
||||
).all()
|
||||
|
||||
@@ -21,6 +21,21 @@ def ensure_schema_and_admins() -> None:
|
||||
db.session.execute(text("ALTER TABLE user ADD COLUMN calendar_feed_token VARCHAR(255)"))
|
||||
db.session.commit()
|
||||
|
||||
task_template_columns = {column["name"] for column in inspector.get_columns("task_template")}
|
||||
if "default_assigned_user_secondary_id" not in task_template_columns:
|
||||
db.session.execute(text("ALTER TABLE task_template ADD COLUMN default_assigned_user_secondary_id INTEGER"))
|
||||
db.session.commit()
|
||||
|
||||
task_instance_columns = {column["name"] for column in inspector.get_columns("task_instance")}
|
||||
if "assigned_user_secondary_id" not in task_instance_columns:
|
||||
db.session.execute(text("ALTER TABLE task_instance ADD COLUMN assigned_user_secondary_id INTEGER"))
|
||||
db.session.commit()
|
||||
|
||||
quick_win_columns = {column["name"] for column in inspector.get_columns("quick_win")}
|
||||
if "sort_order" not in quick_win_columns:
|
||||
db.session.execute(text("ALTER TABLE quick_win ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0"))
|
||||
db.session.commit()
|
||||
|
||||
ensure_app_settings()
|
||||
|
||||
users_without_feed = User.query.filter(User.calendar_feed_token.is_(None)).all()
|
||||
@@ -46,6 +61,7 @@ def ensure_schema_and_admins() -> None:
|
||||
default_quick_win_user = first_user
|
||||
|
||||
_ensure_default_quick_wins(default_quick_win_user or User.query.order_by(User.id.asc()).first())
|
||||
_ensure_quick_win_ordering()
|
||||
|
||||
|
||||
def _ensure_default_quick_wins(default_user: User | None) -> None:
|
||||
@@ -62,6 +78,7 @@ def _ensure_default_quick_wins(default_user: User | None) -> None:
|
||||
|
||||
existing_titles = {quick_win.title for quick_win in QuickWin.query.all()}
|
||||
created = False
|
||||
next_sort_order = QuickWin.query.count()
|
||||
for title, effort in defaults:
|
||||
if title not in existing_titles:
|
||||
db.session.add(
|
||||
@@ -70,8 +87,21 @@ def _ensure_default_quick_wins(default_user: User | None) -> None:
|
||||
effort=effort,
|
||||
active=True,
|
||||
created_by_user_id=default_user.id,
|
||||
sort_order=next_sort_order,
|
||||
)
|
||||
)
|
||||
next_sort_order += 1
|
||||
created = True
|
||||
if created:
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def _ensure_quick_win_ordering() -> None:
|
||||
quick_wins = QuickWin.query.order_by(QuickWin.sort_order.asc(), QuickWin.id.asc()).all()
|
||||
dirty = False
|
||||
for index, quick_win in enumerate(quick_wins):
|
||||
if quick_win.sort_order != index:
|
||||
quick_win.sort_order = index
|
||||
dirty = True
|
||||
if dirty:
|
||||
db.session.commit()
|
||||
|
||||
@@ -2,6 +2,8 @@ from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime, time, timedelta
|
||||
|
||||
from sqlalchemy import or_
|
||||
|
||||
from ..models import TaskInstance, User
|
||||
|
||||
|
||||
@@ -23,7 +25,12 @@ def _format_timestamp(value: datetime | None) -> str:
|
||||
|
||||
def build_calendar_feed(user: User, base_url: str) -> str:
|
||||
tasks = (
|
||||
TaskInstance.query.filter_by(assigned_user_id=user.id)
|
||||
TaskInstance.query.filter(
|
||||
or_(
|
||||
TaskInstance.assigned_user_id == user.id,
|
||||
TaskInstance.assigned_user_secondary_id == user.id,
|
||||
)
|
||||
)
|
||||
.order_by(TaskInstance.due_date.asc(), TaskInstance.id.asc())
|
||||
.all()
|
||||
)
|
||||
|
||||
@@ -25,12 +25,19 @@ def refresh_task_statuses(tasks: list[TaskInstance]) -> None:
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def effective_points(base_points: int, assigned_user_secondary_id: int | None) -> int:
|
||||
if assigned_user_secondary_id:
|
||||
return max(1, base_points // 2)
|
||||
return base_points
|
||||
|
||||
|
||||
def create_task_template_and_instance(form) -> TaskInstance:
|
||||
template = TaskTemplate(
|
||||
title=form.title.data.strip(),
|
||||
description=(form.description.data or "").strip(),
|
||||
default_points=form.default_points.data,
|
||||
default_assigned_user_id=form.assigned_user_id.data,
|
||||
default_assigned_user_secondary_id=form.assigned_user_secondary_id.data or None,
|
||||
recurrence_interval_value=form.recurrence_interval_value.data if form.recurrence_interval_unit.data != "none" else None,
|
||||
recurrence_interval_unit=form.recurrence_interval_unit.data,
|
||||
active=form.active.data,
|
||||
@@ -43,8 +50,9 @@ def create_task_template_and_instance(form) -> TaskInstance:
|
||||
title=template.title,
|
||||
description=template.description,
|
||||
assigned_user_id=template.default_assigned_user_id,
|
||||
assigned_user_secondary_id=template.default_assigned_user_secondary_id,
|
||||
due_date=form.due_date.data,
|
||||
points_awarded=template.default_points,
|
||||
points_awarded=effective_points(template.default_points, template.default_assigned_user_secondary_id),
|
||||
status="open",
|
||||
)
|
||||
refresh_task_status(task, form.due_date.data)
|
||||
@@ -59,6 +67,7 @@ def update_template_and_instance(task: TaskInstance, form) -> TaskInstance:
|
||||
template.description = (form.description.data or "").strip()
|
||||
template.default_points = form.default_points.data
|
||||
template.default_assigned_user_id = form.assigned_user_id.data
|
||||
template.default_assigned_user_secondary_id = form.assigned_user_secondary_id.data or None
|
||||
template.recurrence_interval_unit = form.recurrence_interval_unit.data
|
||||
template.recurrence_interval_value = (
|
||||
form.recurrence_interval_value.data if form.recurrence_interval_unit.data != "none" else None
|
||||
@@ -68,7 +77,8 @@ def update_template_and_instance(task: TaskInstance, form) -> TaskInstance:
|
||||
task.title = template.title
|
||||
task.description = template.description
|
||||
task.assigned_user_id = template.default_assigned_user_id
|
||||
task.points_awarded = template.default_points
|
||||
task.assigned_user_secondary_id = template.default_assigned_user_secondary_id
|
||||
task.points_awarded = effective_points(template.default_points, template.default_assigned_user_secondary_id)
|
||||
task.due_date = form.due_date.data
|
||||
refresh_task_status(task, form.due_date.data)
|
||||
db.session.commit()
|
||||
@@ -108,8 +118,12 @@ def ensure_next_recurring_task(task: TaskInstance) -> TaskInstance | None:
|
||||
title=task.task_template.title,
|
||||
description=task.task_template.description,
|
||||
assigned_user_id=task.task_template.default_assigned_user_id,
|
||||
assigned_user_secondary_id=task.task_template.default_assigned_user_secondary_id,
|
||||
due_date=next_due,
|
||||
points_awarded=task.task_template.default_points,
|
||||
points_awarded=effective_points(
|
||||
task.task_template.default_points,
|
||||
task.task_template.default_assigned_user_secondary_id,
|
||||
),
|
||||
status="open",
|
||||
)
|
||||
refresh_task_status(next_task, today_local())
|
||||
@@ -149,6 +163,7 @@ def create_quick_task(title: str, effort: str, creator: User, description: str =
|
||||
title=template.title,
|
||||
description=description,
|
||||
assigned_user_id=creator.id,
|
||||
assigned_user_secondary_id=None,
|
||||
due_date=today_local(),
|
||||
points_awarded=template.default_points,
|
||||
status="open",
|
||||
|
||||
@@ -473,6 +473,9 @@ p {
|
||||
color: #1d4ed8;
|
||||
}
|
||||
|
||||
.status-badge--due_today,
|
||||
.status-badge--due_tomorrow,
|
||||
.status-badge--due_day_after_tomorrow,
|
||||
.status-badge--soon {
|
||||
background: #fff3d6;
|
||||
color: #b45309;
|
||||
@@ -514,6 +517,16 @@ p {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.task-assignee__avatars {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.task-assignee__avatars .avatar + .avatar {
|
||||
margin-left: -10px;
|
||||
border: 2px solid var(--surface-strong);
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
@@ -903,6 +916,9 @@ p {
|
||||
border-left: 4px solid #2563eb;
|
||||
}
|
||||
|
||||
.calendar-task--due_today,
|
||||
.calendar-task--due_tomorrow,
|
||||
.calendar-task--due_day_after_tomorrow,
|
||||
.calendar-task--soon {
|
||||
border-left: 4px solid #f59e0b;
|
||||
}
|
||||
@@ -1066,6 +1082,11 @@ p {
|
||||
|
||||
.quick-win-manage-card {
|
||||
align-items: stretch;
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.quick-win-manage-card.is-dragging {
|
||||
opacity: 0.72;
|
||||
}
|
||||
|
||||
.quick-win-manage-form {
|
||||
@@ -1073,6 +1094,14 @@ p {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.quick-win-manage-card__drag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: var(--muted);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.quick-win-manage-card__actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
@@ -1427,6 +1456,9 @@ p {
|
||||
color: #8db7ff;
|
||||
}
|
||||
|
||||
.status-badge--due_today,
|
||||
.status-badge--due_tomorrow,
|
||||
.status-badge--due_day_after_tomorrow,
|
||||
.status-badge--soon {
|
||||
background: rgba(245, 158, 11, 0.18);
|
||||
color: #ffd38a;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const dialogForm = document.getElementById("completeDialogForm");
|
||||
const dialogChoice = document.getElementById("completeDialogChoice");
|
||||
const dialogText = document.getElementById("completeDialogText");
|
||||
const dialogChoices = document.getElementById("completeDialogChoices");
|
||||
const closeButton = document.getElementById("completeDialogClose");
|
||||
const quickTaskDialog = document.getElementById("quickTaskDialog");
|
||||
const quickTaskOpen = document.getElementById("quickTaskOpen");
|
||||
@@ -13,24 +14,56 @@
|
||||
const quickWinCustomFields = document.getElementById("quickWinCustomFields");
|
||||
const quickWinTitle = document.getElementById("quick-title");
|
||||
const quickWinEffort = document.getElementById("quick-effort");
|
||||
const currentUserId = document.body.dataset.currentUserId;
|
||||
const currentUserName = document.body.dataset.currentUserName;
|
||||
const quickWinSortList = document.querySelector("[data-quick-win-sort-list]");
|
||||
const quickWinSortToken = document.getElementById("quickWinSortToken");
|
||||
let draggedQuickWin = null;
|
||||
|
||||
function buildCompletionOptions(button) {
|
||||
const options = [];
|
||||
const assignedPairs = [
|
||||
[button.dataset.assignedPrimaryId, button.dataset.assignedPrimaryName],
|
||||
[button.dataset.assignedSecondaryId, button.dataset.assignedSecondaryName],
|
||||
];
|
||||
|
||||
assignedPairs.forEach(([id, label]) => {
|
||||
if (id && label && !options.some((option) => option.value === id)) {
|
||||
options.push({ value: id, label });
|
||||
}
|
||||
});
|
||||
|
||||
if (currentUserId && currentUserName && !options.some((option) => option.value === currentUserId)) {
|
||||
options.push({ value: currentUserId, label: "Ich" });
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
document.querySelectorAll("[data-complete-action]").forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
if (!dialog || !dialogForm || !dialogChoice || !dialogText) {
|
||||
if (!dialog || !dialogForm || !dialogChoice || !dialogText || !dialogChoices) {
|
||||
return;
|
||||
}
|
||||
dialogForm.action = button.dataset.completeAction;
|
||||
dialogText.textContent = `Die Aufgabe "${button.dataset.completeTitle}" war ${button.dataset.completeAssigned} zugewiesen. Wer hat sie erledigt?`;
|
||||
dialog.showModal();
|
||||
});
|
||||
});
|
||||
dialogChoices.innerHTML = "";
|
||||
|
||||
document.querySelectorAll("[data-complete-choice]").forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
dialogChoice.value = button.dataset.completeChoice || "me";
|
||||
buildCompletionOptions(button).forEach((option, index) => {
|
||||
const choiceButton = document.createElement("button");
|
||||
choiceButton.type = "button";
|
||||
choiceButton.className = index === 0 ? "button button--secondary" : "button";
|
||||
choiceButton.dataset.completeChoice = option.value;
|
||||
choiceButton.textContent = option.label;
|
||||
choiceButton.addEventListener("click", () => {
|
||||
dialogChoice.value = option.value;
|
||||
dialog.close();
|
||||
dialogForm.submit();
|
||||
});
|
||||
dialogChoices.appendChild(choiceButton);
|
||||
});
|
||||
dialog.showModal();
|
||||
});
|
||||
});
|
||||
|
||||
if (closeButton && dialog) {
|
||||
@@ -87,6 +120,64 @@
|
||||
});
|
||||
}
|
||||
|
||||
async function persistQuickWinSort() {
|
||||
if (!quickWinSortList || !quickWinSortToken) {
|
||||
return;
|
||||
}
|
||||
const ids = [...quickWinSortList.querySelectorAll("[data-quick-win-sort-item]")]
|
||||
.map((item) => item.dataset.quickWinSortItem)
|
||||
.filter(Boolean);
|
||||
|
||||
await fetch("/settings/quick-wins/reorder", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-CSRFToken": quickWinSortToken.value,
|
||||
},
|
||||
body: JSON.stringify({ ids }),
|
||||
});
|
||||
}
|
||||
|
||||
if (quickWinSortList) {
|
||||
quickWinSortList.querySelectorAll("[data-quick-win-sort-item]").forEach((item) => {
|
||||
item.addEventListener("dragstart", () => {
|
||||
draggedQuickWin = item;
|
||||
item.classList.add("is-dragging");
|
||||
});
|
||||
|
||||
item.addEventListener("dragend", () => {
|
||||
item.classList.remove("is-dragging");
|
||||
draggedQuickWin = null;
|
||||
});
|
||||
|
||||
item.addEventListener("dragover", (event) => {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
item.addEventListener("drop", async (event) => {
|
||||
event.preventDefault();
|
||||
if (!draggedQuickWin || draggedQuickWin === item) {
|
||||
return;
|
||||
}
|
||||
|
||||
const items = [...quickWinSortList.querySelectorAll("[data-quick-win-sort-item]")];
|
||||
const draggedIndex = items.indexOf(draggedQuickWin);
|
||||
const targetIndex = items.indexOf(item);
|
||||
if (draggedIndex < targetIndex) {
|
||||
item.after(draggedQuickWin);
|
||||
} else {
|
||||
item.before(draggedQuickWin);
|
||||
}
|
||||
|
||||
try {
|
||||
await persistQuickWinSort();
|
||||
} catch (error) {
|
||||
console.error("Quick-Win-Sortierung konnte nicht gespeichert werden", error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const pushButton = document.getElementById("pushToggle");
|
||||
const pushHint = document.getElementById("pushHint");
|
||||
const vapidKey = document.body.dataset.pushKey;
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
<link rel="apple-touch-icon" href="{{ url_for('static', filename='images/apple-touch-icon.png') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css', v=asset_version('css/style.css')) }}">
|
||||
</head>
|
||||
<body data-push-key="{{ config['VAPID_PUBLIC_KEY'] if current_user.is_authenticated else '' }}">
|
||||
<body
|
||||
data-push-key="{{ config['VAPID_PUBLIC_KEY'] if current_user.is_authenticated else '' }}"
|
||||
data-current-user-id="{{ current_user.id if current_user.is_authenticated else '' }}"
|
||||
data-current-user-name="{{ current_user.name if current_user.is_authenticated else '' }}"
|
||||
>
|
||||
{% from "partials/macros.html" import nav_icon %}
|
||||
<div class="app-shell {% if not current_user.is_authenticated %}app-shell--auth{% endif %}">
|
||||
{% if current_user.is_authenticated %}
|
||||
@@ -119,10 +123,7 @@
|
||||
<p class="eyebrow">Punkte fair verbuchen</p>
|
||||
<h2>Wer hat diese Aufgabe erledigt?</h2>
|
||||
<p id="completeDialogText">Bitte wähle aus, wem die Punkte gutgeschrieben werden sollen.</p>
|
||||
<div class="choice-grid">
|
||||
<button type="button" class="button button--secondary" data-complete-choice="assigned">Zugewiesene Person</button>
|
||||
<button type="button" class="button" data-complete-choice="me">Ich</button>
|
||||
</div>
|
||||
<div class="choice-grid" id="completeDialogChoices"></div>
|
||||
<button type="button" class="button button--ghost" id="completeDialogClose">Abbrechen</button>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<div>
|
||||
<div class="chip-row">
|
||||
{{ status_badge(task) }}
|
||||
<span class="point-pill">{{ task.points_awarded }} Punkte</span>
|
||||
<span class="point-pill">{{ task.points_awarded }} Punkte{% if task.is_shared_assignment %} / Person{% endif %}</span>
|
||||
</div>
|
||||
<h3>{{ task.title }}</h3>
|
||||
</div>
|
||||
@@ -68,7 +68,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<dt>Zuständig</dt>
|
||||
<dd>{{ task.assigned_user.name if task.assigned_user else 'Unverteilt' }}</dd>
|
||||
<dd>{{ task.assignee_label }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Rhythmus</dt>
|
||||
@@ -84,18 +84,26 @@
|
||||
|
||||
<div class="task-card__footer">
|
||||
<div class="task-assignee">
|
||||
{{ avatar(task.assigned_user) }}
|
||||
<span>{{ task.assigned_user.name if task.assigned_user else 'Ohne Person' }}</span>
|
||||
<span class="task-assignee__avatars">
|
||||
{% for assigned_user in task.assigned_users %}
|
||||
{{ avatar(assigned_user) }}
|
||||
{% endfor %}
|
||||
</span>
|
||||
<span>{{ task.assignee_label }}</span>
|
||||
</div>
|
||||
|
||||
{% if not task.completed_at %}
|
||||
{% if task.assigned_user_id and task.assigned_user_id != current_user.id %}
|
||||
{% if task.assigned_users and current_user.id not in task.assigned_user_ids %}
|
||||
<button
|
||||
type="button"
|
||||
class="button"
|
||||
data-complete-action="{{ url_for('tasks.complete', task_id=task.id) }}"
|
||||
data-complete-title="{{ task.title }}"
|
||||
data-complete-assigned="{{ task.assigned_user.name if task.assigned_user else 'Zugewiesene Person' }}"
|
||||
data-complete-assigned="{{ task.assignee_label }}"
|
||||
data-assigned-primary-id="{{ task.assigned_user.id if task.assigned_user else '' }}"
|
||||
data-assigned-primary-name="{{ task.assigned_user.name if task.assigned_user else '' }}"
|
||||
data-assigned-secondary-id="{{ task.assigned_user_secondary.id if task.assigned_user_secondary else '' }}"
|
||||
data-assigned-secondary-name="{{ task.assigned_user_secondary.name if task.assigned_user_secondary else '' }}"
|
||||
>
|
||||
{{ nav_icon('check') }}
|
||||
<span>Erledigen</span>
|
||||
|
||||
@@ -36,11 +36,17 @@
|
||||
<article class="panel">
|
||||
<p class="eyebrow">Direkt sichtbar</p>
|
||||
<h2>Aktive Quick-Wins bearbeiten</h2>
|
||||
<div class="quick-win-list">
|
||||
<p class="muted">Per Drag & Drop kannst du die Reihenfolge festlegen, die später auch bei den Quick-Win-Chips erscheint.</p>
|
||||
<input type="hidden" id="quickWinSortToken" value="{{ csrf_token() }}">
|
||||
<div class="quick-win-list" data-quick-win-sort-list>
|
||||
{% for quick_win in quick_wins %}
|
||||
<article class="quick-win-manage-card">
|
||||
<article class="quick-win-manage-card" draggable="true" data-quick-win-sort-item="{{ quick_win.id }}">
|
||||
<form method="post" action="{{ url_for('settings.update_quick_win', quick_win_id=quick_win.id) }}" class="quick-win-manage-form">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<div class="quick-win-manage-card__drag">
|
||||
{{ nav_icon('list') }}
|
||||
<span>Ziehen zum Sortieren</span>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="quick-win-title-{{ quick_win.id }}">Titel</label>
|
||||
<input id="quick-win-title-{{ quick_win.id }}" type="text" name="title" value="{{ quick_win.title }}" minlength="2" maxlength="160" required>
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
<option value="all" {% if filters.status == 'all' %}selected{% endif %}>Alle</option>
|
||||
<option value="open" {% if filters.status == 'open' %}selected{% endif %}>Offen</option>
|
||||
<option value="soon" {% if filters.status == 'soon' %}selected{% endif %}>Bald fällig</option>
|
||||
<option value="today" {% if filters.status == 'today' %}selected{% endif %}>Heute fällig</option>
|
||||
<option value="tomorrow" {% if filters.status == 'tomorrow' %}selected{% endif %}>Morgen fällig</option>
|
||||
<option value="day_after_tomorrow" {% if filters.status == 'day_after_tomorrow' %}selected{% endif %}>Übermorgen fällig</option>
|
||||
<option value="overdue" {% if filters.status == 'overdue' %}selected{% endif %}>Überfällig</option>
|
||||
<option value="completed" {% if filters.status == 'completed' %}selected{% endif %}>Erledigt</option>
|
||||
</select>
|
||||
@@ -48,4 +51,3 @@
|
||||
{% endfor %}
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@
|
||||
<small class="calendar-task__person" lang="de">
|
||||
{% if task.completed_by_user %}
|
||||
{{ task.completed_by_user.name|hyphenate_de }}
|
||||
{% elif task.assigned_user %}
|
||||
{{ task.assigned_user.name|hyphenate_de }}
|
||||
{% elif task.assigned_users %}
|
||||
{{ task.assignee_label|hyphenate_de }}
|
||||
{% else %}
|
||||
{{ 'Ohne Zuweisung'|hyphenate_de }}
|
||||
{% endif %}
|
||||
@@ -108,8 +108,8 @@
|
||||
<small class="calendar-task__person" lang="de">
|
||||
{% if task.completed_by_user %}
|
||||
{{ task.completed_by_user.name|hyphenate_de }}
|
||||
{% elif task.assigned_user %}
|
||||
{{ task.assigned_user.name|hyphenate_de }}
|
||||
{% elif task.assigned_users %}
|
||||
{{ task.assignee_label|hyphenate_de }}
|
||||
{% else %}
|
||||
{{ 'Ohne Zuweisung'|hyphenate_de }}
|
||||
{% endif %}
|
||||
|
||||
@@ -46,13 +46,41 @@
|
||||
<section class="stack">
|
||||
<div class="section-heading">
|
||||
<h2>Bald fällig</h2>
|
||||
<span class="section-heading__count">{{ sections.soon|length }}</span>
|
||||
<span class="section-heading__count">{{ sections.due_today|length }}</span>
|
||||
</div>
|
||||
<div class="task-grid">
|
||||
{% for task in sections.soon %}
|
||||
{% for task in sections.due_today %}
|
||||
{{ task_card(task, current_user) }}
|
||||
{% else %}
|
||||
<div class="empty-state">Gerade nichts, was in den nächsten Tagen drängt.</div>
|
||||
<div class="empty-state">Heute ist gerade nichts mehr auf Kante.</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="stack">
|
||||
<div class="section-heading">
|
||||
<h2>Morgen fällig</h2>
|
||||
<span class="section-heading__count">{{ sections.due_tomorrow|length }}</span>
|
||||
</div>
|
||||
<div class="task-grid">
|
||||
{% for task in sections.due_tomorrow %}
|
||||
{{ task_card(task, current_user) }}
|
||||
{% else %}
|
||||
<div class="empty-state">Für morgen sieht es gerade entspannt aus.</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="stack">
|
||||
<div class="section-heading">
|
||||
<h2>Übermorgen fällig</h2>
|
||||
<span class="section-heading__count">{{ sections.due_day_after_tomorrow|length }}</span>
|
||||
</div>
|
||||
<div class="task-grid">
|
||||
{% for task in sections.due_day_after_tomorrow %}
|
||||
{{ task_card(task, current_user) }}
|
||||
{% else %}
|
||||
<div class="empty-state">Auch übermorgen ist noch nichts Drängendes drin.</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
@@ -85,4 +113,3 @@
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -35,6 +35,13 @@
|
||||
{% for error in form.assigned_user_id.errors %}<small class="error">{{ error }}</small>{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
{{ form.assigned_user_secondary_id.label }}
|
||||
{{ form.assigned_user_secondary_id() }}
|
||||
<small class="muted">Wenn du hier noch jemanden auswählst, zählen die Punkte pro Person halbiert.</small>
|
||||
{% for error in form.assigned_user_secondary_id.errors %}<small class="error">{{ error }}</small>{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
{{ form.due_date.label }}
|
||||
{{ form.due_date() }}
|
||||
|
||||
Reference in New Issue
Block a user