Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
imdivakar92 committed Oct 14, 2017
0 parents commit 3f8216a
Show file tree
Hide file tree
Showing 134 changed files with 33,965 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
indent_style = tab

[{*.yml,*.json}]
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public/js/bootstrap
public/js/jquery
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "keystone"
}
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules

# Ignore .env configuration files
.env

# Ignore .DS_Store files on OS X
.DS_Store
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node keystone.js
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"# Dash"
53 changes: 53 additions & 0 deletions keystone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require('dotenv').config();

// Require keystone
var keystone = require('keystone');

keystone.init({
'name': 'Dash',
'brand': 'Dash',

'less': 'public',
'static': 'public',
'favicon': 'public/favicon.ico',
'views': 'templates/views',
'view engine': 'pug',

'emails': 'templates/emails',

'auto update': true,
'session': true,
'auth': true,
'user model': 'User',
});
keystone.import('models');
keystone.set('locals', {
_: require('lodash'),
env: keystone.get('env'),
utils: keystone.utils,
editable: keystone.content.editable,
});
keystone.set('routes', require('./routes'));

keystone.set('nav', {
posts: ['posts', 'post-categories'],
galleries: 'galleries',
enquiries: 'enquiries',
users: 'users',
});


if (!process.env.MAILGUN_API_KEY || !process.env.MAILGUN_DOMAIN) {
console.log('----------------------------------------'
+ '\nWARNING: MISSING MAILGUN CREDENTIALS'
+ '\n----------------------------------------'
+ '\nYou have opted into email sending but have not provided'
+ '\nmailgun credentials. Attempts to send will fail.'
+ '\n\nCreate a mailgun account and add the credentials to the .env file to'
+ '\nset up your mailgun integration');
}


keystone.start();
75 changes: 75 additions & 0 deletions models/Enquiry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
* Enquiry Model
* =============
*/

var Enquiry = new keystone.List('Enquiry', {
nocreate: true,
noedit: true,
});

Enquiry.add({
name: { type: Types.Name, required: true },
email: { type: Types.Email, required: true },
phone: { type: String },
enquiryType: { type: Types.Select, options: [
{ value: 'message', label: 'Just leaving a message' },
{ value: 'question', label: 'I\'ve got a question' },
{ value: 'other', label: 'Something else...' },
] },
message: { type: Types.Markdown, required: true },
createdAt: { type: Date, default: Date.now },
});

Enquiry.schema.pre('save', function (next) {
this.wasNew = this.isNew;
next();
});

Enquiry.schema.post('save', function () {
if (this.wasNew) {
this.sendNotificationEmail();
}
});

Enquiry.schema.methods.sendNotificationEmail = function (callback) {
if (typeof callback !== 'function') {
callback = function (err) {
if (err) {
console.error('There was an error sending the notification email:', err);
}
};
}

if (!process.env.MAILGUN_API_KEY || !process.env.MAILGUN_DOMAIN) {
console.log('Unable to send email - no mailgun credentials provided');
return callback(new Error('could not find mailgun credentials'));
}

var enquiry = this;
var brand = keystone.get('brand');

keystone.list('User').model.find().where('isAdmin', true).exec(function (err, admins) {
if (err) return callback(err);
new keystone.Email({
templateName: 'enquiry-notification',
transport: 'mailgun',
}).send({
to: admins,
from: {
name: 'Dash',
email: '[email protected]',
},
subject: 'New Enquiry for Dash',
enquiry: enquiry,
brand: brand,
}, callback);
});
};

Enquiry.defaultSort = '-createdAt';
Enquiry.defaultColumns = 'name, email, enquiryType, createdAt';
Enquiry.register();
20 changes: 20 additions & 0 deletions models/Gallery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
* Gallery Model
* =============
*/

var Gallery = new keystone.List('Gallery', {
autokey: { from: 'name', path: 'key', unique: true },
});

Gallery.add({
name: { type: String, required: true },
publishedDate: { type: Date, default: Date.now },
heroImage: { type: Types.CloudinaryImage },
images: { type: Types.CloudinaryImages },
});

Gallery.register();
32 changes: 32 additions & 0 deletions models/Post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
* Post Model
* ==========
*/

var Post = new keystone.List('Post', {
map: { name: 'title' },
autokey: { path: 'slug', from: 'title', unique: true },
});

Post.add({
title: { type: String, required: true },
state: { type: Types.Select, options: 'draft, published, archived', default: 'draft', index: true },
author: { type: Types.Relationship, ref: 'User', index: true },
publishedDate: { type: Types.Date, index: true, dependsOn: { state: 'published' } },
image: { type: Types.CloudinaryImage },
content: {
brief: { type: Types.Html, wysiwyg: true, height: 150 },
extended: { type: Types.Html, wysiwyg: true, height: 400 },
},
categories: { type: Types.Relationship, ref: 'PostCategory', many: true },
});

Post.schema.virtual('content.full').get(function () {
return this.content.extended || this.content.brief;
});

Post.defaultColumns = 'title, state|20%, author|20%, publishedDate|20%';
Post.register();
18 changes: 18 additions & 0 deletions models/PostCategory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var keystone = require('keystone');

/**
* PostCategory Model
* ==================
*/

var PostCategory = new keystone.List('PostCategory', {
autokey: { from: 'name', path: 'key', unique: true },
});

PostCategory.add({
name: { type: String, required: true },
});

PostCategory.relationship({ ref: 'Post', path: 'posts', refPath: 'categories' });

PostCategory.register();
34 changes: 34 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
* User Model
* ==========
*/
var User = new keystone.List('User');

User.add({
name: { type: Types.Name, required: true, index: true },
email: { type: Types.Email, initial: true, required: true, unique: true, index: true },
password: { type: Types.Password, initial: true, required: true },
}, 'Permissions', {
isAdmin: { type: Boolean, label: 'Can access Keystone', index: true },
});

// Provide access to Keystone
User.schema.virtual('canAccessKeystone').get(function () {
return this.isAdmin;
});


/**
* Relationships
*/
User.relationship({ ref: 'Post', path: 'posts', refPath: 'author' });


/**
* Registration
*/
User.defaultColumns = 'name, email, isAdmin';
User.register();
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "dash",
"version": "0.0.0",
"private": true,
"dependencies": {
"keystone": "4.0.0-beta.5",
"lodash": "^4.13.1",
"pug": "2.0.0-beta11",
"dotenv": "4.0.0",
"keystone-email": "1.0.5",
"async": "2.1.4"
},
"devDependencies": {
"eslint": "3.15.0",
"eslint-config-keystone": "3.0.0",
"eslint-plugin-react": "^5.1.1"
},
"scripts": {
"lint": "eslint .",
"start": "node keystone.js"
}
}
Binary file added public/favicon.ico
Binary file not shown.
Binary file added public/fonts/glyphicons-halflings-regular.eot
Binary file not shown.
Loading

0 comments on commit 3f8216a

Please sign in to comment.