Skip to content

Commit 45c6233

Browse files
authored
Merge pull request #47 from icefoganalytics/caleb/dev-site-print-add-photos
injecting photos into handlebars template
2 parents 3933c71 + 062c2b2 commit 45c6233

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

api/services/place/print-site-service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isNil, isString } from 'lodash';
1+
import { isNil, isString, isUndefined } from 'lodash';
22
import fs from 'fs';
33
import { create } from 'handlebars';
44
import knex from 'knex';
@@ -22,9 +22,11 @@ import {
2222
SITE_STATUS_TYPES,
2323
WEB_LINK_TYPES,
2424
} from '../../models';
25+
import { PhotoService } from '../photo-service';
2526
import BaseService from '../base-service';
2627

2728
const db = knex(DB_CONFIG);
29+
const photoService = new PhotoService(DB_CONFIG);
2830

2931
export class PrintSiteService extends BaseService {
3032
constructor(
@@ -54,6 +56,7 @@ export class PrintSiteService extends BaseService {
5456
const template = h.compile(PDF_TEMPLATE.toString(), {});
5557

5658
const {
59+
id: placeId,
5760
primaryName,
5861
names,
5962
historicalPatterns,
@@ -179,6 +182,18 @@ export class PrintSiteService extends BaseService {
179182
secondaryStatuteHandlebarData = await this.makeStatuteHandlebarData(this.place.statute2Id);
180183
}
181184

185+
let photos: any[] = [];
186+
if (includePhotosSection && !isUndefined(placeId)) {
187+
photos = await photoService.getAllForPlace(placeId);
188+
}
189+
//console.log(photos[0]);
190+
const photosWithDataUris = photos
191+
.filter((photo) => photo.ThumbFile && Buffer.isBuffer(photo.ThumbFile))
192+
.map((photo) => ({
193+
...photo,
194+
dataUri: `data:image/jpeg;base64,${photo.ThumbFile.toString('base64')}`,
195+
}));
196+
182197
const handlebarsData = {
183198
includeSummarySection,
184199
includeLocationSection,
@@ -266,6 +281,7 @@ export class PrintSiteService extends BaseService {
266281
statute: statuteHandlebarData,
267282
secondaryStatute: secondaryStatuteHandlebarData,
268283
descriptions: descriptionsHandlebarData,
284+
photos: photosWithDataUris,
269285
};
270286

271287
return template(handlebarsData);

api/templates/places/placePrint.handlebars

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,21 @@
472472
<h1>Photos</h1>
473473
<hr />
474474
<table class='infoTable' border='0' cellspacing='0' cellpadding='0'>
475-
<tr>
476-
<td>
477-
</td>
478-
</tr>
475+
{{#each photos}}
476+
<tr>
477+
<td>
478+
<img src='{{dataUri}}' style='border: 1px solid black;' />
479+
</td>
480+
</tr>
481+
<tr>
482+
<td>
483+
<strong>File Name</strong><div class='box'>{{originalFileName}}</div>
484+
<strong>Feature Name</strong><div class='box'>{{featureName}}</div>
485+
<strong>Date Created</strong><div class='box'>{{dateCreated}}</div>
486+
<strong>Date Photo Taken</strong><div class='box'>{{datePhotoTaken}}</div>
487+
</td>
488+
</tr>
489+
{{/each}}
479490
</table>
480491
</div>
481492
{{/if}}

0 commit comments

Comments
 (0)