editor.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <div ng-controller="TemplateEditorCtrl" ng-init="init()">
  2. <div class="tabbed-view-header">
  3. <h2 class="tabbed-view-title">
  4. Templating
  5. </h2>
  6. <ul class="gf-tabs">
  7. <li class="gf-tabs-item" >
  8. <a class="gf-tabs-link" ng-click="mode = 'list';" ng-class="{active: mode === 'list'}">
  9. Variables
  10. </a>
  11. </li>
  12. <li class="gf-tabs-item" ng-show="mode === 'edit'">
  13. <a class="gf-tabs-link" ng-class="{active: mode === 'edit'}">
  14. Edit
  15. </a>
  16. </li>
  17. <li class="gf-tabs-item" ng-show="mode === 'new'">
  18. <span class="active gf-tabs-link">New</span>
  19. </li>
  20. </ul>
  21. <button class="tabbed-view-close-btn" ng-click="dismiss();dashboard.refresh();">
  22. <i class="fa fa-remove"></i>
  23. </button>
  24. </div>
  25. <div class="tabbed-view-body">
  26. <div ng-if="mode === 'list'">
  27. <div ng-if="variables.length === 0">
  28. <em>No template variables defined</em>
  29. </div>
  30. <table class="grafana-options-table">
  31. <tr ng-repeat="variable in variables">
  32. <td style="width: 1%">
  33. <span class="template-variable">
  34. ${{variable.name}}
  35. </span>
  36. </td>
  37. <td class="max-width" style="max-width: 200px;">
  38. {{variable.query}}
  39. </td>
  40. <td style="width: 1%"><i ng-click="_.move(variables,$index,$index-1)" ng-hide="$first" class="pointer fa fa-arrow-up"></i></td>
  41. <td style="width: 1%"><i ng-click="_.move(variables,$index,$index+1)" ng-hide="$last" class="pointer fa fa-arrow-down"></i></td>
  42. <td style="width: 1%">
  43. <a ng-click="duplicate(variable)" class="btn btn-inverse btn-mini">
  44. Duplicate
  45. </a>
  46. </td>
  47. <td style="width: 1%">
  48. <a ng-click="edit(variable)" class="btn btn-inverse btn-mini">
  49. <i class="fa fa-edit"></i>
  50. Edit
  51. </a>
  52. </td>
  53. <td style="width: 1%">
  54. <a ng-click="removeVariable(variable)" class="btn btn-danger btn-mini">
  55. <i class="fa fa-remove"></i>
  56. </a>
  57. </td>
  58. </tr>
  59. </table>
  60. </div>
  61. <div class="gf-form" ng-show="mode === 'list'">
  62. <div class="gf-form-button-row">
  63. <a type="button" class="btn gf-form-button btn-success" ng-click="mode = 'new';"><i class="fa fa-plus" ></i>&nbsp;&nbsp;New</a>
  64. </div>
  65. </div>
  66. <div ng-if="mode === 'edit' || mode === 'new'">
  67. <h5 class="section-heading">Variable</h5>
  68. <div class="gf-form-group">
  69. <div class="gf-form-inline">
  70. <div class="gf-form max-width-19">
  71. <span class="gf-form-label width-6">Name</span>
  72. <input type="text" class="gf-form-input" placeholder="name" ng-model='current.name'></input>
  73. </div>
  74. <div class="gf-form max-width-19">
  75. <span class="gf-form-label width-6">
  76. Type
  77. <info-popover mode="right-normal">
  78. <dl>
  79. <dt>Query</dt>
  80. <dd>Variable values are fetched from a metric names query to a data source</dd>
  81. <dt>Interval</dt>
  82. <dd>Timespan variable type</dd>
  83. <dt>Datasource</dt>
  84. <dd>Dynamically switch data sources using this type of variable</dd>
  85. <dt>Custom</dt>
  86. <dd>Define variable values manually</dd>
  87. </dl>
  88. <a href="http://docs.grafana.org/reference/templating" target="_blank">Templating docs</a>
  89. </info-popover>
  90. </span>
  91. <div class="gf-form-select-wrapper max-width-17">
  92. <select class="gf-form-input" ng-model="current.type" ng-options="f.value as f.text for f in variableTypes" ng-change="typeChanged()"></select>
  93. </div>
  94. </div>
  95. </div>
  96. <div class="gf-form-inline">
  97. <div class="gf-form max-width-19">
  98. <span class="gf-form-label width-6">Label</span>
  99. <input type="text" class="gf-form-input" ng-model='current.label' placeholder="optional display name"></input>
  100. </div>
  101. <div class="gf-form max-width-19">
  102. <span class="gf-form-label width-6">Hide</span>
  103. <div class="gf-form-select-wrapper max-width-15">
  104. <select class="gf-form-input" ng-model="current.hide" ng-options="f.value as f.text for f in hideOptions"></select>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. <div ng-show="current.type === 'interval'" class="gf-form-group">
  110. <h5 class="section-heading">Interval Options</h5>
  111. <div class="gf-form">
  112. <span class="gf-form-label width-9">Values</span>
  113. <input type="text" class="gf-form-input" placeholder="name" ng-model='current.query' placeholder="1m,10m,1h,6h,1d,7d" ng-model-onblur ng-change="runQuery()"></input>
  114. </div>
  115. <div class="gf-form">
  116. <span class="gf-form-label width-9">Auto option</span>
  117. <editor-checkbox text="Enable" model="current.auto" change="runQuery()"></editor-checkbox>
  118. </div>
  119. <div class="gf-form-inline">
  120. <div class="gf-form">
  121. <span class="gf-form-label width-9" ng-show="current.auto">
  122. Auto steps <tip>How many times should the current time range be divided to calculate the value</tip>
  123. </span>
  124. <div class="gf-form-select-wrapper max-width-10" ng-show="current.auto">
  125. <select class="gf-form-input" ng-model="current.auto_count" ng-options="f for f in [2,3,4,5,10,20,30,40,50,100,200,300,400,500]" ng-change="runQuery()"></select>
  126. </div>
  127. </div>
  128. <div class="gf-form">
  129. <span class="gf-form-label" ng-show="current.auto">
  130. Min interval <tip>The calculated value will not go below this threshold</tip>
  131. </span>
  132. <input type="text" class="gf-form-input max-width-10" ng-show="current.auto" ng-model="current.auto_min" ng-change="runQuery()" placeholder="10s"></input>
  133. </div>
  134. </div>
  135. </div>
  136. <div ng-show="current.type === 'custom'" class="gf-form-group">
  137. <h5 class="section-heading">Custom Options</h5>
  138. <div class="gf-form">
  139. <span class="gf-form-label width-13">Values seperated by comma</span>
  140. <input type="text" class="gf-form-input" ng-model='current.query' ng-blur="runQuery()" placeholder="1, 10, 20, myvalue"></input>
  141. </div>
  142. </div>
  143. <div ng-show="current.type === 'query'" class="gf-form-group">
  144. <h5 class="section-heading">Query Options</h5>
  145. <div class="gf-form-inline">
  146. <div class="gf-form max-width-21">
  147. <span class="gf-form-label width-7" ng-show="current.type === 'query'">Data source</span>
  148. <div class="gf-form-select-wrapper max-width-14">
  149. <select class="gf-form-input" ng-model="current.datasource" ng-options="f.value as f.name for f in datasources"></select>
  150. </div>
  151. </div>
  152. <div class="gf-form max-width-21">
  153. <span class="gf-form-label width-7">
  154. Refresh
  155. <info-popover mode="right-normal">
  156. When to update the values of this variable.
  157. </info-popover>
  158. </span>
  159. <div class="gf-form-select-wrapper max-width-14">
  160. <select class="gf-form-input" ng-model="current.refresh" ng-options="f.value as f.text for f in refreshOptions"></select>
  161. </div>
  162. </div>
  163. </div>
  164. <div class="gf-form">
  165. <span class="gf-form-label width-7">Query</span>
  166. <input type="text" class="gf-form-input" ng-model='current.query' placeholder="metric name or tags query" ng-model-onblur ng-change="runQuery()"></input>
  167. </div>
  168. <div class="gf-form">
  169. <span class="gf-form-label width-7">
  170. Regex
  171. <info-popover mode="right-normal">
  172. Optional, if you want to extract part of a series name or metric node segment.
  173. </info-popover>
  174. </span>
  175. <input type="text" class="gf-form-input" ng-model='current.regex' placeholder="/.*-(.*)-.*/" ng-model-onblur ng-change="runQuery()"></input>
  176. </div>
  177. </div>
  178. <div ng-show="current.type === 'datasource'" class="gf-form-group">
  179. <h5 class="section-heading">Data source options</h5>
  180. <div class="gf-form">
  181. <label class="gf-form-label width-12">Type</label>
  182. <div class="gf-form-select-wrapper max-width-18">
  183. <select class="gf-form-input" ng-model="current.query" ng-options="f.value as f.text for f in datasourceTypes" ng-change="runQuery()"></select>
  184. </div>
  185. </div>
  186. <div class="gf-form">
  187. <label class="gf-form-label width-12">
  188. Instance name filter
  189. <info-popover mode="right-normal">
  190. Regex filter for which data source instances to choose from in
  191. the variable value dropdown. Leave empty for all.
  192. <br><br>
  193. Example: <code>/^prod/</code>
  194. </info-popover>
  195. </label>
  196. <input type="text" class="gf-form-input max-width-18" ng-model='current.regex' placeholder="/.*-(.*)-.*/" ng-model-onblur ng-change="runQuery()"></input>
  197. </div>
  198. </div>
  199. <div class="section gf-form-group" ng-hide="current.type === 'datasource'">
  200. <h5 class="section-heading">Selection Options</h5>
  201. <div class="section">
  202. <gf-form-switch class="gf-form"
  203. label="Multi-value"
  204. label-class="width-10"
  205. tooltip="Enables multiple values to be selected at the same time"
  206. checked="current.multi"
  207. on-change="runQuery()">
  208. </gf-form-switch>
  209. <gf-form-switch class="gf-form"
  210. label="Include All option"
  211. label-class="width-10"
  212. checked="current.includeAll"
  213. on-change="runQuery()">
  214. </gf-form-switch>
  215. </div>
  216. <div class="gf-form" ng-if="current.includeAll">
  217. <span class="gf-form-label width-10">Custom all value</span>
  218. <input type="text" class="gf-form-input max-width-15" ng-model='current.allValue' placeholder="blank = auto"></input>
  219. </div>
  220. </div>
  221. <div class="gf-form-group" ng-if="current.type === 'query'">
  222. <h5>Value groups/tags (Experimental feature)</h5>
  223. <div class="gf-form">
  224. <editor-checkbox text="Enable" model="current.useTags" change="runQuery()"></editor-checkbox>
  225. </div>
  226. <div class="gf-form last" ng-if="current.useTags">
  227. <span class="gf-form-label width-10">Tags query</span>
  228. <input type="text" class="gf-form-input" ng-model='current.tagsQuery' placeholder="metric name or tags query" ng-model-onblur></input>
  229. </div>
  230. <div class="gf-form" ng-if="current.useTags">
  231. <li class="gf-form-label width-10">Tag values query</li>
  232. <input type="text" class="gf-form-input" ng-model='current.tagValuesQuery' placeholder="apps.$tag.*" ng-model-onblur></input>
  233. </div>
  234. </div>
  235. <div class="gf-form-group">
  236. <h5>Preview of values (shows max 20)</h5>
  237. <div class="gf-form-inline">
  238. <div class="gf-form" ng-repeat="option in current.options | limitTo: 20">
  239. <span class="gf-form-label">{{option.text}}</span>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. <div class="gf-form-button-row p-y-0">
  245. <button type="button" class="btn btn-success" ng-show="mode === 'edit'" ng-click="update();">Update</button>
  246. <button type="button" class="btn btn-success" ng-show="mode === 'new'" ng-click="add();">Add</button>
  247. </div>
  248. </div>
  249. </div>