Commit cf33fdc3 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate version-data to TypeScript

parent 2e1a3939
/** import type { SegmentInfo } from '../../types/annotator';
* @typedef {import('../../types/annotator').SegmentInfo} SegmentInfo import type { Frame } from '../store/modules/frames';
* @typedef {import('../store/modules/frames').Frame} Frame
*/
/** type UserDetails = {
* @typedef UserDetails userid?: string | null;
* @prop {string|null} [userid] displayName?: string;
* @prop {string} [displayName] };
*/
export class VersionData { export class VersionData {
public version: string;
public userAgent: string;
public urls: string;
public fingerprint: string;
public account: string;
public timestamp: string;
public segment: string | undefined;
/** /**
* @param {UserDetails} userInfo * @param documentFrames - Metadata for connected frames.
* @param {Frame[]} documentFrames - Metadata for connected frames.
* If there are multiple frames, the "main" one should be listed first. * If there are multiple frames, the "main" one should be listed first.
* @param {Window} window_ - test seam * @param window_ - test seam
*/ */
constructor(userInfo, documentFrames, window_ = window) { constructor(
userInfo: UserDetails,
documentFrames: Frame[],
window_: Window = window
) {
const noValueString = 'N/A'; const noValueString = 'N/A';
let accountString = noValueString; let accountString = noValueString;
...@@ -38,7 +46,7 @@ export class VersionData { ...@@ -38,7 +46,7 @@ export class VersionData {
this.account = accountString; this.account = accountString;
this.timestamp = new Date().toString(); this.timestamp = new Date().toString();
const segmentInfo = documentFrames[0]?.segment; const segmentInfo: SegmentInfo | undefined = documentFrames[0]?.segment;
if (segmentInfo) { if (segmentInfo) {
const segmentFields = []; const segmentFields = [];
if (segmentInfo.cfi) { if (segmentInfo.cfi) {
...@@ -58,9 +66,9 @@ export class VersionData { ...@@ -58,9 +66,9 @@ export class VersionData {
* Return a single formatted string representing version data, suitable for * Return a single formatted string representing version data, suitable for
* copying to the clipboard. * copying to the clipboard.
* *
* @return {string} - Single, multiline string representing current version data * @return Single, multiline string representing current version data
*/ */
asFormattedString() { asFormattedString(): string {
return `Version: ${this.version} return `Version: ${this.version}
User Agent: ${this.userAgent} User Agent: ${this.userAgent}
URL: ${this.urls} URL: ${this.urls}
...@@ -74,9 +82,9 @@ Date: ${this.timestamp} ...@@ -74,9 +82,9 @@ Date: ${this.timestamp}
* Return a single, encoded URL string of version data suitable for use in * Return a single, encoded URL string of version data suitable for use in
* a querystring (as the value of a single parameter) * a querystring (as the value of a single parameter)
* *
* @return {string} - URI-encoded string * @return URI-encoded string
*/ */
asEncodedURLString() { asEncodedURLString(): string {
return encodeURIComponent(this.asFormattedString()); return encodeURIComponent(this.asFormattedString());
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment