Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fltrail
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fides
fltrail
Commits
5d81a410
Commit
5d81a410
authored
6 years ago
by
Sven Kästle
Browse files
Options
Downloads
Patches
Plain Diff
refactor: Update methods to newest version of annotation object
parent
82724562
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js
+50
-44
50 additions, 44 deletions
...samforschen/src/main/webapp/assets/js/annotationScript.js
with
50 additions
and
44 deletions
gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js
+
50
−
44
View file @
5d81a410
// initialize user
Id
, userColors and targetId
var
user
Id
=
randomUserId
();
// initialize user
Token
, userColors and targetId
var
user
Token
=
getUserTokenFromUrl
();
var
userColors
=
new
Map
();
var
userColorsDark
=
new
Map
();
var
targetId
=
200
;
...
...
@@ -28,17 +28,20 @@ $(document).ready(function() {
// if user selected something
if
(
body
.
length
>
0
)
{
// annotationPostRequest
var
r
equest
=
{
user
Id
:
user
Id
,
var
annotationPostR
equest
=
{
user
Token
:
user
Token
,
targetId
:
targetId
,
body
:
body
,
startCharacter
:
window
.
getSelection
().
getRangeAt
(
0
).
startOffset
,
endCharacter
:
window
.
getSelection
().
getRangeAt
(
0
).
endOffset
body
:
{
title
:
"
title
"
,
comment
:
body
,
startCharacter
:
window
.
getSelection
().
getRangeAt
(
0
).
startOffset
,
endCharacter
:
window
.
getSelection
().
getRangeAt
(
0
).
endOffset
}
};
console
.
log
(
r
equest
);
console
.
log
(
annotationPostR
equest
);
createAnnotation
(
r
equest
,
function
(
response
)
{
createAnnotation
(
annotationPostR
equest
,
function
(
response
)
{
// display the new annotation
displayAnnotation
(
response
);
...
...
@@ -186,41 +189,48 @@ function displayAnnotation(annotation) {
// insert annotation card
list
.
prepend
(
// list element
$
(
'
<li>
'
)
.
attr
(
'
class
'
,
'
listelement
'
)
.
append
(
// annotation card
$
(
'
<div>
'
).
attr
(
'
class
'
,
'
annotation-card
'
)
.
mouseenter
(
function
()
{
$
(
this
).
children
(
'
.annotation-header
'
).
css
(
'
background-color
'
,
getDarkUserColor
(
annotation
.
user
Id
));
$
(
this
).
children
(
'
.annotation-header
'
).
css
(
'
background-color
'
,
getDarkUserColor
(
annotation
.
user
Token
));
})
.
mouseleave
(
function
()
{
$
(
this
).
children
(
'
.annotation-header
'
).
css
(
'
background-color
'
,
getUserColor
(
annotation
.
user
Id
));
$
(
this
).
children
(
'
.annotation-header
'
).
css
(
'
background-color
'
,
getUserColor
(
annotation
.
user
Token
));
})
.
append
(
// annotation header
$
(
'
<div>
'
).
attr
(
'
class
'
,
'
annotation-header
'
)
.
css
(
'
background-color
'
,
getUserColor
(
annotation
.
user
Id
))
.
css
(
'
background-color
'
,
getUserColor
(
annotation
.
user
Token
))
.
append
(
// header data
$
(
'
<div>
'
).
attr
(
'
class
'
,
'
annotation-header-title
'
)
.
append
(
// user
$
(
'
<div>
'
).
attr
(
'
class
'
,
'
overflow-hidden
'
)
.
append
(
$
(
'
<i>
'
).
attr
(
'
class
'
,
'
fas fa-user
'
)
)
.
append
(
$
(
'
<span>
'
).
append
(
annotation
.
user
Id
)
$
(
'
<span>
'
).
append
(
annotation
.
user
Token
)
)
)
.
append
(
// title
$
(
'
<div>
'
).
attr
(
'
class
'
,
'
overflow-hidden
'
)
.
append
(
$
(
'
<i>
'
).
attr
(
'
class
'
,
'
fas fa-bookmark
'
)
)
.
append
(
$
(
'
<span>
'
).
append
(
'
title
'
+
annotation
.
userId
)
$
(
'
<span>
'
).
append
(
annotation
.
body
.
title
)
)
)
)
.
append
(
// unfold button
$
(
'
<div>
'
).
attr
(
'
class
'
,
'
annotation-header-toggle
'
)
.
click
(
function
()
{
toggleButtonHandler
(
$
(
this
));
...
...
@@ -231,16 +241,19 @@ function displayAnnotation(annotation) {
)
)
.
append
(
// annotation body
$
(
'
<div>
'
).
attr
(
'
class
'
,
'
annotation-body
'
)
.
append
(
$
(
'
<p>
'
).
attr
(
'
class
'
,
'
overflow-hidden
'
).
append
(
annotation
.
body
)
$
(
'
<p>
'
).
attr
(
'
class
'
,
'
overflow-hidden
'
).
append
(
annotation
.
body
.
comment
)
)
)
.
append
(
// annotation footer
$
(
'
<div>
'
).
attr
(
'
class
'
,
'
annotation-footer
'
)
.
append
(
// delete
function
()
{
if
(
user
Id
==
annotation
.
user
Id
)
{
if
(
user
Token
==
annotation
.
user
Token
)
{
return
$
(
'
<div>
'
).
attr
(
'
class
'
,
'
annotation-footer-delete
'
)
.
append
(
$
(
'
<i>
'
).
attr
(
'
class
'
,
deleteIcon
)
...
...
@@ -252,6 +265,7 @@ function displayAnnotation(annotation) {
}
)
.
append
(
// timestamp
$
(
'
<div>
'
).
attr
(
'
class
'
,
'
annotation-footer-date overflow-hidden
'
)
.
append
(
$
(
'
<i>
'
).
attr
(
'
class
'
,
dateIcon
)
...
...
@@ -266,7 +280,7 @@ function displayAnnotation(annotation) {
)
.
data
(
'
annotation
'
,
annotation
)
.
mouseenter
(
function
()
{
addHighlightedText
(
annotation
.
startCharacter
,
annotation
.
endCharacter
,
annotation
.
user
Id
);
addHighlightedText
(
annotation
.
body
.
startCharacter
,
annotation
.
body
.
endCharacter
,
annotation
.
user
Token
);
})
.
mouseleave
(
function
()
{
deleteHighlightedText
();
...
...
@@ -284,11 +298,11 @@ function displayAnnotation(annotation) {
*
* @param startCharacter The offset of the start character
* @param endCharacter The offset of the end character
* @param user
Id
The user
id
* @param user
Token
The user
token
*/
function
addHighlightedText
(
startCharacter
,
endCharacter
,
user
Id
)
{
function
addHighlightedText
(
startCharacter
,
endCharacter
,
user
Token
)
{
// create <span> tag with the annotated text
var
replacement
=
$
(
'
<span></span>
'
).
css
(
'
background-color
'
,
getUserColor
(
user
Id
)).
html
(
documentText
.
slice
(
startCharacter
,
endCharacter
));
var
replacement
=
$
(
'
<span></span>
'
).
css
(
'
background-color
'
,
getUserColor
(
user
Token
)).
html
(
documentText
.
slice
(
startCharacter
,
endCharacter
));
// wrap an <p> tag around the replacement, get its parent (the <p>) and ask for the html
var
replacementHtml
=
replacement
.
wrap
(
'
<p/>
'
).
parent
().
html
();
...
...
@@ -327,39 +341,39 @@ function getSelectedText() {
/**
* Get color based on user id
*
* @param user
Id
The id of the user
* @param user
Token
The id of the user
* @returns {string} The user color
*/
function
getUserColor
(
user
Id
)
{
// insert new color if there is no user
Id
key
if
(
userColors
.
get
(
user
Id
)
==
null
)
{
generateRandomColor
(
user
Id
);
function
getUserColor
(
user
Token
)
{
// insert new color if there is no user
Token
key
if
(
userColors
.
get
(
user
Token
)
==
null
)
{
generateRandomColor
(
user
Token
);
}
// return the color
return
userColors
.
get
(
user
Id
);
return
userColors
.
get
(
user
Token
);
}
/**
* Get dark color based on user id
*
* @param user
Id The id
of the user
* @param user
Token The token
of the user
* @returns {string} The dark user color
*/
function
getDarkUserColor
(
user
Id
)
{
// insert new color if there is no user
Id
key
if
(
userColorsDark
.
get
(
user
Id
)
==
null
)
{
generateRandomColor
(
user
Id
);
function
getDarkUserColor
(
user
Token
)
{
// insert new color if there is no user
Token
key
if
(
userColorsDark
.
get
(
user
Token
)
==
null
)
{
generateRandomColor
(
user
Token
);
}
// return the color
return
userColorsDark
.
get
(
user
Id
);
return
userColorsDark
.
get
(
user
Token
);
}
/**
* Generate a random color of the format 'rgb(r, g, b)'
*
* @param user
Id
The given user
id
* @param user
Token
The given user
token
*/
function
generateRandomColor
(
user
Id
)
{
function
generateRandomColor
(
user
Token
)
{
var
r
=
Math
.
floor
(
Math
.
random
()
*
56
)
+
170
;
var
g
=
Math
.
floor
(
Math
.
random
()
*
56
)
+
170
;
var
b
=
Math
.
floor
(
Math
.
random
()
*
56
)
+
170
;
...
...
@@ -370,8 +384,8 @@ function generateRandomColor(userId) {
var
color
=
'
rgb(
'
+
r
+
'
,
'
+
g
+
'
,
'
+
b
+
'
)
'
;
var
colorDark
=
'
rgb(
'
+
r_d
+
'
,
'
+
g_d
+
'
,
'
+
b_d
+
'
)
'
;
userColors
.
set
(
user
Id
,
color
);
userColorsDark
.
set
(
user
Id
,
colorDark
);
userColors
.
set
(
user
Token
,
color
);
userColorsDark
.
set
(
user
Token
,
colorDark
);
}
/**
...
...
@@ -446,11 +460,3 @@ function toggleButtonHandler(element) {
// toggle between up and down button
element
.
children
(
"
i
"
).
toggleClass
(
"
fa-chevron-down fa-chevron-up
"
)
}
/*
MOCKUP FUNCTIONS
*/
function
randomUserId
()
{
return
Math
.
floor
((
Math
.
random
()
*
12
)
+
1
);;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment