Skip to content

Commit

Permalink
Misc Updates
Browse files Browse the repository at this point in the history
* Add autoclean via subscription extension.
* Remove log line.
* Fix bugs with sermon admin page.
* Properly return a 404 the universal way.
* Update version to 1.3.9
* Remove unused factory method.
  • Loading branch information
clarkmalmgren committed Jan 11, 2018
1 parent 8bb7dc6 commit c429902
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 60 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229
}
]
}
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bolingbrook-church",
"version": "1.3.8",
"version": "1.3.9",
"license": "MIT",
"angular-cli": {},
"scripts": {
Expand Down Expand Up @@ -29,6 +29,7 @@
"@angular/platform-browser-dynamic": "^5.0.5",
"@angular/platform-server": "^5.0.5",
"@angular/router": "^5.0.5",
"@nguniversal/express-engine": "^5.0.0-beta.5",
"@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
"@types/moment": "^2.13.0",
"@types/moment-timezone": "^0.5.2",
Expand Down
6 changes: 4 additions & 2 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'reflect-metadata';
import { renderModuleFactory } from '@angular/platform-server';
import { enableProdMode } from '@angular/core';
import * as express from 'express';
import { RESPONSE } from '@nguniversal/express-engine/tokens'
import { join } from 'path';
import { readFileSync } from 'fs';
import { Sitemap } from './server/sitemap';
Expand Down Expand Up @@ -35,7 +36,8 @@ app.engine('html', (_, options, callback) => {
url: options.req.url,
// DI so that we can get lazy-loading to work differently (since we need it to just instantly render it)
extraProviders: [
provideModuleMap(LAZY_MODULE_MAP)
provideModuleMap(LAZY_MODULE_MAP),
{ provide: RESPONSE, useFactory: () => options.res, deps: [] }
]
}).then(html => {
callback(null, html);
Expand All @@ -57,7 +59,7 @@ app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));

// All regular routes use the Universal engine
app.get('*', (req, res) => {
res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req });
res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req: req, res: res });
});

// Start up the Node server
Expand Down
15 changes: 11 additions & 4 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import { HttpModule } from '@angular/http';
import { MATERIAL_MODULES } from './components/atoms/material';
import { AppComponent } from './app.component';
import * as Components from './components';
import { SERVICES, GlobalErrorHandler } from './services';
import { Aperture } from './services/aperture';
import { BrowserAperture } from './services/aperture.browser';
import { FirebaseService } from './services/firebase.service';
import { FirebaseBrowserService } from './services/firebase.browser';
import { BrowserResponseService } from './services/response.browser';

import {
SERVICES,
Aperture,
FirebaseService,
GlobalErrorHandler,
ResponseService
} from './services';

@NgModule({
declarations: [
Expand All @@ -33,7 +39,8 @@ import { FirebaseBrowserService } from './services/firebase.browser'
...SERVICES,
{ provide: Aperture, useClass: BrowserAperture},
{ provide: FirebaseService, useClass: FirebaseBrowserService },
{ provide: ErrorHandler, useClass: GlobalErrorHandler }
{ provide: ErrorHandler, useClass: GlobalErrorHandler },
{ provide: ResponseService, useClass: BrowserResponseService }
],
bootstrap: [ AppComponent ]
})
Expand Down
21 changes: 12 additions & 9 deletions src/app/app.server.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server';
import { ModuleMapLoaderModule } from '@nguniversal/module-map-ngfactory-loader';
import { AppModule } from './app.module';
import { AppComponent } from './app.component';
import { Aperture } from './services/aperture';
import { ServerAperture } from './services/aperture.server';
import { FirebaseService } from './services/firebase.service';
import { FirebaseServerService } from './services/firebase.server';
import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server';
import { ModuleMapLoaderModule } from '@nguniversal/module-map-ngfactory-loader';
import { RESPONSE } from '@nguniversal/express-engine/tokens'
import * as express from 'express';
import { AppModule } from './app.module';
import { AppComponent } from './app.component';
import { Aperture, FirebaseService, ResponseService } from './services';
import { ServerAperture } from './services/aperture.server';
import { FirebaseServerService } from './services/firebase.server';
import { ServerResponseService } from './services/response.server';

@NgModule({
imports: [
Expand All @@ -20,6 +22,7 @@ import { FirebaseServerService } from './services/firebase.server';
providers: [
{ provide: Aperture, useClass: ServerAperture},
{ provide: FirebaseService, useClass: FirebaseServerService },
{ provide: ResponseService, useClass: ServerResponseService }
]
})
export class AppServerModule { }
19 changes: 9 additions & 10 deletions src/app/components/atoms/infinite-scroll.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ export class InfiniteScrollDirective extends Autoclean implements AfterViewInit
}

ngAfterViewInit() {
this.autoclean(
this.aperture
.observableWindowEvent('scroll')
.map((e: Event) => new Snapshot((e.target as any).scrollingElement as Element))
.pairwise()
.filter((pair: Snapshot[]) => pair[0].scrollTop < pair[1].scrollTop)
.map((pair: Snapshot[]) => pair[1])
.filter((s: Snapshot) => 100 * (s.scrollTop + s.clientHeight) / s.scrollHeight > this.scrollPercent)
.subscribe(e => { this.onScroll.emit(''); })
);
this.aperture
.observableWindowEvent('scroll')
.map((e: Event) => new Snapshot((e.target as any).scrollingElement as Element))
.pairwise()
.filter((pair: Snapshot[]) => pair[0].scrollTop < pair[1].scrollTop)
.map((pair: Snapshot[]) => pair[1])
.filter((s: Snapshot) => 100 * (s.scrollTop + s.clientHeight) / s.scrollHeight > this.scrollPercent)
.subscribe(e => { this.onScroll.emit(''); })
.autoclean(this);
}
}
1 change: 0 additions & 1 deletion src/app/components/organisms/sermon-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class SermonListComponent implements OnInit {
}

addSermons(): void {
console.log('Add more sermons!');
this.pager.next();
}

Expand Down
7 changes: 5 additions & 2 deletions src/app/components/pages/admin/secured.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { FirebaseService } from '../../../services/firebase.service';
import { Observable } from '../../../services/observable';
import { Autoclean } from '../../templates/autoclean';

export abstract class Secured implements OnInit {
export abstract class Secured extends Autoclean implements OnInit {

constructor(
protected router: Router,
protected firebase: FirebaseService
) {}
) {
super();
}

ngOnInit(): void {
this.secure();
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/pages/admin/sermons.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h4>Add Another Sermon</h4>
<mat-form-field>
<input matInput #newSermonDate type="date" name="new_sermon_date" placeholder="Date of Service">
</mat-form-field>
<button class="add" mat-mini-fab (click)="addSermon(newSermonDate.value)" [disabled]="!!newSermonDate">
<button class="add" mat-mini-fab (click)="addSermon(newSermonDate.value)" [disabled]="!newSermonDate.value">
<mat-icon>add</mat-icon>
</button>
</div>
Expand Down
14 changes: 11 additions & 3 deletions src/app/components/pages/admin/sermons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class SermonsComponent extends Secured implements OnInit {
sermons: Sermon[];
images: SeriesImageForm[];
pager: PaginatedPager<Sermon>;
newSermonDate: string;

constructor(
router: Router,
Expand All @@ -37,16 +38,22 @@ export class SermonsComponent extends Secured implements OnInit {
if (authd) {
this.update();
}
});
})
.autoclean(this);
}

update(): void {
if (this.pager) {
this.pager.close();
}

this.pager = this.service.paginated();
this.pager
.observe()
.subscribe(sermons => {
this.sermons = sermons;
});
})
.autoclean(this);

this.imageService.listSeries()
.subscribe(images => {
Expand Down Expand Up @@ -74,7 +81,8 @@ export class SermonsComponent extends Secured implements OnInit {

saveSermon(sermon: Sermon): void {
this.service
.saveSermon(sermon);
.saveSermon(sermon)
.subscribe(() => this.update());
}

}
9 changes: 3 additions & 6 deletions src/app/components/pages/not-found.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { Component, OnInit } from '@angular/core';
import { Meta } from '@angular/platform-browser';
import { ResponseService } from '../../services';

@Component({
templateUrl: './not-found.html'
})
export class NotFoundComponent implements OnInit {

constructor(private meta: Meta) {}
constructor(private responseService: ResponseService) {}

ngOnInit() {
this.meta.addTag({
name: 'prerender-status-code',
content: '404'
});
this.responseService.setStatus(404, 'Not Found');
}
}
36 changes: 18 additions & 18 deletions src/app/components/pages/sermons/sermon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@ export class SermonComponent extends Autoclean implements OnInit {

ngOnInit() {
/* Subscribe to Video State Change Events */
this.autoclean(
this.youtubeService
.videoState('sermonVideo')
.subscribe((state) => {
this.videoState = state;
}));
this.youtubeService
.videoState('sermonVideo')
.subscribe((state) => {
this.videoState = state;
})
.autoclean(this);

/* Handle issues if youtube is having issues */
this.autoclean(
this.togglesService.getToggles()
.subscribe((toggles) => {
this.youtube_live_issues = !!toggles.youtube_live_issues;
}));
this.togglesService.getToggles()
.subscribe((toggles) => {
this.youtube_live_issues = !!toggles.youtube_live_issues;
})
.autoclean(this);

/* Record Analytics when Playing */
this.autoclean(
this.interval()
.subscribe(() => {
if (this.videoState === VideoState.PLAYING) {
this.analytics.event(this.live ? 'Live Sermon' : 'Sermon', 'Playing', this.sermon.youtube);
}
}));
this.interval()
.subscribe(() => {
if (this.videoState === VideoState.PLAYING) {
this.analytics.event(this.live ? 'Live Sermon' : 'Sermon', 'Playing', this.sermon.youtube);
}
})
.autoclean(this);

this.activatedRoute.params
.flatMap((params) => {
Expand Down
16 changes: 15 additions & 1 deletion src/app/components/templates/autoclean.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OnDestroy } from '@angular/core';
import { Subscription } from 'app/services';
import { Subscription } from 'rxjs/Subscription';

export abstract class Autoclean implements OnDestroy {

Expand All @@ -13,3 +13,17 @@ export abstract class Autoclean implements OnDestroy {
this.subscriptions.forEach(s => s.unsubscribe());
}
}

function autoclean(this: Subscription, cleaner: Autoclean): Subscription {
cleaner.autoclean(this);
return this;
}

/* tslint:disable */
declare module 'rxjs/Subscription' {
interface Subscription {
autoclean: typeof autoclean;
}
}

Subscription.prototype.autoclean = autoclean;
2 changes: 2 additions & 0 deletions src/app/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GlobalErrorHandler } from './error.hand
import { FirebaseService, FirebaseStorage, FirebaseDatabase } from './firebase.service';
import { Observable, Subscription } from './observable';
import { Pager, PaginatedPager, LinearPager } from './pager';
import { ResponseService } from './response.service';
import { SeriesImageForm, SeriesImageService } from './series.service';
import { SermonService, Sermon } from './sermon.service';
import { FeatureToggles, TogglesService } from './toggles.service';
Expand Down Expand Up @@ -40,6 +41,7 @@ export {
Observable,
Pager,
PaginatedPager,
ResponseService,
SeriesImageForm,
SeriesImageService,
Sermon,
Expand Down
7 changes: 6 additions & 1 deletion src/app/services/pager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ export abstract class Pager<T> {
});
}

close(): void {
this.observer.complete();
this.observer = undefined;
}

get length(): number {
return this.items.length;
return this.items ? this.items.length : 0;
}

get pages(): number {
Expand Down
11 changes: 11 additions & 0 deletions src/app/services/response.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Injectable } from '@angular/core';
import { ResponseService } from './response.service';

@Injectable()
export class BrowserResponseService extends ResponseService {

setStatus(code: number, message?: string): void {
console.error(`Setting HTTP Response Code [${code}: ${message}] not supported on browser`);
}

}
17 changes: 17 additions & 0 deletions src/app/services/response.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Injectable, Inject } from '@angular/core';
import { RESPONSE } from '@nguniversal/express-engine/tokens'
import * as express from 'express';
import { ResponseService } from './response.service';

@Injectable()
export class ServerResponseService extends ResponseService {

constructor( @Inject(RESPONSE) private response: express.Response ) {
super();
}

setStatus(code: number, message?: string): void {
this.response.sendStatus(code, message);
}

}
Loading

0 comments on commit c429902

Please sign in to comment.