mirror of https://github.com/grafana/grafana
parent
8574dca081
commit
dd0afd0a0b
@ -0,0 +1,41 @@ |
||||
import React, { FunctionComponent } from 'react'; |
||||
import { AppNotificationSeverity } from 'app/types'; |
||||
|
||||
interface Props { |
||||
title: string; |
||||
icon?: string; |
||||
text?: string; |
||||
severity: AppNotificationSeverity; |
||||
onClose?: () => void; |
||||
} |
||||
|
||||
function getIconFromSeverity(severity: AppNotificationSeverity): string { |
||||
switch (severity) { |
||||
case AppNotificationSeverity.Error: { |
||||
return 'fa fa-exclamation-triangle'; |
||||
} |
||||
case AppNotificationSeverity.Success: { |
||||
return 'fa fa-check'; |
||||
} |
||||
default: return null; |
||||
} |
||||
} |
||||
|
||||
export const AlertBox: FunctionComponent<Props> = ({ title, icon, text, severity, onClose }) => { |
||||
return ( |
||||
<div className={`alert alert-${severity}`}> |
||||
<div className="alert-icon"> |
||||
<i className={icon || getIconFromSeverity(severity)} /> |
||||
</div> |
||||
<div className="alert-body"> |
||||
<div className="alert-title">{title}</div> |
||||
{text && <div className="alert-text">{text}</div>} |
||||
</div> |
||||
{onClose && ( |
||||
<button type="button" className="alert-close" onClick={onClose}> |
||||
<i className="fa fa fa-remove" /> |
||||
</button> |
||||
)} |
||||
</div> |
||||
); |
||||
}; |
@ -0,0 +1,15 @@ |
||||
import _ from 'lodash'; |
||||
|
||||
export function getMessageFromError(err: any): string | null { |
||||
if (err && !_.isString(err)) { |
||||
if (err.message) { |
||||
return err.message; |
||||
} else if (err.data && err.data.message) { |
||||
return err.data.message; |
||||
} else { |
||||
return JSON.stringify(err); |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
@ -1,117 +0,0 @@ |
||||
import moment from 'moment'; |
||||
import angular from 'angular'; |
||||
import { appEvents, NavModel } from 'app/core/core'; |
||||
import { DashboardModel } from '../../state/DashboardModel'; |
||||
|
||||
export class DashNavCtrl { |
||||
dashboard: DashboardModel; |
||||
navModel: NavModel; |
||||
titleTooltip: string; |
||||
|
||||
/** @ngInject */ |
||||
constructor(private $scope, private dashboardSrv, private $location, public playlistSrv) { |
||||
if (this.dashboard.meta.isSnapshot) { |
||||
const meta = this.dashboard.meta; |
||||
this.titleTooltip = 'Created: ' + moment(meta.created).calendar(); |
||||
if (meta.expires) { |
||||
this.titleTooltip += '<br>Expires: ' + moment(meta.expires).fromNow() + '<br>'; |
||||
} |
||||
} |
||||
} |
||||
|
||||
toggleSettings() { |
||||
const search = this.$location.search(); |
||||
if (search.editview) { |
||||
delete search.editview; |
||||
} else { |
||||
search.editview = 'settings'; |
||||
} |
||||
this.$location.search(search); |
||||
} |
||||
|
||||
toggleViewMode() { |
||||
appEvents.emit('toggle-kiosk-mode'); |
||||
} |
||||
|
||||
close() { |
||||
const search = this.$location.search(); |
||||
if (search.editview) { |
||||
delete search.editview; |
||||
} else if (search.fullscreen) { |
||||
delete search.fullscreen; |
||||
delete search.edit; |
||||
delete search.tab; |
||||
delete search.panelId; |
||||
} |
||||
this.$location.search(search); |
||||
} |
||||
|
||||
starDashboard() { |
||||
this.dashboardSrv.starDashboard(this.dashboard.id, this.dashboard.meta.isStarred).then(newState => { |
||||
this.dashboard.meta.isStarred = newState; |
||||
}); |
||||
} |
||||
|
||||
shareDashboard(tabIndex) { |
||||
const modalScope = this.$scope.$new(); |
||||
modalScope.tabIndex = tabIndex; |
||||
modalScope.dashboard = this.dashboard; |
||||
|
||||
appEvents.emit('show-modal', { |
||||
src: 'public/app/features/dashboard/components/ShareModal/template.html', |
||||
scope: modalScope, |
||||
}); |
||||
} |
||||
|
||||
hideTooltip(evt) { |
||||
angular.element(evt.currentTarget).tooltip('hide'); |
||||
} |
||||
|
||||
saveDashboard() { |
||||
return this.dashboardSrv.saveDashboard(); |
||||
} |
||||
|
||||
showSearch() { |
||||
if (this.dashboard.meta.fullscreen) { |
||||
this.close(); |
||||
return; |
||||
} |
||||
|
||||
appEvents.emit('show-dash-search'); |
||||
} |
||||
|
||||
addPanel() { |
||||
appEvents.emit('dash-scroll', { animate: true, evt: 0 }); |
||||
|
||||
if (this.dashboard.panels.length > 0 && this.dashboard.panels[0].type === 'add-panel') { |
||||
return; // Return if the "Add panel" exists already
|
||||
} |
||||
|
||||
this.dashboard.addPanel({ |
||||
type: 'add-panel', |
||||
gridPos: { x: 0, y: 0, w: 12, h: 8 }, |
||||
title: 'Panel Title', |
||||
}); |
||||
} |
||||
|
||||
navItemClicked(navItem, evt) { |
||||
if (navItem.clickHandler) { |
||||
navItem.clickHandler(); |
||||
evt.preventDefault(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
export function dashNavDirective() { |
||||
return { |
||||
restrict: 'E', |
||||
templateUrl: 'public/app/features/dashboard/components/DashNav/template.html', |
||||
controller: DashNavCtrl, |
||||
bindToController: true, |
||||
controllerAs: 'ctrl', |
||||
transclude: true, |
||||
scope: { dashboard: '=' }, |
||||
}; |
||||
} |
||||
|
||||
angular.module('grafana.directives').directive('dashnav', dashNavDirective); |
@ -1,3 +1,2 @@ |
||||
export { DashNavCtrl } from './DashNavCtrl'; |
||||
import DashNav from './DashNav'; |
||||
export { DashNav }; |
||||
|
Loading…
Reference in new issue