diff --git a/back/webmin/graphql/schema.graphqls b/back/webmin/graphql/schema.graphqls index 7334a8c15e7541907f7ec82bbd262f1f8f8d63aa..6b30b11f4f6b380a5174b5a209171bef3e65c975 100644 --- a/back/webmin/graphql/schema.graphqls +++ b/back/webmin/graphql/schema.graphqls @@ -244,5 +244,6 @@ type Query { stopAndResetData: Boolean! startNode: Boolean! synchronize(url: String!): Boolean + uid(pub: String!): String } diff --git a/back/webmin/queries/gql-uid.ts b/back/webmin/queries/gql-uid.ts new file mode 100644 index 0000000000000000000000000000000000000000..fd4e7715147972154ae3865569de8511ecc7ffa0 --- /dev/null +++ b/back/webmin/queries/gql-uid.ts @@ -0,0 +1,11 @@ +import {Server} from 'duniter/server' + +export function gqlUid(server: Server) { + return async (_: any, params: { pub: string }) => { + const idty = await server.dal.getWrittenIdtyByPubkey(params.pub) + if (idty) { + return idty.uid + } + return null + } +} diff --git a/back/webmin/webmin.ts b/back/webmin/webmin.ts index 11be942ac986d8ac9785c1c895e42664147377db..795a2ec73d58ee7dfb920b78c00aca64a1986ee3 100644 --- a/back/webmin/webmin.ts +++ b/back/webmin/webmin.ts @@ -10,6 +10,7 @@ import {Querable, querablep} from 'duniter/app/lib/common-libs/querable' import {NodeState, SoftVersions} from '../../common/types' import {SyncProgress, SyncEnding} from '../../common/dto' import {WS2PConnection} from 'duniter/app/modules/ws2p/lib/WS2PConnection' +import {gqlUid} from './queries/gql-uid' export const pubsub = new PubSub(); @@ -232,7 +233,9 @@ export function plugModule(server: Server, startServices: () => Promise<void>, s }) syncPromise = querablep(sync.syncPromise) - } + }, + + uid: gqlUid(server) }, Subscription: { diff --git a/src/components/ForkNode.vue b/src/components/ForkNode.vue index 366fe1beba565be2931368e2329a037432bf35ed..bec265e9adba4a30e91f92b5ce81215bf1f48dcc 100644 --- a/src/components/ForkNode.vue +++ b/src/components/ForkNode.vue @@ -35,16 +35,35 @@ import Vue from 'vue'; import {Prop} from 'vue-property-decorator'; + const LABEL_LENGTH = 8 + @Component({}) export default class extends Vue { - @Prop(String) label + + @Prop(String) pubkey @Prop(Number) type @Prop(Number) number @Prop(Number) forkLevel + uid = '' + get bgColor() { - const rgb = Math.min(240, 120 + this.forkLevel * 1) + const rgb = Math.min(240, 90 + this.forkLevel * 10) return 'rgb(' + rgb + ',' + rgb + ',' + rgb + ')' } + + async mounted() { + this.uid = await this.$webmin.uid(this.pubkey) + } + + get label() { + if (this.uid) { + const overflow = this.uid.length - LABEL_LENGTH + return overflow >= 0 + ? this.uid.substr(0, LABEL_LENGTH - 2) + '..' + : this.uid.padEnd(LABEL_LENGTH, ' ') + } + return '*' + this.pubkey.substr(0, LABEL_LENGTH - 1) + } } </script> diff --git a/src/lib/services/webmin.service.ts b/src/lib/services/webmin.service.ts index e45b9fb55c9fcf6484ce9cb1e559092e9c7ed1ea..343d803855d17e177692f3539afbd091d987444f 100644 --- a/src/lib/services/webmin.service.ts +++ b/src/lib/services/webmin.service.ts @@ -276,4 +276,20 @@ export class WebminService { }) .result() } + + async uid(pub: string) { + const res = await this.getApollo() + .watchQuery({ + query: gql` + query ($pub: String!){ + uid(pub: $pub) + } + `, + variables: { + pub + }, + }) + .result() + return res.data.uid + } } diff --git a/src/views/home/Overview.vue b/src/views/home/Overview.vue index 83fe01f7f1d5ef02abad6eaf109fc27c2e9e3b9b..f09024d5d88b94b7f35dee5ce0d6b422327c3cb2 100644 --- a/src/views/home/Overview.vue +++ b/src/views/home/Overview.vue @@ -38,8 +38,8 @@ </div> <div class="col"> <ForkNode - v-for="node in networkForkView" v-bind:key="node.pubkey" - :label="node.label" + v-for="node in networkForkView" v-bind:key="node.pub" + :pubkey="node.pub" :type="node.fork" :number="node.forkNumber" :forkLevel="node.forkLevel" @@ -144,7 +144,7 @@ currentSecond: { bs: string, count: number } netViewKeys: string[] = [] netPubkeys: string[] = [] - networkForkView: { label: string, fork: number }[] = [] + networkForkView: { pub: string, fork: number }[] = [] theNetView: { [bs: string]: number } = {} nodes: { name: string }[] = Array.from({ length: 30 }).map((v, i) => ({ name: `Node#${i}` })) @@ -236,7 +236,7 @@ this.networkForkView = this.netPubkeys.map(pub => { return { - label: pub.substr(0, 8), + pub, fork: this.headsByNode[pub] === this.currentBest.bs ? 0 : (this.headsByNode[pub] === this.currentSecond.bs ? 1 : 2), forkLevel: parseInt(String(this.currentBest.bs)) - parseInt(String(this.headsByNode[pub])), forkNumber: parseInt(String(this.headsByNode[pub]))