Co-authored-by: dbroqua <contact@darkou.fr> Reviewed-on: https://git.darkou.fr/dbroqua/MusicTopus/pulls/44
73 lines
1.8 KiB
JavaScript
73 lines
1.8 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;
|
|
}
|
|
}
|
|
|
|
setPageTitle(title) {
|
|
this.pageContent.page.title = title;
|
|
}
|
|
|
|
setPageContent(field, value) {
|
|
this.pageContent.page[field] = value;
|
|
}
|
|
|
|
getPageContent(field) {
|
|
return this.pageContent.page[field];
|
|
}
|
|
|
|
/**
|
|
* Rendu de la page
|
|
* @return {Object}
|
|
*/
|
|
render() {
|
|
this.pageContent.session = this.req.session;
|
|
this.pageContent.flash = {
|
|
info: this.req.flash("info"),
|
|
error: [
|
|
...this.req.flash("error"),
|
|
...(this.req.session?.flash?.error || []),
|
|
],
|
|
success: this.req.flash("success"),
|
|
};
|
|
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(this.req);
|
|
|
|
return this.pageContent;
|
|
}
|
|
}
|
|
|
|
export default Pages;
|