diff --git a/lib/volumen/admin_routes.rb b/lib/volumen/admin_routes.rb index 5aa9f21..d7925af 100644 --- a/lib/volumen/admin_routes.rb +++ b/lib/volumen/admin_routes.rb @@ -3,6 +3,7 @@ module Volumen # Server-rendered admin routes, registered into Volumen::Server. module AdminRoutes + # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def self.registered(app) app.get "/admin" do redirect to("/admin/") @@ -11,6 +12,7 @@ module Volumen app.get "/admin/" do require_login! @posts = sorted_posts + @crumbs = [["Posts", nil]] erb :list end @@ -43,6 +45,7 @@ module Volumen require_login! @mode = :new @post = Post.new(metadata: { "lang" => config.language }) + @crumbs = [["Posts", to("/admin/")], ["New post", nil]] erb :form end @@ -57,6 +60,8 @@ module Volumen @mode = :edit @post = store.find(params["slug"]) halt(404, "Not found") if @post.nil? + title = @post.title.to_s.empty? ? params["slug"] : @post.title + @crumbs = [["Posts", to("/admin/")], [title, nil]] erb :form end @@ -106,6 +111,7 @@ module Volumen app.get "/admin/settings" do require_login! + @crumbs = [["Settings", nil]] render_settings end @@ -141,6 +147,7 @@ module Volumen check_csrf! remove_user(params["username"]) end + # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity end end end diff --git a/lib/volumen/web/views/form.erb b/lib/volumen/web/views/form.erb index 3514062..d79e3cd 100644 --- a/lib/volumen/web/views/form.erb +++ b/lib/volumen/web/views/form.erb @@ -1,108 +1,190 @@ -

<%= @mode == :new ? "New post" : "Edit post" %>

+<% + crumbs = @mode == :new ? [["Posts", to("/admin/")], ["New post", nil]] : [["Posts", to("/admin/")], [@post.title.to_s.empty? ? "Untitled" : @post.title, nil]] +%> + +
+
+

<%= @mode == :new ? "New post" : "Edit post" %>

+

<%= @mode == :new ? "Draft a new article in Markdown." : "Update and publish this post." %>

+
+
+ <% if @mode == :edit %> + " target="_blank"> + + Preview + + <% end %> + ">Cancel + +
+
<% if @error %> -

<%= h(@error) %>

+
+ +
<%= h(@error) %>
+
<% end %>
"> -
- - - - - - - - - - -
- -
- -
- - - -
- - - - -
- -
- - -
- - - -
-
-
-
- - - - - - - - - +
+
+
+
+

Details

+

Title, slug, and publishing options

-
-
-
Preview
-
+ +
+ + +
+ +
+
+ + placeholder="my-post-slug"> +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + "> +

Leave empty to publish immediately

+
+
+ + " placeholder="comma, separated"> +
+
+ +
+ + +

Auto-generated from the first paragraph if left empty

+
+ +
+ + +
+
+ +
+
+
+

Cover image

+

Header image shown on the article page

+
+
+
+
+ + + +
+ + + + +
+
+ +
+
+ + +
+ + + +
+
+
+
+ Markdown + + + + + + + + + + +
+ +
+
+
+ Preview +
+
+
+
- diff --git a/lib/volumen/web/views/layout.erb b/lib/volumen/web/views/layout.erb index d5a79cb..3b619f3 100644 --- a/lib/volumen/web/views/layout.erb +++ b/lib/volumen/web/views/layout.erb @@ -4,251 +4,552 @@ volumen admin + + - -
-
- <%= yield %> + <% if request.path_info == "/admin/login" || (defined?(login_page) && login_page) %> + -
+ <% else %> +
+ +
+
+ <% if defined?(@crumbs) && @crumbs %> + + <% end %> + +
+
+ <%= yield %> +
+
+
+ <% end %> diff --git a/lib/volumen/web/views/list.erb b/lib/volumen/web/views/list.erb index a6f363a..aeda6ad 100644 --- a/lib/volumen/web/views/list.erb +++ b/lib/volumen/web/views/list.erb @@ -1,34 +1,113 @@ +
+
+

Posts

+

<%= @posts.length %> post<%= @posts.length == 1 ? "" : "s" %> in total

+
+ "> + + New post + +
+
-

Posts

- ">New post + +
+ + + + +
<% if @posts.empty? %> -

No posts yet. Create your first one.

+
+ +

No posts yet

+

Create your first post to get started.

+ " style="margin-top: 0.75rem;">Create post +
<% else %> - - - - - - <% @posts.each do |post| %> - - - - - - - - - <% end %> - -
TitleSlugLangDateDraft
<%= h(post.title) %><%= h(post.slug) %><%= h(post.lang) %><%= h(post.date_string) %><%= post.draft? ? "yes" : "" %> - ">Edit -
" - onsubmit="return confirm('Delete this post?');"> - - -
-
+
+ <% @posts.each do |post| %> + <% + status = if post.draft? + "draft" + elsif post.scheduled? + "scheduled" + else + "published" + end + %> + " + class="post-card" + data-title="<%= h(post.title.to_s.downcase) %>" + data-slug="<%= h(post.slug) %>" + data-status="<%= status %>"> + <% if post.cover %> +
+ <% else %> +
+ +
+ <% end %> +
+

<%= h(post.title) %>

+ <% if post.excerpt && !post.excerpt.to_s.empty? %> +

<%= h(post.excerpt) %>

+ <% end %> + +
+
+ Edit + +
" + onsubmit="return confirm('Delete this post?');" style="margin: 0;"> + + +
+
+
+ <% end %> +
<% end %> + + diff --git a/lib/volumen/web/views/login.erb b/lib/volumen/web/views/login.erb index 80d7c3d..162b00a 100644 --- a/lib/volumen/web/views/login.erb +++ b/lib/volumen/web/views/login.erb @@ -1,23 +1,29 @@ - +

Sign in

+

Welcome back. Sign in to manage your posts.

+ +<% if @error %> +
+ +
<%= h(@error) %>
+
+<% end %> + +<% unless users.any? %> +
+ +
No users configured. Set admin.password_hash in your config or run volumen hash-password.
+
+<% end %> + +
"> + +
+ + +
+
+ + +
+ +
diff --git a/lib/volumen/web/views/settings.erb b/lib/volumen/web/views/settings.erb index 72b0d94..a094865 100644 --- a/lib/volumen/web/views/settings.erb +++ b/lib/volumen/web/views/settings.erb @@ -1,49 +1,89 @@ -

Settings

+
+
+

Settings

+

Manage your account and users

+
+
-<% if @notice %>

<%= h(@notice) %>

<% end %> -<% if @error %>

<%= h(@error) %>

<% end %> +<% if @notice %> +
+ +
<%= h(@notice) %>
+
+<% end %> +<% if @error %> +
+ +
<%= h(@error) %>
+
+<% end %> -
-

Your account

-

Signed in as <%= h(current_user) %> (<%= h(current_role) %>).

+
+
+
+

Your account

+

Signed in as <%= h(current_user) %> · <%= h(current_role) %>

+
+
"> -

Change password

- - - +

Change password

+
+
+ + +
+
+ + +
+
+
+
+
"> -

Change username

- - +

Change username

+
+ + +
+
-
+
<% if admin? %> -
-

Users

- - +
+
+
+

Users

+

Add or remove admin and editor accounts

+
+
+ +
UsernameRole
+ + + <% @users.each do |user| %> - + - @@ -66,21 +107,30 @@
UsernameRole
<%= h(user.username) %><%= user.username == current_user ? " (you)" : "" %> + <%= h(user.username) %> + <% if user.username == current_user %>you<% end %> + <% if user.username == current_user %> - <%= h(user.role) %> + <%= h(user.role) %> <% else %> -
"> + " + style="margin: 0;"> - <% Volumen::Users::ROLES.each do |role| %> <% end %> @@ -51,13 +91,14 @@
<% end %>
+ <% unless user.username == current_user %> -
" - onsubmit="return confirm('Remove this user?');"> + onsubmit="return confirm('Remove this user?');" + style="margin: 0;"> - +
<% end %>
+
+
"> -

Add user

-
- - -
+
+ + +
+
+ + - +
- + - +
<% end %>