Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
f1660aa2
Commit
f1660aa2
authored
Oct 25, 2018
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: updated backend srv to use appEvents and removed parts of alertsSrv
parent
f34cbae2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
105 deletions
+14
-105
public/app/core/components/grafana_app.ts
+0
-4
public/app/core/services/alert_srv.ts
+4
-92
public/app/core/services/backend_srv.ts
+7
-6
public/app/core/specs/backend_srv.test.ts
+1
-1
public/app/features/dashboard/upload.ts
+2
-2
No files found.
public/app/core/components/grafana_app.ts
View file @
f1660aa2
...
...
@@ -16,7 +16,6 @@ export class GrafanaCtrl {
/** @ngInject */
constructor
(
$scope
,
alertSrv
,
utilSrv
,
$rootScope
,
$controller
,
...
...
@@ -37,11 +36,8 @@ export class GrafanaCtrl {
$scope
.
_
=
_
;
profiler
.
init
(
config
,
$rootScope
);
alertSrv
.
init
();
utilSrv
.
init
();
bridgeSrv
.
init
();
$scope
.
dashAlerts
=
alertSrv
;
};
$rootScope
.
colors
=
colors
;
...
...
public/app/core/services/alert_srv.ts
View file @
f1660aa2
import
angular
from
'angular'
;
import
_
from
'lodash'
;
import
coreModule
from
'app/core/core_module'
;
import
appEvents
from
'app/core/app_events'
;
export
class
AlertSrv
{
list
:
any
[];
constructor
()
{}
/** @ngInject */
constructor
(
private
$timeout
,
private
$rootScope
)
{
this
.
list
=
[];
}
init
()
{
this
.
$rootScope
.
onAppEvent
(
'alert-error'
,
(
e
,
alert
)
=>
{
this
.
set
(
alert
[
0
],
alert
[
1
],
'error'
,
12000
);
},
this
.
$rootScope
);
this
.
$rootScope
.
onAppEvent
(
'alert-warning'
,
(
e
,
alert
)
=>
{
this
.
set
(
alert
[
0
],
alert
[
1
],
'warning'
,
5000
);
},
this
.
$rootScope
);
this
.
$rootScope
.
onAppEvent
(
'alert-success'
,
(
e
,
alert
)
=>
{
this
.
set
(
alert
[
0
],
alert
[
1
],
'success'
,
3000
);
},
this
.
$rootScope
);
appEvents
.
on
(
'alert-warning'
,
options
=>
this
.
set
(
options
[
0
],
options
[
1
],
'warning'
,
5000
));
appEvents
.
on
(
'alert-success'
,
options
=>
this
.
set
(
options
[
0
],
options
[
1
],
'success'
,
3000
));
appEvents
.
on
(
'alert-error'
,
options
=>
this
.
set
(
options
[
0
],
options
[
1
],
'error'
,
7000
));
}
getIconForSeverity
(
severity
)
{
switch
(
severity
)
{
case
'success'
:
return
'fa fa-check'
;
case
'error'
:
return
'fa fa-exclamation-triangle'
;
default
:
return
'fa fa-exclamation'
;
}
}
set
(
title
,
text
,
severity
,
timeout
)
{
if
(
_
.
isObject
(
text
))
{
console
.
log
(
'alert error'
,
text
);
if
(
text
.
statusText
)
{
text
=
`HTTP Error (
${
text
.
status
}
)
${
text
.
statusText
}
`
;
}
}
const
newAlert
=
{
title
:
title
||
''
,
text
:
text
||
''
,
severity
:
severity
||
'info'
,
icon
:
this
.
getIconForSeverity
(
severity
),
};
const
newAlertJson
=
angular
.
toJson
(
newAlert
);
// remove same alert if it already exists
_
.
remove
(
this
.
list
,
value
=>
{
return
angular
.
toJson
(
value
)
===
newAlertJson
;
});
this
.
list
.
push
(
newAlert
);
if
(
timeout
>
0
)
{
this
.
$timeout
(()
=>
{
this
.
list
=
_
.
without
(
this
.
list
,
newAlert
);
},
timeout
);
}
if
(
!
this
.
$rootScope
.
$$phase
)
{
this
.
$rootScope
.
$digest
();
}
return
newAlert
;
}
clear
(
alert
)
{
this
.
list
=
_
.
without
(
this
.
list
,
alert
);
}
clearAll
()
{
this
.
list
=
[];
set
()
{
console
.
log
(
'old depricated alert srv being used'
);
}
}
// this is just added to not break old plugins that might be using it
coreModule
.
service
(
'alertSrv'
,
AlertSrv
);
public/app/core/services/backend_srv.ts
View file @
f1660aa2
...
...
@@ -9,7 +9,7 @@ export class BackendSrv {
private
noBackendCache
:
boolean
;
/** @ngInject */
constructor
(
private
$http
,
private
alertSrv
,
private
$q
,
private
$timeout
,
private
contextSrv
)
{}
constructor
(
private
$http
,
private
$q
,
private
$timeout
,
private
contextSrv
)
{}
get
(
url
,
params
?)
{
return
this
.
request
({
method
:
'GET'
,
url
:
url
,
params
:
params
});
...
...
@@ -49,14 +49,14 @@ export class BackendSrv {
}
if
(
err
.
status
===
422
)
{
this
.
alertSrv
.
set
(
'Validation failed'
,
data
.
message
,
'warning'
,
4000
);
appEvents
.
emit
(
'alert-warning'
,
[
'Validation failed'
,
data
.
message
]
);
throw
data
;
}
data
.
severity
=
'error'
;
let
severity
=
'error'
;
if
(
err
.
status
<
500
)
{
data
.
severity
=
'warning'
;
severity
=
'warning'
;
}
if
(
data
.
message
)
{
...
...
@@ -66,7 +66,8 @@ export class BackendSrv {
description
=
message
;
message
=
'Error'
;
}
this
.
alertSrv
.
set
(
message
,
description
,
data
.
severity
,
10000
);
appEvents
.
emit
(
'alert-'
+
severity
,
[
message
,
description
]);
}
throw
data
;
...
...
@@ -93,7 +94,7 @@ export class BackendSrv {
if
(
options
.
method
!==
'GET'
)
{
if
(
results
&&
results
.
data
.
message
)
{
if
(
options
.
showSuccessAlert
!==
false
)
{
this
.
alertSrv
.
set
(
results
.
data
.
message
,
''
,
'success'
,
3000
);
appEvents
.
emit
(
'alert-success'
,
[
results
.
data
.
message
]
);
}
}
}
...
...
public/app/core/specs/backend_srv.test.ts
View file @
f1660aa2
...
...
@@ -9,7 +9,7 @@ describe('backend_srv', () => {
return
Promise
.
resolve
({});
};
const
_backendSrv
=
new
BackendSrv
(
_httpBackend
,
{},
{},
{}
,
{}
);
const
_backendSrv
=
new
BackendSrv
(
_httpBackend
,
{},
{},
{});
describe
(
'when handling errors'
,
()
=>
{
it
(
'should return the http status code'
,
async
()
=>
{
...
...
public/app/features/dashboard/upload.ts
View file @
f1660aa2
...
...
@@ -11,7 +11,7 @@ const template = `
`
;
/** @ngInject */
function
uploadDashboardDirective
(
timer
,
alertSrv
,
$location
)
{
function
uploadDashboardDirective
(
timer
,
$location
)
{
return
{
restrict
:
'E'
,
template
:
template
,
...
...
@@ -59,7 +59,7 @@ function uploadDashboardDirective(timer, alertSrv, $location) {
// Something
elem
[
0
].
addEventListener
(
'change'
,
file_selected
,
false
);
}
else
{
a
lertSrv
.
set
(
'Oops'
,
'Sorry, the HTML5 File APIs are not fully supported in this browser.'
,
'error'
);
a
ppEvents
.
emit
(
'alert-error'
,
[
'Oops'
,
'The HTML5 File APIs are not fully supported in this browser'
]
);
}
},
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment