| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947 |
- ## Licensed to Cloudera, Inc. under one
- ## or more contributor license agreements. See the NOTICE file
- ## distributed with this work for additional information
- ## regarding copyright ownership. Cloudera, Inc. licenses this file
- ## to you under the Apache License, Version 2.0 (the
- ## "License"); you may not use this file except in compliance
- ## with the License. You may obtain a copy of the License at
- ##
- ## http://www.apache.org/licenses/LICENSE-2.0
- ##
- ## Unless required by applicable law or agreed to in writing, software
- ## distributed under the License is distributed on an "AS IS" BASIS,
- ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ## See the License for the specific language governing permissions and
- ## limitations under the License.
- <%!
- from desktop.lib.django_util import extract_field_data
- from desktop.views import commonheader, commonfooter, commonshare, _ko
- from beeswax import conf as beeswax_conf
- from django.utils.translation import ugettext as _
- %>
- <%namespace name="comps" file="beeswax_components.mako" />
- <%namespace name="layout" file="layout.mako" />
- <%namespace name="dashboard" file="common_dashboard.mako" />
- <%namespace name="tableStats" file="/table_stats.mako" />
- <%namespace name="assist" file="/assist.mako" />
- ${ commonheader(_('Query'), app_name, user) | n,unicode }
- ${ layout.menubar(section='query') }
- <div id="temporaryPlaceholder"></div>
- <div id="beeswax-execute">
- <div id="query-editor" class="container-fluid hide section">
- <div class="panel-container">
- <div class="left-panel" id="navigator">
- <ul class="nav nav-tabs" style="margin-bottom: 0">
- <li class="active"><a href="#navigatorTab" data-toggle="tab" class="sidetab">${_('Assist')}</a></li>
- <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>
- % if app_name == 'impala':
- <li><a href="#sessionTab" data-toggle="tab" class="sidetab">${_('Session')}</a></li>
- % endif
- </ul>
- <div class="tab-content" style=" overflow: hidden;">
- <div class="tab-pane active" id="navigatorTab">
- <div class="card card-small card-tab" style="margin-bottom: 0;">
- <div class="card-body" style="margin-top: 0; height: 100%;">
- <div class="assist" data-bind="component: {
- name: 'assist-panel',
- params: {
- user: HIVE_AUTOCOMPLETE_USER,
- onlySql: true,
- sql: {
- sourceTypes: editorViewModel.sqlSourceTypes,
- activeSourceType: snippetType,
- navigationSettings: {
- openItem: false,
- showPreview: true,
- showStats: true
- }
- },
- visibleAssistPanels: ['sql']
- }
- }"></div>
- </div>
- </div>
- </div>
- <div class="tab-pane" id="settingsTab">
- <div class="card card-small card-tab">
- <div class="card-body">
- <div id="advanced-settings">
- <form id="advancedSettingsForm" action="" method="POST" class="form form-horizontal">
- ${ csrf_token(request) | n,unicode }
- <ul class="nav nav-list" style="border: none; padding: 0;">
- <li class="nav-header">${_('settings')}</li>
- <li class="white paramContainer">
- <!-- ko foreach: design.settings.values -->
- <div class="param">
- <div class="remove">
- <button data-bind="click: $root.removeSetting.bind(this, $index())" type="button" class="btn btn-mini settingsDelete" title="${_('Delete this setting')}">x
- </button>
- </div>
- <div data-bind="css: {'error': $root.getSettingKeyErrors($index()).length > 0}" class="control-group">
- <label>${_('Key')}</label>
- <input data-bind="value: key" type="text" class="settingsField" autocomplete="off" placeholder="${ 'impala.resultset.cache.size' if app_name == 'impala' else 'mapred.reduce.tasks' }"/>
- </div>
- <div data-bind="css: {'error': $root.getSettingValueErrors($index()).length > 0}" class="control-group">
- <label>${_('Value')}</label>
- <input data-bind="value: value" type="text" class="settingValuesField" placeholder="${ '5000' if app_name == 'impala' else '1' }"/>
- </div>
- </div>
- <!-- /ko -->
- <div class="control-group">
- <a data-bind="click: function() { $root.addSetting('','') }" class="btn btn-mini paramAdd">${_('Add')}</a>
- </div>
- </li>
- <li class="nav-header
- % if app_name == 'impala':
- hide
- % endif
- ">
- ${_('File Resources')}
- </li>
- <li class="white paramContainer
- % if app_name == 'impala':
- hide
- % endif
- ">
- <!-- ko foreach: design.fileResources.values -->
- <div class="param">
- <div class="remove">
- <button data-bind="click: $root.removeFileResource.bind(this, $index())" type="button" class="btn btn-mini" title="${_('Delete this setting')}">×</button>
- </div>
- <div data-bind="css: {'error': $root.getFileResourceTypeErrors($index()).length > 0}" class="control-group">
- <label>${_('Type')}</label>
- <select data-bind="value: type" class="input-small">
- <option value="JAR">${_('jar')}</option>
- <option value="ARCHIVE">${_('archive')}</option>
- <option value="FILE">${_('file')}</option>
- </select>
- </div>
- <div data-bind="css: {'error': $root.getFileResourcePathErrors($index()).length > 0}" class="control-group">
- <label>${_('Path')}</label>
- <input data-bind="value: path" type="text" class="filesField fileChooser" placeholder="/user/foo/udf.jar"/>
- </div>
- </div>
- <!-- /ko -->
- <div class="control-group">
- <a data-bind="click: function() { $root.addFileResource('','') }" class="btn btn-mini paramAdd">${_('Add')}</a>
- </div>
- </li>
- <li title="${ _('User-Defined Functions') }" class="nav-header
- % if app_name == 'impala':
- hide
- % endif
- ">
- ${_('UDFs')}
- </li>
- <li class="white paramContainer
- % if app_name == 'impala':
- hide
- % endif
- ">
- <!-- ko foreach: design.functions.values -->
- <div class="param">
- <div class="remove">
- <button data-bind="click: $root.removeFunction.bind(this, $index())" type="button" class="btn btn-mini settingsDelete" title="${_('Delete this setting')}">×</button>
- </div>
- <div data-bind="css: {'error': $root.getFunctionNameErrors($index()).length > 0}" class="control-group">
- <label>${_('Name')}</label>
- <input data-bind="value: name" type="text" class="functionsField" autocomplete="off" placeholder="myFunction"/>
- </div>
- <div data-bind="css: {'error': $root.getFunctionClassNameErrors($index()).length > 0}" class="control-group">
- <label>${_('Class name')}</label>
- <input data-bind="value: class_name" type="text" class="classNamesField" placeholder="com.acme.example"/>
- </div>
- </div>
- <!-- /ko -->
- <div class="control-group">
- <a data-bind="click: function() { $root.addFunction('','') }" class="btn btn-mini paramAdd">${_('Add')}</a>
- </div>
- </li>
- <li class="nav-header">${_('Options')}</li>
- <li class="white" style="padding-top:0; padding-left:0">
- <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.")}">
- <input data-bind="checked: design.isParameterized" type="checkbox"/>
- ${_("Enable parameterization")}
- </label>
- </li>
- % if app_name == 'impala':
- <li class="nav-header">
- ${_('Metastore Catalog')}
- </li>
- <li class="white" style="padding-top:0; padding-left:0">
- <div class="control-group">
- <span id="refresh-dyk">
- <i class="fa fa-refresh"></i>
- ${ _('Sync tables tips') }
- </span>
- <div id="refresh-content" class="hide">
- <ul style="text-align: left;">
- <li>"invalidate
- metadata" ${ _("invalidates the entire catalog metadata. All table metadata will be reloaded on the next access.") }</li>
- <li>"invalidate metadata
- <table>" ${ _("invalidates the metadata, load on the next access") }</li>
- <li>"refresh
- <table>" ${ _("refreshes the metadata immediately. It is a faster, incremental refresh.") }</li>
- </ul>
- </div>
- </div>
- </li>
- % endif
- </ul>
- </form>
- </div>
- </div>
- </div>
- </div>
- % if app_name == 'impala':
- <div class="tab-pane" id="sessionTab">
- <div class="card card-small card-tab">
- <div class="card-body">
- <!-- ko if: $root.fetchingImpalaSession() -->
- <div style="margin: 5px">
- <!--[if !IE]><!--><i class="fa fa-spinner fa-spin" style="font-size: 20px; color: #BBB"></i><!--<![endif]-->
- <!--[if IE]><img src="${ static('desktop/art/spinner.gif') }"/><![endif]-->
- </div>
- <!-- /ko -->
- <!-- ko ifnot: $root.fetchingImpalaSession() -->
- <!-- ko if: $root.impalaSessionLink() != '' -->
- <ul class="nav nav-list" style="border: none; padding: 0;">
- <li class="nav-header">${ _('address')}</li>
- </ul>
- <div style="margin: 2px">
- <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>
- </div>
- <!-- /ko -->
- <!-- ko if: $root.impalaSessionLink() == '' -->
- <div style="margin: 5px">
- ${ _("There's currently no valid session") }
- </div>
- <!-- /ko -->
- <!-- /ko -->
- </div>
- </div>
- </div>
- % endif
- </div>
- </div>
- <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>
- <div class="right-panel" id="querySide">
- <div class="alert" data-bind="visible: design.isRedacted">
- ${ _('This query had some sensitive information removed when saved.') }
- </div>
- <div id="queryContainer" class="card card-small">
- <div class="pull-right" style="margin: 10px">
- <i class="fa fa-question-circle" id="help"></i>
- <div id="help-content" class="hide">
- <ul style="text-align: left;">
- <li>${ _('Press CTRL + Space to autocomplete') }</li>
- <li>${ _("You can execute queries with multiple SQL statements delimited by a semicolon ';'") }</li>
- <li>${ _('You can highlight and run a fragment of a query') }</li>
- </ul>
- </div>
- </div>
- <div style="margin-bottom: 30px">
- % if can_edit_name:
- <h1 class="card-heading simple">
- <a class="share-link" rel="tooltip" data-placement="bottom" style="padding-left:10px; padding-right: 10px" data-bind="click: openShareModal,
- attr: {'data-original-title': '${ _ko("Share") } '+name},
- css: {'baseShared': true, 'isShared': isShared()}">
- <i class="fa fa-users"></i>
- </a>
- <a href="javascript:void(0);"
- id="query-name"
- data-type="text"
- data-name="name"
- data-value="${design.name}"
- data-original-title="${ _('Query name') }"
- data-placement="right">
- </a>
- <a href="javascript:void(0);"
- id="query-description"
- data-type="textarea"
- data-name="description"
- data-value="${design.desc}"
- data-original-title="${ _('Query description') }"
- data-placement="right" style="font-size: 14px; margin-left: 10px">
- </a>
- </h1>
- %endif
- </div>
- <div class="card-body">
- <div class="tab-content">
- <div id="queryPane">
- <div data-bind="css: {'hide': design.errors().length == 0 || design.inlineErrors().length > 0}" class="alert alert-error">
- <!-- ko if: $root.getQueryErrors().length > 0 -->
- <p><strong>${_('Please provide a query')}</strong></p>
- <!-- /ko -->
- <!-- ko if: $root.getQueryErrors().length == 0 -->
- <p><strong>${_('Your query has the following error(s):')}</strong></p>
- <div data-bind="foreach: design.errors">
- <p data-bind="text: $data" class="queryErrorMessage"></p>
- </div>
- <!-- /ko -->
- </div>
- <div data-bind="css: {'hide': design.watch.errors().length == 0 || design.watch.inlineErrors().length > 0}" class="alert alert-error">
- <p><strong>${_('Your query has the following error(s):')}</strong></p>
- <div data-bind="foreach: design.watch.errors">
- <p data-bind="text: $data" class="queryErrorMessage"></p>
- </div>
- </div>
- <textarea class="hide" tabindex="1" name="query" id="queryField"></textarea>
- <div class="actions">
- <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>
- <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>
- <button data-bind="click: tryExecuteNextStatement, visible: !$root.design.isFinished()" type="button" class="btn btn-primary disable-feedback" tabindex="2">${_('Next')}</button>
- <button data-bind="click: tryExecuteQuery, visible: !$root.design.isFinished()" type="button" id="executeQuery" class="btn btn-primary disable-feedback" tabindex="2">${_('Restart')}</button>
- % if can_edit:
- <button data-bind="click: trySaveDesign, css: {'hide': !$root.design.id() || $root.design.id() == -1}" type="button" class="btn hide">${_('Save')}</button>
- % endif
- <button data-bind="click: saveAsModal" type="button" class="btn">${_('Save as...')}</button>
- <button data-bind="click: tryExplainQuery, visible: $root.canExecute" type="button" id="explainQuery" class="btn">${_('Explain')}</button>
- <button data-bind="click: formatQuery" type="button" class="btn">${_('Format')}</button>
- ${_('or create a')}
- <button data-bind="click: createNewQuery" type="button" class="btn">${_('New query')}</button>
- <br/><br/>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div id="resizePanel"><a href="javascript:void(0)"><i class="fa fa-ellipsis-h"></i></a></div>
- <div class="card card-small scrollable resultsContainer">
- <div class="query-right-actions" data-bind="visible: !design.explain()">
- <!-- ko if: $root.hasResults() -->
- <a id="expandResults" href="javascript:void(0)" title="${_('See results in full screen')}" rel="tooltip"
- class="view-query-results hide pull-right"><h4><i class="fa fa-expand"></i></h4></a>
- <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"
- class="view-query-results hide pull-right"><h4><i class="fa fa-save"></i></h4>
- </a>
- <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"
- class="view-query-results download hide pull-right"><h4><i class="hfo hfo-file-csv"></i></h4>
- </a>
- <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"
- class="view-query-results download hide pull-right"><h4><i class="hfo hfo-file-xls"></i></h4></a>
- <!-- /ko -->
- <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>
- </div>
- <div class="card-body">
- <ul class="nav nav-tabs">
- <li class="active recentLi"><a href="#recentTab" data-toggle="tab">${_('Recent queries')}</a></li>
- <li><a href="#query" data-toggle="tab">${_('Query')}</a></li>
- <!-- ko if: !design.explain() -->
- <li><a href="#log" data-toggle="tab">${_('Log')}</a></li>
- <!-- /ko -->
- <!-- ko if: !design.explain() -->
- <li><a href="#columns" data-toggle="tab">${_('Columns')}</a></li>
- <li><a href="#results" data-toggle="tab">${_('Results')}</a></li>
- <li><a href="#chart" data-toggle="tab">${_('Chart')}</a></li>
- <!-- /ko -->
- <!-- ko if: design.explain() && !design.isRunning() -->
- <li><a href="#explanation" data-toggle="tab">${_('Explanation')}</a></li>
- <!-- /ko -->
- </ul>
- <div class="tab-content">
- <div class="active tab-pane" id="recentTab">
- <div id="recentLoader">
- <!--[if !IE]><!--><i class="fa fa-spinner fa-spin" style="font-size: 20px; color: #DDD"></i><!--<![endif]-->
- <!--[if IE]><img src="${ static('desktop/art/spinner.gif') }"/><![endif]-->
- </div>
- <table id="recentQueries" class="table table-striped table-condensed datatables" cellpadding="0" cellspacing="0" data-tablescroller-enforce-height="true">
- <thead>
- <tr>
- <th>${_('Time')}</th>
- <th>${_('Query')}</th>
- <th>${_('Result')}</th>
- <th> </th>
- </tr>
- </thead>
- <tbody>
- </tbody>
- </table>
- </div>
- <div class="tab-pane" id="query">
- <pre data-bind="visible: viewModel.design.statement() == ''">${_('There is currently no query to visualize.')}</pre>
- <pre data-bind="visible: viewModel.design.statement() != '', text: viewModel.design.statement()"></pre>
- </div>
- <!-- ko if: design.explain() -->
- <div class="tab-pane" id="explanation">
- <pre data-bind="text: $root.design.results.explanation()"></pre>
- </div>
- <!-- /ko -->
- <!-- ko if: !design.explain() -->
- <div class="tab-pane" id="log">
- <div style="position:relative">
- <ul data-bind="foreach: $root.design.watch.jobUrls" class="unstyled jobs-overlay">
- <li><a data-bind="text: $.trim($data.name), attr: { href: $data.url }" target="_blank"></a></li>
- </ul>
- <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>
- <pre data-bind="visible: $root.design.watch.logs().length > 0, text: $root.design.watch.logs().join('\n')"></pre>
- </div>
- </div>
- <div class="tab-pane" id="columns">
- <pre data-bind="visible: $root.design.results.columns().length == 0">${_('There are currently no columns to visualize.')}</pre>
- <div data-bind="visible: $root.design.results.columns().length > 10">
- <input id="columnFilter" class="input-xlarge" type="text" placeholder="${_('Filter for column name or type...')}" />
- </div>
- <table class="table table-striped table-condensed" cellpadding="0" cellspacing="0">
- <tbody data-bind="foreach: $root.design.results.columns">
- <tr class="columnRow" data-bind="visible: $index() > 0">
- <td rel="columntooltip" data-placement="left" data-bind="attr: {title: '${ _ko("Scroll to the column") }">
- <a href="javascript:void(0)" data-row-selector="true" class="column-selector" data-bind="text: $data.name"></a>
- </td>
- <td class="columnType" data-bind="text: $.trim($data.type)"></td>
- </tr>
- </tbody>
- </table>
- </div>
- <div class="tab-pane" id="results">
- <div data-bind="css: {'hide': design.results.errors().length == 0}" class="alert alert-error">
- <p><strong>${_('Fetching results ran into the following error(s):')}</strong></p>
- <div data-bind="foreach: design.results.errors">
- <p data-bind="text: $data" class="queryErrorMessage"></p>
- </div>
- </div>
- <div data-bind="css: {'hide': !$root.hasResults()}">
- <table id="resultTable" class="table table-striped table-condensed" cellpadding="0" cellspacing="0" data-tablescroller-enforce-height="true">
- <thead>
- <tr data-bind="foreach: $root.design.results.columns">
- <th data-bind="html: ($index() == 0 ? ' ' : $data.name), css: { 'sort-numeric': isNumericColumn($data.type), 'sort-date': isDateTimeColumn($data.type), 'sort-string': isStringColumn($data.type), 'datatables-counter-col': $index() == 0}"></th>
- </tr>
- </thead>
- </table>
- % if app_name == 'impala':
- <a class="pointer" data-bind="visible: $root.scrollNotWorking() && $root.hasMoreResults(), click: manualFetch" style="padding: 10px">${ _('Show more results...') }</a>
- % endif
- </div>
- <div data-bind="css: {'hide': !$root.design.results.empty() || $root.design.results.expired()}" id="resultEmpty">
- <pre>${_('The operation has no results.')}</pre>
- </div>
- <div data-bind="css: {'hide': !$root.design.results.expired()}" id="resultExpired">
- <pre>${_('The results have expired, rerun the query if needed.')}</pre>
- </div>
- </div>
- <div class="tab-pane" id="chart">
- <pre data-bind="visible: $root.design.results.empty() || $root.design.results.expired()">${_('There is currently no data to build a chart on.')}</pre>
- <div class="alert hide">
- <strong>${_('Warning:')}</strong> ${_('the results on the chart have been limited to 1000 rows.')}
- </div>
- <div data-bind="visible: ! $root.design.results.empty() && ! $root.design.results.expired()" style="text-align: center">
- <form class="form-inline">
- ${_('Chart type')}
- <div class="btn-group" data-toggle="buttons-radio">
- <a rel="tooltip" data-placement="top" title="${_('Bars')}" id="blueprintBars" href="javascript:void(0)" class="btn"><i class="hcha hcha-bar-chart"></i></a>
- <a rel="tooltip" data-placement="top" title="${_('Lines')}" id="blueprintLines" href="javascript:void(0)" class="btn"><i class="hcha hcha-line-chart"></i></a>
- <a rel="tooltip" data-placement="top" title="${_('Pie')}" id="blueprintPie" href="javascript:void(0)" class="btn"><i class="hcha hcha-pie-chart"></i></a>
- <a rel="tooltip" data-placement="top" title="${_('Map')}" id="blueprintMap" href="javascript:void(0)" class="btn"><i class="hcha hcha-map-chart"></i></a>
- </div>
- <span id="blueprintAxis" class="hide">
- <label>${_('X-Axis')}
- <select id="blueprintX" class="blueprintSelect"></select>
- </label>
- <label>${_('Y-Axis')}
- <select id="blueprintY" class="blueprintSelect"></select>
- </label>
- <div class="btn-group" data-toggle="buttons-radio">
- <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>
- <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>
- <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>
- </div>
- </span>
- <span id="blueprintLatLng" class="hide">
- <label>${_('Latitude')}
- <select id="blueprintLat" class="blueprintSelect"></select>
- </label>
- <label>${_('Longitude')}
- <select id="blueprintLng" class="blueprintSelect"></select>
- </label>
- <label>${_('Label')}
- <select id="blueprintDesc" class="blueprintSelect"></select>
- </label>
- </span>
- </form>
- </div>
- <div data-bind="visible: ! $root.design.results.empty() && ! $root.design.results.expired()" id="blueprint" class="empty center">${_("Please select a chart type.")}</div>
- <div style="margin: 10px" data-bind="visible: ! $root.design.results.empty() && ! $root.design.results.expired()">
- <div id="pieChart" data-bind="pieChart: {data: {counts: $root.chartData}, fqs: ko.observableArray([]),
- transformer: pieChartDataTransformer,
- maxWidth: 350 }, visible: $root.chartType() == 'pie'"></div>
- <div id="barChart" data-bind="barChart: {datum: {counts: $root.chartData}, fqs: ko.observableArray([]), hideSelection: true,
- transformer: barChartDataTransformer}, visible: $root.chartType() == 'bars'"></div>
- <div id="lineChart" data-bind="lineChart: {datum: {counts: $root.chartData},
- transformer: lineChartDataTransformer,
- showControls: false }, visible: $root.chartType() == 'lines'"></div>
- <div id="leafletMapChart" data-bind="leafletMapChart: {datum: {counts: $root.chartData},
- transformer: leafletMapChartDataTransformer,
- showControls: false }, visible: $root.chartType() == 'map'"></div>
- </div>
- </div>
- <!-- /ko -->
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div id="execute-parameter-selection" class="container-fluid hide section">
- <div class="row-fluid">
- <div class="card card-small">
- <h1 class="card-heading simple">${_('Please specify parameters for this query')}</h1>
- <div class="card-body">
- <p>
- <form method="POST" action="" class="form-horizontal">
- ${ csrf_token(request) | n,unicode }
- <fieldset>
- <!-- ko foreach: $root.design.parameters -->
- <div class="control-group">
- <label data-bind="text: name" class="control-label"></label>
- <div class="controls">
- <input data-bind="value: value, valueUpdate:'afterkeydown'" type="text"/>
- </div>
- </div>
- <!-- /ko -->
- <div class="form-actions" style="padding-left: 10px">
- <a class="btn" href="javascript:history.go(-1);">${_('Cancel')}</a>
- <button data-bind="enable: $root.hasParametersFilled, click: tryExecuteParameterizedQuery" type="button" class="btn btn-primary">${_('Execute query')}</button>
- </div>
- </fieldset>
- </form>
- </p>
- </div>
- </div>
- </div>
- </div>
- <div id="explain-parameter-selection" class="container-fluid hide section">
- <div class="row-fluid">
- <div class="card card-small">
- <h1 class="card-heading simple">${_('Please specify parameters for this query')}</h1>
- <div class="card-body">
- <p>
- <form method="POST" action="" class="form-horizontal">
- ${ csrf_token(request) | n,unicode }
- <fieldset>
- <!-- ko foreach: $root.design.parameters -->
- <div class="control-group">
- <label data-bind="text: name" class="control-label"></label>
- <div class="controls">
- <input data-bind="value: value, valueUpdate:'afterkeydown'" type="text"/>
- </div>
- </div>
- <!-- /ko -->
- <div class="form-actions" style="padding-left: 10px">
- <a class="btn" href="javascript:history.go(-1);">${_('Cancel')}</a>
- <button data-bind="enable: $root.hasParametersFilled, click: tryExplainParameterizedQuery" type="button" class="btn btn-primary">${_('Explain query')}</button>
- </div>
- </fieldset>
- </form>
- </p>
- </div>
- </div>
- </div>
- </div>
- <div id="chooseFile" class="modal hide fade">
- <div class="modal-header">
- <a href="#" class="close" data-dismiss="modal">×</a>
- <h3>${_('Choose a file')}</h3>
- </div>
- <div class="modal-body">
- <div id="filechooser">
- </div>
- </div>
- <div class="modal-footer">
- </div>
- </div>
- <div id="chooseFolder" class="modal hide fade">
- <div class="modal-header">
- <a href="#" class="close" data-dismiss="modal">×</a>
- <h3>${_('Select a directory')}</h3>
- </div>
- <div class="modal-body">
- <div id="folderchooser">
- </div>
- </div>
- <div class="modal-footer">
- </div>
- </div>
- <div id="choosePath" class="modal hide fade">
- <div class="modal-header">
- <a href="#" class="close" data-dismiss="modal">×</a>
- <h3>${_('Select a file or directory')}</h3>
- </div>
- <div class="modal-body">
- <div id="pathchooser">
- </div>
- </div>
- <div class="modal-footer">
- </div>
- </div>
- <div id="saveAs" class="modal hide fade">
- <div class="modal-header">
- <a href="#" class="close" data-dismiss="modal">×</a>
- <h3>${_('Choose a name')}</h3>
- </div>
- <form class="form-horizontal">
- <div class="control-group" id="saveas-query-name">
- <label class="control-label">${_('Name')}</label>
- <div class="controls">
- <input data-bind="value: $root.design.name, html" type="text" class="input-xlarge">
- <span class="help-inline"></span>
- </div>
- </div>
- <div class="control-group" id="saveas-query-description">
- <label class="control-label">${_('Description')}</label>
- <div class="controls">
- <input data-bind="value: $root.design.description, html" type="text" class="input-xlarge">
- <span class="help-inline"></span>
- </div>
- </div>
- </form>
- <div class="modal-footer">
- <button class="btn" data-dismiss="modal">${_('Cancel')}</button>
- <button data-bind="click: trySaveAsDesign" class="btn btn-primary">${_('Save')}</button>
- </div>
- </div>
- <div id="saveResultsModal" class="modal hide fade">
- <div class="loader">
- <div class="overlay"></div>
- <!--[if !IE]><!--><i class="fa fa-spinner fa-spin"></i><!--<![endif]-->
- <!--[if IE]><img class="spinner" src="${ static('desktop/art/spinner-big-inverted.gif') }"/><![endif]-->
- </div>
- <div class="modal-header">
- <a href="#" class="close" data-dismiss="modal">×</a>
- <h3>${_('Save Query Results')}</h3>
- </div>
- <div class="modal-body" style="padding: 4px">
- <!-- ko if: $root.design.results.save.saveTargetError() -->
- <h4 data-bind="text: $root.design.results.save.saveTargetError()"></h4>
- <!-- /ko -->
- <!-- ko if: $root.design.results.save.targetTableError() -->
- <h4 data-bind="text: $root.design.results.save.targetTableError()"></h4>
- <!-- /ko -->
- <!-- ko if: $root.design.results.save.targetDirectoryError() -->
- <h4 data-bind="text: $root.design.results.save.targetDirectoryError()"></h4>
- <!-- /ko -->
- <form id="saveResultsForm" method="POST" class="form form-inline">
- ${ csrf_token(request) | n,unicode }
- <fieldset>
- <div data-bind="css: {'error': $root.design.results.save.targetFileError()}" class="control-group">
- <div class="controls">
- <label class="radio">
- <input data-bind="checked: $root.design.results.save.type" type="radio" name="save-results-type" value="hdfs-file">
- ${ _('In an HDFS file') }
- </label>
- <span data-bind="visible: $root.design.results.save.type() == 'hdfs-file'">
- <input data-bind="value: $root.design.results.save.path" type="text" name="target_file" placeholder="${_('Path to CSV file')}" class="pathChooser">
- </span>
- <label class="radio" data-bind="visible: $root.design.results.save.type() == 'hdfs-file'">
- <input data-bind="checked: $root.design.results.save.overwrite" type="checkbox" name="overwrite">
- ${ _('Overwrite') }
- </label>
- </div>
- </div>
- <div data-bind="css: {'error': $root.design.results.save.targetTableError()}" class="control-group">
- <div class="controls">
- <label class="radio">
- <input data-bind="checked: $root.design.results.save.type" type="radio" name="save-results-type" value="hive-table">
- ${ _('In a new table') }
- </label>
- <span data-bind="visible: $root.design.results.save.type() == 'hive-table'">
- <input data-bind="value: $root.design.results.save.path" type="text" name="target_table" class="span4" placeholder="${_('Table name or <database name>.<table name>')}">
- </span>
- </div>
- </div>
- <div data-bind="css: {'error': $root.design.results.save.targetDirectoryError()}" class="control-group hide advanced">
- <div class="controls">
- <label class="radio">
- <input data-bind="checked: $root.design.results.save.type" type="radio" name="save-results-type" value="hdfs-directory">
- ${ _('Big Query in HDFS') }
- </label>
- <span data-bind="visible: $root.design.results.save.type() == 'hdfs-directory'">
- <input data-bind="value: $root.design.results.save.path" type="text" name="target_dir" placeholder="${_('Path to directory')}" class="folderChooser">
- <i class="fa fa-question-circle" id="hdfs-directory-help"></i>
- </span>
- </div>
- </div>
- </fieldset>
- </form>
- <div id="hdfs-directory-help-content" class="hide">
- <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>
- </div>
- </div>
- <div class="modal-footer">
- % if app_name != 'impala':
- <a id="save-results-advanced" href="javascript:void(0)" class="pull-left">${ _('Show advanced fields') }</a>
- % endif
- <a id="save-results-simple" href="javascript:void(0)" class="pull-left hide">${ _('Hide advanced fields') }</a>
- <button class="btn" data-dismiss="modal">${_('Cancel')}</button>
- <button data-bind="click: trySaveResults" class="btn btn-primary disable-feedback">${_('Save')}</button>
- </div>
- </div>
- </div>
- <div id="tableAnalysis" class="popover mega-popover right">
- <div class="arrow"></div>
- <h3 class="popover-title" style="text-align: left">
- <a class="pull-right pointer close-popover" style="margin-left: 8px"><i class="fa fa-times"></i></a>
- <a class="pull-right pointer stats-refresh" style="margin-left: 8px"><i class="fa fa-refresh"></i></a>
- <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>
- <strong class="table-name"></strong> ${ _(' table analysis') }
- </h3>
- <div class="popover-content">
- <div id="tableAnalysisStats">
- <div class="content"></div>
- </div>
- </div>
- </div>
- <div id="columnAnalysis" class="popover mega-popover right">
- <div class="arrow"></div>
- <h3 class="popover-title" style="text-align: left">
- <a class="pull-right pointer close-popover" style="margin-left: 8px"><i class="fa fa-times"></i></a>
- <a class="pull-right pointer stats-refresh" style="margin-left: 8px"><i class="fa fa-refresh"></i></a>
- <strong class="column-name"></strong> ${ _(' column analysis') }
- </h3>
- <div class="popover-content">
- <div class="pull-right hide filter">
- <input id="columnAnalysisTermsFilter" type="text" placeholder="${ _('Prefix filter...') }"/>
- </div>
- <ul class="nav nav-tabs" role="tablist">
- <li class="active"><a href="#columnAnalysisStats" role="tab" data-toggle="tab">${ _('Stats') }</a></li>
- <li><a href="#columnAnalysisTerms" role="tab" data-toggle="tab">${ _('Terms') }</a></li>
- </ul>
- <div class="tab-content">
- <div class="tab-pane active" id="columnAnalysisStats" style="text-align: left">
- <div class="content"></div>
- </div>
- <div class="tab-pane" id="columnAnalysisTerms" style="text-align: left">
- <div class="alert">${ _('There are no terms to be shown') }</div>
- <div class="content"></div>
- </div>
- </div>
- </div>
- </div>
- <div id="clearHistoryModal" class="modal hide fade">
- <div class="modal-header">
- <a href="#" class="close" data-dismiss="modal">×</a>
- <h3>${_('Confirm History Clear')}</h3>
- </div>
- <div class="modal-body">
- <p>${_('Are you sure you want to clear the query history?')}</p>
- </div>
- <div class="modal-footer">
- <a class="btn" data-dismiss="modal">${_('No')}</a>
- <a class="btn btn-danger disable-feedback" onclick="viewModel.clearQueryHistory()">${_('Yes')}</a>
- </div>
- </div>
- ${ commonshare() | n,unicode }
- <script src="${ static('desktop/js/hue.json.js') }" type="text/javascript" charset="utf-8"></script>
- <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>
- <script src="${ static('desktop/ext/js/routie-0.3.0.min.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/ext/js/knockout.min.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/ext/js/knockout-mapping.min.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/ko.hue-bindings.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/sqlAutocompleter.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/hdfsAutocompleter.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/assist/tableStats.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/assist/assistHelper.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/assist/assistHdfsEntry.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/assist/assistDbEntry.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/assist/assistDbSource.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/fileBrowser/hueFileEntry.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/autocompleter.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('notebook/js/notebook.ko.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('beeswax/js/beeswax.vm.js') }"></script>
- <script src="${ static('desktop/js/share.vm.js') }"></script>
- <script src="${ static('desktop/ext/js/vkbeautify.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/ext/js/codemirror-3.11.js') }"></script>
- <link rel="stylesheet" href="${ static('desktop/ext/css/codemirror.css') }">
- <script src="${ static('desktop/js/codemirror-hql.js') }"></script>
- % if app_name == 'impala':
- <script src="${ static('desktop/js/codemirror-isql-hint.js') }"></script>
- % else:
- <script src="${ static('desktop/js/codemirror-hql-hint.js') }"></script>
- % endif
- <script src="${ static('desktop/js/codemirror-show-hint.js') }"></script>
- <link href="${ static('desktop/ext/css/bootstrap-editable.css') }" rel="stylesheet">
- <script src="${ static('desktop/ext/js/bootstrap-editable.min.js') }"></script>
- <script src="${ static('desktop/ext/js/moment-with-locales.min.js') }"></script>
- <script src="${ static('beeswax/js/stats.utils.js') }"></script>
- <link rel="stylesheet" href="${ static('desktop/ext/select2/select2.css') }">
- <script src="${ static('desktop/ext/select2/select2.min.js') }" type="text/javascript" charset="utf-8"></script>
- ${ assist.assistPanel('.table-container') }
- ${ tableStats.tableStats() }
- <style type="text/css">
- h1 {
- margin-bottom: 5px;
- }
- .panel-container {
- width: 100%;
- position: relative;
- }
- .left-panel {
- position: absolute;
- }
- .resizer {
- position: absolute;
- width: 20px;
- text-align: center;
- z-index: 1000;
- }
- .resize-bar {
- top: 50%;
- position: relative;
- cursor: ew-resize;
- }
- .right-panel {
- position: absolute;
- }
- #chooseFile, #chooseFolder, #choosePath {
- z-index: 1100;
- }
- #filechooser, #folderchooser, #pathchooser {
- min-height: 100px;
- overflow-y: auto;
- }
- .control-group {
- margin-bottom: 3px !important;
- }
- .control-group label {
- float: left;
- padding-top: 5px;
- text-align: left;
- width: 40px;
- }
- .control-group label.radio {
- float: none;
- width: auto;
- }
- .sidebar-nav {
- margin-bottom: 90px !important;
- }
- .paramContainer {
- padding-top: 3px!important;
- padding-left: 0px!important;
- padding-right: 0px!important;
- }
- .param {
- margin-bottom: 5px;
- padding:4px;
- padding-left:8px;
- border-bottom: 1px solid #F6F6F6;
- }
- .param:nth-child(even) {
- background-color: #F0F0F0;
- }
- .table-actions {
- position: absolute;
- right: 0;
- padding-left: 3px;
- background-color: #FFF;
- }
- .preview-data {
- margin-right: 5px;
- }
- .remove {
- float: right;
- }
- .fileChooserBtn {
- border-radius: 0 3px 3px 0;
- height: 31px;
- }
- .CodeMirror {
- border: 1px solid #eee;
- margin-bottom: 20px;
- }
- .editorError {
- color: #B94A48;
- background-color: #F2DEDE;
- padding: 4px;
- font-size: 11px;
- }
- .editable-empty, .editable-empty:hover {
- color: #666;
- font-style: normal;
- }
- .tooltip.left {
- margin-left: -13px;
- }
- .fullscreen {
- position: absolute;
- top: 70px;
- left: 0;
- width: 100%;
- background-color: #FFFFFF;
- z-index: 100;
- }
- .map {
- height: 200px;
- }
- #resultTable td, #resultTable th {
- white-space: nowrap;
- border-right: 1px solid #e5e5e5;
- }
- .tab-content {
- min-height: 100px;
- }
- .columnType {
- text-align: right!important;
- color: #999;
- }
- #queryContainer {
- margin-bottom: 0;
- }
- #resizePanel a {
- position: absolute;
- cursor: ns-resize;
- color: #666;
- margin-left: auto;
- margin-right: auto;
- }
- .resultsContainer {
- margin-top: 20px;
- }
- #recentQueries {
- width: 100%;
- }
- #recentQueries code {
- cursor: pointer;
- white-space: normal;
- }
- #recentQueries tr td:first-child {
- white-space: nowrap;
- }
- .table-container {
- margin-right:10px;
- }
- #navigator .card-body {
- margin-top: 1px !important;
- padding: 7px !important;
- }
- #navigator .nav-header {
- padding-left: 0;
- }
- #navigator .control-group {
- padding-left: 0;
- }
- #navigator .nav-list > li.white, #navigator .nav-list .nav-header {
- margin: 0;
- }
- #saveResultsModal .overlay {
- background: black; opacity: 0.5;
- position: absolute;
- top: 0px;
- right:0px;
- left: 0px;
- bottom: 0px;
- z-index: 100;
- }
- #saveResultsModal .loader {
- text-align: center;
- position: absolute;
- top: 0px;
- right:0px;
- left: 0px;
- bottom: 0px;
- }
- #saveResultsModal i.fa-spinner, #saveResultsModal img.spinner {
- margin-top: -30px;
- margin-left: -30px;
- position: absolute;
- top: 50%;
- left: 50%;
- z-index: 101;
- }
- #saveResultsModal i.fa-spinner {
- font-size: 60px;
- color: #DDD;
- }
- .tooltip {
- z-index: 10001;
- }
- .filesField, .functionsField, .classNamesField, .settingsField, .settingValuesField {
- width: 60%;
- }
- .fileChooser, .folderChooser {
- border-radius: 3px 0 0 3px !important;
- border-right: 0 !important;
- }
- .pull-right.hover-actions, .pull-right.blue {
- margin-top: -4px;
- }
- .query-right-actions {
- margin-right: 10px;
- }
- .query-right-actions h4 {
- padding: 0 10px;
- }
- </style>
- <link rel="stylesheet" href="${ static('desktop/ext/css/hue-filetypes.css') }">
- <link rel="stylesheet" href="${ static('desktop/ext/css/hue-charts.css') }">
- <script src="${ static('desktop/ext/js/jquery/plugins/jquery-fieldselection.js') }" type="text/javascript"></script>
- <script src="${ static('beeswax/js/autocomplete.utils.js') }" type="text/javascript" charset="utf-8"></script>
- <link rel="stylesheet" href="${ static('desktop/ext/chosen/chosen.min.css') }">
- <script src="${ static('desktop/ext/chosen/chosen.jquery.min.js') }" type="text/javascript" charset="utf-8"></script>
- ${ dashboard.import_charts() }
- <script type="text/javascript" charset="utf-8">
- // avoid blinking of the panels
- var leftPanelWidth = $.totalStorage("${app_name}_left_panel_width") != null ? $.totalStorage("${app_name}_left_panel_width") : 250;
- $(".left-panel").css("width", leftPanelWidth + "px");
- $(".right-panel").css("left", leftPanelWidth + 20 + "px");
- var codeMirror, resizeNavigator, dataTable, renderRecent, syncWithHive;
- var HIVE_AUTOCOMPLETE_BASE_URL = "${ autocomplete_base_url | n,unicode }";
- var HIVE_AUTOCOMPLETE_FAILS_QUIETLY_ON = [500]; // error codes from beeswax/views.py - autocomplete
- var HIVE_AUTOCOMPLETE_USER = "${ user }";
- var HIVE_AUTOCOMPLETE_APP = "${app_name}";
- var STATS_PROBLEMS = "${ _('There was a problem loading the stats.') }";
- var snippetType = HIVE_AUTOCOMPLETE_APP == "impala" ? "impala" : "hive";
- var editorViewModelOptions = {
- snippetViewSettings: {},
- languages: [],
- user: HIVE_AUTOCOMPLETE_USER
- };
- editorViewModelOptions.snippetViewSettings[snippetType] = {
- sqlDialect: true
- };
- editorViewModelOptions.languages.push({
- type: snippetType,
- name: HIVE_AUTOCOMPLETE_APP == "impala" ? "Impala" : "Hive"
- });
- var i18n = {
- errorLoadingDatabases: "${ _('There was a problem loading the databases') }"
- }
- var editorViewModel = new EditorViewModel([], editorViewModelOptions, i18n);
- var notebook = editorViewModel.newNotebook();
- var snippet = notebook.newSnippet(snippetType);
- var assistHelper = snippet.getAssistHelper();
- var autocompleter = new Autocompleter({
- snippet: snippet,
- user: HIVE_AUTOCOMPLETE_USER
- });
- var escapeOutput = function (str) {
- return $('<span>').text(str).html().trim();
- };
- var truncateOutput = function (obj) {
- //default to 20 characters (column output displays first 21 chars so we need to consider the length of both column name and type
- var chars = obj.chars || 20,
- name = obj.name || '',
- type = obj.type || '',
- output = name.length + type.length,
- suffix = '',
- trim;
- if (output > chars) {
- trim = Math.abs((output + 4) - chars); // 4 accounts for ellipsis, spaces, parenthesis
- type = type.slice(0, Math.abs(type.length - trim));
- suffix = '…';
- }
- return escapeOutput(type) + suffix;
- };
- var reinitTimeout = -1;
- function onPanelPosition() {
- placeResizePanelHandle();
- window.clearTimeout(reinitTimeout);
- reinitTimeout = window.setTimeout(function () {
- reinitializeTableExtenders();
- }, 50);
- }
- function placeResizePanelHandle() {
- // dynamically positioning the resize panel handle since IE doesn't play well with styles.
- $("#resizePanel a").css("left", $("#resizePanel").position().left + $("#resizePanel").width()/2 - 8);
- }
- function reinitializeTableExtenders() {
- $("#resultTable").jHueTableExtender({
- fixedHeader: true,
- fixedFirstColumn: true,
- includeNavigator: false
- });
- $("#recentQueries").jHueTableExtender({
- fixedHeader: true,
- includeNavigator: false
- });
- }
- var CURRENT_CODEMIRROR_SIZE = 100;
- var INITIAL_HORIZONTAL_RESIZE_POSITION = -1;
- // Navigator, recent queries
- $(document).ready(function () {
- $("#resizePanel a").draggable({
- axis: "y",
- drag: function (e, ui) {
- draggableHelper($(this), e, ui);
- $(".jHueTableExtenderClonedContainer").hide();
- $(".jHueTableExtenderClonedContainerColumn").hide();
- $(".jHueTableExtenderClonedContainerCell").hide();
- },
- stop: function (e, ui) {
- $(".jHueTableExtenderClonedContainer").show();
- $(".jHueTableExtenderClonedContainerColumn").show();
- $(".jHueTableExtenderClonedContainerCell").show();
- draggableHelper($(this), e, ui);
- reinitializeTableExtenders();
- }
- });
- function checkForInitialSplitterPosition() {
- INITIAL_HORIZONTAL_RESIZE_POSITION = $("#resizePanel a").position().top;
- if (INITIAL_HORIZONTAL_RESIZE_POSITION <= 0) {
- window.setTimeout(checkForInitialSplitterPosition, 200);
- }
- }
- checkForInitialSplitterPosition();
- function resizeCodeMirror(el) {
- CURRENT_CODEMIRROR_SIZE = 100 + (el.position().top - INITIAL_HORIZONTAL_RESIZE_POSITION);
- codeMirror.setSize("99%", CURRENT_CODEMIRROR_SIZE);
- }
- function draggableHelper(el, e, ui) {
- if (el.position().top > INITIAL_HORIZONTAL_RESIZE_POSITION) {
- resizeCodeMirror(el);
- }
- if (ui.position.top < INITIAL_HORIZONTAL_RESIZE_POSITION) {
- ui.position.top = INITIAL_HORIZONTAL_RESIZE_POSITION;
- resizeCodeMirror(el);
- }
- }
- var recentQueries = $("#recentQueries").dataTable({
- "bPaginate": false,
- "bLengthChange": false,
- "bInfo": false,
- "bFilter": false,
- "aoColumns": [
- { "sWidth" : "100px", "sSortDataType":"dom-sort-value", "sType":"numeric" },
- null,
- { "sWidth" : "80px", "bSortable": false },
- { "bSortable": false, "sWidth" : "4px" }
- ],
- "aaSorting": [
- [0, 'desc']
- ],
- "oLanguage": {
- "sEmptyTable": "${_('No data available')}",
- "sInfo": "${_('Showing _START_ to _END_ of _TOTAL_ entries')}",
- "sInfoEmpty": "${_('Showing 0 to 0 of 0 entries')}",
- "sInfoFiltered": "${_('(filtered from _MAX_ total entries)')}",
- "sZeroRecords": "${_('No matching records')}",
- "oPaginate": {
- "sFirst": "${_('First')}",
- "sLast": "${_('Last')}",
- "sNext": "${_('Next')}",
- "sPrevious": "${_('Previous')}"
- }
- }
- });
- renderRecent = function() {
- $("#recentLoader").show();
- $("#recentQueries").hide();
- recentQueries.fnClearTable();
- var locale = window.navigator.userLanguage || window.navigator.language;
- moment.locale(locale);
- $.getJSON("${ url(app_name + ':list_query_history') }?format=json&recent=true", function(data) {
- if (data && data.queries) {
- var _rows = [];
- $(data.queries).each(function(cnt, item){
- _rows.push([
- '<span data-sort-value="' + item.timeInMs + '">' + moment(item.timeInMs*1000).format("L LTS") + '</span>',
- '<code style="cursor:pointer">' + item.query + '</code>',
- (item.resultsUrl != "" ? '<a href="' + item.resultsUrl + '" data-row-selector-exclude="true">${_('See results...')}</a>': ''),
- (item.designUrl != "" ? '<a href="' + item.designUrl + '" data-row-selector="true"> </a>': '')
- ]);
- });
- recentQueries.fnAddData(_rows);
- if (_rows.length > 0){
- $(".clear-queries").show();
- }
- else {
- $(".clear-queries").hide();
- }
- }
- $("a[data-row-selector='true']").jHueRowSelector();
- $("#recentLoader").hide();
- $("#recentQueries").show().css("width", "100%");
- reinitializeTableExtenders();
- });
- };
- renderRecent();
- $("#navigatorSearch").jHueDelayedInput(function(){
- $("#navigatorTables li").removeClass("hide");
- $("#navigatorTables li").each(function () {
- if ($(this).text().toLowerCase().indexOf($("#navigatorSearch").val().toLowerCase()) == -1) {
- $(this).addClass("hide");
- }
- });
- });
- $("#columnFilter").jHueDelayedInput(function(){
- $(".columnRow").removeClass("hide");
- $(".columnRow").each(function () {
- if ($(this).text().toLowerCase().indexOf($("#columnFilter").val().toLowerCase()) == -1) {
- $(this).addClass("hide");
- }
- });
- });
- resizeNavigator = function () {
- $(".resizer").css("height", $(window).height() + "px");
- $("#navigator .card").css("height", $(window).height() + "px");
- $(".table-container").css("max-height", ($(window).height() - 180) + "px").css("overflow-y", "auto");
- };
- $("#expandResults").on("click", function(){
- $("#resultTablejHueTableExtenderClonedContainer").remove();
- $("#resultTablejHueTableExtenderClonedContainerColumn").remove();
- $("#resultTablejHueTableExtenderClonedContainerCell").remove();
- if ($(this).find("i").hasClass("fa-expand")){
- $(this).find("i").removeClass("fa-expand").addClass("fa-compress");
- $(this).parent().parent().addClass("fullscreen");
- }
- else {
- $(this).find("i").addClass("fa-expand").removeClass("fa-compress");
- $(this).parent().parent().removeClass("fullscreen");
- }
- reinitializeTable();
- });
- resizeNavigator();
- window.setTimeout(resizeNavigator, 200);
- $(document).on("click", ".column-selector", function () {
- var _t = $("#resultTable");
- var _text = $.trim($(this).text().split("(")[0]);
- var _col = _t.find("th").filter(function() {
- return $.trim($(this).text()) == _text;
- });
- _t.find(".columnSelected").removeClass("columnSelected");
- _t.find("tr td:nth-child(" + (_col.index() + 1) + ")").addClass("columnSelected");
- $("a[href='#results']").click();
- });
- $(document).on("click", "#tableAnalysis .close-popover", function () {
- $("#tableAnalysis").hide();
- });
- $(document).on("click", "#columnAnalysis .close-popover", function () {
- $("#columnAnalysis").hide();
- });
- $(document).on("clear.history", function() {
- renderRecent();
- $("#clearHistoryModal").modal("hide");
- });
- $(document).on("shown", "a[data-toggle='tab']:not(.sidetab)", function (e) {
- if ($(e.target).attr("href") == "#log") {
- logsAtEnd = true;
- window.setTimeout(resizeLogs, 150);
- }
- if ($(e.target).attr("href") == "#results" && $(e.relatedTarget).attr("href") == "#columns") {
- if ($("#resultTable .columnSelected").length > 0) {
- var _t = $("#resultTable");
- var _col = _t.find("th:nth-child(" + ($("#resultTable .columnSelected").index() + 1) + ")");
- _t.parent().animate({
- scrollLeft: _col.position().left + _t.parent().scrollLeft() - _t.parent().offset().left - 30
- }, 300);
- }
- }
- if ($(e.target).attr("href") == "#results" || $(e.target).attr("href") == "#recentTab") {
- reinitializeTableExtenders();
- }
- if ($(e.target).attr("href") != "#results"){
- $($(e.target).attr("href")).css('height', 'auto');
- if ($(e.target).attr("href") == "#chart") {
- logGA('results/chart');
- predictGraph();
- }
- if ($(e.target).attr("href") == "#resultTab") {
- reinitializeTable();
- }
- } else {
- reinitializeTable();
- }
- if ($(e.target).attr("href") == "#columnAnalysisTerms") {
- $("#columnAnalysis .filter").removeClass("hide");
- }
- if ($(e.target).attr("href") == "#columnAnalysisStats") {
- $("#columnAnalysis .filter").addClass("hide");
- }
- return e;
- });
- });
- // Codemirror query field
- function getHighlightedQuery() {
- var selection = codeMirror.getSelection();
- if (selection != "") {
- return selection;
- }
- return null;
- }
- function reinitializeTable(max) {
- var _max = max || 10;
- function fn(){
- var container = $($("a[data-toggle='tab']:not(.sidetab)").parent(".active").find("a").attr("href"));
- if ($("#results .dataTables_wrapper").height() > 0) {
- $("#results .dataTables_wrapper").jHueTableScroller({
- minHeight: $(window).height() - 150,
- heightAfterCorrection: 0
- });
- $("#recentTab .dataTables_wrapper").jHueTableScroller({
- minHeight: $(window).height() - 150,
- heightAfterCorrection: 0
- });
- reinitializeTableExtenders();
- container.height($(window).height() - 150);
- $("#results .dataTables_wrapper").jHueScrollUp();
- } else if ($('#resultEmpty').height() > 0) {
- container.height($('#resultEmpty').height());
- } else if ($('#resultExpired').height() > 0) {
- container.height($('#resultExpired').height());
- }
- if ($("#results .dataTables_wrapper").data('original-height') == 0 && --_max != 0) {
- $("#results .dataTables_wrapper").data('original-height', $("#results .dataTables_wrapper").height());
- window.setTimeout(fn, 100);
- }
- if ($("#recentTab .dataTables_wrapper").data('original-height') == 0 && --_max != 0) {
- $("#recentTab .dataTables_wrapper").data('original-height', $("#recentTab .dataTables_wrapper").height());
- window.setTimeout(fn, 100);
- }
- }
- window.setTimeout(fn, 100);
- }
- $(document).ready(function () {
- $.jHueScrollUp();
- var queryPlaceholder = $("<span>").html($("<span>").html("${_('Example: SELECT * FROM tablename, or press CTRL + space')}").text()).text();
- $("#executeQuery").tooltip({
- title: '${_("Press \"tab\", then \"enter\".")}'
- });
- initQueryField();
- var resizeTimeout = -1;
- var winWidth = $(window).width();
- var winHeight = $(window).height();
- $(window).on("resize", function () {
- window.clearTimeout(resizeTimeout);
- resizeTimeout = window.setTimeout(function () {
- // prevents endless loop in IE8
- if (winWidth != $(window).width() || winHeight != $(window).height()) {
- resizeNavigator();
- winWidth = $(window).width();
- winHeight = $(window).height();
- }
- }, 200);
- });
- function initQueryField() {
- if ($("#queryField").val() == "") {
- $("#queryField").val(queryPlaceholder);
- }
- }
- var queryEditor = $("#queryField")[0];
- % if app_name == 'impala':
- var AUTOCOMPLETE_SET = CodeMirror.impalaSQLHint;
- % else:
- var AUTOCOMPLETE_SET = CodeMirror.hiveQLHint;
- % endif
- CodeMirror.onAutocomplete = function (data, from, to) {
- if (data.indexOf("(") > -1){
- codeMirror.setCursor({line: from.line, ch: from.ch + data.length - 1});
- codeMirror.execCommand("autocomplete");
- }
- if (CodeMirror.tableFieldMagic) {
- codeMirror.replaceRange(" ", from, from);
- codeMirror.setCursor(from);
- codeMirror.execCommand("autocomplete");
- }
- };
- $(document).on("error.autocomplete", function(){
- $(".CodeMirror-spinner").remove();
- });
- function splitStatements(hql) {
- var statements = [];
- var current = "";
- var betweenQuotes = null;
- for (var i = 0, len = hql.length; i < len; i++) {
- var c = hql[i];
- current += c;
- if ($.inArray(c, ['"', "'"]) > -1) {
- if (betweenQuotes == c) {
- betweenQuotes = null;
- }
- else if (betweenQuotes == null) {
- betweenQuotes = c;
- }
- }
- else if (c == ";") {
- if (betweenQuotes == null) {
- statements.push(current);
- current = "";
- }
- }
- }
- if (current != "" && current != ";") {
- statements.push(current);
- }
- return statements;
- }
- function getStatementAtCursor() {
- var _pos = codeMirror.indexFromPos(codeMirror.getCursor());
- var _statements = splitStatements(codeMirror.getValue());
- var _cumulativePos = 0;
- var _statementAtCursor = "";
- var _relativePos = 0;
- for (var i = 0; i < _statements.length; i++) {
- if (_cumulativePos + _statements[i].length >= _pos && _statementAtCursor == "") {
- _statementAtCursor = _statements[i].split("\n").join(" ");
- _relativePos = _pos - _cumulativePos;
- }
- _cumulativePos += _statements[i].length;
- }
- return {
- statement: _statementAtCursor,
- relativeIndex: _relativePos
- };
- }
- CodeMirror.commands.autocomplete = function (cm) {
- $(document.body).on("contextmenu", function (e) {
- e.preventDefault(); // prevents native menu on FF for Mac from being shown
- });
- var pos = cm.cursorCoords();
- if ($(".CodeMirror-spinner").length == 0) {
- $("<i class='fa fa-spinner fa-spin CodeMirror-spinner'></i>").appendTo($("body"));
- }
- $(".CodeMirror-spinner").css("top", pos.top + "px").css("left", (pos.left - 4) + "px").show();
- var _statementAtCursor = getStatementAtCursor();
- var _before = codeMirror.getValue().substr(0, codeMirror.indexFromPos(codeMirror.getCursor()));
- var _after = _statementAtCursor.statement.substr(_statementAtCursor.relativeIndex).replace(/;+$/, "");
- autocompleter.autocomplete(_before, _after, function(suggestions) {
- var isFromDot = _before.match(/.*\.[^ ]*$/) != null;
- var isTable = false;
- var tableFieldMagic = false;
- var hasFromPrefix = false;
- var values = suggestions.map(function(suggestion) {
- if (suggestion.meta === "table") {
- isTable = true; // They're all tables.
- var match = suggestion.value.match(/(\? )?from ([^ ]+)$/i);
- if (match != null) {
- if (typeof match[1] != "undefined") {
- tableFieldMagic = true;
- return match[2];
- } else {
- hasFromPrefix = true;
- }
- }
- return suggestion.value;
- } else {
- return isFromDot ? "." + suggestion.value : suggestion.value;
- }
- }).join(" ");
- if (values.length > 0 && !hasFromPrefix) {
- CodeMirror.fromDot = isFromDot;
- CodeMirror.possibleSoloField = true;
- CodeMirror.tableFieldMagic = tableFieldMagic;
- CodeMirror.possibleTable = isTable && !tableFieldMagic;
- CodeMirror.catalogTables = isTable ? values : "";
- CodeMirror.catalogFields = isTable ? "" : values;
- } else {
- CodeMirror.fromDot = false;
- CodeMirror.possibleSoloField = false;
- CodeMirror.tableFieldMagic = false;
- CodeMirror.possibleTable = false;
- CodeMirror.catalogTables = "";
- CodeMirror.catalogFields = "";
- }
- CodeMirror.showHint(cm, AUTOCOMPLETE_SET);
- });
- };
- codeMirror = CodeMirror(function (elt) {
- queryEditor.parentNode.replaceChild(elt, queryEditor);
- }, {
- value: queryEditor.value,
- readOnly: false,
- lineNumbers: true,
- % if app_name == 'impala':
- mode: "text/x-impalaql",
- % else:
- mode: "text/x-hiveql",
- % endif
- extraKeys: {
- "Ctrl-Space": function () {
- codeMirror.execCommand("autocomplete");
- },
- Tab: function (cm) {
- $("#executeQuery").focus();
- }
- },
- onKeyEvent: function (e, s) {
- if (s.type == "keydown" && s.keyCode == 73 && (s.altKey || s.ctrlKey || s.metaKey)) {
- formatQuery();
- }
- if (s.type == "keyup") {
- if (s.keyCode == 190) {
- var _statement = getStatementAtCursor().statement;
- if (_statement.toUpperCase().indexOf("FROM") > -1) {
- window.setTimeout(function () {
- codeMirror.execCommand("autocomplete");
- }, 100); // timeout for IE8
- }
- }
- }
- }
- });
- huePubSub.subscribe('assist.dblClickDbItem', function(assistDbEntry) {
- var text = assistDbEntry.editorText();
- if (codeMirror.getValue() == queryPlaceholder) {
- codeMirror.setValue("");
- if (assistDbEntry.definition.isTable) {
- text = "SELECT * FROM " + assistDbEntry.editorText() + " LIMIT 100";
- }
- else if (assistDbEntry.definition.isColumn) {
- text = "SELECT " + assistDbEntry.editorText().split(",")[0] + " FROM " + assistDbEntry.parent.editorText() + " LIMIT 100";
- }
- }
- codeMirror.replaceSelection(text);
- codeMirror.setSelection(codeMirror.getCursor());
- codeMirror.focus();
- });
- $(".CodeMirror").droppable({
- accept: ".draggableText",
- drop: function (e, ui) {
- var position = codeMirror.coordsChar({"left": e.clientX, "top": e.clientY});
- var text = ui.helper.text();
- codeMirror.setCursor(position);
- var value = codeMirror.getValue();
- var index = codeMirror.indexFromPos(codeMirror.getCursor());
- if (index > 0 && value.charAt(index - 1) !== ' ' && value.charAt(index - 1) !== '.') {
- text = " " + text;
- }
- if ((index + 1) < value.length - 1 && value.charAt(index + 1) !== ' ' && text.charAt(text.length - 1) !== ' ') {
- text += " ";
- }
- codeMirror.replaceSelection(text);
- codeMirror.setSelection(codeMirror.getCursor());
- codeMirror.focus();
- }
- });
- codeMirror.on("focus", function () {
- if (codeMirror.getValue() == queryPlaceholder) {
- codeMirror.setValue("");
- }
- viewModel.queryEditorBlank(true);
- clearErrorWidgets();
- $("#validationResults").empty();
- });
- % if not (design and design.id) and not ( query_history and query_history.id ):
- if ($.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query") != null && $.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query") != "") {
- viewModel.queryEditorBlank(true);
- codeMirror.setValue($.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query"));
- }
- % endif
- codeMirror.on("blur", function () {
- $(document.body).off("contextmenu");
- });
- codeMirror.on("update", function () {
- if (CURRENT_CODEMIRROR_SIZE == 100 && codeMirror.lineCount() > 7){
- CURRENT_CODEMIRROR_SIZE = 270;
- codeMirror.setSize("99%", CURRENT_CODEMIRROR_SIZE);
- reinitializeTableExtenders();
- }
- });
- $("#download-excel").click(function () {
- if (viewModel.design.results.columns().length > 255) {
- $.jHueNotify.warn("${ _('Results exceeds maximum number of columns permitted by Excel, will truncate results to 255 columns.') }")
- }
- });
- });
- var editables = function() {
- // Edit query name and description.
- $("#query-name").editable({
- validate: function (value) {
- if ($.trim(value) == '') {
- return "${ _('This field is required.') }";
- }
- },
- success: function (response, newValue) {
- viewModel.design.name(newValue);
- },
- emptytext: "${ _('Query name') }"
- });
- $("#query-description").editable({
- success: function (response, newValue) {
- viewModel.design.description(newValue);
- },
- emptytext: "${ _('Empty description') }"
- });
- $(".fileChooser:not(:has(~ button))").after(getFileBrowseButton($(".fileChooser:not(:has(~ button))")));
- };
- $(document).one('fetched.design', editables);
- $(document).one('fetched.query', editables);
- function isNumericColumn(type) {
- return $.inArray(type, ['TINYINT_TYPE', 'SMALLINT_TYPE', 'INT_TYPE', 'BIGINT_TYPE', 'FLOAT_TYPE', 'DOUBLE_TYPE', 'DECIMAL_TYPE', 'TIMESTAMP_TYPE', 'DATE_TYPE']) > -1;
- }
- function isDateTimeColumn(type) {
- return $.inArray(type, ['TIMESTAMP_TYPE', 'DATE_TYPE']) > -1;
- }
- function isStringColumn(type) {
- return !isNumericColumn(type) && !isDateTimeColumn(type);
- }
- var map;
- var graphHasBeenPredicted = false;
- function getMapBounds(lats, lngs) {
- lats = lats.sort();
- lngs = lngs.sort();
- return [
- [lats[lats.length - 1], lngs[lngs.length - 1]], // north-east
- [lats[0], lngs[0]] // south-west
- ]
- }
- function generateGraph(graphType) {
- $("#chart").height(Math.max($(window).height() - $("#blueprint").offset().top + 30, 500));
- $("#chart .alert").addClass("hide");
- if (graphType != "") {
- $("#blueprint").attr("class", "").attr("style", "").empty();
- if (graphType == ko.HUE_CHARTS.TYPES.MAP) {
- if ($("#blueprintLat").val() != "-1" && $("#blueprintLng").val() != "-1") {
- var _latCol = $("#blueprintLat").val() * 1;
- var _lngCol = $("#blueprintLng").val() * 1;
- var _descCol = $("#blueprintDesc").val() * 1;
- var _lats = [];
- var _lngs = [];
- $("#resultTable>tbody>tr>td:nth-child(" + _latCol + ")").each(function (cnt) {
- _lats.push($.trim($(this).text()) * 1);
- });
- $("#resultTable>tbody>tr>td:nth-child(" + _lngCol + ")").each(function (cnt) {
- _lngs.push($.trim($(this).text()) * 1);
- });
- var _koData = [];
- try {
- $("#resultTable>tbody>tr>td:nth-child(" + _latCol + ")").each(function (cnt) {
- if (cnt < 1000) {
- if (_descCol != "-1") {
- _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())});
- }
- else {
- _koData.push({ lat: $.trim($(this).text()) * 1, lng: $.trim($("#resultTable>tbody>tr:nth-child(" + (cnt + 1) + ")>td:nth-child(" + _lngCol + ")").text()) * 1});
- }
- }
- });
- viewModel.chartData(_koData);
- }
- catch (err) {
- if (typeof console != "undefined") {
- console.error(err);
- }
- }
- if ($("#resultTable>tbody>tr>td:nth-child(" + _latCol + ")").length > 1000){
- $("#chart .alert").removeClass("hide");
- }
- }
- else {
- $("#blueprint").addClass("empty").css("text-align", "center").text("${_("Please select the latitude and longitude columns.")}");
- }
- }
- else {
- if ($("#blueprintX").val() != "-1" && $("#blueprintY").val() != "-1") {
- var _x = $("#blueprintX").val() * 1;
- var _y = $("#blueprintY").val() * 1;
- var _koData = [];
- $("#resultTable>tbody>tr>td:nth-child(" + _x + ")").each(function (cnt) {
- if (cnt < 1000) {
- _koData.push({ value: $.trim($(this).text()), count: $.trim($("#resultTable>tbody>tr:nth-child(" + (cnt + 1) + ")>td:nth-child(" + _y + ")").text()) * 1});
- }
- });
- viewModel.chartData(_koData);
- if ($("#resultTable>tbody>tr>td:nth-child(" + _x + ")").length > 1000){
- $("#chart .alert").removeClass("hide");
- }
- }
- else {
- $("#blueprint").addClass("empty").css("text-align", "center").text("${_("Please select the columns you would like to see in this chart.")}");
- }
- }
- }
- }
- function getGraphType() {
- var _type = "";
- if ($("#blueprintBars").hasClass("active")) {
- _type = ko.HUE_CHARTS.TYPES.BARCHART;
- }
- if ($("#blueprintLines").hasClass("active")) {
- _type = ko.HUE_CHARTS.TYPES.LINECHART;
- }
- if ($("#blueprintMap").hasClass("active")) {
- _type = ko.HUE_CHARTS.TYPES.MAP;
- }
- if ($("#blueprintPie").hasClass("active")) {
- _type = ko.HUE_CHARTS.TYPES.PIECHART;
- }
- viewModel.chartType(_type);
- return _type;
- }
- function predictGraph() {
- if (!graphHasBeenPredicted) {
- graphHasBeenPredicted = true;
- var _firstAllString, _firstAllNumeric;
- var _cols = viewModel.design.results.columns();
- $(_cols).each(function (cnt, col) {
- if (cnt > 0){
- if (_firstAllString == null && !isNumericColumn(col.type)) {
- _firstAllString = cnt + 1;
- }
- if (_firstAllNumeric == null && isNumericColumn(col.type)) {
- _firstAllNumeric = cnt + 1;
- }
- }
- });
- if (_firstAllString != null && _firstAllNumeric != null) {
- $("#blueprintBars").addClass("active");
- $("#blueprintLines").removeClass("active");
- $("#blueprintPie").removeClass("active");
- $("#blueprintMap").removeClass("active");
- $("#blueprintAxis").removeClass("hide");
- $("#blueprintLatLng").addClass("hide");
- $("#blueprintX").val(_firstAllString);
- $("#blueprintY").val(_firstAllNumeric);
- }
- }
- generateGraph(getGraphType());
- }
- // Logs
- var logsAtEnd = true;
- $(document).ready(function () {
- var labels = {
- MRJOB: "${_('MR Job')}",
- MRJOBS: "${_('MR Jobs')}"
- };
- $(window).resize(function () {
- resizeLogs();
- });
- $("a[href='#log']").on("shown", function () {
- resizeLogs();
- });
- % if app_name == 'impala':
- $("a[href='#sessionTab']").on("shown", function () {
- // get the impala session info
- viewModel.fetchImpalaSession();
- });
- % endif
- $(".blueprintSelect").on("change", function () {
- generateGraph(getGraphType())
- });
- $("#blueprintBars").on("click", function () {
- $("#blueprintAxis").removeClass("hide");
- $("#blueprintLatLng").addClass("hide");
- viewModel.chartType(ko.HUE_CHARTS.TYPES.BARCHART);
- generateGraph(ko.HUE_CHARTS.TYPES.BARCHART)
- });
- $("#blueprintLines").on("click", function () {
- $("#blueprintAxis").removeClass("hide");
- $("#blueprintLatLng").addClass("hide");
- viewModel.chartType(ko.HUE_CHARTS.TYPES.LINECHART);
- generateGraph(ko.HUE_CHARTS.TYPES.LINECHART)
- });
- $("#blueprintPie").on("click", function () {
- $("#blueprintAxis").removeClass("hide");
- $("#blueprintLatLng").addClass("hide");
- viewModel.chartType(ko.HUE_CHARTS.TYPES.PIECHART);
- generateGraph(ko.HUE_CHARTS.TYPES.PIECHART)
- });
- $("#blueprintMap").on("click", function () {
- $("#blueprintAxis").addClass("hide");
- $("#blueprintLatLng").removeClass("hide");
- viewModel.chartType(ko.HUE_CHARTS.TYPES.MAP);
- generateGraph(ko.HUE_CHARTS.TYPES.MAP)
- });
- $("#blueprintNoSort").on("click", function () {
- viewModel.chartSorting("none");
- redrawChart();
- });
- $("#blueprintSortAsc").on("click", function () {
- viewModel.chartSorting("asc");
- redrawChart();
- });
- $("#blueprintSortDesc").on("click", function () {
- viewModel.chartSorting("desc");
- redrawChart();
- });
- function redrawChart() {
- generateGraph(viewModel.chartType());
- }
- $("#log pre:eq(1)").scroll(function () {
- if ($(this).scrollTop() + $(this).height() + 20 >= $(this)[0].scrollHeight) {
- logsAtEnd = true;
- }
- else {
- logsAtEnd = false;
- }
- });
- viewModel.design.watch.logs.subscribe(function(val){
- var _logsEl = $("#log pre:eq(1)");
- if (logsAtEnd && _logsEl[0]) {
- _logsEl.scrollTop(_logsEl[0].scrollHeight - _logsEl.height());
- }
- window.setTimeout(resizeLogs, 10);
- });
- viewModel.design.results.columns.subscribe(function(val){
- $("*[rel=columntooltip]").tooltip({
- delay: {show: 500}
- });
- $("a[data-row-selector='true']").jHueRowSelector();
- });
- });
- function resizeLogs() {
- // Use fixed subtraction since logs aren't always visible.
- if ($("#log pre:eq(1)").length > 0) {
- var _height = Math.max($(window).height() - $("#log pre:eq(1)").offset().top, 250);
- $("#log").height(_height - 10);
- $("#log pre:eq(1)").css("overflow", "auto").height(_height - 50);
- }
- }
- // Result Datatable
- function cleanResultsTable() {
- if (dataTable) {
- viewModel.design.results.rows([]);
- dataTable.fnClearTable();
- dataTable.fnDestroy();
- viewModel.design.results.columns.valueHasMutated();
- viewModel.design.results.rows.valueHasMutated();
- dataTable = null;
- }
- }
- function addRowNumberToResults(data, startIndex) {
- var _tmpdata = [];
- $(data).each(function(cnt, item){
- item.unshift(cnt + startIndex + 1);
- _tmpdata.push(item);
- });
- return _tmpdata;
- }
- var _scrollTimeout = -1;
- function datatableScroll() {
- viewModel.scrollNotWorking(false);
- // Automatic results grower
- var dataTableEl = $("#results .dataTables_wrapper");
- var _lastScrollPosition = dataTableEl.data("scrollPosition") != null ? dataTableEl.data("scrollPosition") : 0;
- window.clearTimeout(_scrollTimeout);
- _scrollTimeout = window.setTimeout(function(){
- dataTableEl.data("scrollPosition", dataTableEl.scrollTop());
- if (_lastScrollPosition != dataTableEl.scrollTop() && dataTableEl.scrollTop() + dataTableEl.outerHeight() + 20 > dataTableEl[0].scrollHeight && dataTable && viewModel.hasMoreResults()) {
- dataTableEl.animate({opacity: '0.55'}, 200);
- viewModel.fetchResults();
- }
- }, 100);
- }
- var firstFnDrawcallback = false;
- var manualFetchResultCounter = 0;
- function addResults(viewModel, dataTable, startRow, nextRow) {
- if (startRow == 0) {
- firstFnDrawcallback = true;
- }
- dataTable.fnAddData(addRowNumberToResults(viewModel.design.results.rows.slice(startRow, nextRow), startRow));
- % if app_name == 'impala':
- manualFetchResultCounter += (nextRow - startRow);
- if (manualFetchResultCounter < 100 && viewModel.scrollNotWorking() && viewModel.hasMoreResults()){
- manualFetch();
- }
- else {
- manualFetchResultCounter = 0;
- }
- %endif
- }
- function resultsTable(e, data) {
- $("#results .dataTables_wrapper").animate({opacity: '1'}, 50);
- $.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query", null);
- if (viewModel.design.results.columns().length > 0) {
- if (!dataTable) {
- dataTable = $("#resultTable").dataTable({
- "bPaginate": false,
- "bLengthChange": false,
- "bInfo": false,
- "bDestroy": true,
- "bAutoWidth": false,
- "oLanguage": {
- "sEmptyTable": "${_('No data available')}",
- "sZeroRecords": "${_('No matching records')}"
- },
- "fnDrawCallback": function (oSettings) {
- reinitializeTableExtenders();
- if (firstFnDrawcallback) {
- firstFnDrawcallback = false;
- window.setTimeout(reinitializeTable, 100);
- }
- },
- "aoColumnDefs": [
- {
- "sType": "numeric",
- "aTargets": [ "sort-numeric" ]
- },
- {
- "sType": "string",
- "aTargets": [ "sort-string" ]
- },
- {
- "sType": "date",
- "aTargets": [ "sort-date" ]
- }
- ]
- });
- $(".dataTables_filter").hide();
- reinitializeTable();
- var _options = '<option value="-1">${ _("Please select a column")}</option>';
- $(viewModel.design.results.columns()).each(function(cnt, item){
- if (cnt > 0){
- _options += '<option value="'+(cnt + 1)+'">'+ item.name +'</option>';
- }
- });
- $(".blueprintSelect").html(_options);
- // Automatic results grower
- var dataTableEl = $("#results .dataTables_wrapper");
- dataTableEl.on("scroll", datatableScroll);
- }
- addResults(viewModel, dataTable, data.start_row, data.next_row);
- }
- }
- function manualFetch() {
- $("#results .dataTables_wrapper").css("opacity", "0.55");
- viewModel.fetchResults();
- }
- $(document).on('execute.query', cleanResultsTable);
- $(document).on('explain.query', cleanResultsTable);
- $(document).on('fetched.results', resultsTable);
- var selectedLine = -1;
- var errorWidgets = [];
- function clearErrorWidgets() {
- $(".jHueTableExtenderClonedContainer").hide();
- $(".jHueTableExtenderClonedContainerColumn").hide();
- $(".jHueTableExtenderClonedContainerCell").hide();
- $.each(errorWidgets, function(index, errorWidget) {
- errorWidget.clear();
- });
- errorWidgets = [];
- }
- $(document).on('execute.query', clearErrorWidgets);
- $(document).on('explain.query', clearErrorWidgets);
- $(document).on('error.query', function () {
- $.each(errorWidgets, function(index, el) {
- $(el).remove();
- errorWidgets = [];
- });
- // Move error to codeMirror if we know the line number
- $.each($(".queryErrorMessage"), function(index, el) {
- var err = $(el).text();
- var firstPos = err.toLowerCase().indexOf("line");
- if (firstPos > -1) {
- selectedLine = $.trim(err.substring(err.indexOf(" ", firstPos), err.indexOf(":", firstPos))) * 1;
- if (codeMirror.getSelection()) {
- selectedLine += codeMirror.getCursor(true).line;
- }
- errorWidgets.push(
- codeMirror.addLineWidget(
- selectedLine > 0 ? selectedLine - 1 : selectedLine,
- $("<div>").addClass("editorError").html("<i class='fa fa-exclamation-circle'></i> " + err)[0], {
- coverGutter: true,
- noHScroll: true
- }
- )
- );
- codeMirror.scrollTo(null, codeMirror.charCoords({
- line: selectedLine > 0 ? selectedLine - 1 : selectedLine,
- ch: 0
- }, "local").top - codeMirror.getScrollerElement().offsetHeight / 2 - 5);
- $(el).hide();
- }
- });
- reinitializeTableExtenders();
- });
- // Save
- function trySaveDesign() {
- var query = codeMirror.getValue();
- viewModel.design.query.value(query);
- if (viewModel.design.id() && viewModel.design.id() != -1) {
- viewModel.saveDesign();
- logGA('design/save');
- }
- }
- function saveAsModal() {
- var query = getHighlightedQuery() || codeMirror.getValue();
- viewModel.design.query.value(query);
- $('#saveAs').modal('show');
- }
- function trySaveAsDesign() {
- if (viewModel.design.query.value() && viewModel.design.name()) {
- viewModel.design.id(-1);
- viewModel.saveDesign();
- $('#saveAs').find('.help-inline').text('');
- $('#saveAs').find('.control-group').removeClass('error');
- logGA('design/save-as');
- } else if (viewModel.design.name()) {
- $.jHueNotify.error("${_('No query provided to save.')}");
- $('#saveAs').modal('hide');
- } else {
- $('#saveas-query-name').addClass('error');
- }
- }
- function saveResultsModal() {
- $("#saveResultsModal .loader").hide();
- $('#saveResultsModal').modal('show');
- }
- function trySaveResults() {
- var deferred = viewModel.saveResults();
- if (deferred) {
- $("#saveResultsModal button.btn-primary").button('loading');
- $("#saveResultsModal .loader").show();
- deferred.done(function() {
- $("#saveResultsModal button.btn-primary").button('reset');
- $("#saveResultsModal .loader").hide();
- });
- }
- logGA('results/save');
- }
- $(document).on('saved.results', function() {
- $('#saveResultsModal').modal('hide');
- });
- // Querying and click events.
- function tryExecuteQuery() {
- viewModel.scrollNotWorking(true);
- $("#results .dataTables_wrapper").off("scroll", datatableScroll);
- $(".jHueTableExtenderClonedContainer").hide();
- $(".jHueTableExtenderClonedContainerColumn").hide();
- $(".jHueTableExtenderClonedContainerCell").hide();
- $(".tooltip").remove();
- var query = getHighlightedQuery() || codeMirror.getValue();
- viewModel.design.query.value(query);
- if ($("#results .dataTables_wrapper").length > 0) { // forces results to be up
- $("#results .dataTables_wrapper").scrollTop(0);
- }
- if ($("#recentQueries .dataTables_wrapper").length > 0) { // forces results to be up
- $("#recentQueries .dataTables_wrapper").scrollTop(0);
- }
- renderRecent();
- clickHard('.resultsContainer .nav-tabs a[href="#log"]');
- graphHasBeenPredicted = false;
- if (viewModel.design.isParameterized()) {
- viewModel.fetchParameters();
- } else {
- viewModel.executeQuery();
- }
- logGA('query/execute');
- }
- function tryExecuteNextStatement() {
- viewModel.scrollNotWorking(true);
- var query = getHighlightedQuery() || codeMirror.getValue();
- // If we highlight a part of query, we update the query and restart the query history
- // In the other case we update the query but continue at the same statement we were
- if (viewModel.design.query.value() != query) {
- viewModel.design.query.value(query);
- if (getHighlightedQuery()) {
- viewModel.executeQuery();
- } else {
- viewModel.executeNextStatement();
- }
- } else {
- viewModel.executeNextStatement();
- }
- logGA('query/execute_next');
- }
- function tryExecuteParameterizedQuery() {
- viewModel.scrollNotWorking(true);
- $(".tooltip").remove();
- viewModel.executeQuery();
- routie('query');
- }
- function tryExplainQuery() {
- $(".tooltip").remove();
- var query = getHighlightedQuery() || codeMirror.getValue();
- viewModel.design.query.value(query);
- viewModel.explainQuery();
- logGA('query/explain');
- }
- function formatQuery() {
- if (vkbeautify) {
- if (codeMirror.getSelection() != '') {
- codeMirror.replaceSelection(vkbeautify.sql(codeMirror.getSelection(), 2));
- }
- else {
- codeMirror.setValue(vkbeautify.sql(codeMirror.getValue(), 2));
- }
- viewModel.design.query.value(codeMirror.getValue());
- }
- }
- function tryExplainParameterizedQuery() {
- $(".tooltip").remove();
- viewModel.explainQuery();
- routie('query');
- }
- function tryCancelQuery() {
- $(".tooltip").remove();
- viewModel.cancelQuery();
- }
- function createNewQuery() {
- $.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query", null);
- location.href="${ url(app_name + ':execute_query') }";
- }
- // Server error handling.
- $(document).on('server.error', function (e, data) {
- $(document).trigger('error', "${_('Server error occurred: ')}" + data.message ? data.message : data.error);
- });
- $(document).on('server.unmanageable_error', function (e, responseText) {
- var message = responseText;
- if (! message) {
- message = '${ _("Hue server is probably down.") }';
- }
- $(document).trigger('error', "${_('Unmanageable server error occurred: ')}" + message);
- });
- // Other
- $(document).on('saved.design', function (e, id) {
- $('#saveAs').modal('hide');
- $(document).trigger('info', "${_('Query saved.')}");
- window.location.href = "/${ app_name }/execute/design/" + id;
- });
- $(document).on('error_save.design', function (e, message) {
- var _message = "${_('Could not save design')}";
- if (typeof message == "object"){
- $('#saveAs').find('.help-inline').text('');
- $('#saveAs').find('.control-group').removeClass('error');
- if (message.saveform){
- if ($('#saveAs').is(":visible")){
- if (message.saveform.name){
- $('#saveas-query-name').addClass('error');
- $('#saveas-query-name').find('.help-inline').text(message.saveform.name.join(' '));
- }
- if (message.saveform.description) {
- $('#saveas-query-description').addClass('error');
- $('#saveas-query-name').find('.help-inline').text(message.saveform.description.join(' '));
- }
- }
- else {
- if (message.saveform.name) {
- _message += " - ${_('Name')}: " + message.saveform.name.join(' ');
- }
- if (message.saveform.description) {
- _message += " - ${_('Description')}: " + message.saveform.description.join(' ');
- }
- $(document).trigger('error', _message);
- }
- }
- }
- else {
- if (message) {
- _message += ": " + message;
- }
- $(document).trigger('error', _message);
- }
- });
- $(document).on('error_save.results', function (e, message) {
- var _message = "${_('Could not save results')}";
- if (message) {
- _message += ": " + message;
- }
- $(document).trigger('error', _message);
- });
- $(document).on('error_cancel.query', function (e, message) {
- $(document).trigger("error", "${ _('Problem: ') }" + message);
- });
- $(document).on('cancelled.query', function (e) {
- $(document).trigger("info", "${ _('Query canceled!') }")
- });
- function updateSidebarTooltips(selector) {
- $(selector).each(function(){
- $(this).tooltip({
- placement: "right",
- title: $(this).val()
- }).attr('data-original-title', $(this).val()).tooltip('fixTitle');
- });
- }
- $(document).ready(function () {
- $("*[rel=tooltip]").tooltip({
- placement: 'bottom'
- });
- // hack for select default rendered fields
- $("select").addClass("input-medium");
- // Type ahead for settings.
- $.getJSON("${ url(app_name + ':configuration') }", function (data) {
- $(".settingsField").typeahead({
- source: $.map(data.configuration, function (value, key) {
- return value.key;
- })
- });
- });
- $("#help").popover({
- 'title': "${_('Did you know?')}",
- 'content': $("#help-content").html(),
- 'trigger': 'hover',
- 'placement': 'left',
- 'html': true
- });
- $("#hdfs-directory-help").popover({
- 'title': "${_('Did you know?')}",
- 'content': $("#hdfs-directory-help-content").html(),
- 'trigger': 'hover',
- 'placement': 'right',
- 'html': true
- });
- $(document).on('click', '#save-results-simple', function() {
- $('#save-results-advanced').removeClass('hide');
- $('#save-results-simple').addClass('hide');
- $('#saveResultsForm .advanced').addClass('hide');
- });
- $(document).on('click', '#save-results-advanced', function() {
- $('#save-results-advanced').addClass('hide');
- $('#save-results-simple').removeClass('hide');
- $('#saveResultsForm .advanced').removeClass('hide');
- });
- $(document).on("change", ".settingsField", function(){
- updateSidebarTooltips(".settingsField");
- });
- $(document).on("change", ".settingValuesField", function(){
- updateSidebarTooltips(".settingValuesField");
- });
- $(document).on("change", ".filesField", function(){
- updateSidebarTooltips(".filesField");
- });
- $(document).on("change", ".functionsField", function(){
- updateSidebarTooltips(".functionsField");
- });
- $(document).on("change", ".classNamesField", function(){
- updateSidebarTooltips(".classNamesField");
- });
- // loads default
- updateSidebarTooltips(".settingsField");
- updateSidebarTooltips(".settingValuesField");
- updateSidebarTooltips(".filesField");
- updateSidebarTooltips(".functionsField");
- updateSidebarTooltips(".classNamesField");
- });
- % if app_name == 'impala':
- $(document).ready(function () {
- $("#downloadQuery").click(function () {
- $("<input>").attr("type", "hidden").attr("name", "button-submit").attr("value", "Execute").appendTo($("#advancedSettingsForm"));
- $("<input>").attr("type", "hidden").attr("name", "download").attr("value", "true").appendTo($("#advancedSettingsForm"));
- tryExecuteQuery();
- });
- $("#refresh-dyk").popover({
- 'title': "${_('Missing some tables? In order to update the list of tables/metadata seen by Impala, execute one of these queries:')}",
- 'content': $("#refresh-content").html(),
- 'trigger': 'hover',
- 'html': true
- });
- $("#refresh-tip").popover({
- 'title': "${_('Missing some tables? In order to update the list of tables/metadata seen by Impala, execute one of these queries:')}",
- 'content': $("#refresh-content").html(),
- 'trigger': 'hover',
- 'html': true
- });
- });
- % endif
- <%
- if app_name == 'impala':
- from impala import conf as impala_conf
- %>
- % if ( app_name == 'beeswax' and beeswax_conf.CLOSE_QUERIES.get() ) or ( app_name == 'impala' and impala_conf.CLOSE_QUERIES.get() ):
- $(document).ready(function () {
- $(document).on('explain.query', function() {
- viewModel.closeQuery();
- });
- $(document).on('execute.query', function() {
- viewModel.closeQuery();
- });
- // Tricks for not triggering the closing of the query on download
- $("a.download").hover(function(){
- window.onbeforeunload = null;
- },function() {
- window.onbeforeunload = $(window).data('beforeunload');
- }
- );
- });
- // Close the query when leaving the page, backup for later when disabling the close before downloading results.
- window.onbeforeunload = function(e) {
- viewModel.closeQuery();
- };
- $(window).data('beforeunload', window.onbeforeunload);
- % endif
- $(".folderChooser:not(:has(~ button))").after(getFolderBrowseButton($(".folderChooser:not(:has(~ button))"), true));
- $(".pathChooser:not(:has(~ button))").after(getPathBrowseButton($(".pathChooser:not(:has(~ button))"), true));
- // Routie
- $(document).ready(function () {
- function queryPageComponents() {
- $('#advanced-settings').show();
- $('#navigator').show();
- $('#queryContainer').show();
- $('#resizePanel').show();
- $('a[href="#query"]').parent().show();
- }
- function watchPageComponents() {
- $('#advanced-settings').hide();
- viewModel.isEditor(false);
- $('#navigator').hide();
- $('#queryContainer').hide();
- $('#resizePanel').hide();
- $('a[href="#query"]').parent().hide();
- $('a[href="#recentTab"]').parent().hide();
- }
- function queryPage() {
- queryPageComponents();
- $('.resultsContainer .watch-query').hide();
- $('.resultsContainer .view-query-results').hide();
- }
- function queryLogPage() {
- queryPageComponents();
- $('.resultsContainer .watch-query').show();
- $('.resultsContainer .view-query-results').hide();
- }
- function queryResultsPage() {
- queryPageComponents();
- $('.resultsContainer .watch-query').hide();
- $('.resultsContainer .view-query-results').show();
- $(".view-query-results[rel=tooltip]").tooltip({
- placement: 'bottom'
- });
- }
- function parametersPage() {
- queryPageComponents();
- $('.resultsContainer .watch-query').hide();
- $('.resultsContainer .view-query-results').hide();
- }
- function watchLogsPage() {
- watchPageComponents();
- $('.resultsContainer .watch-query').show();
- $('.resultsContainer .view-query-results').hide();
- }
- function watchResultsPage() {
- watchPageComponents();
- $('.resultsContainer .watch-query').hide();
- $('.resultsContainer .view-query-results').show();
- }
- routie({
- 'query': function () {
- showSection('query-editor');
- queryPage();
- codeMirror.setSize("99%", CURRENT_CODEMIRROR_SIZE);
- placeResizePanelHandle();
- },
- 'query/execute/params': function () {
- if (viewModel.design.parameters().length == 0) {
- routie('query');
- }
- showSection('execute-parameter-selection');
- parametersPage();
- },
- 'query/explain/params': function () {
- if (viewModel.design.parameters().length == 0) {
- routie('query');
- }
- showSection('explain-parameter-selection');
- parametersPage();
- },
- 'query/logs': function () {
- if (viewModel.design.watch.logs().length == 0 && viewModel.design.watch.errors().length == 0) {
- routie('query');
- }
- showSection('query-editor');
- queryLogPage();
- clickHard('.resultsContainer .nav-tabs a[href="#log"]');
- },
- 'query/results': function () {
- showSection('query-editor');
- queryResultsPage();
- clickHard('.resultsContainer .nav-tabs a[href="#results"]');
- renderRecent();
- placeResizePanelHandle();
- logGA('query/results');
- },
- 'query/explanation': function () {
- if (! viewModel.design.results.explanation()) {
- routie('query');
- }
- showSection('query-editor');
- queryResultsPage();
- clickHard('.resultsContainer .nav-tabs a[href="#explanation"]');
- },
- 'watch/logs': function() {
- showSection('query-editor');
- watchLogsPage();
- clickHard('.resultsContainer .nav-tabs a[href="#log"]');
- logGA('watch/logs');
- },
- 'watch/results': function() {
- showSection('query-editor');
- watchResultsPage();
- clickHard('.resultsContainer .nav-tabs a[href="#results"]');
- logGA('watch/results');
- },
- '*': function () {
- routie('query');
- }
- });
- });
- // Event setup
- function queryEvents() {
- $(document).on('fetched.parameters', function () {
- if (viewModel.design.parameters().length > 0) {
- routie('query/execute/params');
- } else {
- viewModel.executeQuery();
- }
- });
- $(document).on('explained.query', function () {
- routie('query/explanation');
- });
- $(document).on('watched.query', function (e, data) {
- if (data.status != 2) {
- if (data.status && data.status && data.status != 0) {
- viewModel.design.watch.errors.push(data.error || data.message);
- }
- }
- routie('query/logs');
- });
- $(document).on('error_watch.query', function () {
- routie('query/logs');
- });
- $(document).on('fetched.results', function () {
- routie('query/results');
- });
- $(document).on('execute.query', function() {
- routie('query');
- });
- $(document).ready(function() {
- routie('query');
- });
- }
- function watchEvents() {
- $(document).ready(function() {
- routie('watch/logs');
- });
- $(document).on('error_watch.query', function () {
- routie('watch/logs');
- });
- $(document).on('fetched.results', function () {
- routie('watch/results');
- });
- }
- function cacheQueryTextEvents() {
- var _waitForCodemirrorInit = -1;
- _waitForCodemirrorInit = window.setInterval(function () {
- if (typeof codeMirror != "undefined") {
- codeMirror.on("change", function () {
- $(".query").val(codeMirror.getValue());
- $.totalStorage(hac_getTotalStorageUserPrefix() + "${app_name}_temp_query", codeMirror.getValue());
- });
- window.clearInterval(_waitForCodemirrorInit);
- }
- }, 100);
- }
- function loadDesign(design_id) {
- viewModel.design.id(design_id);
- viewModel.fetchDesign();
- setupCodeMirrorSubscription();
- }
- function loadQueryHistory(query_history_id) {
- viewModel.design.history.id(query_history_id);
- viewModel.fetchQueryHistory();
- setupCodeMirrorSubscription();
- }
- function setupCodeMirrorSubscription() {
- var codeMirrorSubscription = viewModel.design.query.value.subscribe(function (value) {
- viewModel.queryEditorBlank(true);
- var _waitForCodemirrorInit = -1;
- _waitForCodemirrorInit = window.setInterval(function () {
- if (typeof codeMirror != "undefined") {
- codeMirror.setValue(value);
- codeMirrorSubscription.dispose();
- window.clearInterval(_waitForCodemirrorInit);
- }
- }, 100);
- });
- }
- // Knockout
- viewModel = new BeeswaxViewModel("${app_name}", assistHelper);
- ko.applyBindings(viewModel, $("#beeswax-execute")[0]);
- shareViewModel = initSharing("#documentShareModal");
- shareViewModel.setDocId(${doc_id});
- % if not beeswax_conf.USE_GET_LOG_API.get() and app_name != 'impala':
- viewModel.shouldAppendLogs = true;
- % endif
- % if query_history:
- loadQueryHistory(${query_history.id});
- % elif design.id:
- loadDesign(${design.id});
- % else:
- $(document).ready(cacheQueryTextEvents);
- % endif
- viewModel.design.fileResources.values.subscribe(function() {
- // File chooser button for file resources.
- $(".fileChooser:not(:has(~ button))").after(getFileBrowseButton($(".fileChooser:not(:has(~ button))")));
- });
- % if action == 'watch-results':
- $(document).ready(watchEvents);
- $(document).one('fetched.query', function(e) {
- viewModel.watchQueryLoop();
- cacheQueryTextEvents();
- });
- % elif action == 'watch-redirect':
- $(document).ready(watchEvents);
- $(document).one('fetched.query', function(e) {
- viewModel.watchQueryLoop();
- cacheQueryTextEvents();
- });
- $(document).on('stop_watch.query', function(e) {
- var successUrl = "${request.GET['on_success_url']}";
- if (viewModel.design.watch.errors().length != 0) {
- window.setTimeout(function(){
- window.location.href = successUrl + (successUrl.indexOf("?") > -1 ? "&" : "?") + "error=" + encodeURIComponent(viewModel.design.watch.errors().join("\n"));
- }, 200);
- }
- else if (viewModel.design.results.errors().length == 0) {
- window.setTimeout(function(){
- window.location.href = successUrl + (successUrl.indexOf("?") > -1 ? "&" : "?") + "refresh=true";
- }, 200);
- }
- });
- % elif action == 'editor-results':
- $(document).ready(queryEvents);
- $(document).one('fetched.query', function(e) {
- viewModel.watchQueryLoop();
- cacheQueryTextEvents();
- });
- % elif action == 'editor-expired-results':
- $(document).ready(queryEvents);
- $(document).one('fetched.query', function(e) {
- viewModel.design.results.expired(true);
- $(document).trigger('fetched.results', [ [] ]);
- cacheQueryTextEvents();
- });
- % else:
- $(document).ready(queryEvents);
- % endif
- // chart related stuff
- function pieChartDataTransformer(data) {
- var _data = [];
- $(data.counts()).each(function (cnt, item) {
- _data.push({
- label: item.value,
- value: item.count,
- obj: item
- });
- });
- if (viewModel.chartSorting() == "asc"){
- _data.sort(function(a, b){
- return a.value - b.value
- });
- }
- if (viewModel.chartSorting() == "desc"){
- _data.sort(function(a, b){
- return b.value - a.value
- });
- }
- return _data;
- }
- function leafletMapChartDataTransformer(data) {
- if (data != null && data.counts != null) return data.counts();
- }
- function barChartDataTransformer(rawDatum) {
- var _datum = [];
- var _data = [];
- $(rawDatum.counts()).each(function (cnt, item) {
- if (typeof item.from != "undefined") {
- _data.push({
- series: 0,
- x: item.from,
- x_end: item.to,
- y: item.value,
- obj: item
- });
- }
- else {
- _data.push({
- series: 0,
- x: item.value,
- y: item.count,
- obj: item
- });
- }
- });
- if (viewModel.chartSorting() == "asc"){
- _data.sort(function(a, b){
- return a.y - b.y
- });
- }
- if (viewModel.chartSorting() == "desc"){
- _data.sort(function(a, b){
- return b.y - a.y
- });
- }
- _datum.push({
- key: $("#blueprintY option:selected").text(),
- values: _data
- });
- return _datum;
- }
- function lineChartDataTransformer(rawDatum) {
- var _datum = [];
- var _data = [];
- $(rawDatum.counts()).each(function (cnt, item) {
- if (typeof item.from != "undefined") {
- _data.push({
- series: 0,
- x: item.from,
- x_end: item.to,
- y: item.value,
- obj: item
- });
- }
- else {
- _data.push({
- series: 0,
- x: item.value,
- y: item.count,
- obj: item
- });
- }
- });
- if (viewModel.chartSorting() == "asc"){
- _data.sort(function(a, b){
- return a.y - b.y
- });
- }
- if (viewModel.chartSorting() == "desc"){
- _data.sort(function(a, b){
- return b.y - a.y
- });
- }
- _datum.push({
- key: $("#blueprintY option:selected").text(),
- values: _data
- });
- return _datum;
- }
- </script>
- ${ commonfooter(request, messages) | n,unicode }
|