| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801 |
- ## 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="koComponents" file="/ko_components.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">
- <div class="tab-pane active" id="navigatorTab">
- <div class="card card-small card-tab">
- <div class="card-body" style="margin-top: 0;">
- <div class="assist" data-bind="component: { name: 'assist-panel', params: { assistHelper: assistHelper, appName: '${ app_name }' }}"></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 }"><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>
- ${_('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 data-bind="visible: !design.explain() && $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 style="margin-right: 20px"><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 style="margin-right: 20px"><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 style="margin-right: 20px"><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 style="margin-right: 20px"><i class="hfo hfo-file-xls"></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">
- </div>
- </div>
- <div class="control-group">
- <label class="control-label">${_('Description')}</label>
- <div class="controls">
- <input data-bind="value: $root.design.description, html" type="text" class="input-xlarge">
- </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">
- <a id="save-results-advanced" href="javascript:void(0)" class="pull-left">${ _('Show advanced fields') }</a>
- <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 id="navigatorQuicklook" class="modal hide fade">
- <div class="modal-header">
- <a href="#" class="close" data-dismiss="modal">×</a>
- % if has_metastore:
- <a class="tableLink pull-right" href="#" target="_blank" style="margin-right: 20px;margin-top:6px">
- <i class="fa fa-external-link"></i> ${ _('View in Metastore Browser') }
- </a>
- % endif
- <h3>${_('Data sample for')} <span class="tableName"></span></h3>
- </div>
- <div class="modal-body" style="min-height: 100px">
- <div class="loader">
- <!--[if !IE]><!--><i class="fa fa-spinner fa-spin" style="font-size: 30px; color: #DDD"></i><!--<![endif]-->
- <!--[if IE]><img src="${ static('desktop/art/spinner.gif') }"/><![endif]-->
- </div>
- <div class="sample"></div>
- </div>
- <div class="modal-footer">
- <button class="btn btn-primary disable-feedback" data-dismiss="modal">${_('Ok')}</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>
- ${ 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/assistHelper.js') }" type="text/javascript" charset="utf-8"></script>
- <script src="${ static('desktop/js/autocomplete.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/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>
- ${ koComponents.assistPanel() }
- <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;
- }
- .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;
- }
- .jobs-overlay {
- background-color: #FFF;
- opacity: 0.8;
- position: absolute;
- top: 10px;
- right: 15px;
- }
- .jobs-overlay li {
- padding: 5px;
- }
- .jobs-overlay:hover {
- opacity: 1;
- }
- #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;
- }
- </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 assistHelper = new AssistHelper({
- app: HIVE_AUTOCOMPLETE_APP,
- user: HIVE_AUTOCOMPLETE_USER
- });
- var autocompleter = new Autocompleter({
- assistHelper: assistHelper,
- mode: HIVE_AUTOCOMPLETE_APP
- });
- 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,
- 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();
- },
- stop: function (e, ui) {
- $(".jHueTableExtenderClonedContainer").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", 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);
- }
- $("a[data-row-selector='true']").jHueRowSelector();
- $("#recentLoader").hide();
- $("#recentQueries").show().css("width", "100%");
- reinitializeTableExtenders();
- });
- };
- renderRecent();
- $("#navigatorQuicklook").modal({
- show: false
- });
- $("#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() - 150) + "px");
- $("#navigator .card").css("min-height", ($(window).height() - 150) + "px");
- $(".table-container").css("max-height", ($(window).height() - 280) + "px").css("overflow-y", "auto");
- };
- huePubSub.subscribe('assist.dblClickItem', function(value) {
- codeMirror.replaceSelection(value);
- codeMirror.setSelection(codeMirror.getCursor());
- codeMirror.focus();
- });
- $("#expandResults").on("click", function(){
- $("#resultTablejHueTableExtenderClonedContainer").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("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 = _statementAtCursor.statement.substr(0, _statementAtCursor.relativeIndex).replace(/;+$/, "");
- 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 == "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
- }
- }
- }
- }
- });
- 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();
- $.each(errorWidgets, function(index, errorWidget) {
- errorWidget.clear();
- });
- errorWidgets = [];
- }
- $(document).on('execute.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
- }
- )
- );
- $(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-query-name').removeClass('error');
- $('#saveAs').modal('hide');
- 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();
- $(".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 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) {
- $(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 (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.config_values, 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();
- $('#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();
- }
- 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) {
- if (viewModel.design.results.errors().length == 0) {
- window.setTimeout(function(){
- window.location.href = "${request.GET['on_success_url']}";
- }, 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(messages) | n,unicode }
|