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
7a39578f
Commit
7a39578f
authored
Jun 15, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use gf-form-dropdown in user picker
parent
e63fa9c8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
49 deletions
+16
-49
public/app/core/components/user_picker.ts
+16
-49
No files found.
public/app/core/components/user_picker.ts
View file @
7a39578f
...
@@ -4,74 +4,41 @@ import _ from 'lodash';
...
@@ -4,74 +4,41 @@ import _ from 'lodash';
const
template
=
`
const
template
=
`
<div class="dropdown">
<div class="dropdown">
<metric-segment segment="ctrl.userSegment"
<gf-form-dropdown model="ctrl.user"
get-options="ctrl.debouncedSearchUsers($query)"
get-options="ctrl.debouncedSearchUsers($query)"
on-change="ctrl.onChange()"></metric-segment>
css-class="gf-size-auto"
</div>
on-change="ctrl.onChange()"
</gf-form-dropdown>
</div>
`
;
`
;
export
class
UserPickerCtrl
{
export
class
UserPickerCtrl
{
userSegment
:
any
;
user
:
any
;
userLogin
:
string
;
userId
:
number
;
userId
:
number
;
debouncedSearchUsers
:
any
;
debouncedSearchUsers
:
any
;
/** @ngInject */
/** @ngInject */
constructor
(
private
backendSrv
,
private
$scope
,
$sce
,
private
uiSegmentSrv
)
{
constructor
(
private
backendSrv
,
private
$scope
,
$sce
)
{
this
.
user
=
{
text
:
'Choose'
,
value
:
null
};
this
.
debouncedSearchUsers
=
_
.
debounce
(
this
.
searchUsers
,
500
,
{
'leading'
:
true
,
'trailing'
:
false
});
this
.
debouncedSearchUsers
=
_
.
debounce
(
this
.
searchUsers
,
500
,
{
'leading'
:
true
,
'trailing'
:
false
});
this
.
resetUserSegment
();
}
resetUserSegment
()
{
this
.
userId
=
null
;
const
userSegment
=
this
.
uiSegmentSrv
.
newSegment
({
value
:
'Choose'
,
selectMode
:
true
,
fake
:
true
,
cssClass
:
'gf-size-auto'
});
if
(
!
this
.
userSegment
)
{
this
.
userSegment
=
userSegment
;
}
else
{
this
.
userSegment
.
value
=
userSegment
.
value
;
this
.
userSegment
.
html
=
userSegment
.
html
;
this
.
userSegment
.
value
=
userSegment
.
value
;
}
}
}
searchUsers
(
query
:
string
)
{
searchUsers
(
query
:
string
)
{
return
Promise
.
resolve
(
this
.
backendSrv
.
get
(
'/api/users/search?perpage=10&page=1&query='
+
query
).
then
(
result
=>
{
return
Promise
.
resolve
(
this
.
backendSrv
.
get
(
'/api/users/search?perpage=10&page=1&query='
+
query
).
then
(
result
=>
{
return
_
.
map
(
result
.
users
,
this
.
userKey
.
bind
(
this
));
return
_
.
map
(
result
.
users
,
user
=>
{
return
{
text
:
user
.
login
+
' - '
+
user
.
email
,
value
:
user
.
id
};
});
}));
}));
}
}
onChange
()
{
onChange
()
{
this
.
userLogin
=
this
.
userSegment
.
value
.
split
(
' - '
)[
0
];
this
.
userId
=
this
.
user
.
value
;
this
.
backendSrv
.
get
(
'/api/users/search?perpage=10&page=1&query='
+
this
.
userLogin
)
.
then
(
result
=>
{
if
(
!
result
)
{
return
;
}
result
.
users
.
forEach
(
u
=>
{
if
(
u
.
login
===
this
.
userLogin
)
{
this
.
userId
=
u
.
id
;
}
});
});
}
}
userIdChanged
(
newVal
)
{
userIdChanged
()
{
if
(
!
newVa
l
)
{
if
(
this
.
userId
===
nul
l
)
{
this
.
resetUserSegment
()
;
this
.
user
=
{
text
:
'Choose'
,
value
:
null
}
;
}
}
}
}
private
userKey
(
user
:
User
)
{
return
this
.
uiSegmentSrv
.
newSegment
(
user
.
login
+
' - '
+
user
.
email
);
}
}
}
export
interface
User
{
export
interface
User
{
...
...
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