Vulcan/packages/nova-base-components/lib/routes.jsx

256 lines
8.1 KiB
React
Raw Normal View History

2016-02-19 12:27:58 +09:00
import React from 'react';
2016-03-23 11:46:56 +09:00
import Router from './router.js'
2016-02-19 12:27:58 +09:00
import {mount} from 'react-mounter';
2016-04-12 20:09:08 +09:00
import Campaign from 'meteor/nova:newsletter';
2016-02-19 12:27:58 +09:00
2016-03-30 10:52:40 +09:00
import SmartContainers from "meteor/utilities:react-list-container";
const DocumentContainer = SmartContainers.DocumentContainer;
const ListContainer = SmartContainers.ListContainer;
2016-02-17 15:09:49 +09:00
// ------------------------------------- Posts -------------------------------- //
2016-03-23 11:46:56 +09:00
Router.route('/', {
2016-02-18 12:16:32 +09:00
name: 'posts.list',
2016-02-19 12:27:58 +09:00
action(params, queryParams) {
2016-03-30 10:52:40 +09:00
({App, PostList} = Telescope.components);
queryParams = _.isEmpty(queryParams) ? {view: 'new'} : _.clone(queryParams);
({selector, options} = Posts.parameters.get(queryParams));
2016-02-19 12:27:58 +09:00
2016-03-27 16:32:29 +09:00
mount(App, {content:
2016-02-17 17:22:32 +09:00
<ListContainer
collection={Posts}
publication="posts.list"
selector={selector}
options={options}
2016-02-17 17:22:32 +09:00
terms={queryParams}
joins={Posts.getJoins()}
component={PostList}
cacheSubscription={false}
/>})
2016-02-17 15:09:49 +09:00
}
});
2016-03-23 11:46:56 +09:00
Router.route('/daily/:days?', {
name: 'posts.daily',
2016-03-22 10:22:46 +09:00
action(params, queryParams) {
2016-03-27 16:32:29 +09:00
({App, PostDaily} = Telescope.components);
2016-03-22 10:22:46 +09:00
2016-03-27 16:32:29 +09:00
mount(App, {content: <PostDaily days={params.days}/>})
2016-03-22 10:22:46 +09:00
}
});
Router.route('/posts/:_id/:slug?', {
2016-02-18 12:16:32 +09:00
name: 'posts.single',
2016-02-19 12:27:58 +09:00
action(params, queryParams) {
2016-03-30 10:52:40 +09:00
({App, PostPage} = Telescope.components);
2016-03-27 16:32:29 +09:00
mount(App, {content:
2016-03-02 13:54:58 +09:00
<DocumentContainer
collection={Posts}
publication="posts.single"
selector={{_id: params._id}}
2016-02-27 10:58:57 +09:00
terms={params}
joins={Posts.getJoins()}
2016-03-25 11:30:01 +09:00
component={PostPage}
/>});
2016-02-17 15:09:49 +09:00
}
});
2016-03-28 10:55:19 +09:00
// ------------------------------------- Users -------------------------------- //
2016-02-17 15:09:49 +09:00
2016-03-23 11:46:56 +09:00
Router.route('/users/:slug', {
name: 'users.single',
action(params, queryParams) {
2016-03-30 10:52:40 +09:00
({App, UserProfile} = Telescope.components);
2016-03-27 16:32:29 +09:00
mount(App, {content:
2016-03-02 13:54:58 +09:00
<DocumentContainer
collection={Users}
publication="users.single"
2016-02-27 10:58:57 +09:00
selector={{'telescope.slug': params.slug}}
terms={{'telescope.slug': params.slug}}
2016-03-28 12:36:29 +09:00
component={UserProfile}
documentPropName="user"
/>});
}
});
2016-02-23 11:34:40 +09:00
2016-03-23 11:46:56 +09:00
Router.route('/account', {
2016-02-23 11:34:40 +09:00
name: 'account',
action(params, queryParams) {
2016-03-30 10:52:40 +09:00
({App, UserEdit} = Telescope.components);
2016-03-27 16:32:29 +09:00
mount(App, {content:
2016-03-02 13:54:58 +09:00
<DocumentContainer
2016-02-23 11:34:40 +09:00
collection={Users}
publication="users.single"
2016-02-27 10:58:57 +09:00
selector={{_id: Meteor.userId()}}
2016-02-23 11:34:40 +09:00
terms={{_id: Meteor.userId()}}
2016-03-25 12:42:25 +09:00
component={UserEdit}
/>});
2016-02-23 11:34:40 +09:00
}
});
2016-03-23 11:46:56 +09:00
Router.route('/users/:slug/edit', {
2016-02-23 11:34:40 +09:00
name: 'users.edit',
action(params, queryParams) {
2016-03-30 10:52:40 +09:00
({App, UserEdit} = Telescope.components);
2016-03-27 16:32:29 +09:00
mount(App, {content:
2016-03-02 13:54:58 +09:00
<DocumentContainer
2016-02-23 11:34:40 +09:00
collection={Users}
publication="users.single"
2016-02-27 10:58:57 +09:00
selector={params}
2016-02-23 11:34:40 +09:00
terms={params}
2016-03-25 12:42:25 +09:00
component={UserEdit}
/>});
2016-02-23 11:34:40 +09:00
}
});
2016-03-28 10:55:19 +09:00
// ------------------------------------- Other -------------------------------- //
2016-03-23 11:46:56 +09:00
Router.route('/cheatsheet', {
2016-03-19 10:15:36 +09:00
name: 'cheatsheet',
action() {
2016-03-27 16:32:29 +09:00
({App, Cheatsheet} = Telescope.components);
mount(App, {content: <Cheatsheet/>});
2016-03-19 10:15:36 +09:00
}
});
2016-02-23 11:34:40 +09:00
Router.route('/settings', {
name: 'settings',
action() {
({App, Settings} = Telescope.components);
mount(App, {content: <Settings/>});
}
});
2016-04-12 19:36:47 +09:00
Router.route('/emails', {
name: 'emails',
action() {
({App, Emails} = Telescope.components);
mount(App, {content: <Emails/>});
}
});
2016-03-28 10:55:19 +09:00
FlowRouter.notFound = {
action() {
({Error404} = Telescope.components);
mount(App, {content: <Error404/>});
}
2016-04-12 20:09:08 +09:00
};
// ------------------------------------- Emails (Server) -------------------------------- //
Telescope.email.routes = [
{
name: "New Post",
path: "/email/new-post/:_id?",
action: (params, req, res, next) => {
var html;
var post = typeof params.id === "undefined" ? Posts.findOne() : Posts.findOne(params.id);
if (!!post) {
html = Telescope.email.getTemplate('newPost')(Posts.getNotificationProperties(post));
} else {
html = "<h3>No post found.</h3>"
}
res.end(Telescope.email.buildTemplate(html));
}
},
{
name: "Post Approved",
path: "/email/post-approved/:_id?",
action: (params, req, res, next) => {
var html;
var post = typeof params.id === "undefined" ? Posts.findOne() : Posts.findOne(params.id);
if (!!post) {
html = Telescope.email.getTemplate('postApproved')(Posts.getNotificationProperties(post));
} else {
html = "<h3>No post found.</h3>"
}
res.end(Telescope.email.buildTemplate(html));
}
},
{
name: "New Comment",
path: "/email/new-comment/:_id?",
action: (params, req, res, next) => {
var html;
var comment = typeof params.id === "undefined" ? Comments.findOne() : Comments.findOne(params.id);
var post = Posts.findOne(comment.postId);
if (!!comment) {
html = Telescope.email.getTemplate('newComment')(Comments.getNotificationProperties(comment, post));
} else {
html = "<h3>No post found.</h3>"
}
res.end(Telescope.email.buildTemplate(html));
}
},
{
name: "New Reply",
path: "/email/new-reply/:_id?",
action: (params, req, res, next) => {
var html;
var comment = typeof params.id === "undefined" ? Comments.findOne() : Comments.findOne(params.id);
var post = Posts.findOne(comment.postId);
if (!!comment) {
html = Telescope.email.getTemplate('newReply')(Comments.getNotificationProperties(comment, post));
} else {
html = "<h3>No post found.</h3>"
}
res.end(Telescope.email.buildTemplate(html));
}
},
{
name: "New User",
path: "/email/new-user/:_id?",
action: (params, req, res, next) => {
var html;
var user = typeof params.id === "undefined" ? Meteor.users.findOne() : Meteor.users.findOne(params.id);
var emailProperties = {
profileUrl: Users.getProfileUrl(user),
username: Users.getUserName(user)
};
html = Telescope.email.getTemplate('newUser')(emailProperties);
res.end(Telescope.email.buildTemplate(html));
}
},
{
name: "Account Approved",
path: "/email/account-approved/:_id?",
action: (params, req, res, next) => {
var user = typeof params.id === "undefined" ? Meteor.users.findOne() : Meteor.users.findOne(params.id);
var emailProperties = {
profileUrl: Users.getProfileUrl(user),
username: Users.getUserName(user),
siteTitle: Telescope.settings.get('title'),
siteUrl: Telescope.utils.getSiteUrl()
};
var html = Telescope.email.getTemplate('accountApproved')(emailProperties);
res.end(Telescope.email.buildTemplate(html));
}
},
{
name: "Newsletter",
path: "/email/newsletter",
action: (params, req, res, next) => {
var campaign = Campaign.build(Campaign.getPosts(Telescope.settings.get('postsPerNewsletter', 5)));
var newsletterEnabled = '<div class="newsletter-enabled"><strong>Newsletter Enabled:</strong> '+Telescope.settings.get('enableNewsletter', true)+'</div>';
var mailChimpAPIKey = '<div class="mailChimpAPIKey"><strong>mailChimpAPIKey:</strong> '+(typeof Telescope.settings.get('mailChimpAPIKey') !== "undefined")+'</div>';
var mailChimpListId = '<div class="mailChimpListId"><strong>mailChimpListId:</strong> '+(typeof Telescope.settings.get('mailChimpListId') !== "undefined")+'</div>';
var campaignSubject = '<div class="campaign-subject"><strong>Subject:</strong> '+campaign.subject+' (note: contents might change)</div>';
var campaignSchedule = '<div class="campaign-schedule"><strong>Scheduled for:</strong> '+ Meteor.call('getNextJob') +'</div>';
res.end(newsletterEnabled+mailChimpAPIKey+mailChimpListId+campaignSubject+campaignSchedule+campaign.html);
}
},
{
name: "Newsletter Confirmation",
path: "/email/newsletter-confirmation",
action: (params, req, res, next) => {
var confirmationHtml = Telescope.email.getTemplate('newsletterConfirmation')({
time: 'January 1st, 1901',
newsletterLink: 'http://example.com',
subject: 'Lorem ipsum dolor sit amet'
});
res.end(Telescope.email.buildTemplate(confirmationHtml));
}
}
];