Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
subugoe
emo
TIDO
Commits
29fa9b5a
Commit
29fa9b5a
authored
Apr 27, 2021
by
Mathias Goebel
Browse files
feat: move annotation data handling to component
parent
08da9fe2
Pipeline
#191199
passed with stages
in 2 minutes and 56 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/App.vue
View file @
29fa9b5a
...
...
@@ -125,50 +125,10 @@ export default {
return
data
;
},
/**
* filter the annotation IDs and the matching text part of the current item
*
* caller: *getAnnotations()*
*
* @param array annotations
*
* @return array identifiers
*/
filterAnnotations
(
annotations
)
{
const
identifiers
=
[];
annotations
.
forEach
((
annotation
)
=>
{
const
id
=
this
.
getAnnotationId
(
annotation
);
identifiers
.
push
({
id
,
contenttype
:
annotation
.
body
[
'
x-content-type
'
],
description
:
annotation
.
body
.
value
,
selected
:
this
.
config
.
annotations
.
show
,
});
});
return
identifiers
;
},
/**
* get the annotation id/s of the current item
*
* caller: *filterAnnotations()*
*
* @param object annotation
*
* @return string
*/
getAnnotationId
(
annotation
)
{
const
split
=
annotation
.
target
.
id
.
split
(
'
/
'
);
return
split
[
split
.
length
-
1
];
},
/**
* get annotations of the current item
* caller: *getItemData()*
*
* @param string url
*/
getAnnotations
(
url
)
{
...
...
@@ -178,7 +138,7 @@ export default {
this
.
request
(
annotations
.
annotationCollection
.
first
)
.
then
((
current
)
=>
{
if
(
current
.
annotationPage
.
items
.
length
)
{
this
.
annotations
=
this
.
filterAnnotations
(
current
.
annotationPage
.
items
)
;
this
.
annotations
=
current
.
annotationPage
.
items
;
}
else
this
.
annotations
=
[];
});
}
...
...
src/components/annotations.vue
View file @
29fa9b5a
...
...
@@ -3,20 +3,18 @@
v-if=
"annotations.length"
class=
"q-ma-sm annotations"
>
<q-list
class=
"full-width"
>
<q-list>
<q-item
v-for=
"annotation in annotations"
v-for=
"annotation in
filterAnnotations(
annotations
)
"
:key=
"annotation.id"
v-ripple
clickable
>
<q-item-section
avatar
>
<q-icon
:name=
"getIcon(annotation.contenttype)"
/>
<q-icon
:name=
"getIcon(annotation.
body['x-
content
-
type
']
)"
/>
</q-item-section>
<q-item-section>
{{
annotation
.
description
}}
{{
annotation
.
body
.
value
}}
</q-item-section>
</q-item>
</q-list>
...
...
@@ -42,17 +40,50 @@ export default {
},
},
data
()
{
return
{};
return
{
test
:
[],
};
},
created
()
{
this
.
icons
=
Icons
;
},
mounted
()
{},
methods
:
{
availableTypes
()
{
const
array
=
[];
this
.
config
.
annotations
.
types
.
forEach
((
item
)
=>
array
.
push
(
item
.
contenttype
));
return
array
;
},
getIcon
(
contenttype
)
{
const
result
=
this
.
config
.
annotations
.
types
.
filter
((
item
)
=>
item
.
contenttype
===
contenttype
);
return
Icons
.[
result
[
0
].
icon
];
},
/**
* filter the annotation for configured ones
* TODO: move to computed?
* @param array annotations
* @return array annotations without unconfigured ones.
*/
filterAnnotations
(
annotations
)
{
const
arr
=
[];
annotations
.
forEach
((
annotation
)
=>
{
if
(
this
.
availableTypes
().
filter
((
item
)
=>
item
===
annotation
.
body
[
'
x-content-type
'
]).
length
>
0
)
{
arr
.
push
(
annotation
);
}
});
return
arr
;
},
/**
* get the annotation id/s of the current item
* @param object annotation
* @return string
*/
getAnnotationId
(
annotation
)
{
const
split
=
annotation
.
target
.
id
.
split
(
'
/
'
);
return
split
[
split
.
length
-
1
];
},
},
};
</
script
>
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment