Add USB, Notifications, Network plugins and reusable EmployeeSearch component
New Plugins: - USB plugin: Device checkout/checkin with employee lookup, checkout history - Notifications plugin: Announcements with types, scheduling, shopfloor display - Network plugin: Network device management with subnets and VLANs - Equipment and Computers plugins: Asset type separation Frontend: - EmployeeSearch component: Reusable employee lookup with autocomplete - USB views: List, detail, checkout/checkin modals - Notifications views: List, form with recognition mode - Network views: Device list, detail, form - Calendar view with FullCalendar integration - Shopfloor and TV dashboard views - Reports index page - Map editor for asset positioning - Light/dark mode fixes for map tooltips Backend: - Employee search API with external lookup service - Collector API for PowerShell data collection - Reports API endpoints - Slides API for TV dashboard - Fixed AppVersion model (removed BaseModel inheritance) - Added checkout_name column to usbcheckouts table Styling: - Unified detail page styles - Improved pagination (page numbers instead of prev/next) - Dark/light mode theme improvements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
9
plugins/computers/models/__init__.py
Normal file
9
plugins/computers/models/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
"""Computers plugin models."""
|
||||
|
||||
from .computer import Computer, ComputerType, ComputerInstalledApp
|
||||
|
||||
__all__ = [
|
||||
'Computer',
|
||||
'ComputerType',
|
||||
'ComputerInstalledApp',
|
||||
]
|
||||
184
plugins/computers/models/computer.py
Normal file
184
plugins/computers/models/computer.py
Normal file
@@ -0,0 +1,184 @@
|
||||
"""Computer plugin models."""
|
||||
|
||||
from shopdb.extensions import db
|
||||
from shopdb.core.models.base import BaseModel
|
||||
|
||||
|
||||
class ComputerType(BaseModel):
|
||||
"""
|
||||
Computer type classification.
|
||||
|
||||
Examples: Shopfloor PC, Engineer Workstation, CMM PC, Server, etc.
|
||||
"""
|
||||
__tablename__ = 'computertypes'
|
||||
|
||||
computertypeid = db.Column(db.Integer, primary_key=True)
|
||||
computertype = db.Column(db.String(100), unique=True, nullable=False)
|
||||
description = db.Column(db.Text)
|
||||
icon = db.Column(db.String(50), comment='Icon name for UI')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<ComputerType {self.computertype}>"
|
||||
|
||||
|
||||
class Computer(BaseModel):
|
||||
"""
|
||||
Computer-specific extension data.
|
||||
|
||||
Links to core Asset table via assetid.
|
||||
Stores computer-specific fields like hostname, OS, logged in user, etc.
|
||||
"""
|
||||
__tablename__ = 'computers'
|
||||
|
||||
computerid = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
# Link to core asset
|
||||
assetid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('assets.assetid', ondelete='CASCADE'),
|
||||
unique=True,
|
||||
nullable=False,
|
||||
index=True
|
||||
)
|
||||
|
||||
# Computer classification
|
||||
computertypeid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('computertypes.computertypeid'),
|
||||
nullable=True
|
||||
)
|
||||
|
||||
# Network identity
|
||||
hostname = db.Column(
|
||||
db.String(100),
|
||||
index=True,
|
||||
comment='Network hostname'
|
||||
)
|
||||
|
||||
# Operating system
|
||||
osid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('operatingsystems.osid'),
|
||||
nullable=True
|
||||
)
|
||||
|
||||
# Status tracking
|
||||
loggedinuser = db.Column(db.String(100), nullable=True)
|
||||
lastreporteddate = db.Column(db.DateTime, nullable=True)
|
||||
lastboottime = db.Column(db.DateTime, nullable=True)
|
||||
|
||||
# Remote access features
|
||||
isvnc = db.Column(
|
||||
db.Boolean,
|
||||
default=False,
|
||||
comment='VNC remote access enabled'
|
||||
)
|
||||
iswinrm = db.Column(
|
||||
db.Boolean,
|
||||
default=False,
|
||||
comment='WinRM enabled'
|
||||
)
|
||||
|
||||
# Classification flags
|
||||
isshopfloor = db.Column(
|
||||
db.Boolean,
|
||||
default=False,
|
||||
comment='Shopfloor PC (vs office PC)'
|
||||
)
|
||||
|
||||
# Relationships
|
||||
asset = db.relationship(
|
||||
'Asset',
|
||||
backref=db.backref('computer', uselist=False, lazy='joined')
|
||||
)
|
||||
computertype = db.relationship('ComputerType', backref='computers')
|
||||
operatingsystem = db.relationship('OperatingSystem', backref='computers')
|
||||
|
||||
# Installed applications (one-to-many)
|
||||
installedapps = db.relationship(
|
||||
'ComputerInstalledApp',
|
||||
back_populates='computer',
|
||||
cascade='all, delete-orphan',
|
||||
lazy='dynamic'
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
db.Index('idx_computer_type', 'computertypeid'),
|
||||
db.Index('idx_computer_hostname', 'hostname'),
|
||||
db.Index('idx_computer_os', 'osid'),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Computer {self.hostname or self.assetid}>"
|
||||
|
||||
def to_dict(self):
|
||||
"""Convert to dictionary with related names."""
|
||||
result = super().to_dict()
|
||||
|
||||
# Add related object names
|
||||
if self.computertype:
|
||||
result['computertype_name'] = self.computertype.computertype
|
||||
if self.operatingsystem:
|
||||
result['os_name'] = self.operatingsystem.osname
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class ComputerInstalledApp(db.Model):
|
||||
"""
|
||||
Junction table for applications installed on computers.
|
||||
|
||||
Tracks which applications are installed on which computers,
|
||||
including version information.
|
||||
"""
|
||||
__tablename__ = 'computerinstalledapps'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
computerid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('computers.computerid', ondelete='CASCADE'),
|
||||
nullable=False
|
||||
)
|
||||
appid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('applications.appid'),
|
||||
nullable=False
|
||||
)
|
||||
appversionid = db.Column(
|
||||
db.Integer,
|
||||
db.ForeignKey('appversions.appversionid'),
|
||||
nullable=True
|
||||
)
|
||||
isactive = db.Column(db.Boolean, default=True, nullable=False)
|
||||
installeddate = db.Column(db.DateTime, default=db.func.now())
|
||||
|
||||
# Relationships
|
||||
computer = db.relationship('Computer', back_populates='installedapps')
|
||||
application = db.relationship('Application')
|
||||
appversion = db.relationship('AppVersion')
|
||||
|
||||
__table_args__ = (
|
||||
db.UniqueConstraint('computerid', 'appid', name='uq_computer_app'),
|
||||
db.Index('idx_compapp_computer', 'computerid'),
|
||||
db.Index('idx_compapp_app', 'appid'),
|
||||
)
|
||||
|
||||
def to_dict(self):
|
||||
"""Convert to dictionary."""
|
||||
return {
|
||||
'id': self.id,
|
||||
'computerid': self.computerid,
|
||||
'appid': self.appid,
|
||||
'appversionid': self.appversionid,
|
||||
'isactive': self.isactive,
|
||||
'installeddate': self.installeddate.isoformat() + 'Z' if self.installeddate else None,
|
||||
'application': {
|
||||
'appid': self.application.appid,
|
||||
'appname': self.application.appname,
|
||||
'appdescription': self.application.appdescription,
|
||||
} if self.application else None,
|
||||
'version': self.appversion.version if self.appversion else None
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return f"<ComputerInstalledApp computer={self.computerid} app={self.appid}>"
|
||||
Reference in New Issue
Block a user