limpiar HTML de descripciones KAPPA + sync proyectos a Turso
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
export function stripHtml(html: string): string {
|
||||
if (!html) return ''
|
||||
return html
|
||||
.replace(/<[^>]*>/g, '')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'")
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
}
|
||||
|
||||
export function extractFirstSentence(text: string, maxLen = 200): string {
|
||||
const cleaned = stripHtml(text)
|
||||
const match = cleaned.match(/^[^.!?]+[.!?]/)
|
||||
if (match) return match[0].slice(0, maxLen)
|
||||
return cleaned.slice(0, maxLen)
|
||||
}
|
||||
|
||||
export function stripHtmlTags(html: string): string {
|
||||
return stripHtml(html)
|
||||
}
|
||||
@@ -1,5 +1,15 @@
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
export interface ProjectRecord {
|
||||
id: number
|
||||
name: string
|
||||
key: string | null
|
||||
description: string | null
|
||||
status: string
|
||||
start_date: string | null
|
||||
end_date: string | null
|
||||
}
|
||||
|
||||
export interface AlphaUserRecord {
|
||||
id: number
|
||||
email: string
|
||||
@@ -70,6 +80,17 @@ export interface PerformanceRecord {
|
||||
}
|
||||
|
||||
export const tauriDb = {
|
||||
// Projects
|
||||
getProjects(): Promise<ProjectRecord[]> {
|
||||
return invoke('get_projects')
|
||||
},
|
||||
saveProject(project: ProjectRecord): Promise<number> {
|
||||
return invoke('save_project', { project })
|
||||
},
|
||||
deleteProject(id: number): Promise<void> {
|
||||
return invoke('delete_project', { id })
|
||||
},
|
||||
|
||||
// Users
|
||||
getUsers(): Promise<AlphaUserRecord[]> {
|
||||
return invoke('get_users')
|
||||
|
||||
+26
-2
@@ -1,6 +1,8 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import { kappa } from '@/services/kappa-api'
|
||||
import { tauriDb } from '@/services/tauri-db'
|
||||
import { stripHtml } from '@/services/clean-html'
|
||||
import type { KappaInitiative } from '@/types/kappa'
|
||||
|
||||
export const useProjectsStore = defineStore('projects', () => {
|
||||
@@ -20,8 +22,16 @@ export const useProjectsStore = defineStore('projects', () => {
|
||||
error.value = null
|
||||
try {
|
||||
const data = await kappa.getInitiatives() as KappaInitiative[] | { results?: KappaInitiative[] }
|
||||
console.log('[KAPPA] initiatives:', data)
|
||||
projects.value = Array.isArray(data) ? data : (data.results ?? [])
|
||||
const raw = Array.isArray(data) ? data : (data.results ?? [])
|
||||
|
||||
projects.value = raw.map(p => ({
|
||||
...p,
|
||||
description: stripHtml(p.description || ''),
|
||||
name: p.name || p.initiative_name || `Proyecto ${p.id}`,
|
||||
initiative_name: p.initiative_name || p.name,
|
||||
}))
|
||||
|
||||
syncToTurso(projects.value)
|
||||
} catch (e: any) {
|
||||
error.value = e.message
|
||||
} finally {
|
||||
@@ -29,6 +39,20 @@ export const useProjectsStore = defineStore('projects', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function syncToTurso(list: KappaInitiative[]) {
|
||||
for (const p of list) {
|
||||
await tauriDb.saveProject({
|
||||
id: p.id,
|
||||
name: p.initiative_name || p.name || `Proyecto ${p.id}`,
|
||||
key: p.key ?? null,
|
||||
description: p.description ?? null,
|
||||
status: p.status || 'active',
|
||||
start_date: p.start_date ?? null,
|
||||
end_date: p.end_date ?? null,
|
||||
}).catch(() => {})
|
||||
}
|
||||
}
|
||||
|
||||
function select(id: number) {
|
||||
selectedId.value = id
|
||||
localStorage.setItem('kappa_last_project', String(id))
|
||||
|
||||
Reference in New Issue
Block a user