You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
// home.js
|
|
// Copyright (C) 2024 DTP Technologies, LLC
|
|
// All Rights Reserved
|
|
|
|
'use strict';
|
|
|
|
import express from 'express';
|
|
|
|
import { SiteController } from '../../lib/site-controller.js';
|
|
|
|
export default class HomeController extends SiteController {
|
|
|
|
static get name ( ) { return 'HomeController'; }
|
|
static get slug ( ) { return 'home'; }
|
|
|
|
constructor (dtp) {
|
|
super(dtp, HomeController.slug);
|
|
this.dtp = dtp;
|
|
}
|
|
|
|
async start ( ) {
|
|
const router = express.Router();
|
|
this.dtp.app.use('/', router);
|
|
|
|
router.get('/', this.getHome.bind(this));
|
|
|
|
return router;
|
|
}
|
|
|
|
async getHome (req, res, next) {
|
|
const { client: clientService, report: reportService, task: taskService } = this.dtp.services;
|
|
try {
|
|
if (!req.user) {
|
|
return res.redirect('/welcome');
|
|
}
|
|
|
|
res.locals.currentView = 'home';
|
|
res.locals.pageDescription = 'DTP Time Tracker';
|
|
|
|
res.locals.projects = await clientService.getProjectsForUser(req.user);
|
|
res.locals.taskGrid = await taskService.getTaskGridForUser(req.user);
|
|
res.locals.weeklyEarnings = await reportService.getWeeklyEarnings(req.user);
|
|
|
|
res.locals.managedProjects = await clientService.getProjectsForManager(req.user);
|
|
for (const project of res.locals.managedProjects) {
|
|
project.taskGrid = await taskService.getTaskGridForProject(project);
|
|
}
|
|
|
|
res.render('home');
|
|
} catch (error) {
|
|
this.log.error('failed to present the home view', { error });
|
|
return next(error);
|
|
}
|
|
}
|
|
}
|