From: Aidan Cornelius-Bell Date: Sat, 14 Sep 2024 23:41:31 +0000 (+0930) Subject: pages; error handling; links updated; logos more places X-Git-Url: https://gitweb.mndrdr.org/?a=commitdiff_plain;h=52b5bc672cb495fc5e5fbae159bf7c75ef694135;p=arelpe.git pages; error handling; links updated; logos more places --- diff --git a/.DS_Store b/.DS_Store index 92ecf43..0695b44 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/app/.DS_Store b/app/.DS_Store index 3031a20..79b88bf 100644 Binary files a/app/.DS_Store and b/app/.DS_Store differ diff --git a/app/assets/.DS_Store b/app/assets/.DS_Store index 893ce86..648e73d 100644 Binary files a/app/assets/.DS_Store and b/app/assets/.DS_Store differ diff --git a/app/assets/images/logo-192.png b/app/assets/images/icon-512.png similarity index 100% rename from app/assets/images/logo-192.png rename to app/assets/images/icon-512.png diff --git a/app/assets/images/missing.svg b/app/assets/images/missing.svg new file mode 100644 index 0000000..a643d27 --- /dev/null +++ b/app/assets/images/missing.svg @@ -0,0 +1,185 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index f4e73da..9e8f4a2 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -260,11 +260,13 @@ footer p { .pagination { margin: 3em 0; + margin: 40px auto; + text-align: center; } -.pagination a { +.pagination a, .pagination .current, .pagination .gap { border: 1px solid var(--link-color); - padding: 2px 8px; + padding: 4px 8px; text-decoration: none; border-radius: 2px; } @@ -281,6 +283,10 @@ footer p { color: var(--link-color); } +.pagination .current, .pagination .gap { + margin-right: 1px; +} + ul li { list-style: none; margin-left: 2em; diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 0000000..73f7461 --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,59 @@ +class PagesController < ApplicationController + include AdminAuthenticatable + before_action :set_page, only: %i[ show edit update destroy ] + + # GET /pages + def index + @pages = Page.all + end + + # GET /pages/1 + def show + end + + # GET /pages/new + def new + @page = Page.new + end + + # GET /pages/1/edit + def edit + end + + # POST /pages + def create + @page = Page.new(page_params) + + if @page.save + redirect_to @page, notice: "Page was successfully created." + else + render :new, status: :unprocessable_entity + end + end + + # PATCH/PUT /pages/1 + def update + if @page.update(page_params) + redirect_to @page, notice: "Page was successfully updated.", status: :see_other + else + render :edit, status: :unprocessable_entity + end + end + + # DELETE /pages/1 + def destroy + @page.destroy! + redirect_to pages_url, notice: "Page was successfully destroyed.", status: :see_other + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_page + @page = Page.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def page_params + params.require(:page).permit(:title, :slug, :content, :visibility) + end +end diff --git a/app/controllers/pubview_controller.rb b/app/controllers/pubview_controller.rb index 269ca3d..2e84fbe 100644 --- a/app/controllers/pubview_controller.rb +++ b/app/controllers/pubview_controller.rb @@ -1,5 +1,7 @@ class PubviewController < ApplicationController def index + @pages = Page.where(visibility: :visible) + @per_page = 15 @page = params[:page].to_i || 1 @filter = params[:filter] || 'all' @@ -8,6 +10,22 @@ class PubviewController < ApplicationController @total_pages = @items.total_pages @current_page = @items.current_page end + + def show_public + if current_user&.admin? + @page = Page.find_by(slug: params[:slug], visibility: ['visible', 'user_only', 'admin_only']) + elsif current_user + @page = Page.find_by(slug: params[:slug], visibility: ['visible', 'user_only']) + else + @page = Page.find_by(slug: params[:slug], visibility: :visible) + end + if @page + render 'show_public' + else + @missing = "page" + render 'error/error', status: :not_found + end + end def post start_date = Date.new(params[:year].to_i, 1, 1) @@ -21,7 +39,8 @@ class PubviewController < ApplicationController @tags = @post.format_tags @rendered_content = @post.rendered_content else - render file: "#{Rails.root}/public/404.html", layout: false, status: :not_found + @missing = "post" + render 'error/error', status: :not_found, missing: 'post' end end diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb new file mode 100644 index 0000000..2c057fd --- /dev/null +++ b/app/helpers/pages_helper.rb @@ -0,0 +1,2 @@ +module PagesHelper +end diff --git a/app/models/page.rb b/app/models/page.rb new file mode 100644 index 0000000..637c50e --- /dev/null +++ b/app/models/page.rb @@ -0,0 +1,19 @@ +class Page < ApplicationRecord + enum visibility: { + hidden: 0, + visible: 1, + user_only: 2, + admin_only: 3 + }, _default: :hidden + + validates :title, presence: true + validates :slug, presence: true, uniqueness: true, format: { with: /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/, message: "can only contain lowercase letters, numbers, and hyphens" } + + before_validation :generate_slug, if: -> { slug.blank? && title.present? } + + private + + def generate_slug + self.slug = title.parameterize + end +end \ No newline at end of file diff --git a/app/views/devise/base_template.html.erb b/app/views/devise/base_template.html.erb index f26c9a3..318e63c 100644 --- a/app/views/devise/base_template.html.erb +++ b/app/views/devise/base_template.html.erb @@ -4,7 +4,7 @@ <%= yield(:form_content) %> diff --git a/app/views/error/error.html.erb b/app/views/error/error.html.erb new file mode 100644 index 0000000..040f76f --- /dev/null +++ b/app/views/error/error.html.erb @@ -0,0 +1,16 @@ +
+ <%= link_to root_path do %> + <%= image_tag "icon-512.png", class: "logo" %> + <% end %> +

Not found

+
+ +
+
+ <%= image_tag "missing.svg", class: "porter" %> +

Gone missing!

+

Terribly sorry, but the <%= @missing.present? ? @missing : "page" %> you have requested cannot be found (or, perhaps, may have lived up to its ephemeral status and vanished more recently).

+

If you desperately needed to have whatever this once was, <%= link_to "try logging in", new_user_session_path %>, or emailing me.

+

In the meanwhile, you can go back to the <%= link_to "home page", root_url %> to try some other content.

+
+
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 34210b6..b441a45 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -3,7 +3,7 @@ - <%= content_for?(:title) ? yield(:title) : "Aidan shares stuff" %> + <%= content_for?(:title) ? yield(:title) : "mind reader :: aidan's sharing project" %> <% if content_for?(:meta_description) %> @@ -18,14 +18,26 @@ <%= stylesheet_link_tag "application" %> - <%= auto_discovery_link_tag(:rss, rss_url, title: "Aidan has Ideas (Links+Posts)") %> + <%= auto_discovery_link_tag(:rss, rss_url, title: "mind reader (bookmarks and dispatch excerpts)") %> + <%= auto_discovery_link_tag(:rss, dispatches_rss_url, title: "mind reader (full dispatches)") %> + + <% if ['posts', 'pages'].include?(controller.controller_name) %> + + + <% end %> + <% if notice or alert %> +
+

Notice:

+

<%= notice or alert %>

+
+ <% end %> <%= yield %> diff --git a/app/views/pages/_form.html.erb b/app/views/pages/_form.html.erb new file mode 100644 index 0000000..7e50f8d --- /dev/null +++ b/app/views/pages/_form.html.erb @@ -0,0 +1,48 @@ +
+
+ <%= form_with(model: page) do |form| %> + <% if page.errors.any? %> +
+

<%= pluralize(page.errors.count, "error") %> prohibited this page from being saved:

+
    + <% page.errors.each do |error| %> +
  • <%= error.full_message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :title, style: "display: block" %> + <%= form.text_field :title %> +
+ +
+ <%= form.label :slug, style: "display: block" %> + <%= form.text_field :slug %> +
+ +
+ <%= form.label :content, style: "display: block" %> + <%= form.text_area :content, class: 'markdown-editor' %> +
+ +
+ <%= form.label :visibility, style: "display: block" %> + <%= form.select :visibility, Page.visibilities.keys.map { |visibility| [visibility.titleize, visibility] } %> +
+ +
+ <%= form.submit %> +
+ <% end %> +
+
+ + \ No newline at end of file diff --git a/app/views/pages/_page.html.erb b/app/views/pages/_page.html.erb new file mode 100644 index 0000000..f666ff9 --- /dev/null +++ b/app/views/pages/_page.html.erb @@ -0,0 +1,22 @@ +
+

+ Title: + <%= page.title %> +

+ +

+ Slug: + <%= page.slug %> +

+ +

+ Content: + <%= page.content %> +

+ +

+ Visibility: + <%= page.visibility %> +

+ +
diff --git a/app/views/pages/edit.html.erb b/app/views/pages/edit.html.erb new file mode 100644 index 0000000..cae786a --- /dev/null +++ b/app/views/pages/edit.html.erb @@ -0,0 +1,8 @@ +
+ <% content_for :title, "Editing page" %> +

Editing page

+ <%= link_to "Show this page", @page, class: "button" %> + <%= link_to "Back to pages", pages_path, class: "button" %> +
+ +<%= render "form", page: @page %> diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb new file mode 100644 index 0000000..0bd4b6b --- /dev/null +++ b/app/views/pages/index.html.erb @@ -0,0 +1,40 @@ +
+ <% content_for :title, "pages" %> +

Pages

+ <%= link_to "New page", new_page_path, class: "button" %> <%= link_to "Home", root_path, class: "button" %> +
+ +
+
+ + + + + + + + + + + <% @pages.each do |page| %> + + + + + + + <% end %> + +
TitleSlugCreatedActions
<%= page.title %><%= page.slug %><%= page.created_at.strftime("%Y-%m-%d %H:%M") %> + <%= link_to "View", page, class: "button small" %> + <%= link_to "Edit", edit_page_path(page), class: "button small" %> + <%= link_to "Delete", page, method: :delete, data: { confirm: "Are you sure you want to delete this page?" }, class: "button small danger" %> +
+
+
+ +<% if @pages.respond_to?(:total_pages) %> +
+ <%= paginate @pages %> +
+<% end %> \ No newline at end of file diff --git a/app/views/pages/new.html.erb b/app/views/pages/new.html.erb new file mode 100644 index 0000000..274e43b --- /dev/null +++ b/app/views/pages/new.html.erb @@ -0,0 +1,8 @@ +
+ <% content_for :title, "New page" %> +

New page

+ <%= link_to "Back to pages", pages_path, class: "button" %> +
+ +<%= render "form", page: @page %> + diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb new file mode 100644 index 0000000..9d67ad1 --- /dev/null +++ b/app/views/pages/show.html.erb @@ -0,0 +1,13 @@ +
+ <% content_for :title, "Viewing page" %> +

Page details

+ <%= link_to "Edit this page", edit_page_path(@page), class: "button" %> + <%= link_to "Back to pages", pages_path, class: "button" %> + <%= button_to "Destroy this page", @page, method: :delete %> +
+ +
+
+ <%= render @page %> +
+
\ No newline at end of file diff --git a/app/views/posts/_form.html.erb b/app/views/posts/_form.html.erb index e9688af..dc31e1b 100644 --- a/app/views/posts/_form.html.erb +++ b/app/views/posts/_form.html.erb @@ -27,7 +27,7 @@
<%= form.label :content %> - <%= form.text_area :content, rows: 10 %> + <%= form.text_area :content, class: 'markdown-editor', rows: 10 %>
@@ -63,6 +63,12 @@ function toggleFields() { Array.from(dispatchFields).forEach(field => field.style.display = 'none'); Array.from(bookmarkFields).forEach(field => field.style.display = 'block'); } + + // Reinitialize SimpleMDE for newly displayed fields + var elements = document.querySelectorAll('.markdown-editor:not(.CodeMirror)') + elements.forEach(function(element) { + new SimpleMDE({ element: element }) + }) } function fetchTitle() { diff --git a/app/views/pubview/index.html.erb b/app/views/pubview/index.html.erb index f78ca14..aa7e646 100644 --- a/app/views/pubview/index.html.erb +++ b/app/views/pubview/index.html.erb @@ -1,12 +1,6 @@
-<% if notice or alert %> -
-

Notice:

-

<%= notice or alert %>

-
-<% end %> <%= link_to root_path do %> - <%= image_tag "logo-192.png", class: "logo" %> + <%= image_tag "icon-512.png", class: "logo" %> <% end %>

mind reader

Aidan’s anti-capitalist posting and sharing project

@@ -18,7 +12,12 @@ <%= link_to "Bookmarks", root_path(filter: 'bookmarks'), class: "button #{@filter == 'bookmarks' ? 'active' : ''}" %> <% if current_user&.admin? %> <%= link_to "Manage Posts", posts_path, class: "button" %> + <%= link_to "Manage Pages", pages_path, class: "button" %> <%= link_to "Manage API Keys", api_keys_path, class: "button" %> + <% else %> + <% @pages.each do |pg| %> + <%= link_to "#{pg.title}", public_page_path(pg.slug), class: "button" %> + <% end %> <% end %>
@@ -50,8 +49,8 @@
<%= paginate @items %>
\ No newline at end of file diff --git a/app/views/pubview/post.html.erb b/app/views/pubview/post.html.erb index d5d8cee..0751655 100644 --- a/app/views/pubview/post.html.erb +++ b/app/views/pubview/post.html.erb @@ -1,7 +1,10 @@
<%= link_to root_path do %> - <%= image_tag "logo-192.png", class: "logo" %> + <%= image_tag "icon-512.png", class: "logo" %> <% end %> + <% content_for :title, @post.title %> + <% content_for :meta_description, "#{@post.generate_excerpt(150)}." %> + <% content_for :meta_keywords, "#{@post.tags}" %>

<%= @post.title %>

<%= link_to "↼ Back to some other ideas...", root_path %>