Compare commits
No commits in common. "ai-dev" and "master" have entirely different histories.
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
const db = require('../models');
|
const db = require('../models');
|
||||||
const FileDBApi = require('./file');
|
const FileDBApi = require('./file');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
@ -565,36 +566,6 @@ module.exports = class TasksDBApi {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getStats(options) {
|
|
||||||
const currentUser = (options && options.currentUser) || { id: null };
|
|
||||||
const transaction = (options && options.transaction) || undefined;
|
|
||||||
|
|
||||||
const total = await db.tasks.count({
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
const pending = await db.tasks.count({
|
|
||||||
where: { status: 'pending' },
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
const in_progress = await db.tasks.count({
|
|
||||||
where: { status: 'in_progress' },
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
const completed = await db.tasks.count({
|
|
||||||
where: { status: 'completed' },
|
|
||||||
transaction,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
total,
|
|
||||||
pending,
|
|
||||||
in_progress,
|
|
||||||
completed,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
|
||||||
const TasksService = require('../services/tasks');
|
const TasksService = require('../services/tasks');
|
||||||
@ -349,11 +350,6 @@ router.get('/count', wrapAsync(async (req, res) => {
|
|||||||
res.status(200).send(payload);
|
res.status(200).send(payload);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
router.get('/stats', wrapAsync(async (req, res) => {
|
|
||||||
const payload = await TasksService.getStats(req.currentUser);
|
|
||||||
res.status(200).send(payload);
|
|
||||||
}));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* /api/tasks/autocomplete:
|
* /api/tasks/autocomplete:
|
||||||
|
|||||||
@ -132,9 +132,7 @@ module.exports = class TasksService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getStats(currentUser) {
|
|
||||||
return await TasksDBApi.getStats({ currentUser });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import React, {useEffect, useRef, useState} from 'react'
|
import React, {useEffect, useRef} from 'react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import { useState } from 'react'
|
||||||
import { mdiChevronUp, mdiChevronDown } from '@mdi/js'
|
import { mdiChevronUp, mdiChevronDown } from '@mdi/js'
|
||||||
import BaseDivider from './BaseDivider'
|
import BaseDivider from './BaseDivider'
|
||||||
import BaseIcon from './BaseIcon'
|
import BaseIcon from './BaseIcon'
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import React, { ReactNode, useEffect, useState } from 'react'
|
import React, { ReactNode, useEffect } from 'react'
|
||||||
|
import { useState } from 'react'
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { mdiForwardburger, mdiBackburger, mdiMenu } from '@mdi/js'
|
import { mdiForwardburger, mdiBackburger, mdiMenu } from '@mdi/js'
|
||||||
import menuAside from '../menuAside'
|
import menuAside from '../menuAside'
|
||||||
|
|||||||
@ -37,8 +37,6 @@ const Dashboard = () => {
|
|||||||
const [task_exports, setTask_exports] = React.useState(loadingMessage);
|
const [task_exports, setTask_exports] = React.useState(loadingMessage);
|
||||||
const [audit_events, setAudit_events] = React.useState(loadingMessage);
|
const [audit_events, setAudit_events] = React.useState(loadingMessage);
|
||||||
|
|
||||||
const [taskStats, setTaskStats] = React.useState({ total: 0, pending: 0, in_progress: 0, completed: 0 });
|
|
||||||
|
|
||||||
|
|
||||||
const [widgetsRole, setWidgetsRole] = React.useState({
|
const [widgetsRole, setWidgetsRole] = React.useState({
|
||||||
role: { value: '', label: '' },
|
role: { value: '', label: '' },
|
||||||
@ -75,24 +73,12 @@ const Dashboard = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadTaskStats() {
|
|
||||||
if (hasPermission(currentUser, 'READ_TASKS')) {
|
|
||||||
try {
|
|
||||||
const response = await axios.get('/tasks/stats');
|
|
||||||
setTaskStats(response.data);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching task stats:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getWidgets(roleId) {
|
async function getWidgets(roleId) {
|
||||||
await dispatch(fetchWidgets(roleId));
|
await dispatch(fetchWidgets(roleId));
|
||||||
}
|
}
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!currentUser) return;
|
if (!currentUser) return;
|
||||||
loadData().then();
|
loadData().then();
|
||||||
loadTaskStats().then();
|
|
||||||
setWidgetsRole({ role: { value: currentUser?.app_role?.id, label: currentUser?.app_role?.name } });
|
setWidgetsRole({ role: { value: currentUser?.app_role?.id, label: currentUser?.app_role?.name } });
|
||||||
}, [currentUser]);
|
}, [currentUser]);
|
||||||
|
|
||||||
@ -157,46 +143,6 @@ const Dashboard = () => {
|
|||||||
|
|
||||||
{!!rolesWidgets.length && <hr className='my-6 text-midnightBlueTheme-mainBG ' />}
|
{!!rolesWidgets.length && <hr className='my-6 text-midnightBlueTheme-mainBG ' />}
|
||||||
|
|
||||||
<div className='grid grid-cols-1 gap-6 lg:grid-cols-3 mb-6'>
|
|
||||||
{hasPermission(currentUser, 'READ_TASKS') && (
|
|
||||||
<>
|
|
||||||
<Link href={'/tasks/tasks-list'}>
|
|
||||||
<div className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} border-l-4 border-blue-500 dark:border-dark-700 p-6`}>
|
|
||||||
<div className="flex justify-between align-center">
|
|
||||||
<div>
|
|
||||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">Total Tasks</div>
|
|
||||||
<div className="text-3xl leading-tight font-semibold">{taskStats.total}</div>
|
|
||||||
</div>
|
|
||||||
<BaseIcon className="text-blue-500" w="w-16" h="h-16" size={48} path={icon.mdiClipboardTextOutline} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
<Link href={'/tasks/tasks-list'}>
|
|
||||||
<div className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} border-l-4 border-orange-500 dark:border-dark-700 p-6`}>
|
|
||||||
<div className="flex justify-between align-center">
|
|
||||||
<div>
|
|
||||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">Pending</div>
|
|
||||||
<div className="text-3xl leading-tight font-semibold">{taskStats.pending}</div>
|
|
||||||
</div>
|
|
||||||
<BaseIcon className="text-orange-500" w="w-16" h="h-16" size={48} path={icon.mdiClockOutline} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
<Link href={'/tasks/tasks-list'}>
|
|
||||||
<div className={`${corners !== 'rounded-full'? corners : 'rounded-3xl'} dark:bg-dark-900 ${cardsStyle} border-l-4 border-green-500 dark:border-dark-700 p-6`}>
|
|
||||||
<div className="flex justify-between align-center">
|
|
||||||
<div>
|
|
||||||
<div className="text-lg leading-tight text-gray-500 dark:text-gray-400">Completed</div>
|
|
||||||
<div className="text-3xl leading-tight font-semibold">{taskStats.completed}</div>
|
|
||||||
</div>
|
|
||||||
<BaseIcon className="text-green-500" w="w-16" h="h-16" size={48} path={icon.mdiCheckCircleOutline} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="dashboard" className='grid grid-cols-1 gap-6 lg:grid-cols-3 mb-6'>
|
<div id="dashboard" className='grid grid-cols-1 gap-6 lg:grid-cols-3 mb-6'>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user