Skip to content
Permalink
Browse files

Show previous event themes

  • Loading branch information...
local-minimum committed Jan 28, 2018
1 parent c756f03 commit 8fbcdbef083104c3e8d978bad501139383bfa4ce
@@ -182,6 +182,9 @@ function SetupEvent()
nodeMeta_Add($event_nodeid, 0, SH_SCOPE_PUBLIC, 'event-start', $formatStart);
nodeMeta_Add($event_nodeid, 0, SH_SCOPE_PUBLIC, 'event-end', $formatEnd);

// Add metadata number of theme-ideas per user
nodeMeta_Add($event_nodeid, 0, SH_SCOPE_PUBLIC, 'theme-idea-limit', random_int(3, 5));

// Create metadata for grading
nodeMeta_Add($event_nodeid, 0, SH_SCOPE_PUBLIC, 'grade-01', 'Overall');
nodeMeta_Add($event_nodeid, 0, SH_SCOPE_PUBLIC, 'grade-02', 'Silliness');
@@ -3,7 +3,9 @@ import NavSpinner from 'com/nav-spinner/spinner';
import SVGIcon from 'com/svg-icon/icon';
import UIButton from 'com/ui/button/button';
import $ThemeIdea from '../../shrub/js/theme/theme_idea';
import $Node from 'shrub/js/node/node';

const SHOW_PREVIOUS = 6;

const canHaveMoreIdeas = (ideas, submitting, max) => Object.keys(ideas).length + (submitting ? 1 : 0) < max;
const hasSubmittedIdeas = (ideas) => Object.keys(ideas).length > 0;
@@ -15,6 +17,7 @@ export default class ContentEventIdea extends Component {
this.state = {
'idea': '',
'ideas': null,
'previousThemes': [],
'enableSubmit': false,
'maxIdeas': props.node.meta && props.node.meta['theme-idea-limit'] ? props.node.meta['theme-idea-limit'] : 0,
};
@@ -27,6 +30,8 @@ export default class ContentEventIdea extends Component {
}

componentDidMount() {
this.getPreviousEventThemes();

$ThemeIdea.GetMy([this.props.node.id])
.then(r => {
//console.log(r);
@@ -42,6 +47,26 @@ export default class ContentEventIdea extends Component {
});
}

getPreviousEventThemes() {
//TODO: Handle more than 50 events with offsets
$Node.GetFeed(this.props.node.parent, 'parent', 'event', null, null, null, null, 50)
.then((r) => {
const events = r.feed.map((e) => (e.id));
$Node.Get(events).then((r2) => {
const eventThemes = r2.node
.sort((n) => (n.meta['event-start']))
.filter((n) => n.id !== this.props.node.id)
.reverse()
.map((n) => {
return {'id': n.id, 'start': n.meta['event-start'], 'theme': n.meta['event-theme'], 'name': n.name};
});
this.setState({'previousThemes': eventThemes});
})
.catch((err) => (this.setState({'error': "Could not retrieve previous events."})));
})
.catch((err) => (this.setState({'error': "Could not find list of previous events."})));
}

textChange( e, isSubmit ) {
let idea = e.target.value;
if (isSubmit) {
@@ -133,7 +158,7 @@ export default class ContentEventIdea extends Component {
return Object.keys(this.state.ideas).map(this.renderIdea);
}

render( {node, user/*, path, extra*/}, {idea, ideas, error, enableSubmit, maxIdeas} ) {
render( {node, user/*, path, extra*/}, {idea, ideas, error, enableSubmit, maxIdeas, previousThemes} ) {
if ( node.slug && ideas ) {
if ( user && user['id'] ) {
if (maxIdeas == 0) {
@@ -144,6 +169,30 @@ export default class ContentEventIdea extends Component {
</div>
);
}
let ShowPrevious = null;
if ( previousThemes && previousThemes.length > 0 ) {
const ShowThemeList = previousThemes.slice(0, SHOW_PREVIOUS).map((prevEvent) => {
let Theme = null;
if ( prevEvent.theme ) {
Theme = <div class="event-theme">{prevEvent.theme}</div>;
}
else {
Theme = <div class="event-no-theme">Event did not have a theme</div>;
}
return (
<div class="previous-theme previous-theme-item" key={prevEvent.id}>
<div class="event-name">{prevEvent.name}</div>
{Theme}
</div>
);
});
ShowPrevious = (
<div class="previous-theme">
<h4>Previous Themes</h4>
{ShowThemeList}
</div>
);
}
const ShowError = error ? <div class="content-base content-post idea-error">{error}</div> : null;
let ShowSubmit = null;
if (enableSubmit) {
@@ -181,6 +230,7 @@ export default class ContentEventIdea extends Component {
return (
<div class="idea-body">
<h3>Theme Suggestion Round</h3>
{ShowPrevious}
<h4>Your Suggestions</h4>
{ShowMySuggestions}
{ShowSubmit}
@@ -8,6 +8,31 @@
padding: 0.5em;
}

& > .previous-theme {
& > .previous-theme-item {
margin: 0.25em 1em;

& > .event-name {
background: @COL_G;
color: @COL_L;
display: inline-block;
padding: 0.5em 1em;
}

& > .event-theme {
margin-left: 1em;
display: inline-block;
}

& > .event-no-theme {
margin-left: 1em;
font-style: italic;
display: inline-block;
color: @COL_A;
}
}
}

& > .idea-form {
max-width: 30em;
margin-top: 0.5em;
@@ -182,7 +182,7 @@ export function Walk( parent, slugs ) {
return Fetch.Get(API_ENDPOINT+'/vx/node/walk/'+parent+'/'+slugs.join('/'), true);
}

export function GetFeed( id, methods, types, subtypes, subsubtypes, tags, more, limit ) {
export function GetFeed( id, methods, types, subtypes, subsubtypes, tags, offset, limit ) {
let args = [];

args.push(id);
@@ -227,8 +227,8 @@ export function GetFeed( id, methods, types, subtypes, subsubtypes, tags, more,
}
}

if ( more ) {
query.push("offset="+more);
if ( offset ) {
query.push("offset="+offset);
}
if ( limit ) {
query.push("limit="+limit);

0 comments on commit 8fbcdbe

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.