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.

86 lines
2.6 KiB

import {Controller, view, Injectable, SecurityContext, Inject, Collection, Config, Routing, file, Application} from '@extollo/lib'
import {WorkItem} from '../../models/WorkItem.model'
import {FeedPost} from '../../models/FeedPost.model'
@Injectable()
export class Home extends Controller {
@Inject()
protected readonly security!: SecurityContext
@Inject()
protected readonly config!: Config
@Inject()
protected readonly routing!: Routing
public async welcome(feedPosts: Collection<FeedPost>) {
const workItems = await this.getWorkItems()
return view('welcome', {
feedPosts: feedPosts.toArray(),
workItemGroups: workItems.groupBy(item => item.startDate.getFullYear()),
workItemYears: workItems.map(item => item.startDate.getFullYear())
.unique()
.toArray(),
workItemHiddenYears: workItems.filter(item => item.endDate)
.map(item => item.startDate.getFullYear())
.unique()
.toArray()
})
}
public technical() {
const isOptOut = this.request.cookies.has(this.config.get('app.analytics.optOutCookie'))
return view('technical', {
isOptOut,
})
}
public optOutPrompt() {
return view('message', {
title: 'Analytics Opt-Out',
message: 'This will set a cookie to disable analytics recording in your browser on all <code>*.garrettmills.dev</code> sites. Continue?',
buttonAction: this.routing.getNamedPath('opt-out').toRemote,
buttonMethod: 'post',
})
}
public optOut() {
this.request.cookies.set(
this.config.get('app.analytics.optOutCookie'),
true,
{
expires: new Date(Date.now() + (1000 * 60 * 60 * 24 * 365 * 100)),
secure: true,
httpOnly: true,
path: '/',
},
)
return view('message', {
title: 'Analytics Opt-Out',
message: 'You have been opted-out of analytics recording.',
buttonAction: this.routing.getNamedPath('home').toRemote,
})
}
protected async getWorkItems(): Promise<Collection<WorkItem>> {
const query = WorkItem.query<WorkItem>()
.orderByDescending('start_date')
if ( !this.security.hasUser() ) {
query.where('visible', '=', true)
}
return query.get().collect()
}
favicon() {
return file(
Application.getApplication()
.appPath('resources', 'assets', 'favicon', 'favicon.ico')
)
}
}