Chore: make notification center UI
Chore: fiatBalancesNotify refactor Chore: removed now-unused code in some files Feat: change column "detail" in database to use jsonb Chore: add notification center background and button Chore: notifications screen scaffolding Fix: change position of notification UI Feat: join backend and frontend Feat: notification icons and machine names Feat: add clear all button, stripe overlay on invalid notification Fix: rework notification styles Feat: use popper to render notifications Feat: make notification center UI Fix: fix css on notification center Fix: fix invalidateNotification Chore: apply PR requested changes Fix: PR fixes Fix: make toggleable body/root styles be handled by react Chore: delete old notifier file Fix: undo variable name changes for cryptobalance notifs
This commit is contained in:
parent
2a9e8dadba
commit
c457faab40
37 changed files with 1337 additions and 1332 deletions
|
|
@ -1,18 +1,17 @@
|
|||
const _ = require('lodash/fp')
|
||||
const axios = require('axios')
|
||||
|
||||
const logger = require('./logger')
|
||||
const db = require('./db')
|
||||
const pairing = require('./pairing')
|
||||
const notifier = require('./notifier')
|
||||
const dbm = require('./postgresql_interface')
|
||||
const configManager = require('./new-config-manager')
|
||||
const settingsLoader = require('./new-settings-loader')
|
||||
|
||||
module.exports = {getMachineName, getMachines, getMachine, getMachineNames, setMachine}
|
||||
const notifierUtils = require('./notifier/utils')
|
||||
const notifierQueries = require('./notifier/queries')
|
||||
|
||||
function getMachines () {
|
||||
return db.any('select * from devices where display=TRUE order by created')
|
||||
return db.any('SELECT * FROM devices WHERE display=TRUE ORDER BY created')
|
||||
.then(rr => rr.map(r => ({
|
||||
deviceId: r.device_id,
|
||||
cashbox: r.cashbox,
|
||||
|
|
@ -36,10 +35,10 @@ function getConfig (defaultConfig) {
|
|||
}
|
||||
|
||||
function getMachineNames (config) {
|
||||
const fullyFunctionalStatus = {label: 'Fully functional', type: 'success'}
|
||||
const unresponsiveStatus = {label: 'Unresponsive', type: 'error'}
|
||||
const stuckStatus = {label: 'Stuck', type: 'error'}
|
||||
|
||||
const fullyFunctionalStatus = { label: 'Fully functional', type: 'success' }
|
||||
const unresponsiveStatus = { label: 'Unresponsive', type: 'error' }
|
||||
const stuckStatus = { label: 'Stuck', type: 'error' }
|
||||
|
||||
return Promise.all([getMachines(), getConfig(config)])
|
||||
.then(([machines, config]) => Promise.all(
|
||||
[machines, notifier.checkPings(machines), dbm.machineEvents(), config]
|
||||
|
|
@ -49,7 +48,7 @@ function getMachineNames (config) {
|
|||
if (ping && ping.age) return unresponsiveStatus
|
||||
|
||||
if (stuck && stuck.age) return stuckStatus
|
||||
|
||||
|
||||
return fullyFunctionalStatus
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +56,7 @@ function getMachineNames (config) {
|
|||
const cashOutConfig = configManager.getCashOut(r.deviceId, config)
|
||||
|
||||
const cashOut = !!cashOutConfig.active
|
||||
|
||||
|
||||
const statuses = [
|
||||
getStatus(
|
||||
_.first(pings[r.deviceId]),
|
||||
|
|
@ -65,7 +64,7 @@ function getMachineNames (config) {
|
|||
)
|
||||
]
|
||||
|
||||
return _.assign(r, {cashOut, statuses})
|
||||
return _.assign(r, { cashOut, statuses })
|
||||
}
|
||||
|
||||
return _.map(addName, machines)
|
||||
|
|
@ -83,31 +82,29 @@ function getMachineNames (config) {
|
|||
* @returns {string} machine name
|
||||
*/
|
||||
function getMachineName (machineId) {
|
||||
const sql = 'select * from devices where device_id=$1'
|
||||
const sql = 'SELECT * FROM devices WHERE device_id=$1'
|
||||
return db.oneOrNone(sql, [machineId])
|
||||
.then(it => it.name)
|
||||
}
|
||||
|
||||
function getMachine (machineId) {
|
||||
const sql = 'select * from devices where device_id=$1'
|
||||
const sql = 'SELECT * FROM devices WHERE device_id=$1'
|
||||
return db.oneOrNone(sql, [machineId]).then(res => _.mapKeys(_.camelCase)(res))
|
||||
}
|
||||
|
||||
function renameMachine (rec) {
|
||||
const sql = 'update devices set name=$1 where device_id=$2'
|
||||
const sql = 'UPDATE devices SET name=$1 WHERE device_id=$2'
|
||||
return db.none(sql, [rec.newName, rec.deviceId])
|
||||
}
|
||||
|
||||
function resetCashOutBills (rec) {
|
||||
const sql = `
|
||||
update devices set cassette1=$1, cassette2=$2 where device_id=$3;
|
||||
update notifications set read = 't', valid = 'f' where read = 'f' AND valid = 't' AND device_id = $3 AND type = 'fiatBalance';
|
||||
`
|
||||
return db.none(sql, [rec.cassettes[0], rec.cassettes[1], rec.deviceId])
|
||||
const detailB = notifierUtils.buildDetail({ deviceId: rec.deviceId })
|
||||
const sql = `UPDATE devices SET cassette1=$1, cassette2=$2 WHERE device_id=$3;`
|
||||
return db.none(sql, [rec.cassettes[0], rec.cassettes[1], rec.deviceId]).then(() => notifierQueries.invalidateNotification(detailB, 'fiatBalance'))
|
||||
}
|
||||
|
||||
function emptyCashInBills (rec) {
|
||||
const sql = 'update devices set cashbox=0 where device_id=$1'
|
||||
const sql = 'UPDATE devices SET cashbox=0 WHERE device_id=$1'
|
||||
return db.none(sql, [rec.deviceId])
|
||||
}
|
||||
|
||||
|
|
@ -145,3 +142,5 @@ function setMachine (rec) {
|
|||
default: throw new Error('No such action: ' + rec.action)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getMachineName, getMachines, getMachine, getMachineNames, setMachine }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue