From c1e0b6c306fc70ad6ae131dca5e8b35d14eb75e3 Mon Sep 17 00:00:00 2001 From: Bat Date: Sat, 8 Sep 2018 19:54:09 +0100 Subject: [PATCH] Add admin interface to manage interface --- plume-models/src/instance.rs | 8 ++++++++ src/main.rs | 2 ++ src/routes/instance.rs | 17 ++++++++++++++++ templates/instance/admin.html.tera | 3 ++- templates/instance/list.html.tera | 31 ++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 templates/instance/list.html.tera diff --git a/plume-models/src/instance.rs b/plume-models/src/instance.rs index d0d553ed..0697fae6 100644 --- a/plume-models/src/instance.rs +++ b/plume-models/src/instance.rs @@ -52,6 +52,14 @@ impl Instance { .expect("Error loading remote instances infos") } + pub fn page(conn: &PgConnection, (min, max): (i32, i32)) -> Vec { + instances::table.order(instances::public_domain.asc()) + .offset(min.into()) + .limit((max - min).into()) + .load::(conn) + .expect("Error loading a page of instances") + } + pub fn local_id(conn: &PgConnection) -> i32 { Instance::get_local(conn).unwrap().id } diff --git a/src/main.rs b/src/main.rs index 956146f2..8491ebb2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,6 +63,8 @@ fn main() { routes::instance::paginated_federated, routes::instance::federated, routes::instance::admin, + routes::instance::admin_instances, + routes::instance::admin_instances_paginated, routes::instance::update_settings, routes::instance::shared_inbox, routes::instance::nodeinfo, diff --git a/src/routes/instance.rs b/src/routes/instance.rs index 1125da4a..1fa6f40b 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -137,6 +137,23 @@ fn update_settings(conn: DbConn, admin: Admin, form: LenientForm Template { + admin_instances_paginated(admin, conn, Page::first()) +} + +#[get("/admin/instances?")] +fn admin_instances_paginated(admin: Admin, conn: DbConn, page: Page) -> Template { + let instances = Instance::page(&*conn, page.limits()); + Template::render("instance/list", json!({ + "account": admin.0.to_json(&*conn), + "instances": instances, + "instance": Instance::get_local(&*conn), + "page": page.page, + "n_pages": Page::total(Instance::count(&*conn) as i32), + })) +} + #[post("/inbox", data = "")] fn shared_inbox(conn: DbConn, data: String) -> String { let act: serde_json::Value = serde_json::from_str(&data[..]).unwrap(); diff --git a/templates/instance/admin.html.tera b/templates/instance/admin.html.tera index 5c77c32a..3832a958 100644 --- a/templates/instance/admin.html.tera +++ b/templates/instance/admin.html.tera @@ -8,7 +8,8 @@ Administration of {{ instance.name }} {% block content %}

{{ "Administration" | _ }}

-

{{ "Instance settings" | _ }}

+ {{ macros::tabs(links=['/admin', '/admin/instances'], titles=['Configuration', 'Instances'], selected=1) }} +
{{ macros::input(name="name", label="Name", errors=errors, form=form, props='minlenght="1"', default=instance) }} diff --git a/templates/instance/list.html.tera b/templates/instance/list.html.tera new file mode 100644 index 00000000..c534a7df --- /dev/null +++ b/templates/instance/list.html.tera @@ -0,0 +1,31 @@ +{% extends "base" %} +{% import "macros" as macros %} + +{% block title %} +Administration of {{ instance.name }} +{% endblock title %} + +{% block content %} +

{{ "Instances" | _ }}

+ + {{ macros::tabs(links=['/admin', '/admin/instances'], titles=['Configuration', 'Instances'], selected=2) }} + +
+ {% for instance in instances %} + + {% endfor %} +
+ {{ macros::paginate(page=page, total=n_pages) }} +{% endblock content %}