Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
webclient
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
Service Desk
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
retribute.me
webclient
Commits
734f8f8c
Verified
Commit
734f8f8c
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Basic display of suggestions
parent
80f8d93d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/Suggestions.vue
+50
-8
50 additions, 8 deletions
src/components/Suggestions.vue
src/sources/mastodon.js
+8
-8
8 additions, 8 deletions
src/sources/mastodon.js
with
58 additions
and
16 deletions
src/components/Suggestions.vue
+
50
−
8
View file @
734f8f8c
...
...
@@ -19,26 +19,38 @@
<a
@
click=
"fetch(account.id)"
class=
"secondary-content"
><i
class=
"material-icons"
>
refresh
</i></a>
</li>
</ul>
<h2>
Suggestions
</h2>
<h2>
Suggestions
<button
@
click=
"fetch()"
:class=
"['waves-effect', 'waves-light',
{disabled: isLoading}, 'btn-small']" :disabled="isLoading">
<i
class=
"material-icons left"
>
refresh
</i>
Fetch data
</button>
</h2>
<div
v-if=
"isLoading"
class=
"progress"
>
<div
class=
"indeterminate"
></div>
</div>
<ul
class=
"collection"
>
<li
class=
"collection-item avatar"
v-for=
"suggestion in filteredSuggestions"
:key=
"suggestion.fullId"
>
<img
v-if=
"suggestion.avatar"
:src=
"suggestion.avatar"
alt=
""
class=
"circle"
>
<a
target=
"_blank"
rel=
"noopener noreferrer"
:href=
"suggestion.url"
class=
"title"
>
{{
suggestion
.
name
}}
</a>
<p>
Score:
{{
suggestion
.
weight
}}
</p>
</li>
</ul>
</div>
</
template
>
<
script
>
import
sources
from
'
@/sources
'
import
orderBy
from
'
lodash/orderBy
'
export
default
{
data
()
{
return
{
isLoading
:
false
,
results
:
{}
results
:
{},
aggregatedSuggestions
:
{}
}
},
computed
:
{
...
...
@@ -47,9 +59,31 @@ export default {
a
.
_source
=
sources
.
sources
[
a
.
source
]
return
a
})
}
},
filteredSuggestions
()
{
return
orderBy
(
Object
.
values
(
this
.
aggregatedSuggestions
),
[
'
weight
'
,
'
id
'
],
[
'
desc
'
,
'
asc
'
])
},
},
methods
:
{
aggregateSuggestions
(
results
)
{
const
aggregated
=
{}
Object
.
keys
(
results
).
forEach
((
account
)
=>
{
let
r
=
results
[
account
]
if
(
!
r
.
results
||
!
r
.
results
.
accounts
)
{
}
else
{
Object
.
keys
(
r
.
results
.
accounts
).
forEach
((
key
)
=>
{
if
(
aggregated
[
key
])
{
aggregated
[
key
].
weight
+=
r
.
results
.
accounts
[
key
].
weight
aggregated
[
key
].
accounts
.
push
(
account
)
}
else
{
aggregated
[
key
]
=
{...
r
.
results
.
accounts
[
key
],
accounts
:
[
account
],
fullId
:
key
}
}
})
}
})
return
aggregated
},
async
fetch
(
id
)
{
let
accounts
if
(
id
)
{
...
...
@@ -71,6 +105,14 @@ export default {
}
this
.
isLoading
=
false
}
},
watch
:
{
results
:
{
handler
(
v
)
{
this
.
aggregatedSuggestions
=
this
.
aggregateSuggestions
(
v
)
},
deep
:
true
,
}
}
}
</
script
>
This diff is collapsed.
Click to expand it.
src/sources/mastodon.js
+
8
−
8
View file @
734f8f8c
...
...
@@ -83,28 +83,28 @@ export default {
router
.
push
({
path
:
'
/
'
})
},
async
fetch
({
account
,
cache
,
store
,
results
,
vue
})
{
vue
.
$set
(
results
,
'
status
'
,
`Fetching favorites...`
)
results
.
status
=
`Fetching favorites...`
const
token
=
store
.
state
.
sources
.
mastodon
.
appTokens
[
`
${
account
.
username
}
@
${
account
.
domain
}
`
].
access_token
const
client
=
axios
.
create
({
baseURL
:
`https://
${
account
.
domain
}
`
,
headers
:
{
'
Authorization
'
:
`Bearer
${
token
}
`
},
})
const
maxFavorites
=
1
00
const
maxFavorites
=
5
00
let
url
=
'
/api/v1/favourites
'
let
handledFavorites
=
0
results
.
progress
=
0
vue
.
$set
(
results
,
'
accounts
'
,
{}
)
results
.
accounts
=
{}
while
(
handledFavorites
<
maxFavorites
)
{
let
response
=
await
client
.
get
(
url
,
{
params
:
{
limit
:
40
}})
response
.
data
.
forEach
((
f
)
=>
{
handledFavorites
+=
1
let
account
=
f
.
account
.
acct
let
account
=
`webfinger:
${
f
.
account
.
acct
}
`
if
(
results
.
accounts
[
account
])
{
results
.
accounts
[
account
]
+=
1
results
.
accounts
[
account
]
.
weight
+=
1
}
else
{
results
.
accounts
[
account
]
=
1
results
.
accounts
[
account
]
=
{
weight
:
1
,
source
:
'
webfinger
'
,
id
:
f
.
account
.
acct
,
avatar
:
f
.
account
.
avatar
,
name
:
f
.
account
.
display_name
,
url
:
f
.
account
.
url
}
}
results
.
progress
=
Math
.
min
(
100
,
results
.
progres
s
+
1
)
results
.
progress
=
Math
.
min
(
100
,
handledFavorites
/
maxFavorite
s
*
1
00
)
})
let
link
=
response
.
headers
.
link
||
''
let
parsed
=
parseLink
(
link
)
...
...
@@ -113,7 +113,7 @@ export default {
}
else
{
break
}
vue
.
$set
(
results
,
'
status
'
,
`Fetched favorites
${
handledFavorites
}
/
${
maxFavorites
}
`
)
results
.
status
=
`Fetched favorites
${
handledFavorites
}
/
${
maxFavorites
}
`
}
results
.
isLoading
=
false
return
results
...
...
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