Files
shopdb-flask/frontend/src/components/EmailReportButton.vue
cproudlock a846587f39
All checks were successful
CI / backend (push) Successful in 1m23s
CI / naming (push) Successful in 1s
CI / frontend (push) Successful in 7s
Add email sending (service + 3 flows) and a general asset label generator
Email: a stdlib SMTP mailer (settings-first config, graceful no-op when
unconfigured), a test-email endpoint wired to the Email settings page,
forced first-login password change (users.mustchangepassword, migration
7d23, /change-password flow), new-user welcome mail, and on-demand
report/alert delivery (POST /api/reports/email + Email Report buttons)
with an external-cron-with-a-scoped-PAT path documented for automation.
All tests patch smtplib - no network.

Labels: a shared /print/asset-label/<type>/<id> view any asset detail
page opens - card or plain style, QR or barcode, configurable encoding.
Per-type qr_target_* templates plus label_default_style/codetype/encodes
settings on the Printing page. Measuring-tool labels default to encoding
their inspection-operation code (derived from the location name, e.g.
0615), so every tool in an area shares the area code - verified by
decoding the rendered QR. Machine labels default to the machine number;
blank-serial handled gracefully.

808 tests pass; both features verified live.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 11:58:30 -04:00

54 lines
1.6 KiB
Vue

<template>
<button class="btn btn-secondary" :disabled="sending" @click="emailReport">
{{ sending ? 'Sending...' : 'Email report' }}
</button>
</template>
<script setup>
import { ref } from 'vue'
import { reportsApi } from '../api'
import { useToast } from '../composables/toast'
import { apiError } from '../utils/apiError'
// On-demand report delivery. Emails the given rows as an HTML table to the
// site's Alert Recipients (or an explicit `to`). Automatic/scheduled sending is
// out of scope for this app; point an external cron at POST /api/reports/email
// with an API token to automate.
const props = defineProps({
subject: { type: String, required: true },
columns: { type: Array, required: true },
rows: { type: Array, required: true },
intro: { type: String, default: '' },
to: { type: String, default: '' },
})
const toast = useToast()
const sending = ref(false)
async function emailReport() {
sending.value = true
try {
const payload = {
subject: props.subject,
columns: props.columns,
rows: props.rows,
intro: props.intro,
}
if (props.to) payload.to = props.to
const response = await reportsApi.email(payload)
const result = response.data?.data || {}
if (result.sent) {
toast.success('Report emailed.')
} else if (result.error) {
toast.error(`Report email failed: ${result.error}`)
} else {
toast.info(response.data?.message || 'Email is not configured.')
}
} catch (event) {
toast.error(apiError(event, 'Failed to email report'))
} finally {
sending.value = false
}
}
</script>