Minor logging changes, showing question db name in answer window header

This commit is contained in:
mrfry 2021-01-11 14:47:57 +01:00
parent 0d9f7df3de
commit 76c1492b85

View file

@ -112,7 +112,7 @@
// forcing pages for testing. unless you test, do not set these to true! // forcing pages for testing. unless you test, do not set these to true!
setVal('ISDEVEL', true) setVal('ISDEVEL', true)
// only one of these should be true for testing // only one of these should be true for testing
const forceTestPage = true const forceTestPage = false
const forceResultPage = false const forceResultPage = false
const forceDefaultPage = false const forceDefaultPage = false
@ -128,7 +128,7 @@
const minMessageOpacity = 0.2 const minMessageOpacity = 0.2
let infoExpireTime = 60 // Every n seconds basic info should be loaded from server let infoExpireTime = 60 // Every n seconds basic info should be loaded from server
var motd = '' var motd = ''
var userSpecificMotd = '' var userSpecificMotd = {}
var lastestVersion = '' var lastestVersion = ''
var subjInfo var subjInfo
@ -138,7 +138,7 @@
const overlayElemUpdateInterval = 2 // seconds const overlayElemUpdateInterval = 2 // seconds
if (getVal('ISDEVEL')) { if (getVal('ISDEVEL')) {
console.log('Moodle script running in developement mode!') log('Moodle script running in developement mode!')
infoExpireTime = 1 infoExpireTime = 1
serverAdress = 'http://localhost:8080/' serverAdress = 'http://localhost:8080/'
apiAdress = 'http://localhost:8080/' apiAdress = 'http://localhost:8080/'
@ -348,7 +348,7 @@
uid: getUid(), uid: getUid(),
} }
console.log(sentData) log(sentData)
post('ask', sentData).then(results => { post('ask', sentData).then(results => {
removeLoadingMessage() removeLoadingMessage()
@ -398,8 +398,8 @@
resolve(errorsRemoved) resolve(errorsRemoved)
}) })
.catch(err => { .catch(err => {
console.warn('Error in handleQuiz()') warn('Error in handleQuiz()')
console.warn(err) warn(err)
}) })
}) })
} }
@ -1030,7 +1030,7 @@
idInput.value = getCid() idInput.value = getCid()
} }
} catch (e) { } catch (e) {
console.info('Error filling client ID input', e) warn('Error filling client ID input', e)
} }
try { try {
const sideLinks = document.getElementById('sideBarLinks') const sideLinks = document.getElementById('sideBarLinks')
@ -1050,7 +1050,7 @@
.getElementsByClassName('active')[0] .getElementsByClassName('active')[0]
) )
} catch (e) { } catch (e) {
console.info('Error filling client ID input', e) warn('Error filling client ID input', e)
} }
} }
@ -1066,7 +1066,7 @@
}, 100) }, 100)
} }
} catch (e) { } catch (e) {
console.info('Error filling client ID input', e) warn('Error filling client ID input', e)
} }
} }
@ -1142,7 +1142,13 @@
} }
lastestVersion = inf.version.replace(/\n/g, '') lastestVersion = inf.version.replace(/\n/g, '')
motd = inf.motd motd = inf.motd
userSpecificMotd = inf.userSpecificMotd if (getUid() !== inf.uid) {
setVal('userId', inf.uid)
}
userSpecificMotd = {
show: inf.userShouldGetUserSpecificMOTD,
text: inf.userSpecificMotd,
}
subjInfo = inf.subjinfo subjInfo = inf.subjinfo
setVal('userId', inf.uid) setVal('userId', inf.uid)
overlay.querySelector('#infoMainDiv').innerText = `${ overlay.querySelector('#infoMainDiv').innerText = `${
@ -1221,7 +1227,7 @@
function HandleUI(url) { function HandleUI(url) {
const newVersion = info().script.version !== getVal('lastVerson') const newVersion = info().script.version !== getVal('lastVerson')
const showMOTD = shouldShowMotd() const showMOTD = shouldShowMotd()
const showUserSpecificMOTD = !!userSpecificMotd const showUserSpecificMOTD = userSpecificMotd.show
const isNewVersionAvaible = const isNewVersionAvaible =
lastestVersion !== undefined && info().script.version !== lastestVersion lastestVersion !== undefined && info().script.version !== lastestVersion
@ -1248,7 +1254,7 @@
timeout = null timeout = null
} }
if (showUserSpecificMOTD) { if (showUserSpecificMOTD) {
greetMsg.push(texts.userMOTD + userSpecificMotd) greetMsg.push(texts.userMOTD + userSpecificMotd.text)
timeout = null timeout = null
} }
@ -1283,7 +1289,10 @@
return { return {
m: msg, m: msg,
p: answer.match, p: answer.match,
header: answer.detailedMatch.matchedSubjName, header:
answer.detailedMatch.matchedSubjName +
' - ' +
answer.detailedMatch.qdb,
} }
}) })
} }
@ -1305,7 +1314,7 @@
} }
function ShowAnswers(results) { function ShowAnswers(results) {
console.log(results) log(results)
const answers = results.reduce((acc, res) => { const answers = results.reduce((acc, res) => {
const prepared = PrepareAnswers(res) const prepared = PrepareAnswers(res)
addImageIdsToImageNodes(res.question) addImageIdsToImageNodes(res.question)
@ -1403,7 +1412,7 @@
sentData.subj = 'NOSUBJ' sentData.subj = 'NOSUBJ'
log('unable to get subject name :c') log('unable to get subject name :c')
} }
console.log('SENT DATA', sentData) log('SENT DATA', sentData)
post('isAdding', sentData).then(res => { post('isAdding', sentData).then(res => {
next(res.success, sentData, res.totalNewQuestions) next(res.success, sentData, res.totalNewQuestions)
}) })
@ -1445,8 +1454,9 @@
function registerScript() { function registerScript() {
try { try {
// uncomment to re-register again every page refresh
// setVal('registeredWithCid', false) // setVal('registeredWithCid', false)
// setVal('registeredWithUid', true) // setVal('registeredWithUid', false)
if (getVal('registeredWithCid')) { if (getVal('registeredWithCid')) {
if (getVal('registeredWithUid')) { if (getVal('registeredWithUid')) {
@ -1466,10 +1476,11 @@
uid: getUid(), uid: getUid(),
version: info().script.version, version: info().script.version,
date: new Date(), date: new Date(),
installSource: info().script.updateURL,
}) })
} catch (err) { } catch (err) {
console.warn('Unexpected error while registering script') warn('Unexpected error while registering script')
console.log(err) log(err)
} }
} }
@ -1554,7 +1565,7 @@
function addOpacityChangeEvent(elem) { function addOpacityChangeEvent(elem) {
if (!elem.id) { if (!elem.id) {
console.warn('element must have ID to add opacity change event!') warn('element must have ID to add opacity change event!')
return return
} }
@ -2241,11 +2252,7 @@
function logHelper(logMethod, value) { function logHelper(logMethod, value) {
if (logEnabled) { if (logEnabled) {
if (typeof value === 'string') { logMethod('[Moodle Script]: ', value)
logMethod('[Moodle Script]: ' + value)
} else {
logMethod(value)
}
} }
} }
@ -2325,9 +2332,10 @@
lastInfo = JSON.parse(getVal('lastInfo')) lastInfo = JSON.parse(getVal('lastInfo'))
} catch (e) { } catch (e) {
if (showErrors) { if (showErrors) {
console.info(e) warn(e)
} }
} }
if ( if (
lastInfo.result !== 'success' || lastInfo.result !== 'success' ||
now > lastCheck + infoExpireTime * 1000 now > lastCheck + infoExpireTime * 1000
@ -2353,9 +2361,6 @@
setVal('lastInfoCheckTime', now) setVal('lastInfoCheckTime', now)
const res = JSON.parse(response.responseText) const res = JSON.parse(response.responseText)
setVal('lastInfo', response.responseText) setVal('lastInfo', response.responseText)
if (getUid() !== res.uid) {
setVal('userId', res.uid)
}
resolve(res) resolve(res)
} catch (e) { } catch (e) {
log('Errro paring JSON in GetXHRInfos') log('Errro paring JSON in GetXHRInfos')
@ -2384,7 +2389,7 @@
} }
function GetXHRQuestionAnswer(question) { function GetXHRQuestionAnswer(question) {
console.log('QUESTIONS', question) log('QUESTIONS', question)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let url = apiAdress + 'ask?' let url = apiAdress + 'ask?'
let params = [] let params = []