From 9b630fe1e1e92ad0ffe923eabdb71a586061d244 Mon Sep 17 00:00:00 2001 From: JOSEPH LE Date: Mon, 20 May 2024 16:30:57 +0700 Subject: [PATCH] Create a workflow statistics page from Jira --- BACKEND/app/Services/JiraService.php | 6 +- FRONTEND/src/pages/Tracking/Tracking.tsx | 7 +- FRONTEND/src/pages/Worklogs/Worklogs.tsx | 649 +++++++++++------------ 3 files changed, 320 insertions(+), 342 deletions(-) diff --git a/BACKEND/app/Services/JiraService.php b/BACKEND/app/Services/JiraService.php index a4909a7..b372556 100644 --- a/BACKEND/app/Services/JiraService.php +++ b/BACKEND/app/Services/JiraService.php @@ -76,7 +76,7 @@ class JiraService "assignee = '%s' AND status IN ('backlog', 'todo', 'in progress')", $accountId ), - 'maxResults' => 10, + 'maxResults' => 50, 'startAt' => $startAt ]; @@ -104,7 +104,7 @@ class JiraService $body = [ 'jql' => "worklogAuthor = '{$accountId}'AND worklogDate >= '{$startDate}' AND worklogDate <= '{$endDate}'", 'fields' => ['summary', 'status', 'timeoriginalestimate', 'timespent', 'project'], - 'maxResults' => 50 + 'maxResults' => 100 ]; $response = $this->client->post('/rest/api/3/search', [ @@ -134,7 +134,7 @@ class JiraService ] ])->then(function ($checkApiResponse) use ($issueId, $index) { $checkApi = json_decode($checkApiResponse->getBody()->getContents(), true); - $maxResults = 50; + $maxResults = 100; $totalWorklogs = $checkApi['total']; return $this->client->getAsync("/rest/api/3/issue/{$issueId}/worklog", [ 'query' => [ diff --git a/FRONTEND/src/pages/Tracking/Tracking.tsx b/FRONTEND/src/pages/Tracking/Tracking.tsx index 7c87cc6..3d0afaa 100755 --- a/FRONTEND/src/pages/Tracking/Tracking.tsx +++ b/FRONTEND/src/pages/Tracking/Tracking.tsx @@ -116,8 +116,13 @@ const Tracking = () => { } useEffect(()=>{ - setInterval(()=>{ + if(listTracking.data.length === 0){ getAllTracking() + } + setInterval(()=>{ + if(window.location.pathname.includes('tracking')){ + getAllTracking() + } }, 7000) }, []) return ( diff --git a/FRONTEND/src/pages/Worklogs/Worklogs.tsx b/FRONTEND/src/pages/Worklogs/Worklogs.tsx index 8ef994f..8de8782 100644 --- a/FRONTEND/src/pages/Worklogs/Worklogs.tsx +++ b/FRONTEND/src/pages/Worklogs/Worklogs.tsx @@ -117,7 +117,7 @@ const Worklogs = () => { startDate: localStorage.getItem('data') !== null ? JSON.parse(localStorage.getItem('data')!).date.startDate - : moment(Date.now()).format('YYYY-MM-DD'), + : moment(Date.now()-604800000).format('YYYY-MM-DD'), endDate: localStorage.getItem('data') !== null ? JSON.parse(localStorage.getItem('data')!).date.endDate @@ -172,65 +172,88 @@ const Worklogs = () => { ) : (
-
-

- Admin/Worklogs - {!updating ? ( - - Updating data in the background ... - - ) : ( - '' - )} -

-
- - { - setDate({ ...date, startDate: moment(e).format('YYYY-MM-DD') }) - }} - /> - { - setDate({ ...date, endDate: moment(e).format('YYYY-MM-DD') }) - }} - /> - + { + setDate({ ...date, startDate: moment(e).format('YYYY-MM-DD') }); + }} + /> + { + setDate({ ...date, endDate: moment(e).format('YYYY-MM-DD') }); + }} + /> + + - {/* Box main content */} - - - - Members - - - {worklogs.map((w) => ( + + {/* Box main content */} + + + + Members + + + {worklogs.map((w) => ( { ))} - - - - {worklogs?.map((user, index) => ( - // Box user - - - - {user.username}( - {user?.information.issues.reduce( - (total: number, issue: Issue) => { - var totalSpent = issue.fields.worklog.worklogs?.reduce( - (accumulator: number, currentValue: WorkLog) => { - if ( - parseInt(moment(date.startDate).format('YYYYMMDD')) <= - parseInt( - moment(currentValue.started).format('YYYYMMDD'), - ) && - parseInt( - moment(currentValue.started).format('YYYYMMDD'), - ) <= - parseInt(moment(date.endDate).format('YYYYMMDD')) && - currentValue.updateAuthor.displayName === - user.username - ) { - return accumulator + currentValue.timeSpentSeconds - } - return accumulator - }, - 0, - ) - return total + totalSpent + + + {worklogs?.map((user, index) => ( + // Box user + + + + {user.username}( + {user?.information.issues.reduce((total, issue) => { + const totalSpent = issue.fields.worklog.worklogs?.reduce( + (accumulator, currentValue) => { + if ( + parseInt(moment(date.startDate).format('YYYYMMDD')) <= + parseInt(moment(currentValue.started).format('YYYYMMDD')) && + parseInt(moment(currentValue.started).format('YYYYMMDD')) <= + parseInt(moment(date.endDate).format('YYYYMMDD')) && + currentValue.updateAuthor.displayName === user.username + ) { + return accumulator + currentValue.timeSpentSeconds; + } + return accumulator; }, 0, - ) / - 60 / - 60} - h) - - {/* Box issue-todo */} - - {/* Box issue */} - - - WORKLOG - - {user.information.issues.map((iss) => { - if ( - iss.fields.worklog.worklogs.filter( - (w) => - parseInt(moment(date.startDate).format('YYYYMMDD')) <= - parseInt(moment(w.started).format('YYYYMMDD')) && - parseInt(moment(date.endDate).format('YYYYMMDD')) >= - parseInt(moment(w.started).format('YYYYMMDD')) && - w.updateAuthor.displayName === user.username, - ).length > 0 - ) { - return ( - - {/* Box information issue */} - - - Summary:{' '} - - - - {iss.fields.project.name} - - - - {iss.fields.summary} - - - - Estimate:{' '} - {iss.fields.timeoriginalestimate / 60 / 60}h - - - Total time spent:{' '} - {iss.fields.timespent / 60 / 60}h - - - Time spent ({date.startDate === date.endDate ? date.startDate : date.startDate+" to "+date.endDate}): - {' '}{iss.fields.worklog.worklogs?.reduce( - ( - accumulator: number, - currentValue: WorkLog, - ) => { - if ( - parseInt( - moment(date.startDate).format('YYYYMMDD'), - ) <= - parseInt( - moment(currentValue.started).format( - 'YYYYMMDD', - ), - ) && - parseInt( - moment(currentValue.started).format( - 'YYYYMMDD', - ), - ) <= - parseInt( - moment(date.endDate).format('YYYYMMDD'), - ) && - currentValue.updateAuthor.displayName === - user.username - ) { - return ( - accumulator + - currentValue.timeSpentSeconds - ) - } - return accumulator - }, - 0, - ) / - 60 / - 60} - h - - - {iss.fields.worklog.worklogs?.map((log, index) => { - if ( - moment(date.startDate).format('YYYYMMDD') <= - moment(log.started).format('YYYYMMDD') && - moment(log.started).format('YYYYMMDD') <= - moment(date.endDate).format('YYYYMMDD') && - log.updateAuthor.displayName === user.username - ) { - return ( - // Box worklog - - - Start date:{' '} - {moment(log.started).format( - 'HH:mm YYYY/MM/DD', - )} - - - Time spent: {log.timeSpent} - - {log?.comment && - log?.comment?.content[0]?.content[0] - ?.text && ( - - Comment:{' '} - {log?.comment && - log?.comment?.content[0]?.content[0] - ?.text} - - )} - - ) - } - })} - - ) - } - })} - - {/* Box todo */} - - - ASSIGNMENT - - {user.tasksAssign.issues?.map((iss, index) => { + ); + return total + totalSpent; + }, 0) / + 60 / + 60} + h) + + {/* Box issue-todo */} + + {/* Box issue */} + + + WORKLOG + + {user.information.issues.map((iss) => { + if ( + iss.fields.worklog.worklogs.filter( + (w) => + parseInt(moment(date.startDate).format('YYYYMMDD')) <= + parseInt(moment(w.started).format('YYYYMMDD')) && + parseInt(moment(date.endDate).format('YYYYMMDD')) >= + parseInt(moment(w.started).format('YYYYMMDD')) && + w.updateAuthor.displayName === user.username, + ).length > 0 + ) { return ( - - - - {iss.fields.project.name} + {/* Box information issue */} + + + {iss.fields.status.name} + + + Summary:{' '} + + + + {iss.fields.project.name} + + + + {iss.fields.summary} + + + + Estimate: {iss.fields.timeoriginalestimate / 60 / 60}h + + + Total time spent: {iss.fields.timespent / 60 / 60}h + + + + Time spent{' '} + + ( + {date.startDate === date.endDate + ? date.startDate + : date.startDate + ' to ' + date.endDate} + ) + + : + {' '} + {iss.fields.worklog.worklogs?.reduce( + (accumulator, currentValue) => { + if ( + parseInt(moment(date.startDate).format('YYYYMMDD')) <= + parseInt(moment(currentValue.started).format('YYYYMMDD')) && + parseInt(moment(currentValue.started).format('YYYYMMDD')) <= + parseInt(moment(date.endDate).format('YYYYMMDD')) && + currentValue.updateAuthor.displayName === user.username + ) { + return accumulator + currentValue.timeSpentSeconds; + } + return accumulator; + }, + 0, + ) / + 60 / + 60} + h - - Summary: - - {iss.fields.summary} - - - - Time spent: {iss.fields.timespent / 60 / 60}h - - - Estimate: {iss.fields.timeoriginalestimate / 60 / 60}h - - - Status: - {iss.fields.status.name} + {iss.fields.worklog.worklogs?.map((log, index) => { + if ( + moment(date.startDate).format('YYYYMMDD') <= moment(log.started).format('YYYYMMDD') && + moment(log.started).format('YYYYMMDD') <= moment(date.endDate).format('YYYYMMDD') && + log.updateAuthor.displayName === user.username + ) { + return ( + // Box worklog + + + Start date: {moment(log.started).format('HH:mm YYYY/MM/DD')} + + + Time spent: {log.timeSpent} + + {log?.comment && log?.comment?.content[0]?.content[0]?.text && ( + + Comment: {log?.comment?.content[0]?.content[0]?.text} + + )} + + ); + } + })} + + ); + } + })} + + {/* Box todo */} + + + ASSIGNMENT + + {user.tasksAssign.issues?.map((iss, index) => { + return ( + + + + + {iss.fields.project.name} - ) - })} - + + Summary: + + {iss.fields.summary} + + + + Time spent: {iss.fields.timespent / 60 / 60}h + + + Estimate: {iss.fields.timeoriginalestimate / 60 / 60}h + + + {iss.fields.status.name} + + + ); + })} - ))} - + + ))} -
+ + ) }