mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-18 13:20:43 +00:00
Update to convert date-times to UTC before submitting to backend.
This commit is contained in:
@ -98,7 +98,7 @@ function SavedFilters({qController, metaData, tableMetaData, currentSavedFilter,
|
||||
{
|
||||
if (currentSavedFilter != null)
|
||||
{
|
||||
let qFilter = FilterUtils.buildQFilterFromGridFilter(filterModel, columnSortModel);
|
||||
let qFilter = FilterUtils.buildQFilterFromGridFilter(tableMetaData, filterModel, columnSortModel);
|
||||
setFilterIsModified(JSON.stringify(qFilter) !== currentSavedFilter.values.get("filterJson"));
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ function SavedFilters({qController, metaData, tableMetaData, currentSavedFilter,
|
||||
else
|
||||
{
|
||||
formData.append("tableName", tableMetaData.name);
|
||||
formData.append("filterJson", JSON.stringify(FilterUtils.buildQFilterFromGridFilter(filterModel, columnSortModel)));
|
||||
formData.append("filterJson", JSON.stringify(FilterUtils.buildQFilterFromGridFilter(tableMetaData, filterModel, columnSortModel)));
|
||||
|
||||
if (isSaveFilterAs || isRenameFilter || currentSavedFilter == null)
|
||||
{
|
||||
|
@ -283,7 +283,7 @@ function RecordQuery({table, launchProcess}: Props): JSX.Element
|
||||
|
||||
const buildQFilter = (filterModel: GridFilterModel) =>
|
||||
{
|
||||
const filter = FilterUtils.buildQFilterFromGridFilter(filterModel, columnSortModel);
|
||||
const filter = FilterUtils.buildQFilterFromGridFilter(tableMetaData, filterModel, columnSortModel);
|
||||
setHasValidFilters(filter.criteria && filter.criteria.length > 0);
|
||||
return(filter);
|
||||
};
|
||||
|
@ -238,7 +238,7 @@ class FilterUtils
|
||||
** for non-values (e.g., blank), set it to null.
|
||||
** for list-values, it's already in an array, so don't wrap it.
|
||||
*******************************************************************************/
|
||||
public static gridCriteriaValueToQQQ = (operator: QCriteriaOperator, value: any, gridOperatorValue: string): any[] =>
|
||||
public static gridCriteriaValueToQQQ = (operator: QCriteriaOperator, value: any, gridOperatorValue: string, fieldMetaData: QFieldMetaData): any[] =>
|
||||
{
|
||||
if (gridOperatorValue === "isTrue")
|
||||
{
|
||||
@ -263,18 +263,34 @@ class FilterUtils
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
return ([null, null]);
|
||||
}
|
||||
return (FilterUtils.extractIdsFromPossibleValueList(value));
|
||||
return (FilterUtils.prepFilterValuesForBackend(value, fieldMetaData));
|
||||
}
|
||||
|
||||
return (FilterUtils.extractIdsFromPossibleValueList([value]));
|
||||
return (FilterUtils.prepFilterValuesForBackend([value], fieldMetaData));
|
||||
};
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static zeroPad = (n: number): string =>
|
||||
{
|
||||
if (n < 10)
|
||||
{
|
||||
return ("0" + n);
|
||||
}
|
||||
return (`${n}`);
|
||||
};
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Helper method - take a list of values, which may be possible values, and
|
||||
** either return the original list, or a new list that is just the ids of the
|
||||
** possible values (if it was a list of possible values)
|
||||
** possible values (if it was a list of possible values).
|
||||
**
|
||||
** Or, if the values are date-times, convert them to UTC.
|
||||
*******************************************************************************/
|
||||
private static extractIdsFromPossibleValueList = (param: any[]): number[] | string[] =>
|
||||
private static prepFilterValuesForBackend = (param: any[], fieldMetaData: QFieldMetaData): number[] | string[] =>
|
||||
{
|
||||
if (param === null || param === undefined)
|
||||
{
|
||||
@ -294,9 +310,29 @@ class FilterUtils
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fieldMetaData?.type == QFieldType.DATE_TIME)
|
||||
{
|
||||
try
|
||||
{
|
||||
let localDate = new Date(param[i]);
|
||||
let month = (1 + localDate.getUTCMonth());
|
||||
let zp = FilterUtils.zeroPad;
|
||||
let toPush = localDate.getUTCFullYear() + "-" + zp(month) + "-" + zp(localDate.getUTCDate()) + "T" + zp(localDate.getUTCHours()) + ":" + zp(localDate.getUTCMinutes()) + ":" + zp(localDate.getUTCSeconds()) + "Z";
|
||||
console.log(`Input date was ${localDate}. Sending to backend as ${toPush}`);
|
||||
rs.push(toPush);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
console.log("Error converting date-time to UTC: ", e);
|
||||
rs.push(param[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rs.push(param[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (rs);
|
||||
};
|
||||
|
||||
@ -494,7 +530,7 @@ class FilterUtils
|
||||
/*******************************************************************************
|
||||
** build a qqq filter from a grid and column sort model
|
||||
*******************************************************************************/
|
||||
public static buildQFilterFromGridFilter(filterModel: GridFilterModel, columnSortModel: GridSortItem[]): QQueryFilter
|
||||
public static buildQFilterFromGridFilter(tableMetaData: QTableMetaData, filterModel: GridFilterModel, columnSortModel: GridSortItem[]): QQueryFilter
|
||||
{
|
||||
console.log("Building q filter with model:");
|
||||
console.log(filterModel);
|
||||
@ -533,8 +569,10 @@ class FilterUtils
|
||||
return;
|
||||
}
|
||||
|
||||
var fieldMetadata = tableMetaData?.fields.get(item.columnField);
|
||||
|
||||
const operator = FilterUtils.gridCriteriaOperatorToQQQ(item.operatorValue);
|
||||
const values = FilterUtils.gridCriteriaValueToQQQ(operator, item.value, item.operatorValue);
|
||||
const values = FilterUtils.gridCriteriaValueToQQQ(operator, item.value, item.operatorValue, fieldMetadata);
|
||||
qFilter.addCriteria(new QFilterCriteria(item.columnField, operator, values));
|
||||
foundFilter = true;
|
||||
});
|
||||
|
Reference in New Issue
Block a user