Vulcan/packages/nova-demo/demo-app.jsx

90 lines
2.1 KiB
React
Raw Normal View History

2016-04-07 20:05:23 +09:00
import React, { PropTypes, Component } from 'react';
2016-02-26 12:04:42 +09:00
import {mount} from 'react-mounter';
2016-03-22 10:22:46 +09:00
import MoviesWrapper from './demo-components.jsx';
2016-04-07 20:05:23 +09:00
import Core from 'meteor/nova:core';
2016-03-22 10:22:46 +09:00
2016-02-26 13:05:12 +09:00
//////////////////////////////////////////////////////
// Collection & Schema //
//////////////////////////////////////////////////////
2016-02-26 12:04:42 +09:00
2016-02-26 13:05:12 +09:00
Movies = new Mongo.Collection("movies");
2016-02-26 12:04:42 +09:00
const isLoggedIn = user => !!user;
const isOwner = (user, document) => user._id === document.userId;
2016-02-26 12:04:42 +09:00
const schema = new SimpleSchema({
name: {
type: String,
publish: true,
control: "text",
insertableIf: isLoggedIn,
editableIf: isOwner
2016-02-26 12:04:42 +09:00
},
createdAt: {
type: Date,
2016-02-26 13:05:12 +09:00
publish: true,
2016-02-26 12:04:42 +09:00
},
year: {
type: String,
publish: true,
optional: true,
control: "text",
insertableIf: isLoggedIn,
editableIf: isOwner
2016-02-26 12:04:42 +09:00
},
review: {
type: String,
publish: true,
control: "textarea",
insertableIf: isLoggedIn,
editableIf: isOwner
2016-02-26 12:04:42 +09:00
},
userId: {
type: String,
2016-02-28 15:15:18 +09:00
publish: true,
2016-02-26 12:04:42 +09:00
join: {
2016-02-26 13:05:12 +09:00
collection: () => Meteor.users,
joinAs: "user",
fields: ["_id", "username"]
2016-02-26 12:04:42 +09:00
}
}
});
Movies.attachSchema(schema);
//////////////////////////////////////////////////////
// Route //
//////////////////////////////////////////////////////
FlowRouter.route('/demo', {
name: 'demo',
2016-04-07 20:05:23 +09:00
action() {
mount(MoviesWrapper);
}
});
2016-02-26 13:05:12 +09:00
//////////////////////////////////////////////////////
// Methods //
//////////////////////////////////////////////////////
Movies.smartMethods({
2016-04-24 09:36:20 +09:00
createName: "movies.create",
editName: "movies.edit",
createCallback: function (user, document) {
2016-02-26 12:04:42 +09:00
document = _.extend(document, {
createdAt: new Date(),
userId: Meteor.userId()
});
return document;
},
deleteCallback: isOwner
2016-02-26 12:04:42 +09:00
});
2016-02-26 13:05:12 +09:00
//////////////////////////////////////////////////////
// Publications //
//////////////////////////////////////////////////////
2016-02-26 12:04:42 +09:00
if (Meteor.isServer) {
Movies.smartPublish("movies.list");
2016-02-26 12:04:42 +09:00
}