editor.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <div ng-controller="VariableEditorCtrl" ng-init="init()">
  2. <div class="page-action-bar">
  3. <h3 class="dashboard-settings__header">
  4. <a ng-click="setMode('list')">Variables</a>
  5. <span ng-show="mode === 'new'">&gt; New</span>
  6. <span ng-show="mode === 'edit'">&gt; Edit</span>
  7. </h3>
  8. <div class="page-action-bar__spacer"></div>
  9. <a
  10. type="button"
  11. class="btn btn-primary"
  12. ng-click="setMode('new');"
  13. ng-if="variables.length > 0"
  14. ng-hide="mode === 'edit' || mode === 'new'">
  15. New
  16. </a>
  17. </div>
  18. <div ng-if="mode === 'list'">
  19. <div ng-if="variables.length === 0">
  20. <empty-list-cta
  21. on-click="setNewMode"
  22. title="emptyListCta.title"
  23. infoBox="emptyListCta.infoBox"
  24. infoBoxTitle="emptyListCta.infoBoxTitle"
  25. buttonTitle="emptyListCta.buttonTitle"
  26. buttonIcon="emptyListCta.buttonIcon"
  27. />
  28. </div>
  29. <div ng-if="variables.length">
  30. <table class="filter-table filter-table--hover">
  31. <thead>
  32. <tr>
  33. <th>Variable</th>
  34. <th>Definition</th>
  35. <th colspan="5"></th>
  36. </tr>
  37. </thead>
  38. <tbody>
  39. <tr ng-repeat="variable in variables">
  40. <td style="width: 1%">
  41. <span ng-click="edit(variable)" class="pointer template-variable"> ${{ variable.name }} </span>
  42. </td>
  43. <td style="max-width: 200px;" ng-click="edit(variable)" class="pointer max-width">
  44. {{ variable.definition ? variable.definition : variable.query }}
  45. </td>
  46. <td style="width: 1%">
  47. <i ng-click="_.move(variables,$index,$index-1)" ng-hide="$first" class="pointer fa fa-arrow-up"></i>
  48. </td>
  49. <td style="width: 1%">
  50. <i ng-click="_.move(variables,$index,$index+1)" ng-hide="$last" class="pointer fa fa-arrow-down"></i>
  51. </td>
  52. <td style="width: 1%">
  53. <a ng-click="duplicate(variable)" class="btn btn-inverse btn-small">
  54. Duplicate
  55. </a>
  56. </td>
  57. <td style="width: 1%">
  58. <a ng-click="removeVariable(variable)" class="btn btn-danger btn-small">
  59. <i class="fa fa-remove"></i>
  60. </a>
  61. </td>
  62. </tr>
  63. </tbody>
  64. </table>
  65. </div>
  66. </div>
  67. <form ng-if="mode === 'edit' || mode === 'new'" name="ctrl.form">
  68. <h5 class="section-heading">General</h5>
  69. <div class="gf-form-group">
  70. <div class="gf-form-inline">
  71. <div class="gf-form max-width-19">
  72. <span class="gf-form-label width-6">Name</span>
  73. <input
  74. type="text"
  75. class="gf-form-input"
  76. name="name"
  77. placeholder="name"
  78. ng-model="current.name"
  79. required
  80. ng-pattern="namePattern"
  81. />
  82. </div>
  83. <div class="gf-form max-width-19">
  84. <span class="gf-form-label width-6">
  85. Type
  86. <info-popover mode="right-normal">
  87. {{ variableTypes[current.type].description }}
  88. </info-popover>
  89. </span>
  90. <div class="gf-form-select-wrapper max-width-17">
  91. <select
  92. class="gf-form-input"
  93. ng-model="current.type"
  94. ng-options="k as v.name for (k, v) in variableTypes"
  95. ng-change="typeChanged()"
  96. ></select>
  97. </div>
  98. </div>
  99. </div>
  100. <div class="gf-form" ng-show="ctrl.form.name.$error.pattern">
  101. <span class="gf-form-label gf-form-label--error"
  102. >Template names cannot begin with '__', that's reserved for Grafana's global variables</span
  103. >
  104. </div>
  105. <div class="gf-form-inline">
  106. <div class="gf-form max-width-19">
  107. <span class="gf-form-label width-6">Label</span>
  108. <input type="text" class="gf-form-input" ng-model="current.label" placeholder="optional display name" />
  109. </div>
  110. <div class="gf-form max-width-19">
  111. <span class="gf-form-label width-6">Hide</span>
  112. <div class="gf-form-select-wrapper max-width-15">
  113. <select
  114. class="gf-form-input"
  115. ng-model="current.hide"
  116. ng-options="f.value as f.text for f in hideOptions"
  117. ></select>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. <div ng-if="current.type === 'interval'" class="gf-form-group">
  123. <h5 class="section-heading">Interval Options</h5>
  124. <div class="gf-form">
  125. <span class="gf-form-label width-9">Values</span>
  126. <input
  127. type="text"
  128. class="gf-form-input"
  129. ng-model="current.query"
  130. placeholder="1m,10m,1h,6h,1d,7d"
  131. ng-model-onblur
  132. ng-change="runQuery()"
  133. required
  134. />
  135. </div>
  136. <div class="gf-form-inline">
  137. <gf-form-switch
  138. class="gf-form"
  139. label="Auto Option"
  140. label-class="width-9"
  141. checked="current.auto"
  142. on-change="runQuery()"
  143. >
  144. </gf-form-switch>
  145. <div class="gf-form">
  146. <span class="gf-form-label width-9" ng-show="current.auto">
  147. Step count <tip>How many times should the current time range be divided to calculate the value</tip>
  148. </span>
  149. <div class="gf-form-select-wrapper max-width-10" ng-show="current.auto">
  150. <select
  151. class="gf-form-input"
  152. ng-model="current.auto_count"
  153. ng-options="f for f in [1,2,3,4,5,10,20,30,40,50,100,200,300,400,500]"
  154. ng-change="runQuery()"
  155. ></select>
  156. </div>
  157. </div>
  158. <div class="gf-form">
  159. <span class="gf-form-label" ng-show="current.auto">
  160. Min interval <tip>The calculated value will not go below this threshold</tip>
  161. </span>
  162. <input
  163. type="text"
  164. class="gf-form-input max-width-10"
  165. ng-show="current.auto"
  166. ng-model="current.auto_min"
  167. ng-change="runQuery()"
  168. placeholder="10s"
  169. />
  170. </div>
  171. </div>
  172. </div>
  173. <div ng-if="current.type === 'custom'" class="gf-form-group">
  174. <h5 class="section-heading">Custom Options</h5>
  175. <div class="gf-form">
  176. <span class="gf-form-label width-14">Values separated by comma</span>
  177. <input
  178. type="text"
  179. class="gf-form-input"
  180. ng-model="current.query"
  181. ng-blur="runQuery()"
  182. placeholder="1, 10, 20, myvalue, escaped\,value"
  183. required
  184. />
  185. </div>
  186. </div>
  187. <div ng-if="current.type === 'constant'" class="gf-form-group">
  188. <h5 class="section-heading">Constant options</h5>
  189. <div class="gf-form">
  190. <span class="gf-form-label">Value</span>
  191. <input
  192. type="text"
  193. class="gf-form-input"
  194. ng-model="current.query"
  195. ng-blur="runQuery()"
  196. placeholder="your metric prefix"
  197. />
  198. </div>
  199. </div>
  200. <div ng-if="current.type === 'textbox'" class="gf-form-group">
  201. <h5 class="section-heading">Text options</h5>
  202. <div class="gf-form">
  203. <span class="gf-form-label">Default value</span>
  204. <input
  205. type="text"
  206. class="gf-form-input"
  207. ng-model="current.query"
  208. ng-blur="runQuery()"
  209. placeholder="default value, if any"
  210. />
  211. </div>
  212. </div>
  213. <div ng-if="current.type === 'query'" class="gf-form-group">
  214. <h5 class="section-heading">Query Options</h5>
  215. <div class="gf-form-inline">
  216. <div class="gf-form max-width-21">
  217. <span class="gf-form-label width-10">Data source</span>
  218. <div class="gf-form-select-wrapper max-width-14">
  219. <select
  220. class="gf-form-input"
  221. ng-model="current.datasource"
  222. ng-options="f.value as f.name for f in datasources"
  223. ng-change="datasourceChanged()"
  224. required
  225. >
  226. <option value="" ng-if="false"></option>
  227. </select>
  228. </div>
  229. </div>
  230. <div class="gf-form max-width-22">
  231. <span class="gf-form-label width-10">
  232. Refresh
  233. <info-popover mode="right-normal">
  234. When to update the values of this variable.
  235. </info-popover>
  236. </span>
  237. <div class="gf-form-select-wrapper width-15">
  238. <select
  239. class="gf-form-input"
  240. ng-model="current.refresh"
  241. ng-options="f.value as f.text for f in refreshOptions"
  242. ></select>
  243. </div>
  244. </div>
  245. </div>
  246. <rebuild-on-change property="currentDatasource">
  247. <variable-query-editor-loader> </variable-query-editor-loader>
  248. </rebuild-on-change>
  249. <div class="gf-form">
  250. <span class="gf-form-label width-10">
  251. Regex
  252. <info-popover mode="right-normal">
  253. Optional, if you want to extract part of a series name or metric node segment.
  254. </info-popover>
  255. </span>
  256. <input
  257. type="text"
  258. class="gf-form-input"
  259. ng-model="current.regex"
  260. placeholder="/.*-(.*)-.*/"
  261. ng-model-onblur
  262. ng-change="runQuery()"
  263. />
  264. </div>
  265. <div class="gf-form max-width-21">
  266. <span class="gf-form-label width-10">
  267. Sort
  268. <info-popover mode="right-normal">
  269. How to sort the values of this variable.
  270. </info-popover>
  271. </span>
  272. <div class="gf-form-select-wrapper max-width-14">
  273. <select
  274. class="gf-form-input"
  275. ng-model="current.sort"
  276. ng-options="f.value as f.text for f in sortOptions"
  277. ng-change="runQuery()"
  278. ></select>
  279. </div>
  280. </div>
  281. </div>
  282. <div ng-show="current.type === 'datasource'" class="gf-form-group">
  283. <h5 class="section-heading">Data source options</h5>
  284. <div class="gf-form">
  285. <label class="gf-form-label width-12">Type</label>
  286. <div class="gf-form-select-wrapper max-width-18">
  287. <select
  288. class="gf-form-input"
  289. ng-model="current.query"
  290. ng-options="f.value as f.text for f in datasourceTypes"
  291. ng-change="runQuery()"
  292. ></select>
  293. </div>
  294. </div>
  295. <div class="gf-form">
  296. <label class="gf-form-label width-12">
  297. Instance name filter
  298. <info-popover mode="right-normal">
  299. Regex filter for which data source instances to choose from in the variable value dropdown. Leave empty for
  300. all.
  301. <br /><br />
  302. Example: <code>/^prod/</code>
  303. </info-popover>
  304. </label>
  305. <input
  306. type="text"
  307. class="gf-form-input max-width-18"
  308. ng-model="current.regex"
  309. placeholder="/.*-(.*)-.*/"
  310. ng-model-onblur
  311. ng-change="runQuery()"
  312. />
  313. </div>
  314. </div>
  315. <div ng-if="current.type === 'adhoc'" class="gf-form-group">
  316. <h5 class="section-heading">Options</h5>
  317. <div class="gf-form max-width-21">
  318. <span class="gf-form-label width-8">Data source</span>
  319. <div class="gf-form-select-wrapper max-width-14">
  320. <select
  321. class="gf-form-input"
  322. ng-model="current.datasource"
  323. ng-options="f.value as f.name for f in datasources"
  324. required
  325. ng-change="validate()"
  326. >
  327. <option value="" ng-if="false"></option>
  328. </select>
  329. </div>
  330. </div>
  331. </div>
  332. <div class="section gf-form-group" ng-show="variableTypes[current.type].supportsMulti">
  333. <h5 class="section-heading">Selection Options</h5>
  334. <div class="section">
  335. <gf-form-switch
  336. class="gf-form"
  337. label="Multi-value"
  338. label-class="width-10"
  339. tooltip="Enables multiple values to be selected at the same time"
  340. checked="current.multi"
  341. on-change="runQuery()"
  342. >
  343. </gf-form-switch>
  344. <gf-form-switch
  345. class="gf-form"
  346. label="Include All option"
  347. label-class="width-10"
  348. checked="current.includeAll"
  349. on-change="runQuery()"
  350. >
  351. </gf-form-switch>
  352. </div>
  353. <div class="gf-form" ng-if="current.includeAll">
  354. <span class="gf-form-label width-10">Custom all value</span>
  355. <input type="text" class="gf-form-input max-width-15" ng-model="current.allValue" placeholder="blank = auto" />
  356. </div>
  357. </div>
  358. <div class="gf-form-group" ng-if="current.type === 'query'">
  359. <h5>Value groups/tags (Experimental feature)</h5>
  360. <gf-form-switch
  361. class="gf-form"
  362. label="Enabled"
  363. label-class="width-10"
  364. checked="current.useTags"
  365. on-change="runQuery()"
  366. >
  367. </gf-form-switch>
  368. <div class="gf-form last" ng-if="current.useTags">
  369. <span class="gf-form-label width-10">Tags query</span>
  370. <input
  371. type="text"
  372. class="gf-form-input"
  373. ng-model="current.tagsQuery"
  374. placeholder="metric name or tags query"
  375. ng-model-onblur
  376. />
  377. </div>
  378. <div class="gf-form" ng-if="current.useTags">
  379. <li class="gf-form-label width-10">Tag values query</li>
  380. <input
  381. type="text"
  382. class="gf-form-input"
  383. ng-model="current.tagValuesQuery"
  384. placeholder="apps.$tag.*"
  385. ng-model-onblur
  386. />
  387. </div>
  388. </div>
  389. <div class="gf-form-group" ng-show="current.options.length">
  390. <h5>Preview of values</h5>
  391. <div class="gf-form-inline">
  392. <div class="gf-form" ng-repeat="option in current.options | limitTo: optionsLimit">
  393. <span class="gf-form-label">{{ option.text }}</span>
  394. </div>
  395. <div class="gf-form" ng-if="current.options.length > optionsLimit">
  396. <a class="gf-form-label btn-secondary" ng-click="showMoreOptions()">Show more</a>
  397. </div>
  398. </div>
  399. </div>
  400. <div class="alert alert-info gf-form-group" ng-if="infoText">
  401. {{ infoText }}
  402. </div>
  403. <div class="gf-form-button-row p-y-0">
  404. <button type="submit" class="btn btn-primary" ng-show="mode === 'edit'" ng-click="update();">Update</button>
  405. <button type="submit" class="btn btn-primary" ng-show="mode === 'new'" ng-click="add();">Add</button>
  406. </div>
  407. </form>
  408. </div>