Include ALL campus option. Make user campus the default
This commit is contained in:
parent
8ff1fe3f32
commit
44e247703d
|
@ -10,7 +10,9 @@ const router = Router()
|
|||
|
||||
class PrinterController {
|
||||
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) {
|
||||
const printers = await prisma.printer.findMany()
|
||||
|
@ -27,8 +29,9 @@ class PrinterController {
|
|||
|
||||
if (campus == 'RT')
|
||||
networkCriteria = { OR: [{ shortName: 'RT1' }, { shortName: 'RT2' }] }
|
||||
|
||||
if (campus == 'ALL') networkCriteria = undefined
|
||||
else if (campus) networkCriteria = { shortName: String(campus) }
|
||||
else networkCriteria = undefined
|
||||
|
||||
const printers = await prisma.printer.findMany({
|
||||
where: {
|
||||
|
|
|
@ -43,7 +43,8 @@ export type PrinterInfo = {
|
|||
|
||||
export class PrinterStatusService {
|
||||
constructor(private printer: Printer) {
|
||||
this.getPrinterSnmpStatus().then(async printerStatus => {
|
||||
this.getPrinterSnmpStatus()
|
||||
.then(async printerStatus => {
|
||||
const lastStatus = await prisma.printerStatus.findFirst({
|
||||
where: { printerId: this.printer.id },
|
||||
orderBy: { timestamp: 'desc' }
|
||||
|
@ -53,7 +54,8 @@ export class PrinterStatusService {
|
|||
lastStatus?.counter == printerStatus.counter &&
|
||||
lastStatus?.tonerBlackLevel == printerStatus.toners.black.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
|
||||
) {
|
||||
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[] {
|
||||
|
@ -178,8 +185,7 @@ export class PrinterStatusService {
|
|||
current: string | undefined,
|
||||
max: string | undefined
|
||||
) {
|
||||
if (typeof current === 'undefined' || typeof max === 'undefined')
|
||||
throw new Error('current or max is undefined')
|
||||
if (typeof current === 'undefined' || typeof max === 'undefined') return 0
|
||||
|
||||
return Math.floor((+current! / +max!) * 100)
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ const { smAndUp } = useDisplay()
|
|||
const campiSelectItems = [
|
||||
{
|
||||
title: 'Todos',
|
||||
value: ''
|
||||
value: 'ALL'
|
||||
},
|
||||
{
|
||||
title: 'Aquidauana',
|
||||
|
|
|
@ -15,8 +15,6 @@ export const useAppStore = defineStore('app', {
|
|||
|
||||
actions: {
|
||||
async fetchPrinters(force = false) {
|
||||
if (!this.me) return []
|
||||
|
||||
this.loadingPrinters = true
|
||||
try {
|
||||
this.printers = await api<any[]>(
|
||||
|
|
Loading…
Reference in New Issue
Block a user