weiter gehts

This commit is contained in:
rxf
2023-05-01 18:49:46 +02:00
parent 32bf325a68
commit 0e6563bc4e
3 changed files with 61 additions and 19 deletions

View File

@@ -18,6 +18,8 @@ const doMongo = async function(cmd, options) {
await client.connect() await client.connect()
if (cmd === 'getdata') { if (cmd === 'getdata') {
erg = await getAPIdataOne(client, options) erg = await getAPIdataOne(client, options)
} else if (cmd === 'getlastdata') {
erg = await getAPIlastDataOne(client, options)
} else if (cmd === 'putdata') { } else if (cmd === 'putdata') {
erg = await putAPIdataOne(client, options) erg = await putAPIdataOne(client, options)
} else if (cmd === 'deldata') { } else if (cmd === 'deldata') {
@@ -53,6 +55,18 @@ async function getAPIdataOne(client, options) {
return erg return erg
} }
async function getAPIlastDataOne(client, options) {
let erg = {err: null}
try {
erg.data = await client.db(MONGOBASE).collection(COLLECTION).findOne({},{ projection:{_id: 0}, sort: {$natural: -1}})
} catch
(e) {
console.error(e)
erg.err = e
}
return erg
}
async function putAPIdataOne(client, options) { async function putAPIdataOne(client, options) {
let erg = {err: null} let erg = {err: null}
const query = {curdate: options.data.curdate} const query = {curdate: options.data.curdate}

View File

@@ -1,14 +1,16 @@
document.addEventListener('DOMContentLoaded', async function () { document.addEventListener('DOMContentLoaded', async function () {
const DateTime = luxon.DateTime; const DateTime = luxon.DateTime;
const filename = 'data/data.json'
let curdate = '' let curdate = ''
const dt = DateTime.now() const dt = DateTime.now()
const dt1 = dt.plus({month:1}) const dt1 = dt.plus({month:1})
curdate = `${dt.toFormat('LLLL')}/${dt1.toFormat('LLLL y')}` curdate = `${dt.toFormat('LLLL')}/${dt1.toFormat('LLLL_y')}`
document.querySelector('#curmon').innerHTML = curdate document.querySelector('#curmon').innerHTML = curdate.replace('_',' ')
let ret = await getData(filename)
// initSchema('2023-05-01')
let ret = await getData()
fillSchema(ret.data) fillSchema(ret.data)
document.querySelector('#sptab').addEventListener('click', markField); document.querySelector('#sptab').addEventListener('click', markField);
@@ -17,9 +19,7 @@ document.addEventListener('DOMContentLoaded', async function () {
let field = e.target; let field = e.target;
field.setAttribute('aria-label','x'); field.setAttribute('aria-label','x');
field.setAttribute('disabled','disabled'); field.setAttribute('disabled','disabled');
let lastDate = parseInt(field.innerHTML) let data = {curdate: curdate}
let month = curdate.split('/')[0]
let data = {curdate: curdate.slice(0, -5), last: lastDate}
let setArray = [] let setArray = []
let fields = document.querySelectorAll('#sptab button') let fields = document.querySelectorAll('#sptab button')
for (i = 0; i < fields.length; i++) { for (i = 0; i < fields.length; i++) {
@@ -31,22 +31,24 @@ document.addEventListener('DOMContentLoaded', async function () {
} }
data.data = setArray data.data = setArray
storeData(data) storeData(data)
if (e.srcElement.id === 'bt35') {
showNextMonth(e.srcElement.innerHTML)
}
} }
function fillSchema(data) { function fillSchema(data) {
const setArray = data.data const setArray = data.data
for(let i = 1, k = 1; i < 36; i++, k++) { for(let i = 0; i < 35; i++) {
if (i === 18) { let sel = '#bt'+(i+1)
i++ let day = DateTime.fromISO(setArray[i].day).toFormat('d')
} document.querySelector(sel).setAttribute('innerHTML', day)
let sel = '#bt'+i if (setArray[i].day !== '') {
if(setArray[0].day === 'undefined') { if (setArray[i].status) {
document.querySelector(sel).innerHTML = k document.querySelector(sel).setAttribute('aria-label', 'x')
document.querySelector(sel).setAttribute('disabled', 'disabled')
}
} else { } else {
document.querySelector(sel).innerHTML = setArray[i-1].day document.querySelector(sel).setAttribute('disabled', 'disabled')
}
if(setArray[i-1].status) {
document.querySelector(sel).setAttribute('aria-label', 'x')
} }
} }
} }
@@ -67,4 +69,30 @@ document.addEventListener('DOMContentLoaded', async function () {
return response.json() return response.json()
} }
function showNextMonth() {
const dt = DateTime.now()
const dt1 = dt.plus({month:1})
curdate = `${dt.toFormat('LLLL')}/${dt1.toFormat('LLLL_y')}`
document.querySelector('#curmon').innerHTML = curdate.replace('_',' ')
fillSchema(ret.data)
}
function initSchema(startdate) {
let setArray = []
let ld0 = DateTime.fromISO(startdate)
for(let i = 0; i < 35; i++) {
let elem = {status: false}
if (i === 17) {
elem.day = ''
} else {
let ld = ld0.plus({day: i})
elem.day = ld.toFormat('y-LL-dd')
}
setArray.push(elem)
}
let data = {curdate: startdate, data: setArray}
storeData(data)
}
}); });

View File

@@ -10,7 +10,7 @@ router.get('/', function(req, res, next) {
router.get('/data', async function(req, res, next) { router.get('/data', async function(req, res, next) {
const options = {} const options = {}
options.curdate = req.query.curdate options.curdate = req.query.curdate
let erg = await domongo.doMongo('getdata', options) let erg = await domongo.doMongo('getlastdata', options)
res.json(erg) res.json(erg)
}) })