forked from dbroqua/MusicTopus
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
|
import config from "../config";
|
||
|
import { getBaseUrl } from "../helpers";
|
||
|
|
||
|
/**
|
||
|
* Classe permettant de gérer les page du back office
|
||
|
*/
|
||
|
class Pages {
|
||
|
/**
|
||
|
* @param {Object} req
|
||
|
* @param {String} viewname
|
||
|
*/
|
||
|
constructor(req, viewname) {
|
||
|
this.req = req;
|
||
|
this.pageContent = {
|
||
|
page: {
|
||
|
title: null,
|
||
|
user: null,
|
||
|
},
|
||
|
viewname: `pages/${viewname}`,
|
||
|
};
|
||
|
|
||
|
this.user = null;
|
||
|
this.pagename = viewname;
|
||
|
|
||
|
if (req.session && req.session.passport && req.session.passport.user) {
|
||
|
this.user = req.session.passport.user;
|
||
|
}
|
||
|
|
||
|
if (!req.query.page) {
|
||
|
req.query.page = 1;
|
||
|
}
|
||
|
if (!req.query.limit) {
|
||
|
req.query.limit = config.pagination;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Rendu de la page
|
||
|
* @return {Object}
|
||
|
*/
|
||
|
render() {
|
||
|
this.pageContent.session = this.req.session;
|
||
|
this.pageContent.flashInfo = this.req.flash("info");
|
||
|
this.pageContent.error = this.req.flash("error") || null;
|
||
|
this.pageContent.query = this.req.query;
|
||
|
this.pageContent.params = this.req.params;
|
||
|
this.pageContent.user = this.user;
|
||
|
this.pageContent.config = config;
|
||
|
this.pageContent.getBaseUrl = getBaseUrl();
|
||
|
|
||
|
if (this.req.session.flash && this.req.session.flash.error) {
|
||
|
// eslint-disable-next-line prefer-destructuring
|
||
|
this.pageContent.page.failureFlash =
|
||
|
this.req.session.flash.error[0];
|
||
|
this.req.session.flash = null;
|
||
|
}
|
||
|
|
||
|
return this.pageContent;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default Pages;
|