Add logged-in user dashboard page

This commit is contained in:
Drew DeVault 2020-04-27 11:45:53 -04:00
parent 15a3556c64
commit a3fd75170b
5 changed files with 87 additions and 51 deletions

View file

@ -76,6 +76,7 @@ def create_POST():
visibility = valid.require("visibility", cls=Visibility)
valid.expect(not name or len(name) < 128,
"Name must be fewer than 128 characters", field="name")
# TODO: Test that name passes some validity regex
valid.expect(not name or Project.query
.filter(Project.name == name)
.filter(Project.owner_id == current_user.id).count() == 0,

View file

@ -1,12 +1,28 @@
from flask import Blueprint, render_template
from srht.oauth import current_user
from hubsrht.types import Project, Event, EventType
from srht.flask import paginate_query
from srht.oauth import current_user, loginrequired
public = Blueprint("public", __name__)
@public.route("/")
def index():
if current_user:
# TODO: If the user has any projects, render normal dashboard
#return render_template("dashboard.html")
projects = (Project.query
.filter(Project.owner_id == current_user.id)
.order_by(Project.updated.desc())
.limit(5)).all()
if any(projects):
events = (Event.query
.filter(Event.user_id == current_user.id)
.order_by(Event.created.desc())
.limit(2)).all()
return render_template("dashboard.html",
projects=projects, EventType=EventType, events=events)
return render_template("new-user-dashboard.html")
return render_template("index.html")
@public.route("/getting-started")
@loginrequired
def getting_started():
return render_template("new-user-dashboard.html")

View file

@ -3,5 +3,9 @@ from flask import Blueprint
users = Blueprint("users", __name__)
@users.route("/~<username>")
def user_summary_GET(username):
def summary_GET(username):
pass # TODO
@users.route("/projects/<owner>")
def projects_GET(owner):
pass # TODO

View file

@ -1,4 +1,8 @@
{% extends "layout.html" %}
{% import "event.html" as eventutil with context %}
{% block title %}
<title>{{cfg("sr.ht", "site-name")}} dashboard</title>
{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-4">
@ -9,62 +13,73 @@
</p>
<div style="margin-bottom: 1rem">
<a
href="#"
href="{{url_for("projects.create_GET")}}"
class="btn btn-primary btn-block"
>Create new project {{icon("caret-right")}}</a>
<a
href="#"
class="btn btn-default btn-block"
>View your profile {{icon("caret-right")}}</a>
>Discover projects on {{cfg('sr.ht', 'site-name')}} {{icon("caret-right")}}</a>
<a
href="{{url_for("public.getting_started")}}"
class="btn btn-link btn-sm btn-block"
>Getting started with {{cfg('sr.ht', 'site-name')}} {{icon("caret-right")}}</a>
</div>
<h3>Discover interesting projects</h3>
<div class="event-list">
<div class="event">
<h4><a href="#">SourceHut</a></h4>
<p>The hacker's software forge</p>
</div>
<div class="event">
<h4><a href="#">KnightOS</a></h4>
<p>A Unix-like operating system for TI...</p>
</div>
<div class="event">
<h4><a href="#">aerc</a></h4>
<p>The world's best email client</p>
</div>
</div>
<a href="#" class="btn btn-block btn-default">
Browse more projects
{{icon("caret-right")}}
</a>
</div>
<div class="col-md-8">
<hr class="d-md-none" />
<form>
<input
name="search"
type="text"
placeholder="Search your projects"
class="form-control{% if search_error %} is-invalid{% endif %}"
value="{{ search if search else "" }}" />
{% if search_error %}
<div class="invalid-feedback">{{ search_error }}</div>
{% endif %}
</form>
<div class="event-list">
{% for i in range(25 // 3) %}
<div class="event">
<h4><a href="#">SourceHut</a></h4>
<p>The hacker's software forge</p>
<div class="row">
<div class="col-md-12">
<hr class="d-md-none" />
<form action="{{url_for("users.projects_GET",
owner=current_user.canonical_name)}}"
>
<input
name="search"
type="text"
placeholder="Search your projects"
class="form-control" />
{% if search_error %}
<div class="invalid-feedback">{{ search_error }}</div>
{% endif %}
</form>
<div class="event-list">
{% for project in projects %}
<div class="event">
<h4>
{% if project.visibility.value != 'public' %}
<small class="text-muted pull-right">{{project.visibility.value}}</small>
{% endif %}
<a href="{{url_for("projects.summary_GET",
owner=project.owner.canonical_name,
project_name=project.name)}}">{{project.name}}</a>
</h4>
<p>{{project.description}}</p>
</div>
{% endfor %}
</div>
<div class="pull-right">
<a
href="#"
class="btn btn-default"
>More projects&nbsp;{{icon("caret-right")}}</a>
</div>
<div class="clearfix"></div>
</div>
<div class="event">
<h4><a href="#">KnightOS</a></h4>
<p>A Unix-like operating system for TI...</p>
</div>
<div class="row" style="margin-top: 1rem">
<div class="col-md-12">
<div class="event-list project-events">
{% for event in events %}
{{ eventutil.event(event) }}
{% endfor %}
</div>
<div class="pull-right">
<a
href="#"
class="btn btn-default"
>More events&nbsp;{{icon("caret-right")}}</a>
</div>
</div>
<div class="event">
<h4><a href="#">aerc</a></h4>
<p>The world's best email client</p>
</div>
{% endfor %}
</div>
</div>
</div>

View file

@ -1,6 +1,6 @@
<h2>
<a
href="{{url_for("users.user_summary_GET", username=owner.username)}}"
href="{{url_for("users.summary_GET", username=owner.username)}}"
>{{owner.canonical_name}}</a>/{{project.name}}
</h2>
{% macro link(path, title, alternates, cls="") %}