Skip to content

Commit

Permalink
Changed any ypes to actual types
Browse files Browse the repository at this point in the history
Made sure all types are set on the new layout classes.
  • Loading branch information
bgaddis56 committed Aug 28, 2018
1 parent fd1ea91 commit c08aca2
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 31 deletions.
31 changes: 31 additions & 0 deletions src/server/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
export interface kbn_server {
config: () => configObject;
}

export interface configObject {
get: (path: string) => ConfigEntry;
}

export interface ConfigEntry {
zoom: number;
viewport: ViewWidthHeight;
}

export interface ViewWidthHeight {
width: number;
height: number;
}

export interface ViewZoomWidthHeight {
zoom: number;
width: number;
height: number;
}
export interface ViewWidth {
width: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { pdf } from './pdf';
import { groupBy } from 'lodash';
import { oncePerServer } from '../../../../server/lib/once_per_server';
import { screenshotsObservableFactory } from './screenshots';
import { getLayoutFactory } from './layouts';
import { getlayout } from './layouts/layout_factory';

const getTimeRange = (urlScreenshots) => {
const grouped = groupBy(urlScreenshots.map(u => u.timeRange));
Expand All @@ -31,7 +31,6 @@ const formatDate = (date, timezone) => {
function generatePdfObservableFn(server) {
const screenshotsObservable = screenshotsObservableFactory(server);
const captureConcurrency = 1;
const getLayout = getLayoutFactory(server);

const urlScreenshotsObservable = (urls, headers, layout) => {
return Rx.from(urls).pipe(
Expand Down Expand Up @@ -68,7 +67,9 @@ function generatePdfObservableFn(server) {


return function generatePdfObservable(title, urls, browserTimezone, headers, layoutParams, logo) {
const layout = getLayout(layoutParams);

const layout = getlayout(server, layoutParams);

const screenshots$ = urlScreenshotsObservable(urls, headers, layout);

return screenshots$.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { kbn_server } from '../../../../../../../../src/server/index';

export class Layout {
public id: string = '';
public server: any;
public server: kbn_server;

constructor(id: string, server: any) {
constructor(id: string, server: kbn_server) {
this.id = id;
this.server = server;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { kbn_server } from '../../../../../../../../src/server/index';
import { LayoutTypes } from '../../../common/constants';
import { Layout } from './layout';
import { Optimizedlayout } from './optimized_layout';
Expand All @@ -21,7 +22,11 @@ interface Layoutparams {
};
}

export function getlayout(server: string, LayoutParamsin: Layoutparams, zoom: number = 2): Layout {
export function getlayout(
server: kbn_server,
LayoutParamsin: Layoutparams,
zoom: number = 2
): Layout {
if (LayoutParamsin && LayoutParamsin.id === LayoutTypes.PRESERVE_LAYOUT) {
return new Preservelayout(
server,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/
import path from 'path';
import {
ConfigEntry,
configObject,
kbn_server,
ViewWidth,
ViewWidthHeight,
ViewZoomWidthHeight,
} from '../../../../../../../../src/server/index';
import { Layout } from './layout';

type EvalArgs = any[];
Expand All @@ -20,7 +28,7 @@ interface BrowserClient {
}

export class Optimizedlayout extends Layout {
public groupCount = 2;
public groupCount: number = 2;

public selectors = {
screenshot: '[data-shared-item]',
Expand All @@ -30,44 +38,44 @@ export class Optimizedlayout extends Layout {
timefilterToAttribute: 'data-shared-timefilter-to',
};

constructor(server: string, id: string) {
constructor(server: kbn_server, id: string) {
super(id, server);
}

get config() {
get config(): configObject {
return this.server.config();
}

get captureConfig() {
get captureConfig(): ConfigEntry {
return this.config.get('xpack.reporting.capture');
}

public getCssOverridesPath() {
public getCssOverridesPath(): string {
return path.join(__dirname, 'print.css');
}

public getBrowserViewport() {
public getBrowserViewport(): ViewWidthHeight {
return this.captureConfig.viewport;
}

public getBrowserZoom() {
public getBrowserZoom(): number {
return this.captureConfig.zoom;
}

public getViewport(itemsCount: number) {
public getViewport(itemsCount: number): ViewZoomWidthHeight {
return {
zoom: this.captureConfig.zoom,
width: this.captureConfig.viewport.width,
height: this.captureConfig.viewport.height * itemsCount,
};
}

public async positionElements(browser: BrowserClient) {
const elementSize = {
public async positionElements(browser: BrowserClient): Promise<void> {
const elementSize: ViewWidthHeight = {
width: this.captureConfig.viewport.width / this.captureConfig.zoom,
height: this.captureConfig.viewport.height / this.captureConfig.zoom,
};
const evalOptions = {
const evalOptions: EvaluateOptions = {
fn: `function(selector, height, width) {
const visualizations = document.querySelectorAll(selector);
const visualizationsLength = visualizations.length;
Expand All @@ -90,17 +98,17 @@ export class Optimizedlayout extends Layout {
await browser.evaluate(evalOptions);
}

public getPdfImageSize() {
public getPdfImageSize(): ViewWidth {
return {
width: 500,
};
}

public getPdfPageOrientation() {
public getPdfPageOrientation(): string {
return 'portrait';
}

public getPdfPageSize() {
public getPdfPageSize(): string {
return 'A4';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
import path from 'path';
import {
kbn_server,
ViewWidthHeight,
ViewZoomWidthHeight,
} from '../../../../../../../../src/server/index';
import { Layout } from './layout';

interface Pagesizeparams {
Expand All @@ -16,7 +21,7 @@ interface Pagesizeparams {
}

export class Preservelayout extends Layout {
public groupCount = 1;
public groupCount: number = 1;

public selectors = {
screenshot: '[data-shared-items-container]',
Expand All @@ -30,56 +35,56 @@ export class Preservelayout extends Layout {
public width: number = 0;
public zoom: number = 0;

constructor(server: string, id: string, height: number, width: number, zoom: number) {
constructor(server: kbn_server, id: string, height: number, width: number, zoom: number) {
super(id, server);
this.height = height;
this.width = width;
this.zoom = zoom;
}

get scaledHeight() {
get scaledHeight(): number {
return this.height * this.zoom;
}

get scaledWidth() {
get scaledWidth(): number {
return this.width * this.zoom;
}

public getCssOverridesPath() {
public getCssOverridesPath(): string {
return path.join(__dirname, 'preserve_layout.css');
}

public getBrowserViewport() {
public getBrowserViewport(): ViewWidthHeight {
return {
height: this.scaledHeight,
width: this.scaledWidth,
};
}

public getBrowserZoom() {
public getBrowserZoom(): number {
return this.zoom;
}

public getViewport() {
public getViewport(): ViewZoomWidthHeight {
return {
height: this.scaledHeight,
width: this.scaledWidth,
zoom: this.zoom,
};
}

public getPdfImageSize() {
public getPdfImageSize(): ViewWidthHeight {
return {
height: this.height,
width: this.width,
};
}

public getPdfPageOrientation() {
public getPdfPageOrientation(): undefined {
return undefined;
}

public getPdfPageSize(pagesizeparams: Pagesizeparams) {
public getPdfPageSize(pagesizeparams: Pagesizeparams): ViewWidthHeight {
return {
height:
this.height +
Expand Down

0 comments on commit c08aca2

Please sign in to comment.