- Docker infrastructure (Dockerfile, docker-compose.yml, genieacs-sim) - AdonisJS v7 app with Inertia.js + Vue 3 - MongoDB integration - CWMP/TR-069 state machine engine - Configuration engine with compliance tracking - Branding: ADAM ACS (favicon, navbar, locales) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
133 lines
4.8 KiB
TypeScript
133 lines
4.8 KiB
TypeScript
import type { HttpContext } from '@adonisjs/core/http'
|
|
import DeviceService from '#services/device_service'
|
|
import CommandService from '#services/command_service'
|
|
|
|
export default class PagesController {
|
|
private deviceService = new DeviceService()
|
|
private commandService = new CommandService()
|
|
|
|
async home({ inertia }: HttpContext) {
|
|
const { data } = await this.deviceService.getDevices(0, 200)
|
|
return (inertia as any).render('Home', { devices: data, message: '' })
|
|
}
|
|
|
|
async deviceDetail({ params, inertia, response }: HttpContext) {
|
|
const device = await this.deviceService.getDeviceByIdentifier(params.identifier)
|
|
if (!device) {
|
|
return response.status(404).json({ message: 'Device not found' })
|
|
}
|
|
|
|
// Get pending commands (max 5) + last processed command
|
|
const allCommands = await this.commandService.getCommandsByDevice(params.identifier)
|
|
const pending = allCommands
|
|
.filter((c: any) => ['PENDING', 'WAITING', 'SENT'].includes(c.status))
|
|
.slice(0, 5)
|
|
const lastProcessed = allCommands
|
|
.filter((c: any) => ['COMPLETED', 'FAILED'].includes(c.status))
|
|
.sort((a: any, b: any) => new Date(b.updatedAt || b.createdAt).getTime() - new Date(a.updatedAt || a.createdAt).getTime())
|
|
[0]
|
|
const commands = lastProcessed ? [...pending, lastProcessed] : pending
|
|
|
|
return (inertia as any).render('DeviceDetail', { device, commands })
|
|
}
|
|
|
|
async commands({ inertia, request }: HttpContext) {
|
|
const deviceFilter = request.qs().device || ''
|
|
const statusFilter = request.qs().status || ''
|
|
const actionFilter = request.qs().action || ''
|
|
const modeFilter = request.qs().mode || ''
|
|
|
|
let commands: any[] = await this.commandService.getCommands()
|
|
|
|
if (deviceFilter) {
|
|
commands = commands.filter((c: any) => c.deviceIdentifier === deviceFilter)
|
|
}
|
|
if (statusFilter) {
|
|
commands = commands.filter((c: any) => c.status === statusFilter)
|
|
}
|
|
if (actionFilter) {
|
|
commands = commands.filter((c: any) => c.action === actionFilter)
|
|
}
|
|
if (modeFilter) {
|
|
commands = commands.filter((c: any) => c.mode === modeFilter)
|
|
}
|
|
|
|
return (inertia as any).render('Commands', {
|
|
commands,
|
|
filters: { device: deviceFilter, status: statusFilter, action: actionFilter, mode: modeFilter },
|
|
})
|
|
}
|
|
|
|
async commandsFleet({ inertia, session }: HttpContext) {
|
|
const devices = (session as any).get('fleetDevices', [])
|
|
const commands = await this.commandService.getCommands()
|
|
return (inertia as any).render('CommandsFleet', { devices, commands })
|
|
}
|
|
|
|
async storeFleetDevices({ request, response, session }: HttpContext) {
|
|
const { devices } = request.body()
|
|
;(session as any).put('fleetDevices', devices || [])
|
|
return response.redirect().toPath('/commands/fleet')
|
|
}
|
|
|
|
async refreshDevice({ params, response }: HttpContext) {
|
|
// Create a REFRESH command and send Connection Request to wake the CPE
|
|
await this.deviceService.refreshDevice(params.identifier)
|
|
return response.redirect().back()
|
|
}
|
|
|
|
async getModel({ params, request }: HttpContext) {
|
|
const { modelPath } = request.body()
|
|
await this.deviceService.executeCommand(params.identifier, {
|
|
action: 'GET_PARAMETER_NAMES' as any,
|
|
parameters: { parameterPath: modelPath, nextLevel: true },
|
|
mode: 'I',
|
|
})
|
|
}
|
|
|
|
async storeFleetCommand({ request, response, session }: HttpContext) {
|
|
const { action, parameters, mode, priority, devices } = request.body()
|
|
const deviceList = devices || session.get('fleetDevices', [])
|
|
|
|
for (const deviceIdentifier of deviceList) {
|
|
await this.commandService.createCommand({
|
|
deviceIdentifier,
|
|
action,
|
|
parameters: parameters || {},
|
|
mode,
|
|
priority,
|
|
})
|
|
}
|
|
|
|
return response.redirect().toPath('/commands/fleet')
|
|
}
|
|
|
|
async configurationsList({ inertia }: HttpContext) {
|
|
return (inertia as any).render('configurations/ConfigurationsList')
|
|
}
|
|
|
|
async configurationCreate({ inertia }: HttpContext) {
|
|
return (inertia as any).render('configurations/ConfigurationCreate')
|
|
}
|
|
|
|
async configurationEdit({ params, inertia }: HttpContext) {
|
|
return (inertia as any).render('configurations/ConfigurationEdit', { id: params.id })
|
|
}
|
|
|
|
async configurationDetail({ params, inertia }: HttpContext) {
|
|
return (inertia as any).render('configurations/ConfigurationDetail', { id: params.id })
|
|
}
|
|
|
|
async firmwareCatalog({ inertia }: HttpContext) {
|
|
return (inertia as any).render('firmware_catalog/FirmwareCatalog')
|
|
}
|
|
|
|
async firmwareCatalogCreate({ inertia }: HttpContext) {
|
|
return (inertia as any).render('firmware_catalog/FirmwareCatalogCreate')
|
|
}
|
|
|
|
async firmwareCatalogEdit({ params, inertia }: HttpContext) {
|
|
return (inertia as any).render('firmware_catalog/FirmwareCatalogEdit', { id: params.id })
|
|
}
|
|
}
|