added page rendering framework to API
This commit is contained in:
parent
cf363125b7
commit
8052c861bf
6 changed files with 62 additions and 4 deletions
|
@ -33,7 +33,7 @@ var post_upload = multer({
|
||||||
}).array('post_image');
|
}).array('post_image');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrives list of Pages
|
* Retrieves list of Pages
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
router.get('/', (req, res) => {
|
router.get('/', (req, res) => {
|
||||||
|
|
|
@ -14,10 +14,10 @@ fs.ensureDir(uploadPath, () => {
|
||||||
// dir has now been created, including the directory it is to be placed in
|
// dir has now been created, including the directory it is to be placed in
|
||||||
});
|
});
|
||||||
var storage = multer.diskStorage({
|
var storage = multer.diskStorage({
|
||||||
destination: function(req, file, cb) {
|
destination: function (req, file, cb) {
|
||||||
cb(null, uploadPath);
|
cb(null, uploadPath);
|
||||||
},
|
},
|
||||||
filename: function(req, file, cb) {
|
filename: function (req, file, cb) {
|
||||||
var splice = file.originalname.split(':');
|
var splice = file.originalname.split(':');
|
||||||
cb(null, splice[0]);
|
cb(null, splice[0]);
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,21 @@ router.post('/nav-sync', (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post('/publish-pages', (req, res) => {
|
||||||
|
if (req.session.user) {
|
||||||
|
console.log('PUBLISHING');
|
||||||
|
res.json({
|
||||||
|
type: DataEvent.API_RENDER_PAGES,
|
||||||
|
message: 'All Pages Rendered and Published'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.json({
|
||||||
|
type: DataEvent.REQUEST_LAME,
|
||||||
|
message: "You're not logged in, champ"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/***
|
/***
|
||||||
UPLOAD AVATAR
|
UPLOAD AVATAR
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -173,6 +173,19 @@ export default class Pages {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
publish() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let self = this;
|
||||||
|
//get pages for rendering
|
||||||
|
this.getPage()
|
||||||
|
.then(pages => {
|
||||||
|
console.log('PAGES', pages);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// event handlers
|
// event handlers
|
||||||
//--------------------------
|
//--------------------------
|
||||||
|
|
|
@ -22,6 +22,8 @@ block main-content
|
||||||
| DON'T RENDER PAGES ON SAVE
|
| DON'T RENDER PAGES ON SAVE
|
||||||
-else
|
-else
|
||||||
| RENDER PAGES ON SAVE
|
| RENDER PAGES ON SAVE
|
||||||
|
button#publish-pages
|
||||||
|
| Publish Site
|
||||||
input(id="avatar-upload" type="file" name="avatar-upload")
|
input(id="avatar-upload" type="file" name="avatar-upload")
|
||||||
#member-settings-2.column
|
#member-settings-2.column
|
||||||
label INFO
|
label INFO
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import SettingsActions from '../actions/SettingsActions';
|
import SettingsActions from '../actions/SettingsActions';
|
||||||
import ApiUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_FORM } from '../../../src/com/utils/APIUtils';
|
import ApiUtils, {
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_FORM,
|
||||||
|
CONTENT_TYPE_JSON
|
||||||
|
} from '../../../src/com/utils/APIUtils';
|
||||||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||||
import Mailer from '../actions/Mailer';
|
import Mailer from '../actions/Mailer';
|
||||||
import Notifications from '../ui/Notifications';
|
import Notifications from '../ui/Notifications';
|
||||||
|
@ -63,6 +67,9 @@ export default class SettingsIndex {
|
||||||
.getElementById('render-toggle')
|
.getElementById('render-toggle')
|
||||||
.addEventListener('click', e => this.toggleRender(e));
|
.addEventListener('click', e => this.toggleRender(e));
|
||||||
document.getElementById('send-mail').addEventListener('click', e => this.handleMailer(e));
|
document.getElementById('send-mail').addEventListener('click', e => this.handleMailer(e));
|
||||||
|
document
|
||||||
|
.getElementById('publish-pages')
|
||||||
|
.addEventListener('click', e => this.handlePublished(e));
|
||||||
//handle theme toggle
|
//handle theme toggle
|
||||||
let themeBtns = document.querySelectorAll('.theme-select');
|
let themeBtns = document.querySelectorAll('.theme-select');
|
||||||
for (var i = 0, length = themeBtns.length; i < length; i++) {
|
for (var i = 0, length = themeBtns.length; i < length; i++) {
|
||||||
|
@ -155,6 +162,7 @@ export default class SettingsIndex {
|
||||||
}
|
}
|
||||||
api.request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData)
|
api.request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
//TODO: Move JSON processing to API class
|
||||||
let r = JSON.parse(response.request['response']);
|
let r = JSON.parse(response.request['response']);
|
||||||
if (r.type == DataEvent.AVATAR_UPLOADED) {
|
if (r.type == DataEvent.AVATAR_UPLOADED) {
|
||||||
notify.alert(r.message, true);
|
notify.alert(r.message, true);
|
||||||
|
@ -168,4 +176,23 @@ export default class SettingsIndex {
|
||||||
//console.log(err)
|
//console.log(err)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
handlePublished(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
let task = { task: 'publish all pages' };
|
||||||
|
api.request(
|
||||||
|
'/api/v1/settings/publish-pages',
|
||||||
|
DataEvent.API_RENDER_PAGES,
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_JSON,
|
||||||
|
task
|
||||||
|
)
|
||||||
|
.then(response => {
|
||||||
|
let r = JSON.parse(response.request['response']);
|
||||||
|
console.log('RESPONSE', r);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
notify.alert(err, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ export const API_PAGE_CREATE = 'writingNewEntry';
|
||||||
export const API_PAGE_DELETE = 'erasingPage';
|
export const API_PAGE_DELETE = 'erasingPage';
|
||||||
export const API_SETTINGS_WRITE = 'savingSettings';
|
export const API_SETTINGS_WRITE = 'savingSettings';
|
||||||
export const API_IMAGES_UPLOAD = 'uploadProfileImages';
|
export const API_IMAGES_UPLOAD = 'uploadProfileImages';
|
||||||
|
export const API_RENDER_PAGES = 'renderPages';
|
||||||
class DataEvent {
|
class DataEvent {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// methods
|
// methods
|
||||||
|
|
Loading…
Reference in a new issue