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
4b64c1d0
Commit
4b64c1d0
authored
Feb 03, 2018
by
Marcus Efraimsson
Committed by
Torkel Ödegaard
Feb 03, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix frontend validation for creating new folder and import dashboard (#10737)
Fixes #10731
parent
a0d8e96f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
10 deletions
+38
-10
public/app/features/dashboard/create_folder_ctrl.ts
+1
-1
public/app/features/dashboard/dashboard_import_ctrl.ts
+1
-1
public/app/features/dashboard/folder_picker/folder_picker.ts
+1
-1
public/app/features/dashboard/specs/dashboard_import_ctrl.jest.ts
+1
-1
public/app/features/dashboard/validation_srv.ts
+34
-6
No files found.
public/app/features/dashboard/create_folder_ctrl.ts
View file @
4b64c1d0
...
...
@@ -27,7 +27,7 @@ export class CreateFolderCtrl {
this
.
titleTouched
=
true
;
this
.
validationSrv
.
validateNew
DashboardOr
FolderName
(
this
.
title
)
.
validateNewFolderName
(
this
.
title
)
.
then
(()
=>
{
this
.
hasValidationError
=
false
;
})
...
...
public/app/features/dashboard/dashboard_import_ctrl.ts
View file @
4b64c1d0
...
...
@@ -93,7 +93,7 @@ export class DashboardImportCtrl {
this
.
nameExists
=
false
;
this
.
validationSrv
.
validateNewDashboard
OrFolderName
(
this
.
dash
.
title
)
.
validateNewDashboard
Name
(
0
,
this
.
dash
.
title
)
.
then
(()
=>
{
this
.
hasNameValidationError
=
false
;
})
...
...
public/app/features/dashboard/folder_picker/folder_picker.ts
View file @
4b64c1d0
...
...
@@ -67,7 +67,7 @@ export class FolderPickerCtrl {
this
.
newFolderNameTouched
=
true
;
this
.
validationSrv
.
validateNew
DashboardOr
FolderName
(
this
.
newFolderName
)
.
validateNewFolderName
(
this
.
newFolderName
)
.
then
(()
=>
{
this
.
hasValidationError
=
false
;
})
...
...
public/app/features/dashboard/specs/dashboard_import_ctrl.jest.ts
View file @
4b64c1d0
...
...
@@ -19,7 +19,7 @@ describe('DashboardImportCtrl', function() {
};
validationSrv
=
{
validateNewDashboard
OrFolder
Name
:
jest
.
fn
().
mockReturnValue
(
Promise
.
resolve
()),
validateNewDashboardName
:
jest
.
fn
().
mockReturnValue
(
Promise
.
resolve
()),
};
ctx
.
ctrl
=
new
DashboardImportCtrl
(
backendSrv
,
validationSrv
,
navModelSrv
,
{},
{},
{});
...
...
public/app/features/dashboard/validation_srv.ts
View file @
4b64c1d0
import
coreModule
from
'app/core/core_module'
;
const
hitTypes
=
{
FOLDER
:
'dash-folder'
,
DASHBOARD
:
'dash-db'
,
};
export
class
ValidationSrv
{
rootName
=
'general'
;
/** @ngInject */
constructor
(
private
$q
,
private
backendSrv
)
{}
validateNewDashboardOrFolderName
(
name
)
{
validateNewDashboardName
(
folderId
,
name
)
{
return
this
.
validate
(
folderId
,
name
,
'A dashboard in this folder with the same name already exists'
);
}
validateNewFolderName
(
name
)
{
return
this
.
validate
(
0
,
name
,
'A folder or dashboard in the general folder with the same name already exists'
);
}
private
validate
(
folderId
,
name
,
existingErrorMessage
)
{
name
=
(
name
||
''
).
trim
();
const
nameLowerCased
=
name
.
toLowerCase
();
if
(
name
.
length
===
0
)
{
return
this
.
$q
.
reject
({
...
...
@@ -16,7 +30,7 @@ export class ValidationSrv {
});
}
if
(
name
.
toLowerCase
()
===
this
.
rootName
)
{
if
(
folderId
===
0
&&
nameLowerCased
===
this
.
rootName
)
{
return
this
.
$q
.
reject
({
type
:
'EXISTING'
,
message
:
'This is a reserved name and cannot be used for a folder.'
,
...
...
@@ -25,12 +39,26 @@ export class ValidationSrv {
let
deferred
=
this
.
$q
.
defer
();
this
.
backendSrv
.
search
({
query
:
name
}).
then
(
res
=>
{
for
(
let
hit
of
res
)
{
if
(
name
.
toLowerCase
()
===
hit
.
title
.
toLowerCase
())
{
const
promises
=
[];
promises
.
push
(
this
.
backendSrv
.
search
({
type
:
hitTypes
.
FOLDER
,
folderIds
:
[
folderId
],
query
:
name
}));
promises
.
push
(
this
.
backendSrv
.
search
({
type
:
hitTypes
.
DASHBOARD
,
folderIds
:
[
folderId
],
query
:
name
}));
this
.
$q
.
all
(
promises
).
then
(
res
=>
{
let
hits
=
[];
if
(
res
.
length
>
0
&&
res
[
0
].
length
>
0
)
{
hits
=
res
[
0
];
}
if
(
res
.
length
>
1
&&
res
[
1
].
length
>
0
)
{
hits
=
hits
.
concat
(
res
[
1
]);
}
for
(
let
hit
of
hits
)
{
if
(
nameLowerCased
===
hit
.
title
.
toLowerCase
())
{
deferred
.
reject
({
type
:
'EXISTING'
,
message
:
'A folder or dashboard with the same name already exists'
,
message
:
existingErrorMessage
,
});
break
;
}
...
...
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