Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
006cb56d
Unverified
Commit
006cb56d
authored
Nov 01, 2022
by
boojack
Committed by
GitHub
Nov 01, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: heatmap data (#394)
parent
55dee0df
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
45 deletions
+31
-45
acl.go
server/acl.go
+2
-2
memo.go
server/memo.go
+8
-17
UsageHeatMap.tsx
web/src/components/UsageHeatMap.tsx
+9
-8
api.ts
web/src/helpers/api.ts
+1
-1
usage-heat-map.less
web/src/less/usage-heat-map.less
+11
-17
No files found.
server/acl.go
View file @
006cb56d
...
...
@@ -104,11 +104,11 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
}
}
if
common
.
HasPrefixes
(
path
,
"/api/memo/all"
,
"/api/memo/:memoId"
,
"/api/memo/amount"
,
"/api/memo/stats"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
if
common
.
HasPrefixes
(
path
,
"/api/memo/all"
,
"/api/memo/:memoId"
,
"/api/memo/amount"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
return
next
(
c
)
}
if
common
.
HasPrefixes
(
path
,
"/api/memo"
,
"/api/tag"
,
"/api/shortcut"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
if
common
.
HasPrefixes
(
path
,
"/api/memo"
,
"/api/tag"
,
"/api/shortcut"
,
"/api/memo/stats"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
if
_
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
return
next
(
c
)
}
...
...
server/memo.go
View file @
006cb56d
...
...
@@ -257,33 +257,24 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
memoFind
:=
&
api
.
MemoFind
{
RowStatus
:
&
normalStatus
,
}
if
userID
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"userId"
));
err
==
nil
{
memoFind
.
CreatorID
=
&
userID
if
creatorID
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
memoFind
.
CreatorID
=
&
creatorID
}
if
memoFind
.
CreatorID
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user id to find memo"
)
}
currentUserID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
if
!
ok
{
if
memoFind
.
CreatorID
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user id to find memo"
)
}
memoFind
.
VisibilityList
=
[]
api
.
Visibility
{
api
.
Public
}
}
else
{
if
memoFind
.
CreatorID
==
nil
{
memoFind
.
CreatorID
=
&
currentUserID
}
else
{
if
*
memoFind
.
CreatorID
!=
currentUserID
{
memoFind
.
VisibilityList
=
[]
api
.
Visibility
{
api
.
Public
,
api
.
Protected
}
}
else
{
memoFind
.
VisibilityList
=
[]
api
.
Visibility
{
api
.
Public
,
api
.
Protected
,
api
.
Privite
}
}
}
visibilitListStr
:=
c
.
QueryParam
(
"visibility"
)
if
visibilitListStr
!=
""
{
visibilityList
:=
[]
api
.
Visibility
{}
for
_
,
visibility
:=
range
strings
.
Split
(
visibilitListStr
,
","
)
{
visibilityList
=
append
(
visibilityList
,
api
.
Visibility
(
visibility
))
}
memoFind
.
VisibilityList
=
visibilityList
}
list
,
err
:=
s
.
Store
.
FindMemoList
(
ctx
,
memoFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to fetch memo list"
)
.
SetInternal
(
err
)
...
...
web/src/components/UsageHeatMap.tsx
View file @
006cb56d
...
...
@@ -28,16 +28,17 @@ interface DailyUsageStat {
}
const
UsageHeatMap
=
()
=>
{
const
{
memos
}
=
useAppSelector
((
state
)
=>
state
.
memo
);
const
[
allStat
,
setAllStat
]
=
useState
<
DailyUsageStat
[]
>
([]);
const
[
currentStat
,
setCurrentStat
]
=
useState
<
DailyUsageStat
|
null
>
(
null
);
const
containerElRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
todayTimeStamp
=
utils
.
getDateStampByDate
(
Date
.
now
());
const
todayDay
=
new
Date
(
todayTimeStamp
).
getDay
()
+
1
;
const
nullCell
=
new
Array
(
7
-
todayDay
).
fill
(
0
);
const
usedDaysAmount
=
(
tableConfig
.
width
-
1
)
*
tableConfig
.
height
+
todayDay
;
const
beginDayTimestemp
=
todayTimeStamp
-
usedDaysAmount
*
DAILY_TIMESTAMP
;
const
{
memos
}
=
useAppSelector
((
state
)
=>
state
.
memo
);
const
[
allStat
,
setAllStat
]
=
useState
<
DailyUsageStat
[]
>
(
getInitialUsageStat
(
usedDaysAmount
,
beginDayTimestemp
));
const
[
currentStat
,
setCurrentStat
]
=
useState
<
DailyUsageStat
|
null
>
(
null
);
const
containerElRef
=
useRef
<
HTMLDivElement
>
(
null
);
useEffect
(()
=>
{
getMemoStats
(
userService
.
getCurrentUserId
())
.
then
(({
data
:
{
data
}
})
=>
{
...
...
@@ -97,12 +98,12 @@ const UsageHeatMap = () => {
count
<=
0
?
""
:
count
<=
1
?
"stat-day-
L
1-bg"
?
"stat-day-
l
1-bg"
:
count
<=
2
?
"stat-day-
L
2-bg"
?
"stat-day-
l
2-bg"
:
count
<=
4
?
"stat-day-
L
3-bg"
:
"stat-day-
L
4-bg"
;
?
"stat-day-
l
3-bg"
:
"stat-day-
l
4-bg"
;
return
(
<
div
...
...
web/src/helpers/api.ts
View file @
006cb56d
...
...
@@ -91,7 +91,7 @@ export function getMemoList(memoFind?: MemoFind) {
}
export
function
getMemoStats
(
userId
:
UserId
)
{
return
axios
.
get
<
ResponseObject
<
number
[]
>>
(
`/api/memo/stats?
use
rId=
${
userId
}
`
);
return
axios
.
get
<
ResponseObject
<
number
[]
>>
(
`/api/memo/stats?
creato
rId=
${
userId
}
`
);
}
export
function
getMemoById
(
id
:
MemoId
)
{
...
...
web/src/less/usage-heat-map.less
View file @
006cb56d
@import "./mixin.less";
@stat-day-L1-bg: #9be9a8;
@stat-day-L2-bg: #40c463;
@stat-day-L3-bg: #30a14e;
@stat-day-L4-bg: #216e39;
.usage-heat-map-wrapper {
@apply flex flex-row justify-start items-center w-full h-32 flex-wrap pr-6 pb-3 shrink-0;
...
...
@@ -25,33 +20,32 @@
> .stat-wrapper {
> .stat-container {
@apply block rounded-sm;
@apply block rounded-sm
bg-gray-200
;
width: 14px;
height: 14px;
background-color: @bg-lightgray;
&.null {
@apply bg-
transparent
;
@apply bg-
gray-200
;
}
&.stat-day-
L
1-bg {
background-color: @stat-day-L1-bg !important
;
&.stat-day-
l
1-bg {
@apply bg-green-400
;
}
&.stat-day-
L
2-bg {
background-color: @stat-day-L2-bg !important
;
&.stat-day-
l
2-bg {
@apply bg-green-500
;
}
&.stat-day-
L
3-bg {
background-color: @stat-day-L3-bg !important
;
&.stat-day-
l
3-bg {
@apply bg-green-600
;
}
&.stat-day-
L
4-bg {
background-color: @stat-day-L4-bg !important
;
&.stat-day-
l
4-bg {
@apply bg-green-700
;
}
&.today {
border: 1px solid
black;
@apply border border-
black;
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment