added page rendering framework to API

This commit is contained in:
Ro 2020-05-05 12:31:32 -07:00
parent cf363125b7
commit 8052c861bf
6 changed files with 62 additions and 4 deletions

View file

@ -33,7 +33,7 @@ var post_upload = multer({
}).array('post_image');
/**
* Retrives list of Pages
* Retrieves list of Pages
* @public
*/
router.get('/', (req, res) => {

View file

@ -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
*/

View file

@ -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
//--------------------------

View file

@ -22,6 +22,8 @@ block main-content
| DON'T RENDER PAGES ON SAVE
-else
| RENDER PAGES ON SAVE
button#publish-pages
| Publish Site
input(id="avatar-upload" type="file" name="avatar-upload")
#member-settings-2.column
label INFO

View file

@ -1,5 +1,9 @@
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 Mailer from '../actions/Mailer';
import Notifications from '../ui/Notifications';
@ -63,6 +67,9 @@ export default class SettingsIndex {
.getElementById('render-toggle')
.addEventListener('click', e => this.toggleRender(e));
document.getElementById('send-mail').addEventListener('click', e => this.handleMailer(e));
document
.getElementById('publish-pages')
.addEventListener('click', e => this.handlePublished(e));
//handle theme toggle
let themeBtns = document.querySelectorAll('.theme-select');
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)
.then(response => {
//TODO: Move JSON processing to API class
let r = JSON.parse(response.request['response']);
if (r.type == DataEvent.AVATAR_UPLOADED) {
notify.alert(r.message, true);
@ -168,4 +176,23 @@ export default class SettingsIndex {
//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);
});
}
}

View file

@ -23,6 +23,7 @@ export const API_PAGE_CREATE = 'writingNewEntry';
export const API_PAGE_DELETE = 'erasingPage';
export const API_SETTINGS_WRITE = 'savingSettings';
export const API_IMAGES_UPLOAD = 'uploadProfileImages';
export const API_RENDER_PAGES = 'renderPages';
class DataEvent {
//--------------------------
// methods