Add asset checkout, quantity/uniqueness, contacts, and QR labels
Checkout:
- assets.AssignUser + POST /app/assets/{id}/checkout assign/unassign an
asset's user independent of the full edit form. New shared
#checkoutModal, wired from a "Check Out..." context-menu action, backed
by GET /app/assets/{id} and GET /app/users/options JSON endpoints.
Quantity / uniqueness:
- Item types gain an IsUnique flag (checked by default, matching prior
behavior). Assets gain a Quantity column, fixed at 1 for unique types
and adjustable via +/- steppers (POST /app/assets/{id}/quantity) for
non-unique ones. Flipping a type back to unique clamps existing assets'
quantity back to 1. CSV import/export gained a Quantity column.
Migration 0003_quantity.sql.
Contacts:
- New models.RoleContact: an assignable person who cannot sign in
(User.CanLogin). Migration 0004_contacts.sql rebuilds the users table
(SQLite can't alter a CHECK constraint in place) to allow the role.
Users form/list updated; contact creation auto-generates an unusable
password since the login path is blocked by role regardless.
QR asset tags and printable labels:
- Each asset's QR code (via github.com/skip2/go-qrcode, pure Go) encodes
an absolute /scan/<tag> URL; GET /scan/{tag} resolves it and redirects
into /inventory?asset=<id>, which app.js picks up on load to
auto-select that asset - works from a phone camera or a USB
scanner-as-keyboard-wedge pointed at the address bar.
- GET /labels renders a print-ready sheet (right-click an asset for one
label, a folder for every asset in it) with a template switcher between
Avery 5160 (verified dimensions) and 61526 asset tag labels (best-effort
layout, flagged as such on the page).
Also refreshed README to reflect the right-click-first tree UX and all of
the above.
This commit is contained in:
@@ -243,6 +243,7 @@
|
||||
items.push({ label: 'Import CSV…', icon: 'bi-upload', action: function () { openImportModal(id); } });
|
||||
}
|
||||
items.push({ label: 'Export CSV', icon: 'bi-download', action: function () { window.location = '/export/assets.csv?folder_id=' + id + '&recursive=1'; } });
|
||||
items.push({ label: 'Print Labels…', icon: 'bi-qr-code', action: function () { window.open('/labels?folder_id=' + id + '&recursive=1', '_blank'); } });
|
||||
if (isAdmin) {
|
||||
items.push({ divider: true });
|
||||
items.push({ label: 'Delete', icon: 'bi-trash', danger: true, action: function () { startDeleteFolder(id); } });
|
||||
@@ -252,8 +253,10 @@
|
||||
|
||||
function assetMenuItems(id) {
|
||||
var items = [{ label: 'Open', icon: 'bi-box-arrow-up-right', action: function () { navigateAndSelect('asset', id); } }];
|
||||
items.push({ label: 'Print Label', icon: 'bi-qr-code', action: function () { window.open('/labels?asset_id=' + id, '_blank'); } });
|
||||
if (isAdmin) {
|
||||
items.push({ label: 'Edit', icon: 'bi-pencil', action: function () { loadAssetEditForm(id); } });
|
||||
items.push({ label: 'Check Out…', icon: 'bi-person-check', action: function () { openCheckoutModal(id); } });
|
||||
items.push({ label: 'Duplicate', icon: 'bi-files', action: function () { duplicateAsset(id); } });
|
||||
items.push({ label: 'Move to…', icon: 'bi-arrows-move', action: function () { openMoveAssetModal(id); } });
|
||||
items.push({ divider: true });
|
||||
@@ -615,6 +618,55 @@
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Check out / check in modal
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
var checkoutModalEl = document.getElementById('checkoutModal');
|
||||
var checkoutModal = (checkoutModalEl && window.bootstrap) ? new bootstrap.Modal(checkoutModalEl) : null;
|
||||
|
||||
async function openCheckoutModal(id) {
|
||||
if (!checkoutModal) return;
|
||||
checkoutModalEl.dataset.assetId = id;
|
||||
var sel = document.getElementById('checkoutUserSelect');
|
||||
var currentText = document.getElementById('checkoutCurrent');
|
||||
sel.innerHTML = '<option value="">Unassigned (check in)</option>';
|
||||
currentText.textContent = 'Loading…';
|
||||
try {
|
||||
var asset = await apiFetch('/app/assets/' + id);
|
||||
var users = await apiFetch('/app/users/options');
|
||||
(users || []).forEach(function (u) {
|
||||
var opt = document.createElement('option');
|
||||
opt.value = u.id;
|
||||
opt.textContent = u.username;
|
||||
if (asset.AssignedUserID === u.id) opt.selected = true;
|
||||
sel.appendChild(opt);
|
||||
});
|
||||
currentText.textContent = asset.AssignedUsername
|
||||
? 'Currently checked out to ' + asset.AssignedUsername + '.'
|
||||
: 'Not currently checked out to anyone.';
|
||||
document.getElementById('checkoutModalTitle').textContent = 'Check Out "' + asset.Name + '"';
|
||||
} catch (err) {
|
||||
currentText.textContent = '';
|
||||
}
|
||||
checkoutModal.show();
|
||||
}
|
||||
|
||||
var confirmCheckoutBtn = document.getElementById('confirmCheckoutBtn');
|
||||
if (confirmCheckoutBtn) {
|
||||
confirmCheckoutBtn.addEventListener('click', async function () {
|
||||
var id = checkoutModalEl.dataset.assetId;
|
||||
var val = document.getElementById('checkoutUserSelect').value;
|
||||
try {
|
||||
await apiFetch('/app/assets/' + id + '/checkout', { method: 'POST', json: { assigned_user_id: val ? Number(val) : null } });
|
||||
checkoutModal.hide();
|
||||
await navigateAndSelect('asset', id);
|
||||
} catch (err) {
|
||||
alert('Checkout failed: ' + err.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Asset form (create / edit) - shown in a modal
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -701,6 +753,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
// adjustAssetQuantity handles the +/- steppers shown next to non-unique
|
||||
// assets (in the asset detail panel and folder asset tables), updating
|
||||
// the displayed number in place without reloading the whole panel.
|
||||
async function adjustAssetQuantity(stepBtn) {
|
||||
var wrapper = stepBtn.closest('[data-quantity-stepper]');
|
||||
if (!wrapper) return;
|
||||
var id = wrapper.dataset.assetId;
|
||||
var valueEl = wrapper.querySelector('[data-quantity-value]');
|
||||
var delta = parseInt(stepBtn.dataset.step, 10) || 0;
|
||||
try {
|
||||
var res = await apiFetch('/app/assets/' + id + '/quantity', { method: 'POST', json: { delta: delta } });
|
||||
if (valueEl) valueEl.textContent = res.quantity;
|
||||
} catch (err) {
|
||||
alert('Could not update quantity: ' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Folder listing filters / pagination
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -879,6 +948,9 @@
|
||||
|
||||
if (mainPanel) {
|
||||
mainPanel.addEventListener('click', function (e) {
|
||||
var stepBtn = e.target.closest('[data-action="panel-quantity-step"], [data-action="table-quantity-step"]');
|
||||
if (stepBtn) { e.preventDefault(); e.stopPropagation(); adjustAssetQuantity(stepBtn); return; }
|
||||
|
||||
var folderLink = e.target.closest('.folder-link');
|
||||
if (folderLink) { e.preventDefault(); navigateAndSelect('folder', folderLink.dataset.id); return; }
|
||||
|
||||
@@ -936,6 +1008,14 @@
|
||||
submitAssetForm(e.target);
|
||||
}
|
||||
});
|
||||
assetModalEl.addEventListener('click', function (e) {
|
||||
var stepBtn = e.target.closest('[data-action="quantity-step"]');
|
||||
if (!stepBtn) return;
|
||||
var input = document.getElementById('assetFormQuantity');
|
||||
if (!input) return;
|
||||
var next = (parseInt(input.value, 10) || 0) + parseInt(stepBtn.dataset.step, 10);
|
||||
input.value = Math.max(0, next);
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -971,4 +1051,25 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// QR/barcode scan landing: /scan/<tag> redirects here with ?asset=<id>
|
||||
// (or ?scan_error=<tag> if the tag didn't match anything).
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
var inventoryShell = document.querySelector('.inventory-shell');
|
||||
if (inventoryShell) {
|
||||
var autoOpenId = inventoryShell.dataset.autoOpenAsset;
|
||||
if (autoOpenId) {
|
||||
navigateAndSelect('asset', autoOpenId);
|
||||
}
|
||||
var scanError = inventoryShell.dataset.scanError;
|
||||
if (scanError) {
|
||||
alert('No asset found for scanned tag "' + scanError + '".');
|
||||
}
|
||||
if (autoOpenId || scanError) {
|
||||
// Drop the query string so a page refresh doesn't re-trigger this.
|
||||
window.history.replaceState({}, '', '/inventory');
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user