Wip: bookmark statuses view and adder
This commit is contained in:
parent
f6bdd9b6de
commit
87490a3220
30 changed files with 616 additions and 24 deletions
29
app/models/bookmark_category.rb
Normal file
29
app/models/bookmark_category.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: bookmark_categories
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8) not null
|
||||
# title :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class BookmarkCategory < ApplicationRecord
|
||||
include Paginable
|
||||
|
||||
PER_CATEGORY_LIMIT = 20
|
||||
|
||||
belongs_to :account
|
||||
|
||||
has_many :bookmark_category_statuses, inverse_of: :bookmark_category, dependent: :destroy
|
||||
has_many :statuses, through: :bookmark_category_statuses
|
||||
|
||||
validates :title, presence: true
|
||||
|
||||
validates_each :account_id, on: :create do |record, _attr, value|
|
||||
record.errors.add(:base, I18n.t('bookmark_categories.errors.limit')) if BookmarkCategory.where(account_id: value).count >= PER_CATEGORY_LIMIT
|
||||
end
|
||||
end
|
34
app/models/bookmark_category_status.rb
Normal file
34
app/models/bookmark_category_status.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: bookmark_category_statuses
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# bookmark_category_id :bigint(8) not null
|
||||
# status_id :bigint(8) not null
|
||||
# bookmark_id :bigint(8)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class BookmarkCategoryStatus < ApplicationRecord
|
||||
belongs_to :bookmark_category
|
||||
belongs_to :status
|
||||
belongs_to :bookmark
|
||||
|
||||
validates :status_id, uniqueness: { scope: :bookmark_category_id }
|
||||
validate :validate_relationship
|
||||
|
||||
before_validation :set_bookmark
|
||||
|
||||
private
|
||||
|
||||
def set_bookmark
|
||||
self.bookmark = Bookmark.find_by!(account_id: bookmark_category.account_id, status_id: status_id)
|
||||
end
|
||||
|
||||
def validate_relationship
|
||||
errors.add(:account_id, 'bookmark relationship missing') if bookmark_id.blank?
|
||||
end
|
||||
end
|
|
@ -15,6 +15,9 @@ module AccountAssociations
|
|||
has_many :favourites, inverse_of: :account, dependent: :destroy
|
||||
has_many :emoji_reactions, inverse_of: :account, dependent: :destroy
|
||||
has_many :bookmarks, inverse_of: :account, dependent: :destroy
|
||||
has_many :bookmark_categories, inverse_of: :account, dependent: :destroy
|
||||
has_many :circles, inverse_of: :account, dependent: :destroy
|
||||
has_many :antennas, inverse_of: :account, dependent: :destroy
|
||||
has_many :mentions, inverse_of: :account, dependent: :destroy
|
||||
has_many :notifications, inverse_of: :account, dependent: :destroy
|
||||
has_many :conversations, class_name: 'AccountConversation', dependent: :destroy, inverse_of: :account
|
||||
|
|
|
@ -84,6 +84,8 @@ class Status < ApplicationRecord
|
|||
has_many :referenced_by_status_objects, foreign_key: 'target_status_id', class_name: 'StatusReference', inverse_of: :target_status, dependent: :destroy
|
||||
has_many :referenced_by_statuses, through: :referenced_by_status_objects, class_name: 'Status', source: :status
|
||||
has_many :capability_tokens, class_name: 'StatusCapabilityToken', inverse_of: :status, dependent: :destroy
|
||||
has_many :bookmark_category_relationships, class_name: 'BookmarkCategoryStatus', inverse_of: :status, dependent: :destroy
|
||||
has_many :joined_bookmark_categories, class_name: 'BookmarkCategory', through: :bookmark_category_relationships, source: :bookmark_category
|
||||
|
||||
has_and_belongs_to_many :tags
|
||||
has_and_belongs_to_many :preview_cards
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue