From dca0eeb6a6f9be66c124cdd9a598020ed0325c06 Mon Sep 17 00:00:00 2001 From: minottic Date: Thu, 21 Sep 2023 17:54:11 +0200 Subject: [PATCH] Add timestamp to exported snippets Should close: #232 --- .../unit/service.export-snippet.unit.ts | 27 ++++++++++--------- .../src/services/export-snippets.service.ts | 12 +++++++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/sci-log-db/src/__tests__/unit/service.export-snippet.unit.ts b/sci-log-db/src/__tests__/unit/service.export-snippet.unit.ts index 172deef0..b2c1cb30 100644 --- a/sci-log-db/src/__tests__/unit/service.export-snippet.unit.ts +++ b/sci-log-db/src/__tests__/unit/service.export-snippet.unit.ts @@ -14,23 +14,24 @@ describe('Export service unit', function (this: Suite) { let textElement: Element; let exportService: ExportService; const textcontent = ''; + const date = new Date(2023, 3, 13, 11, 13, 15); const subsnippets = [ new Paragraph({ linkType: LinkType.COMMENT, textcontent: '

a comment

', - updatedAt: new Date(2023, 3, 13), + updatedAt: date, updatedBy: 'test', }), new Paragraph({ linkType: LinkType.QUOTE, textcontent: '

a quote

', - updatedAt: new Date(2023, 3, 13), + updatedAt: date, updatedBy: 'test', }), new Paragraph({ linkType: LinkType.PARAGRAPH, textcontent: '

a paragraph sub

', - updatedAt: new Date(2023, 3, 13), + updatedAt: date, updatedBy: 'test', }), ]; @@ -42,7 +43,7 @@ describe('Export service unit', function (this: Suite) { {fileHash: '789', accessHash: 'ghi'}, ], tags: ['tag1', 'tag2'], - updatedAt: new Date(2023, 3, 13), + updatedAt: date, updatedBy: 'test', linkType: LinkType.PARAGRAPH, }); @@ -100,10 +101,10 @@ describe('Export service unit', function (this: Suite) { textElement, ); expect(dateAndAuthor.innerHTML).to.be.eql( - `1 / 13 Apr 2023 / test${textcontent}`, + `1 / 13 Apr 2023, 11:13:15 / test${textcontent}`, ); expect(dateAndAuthor.outerHTML).to.be.eql( - `
1 / 13 Apr 2023 / test${textcontent}
`, + `
1 / 13 Apr 2023, 11:13:15 / test${textcontent}
`, ); }); @@ -153,20 +154,22 @@ describe('Export service unit', function (this: Suite) { }); it('addTitle', () => { - sandbox.stub(Date.prototype, 'toLocaleDateString').returns('13 Apr 2023'); + sandbox + .stub(Date.prototype, 'toLocaleDateString') + .returns('13 Apr 2023, 11:13:15'); exportService['addTitle']('Some test'); expect(exportService.body.innerHTML).to.be.eql( - '

Some test: 13 Apr 2023


', + '

Some test: 13 Apr 2023, 11:13:15


', ); }); it('deep', () => { const deep = exportService['deep'](paragraph); expect(deep.innerHTML).to.be.eql( - '1 / 13 Apr 2023 / test
tag1tag2', + '1 / 13 Apr 2023, 11:13:15 / test
tag1tag2', ); expect(deep.outerHTML).to.be.eql( - '1 / 13 Apr 2023 / test
tag1tag2
', + '1 / 13 Apr 2023, 11:13:15 / test
tag1tag2
', ); }); @@ -185,8 +188,8 @@ describe('Export service unit', function (this: Suite) { }); const subsnippetTest = [ - '1 / 13 Apr 2023 / test
tag1tag2
1.1 / 13 Apr 2023 / test

a comment

1.2 / 13 Apr 2023 / test

a paragraph sub

', - '
1 / 13 Apr 2023 / test

a quote

tag1tag2
', + '1 / 13 Apr 2023, 11:13:15 / test
tag1tag2
1.1 / 13 Apr 2023, 11:13:15 / test

a comment

1.2 / 13 Apr 2023, 11:13:15 / test

a paragraph sub

', + '
1 / 13 Apr 2023, 11:13:15 / test

a quote

tag1tag2
', ]; subsnippetTest.forEach((t, i) => { it(`paragraphToHTML ${i}`, () => { diff --git a/sci-log-db/src/services/export-snippets.service.ts b/sci-log-db/src/services/export-snippets.service.ts index aaa0fd60..85b8e484 100644 --- a/sci-log-db/src/services/export-snippets.service.ts +++ b/sci-log-db/src/services/export-snippets.service.ts @@ -7,6 +7,7 @@ import {RestBindings, Server} from '@loopback/rest'; import PDFMerger from 'pdf-merger-js'; import Prism from 'prismjs'; import LoadLanguages from 'prismjs/components/'; +import {omit} from 'lodash'; @bind({ scope: BindingScope.TRANSIENT, @@ -17,7 +18,14 @@ export class ExportService { body: HTMLBodyElement; dateOptions = { locales: 'en-GB', - options: {year: 'numeric', month: 'short', day: 'numeric'} as const, + options: { + year: 'numeric', + month: 'short', + day: 'numeric', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + } as const, }; batchSize = 2000; paragraphCounter: number; @@ -171,7 +179,7 @@ export class ExportService { titleName ?? 'Scilog' }: ${new Date().toLocaleDateString( this.dateOptions.locales, - this.dateOptions.options, + omit(this.dateOptions.options, 'hour', 'minute', 'second'), )}`; this.body.append(title); const hr = this.document.createElement('hr');