logs, logs-content: Added basic view of logs and added characters to logs

This commit is contained in:
2018-09-29 13:38:18 +02:00
parent 35cee41d3a
commit ed01006b21
27 changed files with 442 additions and 13 deletions
+17
View File
@@ -0,0 +1,17 @@
const {query} = require("../client")
class Channel {
constructor(name, logged, hub, eventName, locationName) {
this.name = name
this.logged = logged
this.hub = hub
this.eventName = eventName
this.locationName = locationName
}
static fromData(data) {
return new Channel(data.name, data.logged, data.hub, data.eventName, data.locationName)
}
}
module.exports = { Channel }
+27 -2
View File
@@ -1,5 +1,30 @@
const {query} = require("../client")
class Character {
}
/**
* @param {string} id
* @param {string[]} nicks
* @param {string} author
* @param {string} name
* @param {string} shortName
* @param {string} description
*/
constructor(id, nicks, author, name, shortName, description) {
this.id = id
this.nicks = nicks
this.nick = this.nicks[0] || null
this.author = author
this.name = name
this.shortName = shortName
this.description = description
}
/**
* Create a character object from data.
*/
static fromData(data) {
return new Character(data.id, data.nicks, data.author, data.name, data.shortName, data.description)
}
}
module.exports = { Character }
+81
View File
@@ -0,0 +1,81 @@
const {query} = require("../client")
const {Character} = require("./Character")
const {Channel} = require("./Channel")
const {Post} = require("./Post")
class Log {
/**
* @param {string} id
* @param {string} shortId
* @param {Date | string | number} date
* @param {string} title
* @param {string} eventName
* @param {string} description
* @param {string} open
* @param {any} channel
* @param {any[]} characters
* @param {any[]} posts
*/
constructor(id, shortId, date, title, eventName, description, open, channel, characters, posts) {
this.id = id
this.shortId = shortId
this.date = date
this.title = title
this.eventName = eventName
this.description = description
this.open = open
this.channel = Channel.fromData(channel)
this.characters = characters.map(c => Character.fromData(c))
this.posts = posts.map(p => Post.fromData(p))
}
static fromData(data) {
return new Log(data.id, data.shortId, data.date, data.title, data.eventName, data.description, data.open, data.channel, data.characters, data.posts)
}
}
const logsApi = {
find(id) {
return query(`
query FindLog($id: String!) {
log(id: $id) {
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
}
}
}
`, {id}).then(({log}) => {
return Log.fromData(log)
})
},
}
module.exports = { Log, logsApi }
+26
View File
@@ -0,0 +1,26 @@
const {query} = require("../client")
class Post {
/**
* @param {string} id
* @param {number} position
* @param {Date | string | number} time
* @param {string} kind
* @param {string} nick
* @param {string} text
*/
constructor(id, position, time, kind, nick, text) {
this.id = id
this.position = position
this.time = new Date(time)
this.kind = kind
this.nick = nick
this.text = text
}
static fromData(data) {
return new Post(data.id, data.position, data.time, data.kind, data.nick, data.text)
}
}
module.exports = {Post}