feat: add lazy loading of card on home page
feat: add universal organization store fix: optimization for JSON data loaded in home page HTML
This commit is contained in:
parent
2e6e64a6d3
commit
ecf9a0720e
8 changed files with 224 additions and 87 deletions
|
|
@ -18,7 +18,7 @@ export default class MediaService {
|
|||
}
|
||||
|
||||
static getBucket(): string {
|
||||
return process.env.S3_BUCKET === undefined ? '___BUCKET_NOT_FOUND_ENV_VAR_ISSUE___' : process.env.S3_BUCKET
|
||||
return process.env.S3_BUCKET == null ? '___BUCKET_NOT_FOUND_ENV_VAR_ISSUE___' : process.env.S3_BUCKET
|
||||
}
|
||||
|
||||
static delete(key: string, context: string) {
|
||||
|
|
@ -36,7 +36,7 @@ export default class MediaService {
|
|||
static deleteMany(keys: string[], context: string) {
|
||||
console.log('> MediaCleanup: in context "' + context + '" deleteMany', keys)
|
||||
keys.forEach((key: string) => {
|
||||
if (key === undefined || key === null || key.length <= 2) { return }
|
||||
if (key == null || key.length <= 2) { return }
|
||||
MediaService.delete(key, context)
|
||||
})
|
||||
}
|
||||
|
|
@ -75,4 +75,8 @@ export default class MediaService {
|
|||
type: type === 'media' ? file.contentType.split('/')[0] : type
|
||||
}
|
||||
}
|
||||
|
||||
static getMediaBaseUrl() {
|
||||
return process.env.S3_BASE_URL == null ? '___BUCKET_BASE_URL_NOT_FOUND_ENV_VAR_ISSUE___' : process.env.S3_BASE_URL
|
||||
}
|
||||
}
|
||||
|
|
@ -49,7 +49,6 @@ let main = async () => {
|
|||
).then(() => {
|
||||
console.log('> App: Connected to mongodb')
|
||||
})
|
||||
|
||||
|
||||
app.set("twig options", {
|
||||
allow_async: true,
|
||||
|
|
|
|||
|
|
@ -29,41 +29,61 @@ export default class AdminOrganizationController {
|
|||
}
|
||||
|
||||
static store(req: express.Request, res: express.Response) {
|
||||
let body: any = {
|
||||
token: AdminOrganizationController.generateToken(),
|
||||
createdAt: new Date(),
|
||||
// start the slugs array
|
||||
slugs: [slugify(req.body.adminName)],
|
||||
...req.body,
|
||||
...{
|
||||
proposedVersion: {
|
||||
name: req.body.adminName,
|
||||
contacts: {
|
||||
facebook: '',
|
||||
twitter: '',
|
||||
instagram: '',
|
||||
website: '',
|
||||
address: '',
|
||||
person: '',
|
||||
email: req.body.email,
|
||||
phone: ''
|
||||
AdminOrganizationController.storeUniversal(
|
||||
req.body.adminName,
|
||||
req.body.email,
|
||||
req.body.validationState
|
||||
).then(({ data, body }) => {
|
||||
res.json({ success: true, data, body })
|
||||
}).catch((err: any) => {
|
||||
res.status(400).json({ success: false, errors: err.errors })
|
||||
})
|
||||
}
|
||||
|
||||
static storeUniversal(adminName: string, email: string, validationState: string): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (validationState == null) {
|
||||
validationState = 'unaware'
|
||||
}
|
||||
let body: any = {
|
||||
token: AdminOrganizationController.generateToken(),
|
||||
createdAt: new Date(),
|
||||
// start the slugs array
|
||||
slugs: [slugify(adminName)],
|
||||
validationState,
|
||||
adminName,
|
||||
email,
|
||||
...{
|
||||
proposedVersion: {
|
||||
name: adminName,
|
||||
contacts: {
|
||||
facebook: '',
|
||||
twitter: '',
|
||||
instagram: '',
|
||||
website: '',
|
||||
address: '',
|
||||
person: '',
|
||||
email,
|
||||
phone: ''
|
||||
}
|
||||
// descriptionShort: '',
|
||||
// descriptionLong: '',
|
||||
// contacts: [],
|
||||
// schedule: [],
|
||||
// pricing: [],
|
||||
// tag: null,
|
||||
// cover: null,
|
||||
// gallery: [],
|
||||
// thumbnail: null
|
||||
}
|
||||
// descriptionShort: '',
|
||||
// descriptionLong: '',
|
||||
// contacts: [],
|
||||
// schedule: [],
|
||||
// pricing: [],
|
||||
// tag: null,
|
||||
// cover: null,
|
||||
// gallery: [],
|
||||
// thumbnail: null
|
||||
}
|
||||
}
|
||||
}
|
||||
Organization.create(body).then(data => {
|
||||
AdminOrganizationController.sendEmailTokenUniversal(data)
|
||||
res.json({ success: true, data, body })
|
||||
}).catch(err => res.status(400).json({ success: false, errors: err.errors }))
|
||||
console.log(body)
|
||||
Organization.create(body).then(data => {
|
||||
AdminOrganizationController.sendEmailTokenUniversal(data)
|
||||
resolve({ data, body })
|
||||
}).catch(err => reject(err))
|
||||
})
|
||||
}
|
||||
|
||||
static update(req: express.Request, res: express.Response) {
|
||||
|
|
@ -172,12 +192,12 @@ export default class AdminOrganizationController {
|
|||
let extra: any = {}
|
||||
let slug = slugify(proposedVersion.name)
|
||||
// only add this slug if the proposed slug is not found in the list of current slug
|
||||
let currentSlugs: string[] = []
|
||||
extra.slugs = []
|
||||
if (Array.isArray(data.get('slugs'))) {
|
||||
currentSlugs = data.get('slugs')
|
||||
extra.slugs = data.get('slugs')
|
||||
}
|
||||
if (currentSlugs.filter(s => s === slug).length === 0) {
|
||||
extra.slugs = currentSlugs.concat([slug])
|
||||
if (extra.slugs.filter((s: any) => s === slug).length === 0) {
|
||||
extra.slugs = extra.slugs.concat([slug])
|
||||
}
|
||||
extra.adminName = proposedVersion.name
|
||||
|
||||
|
|
@ -231,12 +251,12 @@ export default class AdminOrganizationController {
|
|||
updatedAt: new Date()
|
||||
}).then(updateData => {
|
||||
EmailService.send(
|
||||
data.get('email'),
|
||||
extra.email,
|
||||
"Félicitations, vos changements ont été approuvés et publiés !",
|
||||
"published",
|
||||
{
|
||||
adminName: data.get('adminName'),
|
||||
link: EmailService.getBaseUrl() + '/association/' + data.get('slug')
|
||||
link: EmailService.getBaseUrl() + '/association/' + extra.slugs[extra.slugs.length - 1]
|
||||
}
|
||||
)
|
||||
res.json({ success: true, data: updateData })
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import Tag from '../models/Tag'
|
|||
import ErrorController from './ErrorController'
|
||||
import Utils from '../Utils'
|
||||
import mongoose from 'mongoose'
|
||||
import MediaService from '../MediaService'
|
||||
|
||||
export default class PublicController {
|
||||
|
||||
|
|
@ -30,24 +31,29 @@ export default class PublicController {
|
|||
if (!isProposed) {
|
||||
organizations = organizations.filter(o => o.get('publishedAt') !== undefined && o.get('publishedAt') !== null)
|
||||
}
|
||||
// let organizationsData = organizations
|
||||
// .map(o => {
|
||||
// const version = isProposed ? o.get('proposedVersion'): o.get('publishedVersion')
|
||||
// return {
|
||||
// _id: o._id,
|
||||
// name: version.name,
|
||||
// description: version.descriptionShort,
|
||||
// thumbnail: version.thumbnail.key,
|
||||
// tags: version.tags === null ? 'tags_not_found' : version.tags,
|
||||
// slug: o.get('slugs')[o.get('slugs).length -1]
|
||||
// }
|
||||
// })
|
||||
let lorem = "Dolore sit tempor et duo ipsum sit sed takimata, et magna voluptua ut sed justo eirmod. Sed tempor justo magna accusam aliquyam sea invidunt eos. Aliquyam accusam vero accusam sed"
|
||||
let organizationsData = []
|
||||
for (var i = 0; i < 40; i++) {
|
||||
organizationsData.push({ _id: i, name: 'Item ' + i, description: lorem, thumbnail: 'https://picsum.photos/800?hash=' + i, slug: 'qsd-'+i, tags: ['5f0e00e1a4dbfe3e0b5291d2'] })
|
||||
}
|
||||
res.render('home.twig', {
|
||||
isProposed,
|
||||
mediaBaseUrl: MediaService.getMediaBaseUrl(),
|
||||
tags,
|
||||
tagsJSON: JSON.stringify(tags),
|
||||
organizationsJSON: JSON.stringify(organizations
|
||||
.map(o => {
|
||||
const version = isProposed ? o.get('proposedVersion'): o.get('publishedVersion')
|
||||
return {
|
||||
_id: o._id,
|
||||
name: version.name,
|
||||
description: version.descriptionShort,
|
||||
thumbnail: version.thumbnail.location,
|
||||
tags: version.tags === null ? 'tags_not_found' : version.tags,
|
||||
slugs: o.get('slugs'),
|
||||
isProposed
|
||||
}
|
||||
})
|
||||
)
|
||||
organizationsJSON: JSON.stringify(organizationsData)
|
||||
})
|
||||
}).catch(err => () => {
|
||||
console.log(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue