Revert "predzadnji unstagaeni dijelovi"
This reverts commit 1f6c0d6086.
This commit is contained in:
@@ -3055,10 +3055,17 @@ def _request_monthly_archive_generation(*, request, archive_type):
|
|||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
if existing_pending:
|
if existing_pending:
|
||||||
return {
|
stale_pending_threshold = timezone.now() - timedelta(minutes=3)
|
||||||
'status': 'processing',
|
if existing_pending.created_at and existing_pending.created_at < stale_pending_threshold:
|
||||||
'generated_archive_id': str(existing_pending.pk),
|
existing_pending.is_active = False
|
||||||
}
|
existing_pending.status = 'failed'
|
||||||
|
existing_pending.error_message = 'ZIP zahtjev je ostao predugo u pending statusu; pokrece se novi zahtjev.'
|
||||||
|
existing_pending.save(update_fields=['is_active', 'status', 'error_message', 'updated_at'])
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
'status': 'processing',
|
||||||
|
'generated_archive_id': str(existing_pending.pk),
|
||||||
|
}
|
||||||
|
|
||||||
generated_archive = GeneratedFleetArchive.objects.create(
|
generated_archive = GeneratedFleetArchive.objects.create(
|
||||||
requested_by=request.user,
|
requested_by=request.user,
|
||||||
@@ -3080,6 +3087,7 @@ def _request_monthly_archive_generation(*, request, archive_type):
|
|||||||
stage='requested',
|
stage='requested',
|
||||||
year=year,
|
year=year,
|
||||||
month=month,
|
month=month,
|
||||||
|
generated_archive=generated_archive,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import AuthWidget from './AuthWidget';
|
|||||||
import UserDisplay from './ui/UserDisplay';
|
import UserDisplay from './ui/UserDisplay';
|
||||||
import { useEffect, useRef, useState } from 'preact/hooks';
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||||
import { useSpring, animated } from '@react-spring/web';
|
import { useSpring, animated } from '@react-spring/web';
|
||||||
import { hydrateAuthFromStorage } from '../stores/authStore';
|
import { hydrateAuthFromStorage, loadCurrentUser, $user, $accessToken } from '../stores/authStore';
|
||||||
|
|
||||||
const ITEMS = [
|
const ITEMS = [
|
||||||
{ id: 'dashboard', label: 'Dashboard', href: '/' },
|
{ id: 'dashboard', label: 'Dashboard', href: '/' },
|
||||||
@@ -21,8 +21,12 @@ function normalizePath(p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getActiveIndex(path) {
|
function getActiveIndex(path) {
|
||||||
const idx = ITEMS.findIndex((item) => item.href === path);
|
// Exact match (e.g. '/' → Dashboard)
|
||||||
return idx >= 0 ? idx : 0;
|
const exact = ITEMS.findIndex((item) => item.href === path);
|
||||||
|
if (exact >= 0) return exact;
|
||||||
|
// Prefix match for sub-paths (e.g. '/putni-nalozi/racuni' → Putni nalozi)
|
||||||
|
const prefix = ITEMS.findIndex((item) => item.href !== '/' && path.startsWith(item.href));
|
||||||
|
return prefix >= 0 ? prefix : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Navbar({ minimal = false }) {
|
export default function Navbar({ minimal = false }) {
|
||||||
@@ -55,6 +59,10 @@ export default function Navbar({ minimal = false }) {
|
|||||||
// Mount: izmjeri početnu poziciju bez animacije, pa uključi animaciju za buduće navigacije
|
// Mount: izmjeri početnu poziciju bez animacije, pa uključi animaciju za buduće navigacije
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
hydrateAuthFromStorage();
|
hydrateAuthFromStorage();
|
||||||
|
// Učitaj korisnika ako token postoji ali $user još nije popunjen
|
||||||
|
if (!$user.get() && $accessToken.get()) {
|
||||||
|
loadCurrentUser();
|
||||||
|
}
|
||||||
|
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
measureIndicator();
|
measureIndicator();
|
||||||
|
|||||||
@@ -367,10 +367,10 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
|
|||||||
|
|
||||||
async function handleDownloadAllTasksArchive() {
|
async function handleDownloadAllTasksArchive() {
|
||||||
if (downloadingAllTasks) return;
|
if (downloadingAllTasks) return;
|
||||||
|
setBulkDownloadOpen(false);
|
||||||
setDownloadingAllTasks(true);
|
setDownloadingAllTasks(true);
|
||||||
try {
|
try {
|
||||||
await downloadMonthlyServiceTasksArchive(viewYear, viewMonth + 1);
|
await downloadMonthlyServiceTasksArchive(viewYear, viewMonth + 1);
|
||||||
setBulkDownloadOpen(false);
|
|
||||||
} finally {
|
} finally {
|
||||||
setDownloadingAllTasks(false);
|
setDownloadingAllTasks(false);
|
||||||
}
|
}
|
||||||
@@ -378,10 +378,10 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
|
|||||||
|
|
||||||
async function handleDownloadAllWorkOrdersArchive() {
|
async function handleDownloadAllWorkOrdersArchive() {
|
||||||
if (downloadingAllWorkOrders) return;
|
if (downloadingAllWorkOrders) return;
|
||||||
|
setBulkDownloadOpen(false);
|
||||||
setDownloadingAllWorkOrders(true);
|
setDownloadingAllWorkOrders(true);
|
||||||
try {
|
try {
|
||||||
await downloadMonthlyWorkOrdersArchive(viewYear, viewMonth + 1);
|
await downloadMonthlyWorkOrdersArchive(viewYear, viewMonth + 1);
|
||||||
setBulkDownloadOpen(false);
|
|
||||||
} finally {
|
} finally {
|
||||||
setDownloadingAllWorkOrders(false);
|
setDownloadingAllWorkOrders(false);
|
||||||
}
|
}
|
||||||
@@ -655,23 +655,25 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
|
|||||||
{MONTH_NAMES[viewMonth]} {viewYear}
|
{MONTH_NAMES[viewMonth]} {viewYear}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<div className="flex items-center gap-2">
|
||||||
type="button"
|
|
||||||
onClick={handleDownload}
|
|
||||||
disabled={downloading}
|
|
||||||
className="rounded-md bg-indigo-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-indigo-700 disabled:opacity-60"
|
|
||||||
>
|
|
||||||
{downloading ? 'Preuzimanje...' : reportType === 'servicer' ? 'Preuzmi mjesečni izvještaj' : 'Preuzmi DOCX'}
|
|
||||||
</button>
|
|
||||||
{reportType === 'servicer' && (
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setBulkDownloadOpen(true)}
|
onClick={handleDownload}
|
||||||
className="ml-2 rounded-md border border-border-hairline px-3 py-1.5 text-xs font-medium text-text-main hover:bg-canvas-deep"
|
disabled={downloading}
|
||||||
|
className="rounded-md bg-indigo-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-indigo-700 disabled:opacity-60"
|
||||||
>
|
>
|
||||||
Preuzmi ZIP
|
{downloading ? 'Preuzimanje...' : reportType === 'servicer' ? 'Preuzmi mjesečni izvještaj' : 'Preuzmi DOCX'}
|
||||||
</button>
|
</button>
|
||||||
)}
|
{reportType === 'servicer' && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setBulkDownloadOpen(true)}
|
||||||
|
className="rounded-md border border-border-hairline px-3 py-1.5 text-xs font-medium text-text-main hover:bg-canvas-deep"
|
||||||
|
>
|
||||||
|
Preuzmi ZIP
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className="border-b border-border-hairline bg-canvas-deep px-4 py-1.5 text-[11px] text-text-muted">
|
<p className="border-b border-border-hairline bg-canvas-deep px-4 py-1.5 text-[11px] text-text-muted">
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { createTask, fetchTaskTemplates, getStatusLabel } from '../../stores/taskStore';
|
import { createTask, fetchTaskTemplates, getStatusLabel } from '../../stores/taskStore';
|
||||||
import { formatPurposeLabel, formatWorkOrderDisplayCode } from '../../lib/displayIds';
|
import { formatPurposeLabel, formatWorkOrderDisplayCode } from '../../lib/displayIds';
|
||||||
import ModalShell from '../ui/ModalShell';
|
import ModalShell from '../ui/ModalShell';
|
||||||
|
import { updateVehicle } from '../../stores/fleetDashboardStore';
|
||||||
|
|
||||||
const STATUS_OPTIONS = ['aktivan', 'servis', 'zavrsen', 'neaktivan'];
|
const STATUS_OPTIONS = ['aktivan', 'servis', 'zavrsen', 'neaktivan'];
|
||||||
|
|
||||||
@@ -32,6 +33,10 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
|||||||
const [templateLoading, setTemplateLoading] = useState(false);
|
const [templateLoading, setTemplateLoading] = useState(false);
|
||||||
const [templateId, setTemplateId] = useState('');
|
const [templateId, setTemplateId] = useState('');
|
||||||
const [templates, setTemplates] = useState([]);
|
const [templates, setTemplates] = useState([]);
|
||||||
|
const [craneDataModalOpen, setCraneDataModalOpen] = useState(false);
|
||||||
|
const [craneDataForm, setCraneDataForm] = useState({ superstructure_working_hours: '', chassis_working_hours: '', current_mileage: '' });
|
||||||
|
const [savingCraneData, setSavingCraneData] = useState(false);
|
||||||
|
const [craneDataError, setCraneDataError] = useState('');
|
||||||
|
|
||||||
const selectedTemplate = useMemo(
|
const selectedTemplate = useMemo(
|
||||||
() => templates.find((template) => String(template.id) === String(templateId)) || null,
|
() => templates.find((template) => String(template.id) === String(templateId)) || null,
|
||||||
@@ -51,6 +56,10 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
|||||||
setTemplateId('');
|
setTemplateId('');
|
||||||
setTemplates([]);
|
setTemplates([]);
|
||||||
setTemplateLoading(false);
|
setTemplateLoading(false);
|
||||||
|
setCraneDataModalOpen(false);
|
||||||
|
setCraneDataForm({ superstructure_working_hours: '', chassis_working_hours: '', current_mileage: '' });
|
||||||
|
setSavingCraneData(false);
|
||||||
|
setCraneDataError('');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Auto-pre-select today's open work order if exactly one exists for this crane
|
// Auto-pre-select today's open work order if exactly one exists for this crane
|
||||||
@@ -76,6 +85,60 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
|||||||
}));
|
}));
|
||||||
}, [selectedTemplate]);
|
}, [selectedTemplate]);
|
||||||
|
|
||||||
|
function openCraneDataModal() {
|
||||||
|
if (!contextCrane?.id) {
|
||||||
|
setCraneDataError('Dizalica nije odabrana u servisnom kontekstu.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCraneDataForm({
|
||||||
|
superstructure_working_hours: String(contextCrane?.superstructure_working_hours ?? ''),
|
||||||
|
chassis_working_hours: String(contextCrane?.chassis_working_hours ?? ''),
|
||||||
|
current_mileage: String(contextCrane?.current_mileage ?? ''),
|
||||||
|
});
|
||||||
|
setCraneDataError('');
|
||||||
|
setCraneDataModalOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSaveCraneData() {
|
||||||
|
if (!contextCrane?.id) {
|
||||||
|
setCraneDataError('Dizalica nije odabrana u servisnom kontekstu.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const superstructure = craneDataForm.superstructure_working_hours === '' ? undefined : Number(craneDataForm.superstructure_working_hours);
|
||||||
|
const chassis = craneDataForm.chassis_working_hours === '' ? undefined : Number(craneDataForm.chassis_working_hours);
|
||||||
|
const mileage = craneDataForm.current_mileage === '' ? undefined : Number(craneDataForm.current_mileage);
|
||||||
|
if (superstructure !== undefined && (Number.isNaN(superstructure) || superstructure < 0)) {
|
||||||
|
setCraneDataError('Radni sati nadogradnje moraju biti pozitivan broj.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (chassis !== undefined && (Number.isNaN(chassis) || chassis < 0)) {
|
||||||
|
setCraneDataError('Radni sati podvozja moraju biti pozitivan broj.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mileage !== undefined && (Number.isNaN(mileage) || mileage < 0)) {
|
||||||
|
setCraneDataError('Kilometraza mora biti pozitivan broj.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const payload = {};
|
||||||
|
if (superstructure !== undefined) payload.superstructure_working_hours = superstructure;
|
||||||
|
if (chassis !== undefined) payload.chassis_working_hours = chassis;
|
||||||
|
if (mileage !== undefined) payload.current_mileage = mileage;
|
||||||
|
if (Object.keys(payload).length === 0) {
|
||||||
|
setCraneDataError('Unesite barem jednu vrijednost za azuriranje.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSavingCraneData(true);
|
||||||
|
setCraneDataError('');
|
||||||
|
try {
|
||||||
|
await updateVehicle(contextCrane.id, payload);
|
||||||
|
setCraneDataModalOpen(false);
|
||||||
|
} catch (err) {
|
||||||
|
setCraneDataError(err?.message || 'Azuriranje podataka dizalice nije uspjelo.');
|
||||||
|
} finally {
|
||||||
|
setSavingCraneData(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!open) return null;
|
if (!open) return null;
|
||||||
|
|
||||||
function setField(name, value) {
|
function setField(name, value) {
|
||||||
@@ -156,6 +219,7 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<ModalShell
|
<ModalShell
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
overlayClassName="z-50 overflow-y-auto p-4 pt-20"
|
overlayClassName="z-50 overflow-y-auto p-4 pt-20"
|
||||||
@@ -215,6 +279,39 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
|||||||
</label>
|
</label>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{contextCrane && (
|
||||||
|
<div className="rounded-lg border border-border-hairline bg-canvas-base p-3">
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-semibold text-text-main">Podaci odabrane dizalice</p>
|
||||||
|
<p className="text-xs text-text-muted">{contextCrane.registration_number || '-'} / {contextCrane.make || '-'} {contextCrane.model || ''}</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={openCraneDataModal}
|
||||||
|
disabled={submitting}
|
||||||
|
className="rounded border border-border-hairline px-3 py-1 text-xs font-semibold text-text-main hover:bg-canvas-deep disabled:opacity-60"
|
||||||
|
>
|
||||||
|
Uredi podatke dizalice
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<dl className="mt-3 grid gap-2 text-sm sm:grid-cols-3">
|
||||||
|
<div>
|
||||||
|
<dt className="text-xs text-text-muted">Radni sati nadogradnje</dt>
|
||||||
|
<dd className="text-text-main">{contextCrane.superstructure_working_hours ?? '-'}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt className="text-xs text-text-muted">Radni sati podvozja</dt>
|
||||||
|
<dd className="text-text-main">{contextCrane.chassis_working_hours ?? '-'}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt className="text-xs text-text-muted">Kilometraza</dt>
|
||||||
|
<dd className="text-text-main">{contextCrane.current_mileage ?? '-'}</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<label className="flex flex-col gap-1 text-sm">
|
<label className="flex flex-col gap-1 text-sm">
|
||||||
<span className="font-medium text-text-main">Naslov zadatka *</span>
|
<span className="font-medium text-text-main">Naslov zadatka *</span>
|
||||||
<input
|
<input
|
||||||
@@ -326,5 +423,84 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</ModalShell>
|
</ModalShell>
|
||||||
|
|
||||||
|
{craneDataModalOpen && (
|
||||||
|
<ModalShell
|
||||||
|
onClose={() => setCraneDataModalOpen(false)}
|
||||||
|
overlayClassName="z-[60] bg-black/40 p-4"
|
||||||
|
contentClassName="flex min-h-full items-center justify-center"
|
||||||
|
panelClassName="w-full max-w-lg rounded-xl border border-border-hairline bg-canvas-elevated shadow-2xl"
|
||||||
|
>
|
||||||
|
<div className="space-y-4 p-4">
|
||||||
|
<div>
|
||||||
|
<h4 className="text-base font-semibold text-text-main">Izmijeni podatke dizalice</h4>
|
||||||
|
<p className="mt-1 text-sm text-text-muted">
|
||||||
|
Azurirajte radne sate i kilometrazu za dizalicu: <strong>{contextCrane?.registration_number || "-"}</strong>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<label className="flex flex-col gap-1 text-sm">
|
||||||
|
<span className="text-xs text-text-muted">Radni sati nadogradnje</span>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
step="0.01"
|
||||||
|
value={craneDataForm.superstructure_working_hours}
|
||||||
|
onInput={(event) => setCraneDataForm((prev) => ({ ...prev, superstructure_working_hours: event.currentTarget.value }))}
|
||||||
|
disabled={savingCraneData}
|
||||||
|
className="rounded-lg border border-border-hairline bg-canvas-base px-3 py-2 text-text-main disabled:opacity-60"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="flex flex-col gap-1 text-sm">
|
||||||
|
<span className="text-xs text-text-muted">Radni sati podvozja</span>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
step="0.01"
|
||||||
|
value={craneDataForm.chassis_working_hours}
|
||||||
|
onInput={(event) => setCraneDataForm((prev) => ({ ...prev, chassis_working_hours: event.currentTarget.value }))}
|
||||||
|
disabled={savingCraneData}
|
||||||
|
className="rounded-lg border border-border-hairline bg-canvas-base px-3 py-2 text-text-main disabled:opacity-60"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label className="flex flex-col gap-1 text-sm">
|
||||||
|
<span className="text-xs text-text-muted">Kilometraza (km)</span>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
step="1"
|
||||||
|
value={craneDataForm.current_mileage}
|
||||||
|
onInput={(event) => setCraneDataForm((prev) => ({ ...prev, current_mileage: event.currentTarget.value }))}
|
||||||
|
disabled={savingCraneData}
|
||||||
|
className="rounded-lg border border-border-hairline bg-canvas-base px-3 py-2 text-text-main disabled:opacity-60"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
{craneDataError && (
|
||||||
|
<div className="rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700">
|
||||||
|
{craneDataError}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setCraneDataModalOpen(false)}
|
||||||
|
disabled={savingCraneData}
|
||||||
|
className="rounded-lg border border-border-hairline px-4 py-2 text-sm font-medium text-text-main hover:bg-canvas-deep disabled:opacity-60"
|
||||||
|
>
|
||||||
|
Odustani
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleSaveCraneData}
|
||||||
|
disabled={savingCraneData}
|
||||||
|
className="rounded-lg bg-emerald-600 px-4 py-2 text-sm font-semibold text-white hover:bg-emerald-700 disabled:opacity-60"
|
||||||
|
>
|
||||||
|
{savingCraneData ? "Spremanje..." : "Spremi podatke"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ModalShell>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -251,6 +251,15 @@ export default function TaskServiceRecordsModal({
|
|||||||
>
|
>
|
||||||
Postavi servisni kontekst
|
Postavi servisni kontekst
|
||||||
</button>
|
</button>
|
||||||
|
{task?.vehicle && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={openCraneDataModal}
|
||||||
|
className="rounded-md border border-border-hairline px-3 py-1 text-xs font-semibold text-text-main hover:bg-canvas-base"
|
||||||
|
>
|
||||||
|
Uredi podatke dizalice
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
@@ -306,10 +315,10 @@ export default function TaskServiceRecordsModal({
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={openCraneDataModal}
|
onClick={openCraneDataModal}
|
||||||
className="rounded border border-border-hairline px-1.5 py-0.5 text-[10px] text-text-muted hover:bg-canvas-base"
|
className="rounded border border-border-hairline px-2 py-1 text-xs text-text-main hover:bg-canvas-base"
|
||||||
title="Izmijeni radne sate i kilometražu dizalice"
|
title="Izmijeni radne sate i kilometrazu dizalice"
|
||||||
>
|
>
|
||||||
🔧
|
Uredi podatke
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</dd>
|
</dd>
|
||||||
@@ -539,7 +548,12 @@ export default function TaskServiceRecordsModal({
|
|||||||
</ModalShell>
|
</ModalShell>
|
||||||
|
|
||||||
{craneDataModalOpen && (
|
{craneDataModalOpen && (
|
||||||
<ModalShell open={craneDataModalOpen} onClose={() => setCraneDataModalOpen(false)} title="Izmijeni podatke dizalice">
|
<ModalShell
|
||||||
|
onClose={() => setCraneDataModalOpen(false)}
|
||||||
|
overlayClassName="z-[60] bg-black/40 p-4"
|
||||||
|
contentClassName="flex min-h-full items-center justify-center"
|
||||||
|
panelClassName="w-full max-w-lg rounded-xl border border-border-hairline bg-canvas-elevated shadow-2xl"
|
||||||
|
>
|
||||||
<div className="p-4 space-y-4">
|
<div className="p-4 space-y-4">
|
||||||
<p className="text-sm text-text-muted">
|
<p className="text-sm text-text-muted">
|
||||||
Ažurirajte radne sate i kilometražu za dizalicu: <strong>{getTaskCraneDisplay(task)}</strong>
|
Ažurirajte radne sate i kilometražu za dizalicu: <strong>{getTaskCraneDisplay(task)}</strong>
|
||||||
|
|||||||
@@ -321,22 +321,24 @@ export default function WorkOrderInvoicesPdfPage() {
|
|||||||
{workOrder ? `Dizalica: ${workOrder.crane_label || workOrder.crane || '-'}` : 'Pregled računa prije kreiranja PDF-a.'}
|
{workOrder ? `Dizalica: ${workOrder.crane_label || workOrder.crane || '-'}` : 'Pregled računa prije kreiranja PDF-a.'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
type="button"
|
<button
|
||||||
onClick={() => downloadWorkOrderPdf(workOrderId)}
|
type="button"
|
||||||
disabled={!workOrderId}
|
onClick={() => downloadWorkOrderPdf(workOrderId)}
|
||||||
className="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-semibold text-white hover:bg-indigo-700 disabled:opacity-60"
|
disabled={!workOrderId}
|
||||||
>
|
className="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-semibold text-white hover:bg-indigo-700 disabled:opacity-60"
|
||||||
Preuzmi PDF putnog naloga
|
>
|
||||||
</button>
|
Preuzmi PDF putnog naloga
|
||||||
<button
|
</button>
|
||||||
type="button"
|
<button
|
||||||
onClick={() => downloadWorkOrderDocx(workOrderId)}
|
type="button"
|
||||||
disabled={!workOrderId}
|
onClick={() => downloadWorkOrderDocx(workOrderId)}
|
||||||
className="rounded-lg border border-border-hairline px-4 py-2 text-sm font-semibold text-text-main hover:bg-canvas-deep disabled:opacity-60"
|
disabled={!workOrderId}
|
||||||
>
|
className="rounded-lg border border-border-hairline px-4 py-2 text-sm font-semibold text-text-main hover:bg-canvas-deep disabled:opacity-60"
|
||||||
Preuzmi DOCX putnog naloga
|
>
|
||||||
</button>
|
Preuzmi DOCX putnog naloga
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ const DASHBOARD_FETCH_TTL_MS = 30_000; // 30 sekundi
|
|||||||
let dbPromise = null;
|
let dbPromise = null;
|
||||||
let syncListenerStarted = false;
|
let syncListenerStarted = false;
|
||||||
let isSyncInProgress = false;
|
let isSyncInProgress = false;
|
||||||
|
const archiveNotificationPollers = new Map();
|
||||||
|
const ARCHIVE_NOTIFICATION_POLL_INTERVAL_MS = 10_000;
|
||||||
|
const ARCHIVE_NOTIFICATION_POLL_TIMEOUT_MS = 15 * 60 * 1000;
|
||||||
|
|
||||||
function isBrowser() {
|
function isBrowser() {
|
||||||
return typeof window !== 'undefined';
|
return typeof window !== 'undefined';
|
||||||
@@ -831,11 +834,68 @@ function _schedulePdfNotificationPolling() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function _scheduleArchiveNotificationPolling() {
|
function _findCompletedArchiveNotification(notifications, generatedArchiveId) {
|
||||||
|
if (!generatedArchiveId || !Array.isArray(notifications)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return notifications.find((notification) => {
|
||||||
|
const metadata = notification?.metadata || {};
|
||||||
|
return metadata.entity_type === 'fleet_archive'
|
||||||
|
&& String(metadata.generated_archive_id || '') === String(generatedArchiveId)
|
||||||
|
&& ['completed', 'failed'].includes(String(metadata.stage || ''));
|
||||||
|
}) || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _clearArchiveNotificationPoller(generatedArchiveId) {
|
||||||
|
const key = String(generatedArchiveId || '');
|
||||||
|
const handles = archiveNotificationPollers.get(key);
|
||||||
|
if (!handles) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.clearInterval(handles.intervalId);
|
||||||
|
window.clearTimeout(handles.timeoutId);
|
||||||
|
archiveNotificationPollers.delete(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _scheduleArchiveNotificationPolling(generatedArchiveId = null) {
|
||||||
if (!isBrowser()) return;
|
if (!isBrowser()) return;
|
||||||
[5000, 20000, 60000].forEach((delay) => {
|
if (!generatedArchiveId) {
|
||||||
setTimeout(() => _refreshNotificationsAsync(), delay);
|
[5000, 20000, 60000].forEach((delay) => {
|
||||||
});
|
setTimeout(() => _refreshNotificationsAsync(), delay);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = String(generatedArchiveId);
|
||||||
|
if (archiveNotificationPollers.has(key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pollOnce = async () => {
|
||||||
|
try {
|
||||||
|
const notificationModule = await import('./notificationStore.js');
|
||||||
|
await notificationModule.fetchNotifications();
|
||||||
|
const resolvedNotification = _findCompletedArchiveNotification(
|
||||||
|
notificationModule.$notifications.get(),
|
||||||
|
key
|
||||||
|
);
|
||||||
|
if (resolvedNotification) {
|
||||||
|
_clearArchiveNotificationPoller(key);
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// silent — korisnik će i dalje vidjeti toast ili ručno osvježiti notifikacije
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const intervalId = window.setInterval(() => {
|
||||||
|
void pollOnce();
|
||||||
|
}, ARCHIVE_NOTIFICATION_POLL_INTERVAL_MS);
|
||||||
|
const timeoutId = window.setTimeout(() => {
|
||||||
|
_clearArchiveNotificationPoller(key);
|
||||||
|
}, ARCHIVE_NOTIFICATION_POLL_TIMEOUT_MS);
|
||||||
|
|
||||||
|
archiveNotificationPollers.set(key, { intervalId, timeoutId });
|
||||||
|
void pollOnce();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadWorkOrderPdf(workOrderId) {
|
export async function downloadWorkOrderPdf(workOrderId) {
|
||||||
@@ -1030,13 +1090,13 @@ export async function downloadMonthlyCostsReport(year, month) {
|
|||||||
export async function downloadMonthlyServiceTasksArchive(year, month) {
|
export async function downloadMonthlyServiceTasksArchive(year, month) {
|
||||||
try {
|
try {
|
||||||
const payload = await api.post('fleet/reports/monthly-service-tasks-archive-request/', { year, month });
|
const payload = await api.post('fleet/reports/monthly-service-tasks-archive-request/', { year, month });
|
||||||
|
await _refreshNotificationsAsync();
|
||||||
if (payload?.status === 'ready' && payload?.download_url) {
|
if (payload?.status === 'ready' && payload?.download_url) {
|
||||||
showToast('ZIP arhiva servisnih taskova je spremna. Preuzmite je kroz notifikaciju.', 'success');
|
showToast('ZIP arhiva servisnih taskova je spremna. Preuzmite je kroz notifikaciju.', 'success');
|
||||||
_refreshNotificationsAsync();
|
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
showToast('ZIP arhiva servisnih taskova se generira u pozadini. Preuzimanje je dostupno kroz notifikaciju.', 'info');
|
showToast('ZIP arhiva servisnih taskova se generira u pozadini. Preuzimanje je dostupno kroz notifikaciju.', 'info');
|
||||||
_scheduleArchiveNotificationPolling();
|
_scheduleArchiveNotificationPolling(payload?.generated_archive_id || null);
|
||||||
return payload;
|
return payload;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showToast(err?.message || 'Pokretanje generiranja ZIP arhive servisnih taskova nije uspjelo.', 'error');
|
showToast(err?.message || 'Pokretanje generiranja ZIP arhive servisnih taskova nije uspjelo.', 'error');
|
||||||
@@ -1047,13 +1107,13 @@ export async function downloadMonthlyServiceTasksArchive(year, month) {
|
|||||||
export async function downloadMonthlyWorkOrdersArchive(year, month) {
|
export async function downloadMonthlyWorkOrdersArchive(year, month) {
|
||||||
try {
|
try {
|
||||||
const payload = await api.post('fleet/reports/monthly-work-orders-archive-request/', { year, month });
|
const payload = await api.post('fleet/reports/monthly-work-orders-archive-request/', { year, month });
|
||||||
|
await _refreshNotificationsAsync();
|
||||||
if (payload?.status === 'ready' && payload?.download_url) {
|
if (payload?.status === 'ready' && payload?.download_url) {
|
||||||
showToast('ZIP arhiva putnih naloga je spremna. Preuzmite je kroz notifikaciju.', 'success');
|
showToast('ZIP arhiva putnih naloga je spremna. Preuzmite je kroz notifikaciju.', 'success');
|
||||||
_refreshNotificationsAsync();
|
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
showToast('ZIP arhiva putnih naloga se generira u pozadini. Preuzimanje je dostupno kroz notifikaciju.', 'info');
|
showToast('ZIP arhiva putnih naloga se generira u pozadini. Preuzimanje je dostupno kroz notifikaciju.', 'info');
|
||||||
_scheduleArchiveNotificationPolling();
|
_scheduleArchiveNotificationPolling(payload?.generated_archive_id || null);
|
||||||
return payload;
|
return payload;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showToast(err?.message || 'Pokretanje generiranja ZIP arhive putnih naloga nije uspjelo.', 'error');
|
showToast(err?.message || 'Pokretanje generiranja ZIP arhive putnih naloga nije uspjelo.', 'error');
|
||||||
|
|||||||
Reference in New Issue
Block a user