]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление логирования на загрузку файлов в документ списания.
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Tue, 17 Feb 2026 10:03:08 +0000 (13:03 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Tue, 17 Feb 2026 10:03:08 +0000 (13:03 +0300)
erp24/web/js/notification.js
erp24/web/js/validate/validateForm.js

index b3d037f19c1cd069aecd2547e06cd39dfcf3acf3..2a5366ac689335eed905887bef639b2222191d7d 100644 (file)
@@ -5,7 +5,7 @@ setTimeout(initPendingNotifications, 3000);
 
 function initPendingNotifications() {
     pendingNotifications();
-    notificationIntervalId = setInterval(pendingNotifications, 10000);
+    notificationIntervalId = setInterval(pendingNotifications, 600000);
 }
 
 // Останавливаем polling когда вкладка неактивна — экономим соединения и трафик
@@ -18,7 +18,7 @@ document.addEventListener('visibilitychange', function () {
     } else {
         if (!notificationIntervalId) {
             pendingNotifications();
-            notificationIntervalId = setInterval(pendingNotifications, 10000);
+            notificationIntervalId = setInterval(pendingNotifications, 600000);
         }
     }
 });
@@ -49,6 +49,9 @@ function updateKolokolchik(data) {
 }
 
 function pendingNotifications() {
+    // Не отправляем запросы пока идёт загрузка формы — освобождаем соединения
+    if (window._uploadInProgress) return;
+
     $.ajax({
         method: 'POST',
         url: window.location.origin + '/notification/pending',
index 63c642d2888a41c5d3f0275ff581418ded8f80fc..431930708f1f540e2f3485c5c8a27c0428fc85ea 100755 (executable)
@@ -145,15 +145,75 @@ function submitFormWithXHR(yiiform) {
         }
     });
 
+    // Останавливаем notification polling — освобождаем соединения для upload
+    window._uploadInProgress = true;
+
     // Индикатор загрузки
     var submitBtn = yiiform.find('.submitter');
     var originalText = submitBtn.text();
     submitBtn.prop('disabled', true).text('Загрузка...');
 
+    // Прогресс-бар загрузки файлов
+    var $progressWrap = yiiform.find('#upload-progress-wrap');
+    if ($progressWrap.length === 0) {
+        submitBtn.after(
+            '<div id="upload-progress-wrap" style="max-width:500px; margin-top:10px;">' +
+            '  <div class="progress" style="height:22px;">' +
+            '    <div id="upload-progress-bar" class="progress-bar bg-primary progress-bar-striped progress-bar-animated"' +
+            '         role="progressbar" style="width:0%">0%</div>' +
+            '  </div>' +
+            '  <small id="upload-progress-text" class="text-muted"></small>' +
+            '</div>'
+        );
+        $progressWrap = yiiform.find('#upload-progress-wrap');
+    }
+    $progressWrap.show();
+    var $bar = $progressWrap.find('#upload-progress-bar');
+    var $text = $progressWrap.find('#upload-progress-text');
+    var uploadStartTime = Date.now();
+
     var xhr = new XMLHttpRequest();
+
+    // Прогресс отправки файлов на сервер
+    xhr.upload.addEventListener('progress', function (e) {
+        if (e.lengthComputable) {
+            var percent = Math.round(e.loaded / e.total * 100);
+            $bar.css('width', percent + '%').text(percent + '%');
+
+            var elapsed = (Date.now() - uploadStartTime) / 1000;
+            var speedMbps = elapsed > 0 ? (e.loaded / 1024 / 1024) / elapsed : 0;
+            var remaining = speedMbps > 0 ? ((e.total - e.loaded) / 1024 / 1024) / speedMbps : 0;
+
+            var speedText = speedMbps >= 1
+                ? speedMbps.toFixed(1) + ' МБ/с'
+                : (speedMbps * 1024).toFixed(0) + ' КБ/с';
+
+            var remainText = '';
+            if (remaining > 0 && percent < 100) {
+                if (remaining < 60) {
+                    remainText = ' — осталось ~' + Math.ceil(remaining) + ' сек';
+                } else {
+                    remainText = ' — осталось ~' + Math.ceil(remaining / 60) + ' мин';
+                }
+            }
+
+            var loadedMb = (e.loaded / 1024 / 1024).toFixed(1);
+            var totalMb = (e.total / 1024 / 1024).toFixed(1);
+            $text.text(loadedMb + ' / ' + totalMb + ' МБ · ' + speedText + remainText);
+        }
+    });
+
+    xhr.upload.addEventListener('loadend', function () {
+        $bar.css('width', '100%').text('100%');
+        $bar.removeClass('progress-bar-animated');
+        $text.text('Файлы загружены. Обработка на сервере...');
+    });
+
     xhr.open('POST', form.action, true);
 
     xhr.onload = function () {
+        window._uploadInProgress = false;
+        $progressWrap.hide();
         if (xhr.status === 200) {
             var responseURL = xhr.responseURL || '';
             if (responseURL && responseURL !== window.location.href) {
@@ -171,10 +231,19 @@ function submitFormWithXHR(yiiform) {
     };
 
     xhr.onerror = function () {
+        window._uploadInProgress = false;
+        $progressWrap.hide();
         alert('Ошибка сети. Проверьте подключение и попробуйте снова.');
         submitBtn.prop('disabled', false).text(originalText);
     };
 
+    xhr.ontimeout = function () {
+        window._uploadInProgress = false;
+        $progressWrap.hide();
+        alert('Таймаут загрузки. Файлы слишком большие для текущего соединения.');
+        submitBtn.prop('disabled', false).text(originalText);
+    };
+
     xhr.send(formData);
 }