diff --git a/marko/page/logs-content/components/edit-log-modal/component.js b/marko/page/logs-content/components/edit-log-modal/component.js
new file mode 100644
index 0000000..d88585f
--- /dev/null
+++ b/marko/page/logs-content/components/edit-log-modal/component.js
@@ -0,0 +1,68 @@
+const moment = require("moment")
+
+const {logsApi} = require("../../../../../rpdata/api/Log")
+
+module.exports = class {
+ onCreate(input) {
+ this.state = {
+ error: null,
+ loading: false,
+ values: {
+ title: "",
+ event: "",
+ description: "",
+ open: false,
+ },
+ }
+
+ this.first = false
+ }
+
+ onInput(input) {
+ if (input.log && !this.first) {
+ this.state.values = {
+ title: input.log.title,
+ event: input.log.eventName,
+ description: input.log.description,
+ open: input.log.open,
+ }
+
+ this.first = true
+ }
+ }
+
+ 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({id: this.input.log.id}, this.state.values)
+ console.log(input)
+
+ this.state.loading = true
+ logsApi.edit(input).then(data => {
+ this.emit("edited", data)
+ this.emit("close")
+ }).catch(errs => {
+ console.warn("Failed to edit:", errs)
+
+ this.state.error = "Failed to edit: " + errs[0].message
+ }).then(() => {
+ this.state.loading = false
+ })
+ }
+}
\ No newline at end of file
diff --git a/marko/page/logs-content/components/edit-log-modal/index.marko b/marko/page/logs-content/components/edit-log-modal/index.marko
new file mode 100644
index 0000000..38bebc8
--- /dev/null
+++ b/marko/page/logs-content/components/edit-log-modal/index.marko
@@ -0,0 +1,25 @@
+import moment from "moment"
+
+
+ Edit Log
+
+ ${state.error}
+
+ Title
+
+
+ Event Name
+
+
+ Description
+
+
+
+
+ Opening a log will close all others for the same channels.
+
+ Save
+
\ No newline at end of file
diff --git a/marko/page/logs-content/components/logs-content-menu/index.marko b/marko/page/logs-content/components/logs-content-menu/index.marko
index a0bda5e..a62bae7 100644
--- a/marko/page/logs-content/components/logs-content-menu/index.marko
+++ b/marko/page/logs-content/components/logs-content-menu/index.marko
@@ -1,6 +1,6 @@
Log
- Add Post
+ Add Post
Links
diff --git a/marko/page/logs-content/components/page/component.js b/marko/page/logs-content/components/page/component.js
index 59da64b..45adfc2 100644
--- a/marko/page/logs-content/components/page/component.js
+++ b/marko/page/logs-content/components/page/component.js
@@ -17,7 +17,7 @@ module.exports = class {
close() {
this.state.modal = null
}
-
+
/**
* Patch the posts
*
@@ -83,6 +83,10 @@ module.exports = class {
this.patch([patch])
}
+ logEdited(patch) {
+ this.state.log = Object.assign(Object.assign({}, this.state.log), patch)
+ }
+
postAdded(post) {
this.state.log.posts = this.state.log.posts.concat([post])
this.state.log = Object.assign({}, this.state.log)
diff --git a/marko/page/logs-content/components/page/index.marko b/marko/page/logs-content/components/page/index.marko
index 88beaf0..bd8346d 100644
--- a/marko/page/logs-content/components/page/index.marko
+++ b/marko/page/logs-content/components/page/index.marko
@@ -1,7 +1,10 @@
-
+
+
\ No newline at end of file
diff --git a/marko/page/logs-content/components/page/style.less b/marko/page/logs-content/components/page/style.less
index 45f47fb..bc5bb0a 100644
--- a/marko/page/logs-content/components/page/style.less
+++ b/marko/page/logs-content/components/page/style.less
@@ -3,8 +3,27 @@ div.logs-content {
max-width: 75ch;
margin: auto;
- h1 {
- font-weight: 200;
+ div.header {
text-align: center;
+ vertical-align: middle;
+ margin-bottom: 1em;
+
+ h1 {
+ display: block;
+ font-weight: 200;
+ text-align: center;
+ margin-bottom: 0;
+ }
+
+ a {
+ vertical-align: middle;
+ display: inline-block;
+ padding: 0.5em 0.5ch 0.5em 0.5ch;
+ opacity: 0.5;
+ }
+ a:hover {
+ cursor: pointer;
+ opacity: 1;
+ }
}
}
\ No newline at end of file
diff --git a/marko/page/logs/components/logs-list/index.marko b/marko/page/logs/components/logs-list/index.marko
index aeaf35e..4c074b8 100644
--- a/marko/page/logs/components/logs-list/index.marko
+++ b/marko/page/logs/components/logs-list/index.marko
@@ -8,7 +8,7 @@ import moment from "moment"
description=log.description
characters=log.characters
name=(log.title || (log.channelName + " - " + moment(log.date).format("MMMM D, YYYY")))
- tags=[{kind: "Location", name: log.channelName}, {kind: "Event", name: log.event}]
+ tags=[{kind: "Location", name: log.channelName}, {kind: "Event", name: log.eventName}]
enableAllTags=true
createdDate=log.date />
\ No newline at end of file
diff --git a/rpdata/api/Log.js b/rpdata/api/Log.js
index b17d107..125b3ea 100644
--- a/rpdata/api/Log.js
+++ b/rpdata/api/Log.js
@@ -35,7 +35,7 @@ class Log {
}
}
-const logsApi = {
+class LogAPI {
find(id) {
return query(`
query FindLog($id: String!) {
@@ -75,7 +75,95 @@ const logsApi = {
`, {id}).then(({log}) => {
return Log.fromData(log)
})
- },
+ }
+
+ /**
+ * Call `addLog(input)` mutation, returns a Log
+ *
+ * @param {{time:Date, channel:string, title:string, eventName:string, description:string, open:boolean}} input
+ * @returns {Promise}
+ */
+ add(input) {
+ return query(`
+ mutation FindLog($input: LogAddInput!) {
+ log(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(({addLog}) => {
+ return Log.fromData(addLog)
+ })
+ }
+
+ /**
+ * Call `editLog(input)` mutation, returns the id and all editable fields.
+ *
+ * @param {{id:string, title:string, eventName:string, description:string, open:boolean}} input
+ * @returns {Promise<{id:string, title:string, eventName:string, description:string, open:boolean}>}
+ */
+ edit(input) {
+ return query(`
+ mutation EditLog($input: LogEditInput!) {
+ editLog(input: $input) {
+ id
+ title
+ eventName
+ description
+ open
+ }
+ }
+ `, {input}, {permissions: ["log.edit"]}).then(({editLog}) => {
+ return editLog
+ })
+ }
+
+
+ /**
+ * Call `removeLog(input)` mutation, returns the id
+ *
+ * @param {{id:string}} input
+ * @returns {Promise<{id:string}>}
+ */
+ remove(input) {
+ return query(`
+ mutation RemoveLog($input: LogRemoveInput!) {
+ removeLog(input: $input) {
+ id
+ }
+ }
+ `, {input}, {permissions: ["log.remove"]}).then(({editLog}) => {
+ return editLog
+ })
+ }
}
-module.exports = { Log, logsApi }
\ No newline at end of file
+module.exports = { Log, logsApi: new LogAPI }
\ No newline at end of file
diff --git a/rpdata/api/LogHeader.js b/rpdata/api/LogHeader.js
index 72e7984..d34eb12 100644
--- a/rpdata/api/LogHeader.js
+++ b/rpdata/api/LogHeader.js
@@ -14,14 +14,14 @@ class LogHeader {
* @param {boolean} open
* @param {{id:string,name:string,shortName:string,author:string}[]} characters
*/
- constructor(id, shortId, date, channelName, title, description, event, open, characters) {
+ constructor(id, shortId, date, channelName, title, description, eventName, open, characters) {
this.id = id
this.shortId = shortId
this.date = new Date(date)
this.channelName = channelName
this.title = title || null
this.description = description || null
- this.event = event || null
+ this.eventName = eventName || null
this.open = open
this.characters = characters.map(ch => new LogHeaderCharacter(ch.id, ch.name, ch.shortName, ch.author))
}
@@ -76,7 +76,7 @@ const logHeaderApi = {
}
}
`, {filter}).then(({headers}) => {
- return headers.map(h => new LogHeader(h.id, h.shortId, h.date, h.channelName, h.title, h.description, h.event, h.open, h.characters))
+ return headers.map(h => new LogHeader(h.id, h.shortId, h.date, h.channelName, h.title, h.description, h.eventName, h.open, h.characters))
})
},
}