feat: add per-source mail import trigger
This commit is contained in:
@@ -105,6 +105,15 @@
|
||||
<polyline points="22 4 12 14.01 9 11.01"></polyline>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-xs" x-on:click="fetchSource(source)" title="Run import now"
|
||||
:disabled="Boolean(fetching[source.id])">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||||
stroke-linejoin="round">
|
||||
<path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.8 1.04 6.43 2.72"></path>
|
||||
<path d="M21 3v6h-6"></path>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-xs" x-on:click="loadImportHistory(source)" title="Import history">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||||
@@ -471,6 +480,7 @@ function mailSourcesApp() {
|
||||
isTesting: false,
|
||||
isSaving: false,
|
||||
testing: {},
|
||||
fetching: {},
|
||||
historySource: null,
|
||||
importHistory: [],
|
||||
historyLoading: false,
|
||||
@@ -509,6 +519,33 @@ function mailSourcesApp() {
|
||||
}
|
||||
},
|
||||
|
||||
async fetchSource(source) {
|
||||
this.fetching[source.id] = true;
|
||||
this.feedback = { message: '', type: '' };
|
||||
try {
|
||||
const resp = await fetch(`/api/v1/mail-sources/${source.id}/fetch`, {
|
||||
method: 'POST',
|
||||
});
|
||||
const result = await resp.json();
|
||||
if (!resp.ok) {
|
||||
throw new Error(result.detail || 'Import failed');
|
||||
}
|
||||
this.feedback = {
|
||||
message: `Import finished for ${source.name}: ${result.reports_found} report${result.reports_found === 1 ? '' : 's'}, ${result.duplicate_reports || 0} duplicate${result.duplicate_reports === 1 ? '' : 's'}.`,
|
||||
type: result.success ? 'success' : 'error',
|
||||
};
|
||||
await this.loadSources();
|
||||
if (this.historySource && this.historySource.id === source.id) {
|
||||
const updated = this.sources.find(s => s.id === source.id) || source;
|
||||
await this.loadImportHistory(updated);
|
||||
}
|
||||
} catch (e) {
|
||||
this.feedback = { message: `Import error: ${e.message}`, type: 'error' };
|
||||
} finally {
|
||||
this.fetching[source.id] = false;
|
||||
}
|
||||
},
|
||||
|
||||
async loadImportHistory(source) {
|
||||
this.historySource = source;
|
||||
this.importHistory = [];
|
||||
|
||||
Reference in New Issue
Block a user