Browse Source

logs-content: Enabled altering of history (added edit options for log posts)

1.0
Gisle Aune 6 years ago
parent
commit
3c35f75f62
  1. 68
      marko/page/logs-content/components/edit-post-modal/component.js
  2. 26
      marko/page/logs-content/components/edit-post-modal/index.marko
  3. 4
      marko/page/logs-content/components/page/component.js
  4. 1
      marko/page/logs-content/components/page/index.marko
  5. 4
      marko/page/logs-content/components/post/component.js
  6. 3
      marko/page/logs-content/components/post/index.marko
  7. 22
      rpdata/api/Post.js

68
marko/page/logs-content/components/edit-post-modal/component.js

@ -0,0 +1,68 @@
const moment = require("moment")
const {postApi} = require("../../../../../rpdata/api/Post")
module.exports = class {
onCreate(input) {
this.state = {
error: null,
loading: false,
values: {
time: "",
kind: "",
nick: "",
text: "",
},
}
this.first = false
}
onInput(input) {
if (input.post) {
const {kind, nick, text} = input.post
const time = moment.utc(input.post.time).format("YYYY-MM-DD HH:mm:ss")
this.state.values = {time, kind, nick, text}
}
}
change(key, ev) {
this.state.values[key] = ev.target.value
}
open() {
}
close() {
this.first = false
this.emit("close")
}
save() {
if (this.state.loading) {
return
}
const values = this.state.values
let time = new Date(values.time + " UTC")
if (Number.isNaN(time)) {
this.state.error = `Could not parse ${values.time} as date`
return
}
const input = {id: this.input.post.id, time, kind: this.state.values.kind, nick: this.state.values.nick, text: this.state.values.text}
this.state.loading = true
postApi.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
})
}
}

26
marko/page/logs-content/components/edit-post-modal/index.marko

@ -0,0 +1,26 @@
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") >
<h1>Edit Post ${input.post.position}</h1>
<p key="error" class="color-error">${state.error}</p>
<label>Timestamp</label>
<input key="time" placeholder="Title" class="big" on-change("change", "time") value=state.values.time />
<label>Kind</label>
<select key="kind" class="big" placeholder="Kind" on-change("change", "kind") value=state.values.kind>
<option value="text" selected=(state.values.kind === "text")>Text (text, /npc)</option>
<option value="action" selected=(state.values.kind === "action")>Action (/me, /npca)</option>
<option value="scene" selected=(state.values.kind === "scene")>Scene (/scene)</option>
<option value="annotation.info" selected=(state.values.kind === "annotation.info")>Annotation - Info</option>
<option value="annotation.warning" selected=(state.values.kind === "annotation.warning")>Annotation - Warning</option>
<option value="annotation.error" selected=(state.values.kind === "annotation.error")>Annotation - Error</option>
</select>
<label>Nick</label>
<input key="nick" placeholder="IRC_Nick (You can use non-IRC letters here, like ', but I recommend you don't so the character is found)" class="big" on-change("change", "nick") value=state.values.nick />
<label>Text</label>
<textarea key="text" placeholder="Text" class="tall" on-change("change", "text") value=state.values.text />
<button disabled=state.loading on-click("save")>Alter History</button>
</modal>

4
marko/page/logs-content/components/page/component.js

@ -70,6 +70,10 @@ module.exports = class {
})
}
postEdited(post) {
this.patch([post])
}
get title() {
if (this.state.log.title) {
return this.state.log.title

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

@ -6,6 +6,7 @@
key=post.id
on-move("movePost", post)
on-remove("removePost", post)
on-edited("postEdited")
post=post
characters=state.log.characters
last=(post.position === state.log.posts.length)

4
marko/page/logs-content/components/post/component.js

@ -29,6 +29,10 @@ module.exports = class {
this.emit("remove")
}
edited(data) {
this.emit("edited", data)
}
onInput(input) {
if (this.state == null) {
return

3
marko/page/logs-content/components/post/index.marko

@ -3,7 +3,7 @@
<div class="options color-menu">
<a on-click("move", -1, true)>Up</a>
<a on-click("move", +1, true)>Down</a>
<!--<a on-click("open", "edit") >Edit</a>-->
<a on-click("open", "edit") >Edit</a>
<a on-click("open", "remove")>Remove</a>
</div>
<post-meta kind="timestamp" value=input.post.time />
@ -24,4 +24,5 @@
<markdown class="post-content post-text" source=state.text />
</div>
<remove-post-modal enabled=(state.modal === "remove") post=input.post on-close("close") on-remove("remove") />
<edit-post-modal enabled=(state.modal === "edit") post=input.post on-close("close") on-edited("edited") />
</div>

22
rpdata/api/Post.js

@ -43,6 +43,28 @@ class PostAPI {
})
}
/**
* Call `editPost(input)` mutation, returns the id and edited fields of the post
*
* @param {{id:string, time:Date, kind:string, nick:string, text:string}} input
* @returns {Promise<{id:string, time:Date, kind:string, nick:string, text:string}>}
*/
edit(input) {
return query(`
mutation RemovePost($input: PostEditInput!) {
editPost(input: $input) {
id
time
kind
nick
text
}
}
`, {input}, {permissions: ["post.edit"]}).then(({editPost}) => {
return editPost
})
}
/**
* Call `removePost(input)` mutation, returns the id of the affected post.
*

Loading…
Cancel
Save