Skip to content

Commit

Permalink
Update Vue docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jul 7, 2023
1 parent 137c369 commit fb7c00a
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 80 deletions.
6 changes: 5 additions & 1 deletion MyApp/_pages/vue/autoquerygrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ Which columns are displayed and how they're formatted are further customizable w
<span class="hidden lg:inline">Room </span>No
</template>

<template #cost="{ cost }" v-html="currency(cost)"></template>
<template #cost="{ cost }">
<span v-html="currency(cost)"></span>
</template>

<template #bookingStartDate-header>
Start<span class="hidden lg:inline"> Date</span>
Expand All @@ -176,6 +178,8 @@ Which columns are displayed and how they're formatted are further customizable w
</AutoQueryGrid>
```

<responsive class="not-prose mb-4"></responsive>

<h2 class="pt-8 mb-4 text-2xl font-semibold text-gray-900 dark:text-gray-100">
Custom Functionality
</h2>
Expand Down
86 changes: 7 additions & 79 deletions MyApp/wwwroot/pages/vue/autoquerygrid.mjs
Original file line number Diff line number Diff line change
@@ -1,85 +1,12 @@
import { ref, onMounted } from "vue"
import { Authenticate, QueryCoupons } from "./dtos.mjs"
import { useAuth, useClient, useFormatters } from '@servicestack/vue'
import { onMounted } from "vue"
import { Authenticate } from "./dtos.mjs"
import { useAuth, useClient } from '@servicestack/vue'
import { JsonApiClient } from "@servicestack/client"

export const Responsive = {
template:`<AutoQueryGrid type="Booking" :visibleFrom="{ name:'xl', bookingStartDate:'sm', bookingEndDate:'xl', createdBy:'2xl' }">
<template #id="{ id }">
<span class="text-gray-900">{{ id }}</span>
</template>
<template #name="{ name }">
{{ name }}
</template>
<template #roomNumber-header>
<span class="hidden lg:inline">Room </span>No
</template>
<template #cost="{ cost }">{{ currency(cost) }}</template>
<template #bookingStartDate-header>
Start<span class="hidden lg:inline"> Date</span>
</template>
<template #bookingEndDate-header>
End<span class="hidden lg:inline"> Date</span>
</template>
<template #createdBy-header>
Employee
</template>
<template #createdBy="{ createdBy }">{{ createdBy }}</template>
</AutoQueryGrid>`,
setup() {
const client = useClient()
const coupon = ref()
const { currency } = useFormatters()

/** @param {string} id */
async function showCoupon(id) {
const api = await client.api(new QueryCoupons({ id }))
if (api.succeeded) {
coupon.value = api.response.results[0]
}
}
const close = () => coupon.value = null

return { coupon, showCoupon, close, currency }
}
}

export const CustomBooking = {
template:`<div>
<AutoQueryGrid type="Booking" selectedColumns="id,name,cost,bookingStartDate,bookingEndDate,discount">
<template #discount="{ discount }">
<TextLink v-if="discount" class="flex items-end" @click.stop="showCoupon(discount.id)" :title="discount.id">
<Icon class="w-5 h-5 mr-1" type="Coupon" />
<PreviewFormat :value="discount.description" />
</TextLink>
</template>
</AutoQueryGrid>
<AutoEditForm v-if="coupon" type="UpdateCoupon" v-model="coupon" @done="close" @save="close" />
</div>`,
setup() {
const client = useClient()
const coupon = ref()
/** @param {string} id */
async function showCoupon(id) {
const api = await client.api(new QueryCoupons({ id }))
if (api.succeeded) {
coupon.value = api.response.results[0]
}
}
const close = () => coupon.value = null
return { coupon, showCoupon, close }
}
}
import Responsive from "./autoquerygrid/Responsive.mjs"
import CustomBooking from "./autoquerygrid/CustomBooking.mjs"

export default {
install(app) {
console.log('install(app)')
app.provide('client', JsonApiClient.create('https://blazor-gallery-api.jamstacks.net'))
},
components: {
Expand All @@ -90,7 +17,8 @@ export default {
const client = useClient()

onMounted(async () => {
const api = await client.api(new Authenticate({ provider: 'credentials', userName:'[email protected]', password:'p@55wOrd' }))
const api = await client.api(new Authenticate({
provider: 'credentials', userName:'[email protected]', password:'p@55wOrd' }))
if (api.succeeded) {
const { signIn } = useAuth()
signIn(api.response)
Expand Down
30 changes: 30 additions & 0 deletions MyApp/wwwroot/pages/vue/autoquerygrid/CustomBooking.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ref } from "vue"
import { useClient } from "@servicestack/vue"
import { QueryCoupons } from "../dtos.mjs"

export default {
template:`<div>
<AutoQueryGrid type="Booking" selectedColumns="id,name,cost,bookingStartDate,bookingEndDate,discount">
<template #discount="{ discount }">
<TextLink v-if="discount" class="flex items-end" @click.stop="showCoupon(discount.id)" :title="discount.id">
<Icon class="w-5 h-5 mr-1" type="Coupon" />
<PreviewFormat :value="discount.description" />
</TextLink>
</template>
</AutoQueryGrid>
<AutoEditForm v-if="coupon" type="UpdateCoupon" v-model="coupon" @done="close" @save="close" />
</div>`,
setup() {
const client = useClient()
const coupon = ref()
/** @param {string} id */
async function showCoupon(id) {
const api = await client.api(new QueryCoupons({ id }))
if (api.succeeded) {
coupon.value = api.response.results[0]
}
}
const close = () => coupon.value = null
return { coupon, showCoupon, close }
}
}
52 changes: 52 additions & 0 deletions MyApp/wwwroot/pages/vue/autoquerygrid/Responsive.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ref } from "vue"
import { useClient, useFormatters } from "@servicestack/vue"
import { QueryCoupons } from "../dtos.mjs"

export default {
template:`<AutoQueryGrid type="Booking" :visibleFrom="{ name:'xl', bookingStartDate:'sm', bookingEndDate:'xl', createdBy:'2xl' }">
<template #id="{ id }">
<span class="text-gray-900">{{ id }}</span>
</template>
<template #name="{ name }">
{{ name }}
</template>
<template #roomNumber-header>
<span class="hidden lg:inline">Room </span>No
</template>
<template #cost="{ cost }">
<span v-html="currency(cost)"></span>
</template>
<template #bookingStartDate-header>
Start<span class="hidden lg:inline"> Date</span>
</template>
<template #bookingEndDate-header>
End<span class="hidden lg:inline"> Date</span>
</template>
<template #createdBy-header>
Employee
</template>
<template #createdBy="{ createdBy }">{{ createdBy }}</template>
</AutoQueryGrid>`,
setup() {
const client = useClient()
const coupon = ref()
const { currency } = useFormatters()

/** @param {string} id */
async function showCoupon(id) {
const api = await client.api(new QueryCoupons({ id }))
if (api.succeeded) {
coupon.value = api.response.results[0]
}
}
const close = () => coupon.value = null

return { coupon, showCoupon, close, currency }
}
}

0 comments on commit fb7c00a

Please sign in to comment.