Skip to content

Commit

Permalink
Resolve #28: Add embeddable iframe for sharing PB Cards
Browse files Browse the repository at this point in the history
  • Loading branch information
big213 committed Nov 11, 2021
1 parent 1d9c755 commit 1d71a99
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 0 deletions.
26 changes: 26 additions & 0 deletions frontend/components/interface/viewPbCardInterface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
>
<v-icon>mdi-share-variant</v-icon>
</v-btn>
<v-btn
v-if="recordInfo.shareOptions && editable"
icon
@click="copyEmbedLink()"
>
<v-icon>mdi-code-tags</v-icon>
</v-btn>
<v-btn icon @click="reset()">
<v-icon>mdi-refresh</v-icon>
</v-btn>
Expand Down Expand Up @@ -312,6 +319,25 @@ export default {
copyToClipboard(this, shareUrl)
},
// links to a version of the page that can be embedded in an iframe
copyEmbedLink() {
const createdById = this.lockedFilters.find(
(ele) => ele.field === 'createdBy.id'
)?.value
if (!createdById) return
const embedUrl =
window.location.origin +
this.$router.resolve({
name: 'pb-card',
query: {
id: createdById,
},
}).href
copyToClipboard(this, embedUrl)
},
openAddRecordDialog(eventId, key) {
const initializedRecord = {
'event.id': eventId,
Expand Down
78 changes: 78 additions & 0 deletions frontend/layouts/lite.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<template>
<v-app dark>
<v-main>
<nuxt />
</v-main>
<Snackbar />
</v-app>
</template>

<script>
import { mapGetters } from 'vuex'
import Snackbar from '~/components/snackbar/snackbar.vue'
import VersionCheckText from '~/components/common/versionCheckText.vue'
import { goToWcaAuth, handleLogout } from '~/services/auth'
import { copyToClipboard, openLink, handleError } from '~/services/base'
import AdminNavRoutes from '~/components/navigation/adminNavRoutes.vue'
export default {
components: {
Snackbar,
VersionCheckText,
AdminNavRoutes,
},
data() {
return {
clipped: true,
drawer: false,
fixed: true,
miniVariant: false,
}
},
computed: {
...mapGetters({
user: 'auth/user',
}),
isAdmin() {
return this.$store.getters['auth/user']?.role === 'ADMIN'
},
},
mounted() {
this.drawer = this.$vuetify.breakpoint.name !== 'xs'
},
methods: {
copyToClipboard(content) {
return copyToClipboard(this, content)
},
goToWcaAuth,
openLink,
toggleTheme() {
this.$vuetify.theme.dark = !this.$vuetify.theme.dark
localStorage.setItem('theme', this.$vuetify.theme.dark ? 'dark' : 'light')
},
canSee(allowedRoles, allowedPermissions) {
return (
allowedRoles.includes(this.$store.getters['auth/user']?.role) ||
allowedPermissions.some((ele) =>
this.$store.getters['auth/user']?.allPermissions.includes(ele)
)
)
},
logout() {
try {
this.$router.push('/')
handleLogout(this)
} catch (err) {
handleError(this, err)
}
},
},
}
</script>
105 changes: 105 additions & 0 deletions frontend/pages/pb-card.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<template>
<v-container fluid fill-height>
<v-layout align-center justify-center>
<v-row>
<v-col cols="12">
<div v-if="errorMessage" class="text-center">
<span class="display-1 pl-2">{{ errorMessage }} </span>
</div>
<div v-else-if="loading.verifyUser">
<span class="display-1 pl-2"
>Verifying WCA Code...
<v-progress-circular indeterminate></v-progress-circular>
</span>
</div>
<ViewPbCardInterface
v-else-if="userId"
icon="mdi-card-text"
:title="title"
:record-info="recordInfo"
:locked-filters="lockedFilters"
></ViewPbCardInterface>
</v-col>
</v-row>
</v-layout>
</v-container>
</template>

<script>
import ViewPbCardInterface from '~/components/interface/viewPbCardInterface.vue'
import { PublicPbs } from '~/models/special'
import { executeGiraffeql } from '~/services/giraffeql'
import { handleError } from '~/services/base'
export default {
layout: 'lite',
components: {
ViewPbCardInterface,
},
data() {
return {
recordInfo: PublicPbs,
title: 'PB Card',
hiddenFilters: ['createdBy.id', 'isCurrent'],
hiddenHeaders: ['createdBy.name+createdBy.avatar'],
errorMessage: null,
loading: {
verifyUser: false,
},
userId: null,
}
},
computed: {
lockedFilters() {
return [
{
field: 'createdBy.id',
operator: 'eq',
value: this.$route.query.id,
},
]
},
},
mounted() {
this.verifyUserExists()
},
methods: {
async verifyUserExists() {
this.loading.verifyUser = true
try {
if (!this.$route.query.id) {
throw new Error('Missing user ID')
}
const data = await executeGiraffeql(this, {
getUser: {
id: true,
__args: {
id: this.$route.query.id,
},
},
})
this.userId = data.id
} catch (err) {
handleError(this, err)
this.errorMessage = err.message
}
this.loading.verifyUser = false
},
},
head() {
return {
title: this.title,
}
},
}
</script>

0 comments on commit 1d71a99

Please sign in to comment.