1
This commit is contained in:
parent
e6108b44d0
commit
cd6e660a7d
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,8 @@
|
||||
node_modules/
|
||||
*/node_modules/
|
||||
*/build/
|
||||
|
||||
**/node_modules/
|
||||
**/build/
|
||||
.DS_Store
|
||||
.env
|
||||
File diff suppressed because one or more lines are too long
@ -21,6 +21,8 @@ module.exports = class TasksDBApi {
|
||||
priority: data.priority || null,
|
||||
is_procrastinating: data.is_procrastinating || false,
|
||||
|
||||
iscompleted: data.iscompleted || false,
|
||||
|
||||
importHash: data.importHash || null,
|
||||
createdById: currentUser.id,
|
||||
updatedById: currentUser.id,
|
||||
@ -49,6 +51,8 @@ module.exports = class TasksDBApi {
|
||||
priority: item.priority || null,
|
||||
is_procrastinating: item.is_procrastinating || false,
|
||||
|
||||
iscompleted: item.iscompleted || false,
|
||||
|
||||
importHash: item.importHash || null,
|
||||
createdById: currentUser.id,
|
||||
updatedById: currentUser.id,
|
||||
@ -83,6 +87,9 @@ module.exports = class TasksDBApi {
|
||||
if (data.is_procrastinating !== undefined)
|
||||
updatePayload.is_procrastinating = data.is_procrastinating;
|
||||
|
||||
if (data.iscompleted !== undefined)
|
||||
updatePayload.iscompleted = data.iscompleted;
|
||||
|
||||
updatePayload.updatedById = currentUser.id;
|
||||
|
||||
await tasks.update(updatePayload, { transaction });
|
||||
@ -270,6 +277,13 @@ module.exports = class TasksDBApi {
|
||||
};
|
||||
}
|
||||
|
||||
if (filter.iscompleted) {
|
||||
where = {
|
||||
...where,
|
||||
iscompleted: filter.iscompleted,
|
||||
};
|
||||
}
|
||||
|
||||
if (filter.createdAtRange) {
|
||||
const [start, end] = filter.createdAtRange;
|
||||
|
||||
|
||||
52
backend/src/db/migrations/1749136812314.js
Normal file
52
backend/src/db/migrations/1749136812314.js
Normal file
@ -0,0 +1,52 @@
|
||||
module.exports = {
|
||||
/**
|
||||
* @param {QueryInterface} queryInterface
|
||||
* @param {Sequelize} Sequelize
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async up(queryInterface, Sequelize) {
|
||||
/**
|
||||
* @type {Transaction}
|
||||
*/
|
||||
const transaction = await queryInterface.sequelize.transaction();
|
||||
try {
|
||||
await queryInterface.addColumn(
|
||||
'tasks',
|
||||
'iscompleted',
|
||||
{
|
||||
type: Sequelize.DataTypes.BOOLEAN,
|
||||
|
||||
defaultValue: false,
|
||||
allowNull: false,
|
||||
},
|
||||
{ transaction },
|
||||
);
|
||||
|
||||
await transaction.commit();
|
||||
} catch (err) {
|
||||
await transaction.rollback();
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @param {QueryInterface} queryInterface
|
||||
* @param {Sequelize} Sequelize
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async down(queryInterface, Sequelize) {
|
||||
/**
|
||||
* @type {Transaction}
|
||||
*/
|
||||
const transaction = await queryInterface.sequelize.transaction();
|
||||
try {
|
||||
await queryInterface.removeColumn('tasks', 'iscompleted', {
|
||||
transaction,
|
||||
});
|
||||
|
||||
await transaction.commit();
|
||||
} catch (err) {
|
||||
await transaction.rollback();
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
};
|
||||
@ -39,6 +39,13 @@ module.exports = function (sequelize, DataTypes) {
|
||||
defaultValue: false,
|
||||
},
|
||||
|
||||
iscompleted: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
|
||||
importHash: {
|
||||
type: DataTypes.STRING(255),
|
||||
allowNull: true,
|
||||
|
||||
@ -16,6 +16,8 @@ const TasksData = [
|
||||
is_procrastinating: false,
|
||||
|
||||
// type code here for "relation_one" field
|
||||
|
||||
iscompleted: true,
|
||||
},
|
||||
|
||||
{
|
||||
@ -30,6 +32,8 @@ const TasksData = [
|
||||
is_procrastinating: false,
|
||||
|
||||
// type code here for "relation_one" field
|
||||
|
||||
iscompleted: true,
|
||||
},
|
||||
|
||||
{
|
||||
@ -39,11 +43,29 @@ const TasksData = [
|
||||
|
||||
due_date: new Date('2023-11-03T09:00:00Z'),
|
||||
|
||||
priority: 'Medium',
|
||||
priority: 'High',
|
||||
|
||||
is_procrastinating: true,
|
||||
|
||||
// type code here for "relation_one" field
|
||||
|
||||
iscompleted: false,
|
||||
},
|
||||
|
||||
{
|
||||
title: 'Review code submissions',
|
||||
|
||||
description: 'Review the latest code submissions from the team.',
|
||||
|
||||
due_date: new Date('2023-11-02T14:00:00Z'),
|
||||
|
||||
priority: 'High',
|
||||
|
||||
is_procrastinating: false,
|
||||
|
||||
// type code here for "relation_one" field
|
||||
|
||||
iscompleted: true,
|
||||
},
|
||||
];
|
||||
|
||||
@ -82,6 +104,17 @@ async function associateTaskWithUser() {
|
||||
if (Task2?.setUser) {
|
||||
await Task2.setUser(relatedUser2);
|
||||
}
|
||||
|
||||
const relatedUser3 = await Users.findOne({
|
||||
offset: Math.floor(Math.random() * (await Users.count())),
|
||||
});
|
||||
const Task3 = await Tasks.findOne({
|
||||
order: [['id', 'ASC']],
|
||||
offset: 3,
|
||||
});
|
||||
if (Task3?.setUser) {
|
||||
await Task3.setUser(relatedUser3);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -161,6 +161,17 @@ router.post(
|
||||
* description: Data of the updated item
|
||||
* type: object
|
||||
* $ref: "#/components/schemas/Tasks"
|
||||
|
||||
|
||||
// New endpoint for task statistics
|
||||
router.get(
|
||||
'/stats',
|
||||
wrapAsync(async (req, res) => {
|
||||
const stats = await TasksService.stats(req.currentUser);
|
||||
res.status(200).send(stats);
|
||||
}),
|
||||
);
|
||||
|
||||
* required:
|
||||
* - id
|
||||
* responses:
|
||||
|
||||
@ -111,4 +111,29 @@ module.exports = class TasksService {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task statistics: total, completed, pending, and by priority counts.
|
||||
*/
|
||||
static async stats(currentUser) {
|
||||
// Count total tasks
|
||||
const total = await TasksDBApi.findAll({}, null, { countOnly: true, currentUser });
|
||||
// Count completed tasks
|
||||
const completed = await TasksDBApi.findAll({ iscompleted: true }, null, { countOnly: true, currentUser });
|
||||
// Count pending tasks
|
||||
const pending = await TasksDBApi.findAll({ iscompleted: false }, null, { countOnly: true, currentUser });
|
||||
// Group by priority
|
||||
const dbModels = require('../db/models');
|
||||
const { fn, col } = dbModels.sequelize;
|
||||
const raw = await dbModels.tasks.findAll({
|
||||
attributes: ['priority', [fn('COUNT', col('priority')), 'count']],
|
||||
group: ['priority'],
|
||||
});
|
||||
const byPriority = {};
|
||||
raw.forEach(r => {
|
||||
byPriority[r.get('priority')] = parseInt(r.get('count'), 10);
|
||||
});
|
||||
return { total, completed, pending, byPriority };
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -135,6 +135,17 @@ const CardTasks = ({
|
||||
</div>
|
||||
</dd>
|
||||
</div>
|
||||
|
||||
<div className='flex justify-between gap-x-4 py-3'>
|
||||
<dt className=' text-gray-500 dark:text-dark-600'>
|
||||
Iscompleted
|
||||
</dt>
|
||||
<dd className='flex items-start gap-x-2'>
|
||||
<div className='font-medium line-clamp-4'>
|
||||
{dataFormatter.booleanFormatter(item.iscompleted)}
|
||||
</div>
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</li>
|
||||
))}
|
||||
|
||||
@ -90,6 +90,13 @@ const ListTasks = ({
|
||||
{dataFormatter.usersOneListFormatter(item.user)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className={'flex-1 px-3'}>
|
||||
<p className={'text-xs text-gray-500 '}>Iscompleted</p>
|
||||
<p className={'line-clamp-2'}>
|
||||
{dataFormatter.booleanFormatter(item.iscompleted)}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
<ListActionsPopover
|
||||
onDelete={onDelete}
|
||||
|
||||
@ -124,6 +124,20 @@ export const loadColumns = async (
|
||||
params?.value?.id ?? params?.value,
|
||||
},
|
||||
|
||||
{
|
||||
field: 'iscompleted',
|
||||
headerName: 'Iscompleted',
|
||||
flex: 1,
|
||||
minWidth: 120,
|
||||
filterable: false,
|
||||
headerClassName: 'datagrid--header',
|
||||
cellClassName: 'datagrid--cell',
|
||||
|
||||
editable: hasUpdatePermission,
|
||||
|
||||
type: 'boolean',
|
||||
},
|
||||
|
||||
{
|
||||
field: 'actions',
|
||||
type: 'actions',
|
||||
|
||||
@ -17,7 +17,7 @@ export default function WebSiteHeader({ projectName }: WebSiteHeaderProps) {
|
||||
const websiteHeder = useAppSelector((state) => state.style.websiteHeder);
|
||||
const borders = useAppSelector((state) => state.style.borders);
|
||||
|
||||
const style = HeaderStyle.PAGES_RIGHT;
|
||||
const style = HeaderStyle.PAGES_LEFT;
|
||||
|
||||
const design = HeaderDesigns.DESIGN_DIVERSITY;
|
||||
return (
|
||||
|
||||
@ -2,6 +2,11 @@ import * as icon from '@mdi/js';
|
||||
import Head from 'next/head';
|
||||
import React from 'react';
|
||||
import axios from 'axios';
|
||||
import { Chart as ChartJS, ArcElement, Tooltip, Legend, CategoryScale, LinearScale, BarElement } from 'chart.js';
|
||||
import { Pie, Bar } from 'react-chartjs-2';
|
||||
|
||||
ChartJS.register(ArcElement, Tooltip, Legend, CategoryScale, LinearScale, BarElement);
|
||||
|
||||
import type { ReactElement } from 'react';
|
||||
import LayoutAuthenticated from '../layouts/Authenticated';
|
||||
import SectionMain from '../components/SectionMain';
|
||||
|
||||
@ -47,6 +47,8 @@ const EditTasks = () => {
|
||||
is_procrastinating: false,
|
||||
|
||||
user: null,
|
||||
|
||||
iscompleted: false,
|
||||
};
|
||||
const [initialValues, setInitialValues] = useState(initVals);
|
||||
|
||||
@ -162,6 +164,14 @@ const EditTasks = () => {
|
||||
></Field>
|
||||
</FormField>
|
||||
|
||||
<FormField label='Iscompleted' labelFor='iscompleted'>
|
||||
<Field
|
||||
name='iscompleted'
|
||||
id='iscompleted'
|
||||
component={SwitchField}
|
||||
></Field>
|
||||
</FormField>
|
||||
|
||||
<BaseDivider />
|
||||
<BaseButtons>
|
||||
<BaseButton type='submit' color='info' label='Submit' />
|
||||
|
||||
@ -47,6 +47,8 @@ const EditTasksPage = () => {
|
||||
is_procrastinating: false,
|
||||
|
||||
user: null,
|
||||
|
||||
iscompleted: false,
|
||||
};
|
||||
const [initialValues, setInitialValues] = useState(initVals);
|
||||
|
||||
@ -160,6 +162,14 @@ const EditTasksPage = () => {
|
||||
></Field>
|
||||
</FormField>
|
||||
|
||||
<FormField label='Iscompleted' labelFor='iscompleted'>
|
||||
<Field
|
||||
name='iscompleted'
|
||||
id='iscompleted'
|
||||
component={SwitchField}
|
||||
></Field>
|
||||
</FormField>
|
||||
|
||||
<BaseDivider />
|
||||
<BaseButtons>
|
||||
<BaseButton type='submit' color='info' label='Submit' />
|
||||
|
||||
@ -44,6 +44,8 @@ const initialValues = {
|
||||
is_procrastinating: false,
|
||||
|
||||
user: '',
|
||||
|
||||
iscompleted: false,
|
||||
};
|
||||
|
||||
const TasksNew = () => {
|
||||
@ -124,6 +126,14 @@ const TasksNew = () => {
|
||||
></Field>
|
||||
</FormField>
|
||||
|
||||
<FormField label='Iscompleted' labelFor='iscompleted'>
|
||||
<Field
|
||||
name='iscompleted'
|
||||
id='iscompleted'
|
||||
component={SwitchField}
|
||||
></Field>
|
||||
</FormField>
|
||||
|
||||
<BaseDivider />
|
||||
<BaseButtons>
|
||||
<BaseButton type='submit' color='info' label='Submit' />
|
||||
|
||||
@ -106,6 +106,14 @@ const TasksView = () => {
|
||||
<p>{tasks?.user?.firstName ?? 'No data'}</p>
|
||||
</div>
|
||||
|
||||
<FormField label='Iscompleted'>
|
||||
<SwitchField
|
||||
field={{ name: 'iscompleted', value: tasks?.iscompleted }}
|
||||
form={{ setFieldValue: () => null }}
|
||||
disabled
|
||||
/>
|
||||
</FormField>
|
||||
|
||||
<BaseDivider />
|
||||
|
||||
<BaseButton
|
||||
|
||||
@ -157,6 +157,8 @@ const UsersView = () => {
|
||||
<th>Priority</th>
|
||||
|
||||
<th>IsProcrastinating</th>
|
||||
|
||||
<th>Iscompleted</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -184,6 +186,10 @@ const UsersView = () => {
|
||||
item.is_procrastinating,
|
||||
)}
|
||||
</td>
|
||||
|
||||
<td data-label='iscompleted'>
|
||||
{dataFormatter.booleanFormatter(item.iscompleted)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user