platform links
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
ActiveAdmin.register PlatformLink do
|
||||
permit_params :name, :url, :platform, :position
|
||||
|
||||
menu priority: 5, label: "🔗 Platform Links"
|
||||
|
||||
config.sort_order = "platform_asc"
|
||||
|
||||
scope :all, default: true
|
||||
scope("TIC-80") { |s| s.where(platform: "tic80") }
|
||||
scope("Ebitengine") { |s| s.where(platform: "ebitengine") }
|
||||
scope("LOVE") { |s| s.where(platform: "love") }
|
||||
scope("C64") { |s| s.where(platform: "c64") }
|
||||
scope("Godot") { |s| s.where(platform: "godot") }
|
||||
scope("Bevy") { |s| s.where(platform: "bevy") }
|
||||
scope("Phaser") { |s| s.where(platform: "phaser") }
|
||||
|
||||
index do
|
||||
selectable_column
|
||||
id_column
|
||||
column :platform
|
||||
column :name
|
||||
column(:url) { |pl| link_to pl.url, pl.url, target: "_blank" }
|
||||
column :position
|
||||
column :created_at
|
||||
actions
|
||||
end
|
||||
|
||||
filter :platform, as: :select, collection: %w[tic80 ebitengine love c64 godot bevy phaser]
|
||||
filter :name
|
||||
|
||||
form do |f|
|
||||
f.inputs do
|
||||
f.input :platform, as: :select, collection: %w[tic80 ebitengine love c64 godot bevy phaser]
|
||||
f.input :name
|
||||
f.input :url
|
||||
f.input :position, as: :number, input_html: { min: 0 }
|
||||
end
|
||||
f.actions
|
||||
end
|
||||
|
||||
show do
|
||||
attributes_table do
|
||||
row :id
|
||||
row :platform
|
||||
row :name
|
||||
row(:url) { |pl| link_to pl.url, pl.url, target: "_blank" }
|
||||
row :position
|
||||
row :created_at
|
||||
row :updated_at
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
class PlatformLink < ApplicationRecord
|
||||
self.table_name = "platform_links"
|
||||
|
||||
SUPPORTED_PLATFORMS = %w[tic80 ebitengine love c64 godot bevy phaser].freeze
|
||||
|
||||
validates :name, presence: true
|
||||
validates :url, presence: true
|
||||
validates :platform, presence: true, inclusion: { in: SUPPORTED_PLATFORMS }
|
||||
|
||||
default_scope { where(deleted_at: nil).order(:position) }
|
||||
|
||||
def self.ransackable_attributes(auth_object = nil)
|
||||
%w[created_at deleted_at id name platform position updated_at url]
|
||||
end
|
||||
|
||||
def self.ransackable_associations(auth_object = nil)
|
||||
[]
|
||||
end
|
||||
|
||||
def self.for_platform(platform)
|
||||
where(platform: platform).to_a
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
class PlatformLinkSerializer < Blueprinter::Base
|
||||
field :name
|
||||
field :url
|
||||
end
|
||||
@@ -16,6 +16,7 @@ class SoftwareSerializer < Blueprinter::Base
|
||||
field :status
|
||||
field(:highlighted) { |sw| sw.highlighted ? true : false }
|
||||
field(:externalLinks) { |sw| ExternalLinkSerializer.render_as_hash(sw.external_links) }
|
||||
field(:platformLinks) { |sw| PlatformLinkSerializer.render_as_hash(PlatformLink.for_platform(sw.platform)) }
|
||||
field(:imageUrl) { |sw|
|
||||
si = sw.software_images.detect(&:is_default?) || sw.software_images.first
|
||||
si ? "/api/image/#{si.image_id}" : nil
|
||||
|
||||
Reference in New Issue
Block a user