feat: enhance document management UI
This commit is contained in:
@@ -17,16 +17,23 @@ export function useDocuments() {
|
||||
const { get, post, delete: del } = useApi()
|
||||
const { showError, showSuccess } = useToast()
|
||||
|
||||
const loadDocuments = async () => {
|
||||
const loadFromEndpoint = async (endpoint, { updateStore = false } = {}) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await get('/documents')
|
||||
const result = await get(endpoint)
|
||||
if (result.success) {
|
||||
documents.value = result.data
|
||||
const data = result.data || []
|
||||
if (updateStore) {
|
||||
documents.value = data
|
||||
}
|
||||
return { success: true, data }
|
||||
}
|
||||
if (result.error) {
|
||||
showError(result.error)
|
||||
}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des documents:', error)
|
||||
console.error(`Erreur lors du chargement des documents (${endpoint}):`, error)
|
||||
showError("Impossible de charger les documents")
|
||||
return { success: false, error: error.message }
|
||||
} finally {
|
||||
@@ -34,25 +41,31 @@ export function useDocuments() {
|
||||
}
|
||||
}
|
||||
|
||||
const loadDocumentsBySite = async (siteId) => {
|
||||
if (!siteId) return { success: false, error: 'Aucun site sélectionné' }
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await get(`/documents/site/${siteId}`)
|
||||
if (result.success) {
|
||||
documents.value = result.data
|
||||
}
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des documents du site:', error)
|
||||
showError("Impossible de charger les documents du site")
|
||||
return { success: false, error: error.message }
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
const loadDocuments = async (options = {}) => {
|
||||
return loadFromEndpoint('/documents', { updateStore: options.updateStore ?? true })
|
||||
}
|
||||
|
||||
const uploadDocuments = async ({ files = [], context = {} }) => {
|
||||
const loadDocumentsBySite = async (siteId, options = {}) => {
|
||||
if (!siteId) return { success: false, error: 'Aucun site sélectionné' }
|
||||
return loadFromEndpoint(`/documents/site/${siteId}`, { updateStore: options.updateStore ?? false })
|
||||
}
|
||||
|
||||
const loadDocumentsByMachine = async (machineId, options = {}) => {
|
||||
if (!machineId) return { success: false, error: 'Aucune machine sélectionnée' }
|
||||
return loadFromEndpoint(`/documents/machine/${machineId}`, { updateStore: options.updateStore ?? false })
|
||||
}
|
||||
|
||||
const loadDocumentsByComponent = async (componentId, options = {}) => {
|
||||
if (!componentId) return { success: false, error: 'Aucun composant sélectionné' }
|
||||
return loadFromEndpoint(`/documents/composant/${componentId}`, { updateStore: options.updateStore ?? false })
|
||||
}
|
||||
|
||||
const loadDocumentsByPiece = async (pieceId, options = {}) => {
|
||||
if (!pieceId) return { success: false, error: 'Aucune pièce sélectionnée' }
|
||||
return loadFromEndpoint(`/documents/piece/${pieceId}`, { updateStore: options.updateStore ?? false })
|
||||
}
|
||||
|
||||
const uploadDocuments = async ({ files = [], context = {} }, { updateStore = false } = {}) => {
|
||||
if (!files.length) return { success: false, error: 'Aucun fichier sélectionné' }
|
||||
|
||||
loading.value = true
|
||||
@@ -81,7 +94,9 @@ export function useDocuments() {
|
||||
}
|
||||
|
||||
if (created.length) {
|
||||
documents.value = [...created, ...documents.value]
|
||||
if (updateStore) {
|
||||
documents.value = [...created, ...documents.value]
|
||||
}
|
||||
return { success: true, data: created }
|
||||
}
|
||||
|
||||
@@ -95,14 +110,16 @@ export function useDocuments() {
|
||||
}
|
||||
}
|
||||
|
||||
const deleteDocument = async (id) => {
|
||||
const deleteDocument = async (id, { updateStore = false } = {}) => {
|
||||
if (!id) return { success: false, error: 'Identifiant manquant' }
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await del(`/documents/${id}`)
|
||||
if (result.success) {
|
||||
documents.value = documents.value.filter(doc => doc.id !== id)
|
||||
if (updateStore) {
|
||||
documents.value = documents.value.filter(doc => doc.id !== id)
|
||||
}
|
||||
showSuccess('Document supprimé')
|
||||
}
|
||||
return result
|
||||
@@ -120,6 +137,9 @@ export function useDocuments() {
|
||||
loading,
|
||||
loadDocuments,
|
||||
loadDocumentsBySite,
|
||||
loadDocumentsByMachine,
|
||||
loadDocumentsByComponent,
|
||||
loadDocumentsByPiece,
|
||||
uploadDocuments,
|
||||
deleteDocument,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user