Skip to content
Snippets Groups Projects
Commit 7d7952ff authored by Pierre-Jean CHANCELLIER's avatar Pierre-Jean CHANCELLIER
Browse files

add favourites page

parent 88bceffd
No related branches found
No related tags found
No related merge requests found
assets/img/favori_add.png

3.06 KiB

assets/img/favori_remove.png

2.89 KiB

...@@ -33,7 +33,7 @@ export default { ...@@ -33,7 +33,7 @@ export default {
$("#btncopy").tooltip("show") $("#btncopy").tooltip("show")
setTimeout(() => { setTimeout(() => {
$("#btncopy").tooltip("hide") $("#btncopy").tooltip("hide")
}, 500) }, 1000)
} }
} }
} }
......
<template> <template>
<div class="card member"> <div class="card member">
<button
id="favori"
class="btn btn-light position-absolute"
:class="{
add: !isFavorite,
remove: isFavorite
}"
@click="toggleFavourite"></button>
<div class="card-body"> <div class="card-body">
<h2 class="card-title text-center"> <h2 class="card-title text-center mb-4">
{{ hash.uid }} {{ hash.uid }}
<BadgeStatus :membre="hash" /> <BadgeStatus :membre="hash" />
</h2> </h2>
...@@ -121,13 +129,74 @@ ...@@ -121,13 +129,74 @@
<script> <script>
export default { export default {
data() {
return {
favourites: []
}
},
props: { props: {
hash: Object hash: Object
},
methods: {
toggleFavourite() {
let $this = this
$("#favori").tooltip({
title: function () {
return $this.isFavorite
? $this.$t("favoris.supprime")
: $this.$t("favoris.enregistre")
},
html: true,
trigger: "manual"
})
$("#favori").tooltip("show")
setTimeout(() => {
$("#favori").tooltip("hide")
}, 1000)
if (!this.isFavorite) {
this.favourites.push(this.hash.uid)
} else {
this.favourites.splice(this.favourites.indexOf(this.hash.uid), 1)
}
localStorage.favourites = JSON.stringify(this.favourites)
}
},
computed: {
isFavorite() {
this.favourites = localStorage.favourites
? JSON.parse(localStorage.favourites)
: []
return this.favourites.includes(this.hash.uid)
}
} }
} }
</script> </script>
<style lang="scss"> <style lang="scss">
#favori {
top: 1.25rem;
left: 1.25rem;
background-color: var(--light);
background-size: 75%;
background-repeat: no-repeat;
background-position: center;
width: 50px;
height: 50px;
&.add {
background-image: url("~/assets/img/favori_add.png");
}
&.remove {
background-image: url("~/assets/img/favori_remove.png");
}
}
.member { .member {
.table { .table {
text-align: center; text-align: center;
......
import { InMemoryCache, IntrospectionFragmentMatcher, defaultDataIdFromObject } from 'apollo-cache-inmemory' import {
import introspectionQueryResultData from './fragmentTypes.json'; InMemoryCache,
IntrospectionFragmentMatcher,
defaultDataIdFromObject
} from "apollo-cache-inmemory"
import introspectionQueryResultData from "./fragmentTypes.json"
const fragmentMatcher = new IntrospectionFragmentMatcher({ const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData introspectionQueryResultData
}) })
// Apparemment il faut utiliser la syntaxe Apollo v2 // Apparemment il faut utiliser la syntaxe Apollo v2
export const cache = new InMemoryCache({ export const cache = new InMemoryCache({
addTypename: false, addTypename: false,
fragmentMatcher, fragmentMatcher,
dataIdFromObject: object => { dataIdFromObject: (object) => {
switch (object.__typename) { switch (object.__typename) {
case 'Identity': return object.hash case "Identity":
case 'Event': return object.block.number return object.hash
case 'EventId': return `${object.member.hash}:${object.inOut}` case "Event":
case 'Forecast': return `${object.member.hash}:${object.date}:${object.after}:${object.proba}` return object.block.number
default: return defaultDataIdFromObject(object); // fall back to default handling case "EventId":
} return `${object.member.hash}:${object.inOut}`
} case "Forecast":
}) return `${object.member.hash}:${object.date}:${object.after}:${object.proba}`
\ No newline at end of file case "GroupId":
return `${object.id.hash}`
default:
return defaultDataIdFromObject(object) // fall back to default handling
}
}
})
import gql from "graphql-tag" import gql from "graphql-tag"
// Pour la sidebar // Pour la sidebar
export const LAST_BLOCK = gql`query LastBlock{ export const LAST_BLOCK = gql`
countMax { query LastBlock {
number countMax {
bct number
utc0 bct
} utc0
}` }
}
`
// Pour la page index // Pour la page index
export const LAST_EVENTS = gql`query LastEvents($start: Int64, $end: Int64) { export const LAST_EVENTS = gql`
membersCount(start: $start, end: $end) { query LastEvents($start: Int64, $end: Int64) {
idList { membersCount(start: $start, end: $end) {
__typename idList {
member : id { __typename
__typename member: id {
pubkey __typename
uid pubkey
status uid
hash status
limitDate hash
history { limitDate
__typename history {
in __typename
block { in
__typename block {
number __typename
} number
} }
received_certifications { }
__typename received_certifications {
limit __typename
} limit
} }
inOut }
}, inOut
block { }
__typename block {
number __typename
} number
} }
} ` }
}
// Pour la page previsions/index `
export const PREVISIONS = gql`query GetDossiers {
now {
number
bct
__typename
}
parameter(name: sigQty) {
sigQty: value
__typename
}
wwFile(full: true) {
certifs_dossiers {
... on MarkedDatedCertification {
datedCertification {
date
certification {
from {
uid
__typename
}
to {
uid
__typename
}
expires_on
__typename
}
__typename
}
__typename
}
... on MarkedDossier {
dossier {
main_certifs
newcomer {
uid
lastApplication {
lastAppDate: bct
__typename
}
distance: distanceE {
value {
ratio
__typename
}
dist_ok
__typename
}
__typename
}
date
minDate
expires_on: limit
certifications {
date
certification {
from {
uid
quality {
ratio
__typename
}
__typename
}
expires_on
__typename
}
__typename
}
__typename
}
__typename
}
}
__typename
}
}`
// Pour la page previsions/newcomers // Pour la page previsions/newcomers
export const NEWCOMERS = gql`query GetNewcomers{ export const NEWCOMERS = gql`
wwResult { query GetNewcomers {
__typename wwResult {
permutations_nb __typename
dossiers_nb permutations_nb
certifs_nb dossiers_nb
forecastsByNames { certifs_nb
__typename forecastsByNames {
member : id { __typename
__typename member: id {
pubkey __typename
uid pubkey
status uid
hash status
limitDate hash
received_certifications { limitDate
__typename received_certifications {
limit __typename
} limit
} }
date }
after date
proba after
} proba
} }
} ` }
}
`
// Pour la page membres/index // Pour la page membres/index
export const SEARCH_MEMBERS = gql`query SearchMember($hint: String) { export const SEARCH_MEMBERS = gql`
idSearch(with: {hint: $hint}) { query SearchMember($hint: String) {
__typename idSearch(with: { hint: $hint }) {
ids { __typename
__typename ids {
pubkey __typename
uid pubkey
status uid
hash status
limitDate hash
received_certifications { limitDate
__typename received_certifications {
limit __typename
} limit
} }
} }
} ` }
}
`
// Pour la page membres/_hash // Pour la page membres/_hash
export const SEARCH_MEMBER = gql`query SearchMemberWithHash($hash: Hash!) { export const SEARCH_MEMBER = gql`
idFromHash(hash: $hash) { query SearchMemberWithHash($hash: Hash!) {
...attr idFromHash(hash: $hash) {
pubkey ...attr
isLeaving pubkey
sentry isLeaving
membership_pending sentry
limitDate membership_pending
distanceE { limitDate
__typename distanceE {
value { __typename
__typename value {
ratio __typename
} ratio
dist_ok }
} dist_ok
distance { }
__typename distance {
value { __typename
__typename value {
ratio __typename
} ratio
dist_ok }
} dist_ok
received_certifications { }
__typename received_certifications {
certifications { __typename
__typename certifications {
from { __typename
...attr from {
} ...attr
expires_on }
pending expires_on
} pending
} }
sent_certifications { }
__typename sent_certifications {
to { __typename
...attr to {
} ...attr
expires_on }
pending expires_on
} pending
} }
} }
fragment attr on Identity { }
__typename fragment attr on Identity {
uid __typename
hash uid
status hash
minDate status
minDatePassed minDate
quality { minDatePassed
__typename quality {
ratio __typename
} ratio
received_certifications { }
__typename received_certifications {
limit __typename
} limit
}` }
}
`
// Pour la page parametres // Pour la page parametres
export const PARAMS = gql`query getParams{ export const PARAMS = gql`
allParameters { query getParams {
name allParameters {
par_type name
value par_type
comment value
} comment
}` }
\ No newline at end of file }
`
// Pour la page favoris
export const FAVORIS = gql`
query getFavoris($group: [String!]!) {
filterGroup(group: $group) {
__typename
selected {
__typename
id {
...attr
}
}
others {
__typename
id {
...attr
}
}
}
}
fragment attr on Identity {
__typename
pubkey
uid
status
hash
limitDate
received_certifications {
__typename
limit
}
}
`
...@@ -62,6 +62,12 @@ ...@@ -62,6 +62,12 @@
"title": "Duniter" "title": "Duniter"
}, },
"expire": "Expires", "expire": "Expires",
"favoris": {
"enregistre": "Saved to favorites&nbsp;!",
"none": "You don't have any favorites yet",
"supprime": "Deleted from favourites&nbsp;!",
"title": "My favourites"
},
"futuremembers": "Future members", "futuremembers": "Future members",
"infos": "Informations", "infos": "Informations",
"inout": "Entries and exits of the web of trust for the last 2 days", "inout": "Entries and exits of the web of trust for the last 2 days",
......
...@@ -62,6 +62,12 @@ ...@@ -62,6 +62,12 @@
"title": "Duniter" "title": "Duniter"
}, },
"expire": "Expira el", "expire": "Expira el",
"favoris": {
"enregistre": "¡Guardado en favoritos!",
"none": "Aún no tienes favoritos",
"supprime": "¡Eliminado de favoritos!",
"title": "Mis favoritos"
},
"futuremembers": "Futuros miembros", "futuremembers": "Futuros miembros",
"infos": "Informaciones", "infos": "Informaciones",
"inout": "Entradas y salidas de la red de confianza en los últimos 2 días", "inout": "Entradas y salidas de la red de confianza en los últimos 2 días",
......
...@@ -62,6 +62,12 @@ ...@@ -62,6 +62,12 @@
"title": "Duniter" "title": "Duniter"
}, },
"expire": "Expire le", "expire": "Expire le",
"favoris": {
"enregistre": "Enregistré dans les favoris&nbsp;!",
"none": "Vous n'avez pas encore de favoris",
"supprime": "Supprimé des favoris&nbsp;!",
"title": "Mes favoris"
},
"futuremembers": "Futurs membres", "futuremembers": "Futurs membres",
"infos": "Informations", "infos": "Informations",
"inout": "Entrées et sorties de la toile de confiance des 2 derniers jours", "inout": "Entrées et sorties de la toile de confiance des 2 derniers jours",
......
...@@ -14,7 +14,10 @@ export default { ...@@ -14,7 +14,10 @@ export default {
menus: [ menus: [
{ {
title: "wot.title", title: "wot.title",
items: [{ path: "/membres", title: "membres" }] items: [
{ path: "/membres", title: "membres" },
{ path: "/favoris", title: "favoris.title" }
]
}, },
{ {
title: "previsions.title", title: "previsions.title",
......
<template>
<main class="container">
<h2 class="text-center my-5 font-weight-light">
{{ $t("favoris.title") }}
</h2>
<NavigationLoader :isLoading="$apollo.queries.favoris.loading" />
<div class="row text-center">
<div class="col">
<transition name="fade">
<div class="alert alert-danger" v-if="error">{{ error }}</div>
</transition>
<transition name="fade">
<MemberList
:members="favoris"
v-if="favoris && favoris.length != 0" />
</transition>
<transition name="fade">
<div
class="alert alert-info"
v-if="!$apollo.queries.favoris.loading && favoris.length == 0">
{{ $t("favoris.none") }}
</div>
</transition>
</div>
</div>
</main>
</template>
<script>
import { FAVORIS } from "@/graphql/queries.js"
export default {
data() {
return {
breadcrumb: [
{
text: this.$t("accueil"),
to: "/"
},
{
text: this.$t("favoris.title"),
active: true
}
],
error: null
}
},
// local functions. You can use :
// {{ myFunction() }} in template if a value is returned
// - this.myFunction everywhere in the page but not in arrows functions
// - @event="myFunction" on Vue eventHandlers
// methods: {
// myFunction() {
// }
// },
// For computed values. Use {{ myComputedValue }} in the template
// computed: {
// myComputedValue : function() {
// return this.var * 3
// }
// },
apollo: {
favoris: {
query: FAVORIS,
variables() {
return { group: JSON.parse(localStorage.favourites) }
},
update(data) {
let retour = []
for (let i = 0; i < data.filterGroup.selected.length; i++) {
retour[i] = data.filterGroup.selected[i].id
}
return retour
},
error(err) {
this.error = err.message
}
}
},
nuxtI18n: {
paths: {
fr: "/favoris",
en: "/favourites",
es: "/favoritos"
}
},
mounted() {
$nuxt.$emit("changeRoute", this.breadcrumb)
}
}
</script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment