Compare commits
4 Commits
newRendere
...
v2.7.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b68c6a4ad2 | ||
|
|
6e0f042b42 | ||
|
|
c47d492ed3 | ||
|
|
18852932e8 |
13
.github/issue_template.md
vendored
@@ -1,5 +1,16 @@
|
|||||||
Share link to issue brew: http://homebrewery.naturalcrit.com/share/XXXXXXX
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Additional Details
|
||||||
|
|
||||||
|
**Share Link** :
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
**Brew code to reproduce** : <details><summary>Click to expand</summary><code><pre>
|
||||||
|
|
||||||
|
PASTE BREW CODE HERE
|
||||||
|
|
||||||
|
</pre></code></details>
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
# changelog
|
# changelog
|
||||||
|
|
||||||
|
### Saturday, 22/04/217 - v2.7.4
|
||||||
|
- Give ability to hide the render warning notification
|
||||||
|
|
||||||
The self-discovery aspect of the snippets isn't working out.
|
|
||||||
|
|
||||||
|
### Friday, 03/03/2017 - v2.7.3
|
||||||
|
- Increasing the range on the Partial Page Rendering for a quick-fix for it getting out of sync on long brews.
|
||||||
|
|
||||||
|
### Saturday, 18/02/2017 - v2.7.2
|
||||||
|
- Adding ability to delete a brew from the user page, incase the user creates a brew that makes the edit page unrender-able. (re:309)
|
||||||
|
|
||||||
## BIG NEWS
|
## BIG NEWS
|
||||||
With the next major release of Homebrewery, v3.0.0, this tool *will no longer support raw HTML input for brew code*. Most issues and errors users are having are because of this feature and it's become too taxing to help and fix these issues.
|
With the next major release of Homebrewery, v3.0.0, this tool *will no longer support raw HTML input for brew code*. Most issues and errors users are having are because of this feature and it's become too taxing to help and fix these issues.
|
||||||
@@ -30,8 +36,7 @@ All brews made previous to the release of v3.0.0 will still render normally.
|
|||||||
- Fixed realtime renderer not functioning if loaded with malformed html on load (thanks u/RattiganIV re:247)
|
- Fixed realtime renderer not functioning if loaded with malformed html on load (thanks u/RattiganIV re:247)
|
||||||
- Removed a lot of unused files in shared
|
- Removed a lot of unused files in shared
|
||||||
- vitreum v4 now lets me use codemirror as a pure node dependacy
|
- vitreum v4 now lets me use codemirror as a pure node dependacy
|
||||||
- Moved the brew editor and renderer into shared, and made a new hybrid component for them
|
|
||||||
- Added a line highlighter to lines with new pages
|
|
||||||
|
|
||||||
|
|
||||||
### Saturday, 03/12/2016 - v2.6.0
|
### Saturday, 03/12/2016 - v2.6.0
|
||||||
@@ -1,41 +1,38 @@
|
|||||||
const React = require('react');
|
var React = require('react');
|
||||||
const _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
var cx = require('classnames');
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
var HomebrewAdmin = require('./homebrewAdmin/homebrewAdmin.jsx');
|
||||||
|
|
||||||
const BrewLookup = require('./brewLookup/brewLookup.jsx');
|
var Admin = React.createClass({
|
||||||
const AdminSearch = require('./adminSearch/adminSearch.jsx');
|
|
||||||
const InvalidBrew = require('./invalidBrew/invalidBrew.jsx');
|
|
||||||
|
|
||||||
const Admin = React.createClass({
|
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
admin_key : '',
|
url : "",
|
||||||
|
admin_key : "",
|
||||||
|
homebrews : [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
renderNavbar : function(){
|
|
||||||
return <Nav.base>
|
|
||||||
<Nav.section>
|
|
||||||
<Nav.item icon='fa-magic' className='homebreweryLogo'>
|
|
||||||
Homebrewery Admin
|
|
||||||
</Nav.item>
|
|
||||||
</Nav.section>
|
|
||||||
</Nav.base>
|
|
||||||
},
|
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
return <div className='admin'>
|
var self = this;
|
||||||
{this.renderNavbar()}
|
return(
|
||||||
<main className='content'>
|
<div className='admin'>
|
||||||
<BrewLookup adminKey={this.props.admin_key} />
|
|
||||||
<AdminSearch adminKey={this.props.admin_key} />
|
|
||||||
|
|
||||||
<div className='dangerZone'>Danger Zone</div>
|
<header>
|
||||||
|
<div className='container'>
|
||||||
<InvalidBrew adminKey={this.props.admin_key} />
|
<i className='fa fa-rocket' />
|
||||||
</main>
|
naturalcrit admin
|
||||||
</div>
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className='container'>
|
||||||
|
|
||||||
|
<HomebrewAdmin homebrews={this.props.homebrews} admin_key={this.props.admin_key} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,53 +1,39 @@
|
|||||||
|
@import 'naturalcrit/styles/reset.less';
|
||||||
|
@import 'naturalcrit/styles/elements.less';
|
||||||
|
@import 'naturalcrit/styles/animations.less';
|
||||||
|
@import 'naturalcrit/styles/colors.less';
|
||||||
|
@import 'naturalcrit/styles/tooltip.less';
|
||||||
|
|
||||||
@import 'naturalcrit/styles/core.less';
|
@import 'font-awesome/css/font-awesome.css';
|
||||||
html,body, #reactRoot{
|
|
||||||
|
html,body, #reactContainer, .naturalCrit{
|
||||||
min-height : 100%;
|
min-height : 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@sidebarWidth : 250px;
|
||||||
|
|
||||||
body{
|
body{
|
||||||
height : 100%;
|
background-color : #eee;
|
||||||
|
font-family : 'Open Sans', sans-serif;
|
||||||
|
color : #4b5055;
|
||||||
|
font-weight : 100;
|
||||||
|
text-rendering : optimizeLegibility;
|
||||||
margin : 0;
|
margin : 0;
|
||||||
padding : 0;
|
padding : 0;
|
||||||
background-color : #ddd;
|
height : 100%;
|
||||||
font-family : 'Open Sans', sans-serif;
|
|
||||||
font-weight : 100;
|
|
||||||
color : #4b5055;
|
|
||||||
text-rendering : optimizeLegibility;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.admin{
|
.admin{
|
||||||
nav {
|
|
||||||
|
header{
|
||||||
background-color : @red;
|
background-color : @red;
|
||||||
.navItem{
|
|
||||||
background-color : @red;
|
|
||||||
}
|
|
||||||
.homebreweryLogo{
|
|
||||||
font-family : CodeBold;
|
|
||||||
font-size : 12px;
|
|
||||||
color : white;
|
|
||||||
div{
|
|
||||||
margin-top : 2px;
|
|
||||||
margin-bottom : -2px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
h1{
|
|
||||||
margin-bottom : 10px;
|
|
||||||
font-size: 2em;
|
font-size: 2em;
|
||||||
font-weight : 800;
|
padding : 20px 0px;
|
||||||
border-bottom : 1px solid #ddd;
|
|
||||||
}
|
|
||||||
main.content{
|
|
||||||
width : 1000px;
|
|
||||||
margin : 0 auto;
|
|
||||||
padding : 50px 20px;
|
|
||||||
background-color : white;
|
|
||||||
.dangerZone{
|
|
||||||
margin : 30px 0px;
|
|
||||||
padding : 10px 20px;
|
|
||||||
background : repeating-linear-gradient(45deg, @yellow, @yellow 10px, darken(#333, 10%) 10px, darken(#333, 10%) 20px);
|
|
||||||
font-size : 1em;
|
|
||||||
font-weight : 800;
|
|
||||||
color : white;
|
color : white;
|
||||||
text-transform : uppercase;
|
margin-bottom: 30px;
|
||||||
|
i{
|
||||||
|
margin-right: 30px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
|
|
||||||
const React = require('react');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const cx = require('classnames');
|
|
||||||
const request = require('superagent');
|
|
||||||
|
|
||||||
const BrewTable = require('../brewTable/brewTable.jsx');
|
|
||||||
|
|
||||||
const LIMIT = 10;
|
|
||||||
|
|
||||||
const AdminSearch = React.createClass({
|
|
||||||
getDefaultProps: function() {
|
|
||||||
return {
|
|
||||||
adminKey : '',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
getInitialState: function() {
|
|
||||||
return {
|
|
||||||
totalBrews : 1,
|
|
||||||
brews: [],
|
|
||||||
|
|
||||||
searching : false,
|
|
||||||
error : null,
|
|
||||||
|
|
||||||
page : 1,
|
|
||||||
searchTerms : ''
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
handleSearch : function(e){
|
|
||||||
this.setState({
|
|
||||||
searchTerms : e.target.value
|
|
||||||
});
|
|
||||||
},
|
|
||||||
handlePage : function(e){
|
|
||||||
this.setState({
|
|
||||||
page : e.target.value
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
search : function(){
|
|
||||||
this.setState({ searching : true, error : null });
|
|
||||||
|
|
||||||
request.get(`/api/brew`)
|
|
||||||
.query({
|
|
||||||
terms : this.state.searchTerms,
|
|
||||||
limit : LIMIT,
|
|
||||||
page : this.state.page - 1
|
|
||||||
})
|
|
||||||
.set('x-homebrew-admin', this.props.adminKey)
|
|
||||||
.end((err, res) => {
|
|
||||||
if(err){
|
|
||||||
this.setState({
|
|
||||||
searching : false,
|
|
||||||
error : err && err.toString()
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
this.setState({
|
|
||||||
brews : res.body.brews,
|
|
||||||
totalBrews : res.body.total
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function(){
|
|
||||||
return <div className='adminSearch'>
|
|
||||||
<h1>Admin Search</h1>
|
|
||||||
<div className='controls'>
|
|
||||||
<input className='search' type='text' value={this.state.searchTerms} onChange={this.handleSearch} />
|
|
||||||
|
|
||||||
<button onClick={this.search}> <i className='fa fa-search' /> search </button>
|
|
||||||
|
|
||||||
|
|
||||||
<div className='page'>
|
|
||||||
page:
|
|
||||||
<input type='text' value={this.state.page} onChange={this.handlePage} />
|
|
||||||
/ {Math.ceil(this.state.totalBrews / LIMIT)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<BrewTable brews={this.state.brews} />
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = AdminSearch;
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
|
|
||||||
.adminSearch{
|
|
||||||
.controls{
|
|
||||||
margin-bottom : 20px;
|
|
||||||
input.search{
|
|
||||||
height : 33px;
|
|
||||||
padding : 10px;
|
|
||||||
}
|
|
||||||
.page {
|
|
||||||
float : right;
|
|
||||||
font-weight : 800;
|
|
||||||
input{
|
|
||||||
width : 20px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
.brewLookup{
|
|
||||||
height : 200px;
|
|
||||||
input{
|
|
||||||
height : 33px;
|
|
||||||
margin-bottom : 20px;
|
|
||||||
padding : 0px 10px;
|
|
||||||
}
|
|
||||||
.error{
|
|
||||||
font-weight : 800;
|
|
||||||
color : @red;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
const React = require('react');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const cx = require('classnames');
|
|
||||||
|
|
||||||
const Moment = require('moment');
|
|
||||||
|
|
||||||
//TODO: Add in delete
|
|
||||||
|
|
||||||
const BrewTable = React.createClass({
|
|
||||||
getDefaultProps: function() {
|
|
||||||
return {
|
|
||||||
brews : []
|
|
||||||
};
|
|
||||||
},
|
|
||||||
renderRows : function(){
|
|
||||||
return _.map(this.props.brews, (brew) => {
|
|
||||||
let authors = 'None.';
|
|
||||||
if(brew.authors && brew.authors.length) authors = brew.authors.join(', ');
|
|
||||||
|
|
||||||
return <tr className={cx('brewRow', {'isEmpty' : brew.text == "false"})} key={brew.shareId || brew}>
|
|
||||||
<td>{brew.title}</td>
|
|
||||||
<td>{authors}</td>
|
|
||||||
<td><a href={'/edit/' + brew.editId} target='_blank'>{brew.editId}</a></td>
|
|
||||||
<td><a href={'/share/' + brew.shareId} target='_blank'>{brew.shareId}</a></td>
|
|
||||||
<td>{Moment(brew.updatedAt).fromNow()}</td>
|
|
||||||
<td>{brew.views}</td>
|
|
||||||
<td className='deleteButton'>
|
|
||||||
<i className='fa fa-trash' />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
});
|
|
||||||
},
|
|
||||||
render: function(){
|
|
||||||
return <table className='brewTable'>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Title</th>
|
|
||||||
<th>Authors</th>
|
|
||||||
<th>Edit Link</th>
|
|
||||||
<th>Share Link</th>
|
|
||||||
<th>Last Updated</th>
|
|
||||||
<th>Views</th>
|
|
||||||
<th>Remove</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{this.renderRows()}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = BrewTable;
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
|
|
||||||
table.brewTable{
|
|
||||||
th{
|
|
||||||
padding : 10px;
|
|
||||||
background-color : fade(@blue, 20%);
|
|
||||||
font-weight : 800;
|
|
||||||
}
|
|
||||||
tr:nth-child(even){
|
|
||||||
background-color : fade(@green, 10%);
|
|
||||||
}
|
|
||||||
tr.isEmpty{
|
|
||||||
background-color : fade(@red, 30%);
|
|
||||||
}
|
|
||||||
td{
|
|
||||||
min-width : 100px;
|
|
||||||
padding : 10px;
|
|
||||||
text-align : center;
|
|
||||||
|
|
||||||
/*
|
|
||||||
&.preview{
|
|
||||||
position : relative;
|
|
||||||
&:hover{
|
|
||||||
.content{
|
|
||||||
display : block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.content{
|
|
||||||
position : absolute;
|
|
||||||
display : none;
|
|
||||||
top : 100%;
|
|
||||||
left : 0px;
|
|
||||||
z-index : 1000;
|
|
||||||
max-height : 500px;
|
|
||||||
width : 300px;
|
|
||||||
padding : 30px;
|
|
||||||
background-color : white;
|
|
||||||
font-family : monospace;
|
|
||||||
text-align : left;
|
|
||||||
pointer-events : none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,8 @@ const _ = require('lodash');
|
|||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
|
||||||
const request = require('superagent');
|
const request = require('superagent');
|
||||||
const BrewTable = require('../brewTable/brewTable.jsx');
|
const Moment = require('moment');
|
||||||
|
|
||||||
|
|
||||||
const BrewLookup = React.createClass({
|
const BrewLookup = React.createClass({
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
@@ -15,8 +16,7 @@ const BrewLookup = React.createClass({
|
|||||||
return {
|
return {
|
||||||
query:'',
|
query:'',
|
||||||
resultBrew : null,
|
resultBrew : null,
|
||||||
searching : false,
|
searching : false
|
||||||
error : null
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -26,14 +26,13 @@ const BrewLookup = React.createClass({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
lookup : function(){
|
lookup : function(){
|
||||||
this.setState({ searching : true, error : null });
|
this.setState({ searching : true });
|
||||||
|
|
||||||
request.get(`/admin/lookup/${this.state.query}`)
|
request.get(`/admin/lookup/${this.state.query}`)
|
||||||
.set('x-homebrew-admin', this.props.adminKey)
|
.query({ admin_key : this.props.adminKey })
|
||||||
.end((err, res) => {
|
.end((err, res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
searching : false,
|
searching : false,
|
||||||
error : err && err.toString(),
|
|
||||||
resultBrew : (err ? null : res.body)
|
resultBrew : (err ? null : res.body)
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -43,31 +42,14 @@ const BrewLookup = React.createClass({
|
|||||||
if(this.state.searching) return <div className='searching'><i className='fa fa-spin fa-spinner' /></div>;
|
if(this.state.searching) return <div className='searching'><i className='fa fa-spin fa-spinner' /></div>;
|
||||||
if(!this.state.resultBrew) return <div className='noBrew'>No brew found.</div>;
|
if(!this.state.resultBrew) return <div className='noBrew'>No brew found.</div>;
|
||||||
|
|
||||||
return <BrewTable brews={[this.state.resultBrew ]} />
|
|
||||||
|
|
||||||
/*
|
|
||||||
const brew = this.state.resultBrew;
|
const brew = this.state.resultBrew;
|
||||||
return <div className='brewRow'>
|
return <div className='brewRow'>
|
||||||
<div>{brew.title}</div>
|
<div>{brew.title}</div>
|
||||||
<div>{brew.authors.join(', ')}</div>
|
<div>{brew.authors.join(', ')}</div>
|
||||||
<div><a href={'/edit/' + brew.editId} target='_blank'>{brew.editId}</a></div>
|
<div><a href={'/edit/' + brew.editId} target='_blank'>/edit/{brew.editId}</a></div>
|
||||||
<div><a href={'/share/' + brew.shareId} target='_blank'>{brew.shareId}</a></div>
|
<div><a href={'/share/' + brew.shareId} target='_blank'>/share/{brew.shareId}</a></div>
|
||||||
<div>{Moment(brew.updatedAt).fromNow()}</div>
|
<div>{Moment(brew.updatedAt).fromNow()}</div>
|
||||||
<div>{brew.views}</div>
|
<div>{brew.views}</div>
|
||||||
<div>
|
|
||||||
<div className='deleteButton'>
|
|
||||||
<i className='fa fa-trash' />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
*/
|
|
||||||
},
|
|
||||||
|
|
||||||
renderError : function(){
|
|
||||||
if(!this.state.error) return;
|
|
||||||
|
|
||||||
return <div className='error'>
|
|
||||||
{this.state.error}
|
|
||||||
</div>
|
</div>
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -78,7 +60,6 @@ const BrewLookup = React.createClass({
|
|||||||
<button onClick={this.lookup}><i className='fa fa-search'/></button>
|
<button onClick={this.lookup}><i className='fa fa-search'/></button>
|
||||||
|
|
||||||
{this.renderFoundBrew()}
|
{this.renderFoundBrew()}
|
||||||
{this.renderError()}
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
8
client/admin/homebrewAdmin/brewLookup/brewLookup.less
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
.brewLookup{
|
||||||
|
height : 200px;
|
||||||
|
input{
|
||||||
|
height : 33px;
|
||||||
|
padding : 0px 10px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
72
client/admin/homebrewAdmin/brewSearch.jsx
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
var React = require('react');
|
||||||
|
var _ = require('lodash');
|
||||||
|
var cx = require('classnames');
|
||||||
|
|
||||||
|
var request = require('superagent');
|
||||||
|
|
||||||
|
var BrewSearch = React.createClass({
|
||||||
|
|
||||||
|
getDefaultProps: function() {
|
||||||
|
return {
|
||||||
|
admin_key : ''
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
searchTerm: '',
|
||||||
|
brew : null,
|
||||||
|
searching : false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
search : function(){
|
||||||
|
this.setState({
|
||||||
|
searching : true
|
||||||
|
});
|
||||||
|
|
||||||
|
request.get('/homebrew/api/search?id=' + this.state.searchTerm)
|
||||||
|
.query({
|
||||||
|
admin_key : this.props.admin_key,
|
||||||
|
})
|
||||||
|
.end((err, res)=>{
|
||||||
|
console.log(err, res, res.body.brews[0]);
|
||||||
|
this.setState({
|
||||||
|
brew : res.body.brews[0],
|
||||||
|
|
||||||
|
searching : false
|
||||||
|
})
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
handleChange : function(e){
|
||||||
|
this.setState({
|
||||||
|
searchTerm : e.target.value
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSearchClick : function(){
|
||||||
|
this.search();
|
||||||
|
},
|
||||||
|
|
||||||
|
renderBrew : function(){
|
||||||
|
if(!this.state.brew) return null;
|
||||||
|
return <div className='brew'>
|
||||||
|
<div>Edit id : {this.state.brew.editId}</div>
|
||||||
|
<div>Share id : {this.state.brew.shareId}</div>
|
||||||
|
</div>
|
||||||
|
},
|
||||||
|
|
||||||
|
render : function(){
|
||||||
|
return <div className='search'>
|
||||||
|
<input type='text' value={this.state.searchTerm} onChange={this.handleChange} />
|
||||||
|
|
||||||
|
<button onClick={this.handleSearchClick}>Search</button>
|
||||||
|
|
||||||
|
{this.renderBrew()}
|
||||||
|
</div>
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = BrewSearch;
|
||||||
172
client/admin/homebrewAdmin/homebrewAdmin.jsx
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
var React = require('react');
|
||||||
|
var _ = require('lodash');
|
||||||
|
var cx = require('classnames');
|
||||||
|
var request = require('superagent');
|
||||||
|
|
||||||
|
var Moment = require('moment');
|
||||||
|
|
||||||
|
var BrewSearch = require('./brewSearch.jsx');
|
||||||
|
|
||||||
|
var BrewLookup = require('./brewLookup/brewLookup.jsx');
|
||||||
|
|
||||||
|
|
||||||
|
var HomebrewAdmin = React.createClass({
|
||||||
|
getDefaultProps: function() {
|
||||||
|
return {
|
||||||
|
admin_key : ''
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
page: 0,
|
||||||
|
count : 20,
|
||||||
|
brewCache : {},
|
||||||
|
total : 0,
|
||||||
|
|
||||||
|
processingOldBrews : false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
fetchBrews : function(page){
|
||||||
|
request.get('/api/search')
|
||||||
|
.query({
|
||||||
|
admin_key : this.props.admin_key,
|
||||||
|
count : this.state.count,
|
||||||
|
page : page
|
||||||
|
})
|
||||||
|
.end((err, res)=>{
|
||||||
|
if(err || !res.body || !res.body.brews) return;
|
||||||
|
this.state.brewCache[page] = res.body.brews;
|
||||||
|
this.setState({
|
||||||
|
brewCache : this.state.brewCache,
|
||||||
|
total : res.body.total,
|
||||||
|
count : res.body.count
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
componentDidMount: function() {
|
||||||
|
this.fetchBrews(this.state.page);
|
||||||
|
},
|
||||||
|
|
||||||
|
changePageTo : function(page){
|
||||||
|
if(!this.state.brewCache[page]){
|
||||||
|
this.fetchBrews(page);
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
page : page
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
clearInvalidBrews : function(){
|
||||||
|
request.get('/api/invalid')
|
||||||
|
.query({admin_key : this.props.admin_key})
|
||||||
|
.end((err, res)=>{
|
||||||
|
if(!confirm("This will remove " + res.body.count + " brews. Are you sure?")) return;
|
||||||
|
request.get('/api/invalid')
|
||||||
|
.query({admin_key : this.props.admin_key, do_it : true})
|
||||||
|
.end((err, res)=>{
|
||||||
|
alert("Done!")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
deleteBrew : function(brewId){
|
||||||
|
if(!confirm("Are you sure you want to delete '" + brewId + "'?")) return;
|
||||||
|
request.get('/api/remove/' + brewId)
|
||||||
|
.query({admin_key : this.props.admin_key})
|
||||||
|
.end(function(err, res){
|
||||||
|
window.location.reload();
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
handlePageChange : function(dir){
|
||||||
|
this.changePageTo(this.state.page + dir);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
renderPagnination : function(){
|
||||||
|
var outOf;
|
||||||
|
if(this.state.total){
|
||||||
|
outOf = this.state.page + ' / ' + Math.round(this.state.total/this.state.count);
|
||||||
|
}
|
||||||
|
return <div className='pagnination'>
|
||||||
|
<i className='fa fa-chevron-left' onClick={this.handlePageChange.bind(this, -1)}/>
|
||||||
|
{outOf}
|
||||||
|
<i className='fa fa-chevron-right' onClick={this.handlePageChange.bind(this, 1)}/>
|
||||||
|
</div>
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
renderBrews : function(){
|
||||||
|
var brews = this.state.brewCache[this.state.page] || _.times(this.state.count);
|
||||||
|
return _.map(brews, (brew)=>{
|
||||||
|
return <tr className={cx('brewRow', {'isEmpty' : brew.text == "false"})} key={brew.shareId || brew}>
|
||||||
|
<td><a href={'/edit/' + brew.editId} target='_blank'>{brew.editId}</a></td>
|
||||||
|
<td><a href={'/share/' + brew.shareId} target='_blank'>{brew.shareId}</a></td>
|
||||||
|
<td>{Moment(brew.createdAt).fromNow()}</td>
|
||||||
|
<td>{Moment(brew.updatedAt).fromNow()}</td>
|
||||||
|
<td>{Moment(brew.lastViewed).fromNow()}</td>
|
||||||
|
<td>{brew.views}</td>
|
||||||
|
<td>
|
||||||
|
<div className='deleteButton' onClick={this.deleteBrew.bind(this, brew.editId)}>
|
||||||
|
<i className='fa fa-trash' />
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
renderBrewTable : function(){
|
||||||
|
return <div className='brewTable'>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Edit Id</th>
|
||||||
|
<th>Share Id</th>
|
||||||
|
<th>Created At</th>
|
||||||
|
<th>Last Updated</th>
|
||||||
|
<th>Last Viewed</th>
|
||||||
|
<th>Views</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{this.renderBrews()}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
},
|
||||||
|
|
||||||
|
render : function(){
|
||||||
|
var self = this;
|
||||||
|
return <div className='homebrewAdmin'>
|
||||||
|
|
||||||
|
<BrewLookup adminKey={this.props.admin_key} />
|
||||||
|
|
||||||
|
{/*
|
||||||
|
<h2>
|
||||||
|
Homebrews - {this.state.total}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{this.renderPagnination()}
|
||||||
|
{this.renderBrewTable()}
|
||||||
|
|
||||||
|
<button className='clearOldButton' onClick={this.clearInvalidBrews}>
|
||||||
|
Clear Old
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<BrewSearch admin_key={this.props.admin_key} />
|
||||||
|
*/}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = HomebrewAdmin;
|
||||||
53
client/admin/homebrewAdmin/homebrewAdmin.less
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
.homebrewAdmin{
|
||||||
|
margin-bottom: 80px;
|
||||||
|
.brewTable{
|
||||||
|
table{
|
||||||
|
|
||||||
|
th{
|
||||||
|
padding : 10px;
|
||||||
|
font-weight : 800;
|
||||||
|
}
|
||||||
|
tr:nth-child(even){
|
||||||
|
background-color : fade(@green, 10%);
|
||||||
|
}
|
||||||
|
tr.isEmpty{
|
||||||
|
background-color : fade(@red, 30%);
|
||||||
|
}
|
||||||
|
td{
|
||||||
|
min-width : 100px;
|
||||||
|
padding : 10px;
|
||||||
|
text-align : center;
|
||||||
|
|
||||||
|
&.preview{
|
||||||
|
position : relative;
|
||||||
|
&:hover{
|
||||||
|
.content{
|
||||||
|
display : block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.content{
|
||||||
|
position : absolute;
|
||||||
|
display : none;
|
||||||
|
top : 100%;
|
||||||
|
left : 0px;
|
||||||
|
z-index : 1000;
|
||||||
|
max-height : 500px;
|
||||||
|
width : 300px;
|
||||||
|
padding : 30px;
|
||||||
|
background-color : white;
|
||||||
|
font-family : monospace;
|
||||||
|
text-align : left;
|
||||||
|
pointer-events : none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.deleteButton{
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
button.clearOldButton{
|
||||||
|
float : right;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
const React = require('react');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const cx = require('classnames');
|
|
||||||
|
|
||||||
const request = require('superagent');
|
|
||||||
const BrewTable = require('../brewTable/brewTable.jsx');
|
|
||||||
|
|
||||||
|
|
||||||
const InvalidBrew = React.createClass({
|
|
||||||
getDefaultProps: function() {
|
|
||||||
return {
|
|
||||||
adminKey : '',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
getInitialState: function() {
|
|
||||||
return {
|
|
||||||
brews: []
|
|
||||||
};
|
|
||||||
},
|
|
||||||
getInvalid : function(){
|
|
||||||
request.get(`/admin/invalid`)
|
|
||||||
.set('x-homebrew-admin', this.props.adminKey)
|
|
||||||
.end((err, res) => {
|
|
||||||
this.setState({
|
|
||||||
brews : res.body
|
|
||||||
});
|
|
||||||
})
|
|
||||||
},
|
|
||||||
removeInvalid : function(){
|
|
||||||
if(!this.state.brews.length) return;
|
|
||||||
if(!confirm(`Are you sure you want to remove ${this.state.brews.length} brews`)) return;
|
|
||||||
if(!confirm('Sure you are sure?')) return;
|
|
||||||
|
|
||||||
request.delete(`/admin/invalid`)
|
|
||||||
.set('x-homebrew-admin', this.props.adminKey)
|
|
||||||
.end((err, res) => {
|
|
||||||
console.log(err, res.body);
|
|
||||||
alert('Invalid brews removed!');
|
|
||||||
this.getInvalid();
|
|
||||||
})
|
|
||||||
},
|
|
||||||
render: function(){
|
|
||||||
return <div className='invalidBrew'>
|
|
||||||
<h1>Remove Invalid Brews</h1>
|
|
||||||
<div>This will removes all brews older than 3 days and shorter than a tweet.</div>
|
|
||||||
<button className='get' onClick={this.getInvalid}> Get Invalid Brews</button>
|
|
||||||
<button className='remove' disabled={this.state.brews.length == 0} onClick={this.removeInvalid}> Remove invalid Brews</button>
|
|
||||||
|
|
||||||
<BrewTable brews={this.state.brews} />
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = InvalidBrew;
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
.invalidBrew{
|
|
||||||
button{
|
|
||||||
margin: 10px 4px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,33 +2,36 @@ const React = require('react');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
|
||||||
const Markdown = require('depricated/markdown.old.js');
|
const Markdown = require('naturalcrit/markdown.js');
|
||||||
const ErrorBar = require('./errorBar/errorBar.jsx');
|
const ErrorBar = require('./errorBar/errorBar.jsx');
|
||||||
|
|
||||||
|
//TODO: move to the brew renderer
|
||||||
const RenderWarnings = require('homebrewery/renderWarnings/renderWarnings.jsx')
|
const RenderWarnings = require('homebrewery/renderWarnings/renderWarnings.jsx')
|
||||||
const Store = require('homebrewery/brew.store.js');
|
|
||||||
|
|
||||||
|
|
||||||
const PAGE_HEIGHT = 1056;
|
const PAGE_HEIGHT = 1056;
|
||||||
const PPR_THRESHOLD = 50;
|
const PPR_THRESHOLD = 50;
|
||||||
|
|
||||||
const OLD_BrewRenderer = React.createClass({
|
const BrewRenderer = React.createClass({
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
value : '',
|
text : '',
|
||||||
style : '',
|
|
||||||
errors : []
|
errors : []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
const pages = this.props.value.split('\\page');
|
const pages = this.props.text.split('\\page');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
viewablePageNumber: 0,
|
viewablePageNumber: 0,
|
||||||
height : 0,
|
height : 0,
|
||||||
isMounted : false,
|
isMounted : false,
|
||||||
|
|
||||||
|
usePPR : true,
|
||||||
|
|
||||||
pages : pages,
|
pages : pages,
|
||||||
usePPR : pages.length >= PPR_THRESHOLD
|
usePPR : pages.length >= PPR_THRESHOLD,
|
||||||
|
|
||||||
|
errors : []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
height : 0,
|
height : 0,
|
||||||
@@ -46,7 +49,7 @@ const OLD_BrewRenderer = React.createClass({
|
|||||||
componentWillReceiveProps: function(nextProps) {
|
componentWillReceiveProps: function(nextProps) {
|
||||||
if(this.refs.pages && this.refs.pages.firstChild) this.pageHeight = this.refs.pages.firstChild.clientHeight;
|
if(this.refs.pages && this.refs.pages.firstChild) this.pageHeight = this.refs.pages.firstChild.clientHeight;
|
||||||
|
|
||||||
const pages = nextProps.value.split('\\page');
|
const pages = nextProps.text.split('\\page');
|
||||||
this.setState({
|
this.setState({
|
||||||
pages : pages,
|
pages : pages,
|
||||||
usePPR : pages.length >= PPR_THRESHOLD
|
usePPR : pages.length >= PPR_THRESHOLD
|
||||||
@@ -58,9 +61,8 @@ const OLD_BrewRenderer = React.createClass({
|
|||||||
if(this.refs.pages && this.refs.pages.firstChild) this.pageHeight = this.refs.pages.firstChild.clientHeight;
|
if(this.refs.pages && this.refs.pages.firstChild) this.pageHeight = this.refs.pages.firstChild.clientHeight;
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
const parentNode = document.querySelector('.page .content');
|
|
||||||
this.setState({
|
this.setState({
|
||||||
height : parentNode.clientHeight,
|
height : this.refs.main.parentNode.clientHeight,
|
||||||
isMounted : true
|
isMounted : true
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -75,9 +77,13 @@ const OLD_BrewRenderer = React.createClass({
|
|||||||
if(!this.state.isMounted) return false;
|
if(!this.state.isMounted) return false;
|
||||||
|
|
||||||
var viewIndex = this.state.viewablePageNumber;
|
var viewIndex = this.state.viewablePageNumber;
|
||||||
|
if(index == viewIndex - 3) return true;
|
||||||
|
if(index == viewIndex - 2) return true;
|
||||||
if(index == viewIndex - 1) return true;
|
if(index == viewIndex - 1) return true;
|
||||||
if(index == viewIndex) return true;
|
if(index == viewIndex) return true;
|
||||||
if(index == viewIndex + 1) return true;
|
if(index == viewIndex + 1) return true;
|
||||||
|
if(index == viewIndex + 2) return true;
|
||||||
|
if(index == viewIndex + 3) return true;
|
||||||
|
|
||||||
//Check for style tages
|
//Check for style tages
|
||||||
if(pageText.indexOf('<style>') !== -1) return true;
|
if(pageText.indexOf('<style>') !== -1) return true;
|
||||||
@@ -100,13 +106,13 @@ const OLD_BrewRenderer = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
renderDummyPage : function(index){
|
renderDummyPage : function(index){
|
||||||
return <div className='phb v1' id={`p${index + 1}`} key={index}>
|
return <div className='phb' id={`p${index + 1}`} key={index}>
|
||||||
<i className='fa fa-spinner fa-spin' />
|
<i className='fa fa-spinner fa-spin' />
|
||||||
</div>
|
</div>
|
||||||
},
|
},
|
||||||
|
|
||||||
renderPage : function(pageText, index){
|
renderPage : function(pageText, index){
|
||||||
return <div className='phb v1' id={`p${index + 1}`} dangerouslySetInnerHTML={{__html:Markdown.render(pageText)}} key={index} />
|
return <div className='phb' id={`p${index + 1}`} dangerouslySetInnerHTML={{__html:Markdown.render(pageText)}} key={index} />
|
||||||
},
|
},
|
||||||
|
|
||||||
renderPages : function(){
|
renderPages : function(){
|
||||||
@@ -127,7 +133,7 @@ const OLD_BrewRenderer = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
return <div className='brewRendererOld'
|
return <div className='brewRenderer'
|
||||||
onScroll={this.handleScroll}
|
onScroll={this.handleScroll}
|
||||||
ref='main'
|
ref='main'
|
||||||
style={{height : this.state.height}}>
|
style={{height : this.state.height}}>
|
||||||
@@ -144,4 +150,4 @@ const OLD_BrewRenderer = React.createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = OLD_BrewRenderer;
|
module.exports = BrewRenderer;
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
|
|
||||||
@import 'shared/depricated/phb_style_v1/phb.v1.less';
|
@import (less) './client/homebrew/phbStyle/phb.style.less';
|
||||||
|
|
||||||
.pane{
|
.pane{
|
||||||
position : relative;
|
position : relative;
|
||||||
}
|
}
|
||||||
.brewRendererOld{
|
.brewRenderer{
|
||||||
overflow-y : scroll;
|
overflow-y : scroll;
|
||||||
.pageInfo{
|
.pageInfo{
|
||||||
position : absolute;
|
position : absolute;
|
||||||
145
client/homebrew/editor/editor.jsx
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
const React = require('react');
|
||||||
|
const _ = require('lodash');
|
||||||
|
const cx = require('classnames');
|
||||||
|
|
||||||
|
const CodeEditor = require('naturalcrit/codeEditor/codeEditor.jsx');
|
||||||
|
const SnippetBar = require('./snippetbar/snippetbar.jsx');
|
||||||
|
const MetadataEditor = require('./metadataEditor/metadataEditor.jsx');
|
||||||
|
|
||||||
|
|
||||||
|
const splice = function(str, index, inject){
|
||||||
|
return str.slice(0, index) + inject + str.slice(index);
|
||||||
|
};
|
||||||
|
|
||||||
|
const SNIPPETBAR_HEIGHT = 25;
|
||||||
|
|
||||||
|
const Editor = React.createClass({
|
||||||
|
getDefaultProps: function() {
|
||||||
|
return {
|
||||||
|
value : '',
|
||||||
|
onChange : ()=>{},
|
||||||
|
|
||||||
|
metadata : {},
|
||||||
|
onMetadataChange : ()=>{},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
showMetadataEditor: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
cursorPosition : {
|
||||||
|
line : 0,
|
||||||
|
ch : 0
|
||||||
|
},
|
||||||
|
|
||||||
|
componentDidMount: function() {
|
||||||
|
this.updateEditorSize();
|
||||||
|
this.highlightPageLines();
|
||||||
|
window.addEventListener("resize", this.updateEditorSize);
|
||||||
|
},
|
||||||
|
componentWillUnmount: function() {
|
||||||
|
window.removeEventListener("resize", this.updateEditorSize);
|
||||||
|
},
|
||||||
|
|
||||||
|
updateEditorSize : function() {
|
||||||
|
let paneHeight = this.refs.main.parentNode.clientHeight;
|
||||||
|
paneHeight -= SNIPPETBAR_HEIGHT + 1;
|
||||||
|
this.refs.codeEditor.codeMirror.setSize(null, paneHeight);
|
||||||
|
},
|
||||||
|
|
||||||
|
handleTextChange : function(text){
|
||||||
|
this.props.onChange(text);
|
||||||
|
},
|
||||||
|
handleCursorActivty : function(curpos){
|
||||||
|
this.cursorPosition = curpos;
|
||||||
|
},
|
||||||
|
handleInject : function(injectText){
|
||||||
|
const lines = this.props.value.split('\n');
|
||||||
|
lines[this.cursorPosition.line] = splice(lines[this.cursorPosition.line], this.cursorPosition.ch, injectText);
|
||||||
|
|
||||||
|
this.handleTextChange(lines.join('\n'));
|
||||||
|
this.refs.codeEditor.setCursorPosition(this.cursorPosition.line, this.cursorPosition.ch + injectText.length);
|
||||||
|
},
|
||||||
|
handgleToggle : function(){
|
||||||
|
this.setState({
|
||||||
|
showMetadataEditor : !this.state.showMetadataEditor
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
getCurrentPage : function(){
|
||||||
|
const lines = this.props.value.split('\n').slice(0, this.cursorPosition.line + 1);
|
||||||
|
return _.reduce(lines, (r, line) => {
|
||||||
|
if(line.indexOf('\\page') !== -1) r++;
|
||||||
|
return r;
|
||||||
|
}, 1);
|
||||||
|
},
|
||||||
|
|
||||||
|
highlightPageLines : function(){
|
||||||
|
if(!this.refs.codeEditor) return;
|
||||||
|
const codeMirror = this.refs.codeEditor.codeMirror;
|
||||||
|
|
||||||
|
const lineNumbers = _.reduce(this.props.value.split('\n'), (r, line, lineNumber)=>{
|
||||||
|
if(line.indexOf('\\page') !== -1){
|
||||||
|
codeMirror.addLineClass(lineNumber, 'background', 'pageLine');
|
||||||
|
r.push(lineNumber);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}, []);
|
||||||
|
return lineNumbers
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
brewJump : function(){
|
||||||
|
const currentPage = this.getCurrentPage();
|
||||||
|
window.location.hash = 'p' + currentPage;
|
||||||
|
},
|
||||||
|
|
||||||
|
//Called when there are changes to the editor's dimensions
|
||||||
|
update : function(){
|
||||||
|
this.refs.codeEditor.updateSize();
|
||||||
|
},
|
||||||
|
|
||||||
|
renderMetadataEditor : function(){
|
||||||
|
if(!this.state.showMetadataEditor) return;
|
||||||
|
return <MetadataEditor
|
||||||
|
metadata={this.props.metadata}
|
||||||
|
onChange={this.props.onMetadataChange}
|
||||||
|
/>
|
||||||
|
},
|
||||||
|
|
||||||
|
render : function(){
|
||||||
|
this.highlightPageLines();
|
||||||
|
return(
|
||||||
|
<div className='editor' ref='main'>
|
||||||
|
<SnippetBar
|
||||||
|
brew={this.props.value}
|
||||||
|
onInject={this.handleInject}
|
||||||
|
onToggle={this.handgleToggle}
|
||||||
|
showmeta={this.state.showMetadataEditor} />
|
||||||
|
{this.renderMetadataEditor()}
|
||||||
|
<CodeEditor
|
||||||
|
ref='codeEditor'
|
||||||
|
wrap={true}
|
||||||
|
language='gfm'
|
||||||
|
value={this.props.value}
|
||||||
|
onChange={this.handleTextChange}
|
||||||
|
onCursorActivity={this.handleCursorActivty} />
|
||||||
|
|
||||||
|
{/*
|
||||||
|
<div className='brewJump' onClick={this.brewJump}>
|
||||||
|
<i className='fa fa-arrow-right' />
|
||||||
|
</div>
|
||||||
|
*/}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = Editor;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,21 +1,14 @@
|
|||||||
|
|
||||||
.brewEditor{
|
.editor{
|
||||||
position : relative;
|
position : relative;
|
||||||
width : 100%;
|
width : 100%;
|
||||||
|
|
||||||
.codeEditor{
|
.codeEditor{
|
||||||
height : 100%;
|
height : 100%;
|
||||||
.pageLine{
|
.pageLine{
|
||||||
background-color : fade(#333, 15%);
|
background-color : fade(#333, 15%);
|
||||||
border-bottom : #333 solid 1px;
|
border-bottom : #333 solid 1px;
|
||||||
}
|
}
|
||||||
.block{
|
|
||||||
color : purple;
|
|
||||||
//font-style: italic;
|
|
||||||
}
|
|
||||||
.columnSplit{
|
|
||||||
font-style : italic;
|
|
||||||
color : grey;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.brewJump{
|
.brewJump{
|
||||||
@@ -32,4 +25,5 @@
|
|||||||
justify-content:center;
|
justify-content:center;
|
||||||
.tooltipLeft("Jump to brew page");
|
.tooltipLeft("Jump to brew page");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,6 @@ const MetadataEditor = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
renderPublish : function(){
|
renderPublish : function(){
|
||||||
//TODO: Move the publish element into here
|
|
||||||
if(this.props.metadata.published){
|
if(this.props.metadata.published){
|
||||||
return <button className='unpublish' onClick={this.handlePublish.bind(null, false)}>
|
return <button className='unpublish' onClick={this.handlePublish.bind(null, false)}>
|
||||||
<i className='fa fa-ban' /> unpublish
|
<i className='fa fa-ban' /> unpublish
|
||||||
@@ -140,12 +139,13 @@ const MetadataEditor = React.createClass({
|
|||||||
<textarea value={this.props.metadata.description} className='value'
|
<textarea value={this.props.metadata.description} className='value'
|
||||||
onChange={this.handleFieldChange.bind(null, 'description')} />
|
onChange={this.handleFieldChange.bind(null, 'description')} />
|
||||||
</div>
|
</div>
|
||||||
<div className='field thumbnail'>
|
{/*}
|
||||||
<label>thumbnail</label>
|
<div className='field tags'>
|
||||||
<input type='text' className='value'
|
<label>tags</label>
|
||||||
value={this.props.metadata.thumbnail}
|
<textarea value={this.props.metadata.tags}
|
||||||
onChange={this.handleFieldChange.bind(null, 'thumbnail')} />
|
onChange={this.handleFieldChange.bind(null, 'tags')} />
|
||||||
</div>
|
</div>
|
||||||
|
*/}
|
||||||
|
|
||||||
<div className='field systems'>
|
<div className='field systems'>
|
||||||
<label>systems</label>
|
<label>systems</label>
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
.metadataEditor{
|
.metadataEditor{
|
||||||
position : absolute;
|
position : absolute;
|
||||||
|
z-index : 10000;
|
||||||
box-sizing : border-box;
|
box-sizing : border-box;
|
||||||
width : 100%;
|
width : 100%;
|
||||||
padding : 25px;
|
padding : 25px;
|
||||||
// background-color : #999;
|
background-color : #999;
|
||||||
background-color: white;
|
|
||||||
.field{
|
.field{
|
||||||
display : flex;
|
display : flex;
|
||||||
width : 100%;
|
width : 100%;
|
||||||
@@ -76,7 +76,4 @@
|
|||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
line-height : 1.5em;
|
line-height : 1.5em;
|
||||||
}
|
}
|
||||||
.thumbnail.field{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
94
client/homebrew/editor/snippetbar/snippetbar.jsx
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
const React = require('react');
|
||||||
|
const _ = require('lodash');
|
||||||
|
const cx = require('classnames');
|
||||||
|
|
||||||
|
|
||||||
|
const Snippets = require('./snippets/snippets.js');
|
||||||
|
|
||||||
|
const execute = function(val, brew){
|
||||||
|
if(_.isFunction(val)) return val(brew);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const Snippetbar = React.createClass({
|
||||||
|
getDefaultProps: function() {
|
||||||
|
return {
|
||||||
|
brew : '',
|
||||||
|
onInject : ()=>{},
|
||||||
|
onToggle : ()=>{},
|
||||||
|
showmeta : false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
handleSnippetClick : function(injectedText){
|
||||||
|
this.props.onInject(injectedText)
|
||||||
|
},
|
||||||
|
|
||||||
|
renderSnippetGroups : function(){
|
||||||
|
return _.map(Snippets, (snippetGroup)=>{
|
||||||
|
return <SnippetGroup
|
||||||
|
brew={this.props.brew}
|
||||||
|
groupName={snippetGroup.groupName}
|
||||||
|
icon={snippetGroup.icon}
|
||||||
|
snippets={snippetGroup.snippets}
|
||||||
|
key={snippetGroup.groupName}
|
||||||
|
onSnippetClick={this.handleSnippetClick}
|
||||||
|
/>
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
render : function(){
|
||||||
|
return <div className='snippetBar'>
|
||||||
|
{this.renderSnippetGroups()}
|
||||||
|
<div className={cx('toggleMeta', {selected: this.props.showmeta})}
|
||||||
|
onClick={this.props.onToggle}>
|
||||||
|
<i className='fa fa-bars' />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = Snippetbar;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const SnippetGroup = React.createClass({
|
||||||
|
getDefaultProps: function() {
|
||||||
|
return {
|
||||||
|
brew : '',
|
||||||
|
groupName : '',
|
||||||
|
icon : 'fa-rocket',
|
||||||
|
snippets : [],
|
||||||
|
onSnippetClick : function(){},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
handleSnippetClick : function(snippet){
|
||||||
|
this.props.onSnippetClick(execute(snippet.gen, this.props.brew));
|
||||||
|
},
|
||||||
|
renderSnippets : function(){
|
||||||
|
return _.map(this.props.snippets, (snippet)=>{
|
||||||
|
return <div className='snippet' key={snippet.name} onClick={this.handleSnippetClick.bind(this, snippet)}>
|
||||||
|
<i className={'fa fa-fw ' + snippet.icon} />
|
||||||
|
{snippet.name}
|
||||||
|
</div>
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
render : function(){
|
||||||
|
return <div className='snippetGroup'>
|
||||||
|
<div className='text'>
|
||||||
|
<i className={'fa fa-fw ' + this.props.icon} />
|
||||||
|
<span className='groupName'>{this.props.groupName}</span>
|
||||||
|
</div>
|
||||||
|
<div className='dropdown'>
|
||||||
|
{this.renderSnippets()}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
73
client/homebrew/editor/snippetbar/snippetbar.less
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
|
||||||
|
.snippetBar{
|
||||||
|
@height : 25px;
|
||||||
|
position : relative;
|
||||||
|
height : @height;
|
||||||
|
background-color : #ddd;
|
||||||
|
.toggleMeta{
|
||||||
|
position : absolute;
|
||||||
|
top : 0px;
|
||||||
|
right : 0px;
|
||||||
|
height : @height;
|
||||||
|
width : @height;
|
||||||
|
cursor : pointer;
|
||||||
|
line-height : @height;
|
||||||
|
text-align : center;
|
||||||
|
.tooltipLeft("Edit Brew Metadata");
|
||||||
|
&:hover, &.selected{
|
||||||
|
background-color : #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.snippetGroup{
|
||||||
|
display : inline-block;
|
||||||
|
height : @height;
|
||||||
|
padding : 0px 5px;
|
||||||
|
cursor : pointer;
|
||||||
|
font-size : 0.6em;
|
||||||
|
font-weight : 800;
|
||||||
|
line-height : @height;
|
||||||
|
text-transform : uppercase;
|
||||||
|
border-right : 1px solid black;
|
||||||
|
i{
|
||||||
|
vertical-align : middle;
|
||||||
|
margin-right : 3px;
|
||||||
|
font-size : 1.2em;
|
||||||
|
}
|
||||||
|
&:hover, &.selected{
|
||||||
|
background-color : #999;
|
||||||
|
}
|
||||||
|
.text{
|
||||||
|
line-height : @height;
|
||||||
|
.groupName{
|
||||||
|
font-size : 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&:hover{
|
||||||
|
.dropdown{
|
||||||
|
visibility : visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.dropdown{
|
||||||
|
position : absolute;
|
||||||
|
top : 100%;
|
||||||
|
visibility : hidden;
|
||||||
|
z-index : 1000;
|
||||||
|
margin-left : -5px;
|
||||||
|
padding : 0px;
|
||||||
|
background-color : #ddd;
|
||||||
|
.snippet{
|
||||||
|
.animate(background-color);
|
||||||
|
padding : 5px;
|
||||||
|
cursor : pointer;
|
||||||
|
font-size : 10px;
|
||||||
|
i{
|
||||||
|
margin-right : 8px;
|
||||||
|
font-size : 13px;
|
||||||
|
}
|
||||||
|
&:hover{
|
||||||
|
background-color : #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,7 +48,7 @@ const getTOC = (pages) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function(brew){
|
module.exports = function(brew){
|
||||||
|
const pages = brew.split('\\page');
|
||||||
const TOC = getTOC(pages);
|
const TOC = getTOC(pages);
|
||||||
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
||||||
r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`)
|
r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`)
|
||||||
@@ -3,15 +3,13 @@ const _ = require('lodash');
|
|||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
|
||||||
const CreateRouter = require('pico-router').createRouter;
|
const CreateRouter = require('pico-router').createRouter;
|
||||||
const BrewActions = require('homebrewery/brew.actions.js');
|
|
||||||
const AccountActions = require('homebrewery/account.actions.js');
|
|
||||||
|
|
||||||
const HomePage = require('./pages/homePage/homePage.jsx');
|
const HomePage = require('./pages/homePage/homePage.jsx');
|
||||||
const EditPage = require('./pages/editPage/editPage.jsx');
|
const EditPage = require('./pages/editPage/editPage.jsx');
|
||||||
const UserPage = require('./pages/userPage/userPage.jsx');
|
const UserPage = require('./pages/userPage/userPage.jsx');
|
||||||
const SharePage = require('./pages/sharePage/sharePage.jsx');
|
const SharePage = require('./pages/sharePage/sharePage.jsx');
|
||||||
const NewPage = require('./pages/newPage/newPage.jsx');
|
const NewPage = require('./pages/newPage/newPage.jsx');
|
||||||
//const ErrorPage = require('./pages/errorPage/errorPage.jsx');
|
const ErrorPage = require('./pages/errorPage/errorPage.jsx');
|
||||||
const PrintPage = require('./pages/printPage/printPage.jsx');
|
const PrintPage = require('./pages/printPage/printPage.jsx');
|
||||||
|
|
||||||
let Router;
|
let Router;
|
||||||
@@ -19,27 +17,45 @@ const Homebrew = React.createClass({
|
|||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
url : '',
|
url : '',
|
||||||
|
welcomeText : '',
|
||||||
|
changelog : '',
|
||||||
version : '0.0.0',
|
version : '0.0.0',
|
||||||
loginPath : '',
|
account : null,
|
||||||
|
brew : {
|
||||||
user : undefined,
|
title : '',
|
||||||
brew : undefined,
|
text : '',
|
||||||
brews : []
|
shareId : null,
|
||||||
|
editId : null,
|
||||||
|
createdAt : null,
|
||||||
|
updatedAt : null,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
BrewActions.init({
|
global.account = this.props.account;
|
||||||
version : this.props.version,
|
global.version = this.props.version;
|
||||||
brew : this.props.brew
|
|
||||||
});
|
|
||||||
AccountActions.init({
|
|
||||||
user : this.props.user,
|
|
||||||
loginPath : this.props.loginPath
|
|
||||||
});
|
|
||||||
|
|
||||||
Router = CreateRouter({
|
Router = CreateRouter({
|
||||||
'/edit/:id' : <EditPage />,
|
'/edit/:id' : (args) => {
|
||||||
'/share/:id' : <SharePage />,
|
if(!this.props.brew.editId){
|
||||||
|
return <ErrorPage errorId={args.id}/>
|
||||||
|
}
|
||||||
|
|
||||||
|
return <EditPage
|
||||||
|
id={args.id}
|
||||||
|
brew={this.props.brew} />
|
||||||
|
},
|
||||||
|
|
||||||
|
'/share/:id' : (args) => {
|
||||||
|
if(!this.props.brew.shareId){
|
||||||
|
return <ErrorPage errorId={args.id}/>
|
||||||
|
}
|
||||||
|
|
||||||
|
return <SharePage
|
||||||
|
id={args.id}
|
||||||
|
brew={this.props.brew} />
|
||||||
|
},
|
||||||
'/user/:username' : (args) => {
|
'/user/:username' : (args) => {
|
||||||
return <UserPage
|
return <UserPage
|
||||||
username={args.username}
|
username={args.username}
|
||||||
@@ -52,15 +68,15 @@ const Homebrew = React.createClass({
|
|||||||
'/print' : (args, query) => {
|
'/print' : (args, query) => {
|
||||||
return <PrintPage query={query}/>;
|
return <PrintPage query={query}/>;
|
||||||
},
|
},
|
||||||
'/new' : <NewPage />,
|
'/new' : (args) => {
|
||||||
|
return <NewPage />
|
||||||
|
},
|
||||||
'/changelog' : <SharePage />,
|
'/changelog' : (args) => {
|
||||||
'/test' : <SharePage />,
|
return <SharePage
|
||||||
'/test_old' : <SharePage />,
|
brew={{title : 'Changelog', text : this.props.changelog}} />
|
||||||
|
},
|
||||||
|
'*' : <HomePage
|
||||||
'*' : <HomePage brews={this.props.brews}/>,
|
welcomeText={this.props.welcomeText} />,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
render : function(){
|
render : function(){
|
||||||
|
|||||||
@@ -1,23 +1,17 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
|
|
||||||
const Store = require('homebrewery/account.store.js');
|
|
||||||
const Actions = require('homebrewery/account.actions.js');
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(props){
|
module.exports = function(props){
|
||||||
const user = Store.getUser();
|
if(global.account){
|
||||||
if(user && user == props.userPage){
|
return <Nav.item href={`/user/${global.account.username}`} color='yellow' icon='fa-user'>
|
||||||
return <Nav.item onClick={Actions.logout} color='yellow' icon='fa-user-times'>
|
{global.account.username}
|
||||||
logout
|
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
}
|
}
|
||||||
if(user){
|
let url = '';
|
||||||
return <Nav.item href={`/user/${user}`} color='yellow' icon='fa-user'>
|
if(typeof window !== 'undefined'){
|
||||||
{user}
|
url = window.location.href
|
||||||
</Nav.item>
|
|
||||||
}
|
}
|
||||||
return <Nav.item onClick={Actions.login} color='teal' icon='fa-sign-in'>
|
return <Nav.item href={`http://naturalcrit.com/login?redirect=${url}`} color='teal' icon='fa-sign-in'>
|
||||||
login
|
login
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
};
|
};
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
const React = require('react');
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
|
||||||
const Store = require('homebrewery/brew.store.js');
|
|
||||||
|
|
||||||
module.exports = Store.createSmartComponent((props) => {
|
|
||||||
return <Nav.item className='brewTitle'>{props.title}</Nav.item>
|
|
||||||
}, (props) => {
|
|
||||||
return {title : Store.getMetaData().title};
|
|
||||||
})
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
const flux = require('pico-flux')
|
|
||||||
const React = require('react');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const cx = require('classnames');
|
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
|
||||||
|
|
||||||
const Store = require('homebrewery/brew.store.js');
|
|
||||||
const Actions = require('homebrewery/brew.actions.js');
|
|
||||||
|
|
||||||
const onStoreChange = () => {
|
|
||||||
return {
|
|
||||||
status : Store.getStatus(),
|
|
||||||
errors : Store.getErrors()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const ContinousSave = React.createClass({
|
|
||||||
getDefaultProps: function() {
|
|
||||||
return {
|
|
||||||
status : 'ready',
|
|
||||||
errors : undefined
|
|
||||||
};
|
|
||||||
},
|
|
||||||
componentDidMount: function() {
|
|
||||||
flux.actionEmitter.on('dispatch', this.actionHandler);
|
|
||||||
window.onbeforeunload = ()=>{
|
|
||||||
if(this.props.status !== 'ready') return 'You have unsaved changes!';
|
|
||||||
};
|
|
||||||
},
|
|
||||||
componentWillUnmount: function() {
|
|
||||||
flux.actionEmitter.removeListener('dispatch', this.actionHandler);
|
|
||||||
window.onbeforeunload = function(){};
|
|
||||||
},
|
|
||||||
actionHandler : function(actionType){
|
|
||||||
if(actionType == 'UPDATE_BREW_TEXT' || actionType == 'UPDATE_META'){
|
|
||||||
Actions.pendingSave();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
handleClick : function(){
|
|
||||||
Actions.save();
|
|
||||||
},
|
|
||||||
renderError : function(){
|
|
||||||
let errMsg = '';
|
|
||||||
try{
|
|
||||||
errMsg += this.state.errors.toString() + '\n\n';
|
|
||||||
errMsg += '```\n' + JSON.stringify(this.state.errors.response.error, null, ' ') + '\n```';
|
|
||||||
}catch(e){}
|
|
||||||
|
|
||||||
return <Nav.item className='continousSave error' icon="fa-warning">
|
|
||||||
Oops!
|
|
||||||
<div className='errorContainer'>
|
|
||||||
Looks like there was a problem saving. <br />
|
|
||||||
Report the issue <a target='_blank' href={'https://github.com/stolksdorf/naturalcrit/issues/new?body='+ encodeURIComponent(errMsg)}>
|
|
||||||
here
|
|
||||||
</a>.
|
|
||||||
</div>
|
|
||||||
</Nav.item>
|
|
||||||
},
|
|
||||||
render : function(){
|
|
||||||
if(this.props.status == 'error') return this.renderError();
|
|
||||||
|
|
||||||
if(this.props.status == 'saving'){
|
|
||||||
return <Nav.item className='continousSave' icon="fa-spinner fa-spin">saving...</Nav.item>
|
|
||||||
}
|
|
||||||
if(this.props.status == 'pending'){
|
|
||||||
return <Nav.item className='continousSave' onClick={this.handleClick} color='blue' icon='fa-save'>Save Now</Nav.item>
|
|
||||||
}
|
|
||||||
if(this.props.status == 'ready'){
|
|
||||||
return <Nav.item className='continousSave saved'>saved.</Nav.item>
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = Store.createSmartComponent(ContinousSave, onStoreChange);
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
const flux = require('pico-flux')
|
|
||||||
const React = require('react');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const cx = require('classnames');
|
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
|
||||||
|
|
||||||
const Store = require('homebrewery/brew.store.js');
|
|
||||||
const Actions = require('homebrewery/brew.actions.js');
|
|
||||||
|
|
||||||
const onStoreChange = () => {
|
|
||||||
return {
|
|
||||||
status : Store.getStatus(),
|
|
||||||
errors : Store.getErrors()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const ContinousSave = React.createClass({
|
|
||||||
getDefaultProps: function() {
|
|
||||||
return {
|
|
||||||
status : 'ready',
|
|
||||||
errors : undefined
|
|
||||||
};
|
|
||||||
},
|
|
||||||
componentDidMount: function() {
|
|
||||||
flux.actionEmitter.on('dispatch', this.actionHandler);
|
|
||||||
window.onbeforeunload = ()=>{
|
|
||||||
if(this.props.status !== 'ready') return 'You have unsaved changes!';
|
|
||||||
};
|
|
||||||
},
|
|
||||||
componentWillUnmount: function() {
|
|
||||||
flux.actionEmitter.removeListener('dispatch', this.actionHandler);
|
|
||||||
window.onbeforeunload = function(){};
|
|
||||||
},
|
|
||||||
actionHandler : function(actionType){
|
|
||||||
if(actionType == 'UPDATE_BREW_CODE' || actionType == 'UPDATE_META' || actionType == 'UPDATE_BREW_STYLE'){
|
|
||||||
Actions.pendingSave();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
handleClick : function(){
|
|
||||||
Actions.save();
|
|
||||||
},
|
|
||||||
renderError : function(){
|
|
||||||
let errMsg = '';
|
|
||||||
try{
|
|
||||||
errMsg += this.state.errors.toString() + '\n\n';
|
|
||||||
errMsg += '```\n' + JSON.stringify(this.state.errors.response.error, null, ' ') + '\n```';
|
|
||||||
}catch(e){}
|
|
||||||
|
|
||||||
return <Nav.item className='continousSave error' icon="fa-warning">
|
|
||||||
Oops!
|
|
||||||
<div className='errorContainer'>
|
|
||||||
Looks like there was a problem saving. <br />
|
|
||||||
Back up your brew in a text file, just in case.
|
|
||||||
<br /><br />
|
|
||||||
|
|
||||||
Report the issue <a target='_blank' href={'https://github.com/stolksdorf/naturalcrit/issues/new?body='+ encodeURIComponent(errMsg)}>
|
|
||||||
here
|
|
||||||
</a>.
|
|
||||||
</div>
|
|
||||||
</Nav.item>
|
|
||||||
},
|
|
||||||
render : function(){
|
|
||||||
if(this.props.status == 'error') return this.renderError();
|
|
||||||
|
|
||||||
if(this.props.status == 'saving'){
|
|
||||||
return <Nav.item className='continousSave' icon="fa-spinner fa-spin">saving...</Nav.item>
|
|
||||||
}
|
|
||||||
if(this.props.status == 'pending'){
|
|
||||||
return <Nav.item className='continousSave' onClick={this.handleClick} color='blue' icon='fa-save'>Save Now</Nav.item>
|
|
||||||
}
|
|
||||||
if(this.props.status == 'ready'){
|
|
||||||
return <Nav.item className='continousSave saved'>saved.</Nav.item>
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = Store.createSmartComponent(ContinousSave, onStoreChange);
|
|
||||||
@@ -2,12 +2,7 @@ var React = require('react');
|
|||||||
var Nav = require('naturalcrit/nav/nav.jsx');
|
var Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
|
|
||||||
module.exports = function(props){
|
module.exports = function(props){
|
||||||
return <Nav.item
|
return <Nav.item newTab={true} href='https://github.com/stolksdorf/homebrewery/issues' color='red' icon='fa-bug'>
|
||||||
{...props}
|
|
||||||
newTab={true}
|
|
||||||
href='https://github.com/stolksdorf/homebrewery/issues'
|
|
||||||
color='red'
|
|
||||||
icon='fa-bug'>
|
|
||||||
report issue
|
report issue
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
};
|
};
|
||||||
@@ -2,9 +2,34 @@ const React = require('react');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
const Store = require('homebrewery/brew.store.js');
|
|
||||||
|
|
||||||
const Navbar = React.createClass({
|
const Navbar = React.createClass({
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
//showNonChromeWarning : false,
|
||||||
|
ver : '0.0.0'
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
componentDidMount: function() {
|
||||||
|
//const isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
|
||||||
|
this.setState({
|
||||||
|
//showNonChromeWarning : !isChrome,
|
||||||
|
ver : window.version
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
renderChromeWarning : function(){
|
||||||
|
if(!this.state.showNonChromeWarning) return;
|
||||||
|
return <Nav.item className='warning' icon='fa-exclamation-triangle'>
|
||||||
|
Optimized for Chrome
|
||||||
|
<div className='dropdown'>
|
||||||
|
If you are experiencing rendering issues, use Chrome instead
|
||||||
|
</div>
|
||||||
|
</Nav.item>
|
||||||
|
},
|
||||||
|
*/
|
||||||
render : function(){
|
render : function(){
|
||||||
return <Nav.base>
|
return <Nav.base>
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
@@ -12,7 +37,9 @@ const Navbar = React.createClass({
|
|||||||
<Nav.item href='/' className='homebrewLogo'>
|
<Nav.item href='/' className='homebrewLogo'>
|
||||||
<div>The Homebrewery</div>
|
<div>The Homebrewery</div>
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
<Nav.item>{`v${Store.getVersion()}`}</Nav.item>
|
<Nav.item>{`v${this.state.ver}`}</Nav.item>
|
||||||
|
|
||||||
|
{/*this.renderChromeWarning()*/}
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</Nav.base>
|
</Nav.base>
|
||||||
|
|||||||
@@ -13,6 +13,32 @@
|
|||||||
color : @blue;
|
color : @blue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.editTitle.navItem{
|
||||||
|
padding : 2px 12px;
|
||||||
|
input{
|
||||||
|
width : 250px;
|
||||||
|
margin : 0;
|
||||||
|
padding : 2px;
|
||||||
|
background-color : #444;
|
||||||
|
font-family : 'Open Sans', sans-serif;
|
||||||
|
font-size : 12px;
|
||||||
|
font-weight : 800;
|
||||||
|
color : white;
|
||||||
|
text-align : center;
|
||||||
|
border : 1px solid @blue;
|
||||||
|
outline : none;
|
||||||
|
}
|
||||||
|
.charCount{
|
||||||
|
display : inline-block;
|
||||||
|
vertical-align : bottom;
|
||||||
|
margin-left : 8px;
|
||||||
|
color : #666;
|
||||||
|
text-align : right;
|
||||||
|
&.max{
|
||||||
|
color : @red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.brewTitle.navItem{
|
.brewTitle.navItem{
|
||||||
font-size : 12px;
|
font-size : 12px;
|
||||||
font-weight : 800;
|
font-weight : 800;
|
||||||
@@ -99,34 +125,4 @@
|
|||||||
text-align : center;
|
text-align : center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.staticSave.navItem{
|
|
||||||
background-color : @orange;
|
|
||||||
&:hover{
|
|
||||||
background-color : @green;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.continousSave.navItem{
|
|
||||||
width : 105px;
|
|
||||||
text-align : center;
|
|
||||||
&.saved{
|
|
||||||
cursor : initial;
|
|
||||||
color : #666;
|
|
||||||
}
|
|
||||||
&.error{
|
|
||||||
position : relative;
|
|
||||||
background-color : @red;
|
|
||||||
.errorContainer{
|
|
||||||
position : absolute;
|
|
||||||
top : 29px;
|
|
||||||
left : -20px;
|
|
||||||
z-index : 1000;
|
|
||||||
width : 170px;
|
|
||||||
padding : 8px;
|
|
||||||
background-color : #333;
|
|
||||||
a{
|
|
||||||
color : @teal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
Account : require('./account.navitem.jsx'),
|
|
||||||
BrewTitle : require('./brewTitle.navitem.jsx'),
|
|
||||||
ContinousSave : require('./continousSave.navitem.jsx'),
|
|
||||||
Issue : require('./issue.navitem.jsx'),
|
|
||||||
Patreon : require('./patreon.navitem.jsx'),
|
|
||||||
Print : require('./print.navitem.jsx'),
|
|
||||||
Recent : require('./recent.navitem.jsx'),
|
|
||||||
StaticSave : require('./staticSave.navitem.jsx'),
|
|
||||||
};
|
|
||||||
@@ -3,7 +3,6 @@ var Nav = require('naturalcrit/nav/nav.jsx');
|
|||||||
|
|
||||||
module.exports = function(props){
|
module.exports = function(props){
|
||||||
return <Nav.item
|
return <Nav.item
|
||||||
{...props}
|
|
||||||
className='patreon'
|
className='patreon'
|
||||||
newTab={true}
|
newTab={true}
|
||||||
href='https://www.patreon.com/stolksdorf'
|
href='https://www.patreon.com/stolksdorf'
|
||||||
|
|||||||
@@ -8,9 +8,6 @@ var Nav = require('naturalcrit/nav/nav.jsx');
|
|||||||
const VIEW_KEY = 'homebrewery-recently-viewed';
|
const VIEW_KEY = 'homebrewery-recently-viewed';
|
||||||
const EDIT_KEY = 'homebrewery-recently-edited';
|
const EDIT_KEY = 'homebrewery-recently-edited';
|
||||||
|
|
||||||
//DEPRICATED
|
|
||||||
|
|
||||||
|
|
||||||
var BaseItem = React.createClass({
|
var BaseItem = React.createClass({
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
@@ -31,8 +28,6 @@ var BaseItem = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
console.log('Recent nav item is depricated');
|
|
||||||
|
|
||||||
var brews = JSON.parse(localStorage.getItem(this.props.storageKey) || '[]');
|
var brews = JSON.parse(localStorage.getItem(this.props.storageKey) || '[]');
|
||||||
|
|
||||||
brews = _.filter(brews, (brew)=>{
|
brews = _.filter(brews, (brew)=>{
|
||||||
|
|||||||
51
client/homebrew/navbar/reddit.navitem.jsx
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
var React = require('react');
|
||||||
|
var _ = require('lodash');
|
||||||
|
var cx = require('classnames');
|
||||||
|
|
||||||
|
//var striptags = require('striptags');
|
||||||
|
|
||||||
|
var Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
|
|
||||||
|
const MAX_URL_SIZE = 2083;
|
||||||
|
const MAIN_URL = "https://www.reddit.com/r/UnearthedArcana/submit?selftext=true"
|
||||||
|
|
||||||
|
|
||||||
|
var RedditShare = React.createClass({
|
||||||
|
getDefaultProps: function() {
|
||||||
|
return {
|
||||||
|
brew : {
|
||||||
|
title : '',
|
||||||
|
sharedId : '',
|
||||||
|
text : ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
getText : function(){
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
handleClick : function(){
|
||||||
|
var url = [
|
||||||
|
MAIN_URL,
|
||||||
|
'title=' + encodeURIComponent(this.props.brew.title ? this.props.brew.title : 'Check out my brew!'),
|
||||||
|
|
||||||
|
'text=' + encodeURIComponent(this.props.brew.text)
|
||||||
|
|
||||||
|
|
||||||
|
].join('&');
|
||||||
|
|
||||||
|
window.open(url, '_blank');
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
render : function(){
|
||||||
|
return <Nav.item icon='fa-reddit-alien' color='red' onClick={this.handleClick}>
|
||||||
|
share on reddit
|
||||||
|
</Nav.item>
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = RedditShare;
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
const React = require('react');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const cx = require('classnames');
|
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
|
||||||
const Store = require('homebrewery/brew.store.js');
|
|
||||||
const Actions = require('homebrewery/brew.actions.js');
|
|
||||||
|
|
||||||
const StaticSave = React.createClass({
|
|
||||||
getDefaultProps: function() {
|
|
||||||
return {
|
|
||||||
status : 'ready'
|
|
||||||
};
|
|
||||||
},
|
|
||||||
handleClick : function(){
|
|
||||||
Actions.create();
|
|
||||||
},
|
|
||||||
render : function(){
|
|
||||||
if(this.props.status === 'saving'){
|
|
||||||
return <Nav.item icon='fa-spinner fa-spin' className='staticSave'>
|
|
||||||
save...
|
|
||||||
</Nav.item>
|
|
||||||
}
|
|
||||||
if(this.props.status === 'ready'){
|
|
||||||
return <Nav.item icon='fa-save' className='staticSave' onClick={this.handleClick}>
|
|
||||||
save
|
|
||||||
</Nav.item>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = Store.createSmartComponent(StaticSave, ()=>{
|
|
||||||
return {
|
|
||||||
status : Store.getStatus()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,63 +1,230 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
const request = require("superagent");
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
const Navbar = require('../../navbar/navbar.jsx');
|
const Navbar = require('../../navbar/navbar.jsx');
|
||||||
const Items = require('../../navbar/navitems.js');
|
|
||||||
|
|
||||||
const BrewInterface = require('homebrewery/brewInterface/brewInterface.jsx');
|
const ReportIssue = require('../../navbar/issue.navitem.jsx');
|
||||||
const Utils = require('homebrewery/utils.js');
|
const PrintLink = require('../../navbar/print.navitem.jsx');
|
||||||
|
const Account = require('../../navbar/account.navitem.jsx');
|
||||||
|
//const RecentlyEdited = require('../../navbar/recent.navitem.jsx').edited;
|
||||||
|
|
||||||
const Store = require('homebrewery/brew.store.js');
|
const SplitPane = require('naturalcrit/splitPane/splitPane.jsx');
|
||||||
const Actions = require('homebrewery/brew.actions.js');
|
const Editor = require('../../editor/editor.jsx');
|
||||||
|
const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
||||||
|
|
||||||
|
const Markdown = require('naturalcrit/markdown.js');
|
||||||
|
|
||||||
|
const SAVE_TIMEOUT = 3000;
|
||||||
|
|
||||||
|
|
||||||
const EditPage = React.createClass({
|
const EditPage = React.createClass({
|
||||||
|
getDefaultProps: function() {
|
||||||
|
return {
|
||||||
|
brew : {
|
||||||
|
text : '',
|
||||||
|
shareId : null,
|
||||||
|
editId : null,
|
||||||
|
createdAt : null,
|
||||||
|
updatedAt : null,
|
||||||
|
|
||||||
|
title : '',
|
||||||
|
description : '',
|
||||||
|
tags : '',
|
||||||
|
published : false,
|
||||||
|
authors : [],
|
||||||
|
systems : []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
brew : this.props.brew,
|
||||||
|
|
||||||
|
isSaving : false,
|
||||||
|
isPending : false,
|
||||||
|
errors : null,
|
||||||
|
htmlErrors : Markdown.validate(this.props.brew.text),
|
||||||
|
lastUpdated : this.props.brew.updatedAt
|
||||||
|
};
|
||||||
|
},
|
||||||
|
savedBrew : null,
|
||||||
|
|
||||||
componentDidMount: function(){
|
componentDidMount: function(){
|
||||||
|
this.trySave();
|
||||||
|
window.onbeforeunload = ()=>{
|
||||||
|
if(this.state.isSaving || this.state.isPending){
|
||||||
|
return 'You have unsaved changes!';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
htmlErrors : Markdown.validate(this.state.brew.text)
|
||||||
|
})
|
||||||
|
|
||||||
document.addEventListener('keydown', this.handleControlKeys);
|
document.addEventListener('keydown', this.handleControlKeys);
|
||||||
},
|
},
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
|
window.onbeforeunload = function(){};
|
||||||
document.removeEventListener('keydown', this.handleControlKeys);
|
document.removeEventListener('keydown', this.handleControlKeys);
|
||||||
},
|
},
|
||||||
handleControlKeys : Utils.controlKeys({
|
|
||||||
s : Actions.save,
|
|
||||||
p : Actions.print
|
handleControlKeys : function(e){
|
||||||
}),
|
if(!(e.ctrlKey || e.metaKey)) return;
|
||||||
render : function(){
|
const S_KEY = 83;
|
||||||
return <div className='editPage page'>
|
const P_KEY = 80;
|
||||||
<SmartNav />
|
if(e.keyCode == S_KEY) this.save();
|
||||||
<div className='content'>
|
if(e.keyCode == P_KEY) window.open(`/print/${this.props.brew.shareId}?dialog=true`, '_blank').focus();
|
||||||
<BrewInterface />
|
if(e.keyCode == P_KEY || e.keyCode == S_KEY){
|
||||||
</div>
|
e.stopPropagation();
|
||||||
</div>
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
handleSplitMove : function(){
|
||||||
|
this.refs.editor.update();
|
||||||
|
},
|
||||||
|
|
||||||
|
handleMetadataChange : function(metadata){
|
||||||
|
this.setState({
|
||||||
|
brew : _.merge({}, this.state.brew, metadata),
|
||||||
|
isPending : true,
|
||||||
|
}, ()=>{
|
||||||
|
this.trySave();
|
||||||
});
|
});
|
||||||
|
|
||||||
const SmartNav = Store.createSmartComponent(React.createClass({
|
|
||||||
getDefaultProps: function() {
|
|
||||||
return {
|
|
||||||
brew : {}
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
render : function(){
|
|
||||||
|
handleTextChange : function(text){
|
||||||
|
|
||||||
|
//If there are errors, run the validator on everychange to give quick feedback
|
||||||
|
var htmlErrors = this.state.htmlErrors;
|
||||||
|
if(htmlErrors.length) htmlErrors = Markdown.validate(text);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
brew : _.merge({}, this.state.brew, {text : text}),
|
||||||
|
isPending : true,
|
||||||
|
htmlErrors : htmlErrors
|
||||||
|
});
|
||||||
|
|
||||||
|
this.trySave();
|
||||||
|
},
|
||||||
|
|
||||||
|
hasChanges : function(){
|
||||||
|
if(this.savedBrew){
|
||||||
|
return !_.isEqual(this.state.brew, this.savedBrew)
|
||||||
|
}else{
|
||||||
|
return !_.isEqual(this.state.brew, this.props.brew)
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
trySave : function(){
|
||||||
|
if(!this.debounceSave) this.debounceSave = _.debounce(this.save, SAVE_TIMEOUT);
|
||||||
|
if(this.hasChanges()){
|
||||||
|
this.debounceSave();
|
||||||
|
}else{
|
||||||
|
this.debounceSave.cancel();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
save : function(){
|
||||||
|
if(this.debounceSave && this.debounceSave.cancel) this.debounceSave.cancel();
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
isSaving : true,
|
||||||
|
errors : null,
|
||||||
|
htmlErrors : Markdown.validate(this.state.brew.text)
|
||||||
|
});
|
||||||
|
|
||||||
|
request
|
||||||
|
.put('/api/update/' + this.props.brew.editId)
|
||||||
|
.send(this.state.brew)
|
||||||
|
.end((err, res) => {
|
||||||
|
if(err){
|
||||||
|
this.setState({
|
||||||
|
errors : err,
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
this.savedBrew = res.body;
|
||||||
|
this.setState({
|
||||||
|
isPending : false,
|
||||||
|
isSaving : false,
|
||||||
|
lastUpdated : res.body.updatedAt
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
renderSaveButton : function(){
|
||||||
|
if(this.state.errors){
|
||||||
|
var errMsg = '';
|
||||||
|
try{
|
||||||
|
errMsg += this.state.errors.toString() + '\n\n';
|
||||||
|
errMsg += '```\n' + JSON.stringify(this.state.errors.response.error, null, ' ') + '\n```';
|
||||||
|
}catch(e){}
|
||||||
|
|
||||||
|
return <Nav.item className='save error' icon="fa-warning">
|
||||||
|
Oops!
|
||||||
|
<div className='errorContainer'>
|
||||||
|
Looks like there was a problem saving. <br />
|
||||||
|
Report the issue <a target='_blank' href={'https://github.com/stolksdorf/naturalcrit/issues/new?body='+ encodeURIComponent(errMsg)}>
|
||||||
|
here
|
||||||
|
</a>.
|
||||||
|
</div>
|
||||||
|
</Nav.item>
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.state.isSaving){
|
||||||
|
return <Nav.item className='save' icon="fa-spinner fa-spin">saving...</Nav.item>
|
||||||
|
}
|
||||||
|
if(this.state.isPending && this.hasChanges()){
|
||||||
|
return <Nav.item className='save' onClick={this.save} color='blue' icon='fa-save'>Save Now</Nav.item>
|
||||||
|
}
|
||||||
|
if(!this.state.isPending && !this.state.isSaving){
|
||||||
|
return <Nav.item className='save saved'>saved.</Nav.item>
|
||||||
|
}
|
||||||
|
},
|
||||||
|
renderNavbar : function(){
|
||||||
return <Navbar>
|
return <Navbar>
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
<Items.BrewTitle />
|
<Nav.item className='brewTitle'>{this.state.brew.title}</Nav.item>
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
<Items.ContinousSave />
|
{this.renderSaveButton()}
|
||||||
<Items.Issue />
|
{/*<RecentlyEdited brew={this.props.brew} />*/}
|
||||||
|
<ReportIssue />
|
||||||
<Nav.item newTab={true} href={'/share/' + this.props.brew.shareId} color='teal' icon='fa-share-alt'>
|
<Nav.item newTab={true} href={'/share/' + this.props.brew.shareId} color='teal' icon='fa-share-alt'>
|
||||||
Share
|
Share
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
<Items.Print shareId={this.props.brew.shareId} />
|
<PrintLink shareId={this.props.brew.shareId} />
|
||||||
<Items.Account />
|
<Account />
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
|
},
|
||||||
|
|
||||||
|
render : function(){
|
||||||
|
return <div className='editPage page'>
|
||||||
|
{this.renderNavbar()}
|
||||||
|
|
||||||
|
<div className='content'>
|
||||||
|
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
||||||
|
<Editor
|
||||||
|
ref='editor'
|
||||||
|
value={this.state.brew.text}
|
||||||
|
onChange={this.handleTextChange}
|
||||||
|
metadata={this.state.brew}
|
||||||
|
onMetadataChange={this.handleMetadataChange}
|
||||||
|
/>
|
||||||
|
<BrewRenderer text={this.state.brew.text} errors={this.state.htmlErrors} />
|
||||||
|
</SplitPane>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
}), ()=>{
|
|
||||||
return {brew : Store.getBrew()}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = EditPage;
|
module.exports = EditPage;
|
||||||
|
|||||||
@@ -1,4 +1,27 @@
|
|||||||
|
|
||||||
.editPage{
|
.editPage{
|
||||||
|
.navItem.save{
|
||||||
|
width : 105px;
|
||||||
|
text-align : center;
|
||||||
|
&.saved{
|
||||||
|
cursor : initial;
|
||||||
|
color : #666;
|
||||||
|
}
|
||||||
|
&.error{
|
||||||
|
position : relative;
|
||||||
|
background-color : @red;
|
||||||
|
.errorContainer{
|
||||||
|
position : absolute;
|
||||||
|
top : 29px;
|
||||||
|
left : -20px;
|
||||||
|
z-index : 1000;
|
||||||
|
width : 120px;
|
||||||
|
padding : 8px;
|
||||||
|
background-color : #333;
|
||||||
|
a{
|
||||||
|
color : @teal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
12
client/homebrew/pages/hijackPrint.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
//TODO: Depricate
|
||||||
|
|
||||||
|
module.exports = function(shareId){
|
||||||
|
return function(event){
|
||||||
|
event = event || window.event;
|
||||||
|
if((event.ctrlKey || event.metaKey) && event.keyCode == 80){
|
||||||
|
var win = window.open(`/homebrew/print/${shareId}?dialog=true`, '_blank');
|
||||||
|
win.focus();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
Before Width: | Height: | Size: 187 KiB |
|
Before Width: | Height: | Size: 822 KiB |
@@ -1,34 +1,63 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
const request = require("superagent");
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
const Navbar = require('../../navbar/navbar.jsx');
|
const Navbar = require('../../navbar/navbar.jsx');
|
||||||
const NavItem = require('../../navbar/navitems.js');
|
const PatreonNavItem = require('../../navbar/patreon.navitem.jsx');
|
||||||
|
const IssueNavItem = require('../../navbar/issue.navitem.jsx');
|
||||||
|
const RecentNavItem = require('../../navbar/recent.navitem.jsx');
|
||||||
|
const AccountNavItem = require('../../navbar/account.navitem.jsx');
|
||||||
|
|
||||||
|
|
||||||
//const BrewInterface = require('homebrewery/brewInterface/brewInterface.jsx');
|
const SplitPane = require('naturalcrit/splitPane/splitPane.jsx');
|
||||||
const BrewCard = require('homebrewery/brewCard/brewCard.jsx');
|
const Editor = require('../../editor/editor.jsx');
|
||||||
|
const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
||||||
|
|
||||||
|
|
||||||
//const Actions = require('homebrewery/brew.actions.js');
|
|
||||||
|
|
||||||
const HomePage = React.createClass({
|
const HomePage = React.createClass({
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
topBrews : []
|
welcomeText : '',
|
||||||
|
ver : '0.0.0'
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
text: this.props.welcomeText
|
||||||
|
};
|
||||||
|
},
|
||||||
|
handleSave : function(){
|
||||||
|
request.post('/api')
|
||||||
|
.send({
|
||||||
|
text : this.state.text
|
||||||
|
})
|
||||||
|
.end((err, res)=>{
|
||||||
|
if(err) return;
|
||||||
|
var brew = res.body;
|
||||||
|
window.location = '/edit/' + brew.editId;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSplitMove : function(){
|
||||||
|
this.refs.editor.update();
|
||||||
|
},
|
||||||
|
handleTextChange : function(text){
|
||||||
|
this.setState({
|
||||||
|
text : text
|
||||||
|
});
|
||||||
|
},
|
||||||
renderNavbar : function(){
|
renderNavbar : function(){
|
||||||
return <Navbar>
|
return <Navbar ver={this.props.ver}>
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
<NavItem.Patreon collaspe={true} />
|
<PatreonNavItem />
|
||||||
<NavItem.Issue collaspe={true} />
|
<IssueNavItem />
|
||||||
<Nav.item newTab={true} href='/changelog' color='purple' icon='fa-star' collaspe={true}>
|
<Nav.item newTab={true} href='/changelog' color='purple' icon='fa-file-text-o'>
|
||||||
What's new
|
Changelog
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
<NavItem.Recent.both />
|
<RecentNavItem.both />
|
||||||
<NavItem.Account />
|
<AccountNavItem />
|
||||||
{/*}
|
{/*}
|
||||||
<Nav.item href='/new' color='green' icon='fa-external-link'>
|
<Nav.item href='/new' color='green' icon='fa-external-link'>
|
||||||
New Brew
|
New Brew
|
||||||
@@ -38,58 +67,24 @@ const HomePage = React.createClass({
|
|||||||
</Navbar>
|
</Navbar>
|
||||||
},
|
},
|
||||||
|
|
||||||
renderNavigation : function(){
|
|
||||||
return <div className='navigation'>
|
|
||||||
<p>
|
|
||||||
Effortlessly create Authnetic looking D&D homebrews with just text
|
|
||||||
</p>
|
|
||||||
<div>
|
|
||||||
<a className='button new' target='_blank' href='/new'>
|
|
||||||
<i className='fa fa-magic' />
|
|
||||||
<h3>New</h3>
|
|
||||||
<p>This is some sample text</p>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a className='button search' target='_blank' href='/search'>
|
|
||||||
<i className='fa fa-search' />
|
|
||||||
<h3>Search</h3>
|
|
||||||
<p>This is some sample text</p>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<a className='button docs' target='_blank' href='/docs'>
|
|
||||||
<i className='fa fa-book' />
|
|
||||||
<h3>Docs</h3>
|
|
||||||
<p>This is some sample text</p>
|
|
||||||
</a>
|
|
||||||
<a className='button account' target='_blank' href='/account'>
|
|
||||||
<i className='fa fa-user' />
|
|
||||||
<h3>Account</h3>
|
|
||||||
<p>This is some sample text</p>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
renderTopBrews : function(){
|
|
||||||
return <div className='topBrews'>
|
|
||||||
{_.map(this.props.brews, (brew)=><BrewCard brew={brew} key={brew._id}/>)}
|
|
||||||
</div>
|
|
||||||
},
|
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
return <div className='homePage page'>
|
return <div className='homePage page'>
|
||||||
{this.renderNavbar()}
|
{this.renderNavbar()}
|
||||||
<div className='content'>
|
|
||||||
<div className='hero'>
|
|
||||||
hero
|
|
||||||
<h1>The Homebrewery</h1>
|
|
||||||
|
|
||||||
|
<div className='content'>
|
||||||
|
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
||||||
|
<Editor value={this.state.text} onChange={this.handleTextChange} ref='editor'/>
|
||||||
|
<BrewRenderer text={this.state.text} />
|
||||||
|
</SplitPane>
|
||||||
</div>
|
</div>
|
||||||
{this.renderNavigation()}
|
|
||||||
{this.renderTopBrews()}
|
<div className={cx('floatingSaveButton', {show : this.props.welcomeText != this.state.text})} onClick={this.handleSave}>
|
||||||
|
Save current <i className='fa fa-save' />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<a href='/new' className='floatingNewButton'>
|
||||||
|
Create your own <i className='fa fa-magic' />
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,109 +1,43 @@
|
|||||||
|
|
||||||
@import 'homebrewery/phb_style/phb.fonts.less';
|
|
||||||
.homePage{
|
.homePage{
|
||||||
position : relative;
|
position : relative;
|
||||||
.hero{
|
a.floatingNewButton{
|
||||||
// .backgroundScrollAnimation();
|
|
||||||
height : 400px;
|
|
||||||
background-image : url('/assets/homebrew/pages/homePage/fantasy_background.jpg');
|
|
||||||
background-position : 1% 15%;
|
|
||||||
h1{
|
|
||||||
margin-top : 15%;
|
|
||||||
font-family : BookInsanity;
|
|
||||||
font-size : 3em;
|
|
||||||
font-weight : 800;
|
|
||||||
letter-spacing : 0.3em;
|
|
||||||
text-align : center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.navigation{
|
|
||||||
padding : 30px;
|
|
||||||
background-image : url('/assets/homebrew/pages/homePage/dmg_bg.jpg');
|
|
||||||
text-align : center;
|
|
||||||
&>div{
|
|
||||||
//display : flex;
|
|
||||||
margin : 0 auto;
|
|
||||||
// justify-content : center;
|
|
||||||
}
|
|
||||||
p{
|
|
||||||
margin-bottom : 20px;
|
|
||||||
font-size : 0.8em;
|
|
||||||
}
|
|
||||||
a.button{
|
|
||||||
.animate(background-color);
|
.animate(background-color);
|
||||||
position : relative;
|
|
||||||
display : block;
|
|
||||||
height : 60px;
|
|
||||||
max-width : 280px;
|
|
||||||
width : 100%;
|
|
||||||
margin : 15px;
|
|
||||||
padding : 20px 30px;
|
|
||||||
padding-left : 80px;
|
|
||||||
cursor : pointer;
|
|
||||||
background-color : fade(@red, 30%);
|
|
||||||
color : black;
|
|
||||||
text-align : left;
|
|
||||||
text-decoration : none;
|
|
||||||
//flex-grow : 0;
|
|
||||||
display: inline-block;
|
|
||||||
i{
|
|
||||||
position : absolute;
|
position : absolute;
|
||||||
top : 15px;
|
|
||||||
left : 25px;
|
|
||||||
font-size : 2em;
|
|
||||||
//transform-style: preserve-3d;
|
|
||||||
transform: rotateY(0deg);
|
|
||||||
}
|
|
||||||
h3{
|
|
||||||
display : block;
|
display : block;
|
||||||
margin-bottom : 3px;
|
right : 70px;
|
||||||
font-size : 1.2em;
|
bottom : 70px;
|
||||||
font-weight : 600;
|
z-index : 100;
|
||||||
letter-spacing : 0.2em;
|
z-index : 5001;
|
||||||
}
|
padding : 1em;
|
||||||
p{
|
background-color : @orange;
|
||||||
.fadeOutLeft();
|
font-size : 1.5em;
|
||||||
.keep();
|
color : white;
|
||||||
opacity : 0;
|
text-decoration : none;
|
||||||
font-size : 0.8em;
|
box-shadow : 3px 3px 15px black;
|
||||||
}
|
|
||||||
&:hover{
|
&:hover{
|
||||||
background-color : fade(@red, 50%);
|
background-color : darken(@orange, 20%);
|
||||||
p{
|
|
||||||
.fadeInRight();
|
|
||||||
}
|
}
|
||||||
i{
|
}
|
||||||
transform: rotateY(360deg);
|
.floatingSaveButton{
|
||||||
.animateAll(0.5s);
|
.animateAll();
|
||||||
|
position : absolute;
|
||||||
|
display : block;
|
||||||
|
right : 200px;
|
||||||
|
bottom : 90px;
|
||||||
|
z-index : 100;
|
||||||
|
z-index : 5000;
|
||||||
|
padding : 0.8em;
|
||||||
|
cursor : pointer;
|
||||||
|
background-color : @blue;
|
||||||
|
font-size : 0.8em;
|
||||||
|
color : white;
|
||||||
|
text-decoration : none;
|
||||||
|
box-shadow : 3px 3px 15px black;
|
||||||
|
&:hover{
|
||||||
|
background-color : darken(@blue, 20%);
|
||||||
|
}
|
||||||
|
&.show{
|
||||||
|
right : 350px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.topBrews{
|
|
||||||
background-image : url('/assets/homebrew/pages/homePage/phb_bg.jpg');
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
// .vendor(@property, @value) {
|
|
||||||
// -webkit-@{property}: @value;
|
|
||||||
// -khtml-@{property}: @value;
|
|
||||||
// -moz-@{property}: @value;
|
|
||||||
// @{property}: @value;
|
|
||||||
// }
|
|
||||||
// .backgroundScrollAnimation(){
|
|
||||||
// @top : -100px;
|
|
||||||
// .vendor(animation-iteration-count, infinite);
|
|
||||||
// .createAnimation(backgroundScroll, 60s, linear);
|
|
||||||
// .backgroundScrollKeyFrames(){
|
|
||||||
// 0% { background-position: 0 @top}
|
|
||||||
// 100% { background-position: -1200px @top}
|
|
||||||
// }
|
|
||||||
// @-webkit-keyframes backgroundScroll {.backgroundScrollKeyFrames();}
|
|
||||||
// @-moz-keyframes backgroundScroll {.backgroundScrollKeyFrames();}
|
|
||||||
// @-ms-keyframes backgroundScroll {.backgroundScrollKeyFrames();}
|
|
||||||
// @-o-keyframes backgroundScroll {.backgroundScrollKeyFrames();}
|
|
||||||
// @keyframes backgroundScroll {.backgroundScrollKeyFrames();}
|
|
||||||
// }
|
|
||||||
|
Before Width: | Height: | Size: 171 KiB |
@@ -1,59 +1,158 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const cx = require('classnames');
|
||||||
|
const request = require("superagent");
|
||||||
|
|
||||||
|
const Markdown = require('naturalcrit/markdown.js');
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
const Navbar = require('../../navbar/navbar.jsx');
|
const Navbar = require('../../navbar/navbar.jsx');
|
||||||
const Items = require('../../navbar/navitems.js');
|
const AccountNavItem = require('../../navbar/account.navitem.jsx');
|
||||||
|
const IssueNavItem = require('../../navbar/issue.navitem.jsx');
|
||||||
|
|
||||||
const Store = require('homebrewery/brew.store.js');
|
const SplitPane = require('naturalcrit/splitPane/splitPane.jsx');
|
||||||
const Actions = require('homebrewery/brew.actions.js');
|
const Editor = require('../../editor/editor.jsx');
|
||||||
|
const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
||||||
|
|
||||||
const BrewInterface = require('homebrewery/brewInterface/brewInterface.jsx');
|
|
||||||
const Utils = require('homebrewery/utils.js');
|
|
||||||
|
|
||||||
const KEY = 'homebrewery-new';
|
const KEY = 'homebrewery-new';
|
||||||
|
|
||||||
const NewPage = React.createClass({
|
const NewPage = React.createClass({
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
metadata : {
|
||||||
|
title : '',
|
||||||
|
description : '',
|
||||||
|
tags : '',
|
||||||
|
published : false,
|
||||||
|
authors : [],
|
||||||
|
systems : []
|
||||||
|
},
|
||||||
|
|
||||||
|
text: '',
|
||||||
|
isSaving : false,
|
||||||
|
errors : []
|
||||||
|
};
|
||||||
|
},
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
try{
|
const storage = localStorage.getItem(KEY);
|
||||||
const storedBrew = JSON.parse(localStorage.getItem(KEY));
|
if(storage){
|
||||||
if(storedBrew && storedBrew.text) Actions.setBrew(storedBrew);
|
this.setState({
|
||||||
}catch(e){}
|
text : storage
|
||||||
Store.updateEmitter.on('change', this.saveToLocal);
|
})
|
||||||
|
}
|
||||||
document.addEventListener('keydown', this.handleControlKeys);
|
document.addEventListener('keydown', this.handleControlKeys);
|
||||||
},
|
},
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
Store.updateEmitter.removeListener('change', this.saveToLocal);
|
|
||||||
document.removeEventListener('keydown', this.handleControlKeys);
|
document.removeEventListener('keydown', this.handleControlKeys);
|
||||||
},
|
},
|
||||||
|
|
||||||
saveToLocal : function(){
|
handleControlKeys : function(e){
|
||||||
localStorage.setItem(KEY, JSON.stringify(Store.getBrew()));
|
if(!(e.ctrlKey || e.metaKey)) return;
|
||||||
|
const S_KEY = 83;
|
||||||
|
const P_KEY = 80;
|
||||||
|
if(e.keyCode == S_KEY) this.save();
|
||||||
|
if(e.keyCode == P_KEY) this.print();
|
||||||
|
if(e.keyCode == P_KEY || e.keyCode == S_KEY){
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
handleSplitMove : function(){
|
||||||
|
this.refs.editor.update();
|
||||||
|
},
|
||||||
|
|
||||||
|
handleMetadataChange : function(metadata){
|
||||||
|
this.setState({
|
||||||
|
metadata : _.merge({}, this.state.metadata, metadata)
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
handleTextChange : function(text){
|
||||||
|
this.setState({
|
||||||
|
text : text,
|
||||||
|
errors : Markdown.validate(text)
|
||||||
|
});
|
||||||
|
localStorage.setItem(KEY, text);
|
||||||
|
},
|
||||||
|
|
||||||
|
save : function(){
|
||||||
|
this.setState({
|
||||||
|
isSaving : true
|
||||||
|
});
|
||||||
|
|
||||||
|
request.post('/api')
|
||||||
|
.send(_.merge({}, this.state.metadata, {
|
||||||
|
text : this.state.text
|
||||||
|
}))
|
||||||
|
.end((err, res)=>{
|
||||||
|
if(err){
|
||||||
|
this.setState({
|
||||||
|
isSaving : false
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.onbeforeunload = function(){};
|
||||||
|
const brew = res.body;
|
||||||
|
localStorage.removeItem(KEY);
|
||||||
|
window.location = '/edit/' + brew.editId;
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
renderSaveButton : function(){
|
||||||
|
if(this.state.isSaving){
|
||||||
|
return <Nav.item icon='fa-spinner fa-spin' className='saveButton'>
|
||||||
|
save...
|
||||||
|
</Nav.item>
|
||||||
|
}else{
|
||||||
|
return <Nav.item icon='fa-save' className='saveButton' onClick={this.save}>
|
||||||
|
save
|
||||||
|
</Nav.item>
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
print : function(){
|
||||||
|
localStorage.setItem('print', this.state.text);
|
||||||
|
window.open('/print?dialog=true&local=print','_blank');
|
||||||
|
},
|
||||||
|
|
||||||
|
renderLocalPrintButton : function(){
|
||||||
|
return <Nav.item color='purple' icon='fa-file-pdf-o' onClick={this.print}>
|
||||||
|
get PDF
|
||||||
|
</Nav.item>
|
||||||
|
},
|
||||||
|
|
||||||
|
renderNavbar : function(){
|
||||||
|
return <Navbar>
|
||||||
|
|
||||||
|
<Nav.section>
|
||||||
|
<Nav.item className='brewTitle'>{this.state.metadata.title}</Nav.item>
|
||||||
|
</Nav.section>
|
||||||
|
|
||||||
|
<Nav.section>
|
||||||
|
{this.renderSaveButton()}
|
||||||
|
{this.renderLocalPrintButton()}
|
||||||
|
<IssueNavItem />
|
||||||
|
<AccountNavItem />
|
||||||
|
</Nav.section>
|
||||||
|
</Navbar>
|
||||||
},
|
},
|
||||||
handleControlKeys : Utils.controlKeys({
|
|
||||||
s : Actions.saveNew,
|
|
||||||
p : Actions.localPrint
|
|
||||||
}),
|
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
return <div className='newPage page'>
|
return <div className='newPage page'>
|
||||||
<Navbar>
|
{this.renderNavbar()}
|
||||||
<Nav.section>
|
|
||||||
<Items.BrewTitle />
|
|
||||||
</Nav.section>
|
|
||||||
|
|
||||||
<Nav.section>
|
|
||||||
<Items.StaticSave />
|
|
||||||
<Nav.item color='purple' icon='fa-file-pdf-o' onClick={Actions.localPrint}>
|
|
||||||
get PDF
|
|
||||||
</Nav.item>
|
|
||||||
<Items.Issue collaspe={true} />
|
|
||||||
<Items.Account />
|
|
||||||
</Nav.section>
|
|
||||||
</Navbar>
|
|
||||||
|
|
||||||
<div className='content'>
|
<div className='content'>
|
||||||
<BrewInterface />
|
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
||||||
|
<Editor
|
||||||
|
ref='editor'
|
||||||
|
value={this.state.text}
|
||||||
|
onChange={this.handleTextChange}
|
||||||
|
metadata={this.state.metadata}
|
||||||
|
onMetadataChange={this.handleMetadataChange}
|
||||||
|
/>
|
||||||
|
<BrewRenderer text={this.state.text} errors={this.state.errors} />
|
||||||
|
</SplitPane>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
.newPage{
|
.newPage{
|
||||||
|
|
||||||
|
.saveButton{
|
||||||
|
background-color: @orange;
|
||||||
|
&:hover{
|
||||||
|
background-color: @green;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,7 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
const Markdown = require('naturalcrit/markdown.js');
|
||||||
|
|
||||||
const BrewRenderer = require('homebrewery/brewRenderer/brewRenderer.jsx');
|
|
||||||
|
|
||||||
const Markdown = require('homebrewery/markdown.js');
|
|
||||||
|
|
||||||
const Headtags = require('vitreum/headtags');
|
|
||||||
|
|
||||||
const PrintPage = React.createClass({
|
const PrintPage = React.createClass({
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
@@ -15,56 +9,37 @@ const PrintPage = React.createClass({
|
|||||||
query : {},
|
query : {},
|
||||||
brew : {
|
brew : {
|
||||||
text : '',
|
text : '',
|
||||||
style : ''
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
brew: this.props.brew
|
brewText: this.props.brew.text
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
if(this.props.query.local){
|
if(this.props.query.local){
|
||||||
try{
|
this.setState({ brewText : localStorage.getItem(this.props.query.local)});
|
||||||
this.setState({
|
|
||||||
brew : JSON.parse(
|
|
||||||
localStorage.getItem(this.props.query.local)
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}catch(e){}
|
|
||||||
}
|
}
|
||||||
//if(this.props.query.dialog) window.print();
|
|
||||||
},
|
if(this.props.query.dialog) window.print();
|
||||||
//TODO: Print page shouldn't replicate functionality in brew renderer
|
|
||||||
renderStyle : function(){
|
|
||||||
if(!this.state.brew.style) return;
|
|
||||||
return <style>{this.state.brew.style.replace(/;/g, ' !important;')}</style>
|
|
||||||
},
|
},
|
||||||
|
|
||||||
renderPages : function(){
|
renderPages : function(){
|
||||||
return _.map(this.state.brew.text.split('\\page'), (page, index) => {
|
return _.map(this.state.brewText.split('\\page'), (page, index) => {
|
||||||
return <div
|
return <div
|
||||||
className='phb v2'
|
className='phb'
|
||||||
id={`p${index + 1}`}
|
id={`p${index + 1}`}
|
||||||
dangerouslySetInnerHTML={{__html:Markdown.render(page)}}
|
dangerouslySetInnerHTML={{__html:Markdown.render(page)}}
|
||||||
key={index} />;
|
key={index} />;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
renderPrintInstructions : function(){
|
|
||||||
return <div className='printInstructions'>
|
|
||||||
Hey, I'm really cool instructions!!!!!
|
|
||||||
|
|
||||||
</div>
|
|
||||||
},
|
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
return <div className='printPage'>
|
return <div>
|
||||||
<Headtags.title>{this.state.brew.title}</Headtags.title>
|
{this.renderPages()}
|
||||||
{this.renderPrintInstructions()}
|
|
||||||
|
|
||||||
<BrewRenderer text={this.state.brew.text} style={this.state.brew.style} />
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,17 +1,3 @@
|
|||||||
|
|
||||||
.printPage{
|
.printPage{
|
||||||
position : relative;
|
|
||||||
@media print{
|
|
||||||
.printInstructions{
|
|
||||||
display : none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.printInstructions{
|
|
||||||
position : absolute;
|
|
||||||
top : 0px;
|
|
||||||
right : 0px;
|
|
||||||
z-index : 100000;
|
|
||||||
padding : 30px;
|
|
||||||
background-color : @blue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -9,63 +9,60 @@ const ReportIssue = require('../../navbar/issue.navitem.jsx');
|
|||||||
//const RecentlyViewed = require('../../navbar/recent.navitem.jsx').viewed;
|
//const RecentlyViewed = require('../../navbar/recent.navitem.jsx').viewed;
|
||||||
const Account = require('../../navbar/account.navitem.jsx');
|
const Account = require('../../navbar/account.navitem.jsx');
|
||||||
|
|
||||||
const BrewView = require('homebrewery/BrewView/BrewView.jsx');
|
|
||||||
const Utils = require('homebrewery/utils.js');
|
|
||||||
|
|
||||||
const Actions = require('homebrewery/brew.actions.js');
|
const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
||||||
const Store = require('homebrewery/brew.store.js');
|
|
||||||
|
|
||||||
const Headtags = require('vitreum/headtags');
|
|
||||||
|
|
||||||
const SharePage = React.createClass({
|
const SharePage = React.createClass({
|
||||||
|
getDefaultProps: function() {
|
||||||
|
return {
|
||||||
|
brew : {
|
||||||
|
title : '',
|
||||||
|
text : '',
|
||||||
|
shareId : null,
|
||||||
|
createdAt : null,
|
||||||
|
updatedAt : null,
|
||||||
|
views : 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
document.addEventListener('keydown', this.handleControlKeys);
|
document.addEventListener('keydown', this.handleControlKeys);
|
||||||
},
|
},
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
document.removeEventListener('keydown', this.handleControlKeys);
|
document.removeEventListener('keydown', this.handleControlKeys);
|
||||||
},
|
},
|
||||||
handleControlKeys : Utils.controlKeys({
|
handleControlKeys : function(e){
|
||||||
p : Actions.print
|
if(!(e.ctrlKey || e.metaKey)) return;
|
||||||
}),
|
const P_KEY = 80;
|
||||||
|
if(e.keyCode == P_KEY){
|
||||||
renderMetatags : function(brew){
|
window.open(`/print/${this.props.brew.shareId}?dialog=true`, '_blank').focus();
|
||||||
let metatags = [
|
e.stopPropagation();
|
||||||
<Headtags.meta key='site_name' property='og:site_name' content='Homebrewery'/>,
|
e.preventDefault();
|
||||||
<Headtags.meta key='type' property='og:type' content='article' />
|
|
||||||
];
|
|
||||||
if(brew.title){
|
|
||||||
metatags.push(<Headtags.meta key='title' property='og:title' content={brew.title} />);
|
|
||||||
}
|
}
|
||||||
if(brew.description){
|
|
||||||
metatags.push(<Headtags.meta key='description' name='description' content={brew.description} />);
|
|
||||||
}
|
|
||||||
if(brew.thumbnail){
|
|
||||||
metatags.push(<Headtags.meta key='image' property='og:image' content={brew.thumbnail} />);
|
|
||||||
}
|
|
||||||
return metatags;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
const brew = Store.getBrew();
|
|
||||||
return <div className='sharePage page'>
|
return <div className='sharePage page'>
|
||||||
{this.renderMetatags(brew)}
|
|
||||||
|
|
||||||
<Navbar>
|
<Navbar>
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
<Nav.item className='brewTitle'>{brew.title}</Nav.item>
|
<Nav.item className='brewTitle'>{this.props.brew.title}</Nav.item>
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
|
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
<ReportIssue collaspe={true} />
|
<ReportIssue />
|
||||||
<PrintLink shareId={brew.shareId} />
|
{/*<RecentlyViewed brew={this.props.brew} />*/}
|
||||||
<Nav.item href={'/source/' + brew.shareId} color='teal' icon='fa-code'>
|
<PrintLink shareId={this.props.brew.shareId} />
|
||||||
|
<Nav.item href={'/source/' + this.props.brew.shareId} color='teal' icon='fa-code'>
|
||||||
source
|
source
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
<Account />
|
<Account />
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
|
|
||||||
<div className='content'>
|
<div className='content'>
|
||||||
<BrewView brew={brew}/>
|
<BrewRenderer text={this.props.brew.text} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ const React = require('react');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
const request = require("superagent");
|
||||||
//TODO: Depriacte
|
|
||||||
|
|
||||||
const BrewItem = React.createClass({
|
const BrewItem = React.createClass({
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
@@ -17,6 +16,24 @@ const BrewItem = React.createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
deleteBrew : function(){
|
||||||
|
if(!confirm("are you sure you want to delete this brew?")) return;
|
||||||
|
if(!confirm("are you REALLY sure? You will not be able to recover it")) return;
|
||||||
|
|
||||||
|
request.get('/api/remove/' + this.props.brew.editId)
|
||||||
|
.send()
|
||||||
|
.end(function(err, res){
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
renderDeleteBrewLink: function(){
|
||||||
|
if(!this.props.brew.editId) return;
|
||||||
|
|
||||||
|
return <a onClick={this.deleteBrew}>
|
||||||
|
<i className='fa fa-trash' />
|
||||||
|
</a>
|
||||||
|
},
|
||||||
renderEditLink: function(){
|
renderEditLink: function(){
|
||||||
if(!this.props.brew.editId) return;
|
if(!this.props.brew.editId) return;
|
||||||
|
|
||||||
@@ -26,7 +43,6 @@ const BrewItem = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
console.log('Brew Item should be depricated');
|
|
||||||
const brew = this.props.brew;
|
const brew = this.props.brew;
|
||||||
return <div className='brewItem'>
|
return <div className='brewItem'>
|
||||||
<h2>{brew.title}</h2>
|
<h2>{brew.title}</h2>
|
||||||
@@ -50,6 +66,7 @@ const BrewItem = React.createClass({
|
|||||||
<i className='fa fa-share-alt' />
|
<i className='fa fa-share-alt' />
|
||||||
</a>
|
</a>
|
||||||
{this.renderEditLink()}
|
{this.renderEditLink()}
|
||||||
|
{this.renderDeleteBrewLink()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ const RecentNavItem = require('../../navbar/recent.navitem.jsx');
|
|||||||
const Account = require('../../navbar/account.navitem.jsx');
|
const Account = require('../../navbar/account.navitem.jsx');
|
||||||
const BrewItem = require('./brewItem/brewItem.jsx');
|
const BrewItem = require('./brewItem/brewItem.jsx');
|
||||||
|
|
||||||
// const brew = {
|
const brew = {
|
||||||
// title : 'SUPER Long title woah now',
|
title : 'SUPER Long title woah now',
|
||||||
// authors : []
|
authors : []
|
||||||
// }
|
}
|
||||||
|
|
||||||
// const BREWS = _.times(25, ()=>{ return brew});
|
const BREWS = _.times(25, ()=>{ return brew});
|
||||||
|
|
||||||
|
|
||||||
const UserPage = React.createClass({
|
const UserPage = React.createClass({
|
||||||
@@ -29,6 +29,7 @@ const UserPage = React.createClass({
|
|||||||
if(!brews || !brews.length) return <div className='noBrews'>No Brews.</div>;
|
if(!brews || !brews.length) return <div className='noBrews'>No Brews.</div>;
|
||||||
|
|
||||||
const sortedBrews = _.sortBy(brews, (brew)=>{ return brew.title; });
|
const sortedBrews = _.sortBy(brews, (brew)=>{ return brew.title; });
|
||||||
|
|
||||||
return _.map(sortedBrews, (brew, idx) => {
|
return _.map(sortedBrews, (brew, idx) => {
|
||||||
return <BrewItem brew={brew} key={idx}/>
|
return <BrewItem brew={brew} key={idx}/>
|
||||||
});
|
});
|
||||||
@@ -51,11 +52,12 @@ const UserPage = React.createClass({
|
|||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
const brews = this.getSortedBrews();
|
const brews = this.getSortedBrews();
|
||||||
|
|
||||||
return <div className='userPage page'>
|
return <div className='userPage page'>
|
||||||
<Navbar>
|
<Navbar>
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
<RecentNavItem.both />
|
<RecentNavItem.both />
|
||||||
<Account userPage={this.props.username} />
|
<Account />
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 327 B After Width: | Height: | Size: 327 B |
|
Before Width: | Height: | Size: 530 B After Width: | Height: | Size: 530 B |
31
client/homebrew/phbStyle/phb.depricated.less
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
.phb{
|
||||||
|
//Double hr for full width elements
|
||||||
|
hr+hr+blockquote{
|
||||||
|
column-span : all;
|
||||||
|
-webkit-column-span : all;
|
||||||
|
-moz-column-span : all;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************************
|
||||||
|
// * CLASS TABLE
|
||||||
|
// *****************************/
|
||||||
|
hr+table{
|
||||||
|
margin-top : -5px;
|
||||||
|
margin-bottom : 50px;
|
||||||
|
padding-top : 10px;
|
||||||
|
border-collapse : separate;
|
||||||
|
background-color : white;
|
||||||
|
border : initial;
|
||||||
|
border-style : solid;
|
||||||
|
border-image-outset : 37px 17px;
|
||||||
|
border-image-repeat : round;
|
||||||
|
border-image-slice : 150 200 150 200;
|
||||||
|
border-image-source : @frameBorderImage;
|
||||||
|
border-image-width : 47px;
|
||||||
|
}
|
||||||
|
h5+hr+table{
|
||||||
|
column-span : all;
|
||||||
|
-webkit-column-span : all;
|
||||||
|
-moz-column-span : all;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,8 @@
|
|||||||
@media print {
|
|
||||||
.phb.v1{
|
|
||||||
.descriptive, blockquote{
|
|
||||||
box-shadow : none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.phb.v1{
|
|
||||||
@import (less) './phb.fonts.v1.css';
|
|
||||||
@import (less) './phb.assets.v1.less';
|
|
||||||
|
|
||||||
|
|
||||||
|
@import (less) 'shared/naturalcrit/styles/reset.less';
|
||||||
|
@import (less) './client/homebrew/phbStyle/phb.fonts.css';
|
||||||
|
@import (less) './client/homebrew/phbStyle/phb.assets.less';
|
||||||
|
@import (less) './client/homebrew/phbStyle/phb.depricated.less';
|
||||||
//Colors
|
//Colors
|
||||||
@background : #EEE5CE;
|
@background : #EEE5CE;
|
||||||
@noteGreen : #e0e5c1;
|
@noteGreen : #e0e5c1;
|
||||||
@@ -18,10 +10,13 @@
|
|||||||
@horizontalRule : #9c2b1b;
|
@horizontalRule : #9c2b1b;
|
||||||
@headerText : #58180D;
|
@headerText : #58180D;
|
||||||
@monsterStatBackground : #FDF1DC;
|
@monsterStatBackground : #FDF1DC;
|
||||||
|
|
||||||
@page { margin: 0; }
|
@page { margin: 0; }
|
||||||
|
body {
|
||||||
|
counter-reset : phb-page-numbers;
|
||||||
|
}
|
||||||
|
*{
|
||||||
|
-webkit-print-color-adjust : exact;
|
||||||
|
}
|
||||||
.useSansSerif(){
|
.useSansSerif(){
|
||||||
font-family : ScalySans;
|
font-family : ScalySans;
|
||||||
em{
|
em{
|
||||||
@@ -46,9 +41,7 @@
|
|||||||
-webkit-column-gap : 1cm;
|
-webkit-column-gap : 1cm;
|
||||||
-moz-column-gap : 1cm;
|
-moz-column-gap : 1cm;
|
||||||
}
|
}
|
||||||
& *{
|
.phb{
|
||||||
-webkit-print-color-adjust : exact;
|
|
||||||
}
|
|
||||||
.useColumns();
|
.useColumns();
|
||||||
counter-increment : phb-page-numbers;
|
counter-increment : phb-page-numbers;
|
||||||
position : relative;
|
position : relative;
|
||||||
@@ -66,7 +59,6 @@
|
|||||||
text-rendering : optimizeLegibility;
|
text-rendering : optimizeLegibility;
|
||||||
page-break-before : always;
|
page-break-before : always;
|
||||||
page-break-after : always;
|
page-break-after : always;
|
||||||
|
|
||||||
//*****************************
|
//*****************************
|
||||||
// * BASE
|
// * BASE
|
||||||
// *****************************/
|
// *****************************/
|
||||||
@@ -365,11 +357,11 @@
|
|||||||
-webkit-column-break-inside : avoid;
|
-webkit-column-break-inside : avoid;
|
||||||
column-break-inside : avoid;
|
column-break-inside : avoid;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//*****************************
|
//*****************************
|
||||||
// * SPELL LIST
|
// * SPELL LIST
|
||||||
// *****************************/
|
// *****************************/
|
||||||
.spellList{
|
.phb .spellList{
|
||||||
.useSansSerif();
|
.useSansSerif();
|
||||||
column-count : 4;
|
column-count : 4;
|
||||||
column-span : all;
|
column-span : all;
|
||||||
@@ -394,16 +386,20 @@
|
|||||||
//*****************************
|
//*****************************
|
||||||
// * PRINT
|
// * PRINT
|
||||||
// *****************************/
|
// *****************************/
|
||||||
&.print{
|
.phb.print{
|
||||||
blockquote{
|
blockquote{
|
||||||
box-shadow : none;
|
box-shadow : none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@media print {
|
||||||
|
.phb .descriptive, .phb blockquote{
|
||||||
|
box-shadow : none;
|
||||||
|
}
|
||||||
|
}
|
||||||
//*****************************
|
//*****************************
|
||||||
// * WIDE
|
// * WIDE
|
||||||
// *****************************/
|
// *****************************/
|
||||||
.wide{
|
.phb .wide{
|
||||||
column-span : all;
|
column-span : all;
|
||||||
-webkit-column-span : all;
|
-webkit-column-span : all;
|
||||||
-moz-column-span : all;
|
-moz-column-span : all;
|
||||||
@@ -411,7 +407,7 @@
|
|||||||
//*****************************
|
//*****************************
|
||||||
// * CLASS TABLE
|
// * CLASS TABLE
|
||||||
// *****************************/
|
// *****************************/
|
||||||
.classTable{
|
.phb .classTable{
|
||||||
margin-top : 25px;
|
margin-top : 25px;
|
||||||
margin-bottom : 40px;
|
margin-bottom : 40px;
|
||||||
border-collapse : separate;
|
border-collapse : separate;
|
||||||
@@ -430,7 +426,7 @@
|
|||||||
//*****************************
|
//*****************************
|
||||||
// * CLASS TABLE
|
// * CLASS TABLE
|
||||||
// *****************************/
|
// *****************************/
|
||||||
.descriptive{
|
.phb .descriptive{
|
||||||
display : block-inline;
|
display : block-inline;
|
||||||
margin-bottom : 1em;
|
margin-bottom : 1em;
|
||||||
background-color : #faf7ea;
|
background-color : #faf7ea;
|
||||||
@@ -458,13 +454,13 @@
|
|||||||
letter-spacing : -0.02em;
|
letter-spacing : -0.02em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pre+.descriptive{
|
.phb pre+.descriptive{
|
||||||
margin-top : 8px;
|
margin-top : 8px;
|
||||||
}
|
}
|
||||||
//*****************************
|
//*****************************
|
||||||
// * TABLE OF CONTENTS
|
// * TABLE OF CONTENTS
|
||||||
// *****************************/
|
// *****************************/
|
||||||
.toc{
|
.phb .toc{
|
||||||
-webkit-column-break-inside : avoid;
|
-webkit-column-break-inside : avoid;
|
||||||
column-break-inside : avoid;
|
column-break-inside : avoid;
|
||||||
a{
|
a{
|
||||||
@@ -482,40 +478,3 @@
|
|||||||
margin-bottom : 10px;
|
margin-bottom : 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//*****************************
|
|
||||||
// * Old Stuff
|
|
||||||
// *****************************/
|
|
||||||
|
|
||||||
//Double hr for full width elements
|
|
||||||
hr+hr+blockquote{
|
|
||||||
column-span : all;
|
|
||||||
-webkit-column-span : all;
|
|
||||||
-moz-column-span : all;
|
|
||||||
}
|
|
||||||
|
|
||||||
//*****************************
|
|
||||||
// * CLASS TABLE
|
|
||||||
// *****************************/
|
|
||||||
hr+table{
|
|
||||||
margin-top : -5px;
|
|
||||||
margin-bottom : 50px;
|
|
||||||
padding-top : 10px;
|
|
||||||
border-collapse : separate;
|
|
||||||
background-color : white;
|
|
||||||
border : initial;
|
|
||||||
border-style : solid;
|
|
||||||
border-image-outset : 37px 17px;
|
|
||||||
border-image-repeat : round;
|
|
||||||
border-image-slice : 150 200 150 200;
|
|
||||||
border-image-source : @frameBorderImage;
|
|
||||||
border-image-width : 47px;
|
|
||||||
}
|
|
||||||
h5+hr+table{
|
|
||||||
column-span : all;
|
|
||||||
-webkit-column-span : all;
|
|
||||||
-moz-column-span : all;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BIN
client/homebrew/phbStyle/red.png
Normal file
|
After Width: | Height: | Size: 864 B |
@@ -6,7 +6,6 @@ module.exports = function(vitreum){
|
|||||||
<link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
|
<link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
|
||||||
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
|
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
|
||||||
<link rel="icon" href="/assets/homebrew/favicon.ico" type="image/x-icon" />
|
<link rel="icon" href="/assets/homebrew/favicon.ico" type="image/x-icon" />
|
||||||
|
|
||||||
<title>The Homebrewery - NaturalCrit</title>
|
<title>The Homebrewery - NaturalCrit</title>
|
||||||
${vitreum.head}
|
${vitreum.head}
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
{
|
{
|
||||||
"log_level" : "info",
|
"host" : "homebrewery.local.naturalcrit.com:8000",
|
||||||
"login_path" : "/dev/login",
|
"naturalcrit_url" : "local.naturalcrit.com:8010",
|
||||||
"jwt_secret" : "secretsecret",
|
"secret" : "secret"
|
||||||
"admin" : {
|
|
||||||
"user" : "admin",
|
|
||||||
"pass" : "password",
|
|
||||||
"key" : "adminadminadmin"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"login_path" : "http://naturalcrit.com/login",
|
|
||||||
"log_level" : "warn"
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"login_path" : "http://staging.naturalcrit.com/login",
|
|
||||||
"log_level" : "trace"
|
|
||||||
}
|
|
||||||
34
package.json
@@ -1,55 +1,39 @@
|
|||||||
{
|
{
|
||||||
"name": "homebrewery",
|
"name": "homebrewery",
|
||||||
"description": "Create authentic looking D&D homebrews using only markdown",
|
"description": "Create authentic looking D&D homebrews using only markdown",
|
||||||
"version": "3.0.0",
|
"version": "2.7.4",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"logs": "heroku logs -t --app=homebrewery",
|
|
||||||
"dev": "node scripts/dev.js",
|
"dev": "node scripts/dev.js",
|
||||||
"quick": "node scripts/quick.js",
|
"quick": "node scripts/quick.js",
|
||||||
"build": "node scripts/build.js",
|
"build": "node scripts/build.js",
|
||||||
"populate": "node scripts/populate.js",
|
"phb": "node scripts/phb.js",
|
||||||
"prod": "set NODE_ENV=production&& npm run build",
|
"prod": "set NODE_ENV=production&& npm run build",
|
||||||
"postinstall": "npm run build",
|
"postinstall": "npm run build",
|
||||||
"start": "node server.js",
|
"start": "node server.js"
|
||||||
"snippet": "nodemon scripts/snippet.test.js",
|
|
||||||
"todo": "./node_modules/.bin/fixme -i node_modules/** -i build/**",
|
|
||||||
"test": "mocha tests",
|
|
||||||
"test:dev": "nodemon -x mocha tests || exit 0",
|
|
||||||
"test:markdown": "nodemon -x mocha tests/markdown.test.js || exit 0"
|
|
||||||
},
|
},
|
||||||
"author": "stolksdorf",
|
"author": "stolksdorf",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"babel-preset-env": "^1.1.8",
|
||||||
"basic-auth": "^1.0.3",
|
"basic-auth": "^1.0.3",
|
||||||
"body-parser": "^1.14.2",
|
"body-parser": "^1.14.2",
|
||||||
"classnames": "^2.2.0",
|
"classnames": "^2.2.0",
|
||||||
"codemirror": "^5.22.0",
|
"codemirror": "^5.22.0",
|
||||||
"cookie-parser": "^1.4.3",
|
"cookie-parser": "^1.4.3",
|
||||||
"egads": "^1.0.1",
|
|
||||||
"express": "^4.13.3",
|
"express": "^4.13.3",
|
||||||
"jwt-simple": "^0.5.1",
|
"jwt-simple": "^0.5.1",
|
||||||
"lodash": "^4.17.3",
|
"lodash": "^4.11.2",
|
||||||
"loglevel": "^1.4.1",
|
"marked": "^0.3.5",
|
||||||
"moment": "^2.11.0",
|
"moment": "^2.11.0",
|
||||||
"mongoose": "^4.3.3",
|
"mongoose": "^4.3.3",
|
||||||
"nconf": "^0.8.4",
|
"nconf": "^0.8.4",
|
||||||
"pico-flux": "^2.1.2",
|
"pico-flux": "^1.1.0",
|
||||||
"pico-router": "^1.1.0",
|
"pico-router": "^1.1.0",
|
||||||
"react": "^15.4.1",
|
"react": "^15.0.2",
|
||||||
"react-dom": "^15.4.1",
|
"react-dom": "^15.0.2",
|
||||||
"shortid": "^2.2.4",
|
"shortid": "^2.2.4",
|
||||||
"striptags": "^2.1.1",
|
"striptags": "^2.1.1",
|
||||||
"superagent": "^1.6.1",
|
"superagent": "^1.6.1",
|
||||||
"vitreum": "^4.0.12"
|
"vitreum": "^4.0.12"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"app-module-path": "^2.1.0",
|
|
||||||
"chai": "^3.5.0",
|
|
||||||
"chai-as-promised": "^6.0.0",
|
|
||||||
"chai-subset": "^1.4.0",
|
|
||||||
"fixme": "^0.4.3",
|
|
||||||
"mocha": "^3.2.0",
|
|
||||||
"supertest": "^2.0.1",
|
|
||||||
"supertest-as-promised": "^4.0.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
phb.standalone.css
Normal file
@@ -2,20 +2,19 @@ const label = 'build';
|
|||||||
console.time(label);
|
console.time(label);
|
||||||
|
|
||||||
const clean = require('vitreum/steps/clean.js');
|
const clean = require('vitreum/steps/clean.js');
|
||||||
const jsx = require('vitreum/steps/jsx.js');
|
const jsx = require('vitreum/steps/jsx.js').partial;
|
||||||
const lib = require('vitreum/steps/libs.js');
|
const lib = require('vitreum/steps/libs.js').partial;
|
||||||
const less = require('vitreum/steps/less.js');
|
const less = require('vitreum/steps/less.js').partial;
|
||||||
const asset = require('vitreum/steps/assets.js');
|
const asset = require('vitreum/steps/assets.js').partial;
|
||||||
|
|
||||||
const Proj = require('./project.json');
|
const Proj = require('./project.json');
|
||||||
|
|
||||||
Promise.resolve()
|
clean()
|
||||||
.then(()=>clean())
|
.then(lib(Proj.libs))
|
||||||
.then(()=>lib(Proj.libs))
|
.then(jsx('homebrew', './client/homebrew/homebrew.jsx', Proj.libs, ['./shared']))
|
||||||
.then(()=>jsx('homebrew', './client/homebrew/homebrew.jsx', Proj.libs, ['./shared']))
|
.then(less('homebrew', ['./shared']))
|
||||||
.then((deps)=>less('homebrew', ['./shared'], deps))
|
.then(jsx('admin', './client/admin/admin.jsx', Proj.libs, ['./shared']))
|
||||||
.then(()=>jsx('admin', './client/admin/admin.jsx', Proj.libs, ['./shared']))
|
.then(less('admin', ['./shared']))
|
||||||
.then((deps)=>less('admin', ['./shared'], deps))
|
.then(asset(Proj.assets, ['./shared', './client']))
|
||||||
.then(()=>asset(Proj.assets, ['./shared', './client']))
|
.then(console.timeEnd.bind(console, label))
|
||||||
.then(()=>console.timeEnd.bind(console, label))
|
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
@@ -1,21 +1,23 @@
|
|||||||
const label = 'dev';
|
const label = 'dev';
|
||||||
console.time(label);
|
console.time(label);
|
||||||
|
|
||||||
const jsx = require('vitreum/steps/jsx.watch.js');
|
const jsx = require('vitreum/steps/jsx.watch.js').partial;
|
||||||
const less = require('vitreum/steps/less.watch.js');
|
const less = require('vitreum/steps/less.watch.js').partial;
|
||||||
const assets = require('vitreum/steps/assets.watch.js');
|
const assets = require('vitreum/steps/assets.watch.js').partial;
|
||||||
const server = require('vitreum/steps/server.watch.js');
|
const server = require('vitreum/steps/server.watch.js').partial;
|
||||||
const livereload = require('vitreum/steps/livereload.js');
|
const livereload = require('vitreum/steps/livereload.js').partial;
|
||||||
|
|
||||||
const Proj = require('./project.json');
|
const Proj = require('./project.json');
|
||||||
|
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(()=>jsx('homebrew', './client/homebrew/homebrew.jsx', Proj.libs, './shared'))
|
.then(jsx('homebrew', './client/homebrew/homebrew.jsx', Proj.libs, './shared'))
|
||||||
.then((deps)=>less('homebrew', './shared', deps))
|
.then(less('homebrew', './shared'))
|
||||||
.then(()=>jsx('admin', './client/admin/admin.jsx', Proj.libs, './shared'))
|
|
||||||
.then((deps)=>less('admin', './shared', deps))
|
.then(jsx('admin', './client/admin/admin.jsx', Proj.libs, './shared'))
|
||||||
.then(()=>assets(Proj.assets, ['./shared', './client']))
|
.then(less('admin', './shared'))
|
||||||
.then(()=>livereload())
|
|
||||||
.then(()=>server('./server.js', ['server']))
|
.then(assets(Proj.assets, ['./shared', './client']))
|
||||||
.then(()=>console.timeEnd.bind(console, label))
|
.then(livereload())
|
||||||
|
.then(server('./server.js', ['server']))
|
||||||
|
.then(console.timeEnd.bind(console, label))
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
require('fixme')({
|
|
||||||
path: process.cwd(),
|
|
||||||
ignored_directories: ['node_modules/**', '.git/**', 'build/**'],
|
|
||||||
file_patterns: ['**/*.js', '**/*.jsx', '**/*.less'],
|
|
||||||
file_encoding: 'utf8',
|
|
||||||
line_length_limit: 200
|
|
||||||
});
|
|
||||||
10
scripts/phb.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
const less = require('less');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
less.render(fs.readFileSync('./client/homebrew/phbStyle/phb.style.less', 'utf8'), {compress : true})
|
||||||
|
.then((output) => {
|
||||||
|
fs.writeFileSync('./phb.standalone.css', output.css);
|
||||||
|
console.log('phb.standalone.css created!');
|
||||||
|
}, (err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
//Populates the DB with a bunch of brews for UI testing
|
|
||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
const DB = require('../server/db.js');
|
|
||||||
const BrewData = require('../server/brew.data.js');
|
|
||||||
//const BrewGen = require('../tests/brew.gen.js');
|
|
||||||
|
|
||||||
const BrewGen = require('../shared/homebrewery/snippets/brew/brew.snippet.js');
|
|
||||||
|
|
||||||
const BREW_COUNT = 50;
|
|
||||||
|
|
||||||
return Promise.resolve()
|
|
||||||
.then(DB.connect)
|
|
||||||
.then(BrewData.removeAll)
|
|
||||||
.then(() => {
|
|
||||||
return _.reduce(_.times(BREW_COUNT, BrewGen.brewModel), (flow, model)=>{
|
|
||||||
return flow.then(()=>BrewData.create(model))
|
|
||||||
}, Promise.resolve());
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
console.log(`Added ${BREW_COUNT} brews`);
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return DB.close();
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"assets": ["*.png","*.otf", "*.ico", "*.jpg"],
|
"assets": ["*.png","*.otf", "*.ico"],
|
||||||
"shared":["./shared"],
|
"shared":[
|
||||||
|
],
|
||||||
"libs" : [
|
"libs" : [
|
||||||
"react",
|
"react",
|
||||||
"react-dom",
|
"react-dom",
|
||||||
@@ -9,7 +10,6 @@
|
|||||||
"codemirror",
|
"codemirror",
|
||||||
"codemirror/mode/gfm/gfm.js",
|
"codemirror/mode/gfm/gfm.js",
|
||||||
"codemirror/mode/javascript/javascript.js",
|
"codemirror/mode/javascript/javascript.js",
|
||||||
"codemirror/mode/css/css.js",
|
|
||||||
"moment",
|
"moment",
|
||||||
"superagent",
|
"superagent",
|
||||||
"marked",
|
"marked",
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
const snippets = require('../shared/homebrewery/snippets');
|
|
||||||
|
|
||||||
console.log(snippets);
|
|
||||||
|
|
||||||
//console.log(snippets.brew.spell());
|
|
||||||
//console.log(snippets.brew.table());
|
|
||||||
|
|
||||||
console.log(snippets.brew.noncasterTable());
|
|
||||||
150
server.js
@@ -1,36 +1,140 @@
|
|||||||
|
const _ = require('lodash');
|
||||||
|
const jwt = require('jwt-simple');
|
||||||
|
const express = require("express");
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.use(express.static(__dirname + '/build'));''
|
||||||
|
app.use(require('body-parser').json({limit: '25mb'}));
|
||||||
|
app.use(require('cookie-parser')());
|
||||||
|
|
||||||
const config = require('nconf')
|
const config = require('nconf')
|
||||||
.argv()
|
.argv()
|
||||||
.env({ lowerCase: true })
|
.env({ lowerCase: true })
|
||||||
.file('environment', { file: `config/${process.env.NODE_ENV}.json` })
|
.file('environment', { file: `config/${process.env.NODE_ENV}.json` })
|
||||||
.file('defaults', { file: 'config/default.json' });
|
.file('defaults', { file: 'config/default.json' });
|
||||||
|
|
||||||
const log = require('loglevel');
|
//DB
|
||||||
log.setLevel(config.get('log_level'));
|
require('mongoose')
|
||||||
|
.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/naturalcrit')
|
||||||
|
.connection.on('error', () => {
|
||||||
|
console.log('Error : Could not connect to a Mongo Database.');
|
||||||
|
console.log(' If you are running locally, make sure mongodb.exe is running.');
|
||||||
|
});
|
||||||
|
|
||||||
//Server
|
|
||||||
const app = require('./server/app.js');
|
|
||||||
|
|
||||||
/*
|
//Account MIddleware
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
log.debug('---------------------------');
|
if(req.cookies && req.cookies.nc_session){
|
||||||
log.debug(req.method, req.path);
|
try{
|
||||||
|
req.account = jwt.decode(req.cookies.nc_session, config.get('secret'));
|
||||||
if (req.params) {
|
}catch(e){}
|
||||||
log.debug('req params', req.params);
|
|
||||||
}
|
}
|
||||||
if (req.query) {
|
return next();
|
||||||
log.debug('req query', req.query);
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
require('./server/db.js').connect()
|
|
||||||
.then(()=>{
|
app.use(require('./server/homebrew.api.js'));
|
||||||
const PORT = process.env.PORT || 8000;
|
app.use(require('./server/admin.api.js'));
|
||||||
const httpServer = app.listen(PORT, () => {
|
|
||||||
log.info(`server on port:${PORT}`);
|
|
||||||
});
|
const HomebrewModel = require('./server/homebrew.model.js').model;
|
||||||
|
const welcomeText = require('fs').readFileSync('./client/homebrew/pages/homePage/welcome_msg.md', 'utf8');
|
||||||
|
const changelogText = require('fs').readFileSync('./changelog.md', 'utf8');
|
||||||
|
|
||||||
|
|
||||||
|
//Source page
|
||||||
|
String.prototype.replaceAll = function(s,r){return this.split(s).join(r)}
|
||||||
|
app.get('/source/:id', (req, res)=>{
|
||||||
|
HomebrewModel.get({shareId : req.params.id})
|
||||||
|
.then((brew)=>{
|
||||||
|
const text = brew.text.replaceAll('<', '<').replaceAll('>', '>');
|
||||||
|
return res.send(`<code><pre>${text}</pre></code>`);
|
||||||
})
|
})
|
||||||
.catch((err)=>console.error(err))
|
.catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return res.status(404).send('Could not find Homebrew with that id');
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
app.get('/user/:username', (req, res, next) => {
|
||||||
|
const fullAccess = req.account && (req.account.username == req.params.username);
|
||||||
|
HomebrewModel.getByUser(req.params.username, fullAccess)
|
||||||
|
.then((brews) => {
|
||||||
|
req.brews = brews;
|
||||||
|
return next();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
app.get('/edit/:id', (req, res, next)=>{
|
||||||
|
HomebrewModel.get({editId : req.params.id})
|
||||||
|
.then((brew)=>{
|
||||||
|
req.brew = brew.sanatize();
|
||||||
|
return next();
|
||||||
|
})
|
||||||
|
.catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return res.status(400).send(`Can't get that`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//Share Page
|
||||||
|
app.get('/share/:id', (req, res, next)=>{
|
||||||
|
HomebrewModel.get({shareId : req.params.id})
|
||||||
|
.then((brew)=>{
|
||||||
|
return brew.increaseView();
|
||||||
|
})
|
||||||
|
.then((brew)=>{
|
||||||
|
req.brew = brew.sanatize(true);
|
||||||
|
return next();
|
||||||
|
})
|
||||||
|
.catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return res.status(400).send(`Can't get that`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//Print Page
|
||||||
|
app.get('/print/:id', (req, res, next)=>{
|
||||||
|
HomebrewModel.get({shareId : req.params.id})
|
||||||
|
.then((brew)=>{
|
||||||
|
req.brew = brew.sanatize(true);
|
||||||
|
return next();
|
||||||
|
})
|
||||||
|
.catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return res.status(400).send(`Can't get that`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//Render Page
|
||||||
|
const render = require('vitreum/steps/render');
|
||||||
|
const templateFn = require('./client/template.js');
|
||||||
|
app.use((req, res) => {
|
||||||
|
render('homebrew', templateFn, {
|
||||||
|
version : require('./package.json').version,
|
||||||
|
url: req.originalUrl,
|
||||||
|
welcomeText : welcomeText,
|
||||||
|
changelog : changelogText,
|
||||||
|
brew : req.brew,
|
||||||
|
brews : req.brews,
|
||||||
|
account : req.account
|
||||||
|
})
|
||||||
|
.then((page) => {
|
||||||
|
return res.send(page)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
return res.sendStatus(500);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const PORT = process.env.PORT || 8000;
|
||||||
|
app.listen(PORT);
|
||||||
|
console.log(`server on port:${PORT}`);
|
||||||
85
server/admin.api.js
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
const _ = require('lodash');
|
||||||
|
const auth = require('basic-auth');
|
||||||
|
const HomebrewModel = require('./homebrew.model.js').model;
|
||||||
|
const router = require('express').Router();
|
||||||
|
|
||||||
|
|
||||||
|
const mw = {
|
||||||
|
adminOnly : (req, res, next)=>{
|
||||||
|
if(req.query && req.query.admin_key == process.env.ADMIN_KEY) return next();
|
||||||
|
return res.status(401).send('Access denied');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
process.env.ADMIN_USER = process.env.ADMIN_USER || 'admin';
|
||||||
|
process.env.ADMIN_PASS = process.env.ADMIN_PASS || 'password';
|
||||||
|
process.env.ADMIN_KEY = process.env.ADMIN_KEY || 'admin_key';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Removes all empty brews that are older than 3 days and that are shorter than a tweet
|
||||||
|
router.get('/api/invalid', mw.adminOnly, (req, res)=>{
|
||||||
|
const invalidBrewQuery = HomebrewModel.find({
|
||||||
|
'$where' : "this.text.length < 140",
|
||||||
|
createdAt: {
|
||||||
|
$lt: Moment().subtract(3, 'days').toDate()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(req.query.do_it){
|
||||||
|
invalidBrewQuery.remove().exec((err, objs)=>{
|
||||||
|
refreshCount();
|
||||||
|
return res.send(200);
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
invalidBrewQuery.exec((err, objs)=>{
|
||||||
|
if(err) console.log(err);
|
||||||
|
return res.json({
|
||||||
|
count : objs.length
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/admin/lookup/:id', mw.adminOnly, (req, res, next) => {
|
||||||
|
//search for mathcing edit id
|
||||||
|
//search for matching share id
|
||||||
|
// search for partial match
|
||||||
|
|
||||||
|
HomebrewModel.findOne({ $or:[
|
||||||
|
{editId : { "$regex": req.params.id, "$options": "i" }},
|
||||||
|
{shareId : { "$regex": req.params.id, "$options": "i" }},
|
||||||
|
]}).exec((err, brew) => {
|
||||||
|
return res.json(brew);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Admin route
|
||||||
|
|
||||||
|
const render = require('vitreum/steps/render');
|
||||||
|
const templateFn = require('../client/template.js');
|
||||||
|
router.get('/admin', function(req, res){
|
||||||
|
const credentials = auth(req)
|
||||||
|
if (!credentials || credentials.name !== process.env.ADMIN_USER || credentials.pass !== process.env.ADMIN_PASS) {
|
||||||
|
res.setHeader('WWW-Authenticate', 'Basic realm="example"')
|
||||||
|
return res.status(401).send('Access denied')
|
||||||
|
}
|
||||||
|
render('admin', templateFn, {
|
||||||
|
url: req.originalUrl,
|
||||||
|
admin_key : process.env.ADMIN_KEY,
|
||||||
|
})
|
||||||
|
.then((page) => {
|
||||||
|
return res.send(page)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
return res.sendStatus(500);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
const _ = require('lodash');
|
|
||||||
const router = require('express').Router();
|
|
||||||
const vitreumRender = require('vitreum/steps/render');
|
|
||||||
const templateFn = require('../client/template.js');
|
|
||||||
const config = require('nconf');
|
|
||||||
const Moment = require('moment');
|
|
||||||
|
|
||||||
const mw = require('./middleware.js');
|
|
||||||
const BrewData = require('./brew.data.js');
|
|
||||||
|
|
||||||
|
|
||||||
const getInvalidBrewQuery = ()=>{
|
|
||||||
return BrewData.model.find({
|
|
||||||
'$where' : "this.text.length < 140",
|
|
||||||
createdAt: {
|
|
||||||
$lt: Moment().subtract(3, 'days').toDate()
|
|
||||||
}
|
|
||||||
}).select({ text : false });
|
|
||||||
}
|
|
||||||
|
|
||||||
router.get('/admin', mw.adminLogin, (req, res, next) => {
|
|
||||||
return vitreumRender('admin', templateFn, {
|
|
||||||
url : req.originalUrl,
|
|
||||||
admin_key : config.get('admin:key')
|
|
||||||
})
|
|
||||||
.then((page) => {
|
|
||||||
return res.send(page)
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
});
|
|
||||||
|
|
||||||
//Removes all empty brews that are older than 3 days and that are shorter than a tweet
|
|
||||||
router.get('/admin/invalid', mw.adminOnly, (req, res, next)=>{
|
|
||||||
getInvalidBrewQuery().exec()
|
|
||||||
.then((brews) => {
|
|
||||||
return res.json(brews);
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
});
|
|
||||||
router.delete('/admin/invalid', mw.adminOnly, (req, res, next)=>{
|
|
||||||
getInvalidBrewQuery().remove()
|
|
||||||
.then(()=>{
|
|
||||||
return res.status(200).send();
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
});
|
|
||||||
|
|
||||||
router.get('/admin/lookup/:search', mw.adminOnly, (req, res, next) => {
|
|
||||||
BrewData.get({ $or:[
|
|
||||||
//Searches for partial matches on either edit or share
|
|
||||||
{editId : { "$regex": req.params.search, "$options": "i" }},
|
|
||||||
{shareId : { "$regex": req.params.search, "$options": "i" }},
|
|
||||||
]})
|
|
||||||
.then((brews) => {
|
|
||||||
return res.json(brews);
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
const config = require('nconf');
|
|
||||||
const express = require("express");
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
app.use(express.static(__dirname + '/../build'));
|
|
||||||
app.use(require('body-parser').json({limit: '25mb'}));
|
|
||||||
app.use(require('cookie-parser')());
|
|
||||||
|
|
||||||
|
|
||||||
//Middleware
|
|
||||||
const mw = require('./middleware.js');
|
|
||||||
app.use(mw.account);
|
|
||||||
app.use(mw.admin);
|
|
||||||
|
|
||||||
|
|
||||||
//Routes
|
|
||||||
app.use(require('./brew.api.js'));
|
|
||||||
app.use(require('./interface.routes.js'));
|
|
||||||
app.use(require('./admin.routes.js'));
|
|
||||||
|
|
||||||
if(config.get('NODE_ENV') !== 'staging' && config.get('NODE_ENV') !== 'production'){
|
|
||||||
app.use(require('./dev.routes.js'));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Error Handler
|
|
||||||
app.use(require('./error.js').expressHandler);
|
|
||||||
|
|
||||||
module.exports = app;
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
const _ = require('lodash');
|
|
||||||
const router = require('express').Router();
|
|
||||||
|
|
||||||
const BrewData = require('./brew.data.js');
|
|
||||||
const mw = require('./middleware.js');
|
|
||||||
|
|
||||||
//Search
|
|
||||||
router.get('/api/brew', (req, res, next) => {
|
|
||||||
const opts = _.pick(req.query, ['limit', 'sort', 'page']);
|
|
||||||
|
|
||||||
BrewData.termSearch(req.query.terms, opts, req.admin)
|
|
||||||
.then((result) => {
|
|
||||||
return res.status(200).json(result);
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
});
|
|
||||||
|
|
||||||
//User
|
|
||||||
router.get('/api/user/:username', (req, res, next) => {
|
|
||||||
const fullAccess = req.admin ||
|
|
||||||
!!(req.account && req.params.username == req.account.username);
|
|
||||||
|
|
||||||
BrewData.userSearch(req.params.username, fullAccess)
|
|
||||||
.then((result) => {
|
|
||||||
return res.status(200).json(result);
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
});
|
|
||||||
|
|
||||||
//Get
|
|
||||||
router.get('/api/brew/:shareId', mw.viewBrew, (req, res, next) => {
|
|
||||||
return res.json(req.brew.toJSON());
|
|
||||||
});
|
|
||||||
|
|
||||||
//Create
|
|
||||||
router.post('/api/brew', (req, res, next)=>{
|
|
||||||
const brew = req.body;
|
|
||||||
if(req.account) brew.authors = [req.account.username];
|
|
||||||
BrewData.create(brew)
|
|
||||||
.then((brew) => {
|
|
||||||
return res.json(brew.toJSON());
|
|
||||||
})
|
|
||||||
.catch(next)
|
|
||||||
});
|
|
||||||
|
|
||||||
//Update
|
|
||||||
router.put('/api/brew/:editId', mw.loadBrew, (req, res, next)=>{
|
|
||||||
const brew = req.body || {};
|
|
||||||
if(req.account){
|
|
||||||
brew.authors = _.uniq(_.concat(brew.authors, req.account.username));
|
|
||||||
}
|
|
||||||
BrewData.update(req.params.editId, brew)
|
|
||||||
.then((brew) => {
|
|
||||||
return res.json(brew.toJSON());
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
});
|
|
||||||
|
|
||||||
//Delete
|
|
||||||
router.delete('/api/brew/:editId', mw.loadBrew, (req, res, next) => {
|
|
||||||
BrewData.remove(req.params.editId)
|
|
||||||
.then(()=>{
|
|
||||||
return res.sendStatus(200);
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
const _ = require('lodash');
|
|
||||||
const shortid = require('shortid');
|
|
||||||
const mongoose = require('./db.js').instance;
|
|
||||||
|
|
||||||
const Error = require('./error.js');
|
|
||||||
const utils = require('./utils.js');
|
|
||||||
|
|
||||||
const BrewSchema = mongoose.Schema({
|
|
||||||
shareId : {type : String, default: shortid.generate, index: { unique: true }},
|
|
||||||
editId : {type : String, default: shortid.generate, index: { unique: true }},
|
|
||||||
|
|
||||||
text : {type : String, default : ""},
|
|
||||||
style : {type : String, default : ""},
|
|
||||||
|
|
||||||
title : {type : String, default : ""},
|
|
||||||
description : {type : String, default : ""},
|
|
||||||
tags : {type : String, default : ""},
|
|
||||||
thumbnail : {type : String, default : ""},
|
|
||||||
systems : [String],
|
|
||||||
authors : [String],
|
|
||||||
published : {type : Boolean, default : false},
|
|
||||||
|
|
||||||
createdAt : { type: Date, default: Date.now },
|
|
||||||
updatedAt : { type: Date, default: Date.now},
|
|
||||||
lastViewed : { type: Date, default: Date.now},
|
|
||||||
views : {type:Number, default:0},
|
|
||||||
version : {type: Number, default:2}
|
|
||||||
}, {
|
|
||||||
versionKey: false,
|
|
||||||
toJSON : {
|
|
||||||
transform: (doc, ret, options) => {
|
|
||||||
delete ret._id;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Index these fields for fast text searching
|
|
||||||
BrewSchema.index({ title: "text", description: "text" });
|
|
||||||
|
|
||||||
BrewSchema.methods.increaseView = function(){
|
|
||||||
this.views = this.views + 1;
|
|
||||||
return this.save();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const Brew = mongoose.model('Brew', BrewSchema);
|
|
||||||
const BrewData = {
|
|
||||||
schema : BrewSchema,
|
|
||||||
model : Brew,
|
|
||||||
|
|
||||||
get : (query) => {
|
|
||||||
return Brew.findOne(query).exec()
|
|
||||||
.then((brew) => {
|
|
||||||
if(!brew) throw Error.noBrew();
|
|
||||||
return brew;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
create : (brew) => {
|
|
||||||
delete brew.shareId;
|
|
||||||
delete brew.editId;
|
|
||||||
if(!brew.title) brew.title = utils.getGoodBrewTitle(brew.text);
|
|
||||||
return (new Brew(brew)).save();
|
|
||||||
},
|
|
||||||
update : (editId, newBrew) => {
|
|
||||||
return BrewData.get({ editId })
|
|
||||||
.then((brew) => {
|
|
||||||
delete newBrew.shareId;
|
|
||||||
delete newBrew.editId;
|
|
||||||
brew = _.merge(brew, newBrew, { updatedAt : Date.now() });
|
|
||||||
|
|
||||||
brew.markModified('authors');
|
|
||||||
brew.markModified('systems');
|
|
||||||
return brew.save();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
remove : (editId) => {
|
|
||||||
return Brew.find({ editId }).remove().exec();
|
|
||||||
},
|
|
||||||
removeAll : ()=>{
|
|
||||||
return Brew.find({}).remove().exec();
|
|
||||||
},
|
|
||||||
|
|
||||||
//////// Special
|
|
||||||
|
|
||||||
getByShare : (shareId) => {
|
|
||||||
return BrewData.get({ shareId : shareId})
|
|
||||||
.then((brew) => {
|
|
||||||
brew.increaseView();
|
|
||||||
const brewJSON = brew.toJSON();
|
|
||||||
delete brewJSON.editId;
|
|
||||||
return brewJSON;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getByEdit : (editId) => {
|
|
||||||
return BrewData.get({ editId });
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const BrewSearch = require('./brew.search.js')(Brew);
|
|
||||||
|
|
||||||
module.exports = _.merge(BrewData, BrewSearch);
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
module.exports = (BrewModel) => {
|
|
||||||
const cmds = {
|
|
||||||
termSearch : (terms='', opts, fullAccess) => {
|
|
||||||
let query = {};
|
|
||||||
if(terms){
|
|
||||||
query = {$text: {
|
|
||||||
//Wrap terms in quotes to perform an AND operation
|
|
||||||
$search: _.map(terms.split(' '), (term)=>{
|
|
||||||
return `\"${term}\"`;
|
|
||||||
}).join(' '),
|
|
||||||
$caseSensitive : false
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
return cmds.search(query, opts, fullAccess);
|
|
||||||
},
|
|
||||||
|
|
||||||
userSearch : (username, fullAccess) => {
|
|
||||||
const query = {
|
|
||||||
authors : username
|
|
||||||
};
|
|
||||||
|
|
||||||
return cmds.search(query, {}, fullAccess);
|
|
||||||
},
|
|
||||||
|
|
||||||
search : (queryObj={}, options={}, fullAccess = true) => {
|
|
||||||
const opts = _.merge({
|
|
||||||
limit : 25,
|
|
||||||
page : 0,
|
|
||||||
sort : {}
|
|
||||||
}, options);
|
|
||||||
opts.limit = _.toNumber(opts.limit);
|
|
||||||
opts.page = _.toNumber(opts.page);
|
|
||||||
|
|
||||||
let filter = {
|
|
||||||
text : 0,
|
|
||||||
style : 0
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!fullAccess){
|
|
||||||
filter.editId = 0;
|
|
||||||
queryObj.published = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const searchQuery = BrewModel
|
|
||||||
.find(queryObj)
|
|
||||||
.sort(opts.sort)
|
|
||||||
.select(filter)
|
|
||||||
.limit(opts.limit)
|
|
||||||
.skip(opts.page * opts.limit)
|
|
||||||
.lean()
|
|
||||||
.exec();
|
|
||||||
|
|
||||||
const countQuery = BrewModel.count(queryObj).exec();
|
|
||||||
|
|
||||||
return Promise.all([searchQuery, countQuery])
|
|
||||||
.then((result) => {
|
|
||||||
return {
|
|
||||||
brews : result[0],
|
|
||||||
total : result[1]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return cmds;
|
|
||||||
};
|
|
||||||
36
server/db.js
@@ -1,36 +0,0 @@
|
|||||||
const log = require('loglevel');
|
|
||||||
const mongoose = require('mongoose');
|
|
||||||
mongoose.Promise = Promise;
|
|
||||||
|
|
||||||
const dbPath = process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/homebrewery';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
connect : ()=>{
|
|
||||||
return new Promise((resolve, reject)=>{
|
|
||||||
if(mongoose.connection.readyState !== 0){
|
|
||||||
log.warn('DB already connected');
|
|
||||||
return resolve();
|
|
||||||
}
|
|
||||||
mongoose.connect(dbPath,
|
|
||||||
(err) => {
|
|
||||||
if(err){
|
|
||||||
log.error('Error : Could not connect to a Mongo Database.');
|
|
||||||
log.error(' If you are running locally, make sure mongodb.exe is running.');
|
|
||||||
return reject(err);
|
|
||||||
}
|
|
||||||
log.info('DB connected.');
|
|
||||||
return resolve();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
close : ()=>{
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
mongoose.connection.close(()=>{
|
|
||||||
log.info('DB connection closed.');
|
|
||||||
return resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
instance : mongoose
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
const router = require('express').Router();
|
|
||||||
const jwt = require('jwt-simple');
|
|
||||||
const auth = require('basic-auth');
|
|
||||||
const config = require('nconf');
|
|
||||||
|
|
||||||
if(process.env.NODE_ENV == 'production') throw 'Loading dev routes in prod. ABORT ABORT';
|
|
||||||
|
|
||||||
|
|
||||||
router.get('/dev/login', (req, res, next) => {
|
|
||||||
const user = req.query.user;
|
|
||||||
if(!user){
|
|
||||||
return res.send(`
|
|
||||||
<html>
|
|
||||||
<body>dev login</body>
|
|
||||||
<script>
|
|
||||||
var user = prompt('enter username');
|
|
||||||
if(user) window.location = '/dev/login?user=' + encodeURIComponent(user);
|
|
||||||
</script></html>
|
|
||||||
`);
|
|
||||||
}
|
|
||||||
res.cookie('nc_session', jwt.encode({username : req.query.user}, config.get('jwt_secret')));
|
|
||||||
return res.redirect('/');
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
const Error = require('egads').extend('Server Error', 500, 'Generic Server Error');
|
|
||||||
|
|
||||||
Error.noBrew = Error.extend('Can not find a brew with that id', 404, 'No Brew Found');
|
|
||||||
Error.noAuth = Error.extend('You can not access this route', 401, 'Unauthorized');
|
|
||||||
Error.noAdmin = Error.extend('You need admin credentials to access this route', 401, 'Unauthorized');
|
|
||||||
|
|
||||||
|
|
||||||
Error.expressHandler = (err, req, res, next) => {
|
|
||||||
if(err instanceof Error){
|
|
||||||
return res.status(err.status).send({
|
|
||||||
type : err.name,
|
|
||||||
message : err.message
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//If server error, print the whole stack for debugging
|
|
||||||
return res.status(500).send({
|
|
||||||
message : err.message,
|
|
||||||
stack : err.stack
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = Error;
|
|
||||||
144
server/homebrew.api.js
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
const _ = require('lodash');
|
||||||
|
const Moment = require('moment');
|
||||||
|
const HomebrewModel = require('./homebrew.model.js').model;
|
||||||
|
const router = require('express').Router();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Possiblity remove
|
||||||
|
let homebrewTotal = 0;
|
||||||
|
const refreshCount = ()=>{
|
||||||
|
HomebrewModel.count({}, (err, total)=>{
|
||||||
|
homebrewTotal = total;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
refreshCount();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const getTopBrews = (cb)=>{
|
||||||
|
HomebrewModel.find().sort({views: -1}).limit(5).exec(function(err, brews) {
|
||||||
|
cb(brews);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const getGoodBrewTitle = (text) => {
|
||||||
|
const titlePos = text.indexOf('# ');
|
||||||
|
if(titlePos !== -1){
|
||||||
|
const ending = text.indexOf('\n', titlePos);
|
||||||
|
return text.substring(titlePos + 2, ending);
|
||||||
|
}else{
|
||||||
|
return _.find(text.split('\n'), (line)=>{
|
||||||
|
return line;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
router.post('/api', (req, res)=>{
|
||||||
|
|
||||||
|
let authors = [];
|
||||||
|
if(req.account) authors = [req.account.username];
|
||||||
|
|
||||||
|
const newHomebrew = new HomebrewModel(_.merge({},
|
||||||
|
req.body,
|
||||||
|
{authors : authors}
|
||||||
|
));
|
||||||
|
if(!newHomebrew.title){
|
||||||
|
newHomebrew.title = getGoodBrewTitle(newHomebrew.text);
|
||||||
|
}
|
||||||
|
newHomebrew.save((err, obj)=>{
|
||||||
|
if(err){
|
||||||
|
console.error(err, err.toString(), err.stack);
|
||||||
|
return res.status(500).send(`Error while creating new brew, ${err.toString()}`);
|
||||||
|
}
|
||||||
|
return res.json(obj);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
router.put('/api/update/:id', (req, res)=>{
|
||||||
|
HomebrewModel.get({editId : req.params.id})
|
||||||
|
.then((brew)=>{
|
||||||
|
brew = _.merge(brew, req.body);
|
||||||
|
brew.updatedAt = new Date();
|
||||||
|
if(req.account) brew.authors = _.uniq(_.concat(brew.authors, req.account.username));
|
||||||
|
|
||||||
|
brew.markModified('authors');
|
||||||
|
brew.markModified('systems');
|
||||||
|
|
||||||
|
brew.save((err, obj)=>{
|
||||||
|
if(err) throw err;
|
||||||
|
return res.status(200).send(obj);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return res.status(500).send("Error while saving");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/api/remove/:id', (req, res)=>{
|
||||||
|
HomebrewModel.find({editId : req.params.id}, (err, objs)=>{
|
||||||
|
if(!objs.length || err) return res.status(404).send("Can not find homebrew with that id");
|
||||||
|
var resEntry = objs[0];
|
||||||
|
resEntry.remove((err)=>{
|
||||||
|
if(err) return res.status(500).send("Error while removing");
|
||||||
|
return res.status(200).send();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function(app){
|
||||||
|
|
||||||
|
app;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
app.get('/api/search', mw.adminOnly, function(req, res){
|
||||||
|
|
||||||
|
var page = req.query.page || 0;
|
||||||
|
var count = req.query.count || 20;
|
||||||
|
|
||||||
|
var query = {};
|
||||||
|
if(req.query && req.query.id){
|
||||||
|
query = {
|
||||||
|
"$or" : [{
|
||||||
|
editId : req.query.id
|
||||||
|
},{
|
||||||
|
shareId : req.query.id
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
HomebrewModel.find(query, {
|
||||||
|
text : 0 //omit the text
|
||||||
|
}, {
|
||||||
|
skip: page*count,
|
||||||
|
limit: count*1
|
||||||
|
}, function(err, objs){
|
||||||
|
if(err) console.log(err);
|
||||||
|
return res.json({
|
||||||
|
page : page,
|
||||||
|
count : count,
|
||||||
|
total : homebrewTotal,
|
||||||
|
brews : objs
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
*/
|
||||||
81
server/homebrew.model.js
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
var mongoose = require('mongoose');
|
||||||
|
var shortid = require('shortid');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
|
var HomebrewSchema = mongoose.Schema({
|
||||||
|
shareId : {type : String, default: shortid.generate, index: { unique: true }},
|
||||||
|
editId : {type : String, default: shortid.generate, index: { unique: true }},
|
||||||
|
title : {type : String, default : ""},
|
||||||
|
text : {type : String, default : ""},
|
||||||
|
|
||||||
|
description : {type : String, default : ""},
|
||||||
|
tags : {type : String, default : ""},
|
||||||
|
systems : [String],
|
||||||
|
authors : [String],
|
||||||
|
published : {type : Boolean, default : false},
|
||||||
|
|
||||||
|
createdAt : { type: Date, default: Date.now },
|
||||||
|
updatedAt : { type: Date, default: Date.now},
|
||||||
|
lastViewed : { type: Date, default: Date.now},
|
||||||
|
views : {type:Number, default:0},
|
||||||
|
version : {type: Number, default:1}
|
||||||
|
}, { versionKey: false });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HomebrewSchema.methods.sanatize = function(full=false){
|
||||||
|
const brew = this.toJSON();
|
||||||
|
delete brew._id;
|
||||||
|
delete brew.__v;
|
||||||
|
if(full){
|
||||||
|
delete brew.editId;
|
||||||
|
}
|
||||||
|
return brew;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
HomebrewSchema.methods.increaseView = function(){
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.lastViewed = new Date();
|
||||||
|
this.views = this.views + 1;
|
||||||
|
this.save((err) => {
|
||||||
|
if(err) return reject(err);
|
||||||
|
return resolve(this);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HomebrewSchema.statics.get = function(query){
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
Homebrew.find(query, (err, brews)=>{
|
||||||
|
if(err || !brews.length) return reject('Can not find brew');
|
||||||
|
return resolve(brews[0]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
HomebrewSchema.statics.getByUser = function(username, allowAccess=false){
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let query = {authors : username, published : true};
|
||||||
|
if(allowAccess){
|
||||||
|
delete query.published;
|
||||||
|
}
|
||||||
|
Homebrew.find(query, (err, brews)=>{
|
||||||
|
if(err) return reject('Can not find brew');
|
||||||
|
return resolve(_.map(brews, (brew)=>{
|
||||||
|
return brew.sanatize(!allowAccess);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var Homebrew = mongoose.model('Homebrew', HomebrewSchema);
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
schema : HomebrewSchema,
|
||||||
|
model : Homebrew,
|
||||||
|
}
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
const _ = require('lodash');
|
|
||||||
const fs = require('fs');
|
|
||||||
const config = require('nconf');
|
|
||||||
const utils = require('./utils.js');
|
|
||||||
const BrewData = require('./brew.data.js');
|
|
||||||
const router = require('express').Router();
|
|
||||||
const mw = require('./middleware.js');
|
|
||||||
|
|
||||||
|
|
||||||
const statics = {
|
|
||||||
welcomeBrew : fs.readFileSync('./statics/welcome.brew.md', 'utf8'),
|
|
||||||
changelog : fs.readFileSync('./statics/changelog.md', 'utf8'),
|
|
||||||
faq : fs.readFileSync('./statics/faq.md', 'utf8'),
|
|
||||||
|
|
||||||
testBrew : fs.readFileSync('./statics/test.brew.md', 'utf8'),
|
|
||||||
oldTest : fs.readFileSync('./statics/oldTest.brew.md', 'utf8'),
|
|
||||||
};
|
|
||||||
|
|
||||||
let topBrews = [];
|
|
||||||
const getTopBrews = ()=>{
|
|
||||||
//Add in filter of last 2 weeks
|
|
||||||
return BrewData.search({}, {
|
|
||||||
limit : 4,
|
|
||||||
sort : {views : -1}
|
|
||||||
}, false).then(({brews, total})=>brews);
|
|
||||||
};
|
|
||||||
|
|
||||||
getTopBrews().then((brews)=>{
|
|
||||||
topBrews=brews;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const vitreumRender = require('vitreum/steps/render');
|
|
||||||
const templateFn = require('../client/template.js');
|
|
||||||
//TODO: Catch errors here?
|
|
||||||
const renderPage = (req, res, next) => {
|
|
||||||
return vitreumRender('homebrew', templateFn, {
|
|
||||||
url : req.originalUrl,
|
|
||||||
version : require('../package.json').version,
|
|
||||||
loginPath : config.get('login_path'),
|
|
||||||
|
|
||||||
user : req.account && req.account.username,
|
|
||||||
brews : req.brews,
|
|
||||||
brew : req.brew
|
|
||||||
})
|
|
||||||
.then((page)=>res.send(page))
|
|
||||||
.catch(next);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//Share Page
|
|
||||||
router.get('/share/:shareId', mw.viewBrew, renderPage);
|
|
||||||
|
|
||||||
//Edit Page
|
|
||||||
router.get('/edit/:editId', mw.loadBrew, renderPage);
|
|
||||||
|
|
||||||
//Print Page
|
|
||||||
router.get('/print/:shareId', mw.viewBrew, renderPage);
|
|
||||||
router.get('/print', renderPage);
|
|
||||||
|
|
||||||
//Source page
|
|
||||||
router.get('/source/:sharedId', mw.viewBrew, (req, res, next)=>{
|
|
||||||
const text = utils.replaceByMap(req.brew.text, { '<' : '<', '>' : '>' });
|
|
||||||
return res.send(`<code><pre>${text}</pre></code>`);
|
|
||||||
});
|
|
||||||
|
|
||||||
//User Page
|
|
||||||
router.get('/account', (req, res, next)=>{
|
|
||||||
if(req.account && req.account.username){
|
|
||||||
return res.redirect(`/user/${req.account.username}`);
|
|
||||||
}else{
|
|
||||||
return res.redirect(`${config.get('login_path')}?redirect=${encodeURIComponent(req.headers.referer)}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
router.get('/user/:username', (req, res, next) => {
|
|
||||||
const isSelf = req.account && req.params.username == req.account.username;
|
|
||||||
|
|
||||||
BrewData.userSearch(req.params.username, isSelf)
|
|
||||||
.then(({brews, total}) => {
|
|
||||||
req.brews = brews;
|
|
||||||
return next();
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
}, renderPage);
|
|
||||||
|
|
||||||
//Search Page
|
|
||||||
router.get('/search', (req, res, next) => {
|
|
||||||
//TODO: Double check that the defaults are okay
|
|
||||||
BrewData.search()
|
|
||||||
.then((brews) => {
|
|
||||||
req.brews = brews;
|
|
||||||
return next();
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
}, renderPage);
|
|
||||||
|
|
||||||
//Changelog Page
|
|
||||||
router.get('/changelog', (req, res, next) => {
|
|
||||||
req.brew = {
|
|
||||||
text : statics.changelog,
|
|
||||||
title : 'Changelog'
|
|
||||||
};
|
|
||||||
return next();
|
|
||||||
}, renderPage);
|
|
||||||
|
|
||||||
//faq Page
|
|
||||||
router.get('/faq', (req, res, next) => {
|
|
||||||
req.brew = {
|
|
||||||
text : statics.faq,
|
|
||||||
title : 'FAQ',
|
|
||||||
|
|
||||||
editId : true
|
|
||||||
};
|
|
||||||
return next();
|
|
||||||
}, renderPage);
|
|
||||||
|
|
||||||
//New Page
|
|
||||||
router.get('/new', renderPage);
|
|
||||||
|
|
||||||
//Home Page
|
|
||||||
router.get('/', (req, res, next) => {
|
|
||||||
req.brews = topBrews;
|
|
||||||
console.log(topBrews);
|
|
||||||
return next();
|
|
||||||
}, renderPage);
|
|
||||||
|
|
||||||
|
|
||||||
//Test pages
|
|
||||||
router.get('/test', (req, res, next) => {
|
|
||||||
req.brew = {
|
|
||||||
text : statics.testBrew
|
|
||||||
};
|
|
||||||
return next();
|
|
||||||
}, renderPage);
|
|
||||||
router.get('/test_old', (req, res, next) => {
|
|
||||||
req.brew = {
|
|
||||||
text : statics.oldTest,
|
|
||||||
version : 1
|
|
||||||
};
|
|
||||||
return next();
|
|
||||||
}, renderPage);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
const _ = require('lodash');
|
|
||||||
const jwt = require('jwt-simple');
|
|
||||||
const auth = require('basic-auth');
|
|
||||||
const config = require('nconf');
|
|
||||||
|
|
||||||
const Error = require('./error.js');
|
|
||||||
const BrewData = require('./brew.data.js');
|
|
||||||
|
|
||||||
const Middleware = {
|
|
||||||
account : (req, res, next) => {
|
|
||||||
if(req.cookies && req.cookies.nc_session){
|
|
||||||
try{
|
|
||||||
req.account = jwt.decode(req.cookies.nc_session, config.get('jwt_secret'));
|
|
||||||
}catch(e){}
|
|
||||||
}
|
|
||||||
return next();
|
|
||||||
},
|
|
||||||
admin : (req, res, next) => {
|
|
||||||
req.admin = false;
|
|
||||||
if(req.headers['x-homebrew-admin'] === config.get('admin:key')){
|
|
||||||
req.admin = true;
|
|
||||||
}
|
|
||||||
return next();
|
|
||||||
},
|
|
||||||
|
|
||||||
//Filters
|
|
||||||
devOnly : (req, res, next) => {
|
|
||||||
const env = process.env.NODE_ENV;
|
|
||||||
if(env !== 'staging' && env !== 'production') return next();
|
|
||||||
return res.sendStatus(404);
|
|
||||||
},
|
|
||||||
adminOnly : (req, res, next) => {
|
|
||||||
if(req.admin) return next();
|
|
||||||
return next(Error.noAuth());
|
|
||||||
},
|
|
||||||
adminLogin : (req, res, next) => {
|
|
||||||
const creds = auth(req);
|
|
||||||
if(!creds
|
|
||||||
|| creds.name !== config.get('admin:user')
|
|
||||||
|| creds.pass !== config.get('admin:pass')){
|
|
||||||
res.setHeader('WWW-Authenticate', 'Basic realm="example"');
|
|
||||||
return next(Error.noAdmin());
|
|
||||||
}
|
|
||||||
return next();
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: REMOVE
|
|
||||||
//Loaders
|
|
||||||
loadBrew : (req, res, next) => {
|
|
||||||
BrewData.getByEdit(req.params.editId)
|
|
||||||
.then((brew) => {
|
|
||||||
req.brew = brew;
|
|
||||||
return next()
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
},
|
|
||||||
viewBrew : (req, res, next) => {
|
|
||||||
BrewData.getByShare(req.params.shareId)
|
|
||||||
.then((brew) => {
|
|
||||||
req.brew = brew;
|
|
||||||
return next()
|
|
||||||
})
|
|
||||||
.catch(next);
|
|
||||||
},
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Middleware;
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getGoodBrewTitle : (text = '') => {
|
|
||||||
const titlePos = text.indexOf('# ');
|
|
||||||
if(titlePos !== -1){
|
|
||||||
let ending = text.indexOf('\n', titlePos);
|
|
||||||
ending = (ending == -1 ? undefined : ending);
|
|
||||||
return text.substring(titlePos + 2, ending).trim();
|
|
||||||
}else{
|
|
||||||
return (_.find(text.split('\n'), (line)=>{
|
|
||||||
return line;
|
|
||||||
}) || '').trim();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
replaceByMap : (text, mapping) => {
|
|
||||||
return _.reduce(mapping, (r, search, replace) => {
|
|
||||||
return r.split(search).join(replace)
|
|
||||||
}, text)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
const Store = require('./account.store.js');
|
|
||||||
|
|
||||||
const Actions = {
|
|
||||||
init : (initState) => {
|
|
||||||
Store.init(initState);
|
|
||||||
},
|
|
||||||
login : ()=>{
|
|
||||||
window.location = Store.getLoginPath();
|
|
||||||
},
|
|
||||||
logout : ()=>{
|
|
||||||
document.cookie = 'nc_session=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;domain=.naturalcrit.com';
|
|
||||||
//Remove local dev cookies too
|
|
||||||
document.cookie = 'nc_session=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;';
|
|
||||||
window.location ='/';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Actions;
|
|
||||||