logs: Added add log form.
This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
const moment = require("moment")
|
||||||
|
|
||||||
|
const {logsApi} = require("../../../../../rpdata/api/Log")
|
||||||
|
|
||||||
|
module.exports = class {
|
||||||
|
onCreate(input) {
|
||||||
|
this.state = {
|
||||||
|
error: null,
|
||||||
|
loading: false,
|
||||||
|
values: {
|
||||||
|
date: "",
|
||||||
|
channel: "",
|
||||||
|
title: "",
|
||||||
|
event: "",
|
||||||
|
description: "",
|
||||||
|
open: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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.first = false
|
||||||
|
this.emit("close")
|
||||||
|
}
|
||||||
|
|
||||||
|
save() {
|
||||||
|
if (this.state.loading) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const input = Object.assign({}, this.state.values)
|
||||||
|
|
||||||
|
input.date = new Date(input.date)
|
||||||
|
if (Number.isNaN(input.date)) {
|
||||||
|
this.state.error = "Invalid date"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state.loading = true
|
||||||
|
logsApi.add(input).then(log => {
|
||||||
|
window.location = `/logs/${log.id}/`
|
||||||
|
}).catch(errs => {
|
||||||
|
console.warn("Failed to add:", errs)
|
||||||
|
|
||||||
|
this.state.error = "Failed to add: " + errs[0].message
|
||||||
|
}).then(() => {
|
||||||
|
this.state.loading = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import moment from "moment"
|
||||||
|
|
||||||
|
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") >
|
||||||
|
<h1>Add Log</h1>
|
||||||
|
|
||||||
|
<p key="error" class="color-error">${state.error}</p>
|
||||||
|
|
||||||
|
<label>Date</label>
|
||||||
|
<input key="date" placeholder="(Required)" class="big" on-change("change", "date") value=state.values.date />
|
||||||
|
|
||||||
|
<label>Channel</label>
|
||||||
|
<input key="channel" placeholder="(Required)" class="big" on-change("change", "channel") value=state.values.channel />
|
||||||
|
|
||||||
|
<label>Title</label>
|
||||||
|
<input key="title" placeholder="(Optional)" class="big" on-change("change", "title") value=state.values.title />
|
||||||
|
|
||||||
|
<label>Event Name</label>
|
||||||
|
<input key="event" placeholder="(Optional)" class="big" on-change("change", "event") value=state.values.event />
|
||||||
|
|
||||||
|
<label>Description</label>
|
||||||
|
<textarea key="description" placeholder="(Optional)" on-change("change", "description") value=state.values.description />
|
||||||
|
|
||||||
|
<label>Options</label>
|
||||||
|
<toggle value=state.values.open on="Open" off="Closed"
|
||||||
|
onDesc=("IRC posts in "+state.values.channel.name+" will end up here.")
|
||||||
|
offDesc="The logbot will not append to this log."
|
||||||
|
on-change("change", "open") />
|
||||||
|
|
||||||
|
<p if(state.values.open) key="warning" class="color-danger">Opening a log will close all others for the same channels.</p>
|
||||||
|
|
||||||
|
<button disabled=state.loading on-click("save")>Save</button>
|
||||||
|
</modal>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = class {
|
||||||
|
select(value) {
|
||||||
|
this.emit("select", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<menu user=input.user>
|
<menu user=input.user>
|
||||||
<menu-header>Logs</menu-header>
|
<menu-header>Logs</menu-header>
|
||||||
<menu-link selected=input.selected.index icon="L" href="/logs/">All</menu-link>
|
<menu-link selected=input.selected.index icon="L" href="/logs/">All</menu-link>
|
||||||
|
<menu-link dark on-click("select", "add") icon="+">Add Log</menu-link>
|
||||||
<menu-gap />
|
<menu-gap />
|
||||||
<menu-header>Filters</menu-header>
|
<menu-header>Filters</menu-header>
|
||||||
<menu-gap />
|
<menu-gap />
|
||||||
|
|||||||
@@ -3,10 +3,19 @@ const {logHeaderApi} = require("../../../../../rpdata/api/LogHeader")
|
|||||||
module.exports = class {
|
module.exports = class {
|
||||||
onCreate(input) {
|
onCreate(input) {
|
||||||
this.state = {
|
this.state = {
|
||||||
logs: input.logs
|
logs: input.logs,
|
||||||
|
modal: null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open(modal) {
|
||||||
|
this.state.modal = modal
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.state.modal = null
|
||||||
|
}
|
||||||
|
|
||||||
onMount() {
|
onMount() {
|
||||||
logHeaderApi.list({limit: 0}).then(logs => {
|
logHeaderApi.list({limit: 0}).then(logs => {
|
||||||
this.state.logs = logs
|
this.state.logs = logs
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<background src="/assets/images/bg.png" opacity=0.25 />
|
<background src="/assets/images/bg.png" opacity=0.25 />
|
||||||
<logs-menu key="menu" selected=(input.selected || {}) user=input.user />
|
<logs-menu key="menu" on-select("open") selected=(input.selected || {}) user=input.user />
|
||||||
<main>
|
<main>
|
||||||
<logs-list logs=state.logs />
|
<logs-list logs=state.logs />
|
||||||
</main>
|
</main>
|
||||||
|
<add-log-modal enabled=(state.modal === "add") on-close("close") />
|
||||||
|
|||||||
+1
-1
@@ -86,7 +86,7 @@ class LogAPI {
|
|||||||
add(input) {
|
add(input) {
|
||||||
return query(`
|
return query(`
|
||||||
mutation FindLog($input: LogAddInput!) {
|
mutation FindLog($input: LogAddInput!) {
|
||||||
log(input: $input) {
|
addLog(input: $input) {
|
||||||
id
|
id
|
||||||
shortId
|
shortId
|
||||||
date
|
date
|
||||||
|
|||||||
Reference in New Issue
Block a user