Download script.js from Alexsandr123/quality-docs-manager: direct link, hf CLI and curl.
- Browser
- Download file 6.46 kB
-
https://huggingface.co/spaces/Alexsandr123/quality-docs-manager/resolve/main/script.js
- Command line
-
hf download hf://spaces/Alexsandr123/quality-docs-manager/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Alexsandr123/quality-docs-manager/resolve/main/script.js
6.46 kB
| // Initialize documents array | |
| let documents = []; | |
| let isAuthenticated = false; | |
| let editingDocumentId = null; | |
| let selectedFile = null; | |
| // Sample data from PDF | |
| const pdfData = [ | |
| { | |
| "number": "1", | |
| "title": "Политика в области качества и пищевой безопасности АО «ПРОГРЕСС»", | |
| "code": "", | |
| "approvalDate": "2025-08-04", | |
| "scope": "Все подразделения АО \"ПРОГРЕСС\", г. Липецк", | |
| "url": "", | |
| "location": "" | |
| } | |
| ]; | |
| // Initialize PDF data if localStorage is empty | |
| function initializePdfData() { | |
| const savedDocuments = localStorage.getItem('documents'); | |
| if (!savedDocuments && pdfData.length > 0) { | |
| documents = pdfData.map((doc, index) => ({ | |
| id: Date.now() + index, // Unique ID based on timestamp | |
| ...doc | |
| })); | |
| saveToLocalStorage(); | |
| showNotification('Данные из PDF успешно загружены!'); | |
| renderDocuments(); | |
| } | |
| } | |
| // Calculate update date (3 years from approval) | |
| function calculateUpdateDate(approvalDate) { | |
| const date = new Date(approvalDate); | |
| date.setFullYear(date.getFullYear() + 3); | |
| return date; | |
| } | |
| // Get document status based on approval date | |
| function getDocumentStatus(approvalDate) { | |
| const updateDate = calculateUpdateDate(approvalDate); | |
| const today = new Date(); | |
| const timeDiff = updateDate.getTime() - today.getTime(); | |
| const daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24)); | |
| const monthsDiff = Math.floor(daysDiff / 30); | |
| if (daysDiff <= 0) { | |
| return { status: 'expired', days: daysDiff, months: monthsDiff }; | |
| } else if (monthsDiff <= 3) { | |
| return { status: 'danger', days: daysDiff, months: monthsDiff }; | |
| } else if (monthsDiff <= 6) { | |
| return { status: 'warning', days: daysDiff, months: monthsDiff }; | |
| } else { | |
| return { status: 'normal', days: daysDiff, months: monthsDiff }; | |
| } | |
| } | |
| // Get status text and class | |
| function getStatusText(statusInfo) { | |
| switch (statusInfo.status) { | |
| case 'expired': | |
| return { | |
| text: 'ПРОСРОЧЕН', | |
| class: 'expired', | |
| fullText: 'Документ требует срочной актуализации! Просрочен.' | |
| }; | |
| case 'danger': | |
| return { | |
| text: `${statusInfo.months} мес.`, | |
| class: 'danger', | |
| fullText: `Срочная актуализация! Осталось ${statusInfo.months} месяцев (${statusInfo.days} дней)` | |
| }; | |
| case 'warning': | |
| return { | |
| text: `${statusInfo.months} мес.`, | |
| class: 'warning', | |
| fullText: `Требуется актуализация в ближайшее время. Осталось ${statusInfo.months} месяцев` | |
| }; | |
| default: | |
| return { | |
| text: `Актуален`, | |
| class: 'normal', | |
| fullText: `Документ актуален. Актуализация через ${statusInfo.months} месяцев` | |
| }; | |
| } | |
| } | |
| // Save to localStorage | |
| function saveToLocalStorage() { | |
| localStorage.setItem('documents', JSON.stringify(documents)); | |
| } | |
| // Load from localStorage | |
| function loadFromLocalStorage() { | |
| try { | |
| const savedDocuments = localStorage.getItem('documents'); | |
| if (savedDocuments) { | |
| documents = JSON.parse(savedDocuments); | |
| } else { | |
| documents = []; | |
| saveToLocalStorage(); | |
| } | |
| } catch (e) { | |
| console.error('Error loading documents:', e); | |
| documents = []; | |
| saveToLocalStorage(); | |
| } | |
| renderDocuments(); | |
| } | |
| // Render documents list | |
| function renderDocuments() { | |
| const container = document.getElementById('documentsContainer'); | |
| const emptyState = document.getElementById('emptyState'); | |
| if (!container || !emptyState) return; | |
| // Clear existing documents (keep header and empty state) | |
| const header = container.querySelector('.grid.bg-gray-800'); | |
| container.innerHTML = ''; | |
| if (header) container.appendChild(header); | |
| if (emptyState) container.appendChild(emptyState); | |
| if (!documents || documents.length === 0) { | |
| emptyState.classList.remove('hidden'); | |
| return; | |
| } | |
| emptyState.classList.add('hidden'); | |
| if (!Array.isArray(documents)) { | |
| console.error('Documents is not an array'); | |
| return; | |
| } | |
| // Sort documents by status priority | |
| const sortedDocuments = [...documents].sort((a, b) => { | |
| try { | |
| const statusA = getDocumentStatus(a.approvalDate); | |
| const statusB = getDocumentStatus(b.approvalDate); | |
| const priority = { 'expired': 0, 'danger': 1, 'warning': 2, 'normal': 3 }; | |
| return priority[statusA.status] - priority[statusB.status]; | |
| } catch (e) { | |
| console.error('Error sorting documents:', e); | |
| return 0; | |
| } | |
| }); | |
| // Render each document | |
| sortedDocuments.forEach(doc => { | |
| try { | |
| if (!doc.approvalDate) { | |
| console.warn('Document missing approvalDate:', doc); | |
| return; | |
| } | |
| const statusInfo = getDocumentStatus(doc.approvalDate); | |
| const statusText = getStatusText(statusInfo); | |
| const row = document.createElement('div'); | |
| row.className = 'document-row'; | |
| row.innerHTML = ` | |
| <div class="col-span-1 font-medium">${doc.number}</div> | |
| <div class="col-span-5">${doc.title}</div> | |
| <div class="col-span-2 text-gray-600">${doc.code || '-'}</div> | |
| <div class="col-span-2">${doc.approvalDate}</div> | |
| <div class="col-span-2"> | |
| <span class="status-indicator ${statusText.class}"></span> | |
| <span class="text-sm">${statusText.text}</span> | |
| </div> | |
| <div class="document-details"> | |
| <div class="mb-2"><span class="font-medium">Область действия:</span> ${doc.scope}</div> | |
| <div class="mb-2"><span class="font-medium">Место хранения:</span> ${doc.location || 'Не указано'}</div> | |
| <div class="p-2 rounded bg-gray-100 mb-2 text-sm"> |