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
1ddcaf5b
Commit
1ddcaf5b
authored
Dec 19, 2017
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor fixes and formatting after review
parent
0bfedfe4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
59 deletions
+65
-59
public/app/features/dashboard/folder_picker/folder_picker.html
+1
-2
public/app/features/dashboard/folder_picker/folder_picker.ts
+54
-45
public/app/features/dashboard/validation_srv.ts
+10
-12
No files found.
public/app/features/dashboard/folder_picker/folder_picker.html
View file @
1ddcaf5b
...
...
@@ -43,4 +43,4 @@
{{ctrl.validationError}}
</label>
</div>
</div>
\ No newline at end of file
</div>
public/app/features/dashboard/folder_picker/folder_picker.ts
View file @
1ddcaf5b
///<reference path="../../../headers/common.d.ts" />
import
_
from
'lodash'
;
import
coreModule
from
'app/core/core_module'
;
import
appEvents
from
'app/core/app_events'
;
import
_
from
"lodash"
;
import
coreModule
from
"app/core/core_module"
;
import
appEvents
from
"app/core/app_events"
;
export
class
FolderPickerCtrl
{
initialTitle
:
string
;
...
...
@@ -14,7 +12,7 @@ export class FolderPickerCtrl {
enterFolderCreation
:
any
;
exitFolderCreation
:
any
;
enableCreateNew
:
boolean
;
rootName
=
'Root'
;
rootName
=
"Root"
;
folder
:
any
;
createNewFolder
:
boolean
;
newFolderName
:
string
;
...
...
@@ -34,24 +32,26 @@ export class FolderPickerCtrl {
getOptions
(
query
)
{
var
params
=
{
query
:
query
,
type
:
'dash-folder'
,
type
:
"dash-folder"
};
return
this
.
backendSrv
.
search
(
params
).
then
(
result
=>
{
if
(
query
===
''
||
query
.
toLowerCase
()
===
"r"
||
query
.
toLowerCase
()
===
"ro"
||
query
.
toLowerCase
()
===
"roo"
||
query
.
toLowerCase
()
===
"root"
)
{
result
.
unshift
({
title
:
this
.
rootName
,
id
:
0
});
if
(
query
===
""
||
query
.
toLowerCase
()
===
"r"
||
query
.
toLowerCase
()
===
"ro"
||
query
.
toLowerCase
()
===
"roo"
||
query
.
toLowerCase
()
===
"root"
)
{
result
.
unshift
({
title
:
this
.
rootName
,
id
:
0
});
}
if
(
this
.
enableCreateNew
&&
query
===
''
)
{
result
.
unshift
({
title
:
'-- New Folder --'
,
id
:
-
1
});
if
(
this
.
enableCreateNew
&&
query
===
""
)
{
result
.
unshift
({
title
:
"-- New Folder --"
,
id
:
-
1
});
}
return
_
.
map
(
result
,
item
=>
{
return
{
text
:
item
.
title
,
value
:
item
.
id
};
return
{
text
:
item
.
title
,
value
:
item
.
id
};
});
});
}
...
...
@@ -62,13 +62,14 @@ export class FolderPickerCtrl {
this
.
enterFolderCreation
();
return
;
}
this
.
onChange
({
$folder
:
{
id
:
option
.
value
,
title
:
option
.
text
}
});
this
.
onChange
({
$folder
:
{
id
:
option
.
value
,
title
:
option
.
text
}
});
}
newFolderNameChanged
()
{
this
.
newFolderNameTouched
=
true
;
this
.
validationSrv
.
validateNewDashboardOrFolderName
(
this
.
newFolderName
)
this
.
validationSrv
.
validateNewDashboardOrFolderName
(
this
.
newFolderName
)
.
then
(()
=>
{
this
.
hasValidationError
=
false
;
})
...
...
@@ -84,13 +85,18 @@ export class FolderPickerCtrl {
evt
.
preventDefault
();
}
return
this
.
backendSrv
.
createDashboardFolder
(
this
.
newFolderName
).
then
(
result
=>
{
appEvents
.
emit
(
'alert-success'
,
[
'Folder Created'
,
'OK'
]);
this
.
closeCreateFolder
();
this
.
folder
=
{
text
:
result
.
dashboard
.
title
,
value
:
result
.
dashboard
.
id
};
this
.
onFolderChange
(
this
.
folder
);
});
return
this
.
backendSrv
.
createDashboardFolder
(
this
.
newFolderName
)
.
then
(
result
=>
{
appEvents
.
emit
(
"alert-success"
,
[
"Folder Created"
,
"OK"
]);
this
.
closeCreateFolder
();
this
.
folder
=
{
text
:
result
.
dashboard
.
title
,
value
:
result
.
dashboard
.
id
};
this
.
onFolderChange
(
this
.
folder
);
});
}
cancelCreateFolder
(
evt
)
{
...
...
@@ -108,21 +114,21 @@ export class FolderPickerCtrl {
this
.
createNewFolder
=
false
;
this
.
hasValidationError
=
false
;
this
.
validationError
=
null
;
this
.
newFolderName
=
''
;
this
.
newFolderName
=
""
;
this
.
newFolderNameTouched
=
false
;
}
private
loadInitialValue
()
{
if
(
this
.
initialFolderId
&&
this
.
initialFolderId
>
0
)
{
this
.
getOptions
(
''
).
then
(
result
=>
{
this
.
folder
=
_
.
find
(
result
,
{
value
:
this
.
initialFolderId
});
this
.
getOptions
(
""
).
then
(
result
=>
{
this
.
folder
=
_
.
find
(
result
,
{
value
:
this
.
initialFolderId
});
this
.
onFolderLoad
();
});
}
else
{
if
(
this
.
initialTitle
)
{
this
.
folder
=
{
text
:
this
.
initialTitle
,
value
:
null
};
this
.
folder
=
{
text
:
this
.
initialTitle
,
value
:
null
};
}
else
{
this
.
folder
=
{
text
:
this
.
rootName
,
value
:
0
};
this
.
folder
=
{
text
:
this
.
rootName
,
value
:
0
};
}
this
.
onFolderLoad
();
...
...
@@ -131,31 +137,34 @@ export class FolderPickerCtrl {
private
onFolderLoad
()
{
if
(
this
.
onLoad
)
{
this
.
onLoad
({
$folder
:
{
id
:
this
.
folder
.
value
,
title
:
this
.
folder
.
text
}});
this
.
onLoad
({
$folder
:
{
id
:
this
.
folder
.
value
,
title
:
this
.
folder
.
text
}
});
}
}
}
export
function
folderPicker
()
{
return
{
restrict
:
'E'
,
templateUrl
:
'public/app/features/dashboard/folder_picker/folder_picker.html'
,
restrict
:
"E"
,
templateUrl
:
"public/app/features/dashboard/folder_picker/folder_picker.html"
,
controller
:
FolderPickerCtrl
,
bindToController
:
true
,
controllerAs
:
'ctrl'
,
controllerAs
:
"ctrl"
,
scope
:
{
initialTitle
:
'<'
,
initialFolderId
:
'<'
,
labelClass
:
'@'
,
rootName
:
'@'
,
onChange
:
'&'
,
onLoad
:
'&'
,
onCreateFolder
:
'&'
,
enterFolderCreation
:
'&'
,
exitFolderCreation
:
'&'
,
enableCreateNew
:
'@'
initialTitle
:
"<"
,
initialFolderId
:
"<"
,
labelClass
:
"@"
,
rootName
:
"@"
,
onChange
:
"&"
,
onLoad
:
"&"
,
onCreateFolder
:
"&"
,
enterFolderCreation
:
"&"
,
exitFolderCreation
:
"&"
,
enableCreateNew
:
"@"
}
};
}
coreModule
.
directive
(
'folderPicker'
,
folderPicker
);
coreModule
.
directive
(
"folderPicker"
,
folderPicker
);
public/app/features/dashboard/validation_srv.ts
View file @
1ddcaf5b
///<reference path="../../headers/common.d.ts" />
import
coreModule
from
'app/core/core_module'
;
import
coreModule
from
"app/core/core_module"
;
export
class
ValidationSrv
{
rootName
=
'root'
;
rootName
=
"root"
;
/** @ngInject */
constructor
(
private
$q
,
private
backendSrv
)
{}
validateNewDashboardOrFolderName
(
name
)
{
name
=
(
name
||
''
).
trim
();
name
=
(
name
||
""
).
trim
();
if
(
name
.
length
===
0
)
{
return
this
.
$q
.
reject
({
type
:
'REQUIRED'
,
message
:
'Name is required'
type
:
"REQUIRED"
,
message
:
"Name is required"
});
}
if
(
name
.
toLowerCase
()
===
this
.
rootName
)
{
return
this
.
$q
.
reject
({
type
:
'EXISTING'
,
message
:
'A folder or dashboard with the same name already exists'
type
:
"EXISTING"
,
message
:
"A folder or dashboard with the same name already exists"
});
}
...
...
@@ -31,8 +29,8 @@ export class ValidationSrv {
for
(
let
hit
of
res
)
{
if
(
name
.
toLowerCase
()
===
hit
.
title
.
toLowerCase
())
{
deferred
.
reject
({
type
:
'EXISTING'
,
message
:
'A folder or dashboard with the same name already exists'
type
:
"EXISTING"
,
message
:
"A folder or dashboard with the same name already exists"
});
break
;
}
...
...
@@ -45,4 +43,4 @@ export class ValidationSrv {
}
}
coreModule
.
service
(
'validationSrv'
,
ValidationSrv
);
coreModule
.
service
(
"validationSrv"
,
ValidationSrv
);
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