From 0bd9c36db5bfcf2777d08712e1d2d36ad3140b99 Mon Sep 17 00:00:00 2001 From: Nicolas Giard Date: Sat, 22 Sep 2018 11:27:48 -0400 Subject: [PATCH] feat: list sponsors + contributors on contribute admin page --- client/components/admin/admin-contribute.vue | 74 ++++++++++++++++++- .../contribute-query-contributors.gql | 17 +++++ server/graph/resolvers/contribute.js | 33 +++++++++ server/graph/schemas/contribute.graphql | 33 +++++++++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 client/graph/admin/contribute/contribute-query-contributors.gql create mode 100644 server/graph/resolvers/contribute.js create mode 100644 server/graph/schemas/contribute.graphql diff --git a/client/components/admin/admin-contribute.vue b/client/components/admin/admin-contribute.vue index 51bf5468..d16976bd 100644 --- a/client/components/admin/admin-contribute.vue +++ b/client/components/admin/admin-contribute.vue @@ -19,7 +19,7 @@ span {{ $t('admin:contribute.makeADonation') }} .body-1.mt-3.pl-3 {{ $t('admin:contribute.tshirts') }} v-card-actions.ml-2 - v-btn(depressed, color='primary', href='https://wikijs.threadless.com') + v-btn(outline, color='primary', href='https://wikijs.threadless.com') v-icon(left) shopping_cart span {{ $t('admin:contribute.shop') }} v-divider.mt-3 @@ -39,11 +39,83 @@ li {{ $t('admin:contribute.talkToFriends') }} i18next(path='admin:contribute.followUsOnTwitter', tag='li') a(href='https://twitter.com/requarks', target='_blank') Twitter + v-card + v-toolbar(color='teal', dense, dark) + .subheading Sponsors + v-list(two-line, dense) + template(v-for='(sponsor, idx) in sponsors') + v-list-tile(:key='sponsor.id') + v-list-tile-avatar + img(v-if='sponsor.image', :src='sponsor.image') + v-avatar(v-else, color='teal', size='40') + span.white--text.subheading {{sponsor.name[0].toUpperCase()}} + v-list-tile-content + v-list-tile-title {{sponsor.name}} + v-list-tile-sub-title {{sponsor.description}} + v-list-tile-action(v-if='sponsor.twitter') + v-btn(icon, :href='sponsor.twitter', target='_blank') + icon-twitter(fillColor='#9e9e9e') + v-list-tile-action(v-if='sponsor.website') + v-btn(icon, :href='sponsor.website', target='_blank') + v-icon(color='grey') public + v-divider(v-if='idx < sponsors.length - 1') + v-card + v-toolbar(color='blue-grey', dense, dark) + .subheading Backers + v-list(two-line, dense) + template(v-for='(backer, idx) in backers') + v-list-tile(:key='backer.id') + v-list-tile-avatar + img(v-if='backer.image', :src='backer.image') + v-avatar(v-else, color='blue-grey', size='40') + span.white--text.subheading {{backer.name[0].toUpperCase()}} + v-list-tile-content + v-list-tile-title {{backer.name}} + v-list-tile-sub-title {{backer.description}} + v-list-tile-action(v-if='backer.twitter') + v-btn(icon, :href='backer.twitter', target='_blank') + icon-twitter(fillColor='#9e9e9e') + v-list-tile-action(v-if='backer.website') + v-btn(icon, :href='backer.website', target='_blank') + v-icon(color='grey') public + v-divider(v-if='idx < backers.length - 1') diff --git a/client/graph/admin/contribute/contribute-query-contributors.gql b/client/graph/admin/contribute/contribute-query-contributors.gql new file mode 100644 index 00000000..d5c4b4ec --- /dev/null +++ b/client/graph/admin/contribute/contribute-query-contributors.gql @@ -0,0 +1,17 @@ +query { + contribute { + contributors { + company + currency + description + id + image + name + profile + tier + totalDonated + twitter + website + } + } +} diff --git a/server/graph/resolvers/contribute.js b/server/graph/resolvers/contribute.js new file mode 100644 index 00000000..c1d82704 --- /dev/null +++ b/server/graph/resolvers/contribute.js @@ -0,0 +1,33 @@ +const request = require('request-promise') +const _ = require('lodash') + +module.exports = { + Query: { + async contribute() { return {} } + }, + ContributeQuery: { + async contributors(obj, args, context, info) { + const resp = await request({ + uri: 'https://opencollective.com/wikijs/members/all.json', + json: true + }) + const dude = _.filter(resp, c => { + return c.role === 'BACKER' && c.totalAmountDonated > 0 + }).map(c => ({ + company: _.get(c, 'company', '') || '', + currency: _.get(c, 'currency', 'USD') || 'USD', + description: _.get(c, 'description', '') || '', + id: _.get(c, 'MemberId', 0), + image: _.get(c, 'image', '') || '', + name: _.get(c, 'name', 'Anonymous') || '', + profile: _.get(c, 'profile', ''), + tier: _.toLower(_.get(c, 'tier', 'backers')), + totalDonated: _.get(c, 'totalAmountDonated', 0), + twitter: _.get(c, 'twitter', '') || '', + website: _.get(c, 'website', '') || '' + })) + console.info(dude) + return dude + } + } +} diff --git a/server/graph/schemas/contribute.graphql b/server/graph/schemas/contribute.graphql new file mode 100644 index 00000000..ccd8a7d6 --- /dev/null +++ b/server/graph/schemas/contribute.graphql @@ -0,0 +1,33 @@ +# =============================================== +# CONTRIBUTE +# =============================================== + +extend type Query { + contribute: ContributeQuery +} + +# ----------------------------------------------- +# QUERIES +# ----------------------------------------------- + +type ContributeQuery { + contributors: [ContributeContributor] +} + +# ----------------------------------------------- +# TYPES +# ----------------------------------------------- + +type ContributeContributor { + company: String! + currency: String! + description: String! + id: Int! + image: String! + name: String! + profile: String! + tier: String! + totalDonated: Int! + twitter: String! + website: String! +}