Implement datatables renderer for status data type [SCI-4032]

This commit is contained in:
Oleksii Kriuchykhin 2019-11-06 11:44:00 +01:00 committed by Urban Rotnik
parent 2024afce4b
commit e8fdfe7111
7 changed files with 57 additions and 17 deletions

View file

@ -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 '';
};

View file

@ -61,6 +61,10 @@
padding: 3px 12px;
}
}
.repository-status-value-icon {
margin-right: 5px;
}
}
.repository-cog {

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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

View file

@ -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