mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-21 20:44:45 +08:00
Fix big number in repository number value
This commit is contained in:
parent
92f432b86a
commit
9ede0ef716
5 changed files with 17 additions and 20 deletions
|
@ -133,10 +133,8 @@ $.fn.dataTable.render.editRepositoryChecklistValue = function(formId, columnId,
|
|||
ChecklistColumnHelper.initialChecklistEditMode(formId, columnId, $cell, currentValue);
|
||||
};
|
||||
|
||||
$.fn.dataTable.render.editRepositoryNumberValue = function(formId, columnId, cell, $header) {
|
||||
$.fn.dataTable.render.editRepositoryNumberValue = function(formId, columnId, cell) {
|
||||
let $cell = $(cell.node());
|
||||
let decimals = Number($header.data('metadata-decimals'));
|
||||
let number = parseFloat(Number($cell.text()).toFixed(decimals));
|
||||
|
||||
$cell.html(`
|
||||
<div class="form-group">
|
||||
|
@ -144,9 +142,8 @@ $.fn.dataTable.render.editRepositoryNumberValue = function(formId, columnId, cel
|
|||
form="${formId}"
|
||||
type="number"
|
||||
name="repository_cells[${columnId}]"
|
||||
value="${number}"
|
||||
placeholder="${I18n.t('repositories.table.number.enter_number')}"
|
||||
onchange="if (this.value !== '') { this.value = parseFloat(Number(this.value).toFixed(${decimals})); }"
|
||||
value="${$cell.find('.number-value').data('full-value')}"
|
||||
data-type="RepositoryNumberValue">
|
||||
</div>`);
|
||||
};
|
||||
|
|
|
@ -64,9 +64,7 @@ $.fn.dataTable.render.newRepositoryChecklistValue = function(formId, columnId, $
|
|||
ChecklistColumnHelper.initialChecklistEditMode(formId, columnId, $cell);
|
||||
};
|
||||
|
||||
$.fn.dataTable.render.newRepositoryNumberValue = function(formId, columnId, $cell, $header) {
|
||||
let decimals = Number($header.data('metadata-decimals'));
|
||||
|
||||
$.fn.dataTable.render.newRepositoryNumberValue = function(formId, columnId, $cell) {
|
||||
$cell.html(`
|
||||
<div class="form-group">
|
||||
<input class="form-control editing"
|
||||
|
@ -75,7 +73,6 @@ $.fn.dataTable.render.newRepositoryNumberValue = function(formId, columnId, $cel
|
|||
name="repository_cells[${columnId}]"
|
||||
value=""
|
||||
placeholder="${I18n.t('repositories.table.number.enter_number')}"
|
||||
onchange="if (this.value !== '') { this.value = parseFloat(Number(this.value).toFixed(${decimals})); }"
|
||||
data-type="RepositoryNumberValue">
|
||||
</div>`);
|
||||
|
||||
|
|
|
@ -146,5 +146,7 @@ $.fn.dataTable.render.defaultRepositoryNumberValue = function() {
|
|||
};
|
||||
|
||||
$.fn.dataTable.render.RepositoryNumberValue = function(data) {
|
||||
return parseFloat(Number(data.value).toFixed(data.value_decimals));
|
||||
return `<span class="number-value" data-full-value="${data.full_value}">
|
||||
${data.value}
|
||||
</span>`;
|
||||
};
|
||||
|
|
|
@ -18,18 +18,18 @@ class RepositoryNumberValue < ApplicationRecord
|
|||
end
|
||||
|
||||
def data_changed?(new_data)
|
||||
new_data.to_f != data
|
||||
BigDecimal(new_data) != data
|
||||
end
|
||||
|
||||
def update_data!(new_data, user)
|
||||
self.data = new_data.to_f
|
||||
self.data = BigDecimal(new_data)
|
||||
self.last_modified_by = user
|
||||
save!
|
||||
end
|
||||
|
||||
def self.new_with_payload(payload, attributes)
|
||||
value = new(attributes)
|
||||
value.data = payload.to_f
|
||||
value.data = BigDecimal(payload)
|
||||
value
|
||||
end
|
||||
|
||||
|
|
|
@ -2,17 +2,18 @@
|
|||
|
||||
module RepositoryDatatable
|
||||
class RepositoryNumberValueSerializer < RepositoryBaseValueSerializer
|
||||
attributes :value_decimals
|
||||
attributes :full_value
|
||||
|
||||
def value
|
||||
object.data
|
||||
decimal_number = object.repository_cell
|
||||
.repository_column
|
||||
.metadata
|
||||
.fetch('decimals') { Constants::REPOSITORY_NUMBER_TYPE_DEFAULT_DECIMALS }
|
||||
BigDecimal(object.data).round(decimal_number.to_i)
|
||||
end
|
||||
|
||||
def value_decimals
|
||||
object.repository_cell
|
||||
.repository_column
|
||||
.metadata
|
||||
.fetch('decimals') { Constants::REPOSITORY_NUMBER_TYPE_DEFAULT_DECIMALS }
|
||||
def full_value
|
||||
object.data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue