Add print badges, pagination, route splitting, JWT auth fixes, and list page alignment
- Fix equipment badge barcode not rendering (loading race condition) - Fix printer QR code not rendering on initial load (same race condition) - Add model image to equipment badge via imageurl from Model table - Fix white-on-white machine number text on badge, tighten barcode spacing - Add PaginationBar component used across all list pages - Split monolithic router into per-plugin route modules - Fix 25 GET API endpoints returning 401 (jwt_required -> optional=True) - Align list page columns across Equipment, PCs, and Network pages - Add print views: EquipmentBadge, PrinterQRSingle, PrinterQRBatch, USBLabelBatch - Add PC Relationships report, migration docs, and CLAUDE.md project guide - Various plugin model, API, and frontend refinements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,7 +22,7 @@ assets_bp = Blueprint('assets', __name__)
|
||||
# =============================================================================
|
||||
|
||||
@assets_bp.route('/types', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def list_asset_types():
|
||||
"""List all asset types."""
|
||||
page, per_page = get_pagination_params(request)
|
||||
@@ -41,7 +41,7 @@ def list_asset_types():
|
||||
|
||||
|
||||
@assets_bp.route('/types/<int:type_id>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def get_asset_type(type_id: int):
|
||||
"""Get a single asset type."""
|
||||
t = AssetType.query.get(type_id)
|
||||
@@ -91,7 +91,7 @@ def create_asset_type():
|
||||
# =============================================================================
|
||||
|
||||
@assets_bp.route('/statuses', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def list_asset_statuses():
|
||||
"""List all asset statuses."""
|
||||
page, per_page = get_pagination_params(request)
|
||||
@@ -110,7 +110,7 @@ def list_asset_statuses():
|
||||
|
||||
|
||||
@assets_bp.route('/statuses/<int:status_id>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def get_asset_status(status_id: int):
|
||||
"""Get a single asset status."""
|
||||
s = AssetStatus.query.get(status_id)
|
||||
@@ -158,7 +158,7 @@ def create_asset_status():
|
||||
# =============================================================================
|
||||
|
||||
@assets_bp.route('', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def list_assets():
|
||||
"""
|
||||
List all assets with filtering and pagination.
|
||||
@@ -240,7 +240,7 @@ def list_assets():
|
||||
|
||||
|
||||
@assets_bp.route('/<int:asset_id>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def get_asset(asset_id: int):
|
||||
"""
|
||||
Get a single asset with full details.
|
||||
@@ -370,7 +370,7 @@ def delete_asset(asset_id: int):
|
||||
|
||||
|
||||
@assets_bp.route('/lookup/<assetnumber>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def lookup_asset_by_number(assetnumber: str):
|
||||
"""
|
||||
Look up an asset by its asset number.
|
||||
@@ -798,7 +798,7 @@ def get_assets_map():
|
||||
|
||||
|
||||
@assets_bp.route('/<int:asset_id>/communications', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def get_asset_communications(asset_id: int):
|
||||
"""Get all communications for an asset."""
|
||||
from shopdb.core.models import Communication
|
||||
|
||||
@@ -276,7 +276,7 @@ def pc_heartbeat():
|
||||
|
||||
return success_response({
|
||||
'updated': updated,
|
||||
'not_found': not_found,
|
||||
'notfound': not_found,
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}, message=f'{updated} PC(s) heartbeat recorded')
|
||||
|
||||
@@ -351,7 +351,7 @@ def bulk_update():
|
||||
|
||||
return success_response({
|
||||
'updated': updated,
|
||||
'not_found': not_found,
|
||||
'notfound': not_found,
|
||||
'errors': errors,
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}, message=f'{updated} PC(s) updated')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Dashboard API endpoints."""
|
||||
|
||||
from flask import Blueprint
|
||||
from flask import Blueprint, current_app
|
||||
from flask_jwt_extended import jwt_required
|
||||
|
||||
from shopdb.extensions import db
|
||||
@@ -60,10 +60,10 @@ def get_dashboard():
|
||||
'counts': {
|
||||
'equipment': equipment_count,
|
||||
'pcs': pc_count,
|
||||
'network_devices': network_count,
|
||||
'networkdevices': network_count,
|
||||
'total': equipment_count + pc_count + network_count
|
||||
},
|
||||
'by_status': status_dict,
|
||||
'bystatus': status_dict,
|
||||
'recent': [
|
||||
{
|
||||
'machineid': m.machineid,
|
||||
@@ -93,13 +93,51 @@ def get_stats():
|
||||
).all()
|
||||
|
||||
return success_response({
|
||||
'by_type': [
|
||||
'bytype': [
|
||||
{'type': t, 'category': c, 'count': count}
|
||||
for t, c, count in type_counts
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
@dashboard_bp.route('/navigation', methods=['GET'])
|
||||
def get_navigation():
|
||||
"""Get navigation items from all loaded plugins."""
|
||||
pm = current_app.extensions.get('plugin_manager')
|
||||
if not pm:
|
||||
return success_response([])
|
||||
|
||||
all_items = []
|
||||
|
||||
# Core navigation items (always present)
|
||||
all_items.extend([
|
||||
{'name': 'Dashboard', 'icon': 'layout-dashboard', 'route': '/', 'position': 0},
|
||||
{'name': 'Map', 'icon': 'map', 'route': '/map', 'position': 4},
|
||||
])
|
||||
|
||||
# Collect navigation items from all plugins
|
||||
for name, plugin in pm.get_all_plugins().items():
|
||||
try:
|
||||
items = plugin.get_navigation_items()
|
||||
for item in items:
|
||||
item['plugin'] = name
|
||||
all_items.extend(items)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Add core information section items
|
||||
all_items.extend([
|
||||
{'name': 'Applications', 'icon': 'app-window', 'route': '/applications', 'position': 30, 'section': 'information'},
|
||||
{'name': 'Knowledge Base', 'icon': 'book-open', 'route': '/knowledgebase', 'position': 35, 'section': 'information'},
|
||||
{'name': 'Reports', 'icon': 'bar-chart-3', 'route': '/reports', 'position': 40, 'section': 'information'},
|
||||
])
|
||||
|
||||
# Sort by position
|
||||
all_items.sort(key=lambda x: x.get('position', 99))
|
||||
|
||||
return success_response(all_items)
|
||||
|
||||
|
||||
@dashboard_bp.route('/health', methods=['GET'])
|
||||
def health_check():
|
||||
"""Health check endpoint (no auth required)."""
|
||||
|
||||
@@ -17,7 +17,7 @@ locations_bp = Blueprint('locations', __name__)
|
||||
|
||||
|
||||
@locations_bp.route('', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def list_locations():
|
||||
"""List all locations."""
|
||||
page, per_page = get_pagination_params(request)
|
||||
@@ -44,7 +44,7 @@ def list_locations():
|
||||
|
||||
|
||||
@locations_bp.route('/<int:location_id>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def get_location(location_id: int):
|
||||
"""Get a single location."""
|
||||
loc = Location.query.get(location_id)
|
||||
|
||||
@@ -337,7 +337,7 @@ def delete_machine(machine_id: int):
|
||||
|
||||
|
||||
@machines_bp.route('/<int:machine_id>/communications', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
@add_deprecation_headers
|
||||
def get_machine_communications(machine_id: int):
|
||||
"""Get all communications for a machine."""
|
||||
|
||||
@@ -51,7 +51,7 @@ def list_models():
|
||||
|
||||
|
||||
@models_bp.route('/<int:model_id>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def get_model(model_id: int):
|
||||
"""Get a single model."""
|
||||
m = Model.query.get(model_id)
|
||||
|
||||
@@ -17,7 +17,7 @@ operatingsystems_bp = Blueprint('operatingsystems', __name__)
|
||||
|
||||
|
||||
@operatingsystems_bp.route('', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def list_operatingsystems():
|
||||
"""List all operating systems."""
|
||||
page, per_page = get_pagination_params(request)
|
||||
@@ -39,7 +39,7 @@ def list_operatingsystems():
|
||||
|
||||
|
||||
@operatingsystems_bp.route('/<int:os_id>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def get_operatingsystem(os_id: int):
|
||||
"""Get a single operating system."""
|
||||
os = OperatingSystem.query.get(os_id)
|
||||
|
||||
@@ -17,7 +17,7 @@ pctypes_bp = Blueprint('pctypes', __name__)
|
||||
|
||||
|
||||
@pctypes_bp.route('', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def list_pctypes():
|
||||
"""List all PC types."""
|
||||
page, per_page = get_pagination_params(request)
|
||||
@@ -39,7 +39,7 @@ def list_pctypes():
|
||||
|
||||
|
||||
@pctypes_bp.route('/<int:type_id>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def get_pctype(type_id: int):
|
||||
"""Get a single PC type."""
|
||||
pt = PCType.query.get(type_id)
|
||||
|
||||
@@ -31,7 +31,7 @@ def generate_csv(data: list, columns: list) -> str:
|
||||
# =============================================================================
|
||||
|
||||
@reports_bp.route('/equipment-by-type', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def equipment_by_type():
|
||||
"""
|
||||
Report: Equipment count grouped by equipment type.
|
||||
@@ -95,7 +95,7 @@ def equipment_by_type():
|
||||
# =============================================================================
|
||||
|
||||
@reports_bp.route('/assets-by-status', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def assets_by_status():
|
||||
"""
|
||||
Report: Asset count grouped by status.
|
||||
@@ -154,7 +154,7 @@ def assets_by_status():
|
||||
# =============================================================================
|
||||
|
||||
@reports_bp.route('/kb-popularity', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def kb_popularity():
|
||||
"""
|
||||
Report: Most clicked knowledge base articles.
|
||||
@@ -202,7 +202,7 @@ def kb_popularity():
|
||||
# =============================================================================
|
||||
|
||||
@reports_bp.route('/warranty-status', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def warranty_status():
|
||||
"""
|
||||
Report: Assets by warranty expiration status.
|
||||
@@ -305,7 +305,7 @@ def warranty_status():
|
||||
# =============================================================================
|
||||
|
||||
@reports_bp.route('/software-compliance', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def software_compliance():
|
||||
"""
|
||||
Report: Required applications vs installed (per PC).
|
||||
@@ -409,7 +409,7 @@ def software_compliance():
|
||||
# =============================================================================
|
||||
|
||||
@reports_bp.route('/asset-inventory', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def asset_inventory():
|
||||
"""
|
||||
Report: Complete asset inventory summary.
|
||||
@@ -518,8 +518,68 @@ def asset_inventory():
|
||||
# Available Reports List
|
||||
# =============================================================================
|
||||
|
||||
# =============================================================================
|
||||
# Report: PC-Machine Relationships
|
||||
# =============================================================================
|
||||
|
||||
@reports_bp.route('/pc-relationships', methods=['GET'])
|
||||
@jwt_required(optional=True)
|
||||
def pc_relationships():
|
||||
"""
|
||||
Report: PCs with relationships to shop floor machines.
|
||||
|
||||
Returns machine number, vendor, model, PC hostname, and PC IP address
|
||||
for all active PC-equipment relationships.
|
||||
|
||||
Query parameters:
|
||||
- format: 'json' (default) or 'csv'
|
||||
"""
|
||||
sql = db.text("""
|
||||
SELECT
|
||||
eq.machinenumber AS machine_number,
|
||||
v.vendor AS vendor,
|
||||
mo.modelnumber AS model,
|
||||
pc.machinenumber AS hostname,
|
||||
c.ipaddress AS ip
|
||||
FROM machinerelationships mr
|
||||
JOIN machines eq ON mr.parentmachineid = eq.machineid
|
||||
JOIN machines pc ON mr.childmachineid = pc.machineid
|
||||
LEFT JOIN communications c ON pc.machineid = c.machineid AND c.isprimary = 1 AND c.comtypeid = 1
|
||||
LEFT JOIN models mo ON eq.modelnumberid = mo.modelnumberid
|
||||
LEFT JOIN vendors v ON mo.vendorid = v.vendorid
|
||||
WHERE mr.isactive = 1
|
||||
AND pc.pctypeid IS NOT NULL
|
||||
AND eq.machinenumber IS NOT NULL AND eq.machinenumber != ''
|
||||
ORDER BY eq.machinenumber
|
||||
""")
|
||||
|
||||
results = db.session.execute(sql).fetchall()
|
||||
data = [{
|
||||
'machine_number': r.machine_number,
|
||||
'vendor': r.vendor or '',
|
||||
'model': r.model or '',
|
||||
'hostname': r.hostname or '',
|
||||
'ip': r.ip or ''
|
||||
} for r in results]
|
||||
|
||||
if request.args.get('format') == 'csv':
|
||||
csv_data = generate_csv(data, ['machine_number', 'vendor', 'model', 'hostname', 'ip'])
|
||||
return Response(
|
||||
csv_data,
|
||||
mimetype='text/csv',
|
||||
headers={'Content-Disposition': 'attachment; filename=pc_relationships.csv'}
|
||||
)
|
||||
|
||||
return success_response({
|
||||
'report': 'pc_relationships',
|
||||
'generated': datetime.utcnow().isoformat(),
|
||||
'data': data,
|
||||
'total': len(data)
|
||||
})
|
||||
|
||||
|
||||
@reports_bp.route('', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def list_reports():
|
||||
"""List all available reports."""
|
||||
reports = [
|
||||
@@ -564,6 +624,13 @@ def list_reports():
|
||||
'description': 'Complete asset inventory breakdown',
|
||||
'endpoint': '/api/reports/asset-inventory',
|
||||
'category': 'inventory'
|
||||
},
|
||||
{
|
||||
'id': 'pc-relationships',
|
||||
'name': 'PC-Machine Relationships',
|
||||
'description': 'PCs with relationships to shop floor machines',
|
||||
'endpoint': '/api/reports/pc-relationships',
|
||||
'category': 'inventory'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ vendors_bp = Blueprint('vendors', __name__)
|
||||
|
||||
|
||||
@vendors_bp.route('', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def list_vendors():
|
||||
"""List all vendors."""
|
||||
page, per_page = get_pagination_params(request)
|
||||
@@ -39,7 +39,7 @@ def list_vendors():
|
||||
|
||||
|
||||
@vendors_bp.route('/<int:vendor_id>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_required(optional=True)
|
||||
def get_vendor(vendor_id: int):
|
||||
"""Get a single vendor."""
|
||||
v = Vendor.query.get(vendor_id)
|
||||
|
||||
@@ -20,12 +20,12 @@ class AssetType(BaseModel):
|
||||
nullable=False,
|
||||
comment='Category name: equipment, computer, network_device, printer'
|
||||
)
|
||||
plugin_name = db.Column(
|
||||
pluginname = db.Column(
|
||||
db.String(100),
|
||||
nullable=True,
|
||||
comment='Plugin that owns this type'
|
||||
)
|
||||
table_name = db.Column(
|
||||
tablename = db.Column(
|
||||
db.String(100),
|
||||
nullable=True,
|
||||
comment='Extension table name for this type'
|
||||
@@ -174,23 +174,23 @@ class Asset(BaseModel, SoftDeleteMixin, AuditMixin):
|
||||
|
||||
if hasattr(self, 'incoming_relationships'):
|
||||
for rel in self.incoming_relationships:
|
||||
if rel.source_asset and rel.isactive:
|
||||
related_assets.append(rel.source_asset)
|
||||
if rel.sourceasset and rel.isactive:
|
||||
related_assets.append(rel.sourceasset)
|
||||
|
||||
if hasattr(self, 'outgoing_relationships'):
|
||||
for rel in self.outgoing_relationships:
|
||||
if rel.target_asset and rel.isactive:
|
||||
related_assets.append(rel.target_asset)
|
||||
if rel.targetasset and rel.isactive:
|
||||
related_assets.append(rel.targetasset)
|
||||
|
||||
# Find first related asset with location data
|
||||
for related in related_assets:
|
||||
if related.locationid is not None or (related.mapleft is not None and related.maptop is not None):
|
||||
return {
|
||||
'locationid': related.locationid,
|
||||
'location_name': related.location.locationname if related.location else None,
|
||||
'locationname': related.location.locationname if related.location else None,
|
||||
'mapleft': related.mapleft,
|
||||
'maptop': related.maptop,
|
||||
'inherited_from': related.assetnumber
|
||||
'inheritedfrom': related.assetnumber
|
||||
}
|
||||
|
||||
return None
|
||||
@@ -207,33 +207,33 @@ class Asset(BaseModel, SoftDeleteMixin, AuditMixin):
|
||||
|
||||
# Add related object names for convenience
|
||||
if self.assettype:
|
||||
result['assettype_name'] = self.assettype.assettype
|
||||
result['assettypename'] = self.assettype.assettype
|
||||
if self.status:
|
||||
result['status_name'] = self.status.status
|
||||
result['statusname'] = self.status.status
|
||||
if self.location:
|
||||
result['location_name'] = self.location.locationname
|
||||
result['locationname'] = self.location.locationname
|
||||
if self.businessunit:
|
||||
result['businessunit_name'] = self.businessunit.businessunit
|
||||
result['businessunitname'] = self.businessunit.businessunit
|
||||
|
||||
# Add plugin-specific ID for navigation purposes
|
||||
if hasattr(self, 'equipment') and self.equipment:
|
||||
result['plugin_id'] = self.equipment.equipmentid
|
||||
result['pluginid'] = self.equipment.equipmentid
|
||||
elif hasattr(self, 'computer') and self.computer:
|
||||
result['plugin_id'] = self.computer.computerid
|
||||
result['pluginid'] = self.computer.computerid
|
||||
elif hasattr(self, 'network_device') and self.network_device:
|
||||
result['plugin_id'] = self.network_device.networkdeviceid
|
||||
result['pluginid'] = self.network_device.networkdeviceid
|
||||
elif hasattr(self, 'printer') and self.printer:
|
||||
result['plugin_id'] = self.printer.printerid
|
||||
result['pluginid'] = self.printer.printerid
|
||||
|
||||
# Include inherited location if this asset has no location data
|
||||
if include_inherited_location:
|
||||
inherited = self.get_inherited_location()
|
||||
if inherited:
|
||||
result['inherited_location'] = inherited
|
||||
result['inheritedlocation'] = inherited
|
||||
# Also set the location fields if they're missing
|
||||
if result.get('locationid') is None:
|
||||
result['locationid'] = inherited['locationid']
|
||||
result['location_name'] = inherited['location_name']
|
||||
result['locationname'] = inherited['locationname']
|
||||
if result.get('mapleft') is None:
|
||||
result['mapleft'] = inherited['mapleft']
|
||||
if result.get('maptop') is None:
|
||||
@@ -243,7 +243,7 @@ class Asset(BaseModel, SoftDeleteMixin, AuditMixin):
|
||||
if include_type_data:
|
||||
ext_data = self._get_extension_data()
|
||||
if ext_data:
|
||||
result['type_data'] = ext_data
|
||||
result['typedata'] = ext_data
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -34,12 +34,12 @@ class AssetRelationship(BaseModel):
|
||||
|
||||
relationshipid = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
source_assetid = db.Column(
|
||||
sourceassetid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('assets.assetid'),
|
||||
nullable=False
|
||||
)
|
||||
target_assetid = db.Column(
|
||||
targetassetid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('assets.assetid'),
|
||||
nullable=False
|
||||
@@ -53,31 +53,31 @@ class AssetRelationship(BaseModel):
|
||||
notes = db.Column(db.Text)
|
||||
|
||||
# Relationships
|
||||
source_asset = db.relationship(
|
||||
sourceasset = db.relationship(
|
||||
'Asset',
|
||||
foreign_keys=[source_assetid],
|
||||
foreign_keys=[sourceassetid],
|
||||
backref='outgoing_relationships'
|
||||
)
|
||||
target_asset = db.relationship(
|
||||
targetasset = db.relationship(
|
||||
'Asset',
|
||||
foreign_keys=[target_assetid],
|
||||
foreign_keys=[targetassetid],
|
||||
backref='incoming_relationships'
|
||||
)
|
||||
relationship_type = db.relationship('RelationshipType', backref='asset_relationships')
|
||||
relationshiptype = db.relationship('RelationshipType', backref='asset_relationships')
|
||||
|
||||
__table_args__ = (
|
||||
db.UniqueConstraint(
|
||||
'source_assetid',
|
||||
'target_assetid',
|
||||
'sourceassetid',
|
||||
'targetassetid',
|
||||
'relationshiptypeid',
|
||||
name='uq_asset_relationship'
|
||||
),
|
||||
db.Index('idx_asset_rel_source', 'source_assetid'),
|
||||
db.Index('idx_asset_rel_target', 'target_assetid'),
|
||||
db.Index('idx_asset_rel_source', 'sourceassetid'),
|
||||
db.Index('idx_asset_rel_target', 'targetassetid'),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<AssetRelationship {self.source_assetid} -> {self.target_assetid}>"
|
||||
return f"<AssetRelationship {self.sourceassetid} -> {self.targetassetid}>"
|
||||
|
||||
|
||||
class MachineRelationship(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user