From e8fdfe711114c6e2231b0e1e3d59aaaa21591e87 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Wed, 6 Nov 2019 11:44:00 +0100 Subject: [PATCH] Implement datatables renderer for status data type [SCI-4032] --- .../repositories/renderers/view_renderers.js | 26 ++++++++++++------- app/assets/stylesheets/repositories.scss | 4 +++ app/models/repository_status_value.rb | 18 +++++++++++-- .../repository_asset_value_serializer.rb | 4 +-- .../repository_list_value_serializer.rb | 4 +-- .../repository_status_value_serializer.rb | 14 ++++++++++ .../repository_text_value_serializer.rb | 4 +-- 7 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 app/serializers/repository_datatable/repository_status_value_serializer.rb diff --git a/app/assets/javascripts/repositories/renderers/view_renderers.js b/app/assets/javascripts/repositories/renderers/view_renderers.js index 94404965e..ae92c71cd 100644 --- a/app/assets/javascripts/repositories/renderers/view_renderers.js +++ b/app/assets/javascripts/repositories/renderers/view_renderers.js @@ -1,12 +1,12 @@ $.fn.dataTable.render.RepositoryAssetValue = function(data) { - var asset = data.data; + var asset = data.value; return ` - ${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 '' + data.value.icon + '' + data.value.status; +}; + +$.fn.dataTable.render.defaultRepositoryStatusValue = function() { + return ''; +}; diff --git a/app/assets/stylesheets/repositories.scss b/app/assets/stylesheets/repositories.scss index 0e4931bdb..f3ce98422 100644 --- a/app/assets/stylesheets/repositories.scss +++ b/app/assets/stylesheets/repositories.scss @@ -61,6 +61,10 @@ padding: 3px 12px; } } + + .repository-status-value-icon { + margin-right: 5px; + } } .repository-cog { diff --git a/app/models/repository_status_value.rb b/app/models/repository_status_value.rb index 5a4f3ae73..87a323ce5 100644 --- a/app/models/repository_status_value.rb +++ b/app/models/repository_status_value.rb @@ -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 diff --git a/app/serializers/repository_datatable/repository_asset_value_serializer.rb b/app/serializers/repository_datatable/repository_asset_value_serializer.rb index c82d308be..10095b09d 100644 --- a/app/serializers/repository_datatable/repository_asset_value_serializer.rb +++ b/app/serializers/repository_datatable/repository_asset_value_serializer.rb @@ -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, diff --git a/app/serializers/repository_datatable/repository_list_value_serializer.rb b/app/serializers/repository_datatable/repository_list_value_serializer.rb index f963dc21b..87be086d5 100644 --- a/app/serializers/repository_datatable/repository_list_value_serializer.rb +++ b/app/serializers/repository_datatable/repository_list_value_serializer.rb @@ -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 diff --git a/app/serializers/repository_datatable/repository_status_value_serializer.rb b/app/serializers/repository_datatable/repository_status_value_serializer.rb new file mode 100644 index 000000000..7d3534369 --- /dev/null +++ b/app/serializers/repository_datatable/repository_status_value_serializer.rb @@ -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 diff --git a/app/serializers/repository_datatable/repository_text_value_serializer.rb b/app/serializers/repository_datatable/repository_text_value_serializer.rb index 22664f0b5..fce3f7248 100644 --- a/app/serializers/repository_datatable/repository_text_value_serializer.rb +++ b/app/serializers/repository_datatable/repository_text_value_serializer.rb @@ -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