mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
Implement datatables renderer for status data type [SCI-4032]
This commit is contained in:
parent
2024afce4b
commit
e8fdfe7111
7 changed files with 57 additions and 17 deletions
|
@ -1,12 +1,12 @@
|
|||
$.fn.dataTable.render.RepositoryAssetValue = function(data) {
|
||||
var asset = data.data;
|
||||
var asset = data.value;
|
||||
return `
|
||||
<a class="file-preview-link"
|
||||
id="modal_link${asset.id}"
|
||||
data-no-turbolink="true"
|
||||
data-id="true"
|
||||
data-status="asset-present"
|
||||
data-preview-url="${asset.preview_url}"
|
||||
<a class="file-preview-link"
|
||||
id="modal_link${asset.id}"
|
||||
data-no-turbolink="true"
|
||||
data-id="true"
|
||||
data-status="asset-present"
|
||||
data-preview-url="${asset.preview_url}"
|
||||
href="${asset.url}"
|
||||
>
|
||||
${asset.file_name}
|
||||
|
@ -19,7 +19,7 @@ $.fn.dataTable.render.defaultRepositoryAssetValue = function() {
|
|||
};
|
||||
|
||||
$.fn.dataTable.render.RepositoryTextValue = function(data) {
|
||||
return data.data;
|
||||
return data.value;
|
||||
};
|
||||
|
||||
$.fn.dataTable.render.defaultRepositoryTextValue = function() {
|
||||
|
@ -27,9 +27,17 @@ $.fn.dataTable.render.defaultRepositoryTextValue = function() {
|
|||
};
|
||||
|
||||
$.fn.dataTable.render.RepositoryListValue = function(data) {
|
||||
return data.data;
|
||||
return data.value;
|
||||
};
|
||||
|
||||
$.fn.dataTable.render.defaultRepositoryListValue = function() {
|
||||
return '';
|
||||
};
|
||||
|
||||
$.fn.dataTable.render.RepositoryStatusValue = function(data) {
|
||||
return '<i class="repository-status-value-icon">' + data.value.icon + '</i>' + data.value.status;
|
||||
};
|
||||
|
||||
$.fn.dataTable.render.defaultRepositoryStatusValue = function() {
|
||||
return '';
|
||||
};
|
||||
|
|
|
@ -61,6 +61,10 @@
|
|||
padding: 3px 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.repository-status-value-icon {
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.repository-cog {
|
||||
|
|
|
@ -1,12 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RepositoryStatusValue < ApplicationRecord
|
||||
validates :repository_status_item, presence: true
|
||||
|
||||
belongs_to :repository_status_item
|
||||
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User', optional: true,
|
||||
inverse_of: :created_repositroy_status_value
|
||||
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User', optional: true,
|
||||
inverse_of: :modified_repositroy_status_value
|
||||
has_one :repository_cell, as: :value, dependent: :destroy, inverse_of: :value
|
||||
accepts_nested_attributes_for :repository_cell
|
||||
|
||||
validates :repository_status_item, presence: true
|
||||
|
||||
SORTABLE_COLUMN_NAME = 'repository_status_items.status'
|
||||
SORTABLE_VALUE_INCLUDE = { repository_status_value: :repository_status_item }.freeze
|
||||
|
||||
def formatted
|
||||
data
|
||||
end
|
||||
|
||||
def data
|
||||
return nil unless repository_status_item
|
||||
|
||||
"#{repository_status_item.icon} #{repository_status_item.status}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,9 +4,9 @@ module RepositoryDatatable
|
|||
class RepositoryAssetValueSerializer < ActiveModel::Serializer
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
attributes :data, :value_type
|
||||
attributes :value, :value_type
|
||||
|
||||
def data
|
||||
def value
|
||||
asset = object.value.asset
|
||||
{
|
||||
id: asset.id,
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
module RepositoryDatatable
|
||||
class RepositoryListValueSerializer < ActiveModel::Serializer
|
||||
attributes :data, :value_type
|
||||
attributes :value, :value_type
|
||||
|
||||
def data
|
||||
def value
|
||||
object.value.data
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module RepositoryDatatable
|
||||
class RepositoryStatusValueSerializer < ActiveModel::Serializer
|
||||
attributes :value, :value_type
|
||||
|
||||
def value
|
||||
{
|
||||
icon: object.value.repository_status_item.icon,
|
||||
status: object.value.repository_status_item.status
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
module RepositoryDatatable
|
||||
class RepositoryTextValueSerializer < ActiveModel::Serializer
|
||||
attributes :data, :value_type
|
||||
attributes :value, :value_type
|
||||
|
||||
def data
|
||||
def value
|
||||
object.value.data
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue