mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-18 13:20:43 +00:00
Add export to ColumnStats; fix formatDateTimeForFileName
This commit is contained in:
@ -54,6 +54,21 @@ ColumnStats.defaultProps = {
|
|||||||
|
|
||||||
const qController = Client.getInstance();
|
const qController = Client.getInstance();
|
||||||
|
|
||||||
|
// todo - merge w/ same function in TableWidget
|
||||||
|
function download(filename: string, text: string)
|
||||||
|
{
|
||||||
|
var element = document.createElement("a");
|
||||||
|
element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text));
|
||||||
|
element.setAttribute("download", filename);
|
||||||
|
|
||||||
|
element.style.display = "none";
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
element.click();
|
||||||
|
|
||||||
|
document.body.removeChild(element);
|
||||||
|
}
|
||||||
|
|
||||||
function ColumnStats({tableMetaData, fieldMetaData, fieldTableName, filter}: Props): JSX.Element
|
function ColumnStats({tableMetaData, fieldMetaData, fieldTableName, filter}: Props): JSX.Element
|
||||||
{
|
{
|
||||||
const [statusString, setStatusString] = useState("Calculating statistics...");
|
const [statusString, setStatusString] = useState("Calculating statistics...");
|
||||||
@ -97,6 +112,8 @@ function ColumnStats({tableMetaData, fieldMetaData, fieldTableName, filter}: Pro
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// todo - job running!
|
||||||
|
|
||||||
const result = processResult as QJobComplete;
|
const result = processResult as QJobComplete;
|
||||||
|
|
||||||
const statFieldObjects = result.values.statsFields;
|
const statFieldObjects = result.values.statsFields;
|
||||||
@ -174,6 +191,24 @@ function ColumnStats({tableMetaData, fieldMetaData, fieldTableName, filter}: Pro
|
|||||||
setStatusString("Refreshing...")
|
setStatusString("Refreshing...")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const doExport = () =>
|
||||||
|
{
|
||||||
|
let csv = `"${fieldMetaData.label}","Count"\n`;
|
||||||
|
for (let i = 0; i < valueCounts.length; i++)
|
||||||
|
{
|
||||||
|
let fieldValue = valueCounts[i].displayValues.get(fieldMetaData.name);
|
||||||
|
if(fieldValue === undefined)
|
||||||
|
{
|
||||||
|
fieldValue = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
csv += `"${fieldValue}",${valueCounts[i].values.get("count")}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileName = tableMetaData.label + " - " + fieldMetaData.label + " Column Stats " + ValueUtils.formatDateTimeForFileName(new Date()) + ".csv";
|
||||||
|
download(fileName, csv);
|
||||||
|
}
|
||||||
|
|
||||||
function Loading()
|
function Loading()
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
@ -200,9 +235,14 @@ function ColumnStats({tableMetaData, fieldMetaData, fieldTableName, filter}: Pro
|
|||||||
{statusString ?? <> </>}
|
{statusString ?? <> </>}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<Box>
|
||||||
<Button onClick={() => refresh()} startIcon={<Icon>refresh</Icon>}>
|
<Button onClick={() => refresh()} startIcon={<Icon>refresh</Icon>}>
|
||||||
Refresh
|
Refresh
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button onClick={() => doExport()} startIcon={<Icon>save_alt</Icon>} disabled={valueCounts == null || valueCounts.length == 0}>
|
||||||
|
Export
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
<Grid container>
|
<Grid container>
|
||||||
<Grid item xs={8}>
|
<Grid item xs={8}>
|
||||||
|
@ -278,7 +278,7 @@ class ValueUtils
|
|||||||
const zp = (value: number): string => (value < 10 ? `0${value}` : `${value}`);
|
const zp = (value: number): string => (value < 10 ? `0${value}` : `${value}`);
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
const dateString = `${d.getFullYear()}-${zp(d.getMonth() + 1)}-${zp(d.getDate())} ${zp(d.getHours())}${zp(d.getMinutes())}`;
|
const dateString = `${d.getFullYear()}-${zp(d.getMonth() + 1)}-${zp(d.getDate())} ${zp(d.getHours())}${zp(d.getMinutes())}`;
|
||||||
return (date);
|
return (dateString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getFullWeekday(date: Date)
|
public static getFullWeekday(date: Date)
|
||||||
|
Reference in New Issue
Block a user