Skip to content

Commit

Permalink
Fix admin panel JS not working (#28)
Browse files Browse the repository at this point in the history
Fix admin panel JS not working.

Note #3 still means there isn't a workable test suite yet.
  • Loading branch information
jfi authored Oct 14, 2024
1 parent de1dc68 commit 30b5ed1
Show file tree
Hide file tree
Showing 35 changed files with 331 additions and 363 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"titleBar.activeBackground": "#8d5eb7",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#8d5eb799",
"titleBar.inactiveForeground": "#e7e7e799"
"titleBar.inactiveForeground": "#e7e7e799",
"statusBar.background": "#8d5eb7"
}
}
110 changes: 0 additions & 110 deletions CONTRIBUTING.md

This file was deleted.

2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ GEM
activesupport (>= 7.0.0)
rack
railties (>= 7.0.0)
pstore (0.1.3)
psych (5.1.2)
stringio
public_suffix (6.0.1)
Expand Down Expand Up @@ -686,6 +687,7 @@ DEPENDENCIES
msgpack (~> 1.7)
panda_cms!
propshaft (~> 1.0)
pstore
puma (~> 6.4)
rails-route-checker (~> 0.6)
rspec-github (~> 2.4)
Expand Down
2 changes: 1 addition & 1 deletion app/components/panda_cms/admin/flash_message_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def text_colour_css
when :warning
"text-warning"
when :info, :notice
"text-highlight"
"text-active"
else
"text-mid"
end
Expand Down
55 changes: 1 addition & 54 deletions app/controllers/panda_cms/admin/menus_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
module PandaCms
module Admin
class MenusController < ApplicationController
before_action :set_initial_breadcrumb, only: %i[index new edit create update]
before_action :set_paper_trail_whodunnit, only: %i[create update]
before_action :set_initial_breadcrumb, only: %i[index]
before_action :authenticate_admin_user!

# Lists all menus which can be managed by the administrator
Expand All @@ -15,47 +14,6 @@ def index
render :index, locals: {menus: menus}
end

# Loads the menu editor
# @type GET
def edit
add_breadcrumb menu.name, edit_admin_menu_path(menu)
end

# GET /admin/menus/new
# @type GET
def new
@menu = PandaCms::Menu.new
@menu.menu_items.new
set_new_menu_breadcrumb
end

# POST /admin/menus
def create
@menu = PandaCms::Menu.new(menu_params)

if @menu.save
redirect_to admin_menus_path, notice: "Menu was successfully created."
else
flash[:error] = @menu.errors.full_messages.join(", ")
set_new_menu_breadcrumb
render :new, status: :unprocessable_entity
end
end

# @type PATCH/PUT
# @return
def update
if menu.update!(menu_params)
redirect_to edit_admin_menu_path(menu),
status: :see_other,
flash: {success: "This menu was successfully updated!"}
else
add_breadcrumb menu.name, edit_admin_menu_path(menu)
flash[:error] = "There was an error updating the menu."
render :edit, status: :unprocessable_entity
end
end

private

def menu
Expand All @@ -65,17 +23,6 @@ def menu
def set_initial_breadcrumb
add_breadcrumb "Menus", admin_menus_path
end

def set_new_menu_breadcrumb
add_breadcrumb "Add New Menu", new_admin_menu_path
end

# Only allow a list of trusted parameters through.
# @type private
# @return ActionController::StrongParameters
def menu_params
params.require(:menu).permit(:name, menu_items_attributes: %i[id text external_url sort_order panda_cms_page_id _destroy])
end
end
end
end
9 changes: 2 additions & 7 deletions app/javascript/panda_cms/controllers/slug_controller.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<<<<<<<< HEAD:app/javascript/panda_cms/controllers/slug_controller.js
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
========
import { Controller as PandaCmsController } from "@hotwired/stimulus";

export class TextFieldUpdateController extends PandaCmsController {
>>>>>>>> 051dfc5 (Improve rich text editor support):app/javascript/panda_cms/controllers/text_field_update_controller.js
static targets = [
"existing_root",
"input_select",
"input_text",
"output_text",
];

connect() {}
connect() {
}

generatePath() {
this.output_textTarget.value = "/" + this.createSlug(this.input_textTarget.value);
Expand Down
35 changes: 35 additions & 0 deletions app/javascript/panda_cms/panda_cms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Application as PandaCmsApplication } from "@hotwired/stimulus"

const pandaCmsApplication = PandaCmsApplication.start()

// Configure Stimulus development experience
pandaCmsApplication.debug = false
window.pandaStimulus = pandaCmsApplication

// Eager load all controllers defined in the import map under controllers/**/*_controller
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", pandaCmsApplication)

import {
Alert,
Autosave,
ColorPreview,
Dropdown,
Modal,
Tabs,
Popover,
Toggle,
Slideover,
} from "tailwindcss-stimulus-components"

pandaCmsApplication.register("alert", Alert)
pandaCmsApplication.register("autosave", Autosave)
pandaCmsApplication.register("color-preview", ColorPreview)
pandaCmsApplication.register("dropdown", Dropdown)
pandaCmsApplication.register("modal", Modal)
pandaCmsApplication.register("popover", Popover)
pandaCmsApplication.register("slideover", Slideover)
pandaCmsApplication.register("tabs", Tabs)
pandaCmsApplication.register("toggle", Toggle)

export { pandaCmsApplication }
36 changes: 0 additions & 36 deletions app/javascript/panda_cms/panda_cms_base.js

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion app/lib/panda_cms/slug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Slug
#
# @param string [String] The provided string to turn into a slug
# @return string Generated slug
# @see text_field_update_controller.js should also implement this logic
# @see slug_controller.js should also implement this logic
def self.generate(string)
# Trim whitespace and downcase the string
string = string.to_s.strip.downcase
Expand Down
13 changes: 6 additions & 7 deletions app/views/panda_cms/admin/forms/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<%= render PandaCms::Admin::ContainerComponent.new do |component| %>
<% component.with_heading(text: "Add Page", level: 1) do |heading| %>
<% end %>

<%= panda_cms_form_with model: page, url: admin_pages_path, method: :post do |f| %>
<% options = nested_set_options(PandaCms::Page, page) { |i| "#{"-" * i.level} #{i.title} (#{i.path})" } %>
<div data-controller="text-field-update">
<input type="hidden" value="<%= PandaCms::Current.root %>" data-text-field-update-target="existing_root">
<%= f.select :parent_id, options, {}, { "data-text-field-update-target": "input_select", "data-action": "change->text-field-update#setPrePath" } %>
<%= f.text_field :title, { data: { "text-field-update-target": "input_text", action: "focusout->text-field-update#generatePath" } } %>
<%= f.text_field :path, { data: { prefix: PandaCms::Current.root, "text-field-update-target": "output_text" } } %>
<% options = nested_set_options(PandaCms::Page, page) { |i| "#{"-" * i.level} #{i.title} (#{i.path})" } %>
<div data-controller="slug">
<input type="hidden" value="<%= PandaCms::Current.root %>" data-slug-target="existing_root">
<%= f.select :parent_id, options, {}, { "data-slug-target": "input_select", "data-action": "change->slug#setPrePath" } %>
<%= f.text_field :title, { data: { "slug-target": "input_text", action: "focusout->slug#generatePath" } } %>
<%= f.text_field :path, { data: { prefix: PandaCms::Current.root, "slug-target": "output_text" } } %>
<%= f.collection_select :panda_cms_template_id, PandaCms::Template.available, :id, :name %>
<%= f.button %>
</div>
Expand Down
21 changes: 0 additions & 21 deletions app/views/panda_cms/admin/menus/_form.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/panda_cms/admin/menus/_menu_item_fields.html.erb

This file was deleted.

Loading

0 comments on commit 30b5ed1

Please sign in to comment.