execute.mako 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947
  1. ## Licensed to Cloudera, Inc. under one
  2. ## or more contributor license agreements. See the NOTICE file
  3. ## distributed with this work for additional information
  4. ## regarding copyright ownership. Cloudera, Inc. licenses this file
  5. ## to you under the Apache License, Version 2.0 (the
  6. ## "License"); you may not use this file except in compliance
  7. ## with the License. You may obtain a copy of the License at
  8. ##
  9. ## http://www.apache.org/licenses/LICENSE-2.0
  10. ##
  11. ## Unless required by applicable law or agreed to in writing, software
  12. ## distributed under the License is distributed on an "AS IS" BASIS,
  13. ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ## See the License for the specific language governing permissions and
  15. ## limitations under the License.
  16. <%!
  17. from desktop.lib.django_util import extract_field_data
  18. from desktop.views import commonheader, commonfooter, commonshare, _ko
  19. from beeswax import conf as beeswax_conf
  20. from django.utils.translation import ugettext as _
  21. %>
  22. <%namespace name="comps" file="beeswax_components.mako" />
  23. <%namespace name="layout" file="layout.mako" />
  24. <%namespace name="dashboard" file="common_dashboard.mako" />
  25. <%namespace name="tableStats" file="/table_stats.mako" />
  26. <%namespace name="assist" file="/assist.mako" />
  27. ${ commonheader(_('Query'), app_name, user) | n,unicode }
  28. ${ layout.menubar(section='query') }
  29. <div id="temporaryPlaceholder"></div>
  30. <div id="beeswax-execute">
  31. <div id="query-editor" class="container-fluid hide section">
  32. <div class="panel-container">
  33. <div class="left-panel" id="navigator">
  34. <ul class="nav nav-tabs" style="margin-bottom: 0">
  35. <li class="active"><a href="#navigatorTab" data-toggle="tab" class="sidetab">${_('Assist')}</a></li>
  36. <li><a href="#settingsTab" data-toggle="tab" class="sidetab">${_('Settings')} <span data-bind="visible:design.settings.values().length + design.fileResources.values().length + design.functions.values().length > 0, text: design.settings.values().length + design.fileResources.values().length + design.functions.values().length" class="badge badge-info">12</span></a></li>
  37. % if app_name == 'impala':
  38. <li><a href="#sessionTab" data-toggle="tab" class="sidetab">${_('Session')}</a></li>
  39. % endif
  40. </ul>
  41. <div class="tab-content" style=" overflow: hidden;">
  42. <div class="tab-pane active" id="navigatorTab">
  43. <div class="card card-small card-tab" style="margin-bottom: 0;">
  44. <div class="card-body" style="margin-top: 0; height: 100%;">
  45. <div class="assist" data-bind="component: {
  46. name: 'assist-panel',
  47. params: {
  48. user: HIVE_AUTOCOMPLETE_USER,
  49. onlySql: true,
  50. sql: {
  51. sourceTypes: editorViewModel.sqlSourceTypes,
  52. activeSourceType: snippetType,
  53. navigationSettings: {
  54. openItem: false,
  55. showPreview: true,
  56. showStats: true
  57. }
  58. },
  59. visibleAssistPanels: ['sql']
  60. }
  61. }"></div>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="tab-pane" id="settingsTab">
  66. <div class="card card-small card-tab">
  67. <div class="card-body">
  68. <div id="advanced-settings">
  69. <form id="advancedSettingsForm" action="" method="POST" class="form form-horizontal">
  70. ${ csrf_token(request) | n,unicode }
  71. <ul class="nav nav-list" style="border: none; padding: 0;">
  72. <li class="nav-header">${_('settings')}</li>
  73. <li class="white paramContainer">
  74. <!-- ko foreach: design.settings.values -->
  75. <div class="param">
  76. <div class="remove">
  77. <button data-bind="click: $root.removeSetting.bind(this, $index())" type="button" class="btn btn-mini settingsDelete" title="${_('Delete this setting')}">x
  78. </button>
  79. </div>
  80. <div data-bind="css: {'error': $root.getSettingKeyErrors($index()).length > 0}" class="control-group">
  81. <label>${_('Key')}</label>
  82. <input data-bind="value: key" type="text" class="settingsField" autocomplete="off" placeholder="${ 'impala.resultset.cache.size' if app_name == 'impala' else 'mapred.reduce.tasks' }"/>
  83. </div>
  84. <div data-bind="css: {'error': $root.getSettingValueErrors($index()).length > 0}" class="control-group">
  85. <label>${_('Value')}</label>
  86. <input data-bind="value: value" type="text" class="settingValuesField" placeholder="${ '5000' if app_name == 'impala' else '1' }"/>
  87. </div>
  88. </div>
  89. <!-- /ko -->
  90. <div class="control-group">
  91. <a data-bind="click: function() { $root.addSetting('','') }" class="btn btn-mini paramAdd">${_('Add')}</a>
  92. </div>
  93. </li>
  94. <li class="nav-header
  95. % if app_name == 'impala':
  96. hide
  97. % endif
  98. ">
  99. ${_('File Resources')}
  100. </li>
  101. <li class="white paramContainer
  102. % if app_name == 'impala':
  103. hide
  104. % endif
  105. ">
  106. <!-- ko foreach: design.fileResources.values -->
  107. <div class="param">
  108. <div class="remove">
  109. <button data-bind="click: $root.removeFileResource.bind(this, $index())" type="button" class="btn btn-mini" title="${_('Delete this setting')}">&times;</button>
  110. </div>
  111. <div data-bind="css: {'error': $root.getFileResourceTypeErrors($index()).length > 0}" class="control-group">
  112. <label>${_('Type')}</label>
  113. <select data-bind="value: type" class="input-small">
  114. <option value="JAR">${_('jar')}</option>
  115. <option value="ARCHIVE">${_('archive')}</option>
  116. <option value="FILE">${_('file')}</option>
  117. </select>
  118. </div>
  119. <div data-bind="css: {'error': $root.getFileResourcePathErrors($index()).length > 0}" class="control-group">
  120. <label>${_('Path')}</label>
  121. <input data-bind="value: path" type="text" class="filesField fileChooser" placeholder="/user/foo/udf.jar"/>
  122. </div>
  123. </div>
  124. <!-- /ko -->
  125. <div class="control-group">
  126. <a data-bind="click: function() { $root.addFileResource('','') }" class="btn btn-mini paramAdd">${_('Add')}</a>
  127. </div>
  128. </li>
  129. <li title="${ _('User-Defined Functions') }" class="nav-header
  130. % if app_name == 'impala':
  131. hide
  132. % endif
  133. ">
  134. ${_('UDFs')}
  135. </li>
  136. <li class="white paramContainer
  137. % if app_name == 'impala':
  138. hide
  139. % endif
  140. ">
  141. <!-- ko foreach: design.functions.values -->
  142. <div class="param">
  143. <div class="remove">
  144. <button data-bind="click: $root.removeFunction.bind(this, $index())" type="button" class="btn btn-mini settingsDelete" title="${_('Delete this setting')}">&times;</button>
  145. </div>
  146. <div data-bind="css: {'error': $root.getFunctionNameErrors($index()).length > 0}" class="control-group">
  147. <label>${_('Name')}</label>
  148. <input data-bind="value: name" type="text" class="functionsField" autocomplete="off" placeholder="myFunction"/>
  149. </div>
  150. <div data-bind="css: {'error': $root.getFunctionClassNameErrors($index()).length > 0}" class="control-group">
  151. <label>${_('Class name')}</label>
  152. <input data-bind="value: class_name" type="text" class="classNamesField" placeholder="com.acme.example"/>
  153. </div>
  154. </div>
  155. <!-- /ko -->
  156. <div class="control-group">
  157. <a data-bind="click: function() { $root.addFunction('','') }" class="btn btn-mini paramAdd">${_('Add')}</a>
  158. </div>
  159. </li>
  160. <li class="nav-header">${_('Options')}</li>
  161. <li class="white" style="padding-top:0; padding-left:0">
  162. <label class="checkbox" rel="tooltip" data-original-title="${_("If checked (the default), you can include parameters like $parameter_name in your query, and users will be prompted for a value when the query is run.")}">
  163. <input data-bind="checked: design.isParameterized" type="checkbox"/>
  164. ${_("Enable parameterization")}
  165. </label>
  166. </li>
  167. % if app_name == 'impala':
  168. <li class="nav-header">
  169. ${_('Metastore Catalog')}
  170. </li>
  171. <li class="white" style="padding-top:0; padding-left:0">
  172. <div class="control-group">
  173. <span id="refresh-dyk">
  174. <i class="fa fa-refresh"></i>
  175. ${ _('Sync tables tips') }
  176. </span>
  177. <div id="refresh-content" class="hide">
  178. <ul style="text-align: left;">
  179. <li>"invalidate
  180. metadata" ${ _("invalidates the entire catalog metadata. All table metadata will be reloaded on the next access.") }</li>
  181. <li>"invalidate metadata
  182. &lt;table&gt;" ${ _("invalidates the metadata, load on the next access") }</li>
  183. <li>"refresh
  184. &lt;table&gt;" ${ _("refreshes the metadata immediately. It is a faster, incremental refresh.") }</li>
  185. </ul>
  186. </div>
  187. </div>
  188. </li>
  189. % endif
  190. </ul>
  191. </form>
  192. </div>
  193. </div>
  194. </div>
  195. </div>
  196. % if app_name == 'impala':
  197. <div class="tab-pane" id="sessionTab">
  198. <div class="card card-small card-tab">
  199. <div class="card-body">
  200. <!-- ko if: $root.fetchingImpalaSession() -->
  201. <div style="margin: 5px">
  202. <!--[if !IE]><!--><i class="fa fa-spinner fa-spin" style="font-size: 20px; color: #BBB"></i><!--<![endif]-->
  203. <!--[if IE]><img src="${ static('desktop/art/spinner.gif') }"/><![endif]-->
  204. </div>
  205. <!-- /ko -->
  206. <!-- ko ifnot: $root.fetchingImpalaSession() -->
  207. <!-- ko if: $root.impalaSessionLink() != '' -->
  208. <ul class="nav nav-list" style="border: none; padding: 0;">
  209. <li class="nav-header">${ _('address')}</li>
  210. </ul>
  211. <div style="margin: 2px">
  212. <a data-bind="attr: {'href': $root.impalaSessionLink()}" target="_blank"><span data-bind="text: $root.impalaSessionLink().replace(/^(https?):\/\//, '')"></span> <i class="fa fa-external-link"></i></a>
  213. </div>
  214. <!-- /ko -->
  215. <!-- ko if: $root.impalaSessionLink() == '' -->
  216. <div style="margin: 5px">
  217. ${ _("There's currently no valid session") }
  218. </div>
  219. <!-- /ko -->
  220. <!-- /ko -->
  221. </div>
  222. </div>
  223. </div>
  224. % endif
  225. </div>
  226. </div>
  227. <div class="resizer" data-bind="splitDraggable : { appName: '${app_name}', onPosition: onPanelPosition, leftPanelVisible: isEditor }"><div class="resize-bar"><i class="fa fa-ellipsis-v"></i></div></div>
  228. <div class="right-panel" id="querySide">
  229. <div class="alert" data-bind="visible: design.isRedacted">
  230. ${ _('This query had some sensitive information removed when saved.') }
  231. </div>
  232. <div id="queryContainer" class="card card-small">
  233. <div class="pull-right" style="margin: 10px">
  234. <i class="fa fa-question-circle" id="help"></i>
  235. <div id="help-content" class="hide">
  236. <ul style="text-align: left;">
  237. <li>${ _('Press CTRL + Space to autocomplete') }</li>
  238. <li>${ _("You can execute queries with multiple SQL statements delimited by a semicolon ';'") }</li>
  239. <li>${ _('You can highlight and run a fragment of a query') }</li>
  240. </ul>
  241. </div>
  242. </div>
  243. <div style="margin-bottom: 30px">
  244. % if can_edit_name:
  245. <h1 class="card-heading simple">
  246. <a class="share-link" rel="tooltip" data-placement="bottom" style="padding-left:10px; padding-right: 10px" data-bind="click: openShareModal,
  247. attr: {'data-original-title': '${ _ko("Share") } '+name},
  248. css: {'baseShared': true, 'isShared': isShared()}">
  249. <i class="fa fa-users"></i>
  250. </a>
  251. <a href="javascript:void(0);"
  252. id="query-name"
  253. data-type="text"
  254. data-name="name"
  255. data-value="${design.name}"
  256. data-original-title="${ _('Query name') }"
  257. data-placement="right">
  258. </a>
  259. <a href="javascript:void(0);"
  260. id="query-description"
  261. data-type="textarea"
  262. data-name="description"
  263. data-value="${design.desc}"
  264. data-original-title="${ _('Query description') }"
  265. data-placement="right" style="font-size: 14px; margin-left: 10px">
  266. </a>
  267. </h1>
  268. %endif
  269. </div>
  270. <div class="card-body">
  271. <div class="tab-content">
  272. <div id="queryPane">
  273. <div data-bind="css: {'hide': design.errors().length == 0 || design.inlineErrors().length > 0}" class="alert alert-error">
  274. <!-- ko if: $root.getQueryErrors().length > 0 -->
  275. <p><strong>${_('Please provide a query')}</strong></p>
  276. <!-- /ko -->
  277. <!-- ko if: $root.getQueryErrors().length == 0 -->
  278. <p><strong>${_('Your query has the following error(s):')}</strong></p>
  279. <div data-bind="foreach: design.errors">
  280. <p data-bind="text: $data" class="queryErrorMessage"></p>
  281. </div>
  282. <!-- /ko -->
  283. </div>
  284. <div data-bind="css: {'hide': design.watch.errors().length == 0 || design.watch.inlineErrors().length > 0}" class="alert alert-error">
  285. <p><strong>${_('Your query has the following error(s):')}</strong></p>
  286. <div data-bind="foreach: design.watch.errors">
  287. <p data-bind="text: $data" class="queryErrorMessage"></p>
  288. </div>
  289. </div>
  290. <textarea class="hide" tabindex="1" name="query" id="queryField"></textarea>
  291. <div class="actions">
  292. <button data-bind="click: tryExecuteQuery, visible: $root.canExecute, enable: $root.queryEditorBlank" type="button" id="executeQuery" class="btn btn-primary disable-feedback" tabindex="2">${_('Execute')}</button>
  293. <button data-bind="click: tryCancelQuery, visible: $root.design.isRunning()" class="btn btn-danger" data-loading-text="${ _('Canceling...') }" rel="tooltip" data-original-title="${ _('Cancel the query') }">${ _('Cancel') }</button>
  294. <button data-bind="click: tryExecuteNextStatement, visible: !$root.design.isFinished()" type="button" class="btn btn-primary disable-feedback" tabindex="2">${_('Next')}</button>
  295. <button data-bind="click: tryExecuteQuery, visible: !$root.design.isFinished()" type="button" id="executeQuery" class="btn btn-primary disable-feedback" tabindex="2">${_('Restart')}</button>
  296. % if can_edit:
  297. <button data-bind="click: trySaveDesign, css: {'hide': !$root.design.id() || $root.design.id() == -1}" type="button" class="btn hide">${_('Save')}</button>
  298. % endif
  299. <button data-bind="click: saveAsModal" type="button" class="btn">${_('Save as...')}</button>
  300. <button data-bind="click: tryExplainQuery, visible: $root.canExecute" type="button" id="explainQuery" class="btn">${_('Explain')}</button>
  301. <button data-bind="click: formatQuery" type="button" class="btn">${_('Format')}</button>
  302. &nbsp; ${_('or create a')} &nbsp;
  303. <button data-bind="click: createNewQuery" type="button" class="btn">${_('New query')}</button>
  304. <br/><br/>
  305. </div>
  306. </div>
  307. </div>
  308. </div>
  309. </div>
  310. <div id="resizePanel"><a href="javascript:void(0)"><i class="fa fa-ellipsis-h"></i></a></div>
  311. <div class="card card-small scrollable resultsContainer">
  312. <div class="query-right-actions" data-bind="visible: !design.explain()">
  313. <!-- ko if: $root.hasResults() -->
  314. <a id="expandResults" href="javascript:void(0)" title="${_('See results in full screen')}" rel="tooltip"
  315. class="view-query-results hide pull-right"><h4><i class="fa fa-expand"></i></h4></a>
  316. <a id="save-results" data-bind="click: saveResultsModal" href="javascript:void(0)" title="${_('Save the results to HDFS or a new Hive table')}" rel="tooltip"
  317. class="view-query-results hide pull-right"><h4><i class="fa fa-save"></i></h4>
  318. </a>
  319. <a id="download-csv" data-bind="attr: {'href': '/${ app_name }/download/' + $root.design.history.id() + '/csv'}" href="javascript:void(0)" title="${_('Download the results in CSV format')}" rel="tooltip"
  320. class="view-query-results download hide pull-right"><h4><i class="hfo hfo-file-csv"></i></h4>
  321. </a>
  322. <a id="download-excel" data-bind="attr: {'href': '/${ app_name }/download/' + $root.design.history.id() + '/xls'}" href="javascript:void(0)" title="${_('Download the results in XLS format')}" rel="tooltip"
  323. class="view-query-results download hide pull-right"><h4><i class="hfo hfo-file-xls"></i></h4></a>
  324. <!-- /ko -->
  325. <a href="#clearHistoryModal" title="${_('Clear the query history')}" rel="tooltip" class="clear-queries pull-right" data-toggle="modal"><h4><i class="fa fa-calendar-times-o"></i></h4></a>
  326. </div>
  327. <div class="card-body">
  328. <ul class="nav nav-tabs">
  329. <li class="active recentLi"><a href="#recentTab" data-toggle="tab">${_('Recent queries')}</a></li>
  330. <li><a href="#query" data-toggle="tab">${_('Query')}</a></li>
  331. <!-- ko if: !design.explain() -->
  332. <li><a href="#log" data-toggle="tab">${_('Log')}</a></li>
  333. <!-- /ko -->
  334. <!-- ko if: !design.explain() -->
  335. <li><a href="#columns" data-toggle="tab">${_('Columns')}</a></li>
  336. <li><a href="#results" data-toggle="tab">${_('Results')}</a></li>
  337. <li><a href="#chart" data-toggle="tab">${_('Chart')}</a></li>
  338. <!-- /ko -->
  339. <!-- ko if: design.explain() && !design.isRunning() -->
  340. <li><a href="#explanation" data-toggle="tab">${_('Explanation')}</a></li>
  341. <!-- /ko -->
  342. </ul>
  343. <div class="tab-content">
  344. <div class="active tab-pane" id="recentTab">
  345. <div id="recentLoader">
  346. <!--[if !IE]><!--><i class="fa fa-spinner fa-spin" style="font-size: 20px; color: #DDD"></i><!--<![endif]-->
  347. <!--[if IE]><img src="${ static('desktop/art/spinner.gif') }"/><![endif]-->
  348. </div>
  349. <table id="recentQueries" class="table table-striped table-condensed datatables" cellpadding="0" cellspacing="0" data-tablescroller-enforce-height="true">
  350. <thead>
  351. <tr>
  352. <th>${_('Time')}</th>
  353. <th>${_('Query')}</th>
  354. <th>${_('Result')}</th>
  355. <th>&nbsp;</th>
  356. </tr>
  357. </thead>
  358. <tbody>
  359. </tbody>
  360. </table>
  361. </div>
  362. <div class="tab-pane" id="query">
  363. <pre data-bind="visible: viewModel.design.statement() == ''">${_('There is currently no query to visualize.')}</pre>
  364. <pre data-bind="visible: viewModel.design.statement() != '', text: viewModel.design.statement()"></pre>
  365. </div>
  366. <!-- ko if: design.explain() -->
  367. <div class="tab-pane" id="explanation">
  368. <pre data-bind="text: $root.design.results.explanation()"></pre>
  369. </div>
  370. <!-- /ko -->
  371. <!-- ko if: !design.explain() -->
  372. <div class="tab-pane" id="log">
  373. <div style="position:relative">
  374. <ul data-bind="foreach: $root.design.watch.jobUrls" class="unstyled jobs-overlay">
  375. <li><a data-bind="text: $.trim($data.name), attr: { href: $data.url }" target="_blank"></a></li>
  376. </ul>
  377. <pre data-bind="visible: $root.design.watch.logs().length == 0">${_('There are currently no logs to visualize.')} <img src="${ static('desktop/art/spinner.gif') }" data-bind="visible: $root.design.isRunning()"/></pre>
  378. <pre data-bind="visible: $root.design.watch.logs().length > 0, text: $root.design.watch.logs().join('\n')"></pre>
  379. </div>
  380. </div>
  381. <div class="tab-pane" id="columns">
  382. <pre data-bind="visible: $root.design.results.columns().length == 0">${_('There are currently no columns to visualize.')}</pre>
  383. <div data-bind="visible: $root.design.results.columns().length > 10">
  384. <input id="columnFilter" class="input-xlarge" type="text" placeholder="${_('Filter for column name or type...')}" />
  385. </div>
  386. <table class="table table-striped table-condensed" cellpadding="0" cellspacing="0">
  387. <tbody data-bind="foreach: $root.design.results.columns">
  388. <tr class="columnRow" data-bind="visible: $index() > 0">
  389. <td rel="columntooltip" data-placement="left" data-bind="attr: {title: '${ _ko("Scroll to the column") }">
  390. <a href="javascript:void(0)" data-row-selector="true" class="column-selector" data-bind="text: $data.name"></a>
  391. </td>
  392. <td class="columnType" data-bind="text: $.trim($data.type)"></td>
  393. </tr>
  394. </tbody>
  395. </table>
  396. </div>
  397. <div class="tab-pane" id="results">
  398. <div data-bind="css: {'hide': design.results.errors().length == 0}" class="alert alert-error">
  399. <p><strong>${_('Fetching results ran into the following error(s):')}</strong></p>
  400. <div data-bind="foreach: design.results.errors">
  401. <p data-bind="text: $data" class="queryErrorMessage"></p>
  402. </div>
  403. </div>
  404. <div data-bind="css: {'hide': !$root.hasResults()}">
  405. <table id="resultTable" class="table table-striped table-condensed" cellpadding="0" cellspacing="0" data-tablescroller-enforce-height="true">
  406. <thead>
  407. <tr data-bind="foreach: $root.design.results.columns">
  408. <th data-bind="html: ($index() == 0 ? '&nbsp;' : $data.name), css: { 'sort-numeric': isNumericColumn($data.type), 'sort-date': isDateTimeColumn($data.type), 'sort-string': isStringColumn($data.type), 'datatables-counter-col': $index() == 0}"></th>
  409. </tr>
  410. </thead>
  411. </table>
  412. % if app_name == 'impala':
  413. <a class="pointer" data-bind="visible: $root.scrollNotWorking() && $root.hasMoreResults(), click: manualFetch" style="padding: 10px">${ _('Show more results...') }</a>
  414. % endif
  415. </div>
  416. <div data-bind="css: {'hide': !$root.design.results.empty() || $root.design.results.expired()}" id="resultEmpty">
  417. <pre>${_('The operation has no results.')}</pre>
  418. </div>
  419. <div data-bind="css: {'hide': !$root.design.results.expired()}" id="resultExpired">
  420. <pre>${_('The results have expired, rerun the query if needed.')}</pre>
  421. </div>
  422. </div>
  423. <div class="tab-pane" id="chart">
  424. <pre data-bind="visible: $root.design.results.empty() || $root.design.results.expired()">${_('There is currently no data to build a chart on.')}</pre>
  425. <div class="alert hide">
  426. <strong>${_('Warning:')}</strong> ${_('the results on the chart have been limited to 1000 rows.')}
  427. </div>
  428. <div data-bind="visible: ! $root.design.results.empty() && ! $root.design.results.expired()" style="text-align: center">
  429. <form class="form-inline">
  430. ${_('Chart type')}&nbsp;
  431. <div class="btn-group" data-toggle="buttons-radio">
  432. <a rel="tooltip" data-placement="top" title="${_('Bars')}" id="blueprintBars" href="javascript:void(0)" class="btn"><i class="hcha hcha-bar-chart"></i></a>
  433. <a rel="tooltip" data-placement="top" title="${_('Lines')}" id="blueprintLines" href="javascript:void(0)" class="btn"><i class="hcha hcha-line-chart"></i></a>
  434. <a rel="tooltip" data-placement="top" title="${_('Pie')}" id="blueprintPie" href="javascript:void(0)" class="btn"><i class="hcha hcha-pie-chart"></i></a>
  435. <a rel="tooltip" data-placement="top" title="${_('Map')}" id="blueprintMap" href="javascript:void(0)" class="btn"><i class="hcha hcha-map-chart"></i></a>
  436. </div>&nbsp;&nbsp;
  437. <span id="blueprintAxis" class="hide">
  438. <label>${_('X-Axis')}
  439. <select id="blueprintX" class="blueprintSelect"></select>
  440. </label>&nbsp;&nbsp;
  441. <label>${_('Y-Axis')}
  442. <select id="blueprintY" class="blueprintSelect"></select>
  443. </label>&nbsp;
  444. <div class="btn-group" data-toggle="buttons-radio">
  445. <a rel="tooltip" data-placement="top" title="${_('No sorting')}" id="blueprintNoSort" href="javascript:void(0)" class="btn active"><i class="fa fa-align-left fa-rotate-270"></i></a>
  446. <a rel="tooltip" data-placement="top" title="${_('Sort ascending')}" id="blueprintSortAsc" href="javascript:void(0)" class="btn"><i class="fa fa-sort-amount-asc fa-rotate-270"></i></a>
  447. <a rel="tooltip" data-placement="top" title="${_('Sort descending')}" id="blueprintSortDesc" href="javascript:void(0)" class="btn"><i class="fa fa-sort-amount-desc fa-rotate-270"></i></a>
  448. </div>&nbsp;&nbsp;
  449. </span>
  450. <span id="blueprintLatLng" class="hide">
  451. <label>${_('Latitude')}
  452. <select id="blueprintLat" class="blueprintSelect"></select>
  453. </label>&nbsp;&nbsp;
  454. <label>${_('Longitude')}
  455. <select id="blueprintLng" class="blueprintSelect"></select>
  456. </label>&nbsp;&nbsp;
  457. <label>${_('Label')}
  458. <select id="blueprintDesc" class="blueprintSelect"></select>
  459. </label>
  460. </span>
  461. </form>
  462. </div>
  463. <div data-bind="visible: ! $root.design.results.empty() && ! $root.design.results.expired()" id="blueprint" class="empty center">${_("Please select a chart type.")}</div>
  464. <div style="margin: 10px" data-bind="visible: ! $root.design.results.empty() && ! $root.design.results.expired()">
  465. <div id="pieChart" data-bind="pieChart: {data: {counts: $root.chartData}, fqs: ko.observableArray([]),
  466. transformer: pieChartDataTransformer,
  467. maxWidth: 350 }, visible: $root.chartType() == 'pie'"></div>
  468. <div id="barChart" data-bind="barChart: {datum: {counts: $root.chartData}, fqs: ko.observableArray([]), hideSelection: true,
  469. transformer: barChartDataTransformer}, visible: $root.chartType() == 'bars'"></div>
  470. <div id="lineChart" data-bind="lineChart: {datum: {counts: $root.chartData},
  471. transformer: lineChartDataTransformer,
  472. showControls: false }, visible: $root.chartType() == 'lines'"></div>
  473. <div id="leafletMapChart" data-bind="leafletMapChart: {datum: {counts: $root.chartData},
  474. transformer: leafletMapChartDataTransformer,
  475. showControls: false }, visible: $root.chartType() == 'map'"></div>
  476. </div>
  477. </div>
  478. <!-- /ko -->
  479. </div>
  480. </div>
  481. </div>
  482. </div>
  483. </div>
  484. </div>
  485. <div id="execute-parameter-selection" class="container-fluid hide section">
  486. <div class="row-fluid">
  487. <div class="card card-small">
  488. <h1 class="card-heading simple">${_('Please specify parameters for this query')}</h1>
  489. <div class="card-body">
  490. <p>
  491. <form method="POST" action="" class="form-horizontal">
  492. ${ csrf_token(request) | n,unicode }
  493. <fieldset>
  494. <!-- ko foreach: $root.design.parameters -->
  495. <div class="control-group">
  496. <label data-bind="text: name" class="control-label"></label>
  497. <div class="controls">
  498. <input data-bind="value: value, valueUpdate:'afterkeydown'" type="text"/>
  499. </div>
  500. </div>
  501. <!-- /ko -->
  502. <div class="form-actions" style="padding-left: 10px">
  503. <a class="btn" href="javascript:history.go(-1);">${_('Cancel')}</a>
  504. <button data-bind="enable: $root.hasParametersFilled, click: tryExecuteParameterizedQuery" type="button" class="btn btn-primary">${_('Execute query')}</button>
  505. </div>
  506. </fieldset>
  507. </form>
  508. </p>
  509. </div>
  510. </div>
  511. </div>
  512. </div>
  513. <div id="explain-parameter-selection" class="container-fluid hide section">
  514. <div class="row-fluid">
  515. <div class="card card-small">
  516. <h1 class="card-heading simple">${_('Please specify parameters for this query')}</h1>
  517. <div class="card-body">
  518. <p>
  519. <form method="POST" action="" class="form-horizontal">
  520. ${ csrf_token(request) | n,unicode }
  521. <fieldset>
  522. <!-- ko foreach: $root.design.parameters -->
  523. <div class="control-group">
  524. <label data-bind="text: name" class="control-label"></label>
  525. <div class="controls">
  526. <input data-bind="value: value, valueUpdate:'afterkeydown'" type="text"/>
  527. </div>
  528. </div>
  529. <!-- /ko -->
  530. <div class="form-actions" style="padding-left: 10px">
  531. <a class="btn" href="javascript:history.go(-1);">${_('Cancel')}</a>
  532. <button data-bind="enable: $root.hasParametersFilled, click: tryExplainParameterizedQuery" type="button" class="btn btn-primary">${_('Explain query')}</button>
  533. </div>
  534. </fieldset>
  535. </form>
  536. </p>
  537. </div>
  538. </div>
  539. </div>
  540. </div>
  541. <div id="chooseFile" class="modal hide fade">
  542. <div class="modal-header">
  543. <a href="#" class="close" data-dismiss="modal">&times;</a>
  544. <h3>${_('Choose a file')}</h3>
  545. </div>
  546. <div class="modal-body">
  547. <div id="filechooser">
  548. </div>
  549. </div>
  550. <div class="modal-footer">
  551. </div>
  552. </div>
  553. <div id="chooseFolder" class="modal hide fade">
  554. <div class="modal-header">
  555. <a href="#" class="close" data-dismiss="modal">&times;</a>
  556. <h3>${_('Select a directory')}</h3>
  557. </div>
  558. <div class="modal-body">
  559. <div id="folderchooser">
  560. </div>
  561. </div>
  562. <div class="modal-footer">
  563. </div>
  564. </div>
  565. <div id="choosePath" class="modal hide fade">
  566. <div class="modal-header">
  567. <a href="#" class="close" data-dismiss="modal">&times;</a>
  568. <h3>${_('Select a file or directory')}</h3>
  569. </div>
  570. <div class="modal-body">
  571. <div id="pathchooser">
  572. </div>
  573. </div>
  574. <div class="modal-footer">
  575. </div>
  576. </div>
  577. <div id="saveAs" class="modal hide fade">
  578. <div class="modal-header">
  579. <a href="#" class="close" data-dismiss="modal">&times;</a>
  580. <h3>${_('Choose a name')}</h3>
  581. </div>
  582. <form class="form-horizontal">
  583. <div class="control-group" id="saveas-query-name">
  584. <label class="control-label">${_('Name')}</label>
  585. <div class="controls">
  586. <input data-bind="value: $root.design.name, html" type="text" class="input-xlarge">
  587. <span class="help-inline"></span>
  588. </div>
  589. </div>
  590. <div class="control-group" id="saveas-query-description">
  591. <label class="control-label">${_('Description')}</label>
  592. <div class="controls">
  593. <input data-bind="value: $root.design.description, html" type="text" class="input-xlarge">
  594. <span class="help-inline"></span>
  595. </div>
  596. </div>
  597. </form>
  598. <div class="modal-footer">
  599. <button class="btn" data-dismiss="modal">${_('Cancel')}</button>
  600. <button data-bind="click: trySaveAsDesign" class="btn btn-primary">${_('Save')}</button>
  601. </div>
  602. </div>
  603. <div id="saveResultsModal" class="modal hide fade">
  604. <div class="loader">
  605. <div class="overlay"></div>
  606. <!--[if !IE]><!--><i class="fa fa-spinner fa-spin"></i><!--<![endif]-->
  607. <!--[if IE]><img class="spinner" src="${ static('desktop/art/spinner-big-inverted.gif') }"/><![endif]-->
  608. </div>
  609. <div class="modal-header">
  610. <a href="#" class="close" data-dismiss="modal">&times;</a>
  611. <h3>${_('Save Query Results')}</h3>
  612. </div>
  613. <div class="modal-body" style="padding: 4px">
  614. <!-- ko if: $root.design.results.save.saveTargetError() -->
  615. <h4 data-bind="text: $root.design.results.save.saveTargetError()"></h4>
  616. <!-- /ko -->
  617. <!-- ko if: $root.design.results.save.targetTableError() -->
  618. <h4 data-bind="text: $root.design.results.save.targetTableError()"></h4>
  619. <!-- /ko -->
  620. <!-- ko if: $root.design.results.save.targetDirectoryError() -->
  621. <h4 data-bind="text: $root.design.results.save.targetDirectoryError()"></h4>
  622. <!-- /ko -->
  623. <form id="saveResultsForm" method="POST" class="form form-inline">
  624. ${ csrf_token(request) | n,unicode }
  625. <fieldset>
  626. <div data-bind="css: {'error': $root.design.results.save.targetFileError()}" class="control-group">
  627. <div class="controls">
  628. <label class="radio">
  629. <input data-bind="checked: $root.design.results.save.type" type="radio" name="save-results-type" value="hdfs-file">
  630. &nbsp;${ _('In an HDFS file') }
  631. </label>
  632. <span data-bind="visible: $root.design.results.save.type() == 'hdfs-file'">
  633. <input data-bind="value: $root.design.results.save.path" type="text" name="target_file" placeholder="${_('Path to CSV file')}" class="pathChooser">
  634. </span>
  635. <label class="radio" data-bind="visible: $root.design.results.save.type() == 'hdfs-file'">
  636. <input data-bind="checked: $root.design.results.save.overwrite" type="checkbox" name="overwrite">
  637. ${ _('Overwrite') }
  638. </label>
  639. </div>
  640. </div>
  641. <div data-bind="css: {'error': $root.design.results.save.targetTableError()}" class="control-group">
  642. <div class="controls">
  643. <label class="radio">
  644. <input data-bind="checked: $root.design.results.save.type" type="radio" name="save-results-type" value="hive-table">
  645. &nbsp;${ _('In a new table') }
  646. </label>
  647. <span data-bind="visible: $root.design.results.save.type() == 'hive-table'">
  648. <input data-bind="value: $root.design.results.save.path" type="text" name="target_table" class="span4" placeholder="${_('Table name or <database name>.<table name>')}">
  649. </span>
  650. </div>
  651. </div>
  652. <div data-bind="css: {'error': $root.design.results.save.targetDirectoryError()}" class="control-group hide advanced">
  653. <div class="controls">
  654. <label class="radio">
  655. <input data-bind="checked: $root.design.results.save.type" type="radio" name="save-results-type" value="hdfs-directory">
  656. &nbsp;${ _('Big Query in HDFS') }
  657. </label>
  658. <span data-bind="visible: $root.design.results.save.type() == 'hdfs-directory'">
  659. <input data-bind="value: $root.design.results.save.path" type="text" name="target_dir" placeholder="${_('Path to directory')}" class="folderChooser">
  660. <i class="fa fa-question-circle" id="hdfs-directory-help"></i>
  661. </span>
  662. </div>
  663. </div>
  664. </fieldset>
  665. </form>
  666. <div id="hdfs-directory-help-content" class="hide">
  667. <p>${ _("Use this option if you have a large result. It will rerun the entire query and save the results to the chosen HDFS directory.") }</p>
  668. </div>
  669. </div>
  670. <div class="modal-footer">
  671. % if app_name != 'impala':
  672. <a id="save-results-advanced" href="javascript:void(0)" class="pull-left">${ _('Show advanced fields') }</a>
  673. % endif
  674. <a id="save-results-simple" href="javascript:void(0)" class="pull-left hide">${ _('Hide advanced fields') }</a>
  675. <button class="btn" data-dismiss="modal">${_('Cancel')}</button>
  676. <button data-bind="click: trySaveResults" class="btn btn-primary disable-feedback">${_('Save')}</button>
  677. </div>
  678. </div>
  679. </div>
  680. <div id="tableAnalysis" class="popover mega-popover right">
  681. <div class="arrow"></div>
  682. <h3 class="popover-title" style="text-align: left">
  683. <a class="pull-right pointer close-popover" style="margin-left: 8px"><i class="fa fa-times"></i></a>
  684. <a class="pull-right pointer stats-refresh" style="margin-left: 8px"><i class="fa fa-refresh"></i></a>
  685. <span class="pull-right stats-warning muted" rel="tooltip" data-placement="top" title="${ _('The column stats for this table are not accurate') }" style="margin-left: 8px"><i class="fa fa-exclamation-triangle"></i></span>
  686. <strong class="table-name"></strong> ${ _(' table analysis') }
  687. </h3>
  688. <div class="popover-content">
  689. <div id="tableAnalysisStats">
  690. <div class="content"></div>
  691. </div>
  692. </div>
  693. </div>
  694. <div id="columnAnalysis" class="popover mega-popover right">
  695. <div class="arrow"></div>
  696. <h3 class="popover-title" style="text-align: left">
  697. <a class="pull-right pointer close-popover" style="margin-left: 8px"><i class="fa fa-times"></i></a>
  698. <a class="pull-right pointer stats-refresh" style="margin-left: 8px"><i class="fa fa-refresh"></i></a>
  699. <strong class="column-name"></strong> ${ _(' column analysis') }
  700. </h3>
  701. <div class="popover-content">
  702. <div class="pull-right hide filter">
  703. <input id="columnAnalysisTermsFilter" type="text" placeholder="${ _('Prefix filter...') }"/>
  704. </div>
  705. <ul class="nav nav-tabs" role="tablist">
  706. <li class="active"><a href="#columnAnalysisStats" role="tab" data-toggle="tab">${ _('Stats') }</a></li>
  707. <li><a href="#columnAnalysisTerms" role="tab" data-toggle="tab">${ _('Terms') }</a></li>
  708. </ul>
  709. <div class="tab-content">
  710. <div class="tab-pane active" id="columnAnalysisStats" style="text-align: left">
  711. <div class="content"></div>
  712. </div>
  713. <div class="tab-pane" id="columnAnalysisTerms" style="text-align: left">
  714. <div class="alert">${ _('There are no terms to be shown') }</div>
  715. <div class="content"></div>
  716. </div>
  717. </div>
  718. </div>
  719. </div>
  720. <div id="clearHistoryModal" class="modal hide fade">
  721. <div class="modal-header">
  722. <a href="#" class="close" data-dismiss="modal">&times;</a>
  723. <h3>${_('Confirm History Clear')}</h3>
  724. </div>
  725. <div class="modal-body">
  726. <p>${_('Are you sure you want to clear the query history?')}</p>
  727. </div>
  728. <div class="modal-footer">
  729. <a class="btn" data-dismiss="modal">${_('No')}</a>
  730. <a class="btn btn-danger disable-feedback" onclick="viewModel.clearQueryHistory()">${_('Yes')}</a>
  731. </div>
  732. </div>
  733. ${ commonshare() | n,unicode }
  734. <script src="${ static('desktop/js/hue.json.js') }" type="text/javascript" charset="utf-8"></script>
  735. <script src="${ static('desktop/ext/js/jquery/plugins/jquery-ui-1.10.4.draggable-droppable-sortable.min.js') }" type="text/javascript" charset="utf-8"></script>
  736. <script src="${ static('desktop/ext/js/routie-0.3.0.min.js') }" type="text/javascript" charset="utf-8"></script>
  737. <script src="${ static('desktop/ext/js/knockout.min.js') }" type="text/javascript" charset="utf-8"></script>
  738. <script src="${ static('desktop/ext/js/knockout-mapping.min.js') }" type="text/javascript" charset="utf-8"></script>
  739. <script src="${ static('desktop/js/ko.hue-bindings.js') }" type="text/javascript" charset="utf-8"></script>
  740. <script src="${ static('desktop/js/sqlAutocompleter.js') }" type="text/javascript" charset="utf-8"></script>
  741. <script src="${ static('desktop/js/hdfsAutocompleter.js') }" type="text/javascript" charset="utf-8"></script>
  742. <script src="${ static('desktop/js/assist/tableStats.js') }" type="text/javascript" charset="utf-8"></script>
  743. <script src="${ static('desktop/js/assist/assistHelper.js') }" type="text/javascript" charset="utf-8"></script>
  744. <script src="${ static('desktop/js/assist/assistHdfsEntry.js') }" type="text/javascript" charset="utf-8"></script>
  745. <script src="${ static('desktop/js/assist/assistDbEntry.js') }" type="text/javascript" charset="utf-8"></script>
  746. <script src="${ static('desktop/js/assist/assistDbSource.js') }" type="text/javascript" charset="utf-8"></script>
  747. <script src="${ static('desktop/js/fileBrowser/hueFileEntry.js') }" type="text/javascript" charset="utf-8"></script>
  748. <script src="${ static('desktop/js/autocompleter.js') }" type="text/javascript" charset="utf-8"></script>
  749. <script src="${ static('notebook/js/notebook.ko.js') }" type="text/javascript" charset="utf-8"></script>
  750. <script src="${ static('beeswax/js/beeswax.vm.js') }"></script>
  751. <script src="${ static('desktop/js/share.vm.js') }"></script>
  752. <script src="${ static('desktop/ext/js/vkbeautify.js') }" type="text/javascript" charset="utf-8"></script>
  753. <script src="${ static('desktop/ext/js/codemirror-3.11.js') }"></script>
  754. <link rel="stylesheet" href="${ static('desktop/ext/css/codemirror.css') }">
  755. <script src="${ static('desktop/js/codemirror-hql.js') }"></script>
  756. % if app_name == 'impala':
  757. <script src="${ static('desktop/js/codemirror-isql-hint.js') }"></script>
  758. % else:
  759. <script src="${ static('desktop/js/codemirror-hql-hint.js') }"></script>
  760. % endif
  761. <script src="${ static('desktop/js/codemirror-show-hint.js') }"></script>
  762. <link href="${ static('desktop/ext/css/bootstrap-editable.css') }" rel="stylesheet">
  763. <script src="${ static('desktop/ext/js/bootstrap-editable.min.js') }"></script>
  764. <script src="${ static('desktop/ext/js/moment-with-locales.min.js') }"></script>
  765. <script src="${ static('beeswax/js/stats.utils.js') }"></script>
  766. <link rel="stylesheet" href="${ static('desktop/ext/select2/select2.css') }">
  767. <script src="${ static('desktop/ext/select2/select2.min.js') }" type="text/javascript" charset="utf-8"></script>
  768. ${ assist.assistPanel('.table-container') }
  769. ${ tableStats.tableStats() }
  770. <style type="text/css">
  771. h1 {
  772. margin-bottom: 5px;
  773. }
  774. .panel-container {
  775. width: 100%;
  776. position: relative;
  777. }
  778. .left-panel {
  779. position: absolute;
  780. }
  781. .resizer {
  782. position: absolute;
  783. width: 20px;
  784. text-align: center;
  785. z-index: 1000;
  786. }
  787. .resize-bar {
  788. top: 50%;
  789. position: relative;
  790. cursor: ew-resize;
  791. }
  792. .right-panel {
  793. position: absolute;
  794. }
  795. #chooseFile, #chooseFolder, #choosePath {
  796. z-index: 1100;
  797. }
  798. #filechooser, #folderchooser, #pathchooser {
  799. min-height: 100px;
  800. overflow-y: auto;
  801. }
  802. .control-group {
  803. margin-bottom: 3px !important;
  804. }
  805. .control-group label {
  806. float: left;
  807. padding-top: 5px;
  808. text-align: left;
  809. width: 40px;
  810. }
  811. .control-group label.radio {
  812. float: none;
  813. width: auto;
  814. }
  815. .sidebar-nav {
  816. margin-bottom: 90px !important;
  817. }
  818. .paramContainer {
  819. padding-top: 3px!important;
  820. padding-left: 0px!important;
  821. padding-right: 0px!important;
  822. }
  823. .param {
  824. margin-bottom: 5px;
  825. padding:4px;
  826. padding-left:8px;
  827. border-bottom: 1px solid #F6F6F6;
  828. }
  829. .param:nth-child(even) {
  830. background-color: #F0F0F0;
  831. }
  832. .table-actions {
  833. position: absolute;
  834. right: 0;
  835. padding-left: 3px;
  836. background-color: #FFF;
  837. }
  838. .preview-data {
  839. margin-right: 5px;
  840. }
  841. .remove {
  842. float: right;
  843. }
  844. .fileChooserBtn {
  845. border-radius: 0 3px 3px 0;
  846. height: 31px;
  847. }
  848. .CodeMirror {
  849. border: 1px solid #eee;
  850. margin-bottom: 20px;
  851. }
  852. .editorError {
  853. color: #B94A48;
  854. background-color: #F2DEDE;
  855. padding: 4px;
  856. font-size: 11px;
  857. }
  858. .editable-empty, .editable-empty:hover {
  859. color: #666;
  860. font-style: normal;
  861. }
  862. .tooltip.left {
  863. margin-left: -13px;
  864. }
  865. .fullscreen {
  866. position: absolute;
  867. top: 70px;
  868. left: 0;
  869. width: 100%;
  870. background-color: #FFFFFF;
  871. z-index: 100;
  872. }
  873. .map {
  874. height: 200px;
  875. }
  876. #resultTable td, #resultTable th {
  877. white-space: nowrap;
  878. border-right: 1px solid #e5e5e5;
  879. }
  880. .tab-content {
  881. min-height: 100px;
  882. }
  883. .columnType {
  884. text-align: right!important;
  885. color: #999;
  886. }
  887. #queryContainer {
  888. margin-bottom: 0;
  889. }
  890. #resizePanel a {
  891. position: absolute;
  892. cursor: ns-resize;
  893. color: #666;
  894. margin-left: auto;
  895. margin-right: auto;
  896. }
  897. .resultsContainer {
  898. margin-top: 20px;
  899. }
  900. #recentQueries {
  901. width: 100%;
  902. }
  903. #recentQueries code {
  904. cursor: pointer;
  905. white-space: normal;
  906. }
  907. #recentQueries tr td:first-child {
  908. white-space: nowrap;
  909. }
  910. .table-container {
  911. margin-right:10px;
  912. }
  913. #navigator .card-body {
  914. margin-top: 1px !important;
  915. padding: 7px !important;
  916. }
  917. #navigator .nav-header {
  918. padding-left: 0;
  919. }
  920. #navigator .control-group {
  921. padding-left: 0;
  922. }
  923. #navigator .nav-list > li.white, #navigator .nav-list .nav-header {
  924. margin: 0;
  925. }
  926. #saveResultsModal .overlay {
  927. background: black; opacity: 0.5;
  928. position: absolute;
  929. top: 0px;
  930. right:0px;
  931. left: 0px;
  932. bottom: 0px;
  933. z-index: 100;
  934. }
  935. #saveResultsModal .loader {
  936. text-align: center;
  937. position: absolute;
  938. top: 0px;
  939. right:0px;
  940. left: 0px;
  941. bottom: 0px;
  942. }
  943. #saveResultsModal i.fa-spinner, #saveResultsModal img.spinner {
  944. margin-top: -30px;
  945. margin-left: -30px;
  946. position: absolute;
  947. top: 50%;
  948. left: 50%;
  949. z-index: 101;
  950. }
  951. #saveResultsModal i.fa-spinner {
  952. font-size: 60px;
  953. color: #DDD;
  954. }
  955. .tooltip {
  956. z-index: 10001;
  957. }
  958. .filesField, .functionsField, .classNamesField, .settingsField, .settingValuesField {
  959. width: 60%;
  960. }
  961. .fileChooser, .folderChooser {
  962. border-radius: 3px 0 0 3px !important;
  963. border-right: 0 !important;
  964. }
  965. .pull-right.hover-actions, .pull-right.blue {
  966. margin-top: -4px;
  967. }
  968. .query-right-actions {
  969. margin-right: 10px;
  970. }
  971. .query-right-actions h4 {
  972. padding: 0 10px;
  973. }
  974. </style>
  975. <link rel="stylesheet" href="${ static('desktop/ext/css/hue-filetypes.css') }">
  976. <link rel="stylesheet" href="${ static('desktop/ext/css/hue-charts.css') }">
  977. <script src="${ static('desktop/ext/js/jquery/plugins/jquery-fieldselection.js') }" type="text/javascript"></script>
  978. <script src="${ static('beeswax/js/autocomplete.utils.js') }" type="text/javascript" charset="utf-8"></script>
  979. <link rel="stylesheet" href="${ static('desktop/ext/chosen/chosen.min.css') }">
  980. <script src="${ static('desktop/ext/chosen/chosen.jquery.min.js') }" type="text/javascript" charset="utf-8"></script>
  981. ${ dashboard.import_charts() }
  982. <script type="text/javascript" charset="utf-8">
  983. // avoid blinking of the panels
  984. var leftPanelWidth = $.totalStorage("${app_name}_left_panel_width") != null ? $.totalStorage("${app_name}_left_panel_width") : 250;
  985. $(".left-panel").css("width", leftPanelWidth + "px");
  986. $(".right-panel").css("left", leftPanelWidth + 20 + "px");
  987. var codeMirror, resizeNavigator, dataTable, renderRecent, syncWithHive;
  988. var HIVE_AUTOCOMPLETE_BASE_URL = "${ autocomplete_base_url | n,unicode }";
  989. var HIVE_AUTOCOMPLETE_FAILS_QUIETLY_ON = [500]; // error codes from beeswax/views.py - autocomplete
  990. var HIVE_AUTOCOMPLETE_USER = "${ user }";
  991. var HIVE_AUTOCOMPLETE_APP = "${app_name}";
  992. var STATS_PROBLEMS = "${ _('There was a problem loading the stats.') }";
  993. var snippetType = HIVE_AUTOCOMPLETE_APP == "impala" ? "impala" : "hive";
  994. var editorViewModelOptions = {
  995. snippetViewSettings: {},
  996. languages: [],
  997. user: HIVE_AUTOCOMPLETE_USER
  998. };
  999. editorViewModelOptions.snippetViewSettings[snippetType] = {
  1000. sqlDialect: true
  1001. };
  1002. editorViewModelOptions.languages.push({
  1003. type: snippetType,
  1004. name: HIVE_AUTOCOMPLETE_APP == "impala" ? "Impala" : "Hive"
  1005. });
  1006. var i18n = {
  1007. errorLoadingDatabases: "${ _('There was a problem loading the databases') }"
  1008. }
  1009. var editorViewModel = new EditorViewModel([], editorViewModelOptions, i18n);
  1010. var notebook = editorViewModel.newNotebook();
  1011. var snippet = notebook.newSnippet(snippetType);
  1012. var assistHelper = snippet.getAssistHelper();
  1013. var autocompleter = new Autocompleter({
  1014. snippet: snippet,
  1015. user: HIVE_AUTOCOMPLETE_USER
  1016. });
  1017. var escapeOutput = function (str) {
  1018. return $('<span>').text(str).html().trim();
  1019. };
  1020. var truncateOutput = function (obj) {
  1021. //default to 20 characters (column output displays first 21 chars so we need to consider the length of both column name and type
  1022. var chars = obj.chars || 20,
  1023. name = obj.name || '',
  1024. type = obj.type || '',
  1025. output = name.length + type.length,
  1026. suffix = '',
  1027. trim;
  1028. if (output > chars) {
  1029. trim = Math.abs((output + 4) - chars); // 4 accounts for ellipsis, spaces, parenthesis
  1030. type = type.slice(0, Math.abs(type.length - trim));
  1031. suffix = '&hellip;';
  1032. }
  1033. return escapeOutput(type) + suffix;
  1034. };
  1035. var reinitTimeout = -1;
  1036. function onPanelPosition() {
  1037. placeResizePanelHandle();
  1038. window.clearTimeout(reinitTimeout);
  1039. reinitTimeout = window.setTimeout(function () {
  1040. reinitializeTableExtenders();
  1041. }, 50);
  1042. }
  1043. function placeResizePanelHandle() {
  1044. // dynamically positioning the resize panel handle since IE doesn't play well with styles.
  1045. $("#resizePanel a").css("left", $("#resizePanel").position().left + $("#resizePanel").width()/2 - 8);
  1046. }
  1047. function reinitializeTableExtenders() {
  1048. $("#resultTable").jHueTableExtender({
  1049. fixedHeader: true,
  1050. fixedFirstColumn: true,
  1051. includeNavigator: false
  1052. });
  1053. $("#recentQueries").jHueTableExtender({
  1054. fixedHeader: true,
  1055. includeNavigator: false
  1056. });
  1057. }
  1058. var CURRENT_CODEMIRROR_SIZE = 100;
  1059. var INITIAL_HORIZONTAL_RESIZE_POSITION = -1;
  1060. // Navigator, recent queries
  1061. $(document).ready(function () {
  1062. $("#resizePanel a").draggable({
  1063. axis: "y",
  1064. drag: function (e, ui) {
  1065. draggableHelper($(this), e, ui);
  1066. $(".jHueTableExtenderClonedContainer").hide();
  1067. $(".jHueTableExtenderClonedContainerColumn").hide();
  1068. $(".jHueTableExtenderClonedContainerCell").hide();
  1069. },
  1070. stop: function (e, ui) {
  1071. $(".jHueTableExtenderClonedContainer").show();
  1072. $(".jHueTableExtenderClonedContainerColumn").show();
  1073. $(".jHueTableExtenderClonedContainerCell").show();
  1074. draggableHelper($(this), e, ui);
  1075. reinitializeTableExtenders();
  1076. }
  1077. });
  1078. function checkForInitialSplitterPosition() {
  1079. INITIAL_HORIZONTAL_RESIZE_POSITION = $("#resizePanel a").position().top;
  1080. if (INITIAL_HORIZONTAL_RESIZE_POSITION <= 0) {
  1081. window.setTimeout(checkForInitialSplitterPosition, 200);
  1082. }
  1083. }
  1084. checkForInitialSplitterPosition();
  1085. function resizeCodeMirror(el) {
  1086. CURRENT_CODEMIRROR_SIZE = 100 + (el.position().top - INITIAL_HORIZONTAL_RESIZE_POSITION);
  1087. codeMirror.setSize("99%", CURRENT_CODEMIRROR_SIZE);
  1088. }
  1089. function draggableHelper(el, e, ui) {
  1090. if (el.position().top > INITIAL_HORIZONTAL_RESIZE_POSITION) {
  1091. resizeCodeMirror(el);
  1092. }
  1093. if (ui.position.top < INITIAL_HORIZONTAL_RESIZE_POSITION) {
  1094. ui.position.top = INITIAL_HORIZONTAL_RESIZE_POSITION;
  1095. resizeCodeMirror(el);
  1096. }
  1097. }
  1098. var recentQueries = $("#recentQueries").dataTable({
  1099. "bPaginate": false,
  1100. "bLengthChange": false,
  1101. "bInfo": false,
  1102. "bFilter": false,
  1103. "aoColumns": [
  1104. { "sWidth" : "100px", "sSortDataType":"dom-sort-value", "sType":"numeric" },
  1105. null,
  1106. { "sWidth" : "80px", "bSortable": false },
  1107. { "bSortable": false, "sWidth" : "4px" }
  1108. ],
  1109. "aaSorting": [
  1110. [0, 'desc']
  1111. ],
  1112. "oLanguage": {
  1113. "sEmptyTable": "${_('No data available')}",
  1114. "sInfo": "${_('Showing _START_ to _END_ of _TOTAL_ entries')}",
  1115. "sInfoEmpty": "${_('Showing 0 to 0 of 0 entries')}",
  1116. "sInfoFiltered": "${_('(filtered from _MAX_ total entries)')}",
  1117. "sZeroRecords": "${_('No matching records')}",
  1118. "oPaginate": {
  1119. "sFirst": "${_('First')}",
  1120. "sLast": "${_('Last')}",
  1121. "sNext": "${_('Next')}",
  1122. "sPrevious": "${_('Previous')}"
  1123. }
  1124. }
  1125. });
  1126. renderRecent = function() {
  1127. $("#recentLoader").show();
  1128. $("#recentQueries").hide();
  1129. recentQueries.fnClearTable();
  1130. var locale = window.navigator.userLanguage || window.navigator.language;
  1131. moment.locale(locale);
  1132. $.getJSON("${ url(app_name + ':list_query_history') }?format=json&recent=true", function(data) {
  1133. if (data && data.queries) {
  1134. var _rows = [];
  1135. $(data.queries).each(function(cnt, item){
  1136. _rows.push([
  1137. '<span data-sort-value="' + item.timeInMs + '">' + moment(item.timeInMs*1000).format("L LTS") + '</span>',
  1138. '<code style="cursor:pointer">' + item.query + '</code>',
  1139. (item.resultsUrl != "" ? '<a href="' + item.resultsUrl + '" data-row-selector-exclude="true">${_('See results...')}</a>': ''),
  1140. (item.designUrl != "" ? '<a href="' + item.designUrl + '" data-row-selector="true">&nbsp;</a>': '')
  1141. ]);
  1142. });
  1143. recentQueries.fnAddData(_rows);
  1144. if (_rows.length > 0){
  1145. $(".clear-queries").show();
  1146. }
  1147. else {
  1148. $(".clear-queries").hide();
  1149. }
  1150. }
  1151. $("a[data-row-selector='true']").jHueRowSelector();
  1152. $("#recentLoader").hide();
  1153. $("#recentQueries").show().css("width", "100%");
  1154. reinitializeTableExtenders();
  1155. });
  1156. };
  1157. renderRecent();
  1158. $("#navigatorSearch").jHueDelayedInput(function(){
  1159. $("#navigatorTables li").removeClass("hide");
  1160. $("#navigatorTables li").each(function () {
  1161. if ($(this).text().toLowerCase().indexOf($("#navigatorSearch").val().toLowerCase()) == -1) {
  1162. $(this).addClass("hide");
  1163. }
  1164. });
  1165. });
  1166. $("#columnFilter").jHueDelayedInput(function(){
  1167. $(".columnRow").removeClass("hide");
  1168. $(".columnRow").each(function () {
  1169. if ($(this).text().toLowerCase().indexOf($("#columnFilter").val().toLowerCase()) == -1) {
  1170. $(this).addClass("hide");
  1171. }
  1172. });
  1173. });
  1174. resizeNavigator = function () {
  1175. $(".resizer").css("height", $(window).height() + "px");
  1176. $("#navigator .card").css("height", $(window).height() + "px");
  1177. $(".table-container").css("max-height", ($(window).height() - 180) + "px").css("overflow-y", "auto");
  1178. };
  1179. $("#expandResults").on("click", function(){
  1180. $("#resultTablejHueTableExtenderClonedContainer").remove();
  1181. $("#resultTablejHueTableExtenderClonedContainerColumn").remove();
  1182. $("#resultTablejHueTableExtenderClonedContainerCell").remove();
  1183. if ($(this).find("i").hasClass("fa-expand")){
  1184. $(this).find("i").removeClass("fa-expand").addClass("fa-compress");
  1185. $(this).parent().parent().addClass("fullscreen");
  1186. }
  1187. else {
  1188. $(this).find("i").addClass("fa-expand").removeClass("fa-compress");
  1189. $(this).parent().parent().removeClass("fullscreen");
  1190. }
  1191. reinitializeTable();
  1192. });
  1193. resizeNavigator();
  1194. window.setTimeout(resizeNavigator, 200);
  1195. $(document).on("click", ".column-selector", function () {
  1196. var _t = $("#resultTable");
  1197. var _text = $.trim($(this).text().split("(")[0]);
  1198. var _col = _t.find("th").filter(function() {
  1199. return $.trim($(this).text()) == _text;
  1200. });
  1201. _t.find(".columnSelected").removeClass("columnSelected");
  1202. _t.find("tr td:nth-child(" + (_col.index() + 1) + ")").addClass("columnSelected");
  1203. $("a[href='#results']").click();
  1204. });
  1205. $(document).on("click", "#tableAnalysis .close-popover", function () {
  1206. $("#tableAnalysis").hide();
  1207. });
  1208. $(document).on("click", "#columnAnalysis .close-popover", function () {
  1209. $("#columnAnalysis").hide();
  1210. });
  1211. $(document).on("clear.history", function() {
  1212. renderRecent();
  1213. $("#clearHistoryModal").modal("hide");
  1214. });
  1215. $(document).on("shown", "a[data-toggle='tab']:not(.sidetab)", function (e) {
  1216. if ($(e.target).attr("href") == "#log") {
  1217. logsAtEnd = true;
  1218. window.setTimeout(resizeLogs, 150);
  1219. }
  1220. if ($(e.target).attr("href") == "#results" && $(e.relatedTarget).attr("href") == "#columns") {
  1221. if ($("#resultTable .columnSelected").length > 0) {
  1222. var _t = $("#resultTable");
  1223. var _col = _t.find("th:nth-child(" + ($("#resultTable .columnSelected").index() + 1) + ")");
  1224. _t.parent().animate({
  1225. scrollLeft: _col.position().left + _t.parent().scrollLeft() - _t.parent().offset().left - 30
  1226. }, 300);
  1227. }
  1228. }
  1229. if ($(e.target).attr("href") == "#results" || $(e.target).attr("href") == "#recentTab") {
  1230. reinitializeTableExtenders();
  1231. }
  1232. if ($(e.target).attr("href") != "#results"){
  1233. $($(e.target).attr("href")).css('height', 'auto');
  1234. if ($(e.target).attr("href") == "#chart") {
  1235. logGA('results/chart');
  1236. predictGraph();
  1237. }
  1238. if ($(e.target).attr("href") == "#resultTab") {
  1239. reinitializeTable();
  1240. }
  1241. } else {
  1242. reinitializeTable();
  1243. }
  1244. if ($(e.target).attr("href") == "#columnAnalysisTerms") {
  1245. $("#columnAnalysis .filter").removeClass("hide");
  1246. }
  1247. if ($(e.target).attr("href") == "#columnAnalysisStats") {
  1248. $("#columnAnalysis .filter").addClass("hide");
  1249. }
  1250. return e;
  1251. });
  1252. });
  1253. // Codemirror query field
  1254. function getHighlightedQuery() {
  1255. var selection = codeMirror.getSelection();
  1256. if (selection != "") {
  1257. return selection;
  1258. }
  1259. return null;
  1260. }
  1261. function reinitializeTable(max) {
  1262. var _max = max || 10;
  1263. function fn(){
  1264. var container = $($("a[data-toggle='tab']:not(.sidetab)").parent(".active").find("a").attr("href"));
  1265. if ($("#results .dataTables_wrapper").height() > 0) {
  1266. $("#results .dataTables_wrapper").jHueTableScroller({
  1267. minHeight: $(window).height() - 150,
  1268. heightAfterCorrection: 0
  1269. });
  1270. $("#recentTab .dataTables_wrapper").jHueTableScroller({
  1271. minHeight: $(window).height() - 150,
  1272. heightAfterCorrection: 0
  1273. });
  1274. reinitializeTableExtenders();
  1275. container.height($(window).height() - 150);
  1276. $("#results .dataTables_wrapper").jHueScrollUp();
  1277. } else if ($('#resultEmpty').height() > 0) {
  1278. container.height($('#resultEmpty').height());
  1279. } else if ($('#resultExpired').height() > 0) {
  1280. container.height($('#resultExpired').height());
  1281. }
  1282. if ($("#results .dataTables_wrapper").data('original-height') == 0 && --_max != 0) {
  1283. $("#results .dataTables_wrapper").data('original-height', $("#results .dataTables_wrapper").height());
  1284. window.setTimeout(fn, 100);
  1285. }
  1286. if ($("#recentTab .dataTables_wrapper").data('original-height') == 0 && --_max != 0) {
  1287. $("#recentTab .dataTables_wrapper").data('original-height', $("#recentTab .dataTables_wrapper").height());
  1288. window.setTimeout(fn, 100);
  1289. }
  1290. }
  1291. window.setTimeout(fn, 100);
  1292. }
  1293. $(document).ready(function () {
  1294. $.jHueScrollUp();
  1295. var queryPlaceholder = $("<span>").html($("<span>").html("${_('Example: SELECT * FROM tablename, or press CTRL + space')}").text()).text();
  1296. $("#executeQuery").tooltip({
  1297. title: '${_("Press \"tab\", then \"enter\".")}'
  1298. });
  1299. initQueryField();
  1300. var resizeTimeout = -1;
  1301. var winWidth = $(window).width();
  1302. var winHeight = $(window).height();
  1303. $(window).on("resize", function () {
  1304. window.clearTimeout(resizeTimeout);
  1305. resizeTimeout = window.setTimeout(function () {
  1306. // prevents endless loop in IE8
  1307. if (winWidth != $(window).width() || winHeight != $(window).height()) {
  1308. resizeNavigator();
  1309. winWidth = $(window).width();
  1310. winHeight = $(window).height();
  1311. }
  1312. }, 200);
  1313. });
  1314. function initQueryField() {
  1315. if ($("#queryField").val() == "") {
  1316. $("#queryField").val(queryPlaceholder);
  1317. }
  1318. }
  1319. var queryEditor = $("#queryField")[0];
  1320. % if app_name == 'impala':
  1321. var AUTOCOMPLETE_SET = CodeMirror.impalaSQLHint;
  1322. % else:
  1323. var AUTOCOMPLETE_SET = CodeMirror.hiveQLHint;
  1324. % endif
  1325. CodeMirror.onAutocomplete = function (data, from, to) {
  1326. if (data.indexOf("(") > -1){
  1327. codeMirror.setCursor({line: from.line, ch: from.ch + data.length - 1});
  1328. codeMirror.execCommand("autocomplete");
  1329. }
  1330. if (CodeMirror.tableFieldMagic) {
  1331. codeMirror.replaceRange(" ", from, from);
  1332. codeMirror.setCursor(from);
  1333. codeMirror.execCommand("autocomplete");
  1334. }
  1335. };
  1336. $(document).on("error.autocomplete", function(){
  1337. $(".CodeMirror-spinner").remove();
  1338. });
  1339. function splitStatements(hql) {
  1340. var statements = [];
  1341. var current = "";
  1342. var betweenQuotes = null;
  1343. for (var i = 0, len = hql.length; i < len; i++) {
  1344. var c = hql[i];
  1345. current += c;
  1346. if ($.inArray(c, ['"', "'"]) > -1) {
  1347. if (betweenQuotes == c) {
  1348. betweenQuotes = null;
  1349. }
  1350. else if (betweenQuotes == null) {
  1351. betweenQuotes = c;
  1352. }
  1353. }
  1354. else if (c == ";") {
  1355. if (betweenQuotes == null) {
  1356. statements.push(current);
  1357. current = "";
  1358. }
  1359. }
  1360. }
  1361. if (current != "" && current != ";") {
  1362. statements.push(current);
  1363. }
  1364. return statements;
  1365. }
  1366. function getStatementAtCursor() {
  1367. var _pos = codeMirror.indexFromPos(codeMirror.getCursor());
  1368. var _statements = splitStatements(codeMirror.getValue());
  1369. var _cumulativePos = 0;
  1370. var _statementAtCursor = "";
  1371. var _relativePos = 0;
  1372. for (var i = 0; i < _statements.length; i++) {
  1373. if (_cumulativePos + _statements[i].length >= _pos && _statementAtCursor == "") {
  1374. _statementAtCursor = _statements[i].split("\n").join(" ");
  1375. _relativePos = _pos - _cumulativePos;
  1376. }
  1377. _cumulativePos += _statements[i].length;
  1378. }
  1379. return {
  1380. statement: _statementAtCursor,
  1381. relativeIndex: _relativePos
  1382. };
  1383. }
  1384. CodeMirror.commands.autocomplete = function (cm) {
  1385. $(document.body).on("contextmenu", function (e) {
  1386. e.preventDefault(); // prevents native menu on FF for Mac from being shown
  1387. });
  1388. var pos = cm.cursorCoords();
  1389. if ($(".CodeMirror-spinner").length == 0) {
  1390. $("<i class='fa fa-spinner fa-spin CodeMirror-spinner'></i>").appendTo($("body"));
  1391. }
  1392. $(".CodeMirror-spinner").css("top", pos.top + "px").css("left", (pos.left - 4) + "px").show();
  1393. var _statementAtCursor = getStatementAtCursor();
  1394. var _before = codeMirror.getValue().substr(0, codeMirror.indexFromPos(codeMirror.getCursor()));
  1395. var _after = _statementAtCursor.statement.substr(_statementAtCursor.relativeIndex).replace(/;+$/, "");
  1396. autocompleter.autocomplete(_before, _after, function(suggestions) {
  1397. var isFromDot = _before.match(/.*\.[^ ]*$/) != null;
  1398. var isTable = false;
  1399. var tableFieldMagic = false;
  1400. var hasFromPrefix = false;
  1401. var values = suggestions.map(function(suggestion) {
  1402. if (suggestion.meta === "table") {
  1403. isTable = true; // They're all tables.
  1404. var match = suggestion.value.match(/(\? )?from ([^ ]+)$/i);
  1405. if (match != null) {
  1406. if (typeof match[1] != "undefined") {
  1407. tableFieldMagic = true;
  1408. return match[2];
  1409. } else {
  1410. hasFromPrefix = true;
  1411. }
  1412. }
  1413. return suggestion.value;
  1414. } else {
  1415. return isFromDot ? "." + suggestion.value : suggestion.value;
  1416. }
  1417. }).join(" ");
  1418. if (values.length > 0 && !hasFromPrefix) {
  1419. CodeMirror.fromDot = isFromDot;
  1420. CodeMirror.possibleSoloField = true;
  1421. CodeMirror.tableFieldMagic = tableFieldMagic;
  1422. CodeMirror.possibleTable = isTable && !tableFieldMagic;
  1423. CodeMirror.catalogTables = isTable ? values : "";
  1424. CodeMirror.catalogFields = isTable ? "" : values;
  1425. } else {
  1426. CodeMirror.fromDot = false;
  1427. CodeMirror.possibleSoloField = false;
  1428. CodeMirror.tableFieldMagic = false;
  1429. CodeMirror.possibleTable = false;
  1430. CodeMirror.catalogTables = "";
  1431. CodeMirror.catalogFields = "";
  1432. }
  1433. CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
  1434. });
  1435. };
  1436. codeMirror = CodeMirror(function (elt) {
  1437. queryEditor.parentNode.replaceChild(elt, queryEditor);
  1438. }, {
  1439. value: queryEditor.value,
  1440. readOnly: false,
  1441. lineNumbers: true,
  1442. % if app_name == 'impala':
  1443. mode: "text/x-impalaql",
  1444. % else:
  1445. mode: "text/x-hiveql",
  1446. % endif
  1447. extraKeys: {
  1448. "Ctrl-Space": function () {
  1449. codeMirror.execCommand("autocomplete");
  1450. },
  1451. Tab: function (cm) {
  1452. $("#executeQuery").focus();
  1453. }
  1454. },
  1455. onKeyEvent: function (e, s) {
  1456. if (s.type == "keydown" && s.keyCode == 73 && (s.altKey || s.ctrlKey || s.metaKey)) {
  1457. formatQuery();
  1458. }
  1459. if (s.type == "keyup") {
  1460. if (s.keyCode == 190) {
  1461. var _statement = getStatementAtCursor().statement;
  1462. if (_statement.toUpperCase().indexOf("FROM") > -1) {
  1463. window.setTimeout(function () {
  1464. codeMirror.execCommand("autocomplete");
  1465. }, 100); // timeout for IE8
  1466. }
  1467. }
  1468. }
  1469. }
  1470. });
  1471. huePubSub.subscribe('assist.dblClickDbItem', function(assistDbEntry) {
  1472. var text = assistDbEntry.editorText();
  1473. if (codeMirror.getValue() == queryPlaceholder) {
  1474. codeMirror.setValue("");
  1475. if (assistDbEntry.definition.isTable) {
  1476. text = "SELECT * FROM " + assistDbEntry.editorText() + " LIMIT 100";
  1477. }
  1478. else if (assistDbEntry.definition.isColumn) {
  1479. text = "SELECT " + assistDbEntry.editorText().split(",")[0] + " FROM " + assistDbEntry.parent.editorText() + " LIMIT 100";
  1480. }
  1481. }
  1482. codeMirror.replaceSelection(text);
  1483. codeMirror.setSelection(codeMirror.getCursor());
  1484. codeMirror.focus();
  1485. });
  1486. $(".CodeMirror").droppable({
  1487. accept: ".draggableText",
  1488. drop: function (e, ui) {
  1489. var position = codeMirror.coordsChar({"left": e.clientX, "top": e.clientY});
  1490. var text = ui.helper.text();
  1491. codeMirror.setCursor(position);
  1492. var value = codeMirror.getValue();
  1493. var index = codeMirror.indexFromPos(codeMirror.getCursor());
  1494. if (index > 0 && value.charAt(index - 1) !== ' ' && value.charAt(index - 1) !== '.') {
  1495. text = " " + text;
  1496. }
  1497. if ((index + 1) < value.length - 1 && value.charAt(index + 1) !== ' ' && text.charAt(text.length - 1) !== ' ') {
  1498. text += " ";
  1499. }
  1500. codeMirror.replaceSelection(text);
  1501. codeMirror.setSelection(codeMirror.getCursor());
  1502. codeMirror.focus();
  1503. }
  1504. });
  1505. codeMirror.on("focus", function () {
  1506. if (codeMirror.getValue() == queryPlaceholder) {
  1507. codeMirror.setValue("");
  1508. }
  1509. viewModel.queryEditorBlank(true);
  1510. clearErrorWidgets();
  1511. $("#validationResults").empty();
  1512. });
  1513. % if not (design and design.id) and not ( query_history and query_history.id ):
  1514. if ($.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query") != null && $.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query") != "") {
  1515. viewModel.queryEditorBlank(true);
  1516. codeMirror.setValue($.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query"));
  1517. }
  1518. % endif
  1519. codeMirror.on("blur", function () {
  1520. $(document.body).off("contextmenu");
  1521. });
  1522. codeMirror.on("update", function () {
  1523. if (CURRENT_CODEMIRROR_SIZE == 100 && codeMirror.lineCount() > 7){
  1524. CURRENT_CODEMIRROR_SIZE = 270;
  1525. codeMirror.setSize("99%", CURRENT_CODEMIRROR_SIZE);
  1526. reinitializeTableExtenders();
  1527. }
  1528. });
  1529. $("#download-excel").click(function () {
  1530. if (viewModel.design.results.columns().length > 255) {
  1531. $.jHueNotify.warn("${ _('Results exceeds maximum number of columns permitted by Excel, will truncate results to 255 columns.') }")
  1532. }
  1533. });
  1534. });
  1535. var editables = function() {
  1536. // Edit query name and description.
  1537. $("#query-name").editable({
  1538. validate: function (value) {
  1539. if ($.trim(value) == '') {
  1540. return "${ _('This field is required.') }";
  1541. }
  1542. },
  1543. success: function (response, newValue) {
  1544. viewModel.design.name(newValue);
  1545. },
  1546. emptytext: "${ _('Query name') }"
  1547. });
  1548. $("#query-description").editable({
  1549. success: function (response, newValue) {
  1550. viewModel.design.description(newValue);
  1551. },
  1552. emptytext: "${ _('Empty description') }"
  1553. });
  1554. $(".fileChooser:not(:has(~ button))").after(getFileBrowseButton($(".fileChooser:not(:has(~ button))")));
  1555. };
  1556. $(document).one('fetched.design', editables);
  1557. $(document).one('fetched.query', editables);
  1558. function isNumericColumn(type) {
  1559. return $.inArray(type, ['TINYINT_TYPE', 'SMALLINT_TYPE', 'INT_TYPE', 'BIGINT_TYPE', 'FLOAT_TYPE', 'DOUBLE_TYPE', 'DECIMAL_TYPE', 'TIMESTAMP_TYPE', 'DATE_TYPE']) > -1;
  1560. }
  1561. function isDateTimeColumn(type) {
  1562. return $.inArray(type, ['TIMESTAMP_TYPE', 'DATE_TYPE']) > -1;
  1563. }
  1564. function isStringColumn(type) {
  1565. return !isNumericColumn(type) && !isDateTimeColumn(type);
  1566. }
  1567. var map;
  1568. var graphHasBeenPredicted = false;
  1569. function getMapBounds(lats, lngs) {
  1570. lats = lats.sort();
  1571. lngs = lngs.sort();
  1572. return [
  1573. [lats[lats.length - 1], lngs[lngs.length - 1]], // north-east
  1574. [lats[0], lngs[0]] // south-west
  1575. ]
  1576. }
  1577. function generateGraph(graphType) {
  1578. $("#chart").height(Math.max($(window).height() - $("#blueprint").offset().top + 30, 500));
  1579. $("#chart .alert").addClass("hide");
  1580. if (graphType != "") {
  1581. $("#blueprint").attr("class", "").attr("style", "").empty();
  1582. if (graphType == ko.HUE_CHARTS.TYPES.MAP) {
  1583. if ($("#blueprintLat").val() != "-1" && $("#blueprintLng").val() != "-1") {
  1584. var _latCol = $("#blueprintLat").val() * 1;
  1585. var _lngCol = $("#blueprintLng").val() * 1;
  1586. var _descCol = $("#blueprintDesc").val() * 1;
  1587. var _lats = [];
  1588. var _lngs = [];
  1589. $("#resultTable>tbody>tr>td:nth-child(" + _latCol + ")").each(function (cnt) {
  1590. _lats.push($.trim($(this).text()) * 1);
  1591. });
  1592. $("#resultTable>tbody>tr>td:nth-child(" + _lngCol + ")").each(function (cnt) {
  1593. _lngs.push($.trim($(this).text()) * 1);
  1594. });
  1595. var _koData = [];
  1596. try {
  1597. $("#resultTable>tbody>tr>td:nth-child(" + _latCol + ")").each(function (cnt) {
  1598. if (cnt < 1000) {
  1599. if (_descCol != "-1") {
  1600. _koData.push({ lat: $.trim($(this).text()) * 1, lng: $.trim($("#resultTable>tbody>tr:nth-child(" + (cnt + 1) + ")>td:nth-child(" + _lngCol + ")").text()) * 1, label: $.trim($("#resultTable>tbody>tr:nth-child(" + (cnt + 1) + ")>td:nth-child(" + _descCol + ")").text())});
  1601. }
  1602. else {
  1603. _koData.push({ lat: $.trim($(this).text()) * 1, lng: $.trim($("#resultTable>tbody>tr:nth-child(" + (cnt + 1) + ")>td:nth-child(" + _lngCol + ")").text()) * 1});
  1604. }
  1605. }
  1606. });
  1607. viewModel.chartData(_koData);
  1608. }
  1609. catch (err) {
  1610. if (typeof console != "undefined") {
  1611. console.error(err);
  1612. }
  1613. }
  1614. if ($("#resultTable>tbody>tr>td:nth-child(" + _latCol + ")").length > 1000){
  1615. $("#chart .alert").removeClass("hide");
  1616. }
  1617. }
  1618. else {
  1619. $("#blueprint").addClass("empty").css("text-align", "center").text("${_("Please select the latitude and longitude columns.")}");
  1620. }
  1621. }
  1622. else {
  1623. if ($("#blueprintX").val() != "-1" && $("#blueprintY").val() != "-1") {
  1624. var _x = $("#blueprintX").val() * 1;
  1625. var _y = $("#blueprintY").val() * 1;
  1626. var _koData = [];
  1627. $("#resultTable>tbody>tr>td:nth-child(" + _x + ")").each(function (cnt) {
  1628. if (cnt < 1000) {
  1629. _koData.push({ value: $.trim($(this).text()), count: $.trim($("#resultTable>tbody>tr:nth-child(" + (cnt + 1) + ")>td:nth-child(" + _y + ")").text()) * 1});
  1630. }
  1631. });
  1632. viewModel.chartData(_koData);
  1633. if ($("#resultTable>tbody>tr>td:nth-child(" + _x + ")").length > 1000){
  1634. $("#chart .alert").removeClass("hide");
  1635. }
  1636. }
  1637. else {
  1638. $("#blueprint").addClass("empty").css("text-align", "center").text("${_("Please select the columns you would like to see in this chart.")}");
  1639. }
  1640. }
  1641. }
  1642. }
  1643. function getGraphType() {
  1644. var _type = "";
  1645. if ($("#blueprintBars").hasClass("active")) {
  1646. _type = ko.HUE_CHARTS.TYPES.BARCHART;
  1647. }
  1648. if ($("#blueprintLines").hasClass("active")) {
  1649. _type = ko.HUE_CHARTS.TYPES.LINECHART;
  1650. }
  1651. if ($("#blueprintMap").hasClass("active")) {
  1652. _type = ko.HUE_CHARTS.TYPES.MAP;
  1653. }
  1654. if ($("#blueprintPie").hasClass("active")) {
  1655. _type = ko.HUE_CHARTS.TYPES.PIECHART;
  1656. }
  1657. viewModel.chartType(_type);
  1658. return _type;
  1659. }
  1660. function predictGraph() {
  1661. if (!graphHasBeenPredicted) {
  1662. graphHasBeenPredicted = true;
  1663. var _firstAllString, _firstAllNumeric;
  1664. var _cols = viewModel.design.results.columns();
  1665. $(_cols).each(function (cnt, col) {
  1666. if (cnt > 0){
  1667. if (_firstAllString == null && !isNumericColumn(col.type)) {
  1668. _firstAllString = cnt + 1;
  1669. }
  1670. if (_firstAllNumeric == null && isNumericColumn(col.type)) {
  1671. _firstAllNumeric = cnt + 1;
  1672. }
  1673. }
  1674. });
  1675. if (_firstAllString != null && _firstAllNumeric != null) {
  1676. $("#blueprintBars").addClass("active");
  1677. $("#blueprintLines").removeClass("active");
  1678. $("#blueprintPie").removeClass("active");
  1679. $("#blueprintMap").removeClass("active");
  1680. $("#blueprintAxis").removeClass("hide");
  1681. $("#blueprintLatLng").addClass("hide");
  1682. $("#blueprintX").val(_firstAllString);
  1683. $("#blueprintY").val(_firstAllNumeric);
  1684. }
  1685. }
  1686. generateGraph(getGraphType());
  1687. }
  1688. // Logs
  1689. var logsAtEnd = true;
  1690. $(document).ready(function () {
  1691. var labels = {
  1692. MRJOB: "${_('MR Job')}",
  1693. MRJOBS: "${_('MR Jobs')}"
  1694. };
  1695. $(window).resize(function () {
  1696. resizeLogs();
  1697. });
  1698. $("a[href='#log']").on("shown", function () {
  1699. resizeLogs();
  1700. });
  1701. % if app_name == 'impala':
  1702. $("a[href='#sessionTab']").on("shown", function () {
  1703. // get the impala session info
  1704. viewModel.fetchImpalaSession();
  1705. });
  1706. % endif
  1707. $(".blueprintSelect").on("change", function () {
  1708. generateGraph(getGraphType())
  1709. });
  1710. $("#blueprintBars").on("click", function () {
  1711. $("#blueprintAxis").removeClass("hide");
  1712. $("#blueprintLatLng").addClass("hide");
  1713. viewModel.chartType(ko.HUE_CHARTS.TYPES.BARCHART);
  1714. generateGraph(ko.HUE_CHARTS.TYPES.BARCHART)
  1715. });
  1716. $("#blueprintLines").on("click", function () {
  1717. $("#blueprintAxis").removeClass("hide");
  1718. $("#blueprintLatLng").addClass("hide");
  1719. viewModel.chartType(ko.HUE_CHARTS.TYPES.LINECHART);
  1720. generateGraph(ko.HUE_CHARTS.TYPES.LINECHART)
  1721. });
  1722. $("#blueprintPie").on("click", function () {
  1723. $("#blueprintAxis").removeClass("hide");
  1724. $("#blueprintLatLng").addClass("hide");
  1725. viewModel.chartType(ko.HUE_CHARTS.TYPES.PIECHART);
  1726. generateGraph(ko.HUE_CHARTS.TYPES.PIECHART)
  1727. });
  1728. $("#blueprintMap").on("click", function () {
  1729. $("#blueprintAxis").addClass("hide");
  1730. $("#blueprintLatLng").removeClass("hide");
  1731. viewModel.chartType(ko.HUE_CHARTS.TYPES.MAP);
  1732. generateGraph(ko.HUE_CHARTS.TYPES.MAP)
  1733. });
  1734. $("#blueprintNoSort").on("click", function () {
  1735. viewModel.chartSorting("none");
  1736. redrawChart();
  1737. });
  1738. $("#blueprintSortAsc").on("click", function () {
  1739. viewModel.chartSorting("asc");
  1740. redrawChart();
  1741. });
  1742. $("#blueprintSortDesc").on("click", function () {
  1743. viewModel.chartSorting("desc");
  1744. redrawChart();
  1745. });
  1746. function redrawChart() {
  1747. generateGraph(viewModel.chartType());
  1748. }
  1749. $("#log pre:eq(1)").scroll(function () {
  1750. if ($(this).scrollTop() + $(this).height() + 20 >= $(this)[0].scrollHeight) {
  1751. logsAtEnd = true;
  1752. }
  1753. else {
  1754. logsAtEnd = false;
  1755. }
  1756. });
  1757. viewModel.design.watch.logs.subscribe(function(val){
  1758. var _logsEl = $("#log pre:eq(1)");
  1759. if (logsAtEnd && _logsEl[0]) {
  1760. _logsEl.scrollTop(_logsEl[0].scrollHeight - _logsEl.height());
  1761. }
  1762. window.setTimeout(resizeLogs, 10);
  1763. });
  1764. viewModel.design.results.columns.subscribe(function(val){
  1765. $("*[rel=columntooltip]").tooltip({
  1766. delay: {show: 500}
  1767. });
  1768. $("a[data-row-selector='true']").jHueRowSelector();
  1769. });
  1770. });
  1771. function resizeLogs() {
  1772. // Use fixed subtraction since logs aren't always visible.
  1773. if ($("#log pre:eq(1)").length > 0) {
  1774. var _height = Math.max($(window).height() - $("#log pre:eq(1)").offset().top, 250);
  1775. $("#log").height(_height - 10);
  1776. $("#log pre:eq(1)").css("overflow", "auto").height(_height - 50);
  1777. }
  1778. }
  1779. // Result Datatable
  1780. function cleanResultsTable() {
  1781. if (dataTable) {
  1782. viewModel.design.results.rows([]);
  1783. dataTable.fnClearTable();
  1784. dataTable.fnDestroy();
  1785. viewModel.design.results.columns.valueHasMutated();
  1786. viewModel.design.results.rows.valueHasMutated();
  1787. dataTable = null;
  1788. }
  1789. }
  1790. function addRowNumberToResults(data, startIndex) {
  1791. var _tmpdata = [];
  1792. $(data).each(function(cnt, item){
  1793. item.unshift(cnt + startIndex + 1);
  1794. _tmpdata.push(item);
  1795. });
  1796. return _tmpdata;
  1797. }
  1798. var _scrollTimeout = -1;
  1799. function datatableScroll() {
  1800. viewModel.scrollNotWorking(false);
  1801. // Automatic results grower
  1802. var dataTableEl = $("#results .dataTables_wrapper");
  1803. var _lastScrollPosition = dataTableEl.data("scrollPosition") != null ? dataTableEl.data("scrollPosition") : 0;
  1804. window.clearTimeout(_scrollTimeout);
  1805. _scrollTimeout = window.setTimeout(function(){
  1806. dataTableEl.data("scrollPosition", dataTableEl.scrollTop());
  1807. if (_lastScrollPosition != dataTableEl.scrollTop() && dataTableEl.scrollTop() + dataTableEl.outerHeight() + 20 > dataTableEl[0].scrollHeight && dataTable && viewModel.hasMoreResults()) {
  1808. dataTableEl.animate({opacity: '0.55'}, 200);
  1809. viewModel.fetchResults();
  1810. }
  1811. }, 100);
  1812. }
  1813. var firstFnDrawcallback = false;
  1814. var manualFetchResultCounter = 0;
  1815. function addResults(viewModel, dataTable, startRow, nextRow) {
  1816. if (startRow == 0) {
  1817. firstFnDrawcallback = true;
  1818. }
  1819. dataTable.fnAddData(addRowNumberToResults(viewModel.design.results.rows.slice(startRow, nextRow), startRow));
  1820. % if app_name == 'impala':
  1821. manualFetchResultCounter += (nextRow - startRow);
  1822. if (manualFetchResultCounter < 100 && viewModel.scrollNotWorking() && viewModel.hasMoreResults()){
  1823. manualFetch();
  1824. }
  1825. else {
  1826. manualFetchResultCounter = 0;
  1827. }
  1828. %endif
  1829. }
  1830. function resultsTable(e, data) {
  1831. $("#results .dataTables_wrapper").animate({opacity: '1'}, 50);
  1832. $.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query", null);
  1833. if (viewModel.design.results.columns().length > 0) {
  1834. if (!dataTable) {
  1835. dataTable = $("#resultTable").dataTable({
  1836. "bPaginate": false,
  1837. "bLengthChange": false,
  1838. "bInfo": false,
  1839. "bDestroy": true,
  1840. "bAutoWidth": false,
  1841. "oLanguage": {
  1842. "sEmptyTable": "${_('No data available')}",
  1843. "sZeroRecords": "${_('No matching records')}"
  1844. },
  1845. "fnDrawCallback": function (oSettings) {
  1846. reinitializeTableExtenders();
  1847. if (firstFnDrawcallback) {
  1848. firstFnDrawcallback = false;
  1849. window.setTimeout(reinitializeTable, 100);
  1850. }
  1851. },
  1852. "aoColumnDefs": [
  1853. {
  1854. "sType": "numeric",
  1855. "aTargets": [ "sort-numeric" ]
  1856. },
  1857. {
  1858. "sType": "string",
  1859. "aTargets": [ "sort-string" ]
  1860. },
  1861. {
  1862. "sType": "date",
  1863. "aTargets": [ "sort-date" ]
  1864. }
  1865. ]
  1866. });
  1867. $(".dataTables_filter").hide();
  1868. reinitializeTable();
  1869. var _options = '<option value="-1">${ _("Please select a column")}</option>';
  1870. $(viewModel.design.results.columns()).each(function(cnt, item){
  1871. if (cnt > 0){
  1872. _options += '<option value="'+(cnt + 1)+'">'+ item.name +'</option>';
  1873. }
  1874. });
  1875. $(".blueprintSelect").html(_options);
  1876. // Automatic results grower
  1877. var dataTableEl = $("#results .dataTables_wrapper");
  1878. dataTableEl.on("scroll", datatableScroll);
  1879. }
  1880. addResults(viewModel, dataTable, data.start_row, data.next_row);
  1881. }
  1882. }
  1883. function manualFetch() {
  1884. $("#results .dataTables_wrapper").css("opacity", "0.55");
  1885. viewModel.fetchResults();
  1886. }
  1887. $(document).on('execute.query', cleanResultsTable);
  1888. $(document).on('explain.query', cleanResultsTable);
  1889. $(document).on('fetched.results', resultsTable);
  1890. var selectedLine = -1;
  1891. var errorWidgets = [];
  1892. function clearErrorWidgets() {
  1893. $(".jHueTableExtenderClonedContainer").hide();
  1894. $(".jHueTableExtenderClonedContainerColumn").hide();
  1895. $(".jHueTableExtenderClonedContainerCell").hide();
  1896. $.each(errorWidgets, function(index, errorWidget) {
  1897. errorWidget.clear();
  1898. });
  1899. errorWidgets = [];
  1900. }
  1901. $(document).on('execute.query', clearErrorWidgets);
  1902. $(document).on('explain.query', clearErrorWidgets);
  1903. $(document).on('error.query', function () {
  1904. $.each(errorWidgets, function(index, el) {
  1905. $(el).remove();
  1906. errorWidgets = [];
  1907. });
  1908. // Move error to codeMirror if we know the line number
  1909. $.each($(".queryErrorMessage"), function(index, el) {
  1910. var err = $(el).text();
  1911. var firstPos = err.toLowerCase().indexOf("line");
  1912. if (firstPos > -1) {
  1913. selectedLine = $.trim(err.substring(err.indexOf(" ", firstPos), err.indexOf(":", firstPos))) * 1;
  1914. if (codeMirror.getSelection()) {
  1915. selectedLine += codeMirror.getCursor(true).line;
  1916. }
  1917. errorWidgets.push(
  1918. codeMirror.addLineWidget(
  1919. selectedLine > 0 ? selectedLine - 1 : selectedLine,
  1920. $("<div>").addClass("editorError").html("<i class='fa fa-exclamation-circle'></i> " + err)[0], {
  1921. coverGutter: true,
  1922. noHScroll: true
  1923. }
  1924. )
  1925. );
  1926. codeMirror.scrollTo(null, codeMirror.charCoords({
  1927. line: selectedLine > 0 ? selectedLine - 1 : selectedLine,
  1928. ch: 0
  1929. }, "local").top - codeMirror.getScrollerElement().offsetHeight / 2 - 5);
  1930. $(el).hide();
  1931. }
  1932. });
  1933. reinitializeTableExtenders();
  1934. });
  1935. // Save
  1936. function trySaveDesign() {
  1937. var query = codeMirror.getValue();
  1938. viewModel.design.query.value(query);
  1939. if (viewModel.design.id() && viewModel.design.id() != -1) {
  1940. viewModel.saveDesign();
  1941. logGA('design/save');
  1942. }
  1943. }
  1944. function saveAsModal() {
  1945. var query = getHighlightedQuery() || codeMirror.getValue();
  1946. viewModel.design.query.value(query);
  1947. $('#saveAs').modal('show');
  1948. }
  1949. function trySaveAsDesign() {
  1950. if (viewModel.design.query.value() && viewModel.design.name()) {
  1951. viewModel.design.id(-1);
  1952. viewModel.saveDesign();
  1953. $('#saveAs').find('.help-inline').text('');
  1954. $('#saveAs').find('.control-group').removeClass('error');
  1955. logGA('design/save-as');
  1956. } else if (viewModel.design.name()) {
  1957. $.jHueNotify.error("${_('No query provided to save.')}");
  1958. $('#saveAs').modal('hide');
  1959. } else {
  1960. $('#saveas-query-name').addClass('error');
  1961. }
  1962. }
  1963. function saveResultsModal() {
  1964. $("#saveResultsModal .loader").hide();
  1965. $('#saveResultsModal').modal('show');
  1966. }
  1967. function trySaveResults() {
  1968. var deferred = viewModel.saveResults();
  1969. if (deferred) {
  1970. $("#saveResultsModal button.btn-primary").button('loading');
  1971. $("#saveResultsModal .loader").show();
  1972. deferred.done(function() {
  1973. $("#saveResultsModal button.btn-primary").button('reset');
  1974. $("#saveResultsModal .loader").hide();
  1975. });
  1976. }
  1977. logGA('results/save');
  1978. }
  1979. $(document).on('saved.results', function() {
  1980. $('#saveResultsModal').modal('hide');
  1981. });
  1982. // Querying and click events.
  1983. function tryExecuteQuery() {
  1984. viewModel.scrollNotWorking(true);
  1985. $("#results .dataTables_wrapper").off("scroll", datatableScroll);
  1986. $(".jHueTableExtenderClonedContainer").hide();
  1987. $(".jHueTableExtenderClonedContainerColumn").hide();
  1988. $(".jHueTableExtenderClonedContainerCell").hide();
  1989. $(".tooltip").remove();
  1990. var query = getHighlightedQuery() || codeMirror.getValue();
  1991. viewModel.design.query.value(query);
  1992. if ($("#results .dataTables_wrapper").length > 0) { // forces results to be up
  1993. $("#results .dataTables_wrapper").scrollTop(0);
  1994. }
  1995. if ($("#recentQueries .dataTables_wrapper").length > 0) { // forces results to be up
  1996. $("#recentQueries .dataTables_wrapper").scrollTop(0);
  1997. }
  1998. renderRecent();
  1999. clickHard('.resultsContainer .nav-tabs a[href="#log"]');
  2000. graphHasBeenPredicted = false;
  2001. if (viewModel.design.isParameterized()) {
  2002. viewModel.fetchParameters();
  2003. } else {
  2004. viewModel.executeQuery();
  2005. }
  2006. logGA('query/execute');
  2007. }
  2008. function tryExecuteNextStatement() {
  2009. viewModel.scrollNotWorking(true);
  2010. var query = getHighlightedQuery() || codeMirror.getValue();
  2011. // If we highlight a part of query, we update the query and restart the query history
  2012. // In the other case we update the query but continue at the same statement we were
  2013. if (viewModel.design.query.value() != query) {
  2014. viewModel.design.query.value(query);
  2015. if (getHighlightedQuery()) {
  2016. viewModel.executeQuery();
  2017. } else {
  2018. viewModel.executeNextStatement();
  2019. }
  2020. } else {
  2021. viewModel.executeNextStatement();
  2022. }
  2023. logGA('query/execute_next');
  2024. }
  2025. function tryExecuteParameterizedQuery() {
  2026. viewModel.scrollNotWorking(true);
  2027. $(".tooltip").remove();
  2028. viewModel.executeQuery();
  2029. routie('query');
  2030. }
  2031. function tryExplainQuery() {
  2032. $(".tooltip").remove();
  2033. var query = getHighlightedQuery() || codeMirror.getValue();
  2034. viewModel.design.query.value(query);
  2035. viewModel.explainQuery();
  2036. logGA('query/explain');
  2037. }
  2038. function formatQuery() {
  2039. if (vkbeautify) {
  2040. if (codeMirror.getSelection() != '') {
  2041. codeMirror.replaceSelection(vkbeautify.sql(codeMirror.getSelection(), 2));
  2042. }
  2043. else {
  2044. codeMirror.setValue(vkbeautify.sql(codeMirror.getValue(), 2));
  2045. }
  2046. viewModel.design.query.value(codeMirror.getValue());
  2047. }
  2048. }
  2049. function tryExplainParameterizedQuery() {
  2050. $(".tooltip").remove();
  2051. viewModel.explainQuery();
  2052. routie('query');
  2053. }
  2054. function tryCancelQuery() {
  2055. $(".tooltip").remove();
  2056. viewModel.cancelQuery();
  2057. }
  2058. function createNewQuery() {
  2059. $.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query", null);
  2060. location.href="${ url(app_name + ':execute_query') }";
  2061. }
  2062. // Server error handling.
  2063. $(document).on('server.error', function (e, data) {
  2064. $(document).trigger('error', "${_('Server error occurred: ')}" + data.message ? data.message : data.error);
  2065. });
  2066. $(document).on('server.unmanageable_error', function (e, responseText) {
  2067. var message = responseText;
  2068. if (! message) {
  2069. message = '${ _("Hue server is probably down.") }';
  2070. }
  2071. $(document).trigger('error', "${_('Unmanageable server error occurred: ')}" + message);
  2072. });
  2073. // Other
  2074. $(document).on('saved.design', function (e, id) {
  2075. $('#saveAs').modal('hide');
  2076. $(document).trigger('info', "${_('Query saved.')}");
  2077. window.location.href = "/${ app_name }/execute/design/" + id;
  2078. });
  2079. $(document).on('error_save.design', function (e, message) {
  2080. var _message = "${_('Could not save design')}";
  2081. if (typeof message == "object"){
  2082. $('#saveAs').find('.help-inline').text('');
  2083. $('#saveAs').find('.control-group').removeClass('error');
  2084. if (message.saveform){
  2085. if ($('#saveAs').is(":visible")){
  2086. if (message.saveform.name){
  2087. $('#saveas-query-name').addClass('error');
  2088. $('#saveas-query-name').find('.help-inline').text(message.saveform.name.join(' '));
  2089. }
  2090. if (message.saveform.description) {
  2091. $('#saveas-query-description').addClass('error');
  2092. $('#saveas-query-name').find('.help-inline').text(message.saveform.description.join(' '));
  2093. }
  2094. }
  2095. else {
  2096. if (message.saveform.name) {
  2097. _message += " - ${_('Name')}: " + message.saveform.name.join(' ');
  2098. }
  2099. if (message.saveform.description) {
  2100. _message += " - ${_('Description')}: " + message.saveform.description.join(' ');
  2101. }
  2102. $(document).trigger('error', _message);
  2103. }
  2104. }
  2105. }
  2106. else {
  2107. if (message) {
  2108. _message += ": " + message;
  2109. }
  2110. $(document).trigger('error', _message);
  2111. }
  2112. });
  2113. $(document).on('error_save.results', function (e, message) {
  2114. var _message = "${_('Could not save results')}";
  2115. if (message) {
  2116. _message += ": " + message;
  2117. }
  2118. $(document).trigger('error', _message);
  2119. });
  2120. $(document).on('error_cancel.query', function (e, message) {
  2121. $(document).trigger("error", "${ _('Problem: ') }" + message);
  2122. });
  2123. $(document).on('cancelled.query', function (e) {
  2124. $(document).trigger("info", "${ _('Query canceled!') }")
  2125. });
  2126. function updateSidebarTooltips(selector) {
  2127. $(selector).each(function(){
  2128. $(this).tooltip({
  2129. placement: "right",
  2130. title: $(this).val()
  2131. }).attr('data-original-title', $(this).val()).tooltip('fixTitle');
  2132. });
  2133. }
  2134. $(document).ready(function () {
  2135. $("*[rel=tooltip]").tooltip({
  2136. placement: 'bottom'
  2137. });
  2138. // hack for select default rendered fields
  2139. $("select").addClass("input-medium");
  2140. // Type ahead for settings.
  2141. $.getJSON("${ url(app_name + ':configuration') }", function (data) {
  2142. $(".settingsField").typeahead({
  2143. source: $.map(data.configuration, function (value, key) {
  2144. return value.key;
  2145. })
  2146. });
  2147. });
  2148. $("#help").popover({
  2149. 'title': "${_('Did you know?')}",
  2150. 'content': $("#help-content").html(),
  2151. 'trigger': 'hover',
  2152. 'placement': 'left',
  2153. 'html': true
  2154. });
  2155. $("#hdfs-directory-help").popover({
  2156. 'title': "${_('Did you know?')}",
  2157. 'content': $("#hdfs-directory-help-content").html(),
  2158. 'trigger': 'hover',
  2159. 'placement': 'right',
  2160. 'html': true
  2161. });
  2162. $(document).on('click', '#save-results-simple', function() {
  2163. $('#save-results-advanced').removeClass('hide');
  2164. $('#save-results-simple').addClass('hide');
  2165. $('#saveResultsForm .advanced').addClass('hide');
  2166. });
  2167. $(document).on('click', '#save-results-advanced', function() {
  2168. $('#save-results-advanced').addClass('hide');
  2169. $('#save-results-simple').removeClass('hide');
  2170. $('#saveResultsForm .advanced').removeClass('hide');
  2171. });
  2172. $(document).on("change", ".settingsField", function(){
  2173. updateSidebarTooltips(".settingsField");
  2174. });
  2175. $(document).on("change", ".settingValuesField", function(){
  2176. updateSidebarTooltips(".settingValuesField");
  2177. });
  2178. $(document).on("change", ".filesField", function(){
  2179. updateSidebarTooltips(".filesField");
  2180. });
  2181. $(document).on("change", ".functionsField", function(){
  2182. updateSidebarTooltips(".functionsField");
  2183. });
  2184. $(document).on("change", ".classNamesField", function(){
  2185. updateSidebarTooltips(".classNamesField");
  2186. });
  2187. // loads default
  2188. updateSidebarTooltips(".settingsField");
  2189. updateSidebarTooltips(".settingValuesField");
  2190. updateSidebarTooltips(".filesField");
  2191. updateSidebarTooltips(".functionsField");
  2192. updateSidebarTooltips(".classNamesField");
  2193. });
  2194. % if app_name == 'impala':
  2195. $(document).ready(function () {
  2196. $("#downloadQuery").click(function () {
  2197. $("<input>").attr("type", "hidden").attr("name", "button-submit").attr("value", "Execute").appendTo($("#advancedSettingsForm"));
  2198. $("<input>").attr("type", "hidden").attr("name", "download").attr("value", "true").appendTo($("#advancedSettingsForm"));
  2199. tryExecuteQuery();
  2200. });
  2201. $("#refresh-dyk").popover({
  2202. 'title': "${_('Missing some tables? In order to update the list of tables/metadata seen by Impala, execute one of these queries:')}",
  2203. 'content': $("#refresh-content").html(),
  2204. 'trigger': 'hover',
  2205. 'html': true
  2206. });
  2207. $("#refresh-tip").popover({
  2208. 'title': "${_('Missing some tables? In order to update the list of tables/metadata seen by Impala, execute one of these queries:')}",
  2209. 'content': $("#refresh-content").html(),
  2210. 'trigger': 'hover',
  2211. 'html': true
  2212. });
  2213. });
  2214. % endif
  2215. <%
  2216. if app_name == 'impala':
  2217. from impala import conf as impala_conf
  2218. %>
  2219. % if ( app_name == 'beeswax' and beeswax_conf.CLOSE_QUERIES.get() ) or ( app_name == 'impala' and impala_conf.CLOSE_QUERIES.get() ):
  2220. $(document).ready(function () {
  2221. $(document).on('explain.query', function() {
  2222. viewModel.closeQuery();
  2223. });
  2224. $(document).on('execute.query', function() {
  2225. viewModel.closeQuery();
  2226. });
  2227. // Tricks for not triggering the closing of the query on download
  2228. $("a.download").hover(function(){
  2229. window.onbeforeunload = null;
  2230. },function() {
  2231. window.onbeforeunload = $(window).data('beforeunload');
  2232. }
  2233. );
  2234. });
  2235. // Close the query when leaving the page, backup for later when disabling the close before downloading results.
  2236. window.onbeforeunload = function(e) {
  2237. viewModel.closeQuery();
  2238. };
  2239. $(window).data('beforeunload', window.onbeforeunload);
  2240. % endif
  2241. $(".folderChooser:not(:has(~ button))").after(getFolderBrowseButton($(".folderChooser:not(:has(~ button))"), true));
  2242. $(".pathChooser:not(:has(~ button))").after(getPathBrowseButton($(".pathChooser:not(:has(~ button))"), true));
  2243. // Routie
  2244. $(document).ready(function () {
  2245. function queryPageComponents() {
  2246. $('#advanced-settings').show();
  2247. $('#navigator').show();
  2248. $('#queryContainer').show();
  2249. $('#resizePanel').show();
  2250. $('a[href="#query"]').parent().show();
  2251. }
  2252. function watchPageComponents() {
  2253. $('#advanced-settings').hide();
  2254. viewModel.isEditor(false);
  2255. $('#navigator').hide();
  2256. $('#queryContainer').hide();
  2257. $('#resizePanel').hide();
  2258. $('a[href="#query"]').parent().hide();
  2259. $('a[href="#recentTab"]').parent().hide();
  2260. }
  2261. function queryPage() {
  2262. queryPageComponents();
  2263. $('.resultsContainer .watch-query').hide();
  2264. $('.resultsContainer .view-query-results').hide();
  2265. }
  2266. function queryLogPage() {
  2267. queryPageComponents();
  2268. $('.resultsContainer .watch-query').show();
  2269. $('.resultsContainer .view-query-results').hide();
  2270. }
  2271. function queryResultsPage() {
  2272. queryPageComponents();
  2273. $('.resultsContainer .watch-query').hide();
  2274. $('.resultsContainer .view-query-results').show();
  2275. $(".view-query-results[rel=tooltip]").tooltip({
  2276. placement: 'bottom'
  2277. });
  2278. }
  2279. function parametersPage() {
  2280. queryPageComponents();
  2281. $('.resultsContainer .watch-query').hide();
  2282. $('.resultsContainer .view-query-results').hide();
  2283. }
  2284. function watchLogsPage() {
  2285. watchPageComponents();
  2286. $('.resultsContainer .watch-query').show();
  2287. $('.resultsContainer .view-query-results').hide();
  2288. }
  2289. function watchResultsPage() {
  2290. watchPageComponents();
  2291. $('.resultsContainer .watch-query').hide();
  2292. $('.resultsContainer .view-query-results').show();
  2293. }
  2294. routie({
  2295. 'query': function () {
  2296. showSection('query-editor');
  2297. queryPage();
  2298. codeMirror.setSize("99%", CURRENT_CODEMIRROR_SIZE);
  2299. placeResizePanelHandle();
  2300. },
  2301. 'query/execute/params': function () {
  2302. if (viewModel.design.parameters().length == 0) {
  2303. routie('query');
  2304. }
  2305. showSection('execute-parameter-selection');
  2306. parametersPage();
  2307. },
  2308. 'query/explain/params': function () {
  2309. if (viewModel.design.parameters().length == 0) {
  2310. routie('query');
  2311. }
  2312. showSection('explain-parameter-selection');
  2313. parametersPage();
  2314. },
  2315. 'query/logs': function () {
  2316. if (viewModel.design.watch.logs().length == 0 && viewModel.design.watch.errors().length == 0) {
  2317. routie('query');
  2318. }
  2319. showSection('query-editor');
  2320. queryLogPage();
  2321. clickHard('.resultsContainer .nav-tabs a[href="#log"]');
  2322. },
  2323. 'query/results': function () {
  2324. showSection('query-editor');
  2325. queryResultsPage();
  2326. clickHard('.resultsContainer .nav-tabs a[href="#results"]');
  2327. renderRecent();
  2328. placeResizePanelHandle();
  2329. logGA('query/results');
  2330. },
  2331. 'query/explanation': function () {
  2332. if (! viewModel.design.results.explanation()) {
  2333. routie('query');
  2334. }
  2335. showSection('query-editor');
  2336. queryResultsPage();
  2337. clickHard('.resultsContainer .nav-tabs a[href="#explanation"]');
  2338. },
  2339. 'watch/logs': function() {
  2340. showSection('query-editor');
  2341. watchLogsPage();
  2342. clickHard('.resultsContainer .nav-tabs a[href="#log"]');
  2343. logGA('watch/logs');
  2344. },
  2345. 'watch/results': function() {
  2346. showSection('query-editor');
  2347. watchResultsPage();
  2348. clickHard('.resultsContainer .nav-tabs a[href="#results"]');
  2349. logGA('watch/results');
  2350. },
  2351. '*': function () {
  2352. routie('query');
  2353. }
  2354. });
  2355. });
  2356. // Event setup
  2357. function queryEvents() {
  2358. $(document).on('fetched.parameters', function () {
  2359. if (viewModel.design.parameters().length > 0) {
  2360. routie('query/execute/params');
  2361. } else {
  2362. viewModel.executeQuery();
  2363. }
  2364. });
  2365. $(document).on('explained.query', function () {
  2366. routie('query/explanation');
  2367. });
  2368. $(document).on('watched.query', function (e, data) {
  2369. if (data.status != 2) {
  2370. if (data.status && data.status && data.status != 0) {
  2371. viewModel.design.watch.errors.push(data.error || data.message);
  2372. }
  2373. }
  2374. routie('query/logs');
  2375. });
  2376. $(document).on('error_watch.query', function () {
  2377. routie('query/logs');
  2378. });
  2379. $(document).on('fetched.results', function () {
  2380. routie('query/results');
  2381. });
  2382. $(document).on('execute.query', function() {
  2383. routie('query');
  2384. });
  2385. $(document).ready(function() {
  2386. routie('query');
  2387. });
  2388. }
  2389. function watchEvents() {
  2390. $(document).ready(function() {
  2391. routie('watch/logs');
  2392. });
  2393. $(document).on('error_watch.query', function () {
  2394. routie('watch/logs');
  2395. });
  2396. $(document).on('fetched.results', function () {
  2397. routie('watch/results');
  2398. });
  2399. }
  2400. function cacheQueryTextEvents() {
  2401. var _waitForCodemirrorInit = -1;
  2402. _waitForCodemirrorInit = window.setInterval(function () {
  2403. if (typeof codeMirror != "undefined") {
  2404. codeMirror.on("change", function () {
  2405. $(".query").val(codeMirror.getValue());
  2406. $.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query", codeMirror.getValue());
  2407. });
  2408. window.clearInterval(_waitForCodemirrorInit);
  2409. }
  2410. }, 100);
  2411. }
  2412. function loadDesign(design_id) {
  2413. viewModel.design.id(design_id);
  2414. viewModel.fetchDesign();
  2415. setupCodeMirrorSubscription();
  2416. }
  2417. function loadQueryHistory(query_history_id) {
  2418. viewModel.design.history.id(query_history_id);
  2419. viewModel.fetchQueryHistory();
  2420. setupCodeMirrorSubscription();
  2421. }
  2422. function setupCodeMirrorSubscription() {
  2423. var codeMirrorSubscription = viewModel.design.query.value.subscribe(function (value) {
  2424. viewModel.queryEditorBlank(true);
  2425. var _waitForCodemirrorInit = -1;
  2426. _waitForCodemirrorInit = window.setInterval(function () {
  2427. if (typeof codeMirror != "undefined") {
  2428. codeMirror.setValue(value);
  2429. codeMirrorSubscription.dispose();
  2430. window.clearInterval(_waitForCodemirrorInit);
  2431. }
  2432. }, 100);
  2433. });
  2434. }
  2435. // Knockout
  2436. viewModel = new BeeswaxViewModel("${app_name}", assistHelper);
  2437. ko.applyBindings(viewModel, $("#beeswax-execute")[0]);
  2438. shareViewModel = initSharing("#documentShareModal");
  2439. shareViewModel.setDocId(${doc_id});
  2440. % if not beeswax_conf.USE_GET_LOG_API.get() and app_name != 'impala':
  2441. viewModel.shouldAppendLogs = true;
  2442. % endif
  2443. % if query_history:
  2444. loadQueryHistory(${query_history.id});
  2445. % elif design.id:
  2446. loadDesign(${design.id});
  2447. % else:
  2448. $(document).ready(cacheQueryTextEvents);
  2449. % endif
  2450. viewModel.design.fileResources.values.subscribe(function() {
  2451. // File chooser button for file resources.
  2452. $(".fileChooser:not(:has(~ button))").after(getFileBrowseButton($(".fileChooser:not(:has(~ button))")));
  2453. });
  2454. % if action == 'watch-results':
  2455. $(document).ready(watchEvents);
  2456. $(document).one('fetched.query', function(e) {
  2457. viewModel.watchQueryLoop();
  2458. cacheQueryTextEvents();
  2459. });
  2460. % elif action == 'watch-redirect':
  2461. $(document).ready(watchEvents);
  2462. $(document).one('fetched.query', function(e) {
  2463. viewModel.watchQueryLoop();
  2464. cacheQueryTextEvents();
  2465. });
  2466. $(document).on('stop_watch.query', function(e) {
  2467. var successUrl = "${request.GET['on_success_url']}";
  2468. if (viewModel.design.watch.errors().length != 0) {
  2469. window.setTimeout(function(){
  2470. window.location.href = successUrl + (successUrl.indexOf("?") > -1 ? "&" : "?") + "error=" + encodeURIComponent(viewModel.design.watch.errors().join("\n"));
  2471. }, 200);
  2472. }
  2473. else if (viewModel.design.results.errors().length == 0) {
  2474. window.setTimeout(function(){
  2475. window.location.href = successUrl + (successUrl.indexOf("?") > -1 ? "&" : "?") + "refresh=true";
  2476. }, 200);
  2477. }
  2478. });
  2479. % elif action == 'editor-results':
  2480. $(document).ready(queryEvents);
  2481. $(document).one('fetched.query', function(e) {
  2482. viewModel.watchQueryLoop();
  2483. cacheQueryTextEvents();
  2484. });
  2485. % elif action == 'editor-expired-results':
  2486. $(document).ready(queryEvents);
  2487. $(document).one('fetched.query', function(e) {
  2488. viewModel.design.results.expired(true);
  2489. $(document).trigger('fetched.results', [ [] ]);
  2490. cacheQueryTextEvents();
  2491. });
  2492. % else:
  2493. $(document).ready(queryEvents);
  2494. % endif
  2495. // chart related stuff
  2496. function pieChartDataTransformer(data) {
  2497. var _data = [];
  2498. $(data.counts()).each(function (cnt, item) {
  2499. _data.push({
  2500. label: item.value,
  2501. value: item.count,
  2502. obj: item
  2503. });
  2504. });
  2505. if (viewModel.chartSorting() == "asc"){
  2506. _data.sort(function(a, b){
  2507. return a.value - b.value
  2508. });
  2509. }
  2510. if (viewModel.chartSorting() == "desc"){
  2511. _data.sort(function(a, b){
  2512. return b.value - a.value
  2513. });
  2514. }
  2515. return _data;
  2516. }
  2517. function leafletMapChartDataTransformer(data) {
  2518. if (data != null && data.counts != null) return data.counts();
  2519. }
  2520. function barChartDataTransformer(rawDatum) {
  2521. var _datum = [];
  2522. var _data = [];
  2523. $(rawDatum.counts()).each(function (cnt, item) {
  2524. if (typeof item.from != "undefined") {
  2525. _data.push({
  2526. series: 0,
  2527. x: item.from,
  2528. x_end: item.to,
  2529. y: item.value,
  2530. obj: item
  2531. });
  2532. }
  2533. else {
  2534. _data.push({
  2535. series: 0,
  2536. x: item.value,
  2537. y: item.count,
  2538. obj: item
  2539. });
  2540. }
  2541. });
  2542. if (viewModel.chartSorting() == "asc"){
  2543. _data.sort(function(a, b){
  2544. return a.y - b.y
  2545. });
  2546. }
  2547. if (viewModel.chartSorting() == "desc"){
  2548. _data.sort(function(a, b){
  2549. return b.y - a.y
  2550. });
  2551. }
  2552. _datum.push({
  2553. key: $("#blueprintY option:selected").text(),
  2554. values: _data
  2555. });
  2556. return _datum;
  2557. }
  2558. function lineChartDataTransformer(rawDatum) {
  2559. var _datum = [];
  2560. var _data = [];
  2561. $(rawDatum.counts()).each(function (cnt, item) {
  2562. if (typeof item.from != "undefined") {
  2563. _data.push({
  2564. series: 0,
  2565. x: item.from,
  2566. x_end: item.to,
  2567. y: item.value,
  2568. obj: item
  2569. });
  2570. }
  2571. else {
  2572. _data.push({
  2573. series: 0,
  2574. x: item.value,
  2575. y: item.count,
  2576. obj: item
  2577. });
  2578. }
  2579. });
  2580. if (viewModel.chartSorting() == "asc"){
  2581. _data.sort(function(a, b){
  2582. return a.y - b.y
  2583. });
  2584. }
  2585. if (viewModel.chartSorting() == "desc"){
  2586. _data.sort(function(a, b){
  2587. return b.y - a.y
  2588. });
  2589. }
  2590. _datum.push({
  2591. key: $("#blueprintY option:selected").text(),
  2592. values: _data
  2593. });
  2594. return _datum;
  2595. }
  2596. </script>
  2597. ${ commonfooter(request, messages) | n,unicode }