Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
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
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
b71a6ffa
Unverified
Commit
b71a6ffa
authored
Apr 05, 2017
by
Robert Knight
Committed by
Sean Hammond
Apr 06, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move flag count retrieval to a helper function
Move the flag count to a helper which is easier to test and re-use.
parent
396b9d16
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
5 deletions
+26
-5
annotation-metadata.js
src/sidebar/annotation-metadata.js
+12
-0
moderation-banner.js
src/sidebar/components/moderation-banner.js
+1
-5
annotation-metadata-test.js
src/sidebar/test/annotation-metadata-test.js
+13
-0
No files found.
src/sidebar/annotation-metadata.js
View file @
b71a6ffa
...
...
@@ -180,9 +180,21 @@ function location(annotation) {
return
Number
.
POSITIVE_INFINITY
;
}
/**
* Return the number of times the annotation has been flagged
* by other users. If moderation data is unavailable, returns 0.
*/
function
flagCount
(
ann
)
{
if
(
!
ann
.
moderation
)
{
return
0
;
}
return
ann
.
moderation
.
flag_count
;
}
module
.
exports
=
{
documentMetadata
:
documentMetadata
,
domainAndTitle
:
domainAndTitle
,
flagCount
:
flagCount
,
isAnnotation
:
isAnnotation
,
isNew
:
isNew
,
isOrphan
:
isOrphan
,
...
...
src/sidebar/components/moderation-banner.js
View file @
b71a6ffa
...
...
@@ -7,11 +7,7 @@ function ModerationBannerController(annotationUI, flash, store) {
var
self
=
this
;
this
.
flagCount
=
function
()
{
var
moderation
=
self
.
annotation
.
moderation
;
if
(
!
moderation
)
{
return
0
;
}
return
moderation
.
flag_count
;
return
annotationMetadata
.
flagCount
(
self
.
annotation
);
};
this
.
isHidden
=
function
()
{
...
...
src/sidebar/test/annotation-metadata-test.js
View file @
b71a6ffa
...
...
@@ -316,4 +316,17 @@ describe('annotation-metadata', function () {
assert
.
isFalse
(
isWaitingToAnchor
(
pending
));
});
});
describe
(
'.flagCount'
,
function
()
{
var
flagCount
=
annotationMetadata
.
flagCount
;
it
(
'returns 0 if the user is not a moderator'
,
function
()
{
assert
.
equal
(
flagCount
(
fixtures
.
defaultAnnotation
()),
0
);
});
it
(
'returns the flag count if present'
,
function
()
{
var
ann
=
fixtures
.
moderatedAnnotation
({
flagCount
:
10
});
assert
.
equal
(
flagCount
(
ann
),
10
);
});
});
});
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