Changes
+All changes to listed resources is stored for 90 days for transparency reasons. The current state of an object after each change exists, but is only available through the GraphQL API at this time.
+diff --git a/build.js b/build.js
index f2a2f7a..9c2edb0 100644
--- a/build.js
+++ b/build.js
@@ -11,6 +11,7 @@ prebuild.run({
"./marko/page/logs/list.marko",
"./marko/page/data/channels.marko",
"./marko/page/data/characters.marko",
+ "./marko/page/data/changes.marko",
"./marko/page/story-content/view.marko",
"./marko/page/logs-content/view.marko",
]
diff --git a/marko/page/data/changes.marko b/marko/page/data/changes.marko
new file mode 100644
index 0000000..ae0ad56
--- /dev/null
+++ b/marko/page/data/changes.marko
@@ -0,0 +1,6 @@
+
The logbot is not yet available, so this does nothing right now.
- + \ No newline at end of file diff --git a/marko/page/data/components/change/component.js b/marko/page/data/components/change/component.js new file mode 100644 index 0000000..c88926a --- /dev/null +++ b/marko/page/data/components/change/component.js @@ -0,0 +1,115 @@ +const moment = require("moment") + +module.exports = class { + onCreate() { + this.state = { + operation: "", + links: [], + parentLink: null, + } + } + + onInput(input) { + if (input.data) { + this.refresh(input.data) + } + } + + refresh(data) { + this.state.links = [] + this.state.operation = opText[data.op] + this.state.parentLink = null + + switch (data.model) { + case "Channel": { + const key = data.keys.find(k => k.id !== "*") + + this.state.operation += " channel" + this.state.links = [{ + text: key.id, + href: `/data/channels/`, + }] + + break + } + + case "Character": { + const character = data.objects.find(o => o.type === "Character") + + this.state.operation += " character" + this.state.links = [{ + text: `${character.name} (${character.id})`, + href: `/data/characters/`, + }] + + break + } + + case "Story": { + const key = data.keys.find(k => k.model === "Story" && k.id !== "*") + const story = data.objects.find(o => o.type === "Story") + + this.state.operation += " story" + this.state.links = [{ + text: story.name, + href: `/story/${key.id}`, + }] + + break + } + + case "Chapter": { + const storyKey = data.keys.find(k => k.model === "Story") + const chapterKey = data.keys.find(k => k.model === "Chapter") + const chapter = data.objects.find(o => o.type === "Chapter") + + this.state.operation += " chapter" + this.state.links = [{ + text: chapter.title, + href: `/story/${storyKey.id}#${chapterKey.id}`, + }] + + break + } + + case "Log": { + const key = data.keys.find(k => k.id !== "*") + + this.state.operation += " log" + this.state.links = [{ + text: key.id, + href: `/logs/${key.id}`, + }] + + break + } + + case "Post": { + const logKey = data.keys.find(k => k.model === "Log") + const postKeys = data.keys.filter(k => k.model === "Post") + const postObjs = data.objects.filter(o => o.type === "Post") + + this.state.operation += (postKeys.length > 1) ? " posts" : " post" + this.state.links = postObjs.map(po => ({ + text: `[${moment(po.time).format("HH:mm")}] ${po.nick}`, + href: `/logs/${logKey.id}#${po.id}`, + })) + this.state.parentLink = { + prefix: "in log", + text: `${logKey.id}`, + href: `/logs/${logKey.id}`, + } + + break + } + } + } +} + +const opText = { + add: "added", + remove: "removed", + move: "moved", + edit: "edited", + import: "imported", +} \ No newline at end of file diff --git a/marko/page/data/components/change/index.marko b/marko/page/data/components/change/index.marko new file mode 100644 index 0000000..867a524 --- /dev/null +++ b/marko/page/data/components/change/index.marko @@ -0,0 +1,15 @@ +import moment from "moment"; + +All changes to listed resources is stored for 90 days for transparency reasons. The current state of an object after each change exists, but is only available through the GraphQL API at this time.
+The logbot is not yet available, so this does nothing right now.
- \ No newline at end of file diff --git a/routes/data/changes.js b/routes/data/changes.js new file mode 100644 index 0000000..fc5e79d --- /dev/null +++ b/routes/data/changes.js @@ -0,0 +1,15 @@ +const express = require("express") +const router = express.Router() + +const {changesApi} = require("../../rpdata/api/Change") + +const changesTemplate = require("../../marko/page/data/changes.marko") + +router.get("/", async(req, res) => { + res.markoAsync(changesTemplate, { + changes: changesApi.list(), + selected: {changes: true}, + }) +}) + +module.exports = router diff --git a/rpdata/api/Change.js b/rpdata/api/Change.js new file mode 100644 index 0000000..e84bf68 --- /dev/null +++ b/rpdata/api/Change.js @@ -0,0 +1,81 @@ +const {query} = require("../client") + +class Change { + /** + * @param {string} id + * @param {string} model + * @param {string} op + * @param {string} author + * @param {Date | string | number} date + * @param {{model:string,id:string}[]} keys ' + * @param {{type:string, [x:string]:any}[]} objects + */ + constructor(id, model, op, author, date, keys, objects) { + this.id = id + this.model = model + this.op = op + this.author = author + this.date = date + this.keys = keys + this.objects = objects + } + + static fromData(data) { + return new Change(data.id, data.model, data.op, data.author, data.date, data.keys, data.objects) + } +} + +class ChangesAPI { + /** + * Call `channels(filter)` query + * + * @param {{limit:int, keys: {model:string,id:string}[]}} filter + * @returns {Promise