Include ALL campus option. Make user campus the default

This commit is contained in:
Douglas Barone 2023-07-05 08:29:03 -04:00
parent 8ff1fe3f32
commit 44e247703d
4 changed files with 53 additions and 46 deletions

View File

@ -10,7 +10,9 @@ const router = Router()
class PrinterController { class PrinterController {
static async index(req: Request, res: Response) { static async index(req: Request, res: Response) {
const { campus, force } = req.query let { campus, force } = req.query
if (!campus) campus = res.locals.user?.campus
if (force) { if (force) {
const printers = await prisma.printer.findMany() const printers = await prisma.printer.findMany()
@ -27,8 +29,9 @@ class PrinterController {
if (campus == 'RT') if (campus == 'RT')
networkCriteria = { OR: [{ shortName: 'RT1' }, { shortName: 'RT2' }] } networkCriteria = { OR: [{ shortName: 'RT1' }, { shortName: 'RT2' }] }
if (campus == 'ALL') networkCriteria = undefined
else if (campus) networkCriteria = { shortName: String(campus) } else if (campus) networkCriteria = { shortName: String(campus) }
else networkCriteria = undefined
const printers = await prisma.printer.findMany({ const printers = await prisma.printer.findMany({
where: { where: {

View File

@ -43,7 +43,8 @@ export type PrinterInfo = {
export class PrinterStatusService { export class PrinterStatusService {
constructor(private printer: Printer) { constructor(private printer: Printer) {
this.getPrinterSnmpStatus().then(async printerStatus => { this.getPrinterSnmpStatus()
.then(async printerStatus => {
const lastStatus = await prisma.printerStatus.findFirst({ const lastStatus = await prisma.printerStatus.findFirst({
where: { printerId: this.printer.id }, where: { printerId: this.printer.id },
orderBy: { timestamp: 'desc' } orderBy: { timestamp: 'desc' }
@ -53,7 +54,8 @@ export class PrinterStatusService {
lastStatus?.counter == printerStatus.counter && lastStatus?.counter == printerStatus.counter &&
lastStatus?.tonerBlackLevel == printerStatus.toners.black.level && lastStatus?.tonerBlackLevel == printerStatus.toners.black.level &&
lastStatus?.tonerCyanLevel == printerStatus.toners.cyan?.level && lastStatus?.tonerCyanLevel == printerStatus.toners.cyan?.level &&
lastStatus?.tonerMagentaLevel == printerStatus.toners.magenta?.level && lastStatus?.tonerMagentaLevel ==
printerStatus.toners.magenta?.level &&
lastStatus?.tonerYellowLevel == printerStatus.toners.yellow?.level lastStatus?.tonerYellowLevel == printerStatus.toners.yellow?.level
) { ) {
await prisma.printerStatus.update({ await prisma.printerStatus.update({
@ -87,6 +89,11 @@ export class PrinterStatusService {
}) })
} }
}) })
.catch(err => {
console.log(
`Couldn't get printer status for ${printer.serialNumber} (IP:${printer.ip}). Error: ${err}`
)
})
} }
private objectIdsArray(): string[] { private objectIdsArray(): string[] {
@ -178,8 +185,7 @@ export class PrinterStatusService {
current: string | undefined, current: string | undefined,
max: string | undefined max: string | undefined
) { ) {
if (typeof current === 'undefined' || typeof max === 'undefined') if (typeof current === 'undefined' || typeof max === 'undefined') return 0
throw new Error('current or max is undefined')
return Math.floor((+current! / +max!) * 100) return Math.floor((+current! / +max!) * 100)
} }

View File

@ -74,7 +74,7 @@ const { smAndUp } = useDisplay()
const campiSelectItems = [ const campiSelectItems = [
{ {
title: 'Todos', title: 'Todos',
value: '' value: 'ALL'
}, },
{ {
title: 'Aquidauana', title: 'Aquidauana',

View File

@ -15,8 +15,6 @@ export const useAppStore = defineStore('app', {
actions: { actions: {
async fetchPrinters(force = false) { async fetchPrinters(force = false) {
if (!this.me) return []
this.loadingPrinters = true this.loadingPrinters = true
try { try {
this.printers = await api<any[]>( this.printers = await api<any[]>(