Compare commits
2 Commits
ee18af7877
...
1f6c0d6086
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f6c0d6086 | ||
|
|
3aecbdd6ea |
@@ -3055,17 +3055,10 @@ def _request_monthly_archive_generation(*, request, archive_type):
|
||||
.first()
|
||||
)
|
||||
if existing_pending:
|
||||
stale_pending_threshold = timezone.now() - timedelta(minutes=3)
|
||||
if existing_pending.created_at and existing_pending.created_at < stale_pending_threshold:
|
||||
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),
|
||||
}
|
||||
return {
|
||||
'status': 'processing',
|
||||
'generated_archive_id': str(existing_pending.pk),
|
||||
}
|
||||
|
||||
generated_archive = GeneratedFleetArchive.objects.create(
|
||||
requested_by=request.user,
|
||||
@@ -3087,7 +3080,6 @@ def _request_monthly_archive_generation(*, request, archive_type):
|
||||
stage='requested',
|
||||
year=year,
|
||||
month=month,
|
||||
generated_archive=generated_archive,
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
@@ -4,7 +4,7 @@ import AuthWidget from './AuthWidget';
|
||||
import UserDisplay from './ui/UserDisplay';
|
||||
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||
import { useSpring, animated } from '@react-spring/web';
|
||||
import { hydrateAuthFromStorage, loadCurrentUser, $user, $accessToken } from '../stores/authStore';
|
||||
import { hydrateAuthFromStorage } from '../stores/authStore';
|
||||
|
||||
const ITEMS = [
|
||||
{ id: 'dashboard', label: 'Dashboard', href: '/' },
|
||||
@@ -21,12 +21,8 @@ function normalizePath(p) {
|
||||
}
|
||||
|
||||
function getActiveIndex(path) {
|
||||
// Exact match (e.g. '/' → Dashboard)
|
||||
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;
|
||||
const idx = ITEMS.findIndex((item) => item.href === path);
|
||||
return idx >= 0 ? idx : 0;
|
||||
}
|
||||
|
||||
export default function Navbar({ minimal = false }) {
|
||||
@@ -59,10 +55,6 @@ export default function Navbar({ minimal = false }) {
|
||||
// Mount: izmjeri početnu poziciju bez animacije, pa uključi animaciju za buduće navigacije
|
||||
useEffect(() => {
|
||||
hydrateAuthFromStorage();
|
||||
// Učitaj korisnika ako token postoji ali $user još nije popunjen
|
||||
if (!$user.get() && $accessToken.get()) {
|
||||
loadCurrentUser();
|
||||
}
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
measureIndicator();
|
||||
|
||||
@@ -130,8 +130,8 @@ function SortableCodeLabel({ title, direction, onToggle }) {
|
||||
title="Sortiraj po datumu iz koda (godina, mjesec, dan)"
|
||||
>
|
||||
<span>{title}</span>
|
||||
<span className={direction === 'asc' ? 'text-indigo-700' : 'text-text-muted/50'}>↑</span>
|
||||
<span className={direction === 'desc' ? 'text-indigo-700' : 'text-text-muted/50'}>↓</span>
|
||||
<span className={direction === 'asc' ? 'text-indigo-700' : 'text-text-muted/50'}>↑</span>
|
||||
<span className={direction === 'desc' ? 'text-indigo-700' : 'text-text-muted/50'}>↓</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -276,7 +276,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
if (targetWorkOrder) {
|
||||
openWorkOrderDetails(targetWorkOrder);
|
||||
} else {
|
||||
showToast('Traženi putni nalog nije pronađen u trenutnom prikazu.', 'warning');
|
||||
showToast('Traženi putni nalog nije pronađen u trenutnom prikazu.', 'warning');
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -293,7 +293,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
setServiceRecordBackTask(null);
|
||||
setSelectedServiceRecord(targetServiceRecord);
|
||||
} else {
|
||||
showToast('Traženi servisni zapis nije pronađen u trenutnom prikazu.', 'warning');
|
||||
showToast('Traženi servisni zapis nije pronađen u trenutnom prikazu.', 'warning');
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -445,7 +445,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
}
|
||||
// Collect work order IDs that are directly assigned to tasks of the context crane.
|
||||
// This covers cross-crane shared work orders: a WO created for crane A can be
|
||||
// assigned to a task of crane B — it should still appear in crane B's context view.
|
||||
// assigned to a task of crane B — it should still appear in crane B's context view.
|
||||
const contextTaskWorkOrderIds = new Set(
|
||||
tasks
|
||||
.filter((t) => String(t.vehicle || '') === String(hydratedSelectedVehicleId) && t.work_order)
|
||||
@@ -463,7 +463,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
[scopedWorkOrders, currentPage]
|
||||
);
|
||||
|
||||
// Map: workOrderId → array of unique crane objects (own + cross-crane task links)
|
||||
// Map: workOrderId → array of unique crane objects (own + cross-crane task links)
|
||||
const workOrderSharedCranes = useMemo(() => {
|
||||
const craneById = new Map(cranes.map((c) => [String(c.id), c]));
|
||||
const map = new Map();
|
||||
@@ -658,11 +658,11 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
async function handleUpdateWorkOrder(workOrder, changes) {
|
||||
try {
|
||||
await updateWorkOrder(workOrder.id, changes);
|
||||
showToast('Nalog je uspješno ažuriran.', 'success');
|
||||
showToast('Nalog je uspješno ažuriran.', 'success');
|
||||
await fetchFleetDashboardData({ silent: true });
|
||||
await fetchTasks({ force: true });
|
||||
} catch (error) {
|
||||
showToast(error?.message || 'AĹľuriranje naloga nije uspjelo.', 'error');
|
||||
showToast(error?.message || 'Ažuriranje naloga nije uspjelo.', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -674,7 +674,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
|
||||
async function handleSetServiceContext() {
|
||||
if (!selectedCraneRowId) {
|
||||
showToast('Prvo oznaÄŤite redak dizalice.', 'warning');
|
||||
showToast('Prvo označite redak dizalice.', 'warning');
|
||||
return;
|
||||
}
|
||||
const selectedCrane = cranes.find((item) => String(item.id) === String(selectedCraneRowId));
|
||||
@@ -688,7 +688,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
|
||||
function handleSetServiceContextForCrane(selectedCrane) {
|
||||
if (!selectedCrane) {
|
||||
showToast('Odabrana dizalica više nije dostupna.', 'warning');
|
||||
showToast('Odabrana dizalica više nije dostupna.', 'warning');
|
||||
return;
|
||||
}
|
||||
setSelectedCraneRowId(selectedCrane.id);
|
||||
@@ -711,7 +711,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
showToast('Ne mogu dohvatiti dizalice. Provjerite mreĹľu ili prijavu.', 'error');
|
||||
showToast('Ne mogu dohvatiti dizalice. Provjerite mrežu ili prijavu.', 'error');
|
||||
return;
|
||||
}
|
||||
setIsTaskModalOpen(true);
|
||||
@@ -741,7 +741,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
{ key: 'serialNumber', label: 'SN', className: 'px-4 py-3' },
|
||||
{ key: 'model', label: 'Marka / Model', className: 'px-4 py-3' },
|
||||
{ key: 'client', label: 'Kupac', className: 'px-4 py-3' },
|
||||
{ key: 'mileage', label: 'KilometraĹľa', className: 'px-4 py-3' },
|
||||
{ key: 'mileage', label: 'Kilometraža', className: 'px-4 py-3' },
|
||||
{ key: 'status', label: 'Status', className: 'px-4 py-3' },
|
||||
];
|
||||
const taskColumns = [
|
||||
@@ -784,7 +784,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
showToast('Ne mogu dohvatiti dizalice. Provjerite mreĹľu ili prijavu.', 'error');
|
||||
showToast('Ne mogu dohvatiti dizalice. Provjerite mrežu ili prijavu.', 'error');
|
||||
return;
|
||||
}
|
||||
setIsWorkOrderModalOpen(true);
|
||||
@@ -839,9 +839,9 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
<p className="text-[10px] text-text-muted">aktivnih zadataka</p>
|
||||
</article>
|
||||
|
||||
{/* Dovršeni nalozi */}
|
||||
{/* Dovršeni nalozi */}
|
||||
<article className="flex flex-col gap-0.5 rounded-xl border border-border-hairline bg-canvas-elevated px-3 py-2.5 shadow-sm">
|
||||
<p className="text-xs text-text-muted">Dovršeni nalozi</p>
|
||||
<p className="text-xs text-text-muted">Dovršeni nalozi</p>
|
||||
<p className="text-xl font-semibold text-emerald-600">{stats.closedWorkOrders}</p>
|
||||
{stats.totalWorkOrders > 0 && (
|
||||
<p className="text-[10px] text-text-muted">
|
||||
@@ -854,7 +854,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
<article className="flex flex-col gap-0.5 rounded-xl border border-border-hairline bg-canvas-elevated px-3 py-2.5 shadow-sm">
|
||||
<p className="text-xs text-text-muted">Moji danas</p>
|
||||
<p className={`text-xl font-semibold ${myTasksToday > 0 ? 'text-indigo-600' : 'text-text-main'}`}>
|
||||
{hasMounted ? myTasksToday : '—'}
|
||||
{hasMounted ? myTasksToday : '—'}
|
||||
</p>
|
||||
<p className="text-[10px] text-text-muted">planirani na mene</p>
|
||||
</article>
|
||||
@@ -964,7 +964,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
rows={dashboardTasks}
|
||||
rowKey={(task) => task.id}
|
||||
loading={loading}
|
||||
loadingMessage="UÄŤitavanje radnih zadataka..."
|
||||
loadingMessage="Učitavanje radnih zadataka..."
|
||||
emptyMessage="Nema radnih zadataka za odabrani filter."
|
||||
rowClassName={(task) => {
|
||||
const status = String(task?.status || '').toLowerCase();
|
||||
@@ -1018,7 +1018,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
<details className="overflow-hidden rounded-xl border border-border-hairline bg-canvas-elevated shadow-sm">
|
||||
<summary className="flex cursor-pointer select-none items-center justify-between px-4 py-3 text-sm font-medium text-text-muted hover:bg-canvas-deep">
|
||||
<span>Sync log</span>
|
||||
<span className="text-xs opacity-60">â–Ľ</span>
|
||||
<span className="text-xs opacity-60">▾</span>
|
||||
</summary>
|
||||
<div className="border-t border-border-hairline">
|
||||
<SyncLogPanel />
|
||||
@@ -1070,7 +1070,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
onClick={() => fetchFleetDashboardData()}
|
||||
className="text-sm font-medium text-indigo-600 hover:text-indigo-800"
|
||||
>
|
||||
OsvjeĹľi
|
||||
Osvježi
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1079,12 +1079,12 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
rows={latestWorkOrders}
|
||||
rowKey={(workOrder) => workOrder.id}
|
||||
loading={loading}
|
||||
loadingMessage="UÄŤitavanje..."
|
||||
loadingMessage="Učitavanje..."
|
||||
emptyMessage={
|
||||
workOrderScope === 'context'
|
||||
? (!hydratedSelectedVehicleId
|
||||
? 'Odaberite dizalicu za prikaz putnih naloga iz servisnog konteksta.'
|
||||
: 'Nema dostupnih putnih naloga za odabrani servisni kontekst. MoĹľete prebaciti na prikaz svih naloga.')
|
||||
: 'Nema dostupnih putnih naloga za odabrani servisni kontekst. Možete prebaciti na prikaz svih naloga.')
|
||||
: 'Nema dostupnih putnih naloga.'
|
||||
}
|
||||
renderRow={(workOrder) => (
|
||||
@@ -1166,7 +1166,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
className="rounded px-2 py-1 text-xs font-medium text-text-muted hover:bg-canvas-deep hover:text-text-main"
|
||||
title="Upload fotografija putnog naloga"
|
||||
>
|
||||
đź“·
|
||||
Foto
|
||||
</button>
|
||||
</td>
|
||||
</>
|
||||
@@ -1196,7 +1196,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
disabled={currentPage >= totalPages}
|
||||
className="rounded border border-border-hairline px-2 py-1 text-text-main hover:bg-canvas-deep disabled:opacity-50"
|
||||
>
|
||||
Sljedeća
|
||||
Sljedeća
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1230,7 +1230,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
onClick={() => fetchFleetDashboardData()}
|
||||
className="text-sm font-medium text-indigo-600 hover:text-indigo-800"
|
||||
>
|
||||
OsvjeĹľi
|
||||
Osvježi
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1249,7 +1249,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
{ key: 'date', label: 'Datum', className: 'px-4 py-3' },
|
||||
{ key: 'crane', label: 'Dizalica', className: 'px-4 py-3' },
|
||||
{ key: 'description', label: 'Opis', className: 'px-4 py-3' },
|
||||
{ key: 'cost', label: 'Trošak', className: 'px-4 py-3' },
|
||||
{ key: 'cost', label: 'Trošak', className: 'px-4 py-3' },
|
||||
{ key: 'actions', label: 'Akcije', className: 'px-4 py-3' },
|
||||
]}
|
||||
rows={paginatedRecentServiceRecords}
|
||||
@@ -1302,7 +1302,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
disabled={serviceRecordsPage >= serviceRecordsTotalPages}
|
||||
className="rounded border border-border-hairline px-2 py-1 text-text-main hover:bg-canvas-deep disabled:opacity-50"
|
||||
>
|
||||
Sljedeća
|
||||
Sljedeća
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1312,7 +1312,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
)}
|
||||
{hydratedSelectedVehicleId && loading && (
|
||||
<p className="px-4 py-6 text-center text-sm text-text-muted">
|
||||
UÄŤitavanje...
|
||||
Učitavanje...
|
||||
</p>
|
||||
)}
|
||||
{hydratedSelectedVehicleId && !loading && serviceTaskGroups.length === 0 && (
|
||||
@@ -1365,7 +1365,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
{ key: 'date', label: 'Datum', className: 'px-4 py-3' },
|
||||
{ key: 'crane', label: 'DIZALICA', className: 'px-4 py-3' },
|
||||
{ key: 'description', label: 'Opis', className: 'px-4 py-3' },
|
||||
{ key: 'cost', label: 'Trošak', className: 'px-4 py-3' },
|
||||
{ key: 'cost', label: 'Trošak', className: 'px-4 py-3' },
|
||||
{ key: 'files', label: 'Datoteke', className: 'px-4 py-3' },
|
||||
{ key: 'actions', label: 'Akcije', className: 'px-4 py-3' },
|
||||
]}
|
||||
@@ -1400,7 +1400,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
onClick={() => setPhotoUpload({ open: true, serviceRecordId: record.id })}
|
||||
className="rounded border border-border-hairline px-2 py-1 text-xs text-text-main hover:bg-canvas-base"
|
||||
>
|
||||
📎 Dodaj datoteke
|
||||
Dodaj datoteke
|
||||
</button>
|
||||
</td>
|
||||
</>
|
||||
@@ -1419,7 +1419,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
|
||||
{showClients && (
|
||||
<>
|
||||
{/* ── Tablica klijenata i njihovih dizalica ───────── */}
|
||||
{/* Tablica klijenata i njihovih dizalica */}
|
||||
<div id="section-clients">
|
||||
<ClientsSection
|
||||
onSetServiceContext={handleSetServiceContextForCraneId}
|
||||
@@ -1446,7 +1446,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
onClick={() => fetchFleetDashboardData()}
|
||||
className="text-sm font-medium text-indigo-600 hover:text-indigo-800"
|
||||
>
|
||||
OsvjeĹľi
|
||||
Osvježi
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1457,7 +1457,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
rowClassName="hover:bg-canvas-deep"
|
||||
isRowSelected={(vehicle) => String(vehicle.id) === String(selectedCraneRowId)}
|
||||
loading={loading}
|
||||
loadingMessage="UÄŤitavanje vozila..."
|
||||
loadingMessage="Učitavanje vozila..."
|
||||
emptyMessage="Nema dostupnih vozila."
|
||||
renderRow={(vehicle) => (
|
||||
<>
|
||||
@@ -1529,7 +1529,7 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
onSubmit={handleUpdateWorkOrder}
|
||||
/>
|
||||
|
||||
{/* Modali su na root razini div-a — van <main> i <section> —
|
||||
{/* Modali su na root razini div-a — van <main> i <section> —
|
||||
kako bi fixed pozicioniranje i z-index radili ispravno */}
|
||||
<ServiceRecordForm
|
||||
open={serviceRecordOpen}
|
||||
@@ -1632,4 +1632,3 @@ export default function FleetDashboardShell({ pageMode = 'dashboard' }) {
|
||||
</AnimatedPage>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -367,10 +367,10 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
|
||||
|
||||
async function handleDownloadAllTasksArchive() {
|
||||
if (downloadingAllTasks) return;
|
||||
setBulkDownloadOpen(false);
|
||||
setDownloadingAllTasks(true);
|
||||
try {
|
||||
await downloadMonthlyServiceTasksArchive(viewYear, viewMonth + 1);
|
||||
setBulkDownloadOpen(false);
|
||||
} finally {
|
||||
setDownloadingAllTasks(false);
|
||||
}
|
||||
@@ -378,10 +378,10 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
|
||||
|
||||
async function handleDownloadAllWorkOrdersArchive() {
|
||||
if (downloadingAllWorkOrders) return;
|
||||
setBulkDownloadOpen(false);
|
||||
setDownloadingAllWorkOrders(true);
|
||||
try {
|
||||
await downloadMonthlyWorkOrdersArchive(viewYear, viewMonth + 1);
|
||||
setBulkDownloadOpen(false);
|
||||
} finally {
|
||||
setDownloadingAllWorkOrders(false);
|
||||
}
|
||||
@@ -655,25 +655,23 @@ export default function TaskCalendarWidget({ tasks = [], notes = [], workOrders
|
||||
{MONTH_NAMES[viewMonth]} {viewYear}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
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
|
||||
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"
|
||||
onClick={() => setBulkDownloadOpen(true)}
|
||||
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"
|
||||
>
|
||||
{downloading ? 'Preuzimanje...' : reportType === 'servicer' ? 'Preuzmi mjesečni izvještaj' : 'Preuzmi DOCX'}
|
||||
Preuzmi ZIP
|
||||
</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>
|
||||
|
||||
<p className="border-b border-border-hairline bg-canvas-deep px-4 py-1.5 text-[11px] text-text-muted">
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import { createTask, fetchTaskTemplates, getStatusLabel } from '../../stores/taskStore';
|
||||
import { formatPurposeLabel, formatWorkOrderDisplayCode } from '../../lib/displayIds';
|
||||
import ModalShell from '../ui/ModalShell';
|
||||
import { updateVehicle } from '../../stores/fleetDashboardStore';
|
||||
|
||||
const STATUS_OPTIONS = ['aktivan', 'servis', 'zavrsen', 'neaktivan'];
|
||||
|
||||
@@ -33,10 +32,6 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
||||
const [templateLoading, setTemplateLoading] = useState(false);
|
||||
const [templateId, setTemplateId] = 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(
|
||||
() => templates.find((template) => String(template.id) === String(templateId)) || null,
|
||||
@@ -56,10 +51,6 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
||||
setTemplateId('');
|
||||
setTemplates([]);
|
||||
setTemplateLoading(false);
|
||||
setCraneDataModalOpen(false);
|
||||
setCraneDataForm({ superstructure_working_hours: '', chassis_working_hours: '', current_mileage: '' });
|
||||
setSavingCraneData(false);
|
||||
setCraneDataError('');
|
||||
return;
|
||||
}
|
||||
// Auto-pre-select today's open work order if exactly one exists for this crane
|
||||
@@ -85,60 +76,6 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
||||
}));
|
||||
}, [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;
|
||||
|
||||
function setField(name, value) {
|
||||
@@ -219,7 +156,6 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ModalShell
|
||||
onClose={onClose}
|
||||
overlayClassName="z-50 overflow-y-auto p-4 pt-20"
|
||||
@@ -279,39 +215,6 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
||||
</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">
|
||||
<span className="font-medium text-text-main">Naslov zadatka *</span>
|
||||
<input
|
||||
@@ -423,84 +326,5 @@ export default function TaskCreateModal({ open, workOrders = [], contextCrane =
|
||||
</form>
|
||||
</div>
|
||||
</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,15 +251,6 @@ export default function TaskServiceRecordsModal({
|
||||
>
|
||||
Postavi servisni kontekst
|
||||
</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
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
@@ -315,10 +306,10 @@ export default function TaskServiceRecordsModal({
|
||||
<button
|
||||
type="button"
|
||||
onClick={openCraneDataModal}
|
||||
className="rounded border border-border-hairline px-2 py-1 text-xs text-text-main hover:bg-canvas-base"
|
||||
title="Izmijeni radne sate i kilometrazu dizalice"
|
||||
className="rounded border border-border-hairline px-1.5 py-0.5 text-[10px] text-text-muted hover:bg-canvas-base"
|
||||
title="Izmijeni radne sate i kilometražu dizalice"
|
||||
>
|
||||
Uredi podatke
|
||||
🔧
|
||||
</button>
|
||||
)}
|
||||
</dd>
|
||||
@@ -548,12 +539,7 @@ export default function TaskServiceRecordsModal({
|
||||
</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"
|
||||
>
|
||||
<ModalShell open={craneDataModalOpen} onClose={() => setCraneDataModalOpen(false)} title="Izmijeni podatke dizalice">
|
||||
<div className="p-4 space-y-4">
|
||||
<p className="text-sm text-text-muted">
|
||||
Ažurirajte radne sate i kilometražu za dizalicu: <strong>{getTaskCraneDisplay(task)}</strong>
|
||||
|
||||
@@ -321,24 +321,22 @@ export default function WorkOrderInvoicesPdfPage() {
|
||||
{workOrder ? `Dizalica: ${workOrder.crane_label || workOrder.crane || '-'}` : 'Pregled računa prije kreiranja PDF-a.'}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => downloadWorkOrderPdf(workOrderId)}
|
||||
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>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => downloadWorkOrderDocx(workOrderId)}
|
||||
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>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => downloadWorkOrderPdf(workOrderId)}
|
||||
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>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => downloadWorkOrderDocx(workOrderId)}
|
||||
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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -28,9 +28,6 @@ const DASHBOARD_FETCH_TTL_MS = 30_000; // 30 sekundi
|
||||
let dbPromise = null;
|
||||
let syncListenerStarted = 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() {
|
||||
return typeof window !== 'undefined';
|
||||
@@ -834,68 +831,11 @@ function _schedulePdfNotificationPolling() {
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
function _scheduleArchiveNotificationPolling() {
|
||||
if (!isBrowser()) return;
|
||||
if (!generatedArchiveId) {
|
||||
[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();
|
||||
[5000, 20000, 60000].forEach((delay) => {
|
||||
setTimeout(() => _refreshNotificationsAsync(), delay);
|
||||
});
|
||||
}
|
||||
|
||||
export async function downloadWorkOrderPdf(workOrderId) {
|
||||
@@ -1090,13 +1030,13 @@ export async function downloadMonthlyCostsReport(year, month) {
|
||||
export async function downloadMonthlyServiceTasksArchive(year, month) {
|
||||
try {
|
||||
const payload = await api.post('fleet/reports/monthly-service-tasks-archive-request/', { year, month });
|
||||
await _refreshNotificationsAsync();
|
||||
if (payload?.status === 'ready' && payload?.download_url) {
|
||||
showToast('ZIP arhiva servisnih taskova je spremna. Preuzmite je kroz notifikaciju.', 'success');
|
||||
_refreshNotificationsAsync();
|
||||
return payload;
|
||||
}
|
||||
showToast('ZIP arhiva servisnih taskova se generira u pozadini. Preuzimanje je dostupno kroz notifikaciju.', 'info');
|
||||
_scheduleArchiveNotificationPolling(payload?.generated_archive_id || null);
|
||||
_scheduleArchiveNotificationPolling();
|
||||
return payload;
|
||||
} catch (err) {
|
||||
showToast(err?.message || 'Pokretanje generiranja ZIP arhive servisnih taskova nije uspjelo.', 'error');
|
||||
@@ -1107,13 +1047,13 @@ export async function downloadMonthlyServiceTasksArchive(year, month) {
|
||||
export async function downloadMonthlyWorkOrdersArchive(year, month) {
|
||||
try {
|
||||
const payload = await api.post('fleet/reports/monthly-work-orders-archive-request/', { year, month });
|
||||
await _refreshNotificationsAsync();
|
||||
if (payload?.status === 'ready' && payload?.download_url) {
|
||||
showToast('ZIP arhiva putnih naloga je spremna. Preuzmite je kroz notifikaciju.', 'success');
|
||||
_refreshNotificationsAsync();
|
||||
return payload;
|
||||
}
|
||||
showToast('ZIP arhiva putnih naloga se generira u pozadini. Preuzimanje je dostupno kroz notifikaciju.', 'info');
|
||||
_scheduleArchiveNotificationPolling(payload?.generated_archive_id || null);
|
||||
_scheduleArchiveNotificationPolling();
|
||||
return payload;
|
||||
} catch (err) {
|
||||
showToast(err?.message || 'Pokretanje generiranja ZIP arhive putnih naloga nije uspjelo.', 'error');
|
||||
|
||||
Reference in New Issue
Block a user