diff --git a/resources/js/Pages/Dashboard/VikonUpdates/Index.vue b/resources/js/Pages/Dashboard/VikonUpdates/Index.vue index 341ad93..fbd949c 100644 --- a/resources/js/Pages/Dashboard/VikonUpdates/Index.vue +++ b/resources/js/Pages/Dashboard/VikonUpdates/Index.vue @@ -81,18 +81,24 @@ {{ updating ? 'Обновление...' : 'Обновить' }} -
- +
+ +
+ +
@@ -111,11 +117,16 @@

{{ progress }}%

- -
-

- {{ partResult.message }} -

+ +
+
+ + {{ r.success ? '✓' : '✗' }} + + + {{ r.message }} + +
@@ -163,9 +174,9 @@ const progress = ref(0); const updateError = ref(null); const versionInfo = ref({ current_version: props.current_version, has_update: false, latest_version: null }); const accessInfo = ref({ has_access: false, error: null }); -const selectedPart = ref({}); +const selectedParts = ref({}); const updatingPart = ref(null); -const partResult = ref(null); +const partResults = ref([]); const authUrl = computed(() => { const redirect = encodeURIComponent(`${window.location.origin}/vikon_core/update/index.php`); @@ -261,32 +272,47 @@ async function updateModule(moduleId) { } } -async function updatePart(moduleId, part) { - if (!part) return; +function isAllPartsSelected(moduleId) { + const moduleParts = props.parts?.[moduleId] || []; + const selected = selectedParts.value[moduleId] || []; + return moduleParts.length > 0 && moduleParts.every(p => selected.includes(p)); +} - updatingPart.value = `${moduleId}-${part}`; - partResult.value = null; - - try { - const res = await fetch('/dashboard/vikon-updates/update-part', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content, - 'Accept': 'application/json', - }, - body: JSON.stringify({ module_id: moduleId, part }), - }); - - const data = await res.json(); - partResult.value = data; - } catch (e) { - partResult.value = { success: false, message: e.message }; - } finally { - updatingPart.value = null; +function toggleAllParts(moduleId) { + const moduleParts = props.parts?.[moduleId] || []; + if (isAllPartsSelected(moduleId)) { + selectedParts.value[moduleId] = []; + } else { + selectedParts.value[moduleId] = [...moduleParts]; } } +async function updateSelectedParts(moduleId) { + const partsToUpdate = selectedParts.value[moduleId] || []; + if (!partsToUpdate.length) return; + + updatingPart.value = moduleId; + partResults.value = []; + + for (const part of partsToUpdate) { + try { + const res = await axios.post(route('dashboard.vikon-updates.update-part'), { + module_id: moduleId, + part, + }); + partResults.value.push(res.data); + } catch (e) { + partResults.value.push({ + success: false, + message: e.response?.data?.message || e.message, + part, + }); + } + } + + updatingPart.value = null; +} + async function logout() { try { await axios.post(route('dashboard.vikon-updates.logout'));