Skip to content

Commit

Permalink
Remove categories
Browse files Browse the repository at this point in the history
  • Loading branch information
elektronaut committed May 8, 2024
1 parent b8bf7de commit 1d053e6
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 172 deletions.
56 changes: 0 additions & 56 deletions app/controllers/admin/categories_controller.rb

This file was deleted.

19 changes: 2 additions & 17 deletions app/controllers/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Admin
class PagesController < Admin::AdminController
include PagesCore::Admin::PageJsonHelper

before_action :find_categories
before_action :find_page, only: %i[show edit update destroy move]

require_authorization
Expand Down Expand Up @@ -39,8 +38,7 @@ def new
def edit; end

def create
@page = build_page(content_locale, page_params,
param_categories).tap(&:save)
@page = build_page(content_locale, page_params).tap(&:save)
if @page.valid?
respond_with_page(@page) do
redirect_to(edit_admin_page_url(content_locale, @page))
Expand All @@ -52,7 +50,6 @@ def create

def update
if @page.update(page_params)
@page.categories = param_categories
respond_with_page(@page) do
flash[:notice] = t("pages_core.changes_saved")
redirect_to edit_admin_page_url(content_locale, @page)
Expand All @@ -75,11 +72,10 @@ def destroy

private

def build_page(locale, attributes = nil, categories = nil)
def build_page(locale, attributes = nil)
Page.new.localize(locale).tap do |page|
page.author = default_author || current_user
page.attributes = attributes if attributes
page.categories = categories if categories
end
end

Expand All @@ -103,21 +99,10 @@ def page_params
)
end

def param_categories
return [] unless params[:category]

params.permit(category: {})[:category].to_hash
.map { |id, _| Category.find(id) }
end

def find_page
@page = Page.find(params[:id]).localize(content_locale)
end

def find_categories
@categories = Category.order("name")
end

def respond_with_page(page, &block)
respond_to do |format|
format.html(&block)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/pages_core/frontend_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def root_page
@root_page ||= root_pages.first
end

attr_reader :search_query, :search_category_id
attr_reader :search_query
end
end
22 changes: 0 additions & 22 deletions app/models/category.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class Page < ApplicationRecord
optional: true,
inverse_of: :pages

has_many :page_categories, dependent: :destroy
has_many :categories, through: :page_categories

validates(:unique_name,
format: { with: /\A[\w\d_-]+\z/,
allow_blank: true },
Expand Down
6 changes: 0 additions & 6 deletions app/models/page_category.rb

This file was deleted.

6 changes: 2 additions & 4 deletions app/views/admin/news/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
<h2>
<%= link_to_unless_current(
year,
admin_news_index_path(locale, year: year, category: category&.slug)
admin_news_index_path(locale, year: year)
) %>
<%= ": #{@category.name}" if @category %>
<span class="count">
(<%= year_count %>)
</span>
Expand All @@ -37,8 +36,7 @@
<% else %>
<%= link_to(
month_name(month),
admin_news_index_path(locale, year: year, month: month,
category: category&.slug)
admin_news_index_path(locale, year: year, month: month)
) %>
<span class="count">
(<%= page_count %>)
Expand Down
1 change: 0 additions & 1 deletion app/views/admin/news/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<%= render(partial: "sidebar",
locals: {
locale: content_locale,
category: @category,
news_pages: @news_pages,
archive_finder: @archive_finder
}) %>
Expand Down
12 changes: 0 additions & 12 deletions app/views/admin/pages/_edit_options.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@
Make post featured<br />
</div>

<% if @categories.length > 0 %>
<div class="field">
<label>Categories</label>
<% @categories.each do |category| %>
<%= check_box_tag("category[#{category.id}]",
"1",
@page.categories.map { |c| c.id }.include?(category.id)) %>
<%= category.name %><br />
<% end %>
</div>
<% end %>

<%= labelled_field(f.select(:template, available_templates_for_select),
"Template",
errors: @page.errors[:template]) %>
Expand Down
4 changes: 0 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ en:
image: Profile picture
pages_core:
account_holder_exists: Account holder already exists
categories_controller:
created: New category created
deleted: Category was deleted
updated: Category was updated
changes_saved: Your changes were saved
invalid_login: >
The provided email address and password combination was not valid
Expand Down
3 changes: 0 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@
end
end

# Categories
resources :categories

# Authentication
resource :session, only: %i[create destroy] do
member { post :verify_otp }
Expand Down
21 changes: 21 additions & 0 deletions db/migrate/20240508145300_remove_categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class RemoveCategories < ActiveRecord::Migration[7.0]
def change
drop_table :page_categories do |t|
t.integer :page_id
t.integer :category_id
t.index :category_id
t.index :page_id
end

drop_table :categories do |t|
t.string :name
t.string :slug
t.integer :position
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.index :slug
end
end
end
4 changes: 0 additions & 4 deletions spec/factories/factories.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# frozen_string_literal: true

FactoryBot.define do
factory :category do
sequence(:name) { |n| "Category #{n}" }
end

factory :image do
locale { "en" }
file do
Expand Down
18 changes: 1 addition & 17 deletions spec/internal/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_02_01_160700) do
ActiveRecord::Schema[7.1].define(version: 2024_05_08_145300) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
enable_extension "pg_trgm"
Expand All @@ -27,15 +27,6 @@
t.integer "user_id"
end

create_table "categories", id: :serial, force: :cascade do |t|
t.string "name"
t.string "slug"
t.integer "position"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["slug"], name: "index_categories_on_slug"
end

create_table "delayed_jobs", id: :serial, force: :cascade do |t|
t.integer "priority", default: 0
t.integer "attempts", default: 0
Expand Down Expand Up @@ -117,13 +108,6 @@
t.index ["localizable_id", "localizable_type"], name: "index_localizations_on_localizable_id_and_localizable_type"
end

create_table "page_categories", id: :serial, force: :cascade do |t|
t.integer "page_id"
t.integer "category_id"
t.index ["category_id"], name: "index_page_categories_on_category_id"
t.index ["page_id"], name: "index_page_categories_on_page_id"
end

create_table "page_files", id: :serial, force: :cascade do |t|
t.bigint "page_id"
t.bigint "attachment_id"
Expand Down
22 changes: 0 additions & 22 deletions spec/models/category_spec.rb

This file was deleted.

0 comments on commit 1d053e6

Please sign in to comment.