The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

96 lines
2.3 KiB

const {tz} = require("moment-timezone")
const {logsApi} = require("../../../../../rpdata/api/Log")
module.exports = class {
onCreate(input) {
this.state = {
error: null,
loading: false,
imported: null,
values: {
importer: "MircLike",
timezone: tz.guess() || "UTC",
channelName: "",
date: "",
data: "",
sessionThresholdHours: 12,
},
timezones: tz.names(),
}
this.first = false
}
change(key, ev) {
this.state.values[key] = ev.target.value
this.state.values = Object.assign({}, this.state.values)
}
open() {
this.state.loading = false
}
close() {
this.emit("close")
this.state.values = {
importer: "MircLike",
timezone: tz.guess() || "UTC",
channelName: "",
date: "",
data: "",
}
this.state.imported = null
this.state.loading = false
}
save() {
if (this.state.loading) {
return
}
this.state.error = null;
const input = Object.assign({}, this.state.values)
if (input.date != "" && input.importer !== "ForumLog") {
input.date = new Date(input.date)
if (Number.isNaN(input.date)) {
this.state.error = "Invalid date"
return
}
} else if (input.importer === "MircLike") {
this.state.error = "Date is required for mIRC-like logs."
return
} else {
input.date = null;
}
if (input.importer === "IRCCloudLog") {
const hours = parseFloat(input.sessionThresholdHours)
if (Number.isNaN(hours)) {
this.state.error = "The session change threshold must be a number."
return
}
input.sessionThresholdMs = Math.floor(hours * 3600000)
}
delete input.sessionThresholdHours
if (input.channelName.length < 2 || input.channelName.includes(" ") || input.channelName.includes(" ") || input.channelName.charAt(0) !== "#") {
this.state.error = "A valid channelName name is required"
return
}
this.state.loading = true
logsApi.import(input).then(logs => {
this.state.imported = logs
}).catch(errs => {
console.warn("Import failed:", errs)
this.state.error = "Import failed: " + errs[0].message
}).then(() => {
this.state.loading = false
})
}
}