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
e3488221
Commit
e3488221
authored
Sep 13, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'template_sort' of
https://github.com/mtanda/grafana
into mtanda-template_sort
parents
157ab1ba
8af3bb73
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
110 additions
and
3 deletions
+110
-3
public/app/features/templating/editorCtrl.js
+9
-0
public/app/features/templating/partials/editor.html
+11
-0
public/app/features/templating/templateValuesSrv.js
+26
-3
public/test/specs/templateValuesSrv-specs.js
+64
-0
No files found.
public/app/features/templating/editorCtrl.js
View file @
e3488221
...
...
@@ -13,6 +13,7 @@ function (angular, _) {
type
:
'query'
,
datasource
:
null
,
refresh
:
0
,
sort
:
1
,
name
:
''
,
hide
:
0
,
options
:
[],
...
...
@@ -34,6 +35,14 @@ function (angular, _) {
{
value
:
2
,
text
:
"On Time Range Change"
},
];
$scope
.
sortOptions
=
[
{
value
:
0
,
text
:
"Without Sort"
},
{
value
:
1
,
text
:
"Alphabetical (asc)"
},
{
value
:
2
,
text
:
"Alphabetical (desc)"
},
{
value
:
3
,
text
:
"Numerical (asc)"
},
{
value
:
4
,
text
:
"Numerical (desc)"
},
];
$scope
.
hideOptions
=
[
{
value
:
0
,
text
:
""
},
{
value
:
1
,
text
:
"Label"
},
...
...
public/app/features/templating/partials/editor.html
View file @
e3488221
...
...
@@ -181,6 +181,17 @@
<select
class=
"gf-form-input"
ng-model=
"current.refresh"
ng-options=
"f.value as f.text for f in refreshOptions"
></select>
</div>
</div>
<div
class=
"gf-form max-width-21"
>
<span
class=
"gf-form-label width-7"
>
Sort
<info-popover
mode=
"right-normal"
>
How to sort the values of this variable.
</info-popover>
</span>
<div
class=
"gf-form-select-wrapper max-width-14"
>
<select
class=
"gf-form-input"
ng-model=
"current.sort"
ng-options=
"f.value as f.text for f in sortOptions"
ng-change=
"runQuery()"
></select>
</div>
</div>
</div>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-7"
>
Query
</span>
...
...
public/app/features/templating/templateValuesSrv.js
View file @
e3488221
...
...
@@ -342,7 +342,7 @@ function (angular, _, $, kbn) {
this
.
metricNamesToVariableValues
=
function
(
variable
,
metricNames
)
{
var
regex
,
options
,
i
,
matches
;
options
=
{};
// use object hash to remove duplicates
options
=
[];
if
(
variable
.
regex
)
{
regex
=
kbn
.
stringToJsRegex
(
templateSrv
.
replace
(
variable
.
regex
));
...
...
@@ -370,10 +370,33 @@ function (angular, _, $, kbn) {
}
}
options
[
value
]
=
{
text
:
text
,
value
:
value
}
;
options
.
push
({
text
:
text
,
value
:
value
})
;
}
options
=
_
.
uniq
(
options
,
'value'
);
return
_
.
sortBy
(
options
,
'text'
);
if
(
variable
.
sort
===
0
)
{
return
options
;
}
var
sortType
=
Math
.
ceil
(
variable
.
sort
/
2
);
var
reverseSort
=
(
variable
.
sort
%
2
===
0
);
if
(
sortType
===
1
)
{
options
=
_
.
sortBy
(
options
,
'text'
);
}
else
if
(
sortType
===
2
)
{
options
=
_
.
sortBy
(
options
,
function
(
opt
)
{
var
matches
=
opt
.
text
.
match
(
/.*
?(\d
+
)
.*/
);
if
(
!
matches
)
{
return
0
;
}
else
{
return
parseInt
(
matches
[
1
],
10
);
}
});
}
if
(
reverseSort
)
{
options
=
options
.
reverse
();
}
return
options
;
};
this
.
addAllOption
=
function
(
variable
)
{
...
...
public/test/specs/templateValuesSrv-specs.js
View file @
e3488221
...
...
@@ -386,5 +386,69 @@ define([
});
});
describeUpdateVariable
(
'without sort'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
sort
:
0
};
scenario
.
queryResult
=
[{
text
:
'bbb2'
},
{
text
:
'aaa10'
},
{
text
:
'ccc3'
}];
});
it
(
'should return options without sort'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
text
).
to
.
be
(
'bbb2'
);
expect
(
scenario
.
variable
.
options
[
1
].
text
).
to
.
be
(
'aaa10'
);
expect
(
scenario
.
variable
.
options
[
2
].
text
).
to
.
be
(
'ccc3'
);
});
});
describeUpdateVariable
(
'with alphabetical sort (asc)'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
sort
:
1
};
scenario
.
queryResult
=
[{
text
:
'bbb2'
},
{
text
:
'aaa10'
},
{
text
:
'ccc3'
}];
});
it
(
'should return options with alphabetical sort'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
text
).
to
.
be
(
'aaa10'
);
expect
(
scenario
.
variable
.
options
[
1
].
text
).
to
.
be
(
'bbb2'
);
expect
(
scenario
.
variable
.
options
[
2
].
text
).
to
.
be
(
'ccc3'
);
});
});
describeUpdateVariable
(
'with alphabetical sort (desc)'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
sort
:
2
};
scenario
.
queryResult
=
[{
text
:
'bbb2'
},
{
text
:
'aaa10'
},
{
text
:
'ccc3'
}];
});
it
(
'should return options with alphabetical sort'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
text
).
to
.
be
(
'ccc3'
);
expect
(
scenario
.
variable
.
options
[
1
].
text
).
to
.
be
(
'bbb2'
);
expect
(
scenario
.
variable
.
options
[
2
].
text
).
to
.
be
(
'aaa10'
);
});
});
describeUpdateVariable
(
'with numerical sort (asc)'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
sort
:
3
};
scenario
.
queryResult
=
[{
text
:
'bbb2'
},
{
text
:
'aaa10'
},
{
text
:
'ccc3'
}];
});
it
(
'should return options with numerical sort'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
text
).
to
.
be
(
'bbb2'
);
expect
(
scenario
.
variable
.
options
[
1
].
text
).
to
.
be
(
'ccc3'
);
expect
(
scenario
.
variable
.
options
[
2
].
text
).
to
.
be
(
'aaa10'
);
});
});
describeUpdateVariable
(
'with numerical sort (desc)'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
sort
:
4
};
scenario
.
queryResult
=
[{
text
:
'bbb2'
},
{
text
:
'aaa10'
},
{
text
:
'ccc3'
}];
});
it
(
'should return options with numerical sort'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
text
).
to
.
be
(
'aaa10'
);
expect
(
scenario
.
variable
.
options
[
1
].
text
).
to
.
be
(
'ccc3'
);
expect
(
scenario
.
variable
.
options
[
2
].
text
).
to
.
be
(
'bbb2'
);
});
});
});
});
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