new admin structure

This commit is contained in:
Josh Harvey 2017-05-09 00:37:38 +03:00
parent 7d82874916
commit c2282e61b4
17 changed files with 5768 additions and 1204 deletions

View file

@ -12,8 +12,7 @@ const db = require('../db')
const options = require('../options')
const configManager = require('../config-manager')
const configValidate = require('../config-validate')
const machines = require('./machines')
const machineLoader = require('../machine-loader')
function fetchSchema () {
const schemaPath = path.resolve(options.lamassuServerPath, 'lamassu-schema.json')
@ -64,7 +63,7 @@ function getField (schema, group, fieldCode) {
return R.merge(R.pick(['cryptoScope', 'machineScope'], group), field)
}
const fetchMachines = () => machines.getMachines()
const fetchMachines = () => machineLoader.getMachines()
.then(machineList => machineList.map(r => r.deviceId))
function validateCurrentConfig () {
@ -134,7 +133,7 @@ const supportedLanguages = languageRec.supported
const languages = supportedLanguages.map(mapLanguage).filter(r => r)
function fetchData () {
return machines.getMachines()
return machineLoader.getMachineNames()
.then(machineList => ({
currencies: massageCurrencies(currencies),
cryptoCurrencies: [{crypto: 'BTC', display: 'Bitcoin'}, {crypto: 'ETH', display: 'Ethereum'}],
@ -163,36 +162,8 @@ function fetchData () {
function saveConfigGroup (results) {
if (results.values.length === 0) return fetchConfigGroup(results.groupCode)
return configValidate.ensureConstraints(results.values)
.then(fetchConfig)
.then(oldValues => {
results.values.forEach(newValue => {
const oldValueIndex = oldValues
.findIndex(old => old.fieldLocator.code === newValue.fieldLocator.code &&
old.fieldLocator.fieldScope.crypto === newValue.fieldLocator.fieldScope.crypto &&
old.fieldLocator.fieldScope.machine === newValue.fieldLocator.fieldScope.machine
)
const existingValue = oldValueIndex > -1 &&
oldValues[oldValueIndex]
if (existingValue) {
// Delete value record
if (R.isNil(newValue.fieldValue)) {
oldValues.splice(oldValueIndex, 1)
return
}
existingValue.fieldValue = newValue.fieldValue
return
}
if (!R.isNil(newValue.fieldValue)) oldValues.push(newValue)
})
return settingsLoader.save(oldValues)
.then(() => fetchConfigGroup(results.groupCode))
})
return settingsLoader.modifyConfig(results.values)
.then(() => fetchConfigGroup(results.groupCode))
}
module.exports = {