precise work with mongoid

This commit is contained in:
Jan Prochazka
2021-12-07 21:29:31 +01:00
parent c113266095
commit 6bd48ca29f
8 changed files with 25 additions and 34 deletions

View File

@@ -8,6 +8,7 @@ export function getFilterValueExpression(value, dataType) {
if (isTypeDateTime(dataType)) return moment(value).format('YYYY-MM-DD HH:mm:ss');
if (value === true) return 'TRUE';
if (value === false) return 'FALSE';
if (value.$oid) return `ObjectId("${value.$oid}")`;
return `="${value}"`;
}

View File

@@ -28,16 +28,12 @@ const numberTestCondition = () => value => ({
],
});
const idRegex = /[('"]([0-9a-f]{24})['")]/;
const objectIdTestCondition = () => value => ({
$or: [
{
__placeholder__: {
$regex: `.*${value}.*`,
$options: 'i',
},
},
{
__placeholder__: { $oid: value },
__placeholder__: { $oid: value.match(idRegex)[1] },
},
],
});
@@ -78,7 +74,7 @@ const createParser = () => {
.map(Number)
.desc('number'),
objectid: () => token(P.regexp(/[0-9a-f]{24}/)).desc('ObjectId'),
objectid: () => token(P.regexp(/ObjectId\(['"]?[0-9a-f]{24}['"]?\)/)).desc('ObjectId'),
noQuotedString: () => P.regexp(/[^\s^,^'^"]+/).desc('string unquoted'),

View File

@@ -124,6 +124,8 @@
{:else}
<span class="null">({value.data.length} bytes)</span>
{/if}
{:else if value.$oid}
<span class="value">ObjectId("{value.$oid}")</span>
{:else if _.isPlainObject(value)}
<span class="null" title={JSON.stringify(value, undefined, 2)}>(JSON)</span>
{:else if _.isArray(value)}

View File

@@ -67,6 +67,7 @@ export function countColumnSizes(grider: Grider, columns, containerWidth, displa
const value = row[uqName];
let text = value;
if (_.isArray(value)) text = `[${value.length} items]`;
else if (value?.$oid) text = `ObjectId("${value.$oid}")`;
const width = context.measureText(text).width + 8;
// console.log('colName', colName, text, width);
columnSizes.putSizeOverride(colIndex, width);

View File

@@ -4,7 +4,7 @@
showModal(EditJsonModal, {
json: rowData,
onSave: value => {
if (value._id != rowData._id) {
if (rowData._id && value._id != rowData._id) {
showModal(ErrorMessageModal, { message: '_id attribute cannot be changed' });
return false;
}

View File

@@ -71,6 +71,7 @@ export function extractRowCopiedValue(row, col) {
if (value === undefined) value = _.get(row, col);
if (value === null) return '(NULL)';
if (value === undefined) return '(NoField)';
if (value && value.$oid) return `ObjectId("${value.$oid}")`;
if (value && value.type == 'Buffer' && _.isArray(value.data)) return arrayToHexString(value.data);
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value);
return value;