A free open source IT asset/license management system
Fixed #19595 - numbers in custom fields exporting inconsistently
snipe3910d0c462aa
diff --git a/app/Presenters/AssetAuditPresenter.php b/app/Presenters/AssetAuditPresenter.phpindex 79dd8a7d72..7c97ca62b4 100644--- a/app/Presenters/AssetAuditPresenter.php+++ b/app/Presenters/AssetAuditPresenter.php@@ -290,6 +290,10 @@ class AssetAuditPresenter extends Presenter'switchable' => true,'title' => ($field->field_encrypted == '1') ? '<i class="fas fa-lock"></i> '.e($field->name) : e($field->name),'formatter' => 'customFieldsFormatter',+ // Use tableExport attributes on the TD so dot-containing+ // text values stop being misread as EU-locale thousands+ // numbers on export. See issue #19595.+ 'cellStyle' => 'customFieldsCellStyle',];}diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.phpindex 0858d9cf03..644566d8d2 100644--- a/app/Presenters/AssetPresenter.php+++ b/app/Presenters/AssetPresenter.php@@ -422,6 +422,12 @@ class AssetPresenter extends Presenter'switchable' => true,'title' => e($field->name),'formatter' => 'customFieldsFormatter',+ // Use tableExport attributes on the TD so dot-containing+ // text values (e.g. "79.99" in a text field) stop being+ // misread as EU-locale thousands numbers on export. See+ // issue #19595 and the customFieldsCellStyle definition+ // in bootstrap-table.+ 'cellStyle' => 'customFieldsCellStyle','escape' => true,'class' => ($field->field_encrypted == '1') ? 'css-padlock' : '','visible' => ($field->show_in_listview == '1') ? true : false,diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.phpindex e0d684fd7d..9a16431c55 100755--- a/resources/views/account/view-assets.blade.php+++ b/resources/views/account/view-assets.blade.php@@ -349,7 +349,7 @@<th scope="col" data-field="byod" data-formatter="trueFalseFormatter" data-sortable="true" data-visible="false">{{ trans('general.byod') }}</th>@foreach ($field_array as $db_column => $field_name)- <th scope="col" data-field="custom_fields.{{ $db_column }}" data-formatter="customFieldsFormatter" data-sortable="true" data-visible="true">{{ $field_name }}</th>+ <th scope="col" data-field="custom_fields.{{ $db_column }}" data-formatter="customFieldsFormatter" data-cell-style="customFieldsCellStyle" data-sortable="true" data-visible="true">{{ $field_name }}</th>@endforeach</tr></thead>diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.phpindex a2ab29ac19..5280745b83 100644--- a/resources/views/partials/bootstrap-table.blade.php+++ b/resources/views/partials/bootstrap-table.blade.php@@ -952,6 +952,18 @@clearBootstrapTableLoadError(instance);}},+ onPostBody: function () {+ // Reapply the tableExport opt-out attributes on+ // every custom-field cell after each body render,+ // so dot-containing text values don't get misread+ // as EU-locale thousands numbers on export. See+ // customFieldsCellStyle + stampCustomFieldExportAttrs+ // and issue #19595.+ var instance = arguments[arguments.length - 1];+ if (instance && instance.$el) {+ stampCustomFieldExportAttrs(instance.$el);+ }+ },onRefresh: function () {// Fires the moment the user clicks the toolbar's refresh button,// before the retry AJAX call is issued. Clear the callout + restore@@ -3919,7 +3931,7 @@}}// Convert newlines to <br> for textarea fields so they render in- // the table; export will convert <br> back to \n via onCellHtmlData+ // the table. Export converts <br> back to \n via onCellHtmlData.if (row.custom_fields[field_column_plain].element === 'textarea') {var val = row.custom_fields[field_column_plain].value;return val ? val.replace(/(?:\r\n|\r|\n)/g, '<br>') : '';@@ -3931,6 +3943,39 @@}+ // cellStyle callback stamped on every custom-field column (wired+ // from AssetPresenter + the other presenters that render custom+ // fields). Tags the cell so stampCustomFieldExportAttrs below can+ // set the tableExport "leave this cell alone" attributes on the TD+ // after each body render. bs-table's cellStyle only honors classes+ // and css, so the data attributes can't be returned directly from+ // here, and tableExport only reads data-tableexport-* from the TD+ // itself (not inner nodes), so putting them on a wrapper span+ // inside the formatter doesn't work either. See issue #19595.+ function customFieldsCellStyle() {+ return {+ classes: 'snipeit-custom-field-cell',+ };+ }++ // Walk every custom-field cell in a table and set the two+ // tableExport attributes that opt the cell out of the global EU+ // number-parse config (see the exportOptions['numbers'] block above+ // and issue #19415). Called from onPostBody so the attrs get+ // reapplied after every bs-table render.+ //+ // data-tableexport-cellformat="" : skip number-separator conversion+ // data-tableexport-xlsxformatid="49": force XLSX "@" (text) cell format+ function stampCustomFieldExportAttrs($table) {+ if (!$table || !$table.length) {+ return;+ }+ $table.find('td.snipeit-custom-field-cell').each(function () {+ this.setAttribute('data-tableexport-cellformat', '');+ this.setAttribute('data-tableexport-xlsxformatid', '49');+ });+ }+function createdAtFormatter(value) {if ((value) && (value.formatted)) {