Gisle Aune
6 years ago
20 changed files with 329 additions and 11 deletions
-
2marko/components/compact-list-property/index.marko
-
4marko/components/compact-list-property/style.less
-
3marko/components/toggle/style.less
-
6marko/page/data/channels.marko
-
50marko/page/data/components/add-channel-modal/component.js
-
24marko/page/data/components/add-channel-modal/index.marko
-
5marko/page/data/components/channel-list/index.marko
-
20marko/page/data/components/channel/component.js
-
10marko/page/data/components/channel/index.marko
-
34marko/page/data/components/channels-page/component.js
-
5marko/page/data/components/channels-page/index.marko
-
2marko/page/data/components/character/index.marko
-
2marko/page/data/components/characters-page/component.js
-
8marko/page/data/components/data-menu/index.marko
-
57marko/page/data/components/edit-channel-modal/component.js
-
21marko/page/data/components/edit-channel-modal/index.marko
-
2marko/page/data/components/edit-character-modal/index.marko
-
15routes/data/channels.js
-
69rpdata/api/Channel.js
-
1server.js
@ -1,4 +1,4 @@ |
|||
<td class=["compact-list-property", input.short ? "short" : null, input.long ? "long" : null]> |
|||
<div class="label color-menu">${input.label}</div> |
|||
<div class=["value", input.primary ? "color-primary" : "color-text"]>${input.value}</div> |
|||
<div class=["value", input.primary ? "color-primary" : "color-text", input.weak ? "weak" : null] title=input.title>${input.value}</div> |
|||
</td> |
@ -0,0 +1,6 @@ |
|||
<include("../layout", {title: "Data", site: "data"})> |
|||
<@body> |
|||
<background src="/assets/images/bg.png" opacity=0.25 /> |
|||
<channels-page user=input.user channels=input.channels selected=input.selected /> |
|||
</@body> |
|||
</include> |
@ -0,0 +1,50 @@ |
|||
const moment = require("moment") |
|||
|
|||
const {channelApi} = require("../../../../../rpdata/api/Channel") |
|||
|
|||
module.exports = class { |
|||
onCreate(input) { |
|||
this.state = { |
|||
error: null, |
|||
loading: false, |
|||
values: { |
|||
name: "", |
|||
locationName: "", |
|||
eventName: "", |
|||
logged: false, |
|||
} |
|||
} |
|||
} |
|||
|
|||
change(key, ev) { |
|||
this.state.values = Object.assign({}, this.state.values, {[key]: ev.target.value}) |
|||
} |
|||
|
|||
open() { |
|||
|
|||
} |
|||
|
|||
close() { |
|||
this.emit("close") |
|||
} |
|||
|
|||
save() { |
|||
if (this.state.loading) { |
|||
return |
|||
} |
|||
|
|||
const input = Object.assign({}, this.state.values) |
|||
|
|||
this.state.loading = true |
|||
channelApi.add(input).then((res) => { |
|||
this.emit("added", res) |
|||
this.emit("close") |
|||
}).catch(errs => { |
|||
console.warn("Failed to add:", errs) |
|||
|
|||
this.state.error = "Failed to add: " + JSON.stringify(errs) |
|||
}).then(() => { |
|||
this.state.loading = false |
|||
}) |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") > |
|||
<h1>Add Channel</h1> |
|||
|
|||
<p class="color-error">${state.error}</p> |
|||
|
|||
<label>Name</label> |
|||
<input key="name" placeholder="(Required)" class="big" on-change("change", "name") value=state.values.name /> |
|||
|
|||
<label>Event Name</label> |
|||
<input key="eventName" placeholder="(None)" on-change("change", "eventName") value=state.values.eventName /> |
|||
|
|||
<label>Location Name</label> |
|||
<input key="locationName" placeholder="(None)" on-change("change", "locationName") value=state.values.locationName /> |
|||
|
|||
<label>Logged</label> |
|||
<toggle value=state.values.logged on="On" off="Off" |
|||
onDesc="Log new posts in this channel." |
|||
offDesc="The logbot will not monitor this channel." |
|||
on-change("change", "logged") /> |
|||
|
|||
<p class="color-danger" if(state.values.logged)>The logbot is not yet available, so this does nothing right now.</p> |
|||
|
|||
<button disabled=state.loading on-click("save")>Save</button> |
|||
</modal> |
@ -0,0 +1,5 @@ |
|||
<compact-list> |
|||
<compact-list-item for(channel in input.channels) key=(channel.name.replace("'", "_APOS_"))> |
|||
<channel data=channel on-edited("emit", "edited", channel)/> |
|||
</compact-list-item> |
|||
</compact-list> |
@ -0,0 +1,20 @@ |
|||
module.exports = class { |
|||
onCreate() { |
|||
this.state = { |
|||
modal: null, |
|||
deleted: false, |
|||
} |
|||
} |
|||
|
|||
open(modal) { |
|||
this.state.modal = modal |
|||
} |
|||
|
|||
close() { |
|||
this.state.modal = null |
|||
} |
|||
|
|||
removed() { |
|||
this.state.deleted = true |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
<if (!state.deleted)> |
|||
<compact-list-property primary label="Name" value=input.data.name /> |
|||
<compact-list-property label="Event" weak=(input.data.eventName === "") value=(input.data.eventName || "None") /> |
|||
<compact-list-property long label="Location" weak=(input.data.locationName === "") value=(input.data.locationName || "None") /> |
|||
<compact-list-property short weak=!input.data.logged short label="Logged" value=(input.data.logged ? "On" : "Off") /> |
|||
<compact-list-options> |
|||
<a on-click("open", "edit")>Edit</a> |
|||
</compact-list-options> |
|||
<edit-channel-modal enabled=(state.modal === "edit") channel=input.data on-edited("emit", "edited") on-close("close") /> |
|||
</if> |
@ -0,0 +1,34 @@ |
|||
module.exports = class { |
|||
onCreate(input) { |
|||
this.state = { |
|||
channels: input.channels, |
|||
modal: null, |
|||
} |
|||
} |
|||
|
|||
open(modal) { |
|||
this.state.modal = modal |
|||
} |
|||
|
|||
close() { |
|||
this.state.modal = null |
|||
} |
|||
|
|||
channelEdited(channel, patch) { |
|||
const channels = this.state.channels.slice() |
|||
const index = channels.findIndex(c => c.name === channel.name) |
|||
if (index === -1) { |
|||
return |
|||
} |
|||
|
|||
channels[index] = Object.assign({}, channels[index], patch) |
|||
|
|||
this.state.channels = channels |
|||
|
|||
console.log(channels[index]) |
|||
} |
|||
|
|||
channelAdded(channel) { |
|||
this.state.channels = this.state.channels.concat(channel).sort((a,b) => a.name.localeCompare(b.name)) |
|||
} |
|||
} |
@ -0,0 +1,5 @@ |
|||
<data-menu categories=input.categories selected=(input.selected || {}) user=input.user on-open("open") /> |
|||
<main> |
|||
<channel-list channels=state.channels on-edited("channelEdited") /> |
|||
</main> |
|||
<add-channel-modal enabled=(state.modal === "channel.add") user=input.user on-added("channelAdded") on-close("close") /> |
@ -1,9 +1,9 @@ |
|||
<menu user=input.user> |
|||
<menu-header>List</menu-header> |
|||
<menu-link key="characters" selected=input.selected.characters icon="C" href="/data/characters/">Characters</menu-link> |
|||
<menu-link key="channels" selected=input.selected.channels icon="#" href="/data/characters/">Channels</menu-link> |
|||
<menu-link key="channels" selected=input.selected.channels icon="#" href="/data/channels/">Channels</menu-link> |
|||
<menu-gap /> |
|||
<menu-header>Options</menu-header> |
|||
<menu-link dark key="characters_add" icon="+" on-click("emit", "open", "character.add")>Add Character</menu-link> |
|||
<menu-link dark key="channels_add" icon="+" on-click("emit", "open", "channel.add")>Add Channel</menu-link> |
|||
<menu-header>Add</menu-header> |
|||
<menu-link dark key="characters_add" icon="+" on-click("emit", "open", "character.add")>Character</menu-link> |
|||
<menu-link dark key="channels_add" icon="+" on-click("emit", "open", "channel.add")>Channel</menu-link> |
|||
</menu> |
@ -0,0 +1,57 @@ |
|||
const moment = require("moment") |
|||
|
|||
const {channelApi} = require("../../../../../rpdata/api/Channel") |
|||
|
|||
module.exports = class { |
|||
onCreate(input) { |
|||
this.state = { |
|||
error: null, |
|||
loading: false, |
|||
values: { |
|||
locationName: "", |
|||
eventName: "", |
|||
logged: false, |
|||
} |
|||
} |
|||
} |
|||
|
|||
change(key, ev) { |
|||
this.state.values = Object.assign({}, this.state.values, {[key]: ev.target.value}) |
|||
} |
|||
|
|||
onInput(input) { |
|||
this.state.values = { |
|||
eventName: input.channel.eventName, |
|||
locationName: input.channel.locationName, |
|||
logged: input.channel.logged, |
|||
} |
|||
} |
|||
|
|||
open() { |
|||
|
|||
} |
|||
|
|||
close() { |
|||
this.emit("close") |
|||
} |
|||
|
|||
save() { |
|||
if (this.state.loading) { |
|||
return |
|||
} |
|||
|
|||
const input = Object.assign({name: this.input.channel.name}, this.state.values) |
|||
|
|||
this.state.loading = true |
|||
channelApi.edit(input).then((res) => { |
|||
this.emit("edited", res) |
|||
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 |
|||
}) |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") > |
|||
<h1>Edit ${input.channel.name}</h1> |
|||
|
|||
<p class="color-error">${state.error}</p> |
|||
|
|||
<label>Event Name</label> |
|||
<input key="eventName" placeholder="(None)" on-change("change", "eventName") value=state.values.eventName /> |
|||
|
|||
<label>Location Name</label> |
|||
<input key="locationName" placeholder="(None)" on-change("change", "locationName") value=state.values.locationName /> |
|||
|
|||
<label>Logged</label> |
|||
<toggle value=state.values.logged on="On" off="Off" |
|||
onDesc="Log new posts in this channel." |
|||
offDesc="The logbot will not monitor this channel." |
|||
on-change("change", "logged") /> |
|||
|
|||
<p class="color-danger" if(state.values.logged)>The logbot is not yet available, so this does nothing right now.</p> |
|||
|
|||
<button disabled=state.loading on-click("save")>Save</button> |
|||
</modal> |
@ -0,0 +1,15 @@ |
|||
const express = require("express") |
|||
const router = express.Router() |
|||
|
|||
const {channelApi} = require("../../rpdata/api/Channel") |
|||
|
|||
const channelsTemplate = require("../../marko/page/data/channels.marko") |
|||
|
|||
router.get("/", async(req, res) => { |
|||
res.markoAsync(channelsTemplate, { |
|||
channels: channelApi.list(), |
|||
selected: { channels: true }, |
|||
}) |
|||
}) |
|||
|
|||
module.exports = router |
Write
Preview
Loading…
Cancel
Save
Reference in new issue