mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* WIP: intial commit * Tests: Runs e2e tests * Refactor: Adds BASE_URL support * Refactor: Adds namespacing * Refactor: Cleans up the Page api * Build: Adds to build-branches-and-prs job for testing * Build: Hardcoded image for now * Refactor: Uses Selectors in App * Refactor: Adds addDataSource flow * WIP * Refactor: Adds e2eScenario * Refactor: Adds add and delete scenarios * Refactor: Adds logging * Refactor: Adds ability to for Selectors with variables * Refactor: Using variable selectors instead * Refactor: Adds flow until Share Panel * Refactor: Adds clicking on rendered image link * Refactor: Deletes log output * Refactor: Updates snapshots * Chore: Reverts changes * Refactor: Removes log plugin because maybe it breaks yarn build * Refactor: Adds rendered image download * Refactor: Adds image comparison * Refactor: Removes uncaught errors override * Refactor: Changes order of images to compare * Refactor: Updates truth image * Build: Updates path to CI artifacts * Refactor: Cleaning up types and config * wip * Refactor: Cleans up external api * Refactor: More cleanup * Refactor: More cleanup * Refactor: Removes usages of Pages and Flows * Refactor: Removes last traces of Cypress in spec * Refactor: Adds comments
138 lines
4.3 KiB
TypeScript
138 lines
4.3 KiB
TypeScript
import angular, { ILocationService } from 'angular';
|
|
import { dateTime } from '@grafana/data';
|
|
import { e2e } from '@grafana/e2e';
|
|
|
|
import config from 'app/core/config';
|
|
import { appendQueryToUrl, toUrlParams } from 'app/core/utils/url';
|
|
import { TimeSrv } from '../../services/TimeSrv';
|
|
import { TemplateSrv } from 'app/features/templating/template_srv';
|
|
import { LinkSrv } from 'app/features/panel/panellinks/link_srv';
|
|
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
|
|
|
|
/** @ngInject */
|
|
export function ShareModalCtrl(
|
|
$scope: any,
|
|
$rootScope: GrafanaRootScope,
|
|
$location: ILocationService,
|
|
$timeout: any,
|
|
timeSrv: TimeSrv,
|
|
templateSrv: TemplateSrv,
|
|
linkSrv: LinkSrv
|
|
) {
|
|
$scope.options = {
|
|
forCurrent: true,
|
|
includeTemplateVars: true,
|
|
theme: 'current',
|
|
};
|
|
$scope.editor = { index: $scope.tabIndex || 0 };
|
|
$scope.selectors = e2e.pages.SharePanelModal.selectors;
|
|
|
|
$scope.init = () => {
|
|
$scope.panel = $scope.model && $scope.model.panel ? $scope.model.panel : $scope.panel; // React pass panel and dashboard in the "model" property
|
|
$scope.dashboard = $scope.model && $scope.model.dashboard ? $scope.model.dashboard : $scope.dashboard; // ^
|
|
$scope.modeSharePanel = $scope.panel ? true : false;
|
|
|
|
$scope.tabs = [{ title: 'Link', src: 'shareLink.html' }];
|
|
|
|
if ($scope.modeSharePanel) {
|
|
$scope.modalTitle = 'Share Panel';
|
|
$scope.tabs.push({ title: 'Embed', src: 'shareEmbed.html' });
|
|
} else {
|
|
$scope.modalTitle = 'Share';
|
|
}
|
|
|
|
if (!$scope.dashboard.meta.isSnapshot) {
|
|
$scope.tabs.push({ title: 'Snapshot', src: 'shareSnapshot.html' });
|
|
}
|
|
|
|
if (!$scope.dashboard.meta.isSnapshot && !$scope.modeSharePanel) {
|
|
$scope.tabs.push({ title: 'Export', src: 'shareExport.html' });
|
|
}
|
|
|
|
$scope.buildUrl();
|
|
};
|
|
|
|
$scope.buildUrl = () => {
|
|
let baseUrl = $location.absUrl();
|
|
const queryStart = baseUrl.indexOf('?');
|
|
|
|
if (queryStart !== -1) {
|
|
baseUrl = baseUrl.substring(0, queryStart);
|
|
}
|
|
|
|
const params = angular.copy($location.search());
|
|
|
|
const range = timeSrv.timeRange();
|
|
params.from = range.from.valueOf();
|
|
params.to = range.to.valueOf();
|
|
params.orgId = config.bootData.user.orgId;
|
|
|
|
if ($scope.options.includeTemplateVars) {
|
|
templateSrv.fillVariableValuesForUrl(params);
|
|
}
|
|
|
|
if (!$scope.options.forCurrent) {
|
|
delete params.from;
|
|
delete params.to;
|
|
}
|
|
|
|
if ($scope.options.theme !== 'current') {
|
|
params.theme = $scope.options.theme;
|
|
}
|
|
|
|
if ($scope.modeSharePanel) {
|
|
params.panelId = $scope.panel.id;
|
|
params.fullscreen = true;
|
|
} else {
|
|
delete params.panelId;
|
|
delete params.fullscreen;
|
|
}
|
|
|
|
$scope.shareUrl = appendQueryToUrl(baseUrl, toUrlParams(params));
|
|
|
|
let soloUrl = baseUrl.replace(config.appSubUrl + '/dashboard/', config.appSubUrl + '/dashboard-solo/');
|
|
soloUrl = soloUrl.replace(config.appSubUrl + '/d/', config.appSubUrl + '/d-solo/');
|
|
delete params.fullscreen;
|
|
delete params.edit;
|
|
soloUrl = appendQueryToUrl(soloUrl, toUrlParams(params));
|
|
|
|
$scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
|
|
|
|
$scope.imageUrl = soloUrl.replace(
|
|
config.appSubUrl + '/dashboard-solo/',
|
|
config.appSubUrl + '/render/dashboard-solo/'
|
|
);
|
|
$scope.imageUrl = $scope.imageUrl.replace(config.appSubUrl + '/d-solo/', config.appSubUrl + '/render/d-solo/');
|
|
$scope.imageUrl += '&width=1000&height=500' + $scope.getLocalTimeZone();
|
|
};
|
|
|
|
// This function will try to return the proper full name of the local timezone
|
|
// Chrome does not handle the timezone offset (but phantomjs does)
|
|
$scope.getLocalTimeZone = () => {
|
|
const utcOffset = '&tz=UTC' + encodeURIComponent(dateTime().format('Z'));
|
|
|
|
// Older browser does not the internationalization API
|
|
if (!(window as any).Intl) {
|
|
return utcOffset;
|
|
}
|
|
|
|
const dateFormat = (window as any).Intl.DateTimeFormat();
|
|
if (!dateFormat.resolvedOptions) {
|
|
return utcOffset;
|
|
}
|
|
|
|
const options = dateFormat.resolvedOptions();
|
|
if (!options.timeZone) {
|
|
return utcOffset;
|
|
}
|
|
|
|
return '&tz=' + encodeURIComponent(options.timeZone);
|
|
};
|
|
|
|
$scope.getShareUrl = () => {
|
|
return $scope.shareUrl;
|
|
};
|
|
}
|
|
|
|
angular.module('grafana.controllers').controller('ShareModalCtrl', ShareModalCtrl);
|