Browse Source

logs: Added log import form.

1.2
Gisle Aune 6 years ago
parent
commit
c4636cf843
  1. 83
      marko/page/logs/components/import-log-modal/component.js
  2. 44
      marko/page/logs/components/import-log-modal/index.marko
  3. 9
      marko/page/logs/components/import-log-modal/style.less
  4. 1
      marko/page/logs/components/logs-menu/index.marko
  5. 1
      marko/page/logs/components/page/index.marko
  6. 22
      package-lock.json
  7. 47
      rpdata/api/Log.js

83
marko/page/logs/components/import-log-modal/component.js

@ -0,0 +1,83 @@
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: "",
},
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.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
})
}
}

44
marko/page/logs/components/import-log-modal/index.marko

@ -0,0 +1,44 @@
import moment from "moment"
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") >
<if(state.imported == null)>
<h1>Import Log</h1>
<p key="error" class="color-error">${state.error}</p>
<label>Type</label>
<select key="importer" autofocus class="big" placeholder="Kind" on-change("change", "importer") value=state.values.importer>
<option value="MircLike" selected=(state.values.importer === "MircLike")>mIRC-Like log</option>
<option value="ForumLog" selected=(state.values.importer === "ForumLog")>Forum Log</option>
</select>
<label>Timezone</label>
<select key="timezone" class="big" placeholder="Kind" on-change("change", "timezone") value=state.values.timezone>
<option for(tz in state.timezones) value=tz selected=(state.values.timezone === tz)>${tz}</option>
</select>
<label>Channel</label>
<input key="channelName" placeholder="(Required)" class="big" on-change("change", "channelName") value=state.values.channelName />
<if(state.values.importer === "MircLike")>
<label>Date</label>
<input key="date" class="big" placeholder="(Required)" on-change("change", "date") value=state.values.date />
</if>
<label>Content</label>
<textarea key="data" placeholder="(Required)" class="tall" on-change("change", "data") value=state.values.data />
<button disabled=state.loading on-click("save")>Import</button>
</if>
<else>
<h1>Import Successful</h1>
<p>The following logs were imported.</p>
<ol class="imported-log-list">
<for (log in state.imported)>
<li><a class="color-primary" href=("/logs/" + log.id)>${log.id} (${moment(log.date).format("MMMM D, YYYY")})</a></li>
</for>
</ol>
</else>
</modal>

9
marko/page/logs/components/import-log-modal/style.less

@ -0,0 +1,9 @@
ol.imported-log-list {
color: #777;
li {
a:hover {
text-decoration: underline;
}
}
}

1
marko/page/logs/components/logs-menu/index.marko

@ -3,5 +3,6 @@
<menu-link key="logs" selected=(input.selected.index && !state.filtered) icon="L" href="/logs/">All</menu-link>
<if-permitted key="if-permitted" user=input.user permission="log.add">
<menu-link key="add_log" dark on-click("select", "log.add") icon="+">Add Log</menu-link>
<menu-link key="import_log" dark on-click("select", "log.import") icon="+">Import Log</menu-link>
</if-permitted>
</menu>

1
marko/page/logs/components/page/index.marko

@ -5,3 +5,4 @@
<logs-table logs=state.logs on-addfilter("addFilter") />
</main>
<add-log-modal enabled=(state.modal === "log.add") on-close("close") />
<import-log-modal enabled=(state.modal === "log.import") on-close("close") />

22
package-lock.json

@ -1041,7 +1041,7 @@
},
"browserify-aes": {
"version": "1.2.0",
"resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz",
"resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz",
"integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==",
"requires": {
"buffer-xor": "^1.0.3",
@ -1075,7 +1075,7 @@
},
"browserify-rsa": {
"version": "4.0.1",
"resolved": "http://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz",
"resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz",
"integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=",
"requires": {
"bn.js": "^4.1.0",
@ -1357,7 +1357,7 @@
},
"convert-source-map": {
"version": "1.1.3",
"resolved": "http://registry.npmjs.org/convert-source-map/-/convert-source-map-1.1.3.tgz",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.1.3.tgz",
"integrity": "sha1-SCnId+n+SbMWHzvzZziI4gRpmGA="
},
"cookie": {
@ -1396,7 +1396,7 @@
},
"create-hash": {
"version": "1.2.0",
"resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
"resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
"integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==",
"requires": {
"cipher-base": "^1.0.1",
@ -1408,7 +1408,7 @@
},
"create-hmac": {
"version": "1.1.7",
"resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
"resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
"integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==",
"requires": {
"cipher-base": "^1.0.3",
@ -1555,7 +1555,7 @@
},
"diffie-hellman": {
"version": "5.0.3",
"resolved": "http://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
"resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
"integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==",
"requires": {
"bn.js": "^4.1.0",
@ -2647,7 +2647,7 @@
},
"htmlescape": {
"version": "1.1.1",
"resolved": "http://registry.npmjs.org/htmlescape/-/htmlescape-1.1.1.tgz",
"resolved": "https://registry.npmjs.org/htmlescape/-/htmlescape-1.1.1.tgz",
"integrity": "sha1-OgPtwiFLyjtmQko+eVk0lQnLA1E="
},
"htmljs-parser": {
@ -3515,7 +3515,7 @@
},
"minimist": {
"version": "1.2.0",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
},
"mkdirp": {
@ -3707,7 +3707,7 @@
},
"parse-asn1": {
"version": "5.1.1",
"resolved": "http://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.1.tgz",
"resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.1.tgz",
"integrity": "sha512-KPx7flKXg775zZpnp9SxJlz00gTd4BmJ2yJufSc44gMCRrRQ7NSzAcSJQfifuOLgW6bEi+ftrALtsgALeB2Adw==",
"requires": {
"asn1.js": "^4.0.0",
@ -4410,7 +4410,7 @@
},
"sha.js": {
"version": "2.4.11",
"resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
"resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
"integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==",
"requires": {
"inherits": "^2.0.1",
@ -4419,7 +4419,7 @@
},
"shasum": {
"version": "1.0.2",
"resolved": "http://registry.npmjs.org/shasum/-/shasum-1.0.2.tgz",
"resolved": "https://registry.npmjs.org/shasum/-/shasum-1.0.2.tgz",
"integrity": "sha1-5wEjENj0F/TetXEhUOVni4euVl8=",
"requires": {
"json-stable-stringify": "~0.0.0",

47
rpdata/api/Log.js

@ -124,6 +124,53 @@ class LogAPI {
})
}
/**
* Call `importLog(input)` mutation, returns multpile logs.
*
* @param {{importer:"MircLike"|"ForumLog", date?:Date|string|number, channel:string, timezone:string, data:string}} input
* @returns {Promise<Log[]>}
*/
import(input) {
return query(`
mutation ImportLog($input: LogImportInput!) {
importLog(input: $input) {
id
shortId
date
title
eventName
description
open
channel {
name
logged
hub
eventName
locationName
}
characters {
id
nicks
author
name
shortName
description
}
posts {
id
position
time
kind
nick
text
}
}
}
`, {input}, {permissions: ["log.add"]}).then(({importLog}) => {
return importLog.map(d => Log.fromData(d))
})
}
/**
* Call `editLog(input)` mutation, returns the id and all editable fields.
*

Loading…
Cancel
Save