importer.mako 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118
  1. ## Licensed to Cloudera, Inc. under one
  2. ## or more contributor license agreements. See the NOTICE file
  3. ## distributed with this work for additional information
  4. ## regarding copyright ownership. Cloudera, Inc. licenses this file
  5. ## to you under the Apache License, Version 2.0 (the
  6. ## "License"); you may not use this file except in compliance
  7. ## with the License. You may obtain a copy of the License at
  8. ##
  9. ## http://www.apache.org/licenses/LICENSE-2.0
  10. ##
  11. ## Unless required by applicable law or agreed to in writing, software
  12. ## distributed under the License is distributed on an "AS IS" BASIS,
  13. ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ## See the License for the specific language governing permissions and
  15. ## limitations under the License.
  16. <%!
  17. from django.utils.translation import ugettext as _
  18. from desktop import conf
  19. from desktop.views import commonheader, commonfooter, commonshare, commonimportexport, _ko
  20. from indexer.conf import ENABLE_NEW_INDEXER, ENABLE_SQOOP, CONFIG_INDEXER_LIBS_PATH
  21. from notebook.conf import ENABLE_SQL_INDEXER
  22. %>
  23. <%namespace name="actionbar" file="actionbar.mako" />
  24. <%namespace name="assist" file="/assist.mako" />
  25. %if not is_embeddable:
  26. ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
  27. ## TODO lot of those re-imported
  28. <script src="${ static('desktop/js/autocomplete/sqlParseSupport.js') }"></script>
  29. <script src="${ static('desktop/js/autocomplete/sqlAutocompleteParser.js') }"></script>
  30. <script src="${ static('desktop/js/sqlAutocompleter.js') }"></script>
  31. <script src="${ static('desktop/js/sqlAutocompleter2.js') }"></script>
  32. <script src="${ static('desktop/js/hdfsAutocompleter.js') }"></script>
  33. <script src="${ static('desktop/js/autocompleter.js') }"></script>
  34. <script src="${ static('desktop/js/hue.json.js') }"></script>
  35. <script src="${ static('desktop/js/jquery.hiveautocomplete.js') }" type="text/javascript" charset="utf-8"></script>
  36. <script src="${ static('desktop/ext/js/jquery/plugins/jquery-ui-1.10.4.custom.min.js') }"></script>
  37. <script src="${ static('desktop/ext/js/selectize.min.js') }"></script>
  38. <script src="${ static('metastore/js/metastore.ko.js') }"></script>
  39. <script src="${ static('desktop/js/ko.charts.js') }"></script>
  40. <script src="${ static('desktop/ext/js/knockout-sortable.min.js') }"></script>
  41. <script src="${ static('desktop/js/ko.editable.js') }"></script>
  42. <script src="${ static('desktop/ext/js/selectize.min.js') }"></script>
  43. <script src="${ static('desktop/js/ko.selectize.js') }"></script>
  44. ${ assist.assistJSModels() }
  45. <script src="${ static('notebook/js/notebook.ko.js') }"></script>
  46. <link rel="stylesheet" href="${ static('notebook/css/notebook.css') }">
  47. <link rel="stylesheet" href="${ static('notebook/css/notebook-layout.css') }">
  48. ${ assist.assistPanel() }
  49. <link rel="stylesheet" href="${ static('desktop/ext/css/selectize.css') }">
  50. %endif
  51. <link rel="stylesheet" href="${ static('desktop/css/wizard.css') }">
  52. <link rel="stylesheet" href="${ static('indexer/css/importer.css') }" type="text/css">
  53. <style type="text/css">
  54. % if conf.CUSTOM.BANNER_TOP_HTML.get():
  55. .show-assist {
  56. top: 110px!important;
  57. }
  58. .main-content {
  59. top: 112px!important;
  60. }
  61. % endif
  62. </style>
  63. <span id="importerComponents" class="notebook importer-main" data-bind="dropzone: { url: '/filebrowser/upload/file?dest=' + DropzoneGlobals.homeDir, params: {dest: DropzoneGlobals.homeDir}, paramName: 'hdfs_file', onComplete: function(path){ createWizard.source.path(path); } }">
  64. <div class="dz-message" data-dz-message></div>
  65. <div class="navbar hue-title-bar">
  66. <div class="navbar-inner">
  67. <div class="container-fluid">
  68. <div class="nav-collapse">
  69. <ul class="nav">
  70. <li class="app-header">
  71. <a href="${ url('indexer:importer') }">
  72. <!-- ko if: createWizard.prefill.target_type().length == 0 -->
  73. <i class="fa fa-database app-icon"></i> ${_('Importer')}
  74. <!-- /ko -->
  75. <!-- ko ifnot: createWizard.prefill.target_type().length == 0 -->
  76. <!-- ko if: createWizard.prefill.target_type() === 'index' -->
  77. <i class="fa fa-search app-icon"></i> ${_('Import to index')}
  78. <!-- /ko -->
  79. <!-- ko if: createWizard.prefill.target_type() === 'table' -->
  80. <i class="fa fa-database app-icon"></i> ${_('Import to table')}
  81. <!-- /ko -->
  82. <!-- ko if: createWizard.prefill.target_type() === 'database' -->
  83. <i class="fa fa-database app-icon"></i> ${_('Create a new database')}
  84. <!-- /ko -->
  85. <!-- /ko -->
  86. </a>
  87. </li>
  88. </ul>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. %if not is_embeddable:
  94. <a title="${_('Toggle Assist')}" class="pointer show-assist" data-bind="visible: !$root.isLeftPanelVisible() && $root.assistAvailable(), click: function() { $root.isLeftPanelVisible(true); }">
  95. <i class="fa fa-chevron-right"></i>
  96. </a>
  97. %endif
  98. <div class="main-content">
  99. <div class="vertical-full container-fluid" data-bind="style: { 'padding-left' : $root.isLeftPanelVisible() ? '0' : '20px' }">
  100. <div class="vertical-full">
  101. <div class="vertical-full row-fluid panel-container">
  102. %if not is_embeddable:
  103. <div class="assist-container left-panel" data-bind="visible: $root.isLeftPanelVisible() && $root.assistAvailable()">
  104. <a title="${_('Toggle Assist')}" class="pointer hide-assist" data-bind="click: function() { $root.isLeftPanelVisible(false) }">
  105. <i class="fa fa-chevron-left"></i>
  106. </a>
  107. <div class="assist" data-bind="component: {
  108. name: 'assist-panel',
  109. params: {
  110. user: '${user.username}',
  111. onlySql: false,
  112. sql: {
  113. navigationSettings: {
  114. openItem: false,
  115. showStats: true
  116. }
  117. },
  118. visibleAssistPanels: ['sql', 'hdfs', 'documents']
  119. }
  120. }"></div>
  121. </div>
  122. <div class="resizer" data-bind="visible: $root.isLeftPanelVisible() && $root.assistAvailable(), splitDraggable : { appName: 'notebook', leftPanelVisible: $root.isLeftPanelVisible }"><div class="resize-bar">&nbsp;</div></div>
  123. %endif
  124. <div class="content-panel">
  125. <div class="content-panel-inner">
  126. <!-- ko template: 'create-index-wizard' --><!-- /ko -->
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. <script type="text/html" id="create-index-wizard">
  134. <div data-bind="visible: createWizard.show">
  135. <div class="step-indicator-fixed">
  136. <ol class="list-inline text-center step-indicator">
  137. <li data-bind="css: { 'active': currentStep() == 1, 'complete': currentStep() > 1, 'pointer': currentStep() > 1 }, click: function() { currentStep(1) }">
  138. <div class="step" title="${ _('Go to Step 1') }">
  139. <!-- ko if: currentStep() == 1 -->
  140. <!-- ko if: createWizard.isGuessingFormat -->
  141. <span class="fa fa-spinner fa-spin"></span>
  142. <!-- /ko -->
  143. <!-- ko ifnot: createWizard.isGuessingFormat -->
  144. 1
  145. <!-- /ko -->
  146. <!-- /ko -->
  147. <!-- ko ifnot: currentStep() == 1 -->
  148. <span class="fa fa-check"></span>
  149. <!-- /ko -->
  150. </div>
  151. <div class="caption">
  152. <!-- ko if: createWizard.source.inputFormat() != 'manual' -->
  153. ${ _('Pick data from ') }<span data-bind="text: createWizard.source.inputFormat"></span> <span data-bind="text: createWizard.source.path"></span>
  154. <!-- /ko -->
  155. <!-- ko if: createWizard.source.inputFormat() == 'manual' -->
  156. ${ _('No source data') }
  157. <!-- /ko -->
  158. </div>
  159. </li>
  160. <li data-bind="css: { 'inactive': currentStep() == 1, 'active': currentStep() == 2, 'complete': currentStep() == 3, 'pointer': currentStep() == 1 && !createWizard.isGuessingFormat() && createWizard.source.show() }, click: function() { if (!createWizard.isGuessingFormat() && createWizard.source.show()){ currentStep(2); }}">
  161. <div class="step" title="${ _('Go to Step 2') }">
  162. <!-- ko if: currentStep() < 3 -->
  163. <!-- ko if: createWizard.isGuessingFieldTypes -->
  164. <span class="fa fa-spinner fa-spin"></span>
  165. <!-- /ko -->
  166. <!-- ko ifnot: createWizard.isGuessingFieldTypes -->
  167. 2
  168. <!-- /ko -->
  169. <!-- /ko -->
  170. </div>
  171. <div class="caption">
  172. <!-- ko if: createWizard.source.inputFormat() != 'manual' -->
  173. ${ _('Move it to ') }
  174. <!-- /ko -->
  175. <!-- ko if: createWizard.source.inputFormat() == 'manual' -->
  176. ${ _('Create') }
  177. <!-- /ko -->
  178. <span data-bind="text: createWizard.destination.outputFormat"></span> <span data-bind="text: createWizard.destination.name"></span>
  179. </div>
  180. </li>
  181. </ol>
  182. </div>
  183. <div class="vertical-spacer"></div>
  184. <!-- ko if: currentStep() == 1 -->
  185. <div class="card step">
  186. <h4>${_('Source')}</h4>
  187. <div class="card-body">
  188. <div>
  189. <div class="control-group" data-bind="visible: createWizard.prefill.target_type().length == 0 || createWizard.prefill.source_type() == 'all'">
  190. <label for="sourceType" class="control-label"><div>${ _('Type') }</div>
  191. <select id="sourceType" data-bind="selectize: createWizard.source.inputFormats, value: createWizard.source.inputFormat, optionsText: 'name', optionsValue: 'value'"></select>
  192. </label>
  193. </div>
  194. <div class="control-group" data-bind="visible: createWizard.source.inputFormat() == 'rdbms'">
  195. <label for="rdbmsMode" class="control-label"><div>${ _('Mode') }</div>
  196. <label class="radio inline-block margin-right-20">
  197. <input type="radio" name="rdbmsMode" value="customRdbms" data-bind="checked: createWizard.source.rdbmsMode" /> ${_('Custom')}
  198. </label>
  199. <label class="radio inline-block">
  200. <input type="radio" name="rdbmsMode" value="configRdbms" data-bind="checked: createWizard.source.rdbmsMode" /> ${_('Configured')}
  201. </label>
  202. </label>
  203. </div>
  204. <div class="control-group" data-bind="visible: createWizard.prefill.target_type() == 'database'">
  205. <label for="sourceType" class="control-label">${ _('No source is needed for creating a database.') }</label>
  206. </div>
  207. <div class="control-group input-append" data-bind="visible: createWizard.source.inputFormat() == 'file'">
  208. <label for="path" class="control-label"><div>${ _('Path') }</div>
  209. <input type="text" class="form-control path filechooser-input input-xxlarge" data-bind="value: createWizard.source.path, filechooser: createWizard.source.path, filechooserOptions: { linkMarkup: true, skipInitialPathIfEmpty: true, openOnFocus: true, selectFolder: false }" placeholder="${ _('Click or drag from the assist') }">
  210. </label>
  211. <!-- ko if: createWizard.source.path().length > 0 -->
  212. <a data-bind="hueLink: '/filebrowser/view=' + createWizard.source.path()" title="${ _('Open') }" style="font-size: 14px" class="margin-left-10">
  213. <i class="fa fa-external-link-square"></i>
  214. </a>
  215. <!-- /ko -->
  216. </div>
  217. <!-- ko if: createWizard.source.inputFormat() == 'rdbms' -->
  218. <!-- ko if: createWizard.source.rdbmsMode() -->
  219. <div class="control-group">
  220. <label for="rdbmsType" class="control-label"><div>${ _('Driver') }</div>
  221. <select id="rdbmsType" data-bind="selectize: createWizard.source.rdbmsTypes, value: createWizard.source.rdbmsType, optionsText: 'name', optionsValue: 'value'"></select>
  222. </label>
  223. </div>
  224. <!-- /ko -->
  225. <!-- ko if: createWizard.source.rdbmsMode() == 'customRdbms' -->
  226. <div class="control-group input-append">
  227. <label for="rdbmsHostname" class="control-label"><div>${ _('Hostname') }</div>
  228. <input type="text" class="input-xxlarge" data-bind="value: createWizard.source.rdbmsHostname" placeholder="${ _('Enter host/ip here eg. mysql.domain.com or 123.123.123.123') }">
  229. </label>
  230. </div>
  231. <div class="control-group input-append">
  232. <label for="rdbmsPort" class="control-label"><div>${ _('Port') }</div>
  233. <input type="text" class="input-xxlarge" data-bind="value: createWizard.source.rdbmsPort" placeholder="${ _('Enter port number here eg. 3306') }">
  234. </label>
  235. </div>
  236. <div class="control-group input-append">
  237. <label for="rdbmsUsername" class="control-label"><div>${ _('Username') }</div>
  238. <input type="text" class="input-xxlarge" data-bind="value: createWizard.source.rdbmsUsername" placeholder="${ _('Enter username here') }">
  239. </label>
  240. </div>
  241. <div class="control-group input-append">
  242. <label for="rdbmsPassword" class="control-label"><div>${ _('Password') }</div>
  243. <input type="password" class="input-xxlarge" data-bind="value: createWizard.source.rdbmsPassword" placeholder="${ _('Enter password here') }">
  244. </label>
  245. </div>
  246. <div class="control-group">
  247. <button class="btn" data-bind="enable: $root.createWizard.source.rdbmsHostname().length > 0 && $root.createWizard.source.rdbmsPort().length > 0 && $root.createWizard.source.rdbmsUsername().length > 0 && $root.createWizard.source.rdbmsPassword().length > 0, click: createWizard.source.rdbmsCheckConnection">
  248. ${_('Test Connection')}
  249. </button>
  250. </div>
  251. <!-- /ko -->
  252. <!-- ko if: createWizard.source.rdbmsMode() == 'configRdbms' || (createWizard.source.rdbmsMode() == 'customRdbms' && createWizard.source.rdbmsDbIsValid()) -->
  253. <!-- ko if: createWizard.source.rdbmsType -->
  254. <div class="control-group input-append">
  255. <label for="rdbmsDatabaseName" class="control-label"><div>${ _('Database Name') }</div>
  256. <select id="rdbmsDatabaseName" data-bind="selectize: createWizard.source.rdbmsDatabaseNames, value: createWizard.source.rdbmsDatabaseName, optionsText: 'name', optionsValue: 'value'"></select>
  257. </label>
  258. </div>
  259. <!-- /ko -->
  260. <!-- ko if: createWizard.source.rdbmsDatabaseName -->
  261. <div class="control-group input-append">
  262. <!-- ko ifnot: createWizard.source.rdbmsAllTablesSelected() -->
  263. <label for="rdbmsTableName" class="control-label"><div>${ _('Table Name') }</div>
  264. <select id="rdbmsTableName" data-bind="selectize: createWizard.source.rdbmsTableNames, value: createWizard.source.rdbmsTableName, optionsText: 'name', optionsValue: 'value'"></select>
  265. </label>
  266. <!-- /ko -->
  267. <label class="checkbox inline-block">
  268. <input type="checkbox" data-bind="checked: createWizard.source.rdbmsIsAllTables"> ${_('All Tables')}
  269. </label>
  270. </div>
  271. <!-- /ko -->
  272. <!-- /ko -->
  273. <!-- /ko -->
  274. <div class="control-group" data-bind="visible: createWizard.source.inputFormat() == 'table'">
  275. <label for="path" class="control-label"><div>${ _('Table') }</div>
  276. <input type="text" class="input-xlarge" data-bind="value: createWizard.source.table, hivechooser: createWizard.source.table, skipColumns: true, apiHelperUser: '${ user }', apiHelperType: createWizard.source.apiHelperType, mainScrollable: $(MAIN_SCROLLABLE)" placeholder="${ _('Table name or <database>.<table>') }">
  277. </label>
  278. </div>
  279. <div class="control-group" data-bind="visible: createWizard.source.inputFormat() == 'query'">
  280. <label for="path" class="control-label"><div>${ _('Query') }</div>
  281. <select placeholder="${ _('Search your documents...') }" data-bind="documentChooser: { dependentValue: createWizard.source.draggedQuery, mappedDocument: createWizard.source.query }"></select>
  282. </label>
  283. </div>
  284. </div>
  285. </div>
  286. </div>
  287. <!-- ko if: createWizard.source.show() && createWizard.source.inputFormat() != 'manual' -->
  288. <div class="card step" data-bind="visible: createWizard.source.inputFormat() == 'file'">
  289. <!-- ko if: createWizard.isGuessingFormat -->
  290. <h4>${_('Guessing format...')} <i class="fa fa-spinner fa-spin"></i></h4>
  291. <!-- /ko -->
  292. <!-- ko ifnot: createWizard.isGuessingFormat -->
  293. <h4>${_('Format')}</h4>
  294. <div class="card-body">
  295. <label data-bind="visible: createWizard.prefill.source_type().length == 0 && createWizard.source.inputFormat() != 'table'">
  296. <div>${_('File Type')}</div>
  297. <select data-bind="selectize: $root.createWizard.fileTypes, value: $root.createWizard.fileTypeName, optionsText: 'description', optionsValue: 'name'"></select>
  298. </label>
  299. <span class="inline-labels" data-bind="with: createWizard.source.format, visible: createWizard.source.show">
  300. <span data-bind="foreach: getArguments()">
  301. <!-- ko template: {name: 'arg-' + $data.type, data: {description: $data.description, value: $parent[$data.name]}}--><!-- /ko -->
  302. </span>
  303. </span>
  304. </div>
  305. <!-- /ko -->
  306. </div>
  307. <!-- ko ifnot: createWizard.source.inputFormat() == 'rdbms' && createWizard.source.rdbmsIsAllTables() -->
  308. <div class="card step" style="min-height: 310px;">
  309. <!-- ko ifnot: createWizard.isGuessingFormat -->
  310. <!-- ko if: createWizard.isGuessingFieldTypes -->
  311. <h4>${_('Generating preview...')} <i class="fa fa-spinner fa-spin"></i></h4>
  312. <!-- /ko -->
  313. <!-- ko ifnot: createWizard.isGuessingFieldTypes -->
  314. <h4>${_('Preview')}</h4>
  315. <div class="card-body">
  316. <div style="overflow: auto">
  317. <table class="table table-condensed table-preview">
  318. <thead>
  319. <tr data-bind="foreach: createWizard.source.sampleCols">
  320. ##<!-- ko template: 'field-preview-header-template' --><!-- /ko -->
  321. <th data-bind="truncatedText: name" style="padding-right:60px"></th>
  322. ## TODO nested
  323. </tr>
  324. </thead>
  325. <tbody data-bind="foreach: createWizard.source.sample">
  326. <tr data-bind="foreach: $data">
  327. <td data-bind="truncatedText: $data"></td>
  328. </tr>
  329. </tbody>
  330. </table>
  331. </div>
  332. </div>
  333. <!-- /ko -->
  334. <!-- /ko -->
  335. </div>
  336. <!-- /ko -->
  337. <!-- /ko -->
  338. <!-- /ko -->
  339. <!-- ko if: currentStep() == 2 -->
  340. <!-- ko with: createWizard.destination -->
  341. <div class="card step">
  342. <h4>${_('Destination')}</h4>
  343. <div class="card-body">
  344. <div class="control-group">
  345. <label for="destinationType" class="control-label" data-bind="visible: $parent.createWizard.prefill.target_type().length == 0"><div>${ _('Type') }</div>
  346. <select id="destinationType" data-bind="selectize: outputFormats, value: outputFormat, optionsValue: 'value', optionsText: 'name'"></select>
  347. </label>
  348. </div>
  349. <div class="control-group">
  350. <label for="collectionName" class="control-label "><div>${ _('Name') }</div></label>
  351. <!-- ko if: outputFormat() == 'file' -->
  352. <input type="text" class="form-control name input-xlarge" id="collectionName" data-bind="value: name, filechooser: name, filechooserOptions: { linkMarkup: true, skipInitialPathIfEmpty: true, openOnFocus: true, selectFolder: true, displayOnlyFolders: true, uploadFile: false}" placeholder="${ _('Name') }" title="${ _('Directory must not exist in the path') }">
  353. <!-- /ko -->
  354. <!-- ko if: outputFormat() == 'index' -->
  355. <input type="text" class="form-control input-xlarge" id="collectionName" data-bind="value: name, valueUpdate: 'afterkeydown'" placeholder="${ _('Name') }">
  356. <!-- /ko -->
  357. <!-- ko if: ['table', 'database'].indexOf(outputFormat()) != -1 -->
  358. <input type="text" data-bind="value: name, hivechooser: name, skipColumns: true, skipTables: outputFormat() == 'database', valueUpdate: 'afterkeydown', apiHelperUser: '${ user }', apiHelperType: apiHelperType, mainScrollable: $(MAIN_SCROLLABLE), attr: { 'placeholder': outputFormat() == 'table' ? '${ _ko('Table name or <database>.<table>') }' : '${ _ko('Database name') }' }" pattern="^([a-zA-Z0-9_]+\.)?[a-zA-Z0-9_]*$" title="${ _('Only alphanumeric and underscore characters') }">
  359. <!-- /ko -->
  360. <span class="help-inline muted" data-bind="visible: !isTargetExisting() && isTargetChecking()">
  361. <i class="fa fa-spinner fa-spin"></i>
  362. </span>
  363. <span class="help-inline muted" data-bind="visible: ! $parent.createWizard.isValidDestination()">
  364. <i class="fa fa-warning" style="color: #c09853"></i> ${ _('Empty name or invalid characters') }
  365. </span>
  366. <span class="help-inline muted" data-bind="visible: isTargetExisting()">
  367. <!-- ko if: outputFormat() == 'index' -->
  368. ${ _('Adding data to the existing ') } <span data-bind="text: outputFormat"></span>
  369. <!-- /ko -->
  370. <!-- ko if: outputFormat() != 'index' -->
  371. <i class="fa fa-warning" style="color: #c09853"></i> ${ _('Already existing') } <span data-bind="text: outputFormat"></span>
  372. <!-- /ko -->
  373. <a href="javascript:void(0)" data-bind="hueLink: existingTargetUrl(), text: name" title="${ _('Open') }"></a>
  374. </span>
  375. </div>
  376. </div>
  377. </div>
  378. <!-- ko if: outputFormat() == 'table' && $root.createWizard.source.inputFormat() != 'rdbms' -->
  379. <div class="card step">
  380. <h4>${_('Properties')}</h4>
  381. <div class="card-body">
  382. <div class="control-group">
  383. <label for="destinationFormat" class="control-label"><div>${ _('Format') }</div>
  384. <select id="destinationFormat" data-bind="selectize: tableFormats, value: tableFormat, optionsValue: 'value', optionsText: 'name'"></select>
  385. </label>
  386. </div>
  387. <div class="control-group">
  388. <label class="checkbox inline-block" data-bind="visible: tableFormat() != 'kudu'">
  389. <input type="checkbox" data-bind="checked: useDefaultLocation"> ${_('Store in Default location')}
  390. </label>
  391. </div>
  392. <div class="control-group" data-bind="visible: !useDefaultLocation()">
  393. <label for="path" class="control-label"><div>${ _('External location') }</div>
  394. <input type="text" class="form-control path filechooser-input input-xxlarge" data-bind="value: nonDefaultLocation, filechooser: nonDefaultLocation, filechooserOptions: { linkMarkup: true, skipInitialPathIfEmpty: true }, valueUpdate: 'afterkeydown'">
  395. </label>
  396. </div>
  397. <div class="control-group">
  398. <label class="control-label"><div>${ _('Extras') }</div>
  399. <a href="javascript:void(0)" data-bind="css: { 'inactive-action': !showProperties() }, click: function() { showProperties(!showProperties()) }" title="${ _('Show extra properties') }">
  400. <i class="fa fa-sliders fa-padding-top"></i>
  401. </a>
  402. </label>
  403. </div>
  404. <span data-bind="visible: showProperties">
  405. <div class="control-group">
  406. <label class="checkbox inline-block" data-bind="visible: $root.createWizard.source.inputFormat() != 'manual'">
  407. <input type="checkbox" data-bind="checked: importData, disable: !useDefaultLocation() && $parent.createWizard.source.path() == nonDefaultLocation();"> ${_('Import data')}
  408. </label>
  409. </div>
  410. <div class="control-group">
  411. <label><div>${ _('Description') }</div>
  412. <input type="text" class="form-control input-xxlarge" data-bind="value: description, valueUpdate: 'afterkeydown'" placeholder="${ _('Description') }">
  413. </label>
  414. </div>
  415. <div class="control-group" data-bind="visible: $root.createWizard.source.inputFormat() == 'file'">
  416. <label class="checkbox inline-block">
  417. <input type="checkbox" data-bind="checked: hasHeader"> ${_('Use first row as header')}
  418. </label>
  419. </div>
  420. <div class="control-group" data-bind="visible: tableFormat() == 'text'">
  421. <label class="checkbox inline-block">
  422. <input type="checkbox" data-bind="checked: useCustomDelimiters"> ${_('Custom char delimiters')}
  423. </label>
  424. </div>
  425. <span class="inline-labels" data-bind="visible: tableFormat() == 'text' && useCustomDelimiters()">
  426. <label for="fieldDelimiter" class="control-label"><div>${ _('Field') }</div>
  427. <select id="fieldDelimiter" data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { onOptionAdd: function(value){ $root.createWizard.customDelimiters.push({ 'value': value, 'name': value }) }, create: true, maxLength: 2 }, value: customFieldDelimiter, optionsValue: 'value', optionsText: 'name'"></select>
  428. </label>
  429. <label for="collectionDelimiter" class="control-label"><div>${ _('Array, Map') }</div>
  430. <select id="collectionDelimiter" data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { onOptionAdd: function(value){ $root.createWizard.customDelimiters.push({ 'value': value, 'name': value }) }, create: true, maxLength: 2 }, value: customCollectionDelimiter, optionsValue: 'value', optionsText: 'name'"></select>
  431. </label>
  432. <label for="structDelimiter" class="control-label"><div>${ _('Struct') }</div>
  433. <select id="structDelimiter" data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { onOptionAdd: function(value){ $root.createWizard.customDelimiters.push({ 'value': value, 'name': value }) }, create: true, maxLength: 2 }, value: customMapDelimiter, optionsValue: 'value', optionsText: 'name'"></select>
  434. </label>
  435. </span>
  436. </span>
  437. <div class="control-group" data-bind="visible: tableFormat() == 'regexp'">
  438. <label for="customRegexp" class="control-label"><div>${ _('Regexp') }</div>
  439. <input id="customRegexp" class="input-xxlarge" type="text" data-bind="value: customRegexp" placeholder='([^]*) ([^]*) ([^]*) (-|\\[^\\]*\\]) ([^ \"]*|\"[^\"]*\") (-|[0-9]*) (-|[0-9]*)(?: ([^ \"]*|\".*\") ([^ \"]*|\".*\"))?'>
  440. </label>
  441. </div>
  442. <div class="control-group" data-bind="visible: tableFormat() == 'kudu'">
  443. <label for="kuduPksTable" class="control-label"><div>${ _('Primary keys') }</div>
  444. ## At least one selected
  445. <select id="kuduPksTable" data-bind="selectize: columns, selectedOptions: primaryKeys, selectedObjects: primaryKeyObjects, optionsValue: 'name', optionsText: 'name', innerSubscriber: 'name'" size="3" multiple="true"></select>
  446. </label>
  447. </div>
  448. <label class="control-label"><div>${ _('Partitions') }</div>
  449. <!-- ko if: tableFormat() != 'kudu' && $root.createWizard.source.inputFormat() != 'rdbms' -->
  450. <div class="inline-table">
  451. <div class="form-inline" data-bind="foreach: partitionColumns">
  452. <a class="pointer pull-right margin-top-20" data-bind="click: function() { $parent.partitionColumns.remove($data); }"><i class="fa fa-minus"></i></a>
  453. <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field inline-block"></div>
  454. <div class="clearfix"></div>
  455. </div>
  456. <a data-bind="click: function() { partitionColumns.push($root.loadDefaultField({isPartition: true})); }" class="pointer" title="${_('Add Partition')}"><i class="fa fa-plus fa-padding-top"></i> ${_('Add partition')}</a>
  457. </div>
  458. <!-- /ko -->
  459. <!-- ko if: tableFormat() == 'kudu' -->
  460. <div class="form-inline inline-table">
  461. <ul class="unstyled kudu-partitions" data-bind="foreach: kuduPartitionColumns">
  462. <li>
  463. <a class="pointer pull-right" data-bind="click: function() { $parent.kuduPartitionColumns.remove($data); }"><i class="fa fa-minus"></i></a>
  464. <select data-bind="selectize: $parent.primaryKeyObjects, selectedOptions: columns, optionsValue: 'name', optionsText: 'name', selectizeOptions: { placeholder: '${ _ko('Columns...') }' }" size="3" multiple="true"></select>
  465. <select data-bind="selectize: ['RANGE BY', 'HASH'], value: name"></select>
  466. <!-- ko if: name() == 'HASH' -->
  467. <input class="input-small" type="number" data-bind="value: int_val">
  468. <!-- /ko -->
  469. <!-- ko if: name() == 'RANGE BY' -->
  470. <div class="form-inline" data-bind="foreach: range_partitions">
  471. <div class="range-partition">
  472. <a class="pull-right" data-bind="click: function() { $parent.range_partitions.remove($data); }"><i class="fa fa-minus"></i></a>
  473. <!-- ko if: name() == 'VALUES' -->
  474. <input type="text" class="input-small" data-bind="value: lower_val">
  475. <select data-bind="selectize: ['<', '<='], value: include_lower_val"></select>
  476. <select data-bind="selectize: ['VALUES', 'VALUE'], value: name"></select>
  477. <select data-bind="selectize: ['<', '<='], value: include_upper_val"></select>
  478. <input type="text" class="input-small" data-bind="value: upper_val">
  479. <!-- /ko -->
  480. <!-- ko if: name() == 'VALUE' -->
  481. <select data-bind="selectize: ['VALUES', 'VALUE'], value: name"></select>
  482. <div class="inline-block" data-bind="foreach: values" style="max-width: 370px">
  483. <input class="input-small" type="text" data-bind="textInput: value" style="margin-bottom: 5px">
  484. <a data-bind="click: function() { $parent.values.remove($data); }"><i class="fa fa-minus"></i></a>
  485. </div>
  486. <a class="inline-block" data-bind="click: function() { values.push(ko.mapping.fromJS({value: ''})); }" title="${_('Add value')}"><i class="fa fa-plus"></i></a>
  487. <div class="clearfix"></div>
  488. <!-- /ko -->
  489. </div>
  490. </div>
  491. <a data-bind="click: function() { range_partitions.push(ko.mapping.fromJS($parent.KUDU_DEFAULT_RANGE_PARTITION_COLUMN)); }" title="${_('Add column')}"><i class="fa fa-plus"></i></a>
  492. <!-- /ko -->
  493. <!-- /ko -->
  494. </li>
  495. </ul>
  496. <a data-bind="click: function() { kuduPartitionColumns.push(ko.mapping.fromJS(KUDU_DEFAULT_PARTITION_COLUMN)); }" class="pointer" title="${_('Add partition')}"><i class="fa fa-plus"></i> ${_('Add partition')}</a>
  497. </div>
  498. <!-- /ko -->
  499. </label>
  500. </div>
  501. </div>
  502. <!-- /ko -->
  503. <!-- ko if: outputFormat() == 'index' -->
  504. <div class="card step">
  505. <h4>${_('Properties')}</h4>
  506. <div class="card-body">
  507. <div class="control-group">
  508. <label class="checkbox inline-block" title="${ _('Execute a cluster job to index a large dataset.') }" data-bind="visible: $root.createWizard.source.inputFormat() != 'manual'">
  509. <input type="checkbox" data-bind="checked: indexerRunJob"> ${_('Index with a job')}
  510. </label>
  511. <label for="path" class="control-label" data-bind="visible: indexerRunJob"><div>${ _('Libs') }</div>
  512. <input type="text" class="form-control path filechooser-input input-xlarge" data-bind="value: indexerJobLibPath, filechooser: indexerJobLibPath, filechooserOptions: { linkMarkup: true, skipInitialPathIfEmpty: true }, valueUpdate: 'afterkeydown'">
  513. </label>
  514. <!-- ko if: indexerRunJob() && indexerJobLibPath().length > 0 -->
  515. <a data-bind="hueLink: '/filebrowser/view=' + indexerJobLibPath()" title="${ _('Open') }" style="font-size: 14px" class="margin-left-10">
  516. <i class="fa fa-external-link-square"></i>
  517. </a>
  518. <!-- /ko -->
  519. </div>
  520. <div class="control-group">
  521. <label for="kuduPksIndex" class="control-label"><div>${ _('Primary key') }</div>
  522. <select id="kuduPksIndex" data-bind="selectize: columns, selectedOptions: indexerPrimaryKey, selectedObjects: indexerPrimaryKeyObject, optionsValue: 'name', optionsText: 'name', innerSubscriber: 'name'" size="1" multiple="false"></select>
  523. </label>
  524. </div>
  525. <div class="control-group">
  526. <label for="kuduDefaultField" class="control-label"><div>${ _('Default field') }</div>
  527. <select id="kuduDefaultField" data-bind="selectize: columns, selectedOptions: indexerDefaultField, selectedObjects: indexerDefaultFieldObject, optionsValue: 'name', optionsText: 'name', innerSubscriber: 'name'" size="1" multiple="false"></select>
  528. </label>
  529. </div>
  530. <div class="control-group">
  531. <label class="control-label"><div>${ _('Extras') }</div>
  532. <a href="javascript:void(0)" data-bind="css: { 'inactive-action': !showProperties() }, click: function() { showProperties(!showProperties()) }" title="${ _('Show extra properties') }">
  533. <i class="fa fa-sliders fa-padding-top"></i>
  534. </a>
  535. </label>
  536. </div>
  537. <span data-bind="visible: showProperties">
  538. <div class="control-group">
  539. <label for="destinationFormatIndex" class="control-label"><div>${ _('Config set') }</div>
  540. <select id="destinationFormatIndex" data-bind="selectize: indexerConfigSets, value: indexerConfigSet, optionsValue: 'value', optionsText: 'name'"></select>
  541. </label>
  542. </div>
  543. <div class="control-group">
  544. <label for="indexerNumShards" class="control-label"><div>${ _('Num shards') }</div>
  545. <input type="number" class="input-small" placeholder="1" data-bind="value: indexerNumShards">
  546. </label>
  547. </div>
  548. <div class="control-group">
  549. <label for="indexerReplicationFactor" class="control-label"><div>${ _('Replication factor') }</div>
  550. <input type="number" class="input-small" placeholder="1" data-bind="value: indexerReplicationFactor">
  551. </label>
  552. </div>
  553. ## Router, maxShardsPer, shards, routerField
  554. <div class="control-group" data-bind="visible: $root.createWizard.source.inputFormat() == 'file'">
  555. <label class="checkbox inline-block">
  556. <input type="checkbox" data-bind="checked: hasHeader"> ${_('Use first row as header')}
  557. </label>
  558. </div>
  559. </span>
  560. </div>
  561. </div>
  562. <!-- /ko -->
  563. <!-- ko if: $root.createWizard.source.inputFormat() == 'rdbms' && ['file', 'table', 'hbase'].indexOf(outputFormat()) != -1 -->
  564. <div class="card step">
  565. <h4>${_('Properties')}</h4>
  566. <div class="control-group">
  567. <label><div>${ _('Mappers') }</div>
  568. <input type="number" class="form-control input-small" data-bind="value: numMappers, valueUpdate: 'afterkeydown'">
  569. </label>
  570. </div>
  571. <div class="card-body">
  572. <label class="control-label"><div>${ _('Libs') }</div>
  573. <div class="inline-table">
  574. <ul data-bind="sortable: { data: sqoopJobLibPaths, options: { axis: 'y', containment: 'parent', handle: '.move-widget' }}, visible: sqoopJobLibPaths().length" class="unstyled">
  575. <li>
  576. <div class="input-append" style="margin-bottom: 4px">
  577. <input type="text" class="filechooser-input input-xxlarge" data-bind="value: path, valueUpdate:'afterkeydown', filechooser: { value: path, isAddon: true }, filechooserOptions: { skipInitialPathIfEmpty: true }" placeholder="${ _('Path to the file, e.g. hdfs://localhost:8020/user/hue/file.hue') }"/>
  578. <span class="add-on move-widget muted" data-bind="visible: $parent.sqoopJobLibPaths().length > 1"><i class="fa fa-arrows"></i></span>
  579. <a class="add-on muted" href="javascript: void(0);" data-bind="click: function(){ $parent.removeSqoopJobLibPath($data); }"><i class="fa fa-minus"></i></a>
  580. </div>
  581. </li>
  582. </ul>
  583. <div class="config-property-add-value" style="margin-top: 5px;">
  584. <a class="inactive-action pointer" style="padding: 3px 10px 3px 3px;;" data-bind="click: addSqoopJobLibPath">
  585. <i class="fa fa-plus"></i>
  586. </a>
  587. </div>
  588. </div>
  589. </label>
  590. </div>
  591. </div>
  592. <!-- /ko -->
  593. <!-- ko if: ['table', 'index', 'file', 'hbase'].indexOf(outputFormat()) != -1 -->
  594. <div class="card step">
  595. <h4 class="show-edit-on-hover">${_('Fields')} <!-- ko if: $root.createWizard.isGuessingFieldTypes --><i class="fa fa-spinner fa-spin"></i><!-- /ko --> <a class="inactive-action pointer" data-bind="visible: columns().length > 0" href="#fieldsBulkEditor" data-toggle="modal"><i class="fa fa-edit"></i></a></h4>
  596. <div class="card-body no-margin-top columns-form">
  597. <!-- ko if: $root.createWizard.source.inputFormat() === 'manual' -->
  598. <form class="form-inline inline-table" data-bind="foreach: columns">
  599. <!-- ko if: $parent.outputFormat() == 'table' -->
  600. <a class="pointer pull-right margin-top-20" data-bind="click: function() { $parent.columns.remove($data); }"><i class="fa fa-minus"></i></a>
  601. <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field inline-block"></div>
  602. <div class="clearfix"></div>
  603. <!-- /ko -->
  604. <!-- ko if: $parent.outputFormat() == 'index' -->
  605. <a class="pointer pull-right margin-top-20" data-bind="click: function() { $parent.columns.remove($data); }"><i class="fa fa-minus"></i></a>
  606. <div data-bind="template: { name: 'index-field-template', data: $data }" class="margin-top-10 field inline-block index-field"></div>
  607. <div class="clearfix"></div>
  608. <!-- /ko -->
  609. </form>
  610. <div class="clearfix"></div>
  611. <!-- ko if: outputFormat() == 'table' || outputFormat() == 'index' -->
  612. <a data-bind="click: function() { columns.push($root.loadDefaultField({})); }" class="pointer" title="${_('Add Field')}"><i class="fa fa-plus"></i> ${_('Add Field')}</a>
  613. <!-- /ko -->
  614. <!-- /ko -->
  615. <!-- ko ifnot: $root.createWizard.source.inputFormat() === 'manual' -->
  616. <form class="form-inline inline-table" data-bind="foreachVisible: { data: columns, minHeight: 44, container: MAIN_SCROLLABLE, disableNiceScroll: true }">
  617. <!-- ko if: $parent.outputFormat() == 'table' && $root.createWizard.source.inputFormat() != 'rdbms' -->
  618. <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field inline-block"></div>
  619. <div class="clearfix"></div>
  620. <!-- /ko -->
  621. <!-- ko if: ([file', 'table', 'hbase'].indexOf($parent.outputFormat()) != -1 && $root.createWizard.source.inputFormat() == 'rdbms') || $parent.outputFormat() == 'index' -->
  622. <div data-bind="template: { name: 'index-field-template', data: $data }" class="margin-top-10 field inline-block index-field"></div>
  623. <div class="clearfix"></div>
  624. <!-- /ko -->
  625. </form>
  626. <div class="clearfix"></div>
  627. <!-- /ko -->
  628. </div>
  629. </div>
  630. <!-- /ko -->
  631. <!-- ko if: outputFormat() == 'database' -->
  632. <div class="card step">
  633. <h4>${_('Properties')}</h4>
  634. <div class="card-body">
  635. <label><div>${ _('Description') }</div>
  636. <input type="text" class="form-control input-xlarge" data-bind="value: description, valueUpdate: 'afterkeydown'" placeholder="${ _('Description') }">
  637. </label>
  638. <label class="checkbox">
  639. <input type="checkbox" data-bind="checked: useDefaultLocation"> ${_('Default location')}
  640. </label>
  641. <span data-bind="visible: !useDefaultLocation()">
  642. <label for="path" class="control-label"><div>${ _('External location') }</div>
  643. <input type="text" class="form-control path filechooser-input input-xxlarge" data-bind="value: nonDefaultLocation, filechooser: nonDefaultLocation, filechooserOptions: { linkMarkup: true, skipInitialPathIfEmpty: true }, valueUpdate: 'afterkeydown'">
  644. </label>
  645. </span>
  646. </div>
  647. </div>
  648. <!-- /ko -->
  649. <!-- /ko -->
  650. <!-- /ko -->
  651. <div class="form-actions">
  652. <!-- ko if: previousStepVisible -->
  653. <button class="btn" data-bind="click: previousStep">${ _('Back') }</button>
  654. <!-- /ko -->
  655. <!-- ko if: currentStep() == 1 -->
  656. <button class="btn" data-bind="enable: !createWizard.isGuessingFormat() && createWizard.source.show(), click: function() { currentStep(2); }">
  657. ${_('Next')}
  658. </button>
  659. <!-- /ko -->
  660. <!-- ko if: currentStep() == 2 -->
  661. <button class="btn btn-primary disable-feedback" data-bind="click: createWizard.indexFile, enable: createWizard.readyToIndex() && !createWizard.indexingStarted()">
  662. ${ _('Submit') } <i class="fa fa-spinner fa-spin" data-bind="visible: createWizard.indexingStarted"></i>
  663. </button>
  664. <!-- /ko -->
  665. <span data-bind="visible: createWizard.editorId">
  666. <button class="btn btn-success" data-bind="click: function(){ window.open('${ url('notebook:editor') }?editor=' + createWizard.editorId()) }" title="${ _('Open') }">
  667. ${_('Check status')}
  668. </button>
  669. </span>
  670. <div id="importerNotebook"></div>
  671. </div>
  672. </div>
  673. <div id="fieldsBulkEditor" class="modal hide fade">
  674. <div class="modal-header">
  675. <button type="button" class="close" data-dismiss="modal" aria-label="${ _('Close') }"><span aria-hidden="true">&times;</span></button>
  676. <h2 class="modal-title">${ _('Write or paste comma separated field names') }</h2>
  677. </div>
  678. <div class="modal-body">
  679. <input type="text" class="input-xxlarge" placeholder="${ _('e.g. id, name, salary') }" data-bind="textInput: createWizard.destination.bulkColumnNames">
  680. </div>
  681. <div class="modal-footer">
  682. <button class="btn" data-dismiss="modal" aria-hidden="true">${ _('Cancel') }</button>
  683. <button class="btn btn-primary" data-bind="click: createWizard.destination.processBulkColumnNames">${ _('Change field names') }</button>
  684. </div>
  685. </div>
  686. </script>
  687. <script type="text/html" id="table-field-template">
  688. <div>
  689. <label data-bind="visible: level() == 0 || ($parent.type() != 'array' && $parent.type() != 'map')">${ _('Name') }&nbsp;
  690. <input type="text" class="input-large" placeholder="${ _('Field name') }" required data-bind="textInput: name">
  691. </label>
  692. <label class="margin-left-5">${ _('Type') }&nbsp;
  693. <!-- ko if: !(level() > 0 && $parent.type() == 'map') -->
  694. <select class="input-small" data-bind="browserAwareSelectize: $root.createWizard.hiveFieldTypes, value: type"></select>
  695. <!-- /ko -->
  696. <!-- ko if: level() > 0 && $parent.type() == 'map' -->
  697. <select class="input-small" data-bind="browserAwareSelectize: $root.createWizard.hivePrimitiveFieldTypes, value: keyType"></select>
  698. <select class="input-small" data-bind="browserAwareSelectize: $root.createWizard.hiveFieldTypes, value: type"></select>
  699. <!-- /ko -->
  700. <input type="number" class="input-small" placeholder="${ _('Length') }" data-bind="value: length, visible: type() == 'varchar' || type() == 'char'">
  701. <!-- ko if: $parent.type() == 'decimal' -->
  702. <input type="number" class="input-small" placeholder="${ _('Precision') }" data-bind="value: precision">
  703. <input type="number" class="input-small" placeholder="${ _('Scale') }" data-bind="value: scale">
  704. <!-- /ko -->
  705. </label>
  706. <!-- ko if: $root.createWizard.source.inputFormat() != 'manual' && typeof isPartition !== 'undefined' && isPartition() -->
  707. <label class="margin-left-5">${ _('Value') }&nbsp;
  708. <input type="text" class="input-medium margin-left-5" placeholder="${ _('Partition value') }" data-bind="value: partitionValue">
  709. </label>
  710. <!-- /ko -->
  711. <span data-bind="visible: level() == 0 || ($parent.type() != 'array' && $parent.type() != 'map')">
  712. <a href="javascript:void(0)" title="${ _('Show field properties') }" data-bind="css: {'inactive-action': !showProperties()}, click: function() {showProperties(!showProperties()) }"><i class="fa fa-sliders"></i></a>
  713. <span data-bind="visible: showProperties">
  714. <input type="text" class="input-medium margin-left-5" placeholder="${ _('Field comment') }" data-bind="value: comment">
  715. </span>
  716. </span>
  717. <!-- ko if: level() > 0 && $parent.type() == 'struct' && $parent.nested().length > 1 -->
  718. <a data-bind="click: function() { $parent.nested.remove($data); }"><i class="fa fa-minus"></i></a>
  719. <!-- /ko -->
  720. <div class="inline-block" data-bind="template: { name:'field-column-example' }"></div>
  721. <!-- ko if: type() == 'array' || type() == 'map' || type() == 'struct' -->
  722. <div class="operation" data-bind="template: { name: 'table-field-template', foreach: nested }"></div>
  723. <a data-bind="click: function() { nested.push($root.loadDefaultField({level: level() + 1})); }, visible: type() == 'struct'"><i class="fa fa-plus"></i></a>
  724. <!-- /ko -->
  725. </div>
  726. </script>
  727. <script type="text/html" id="index-field-template">
  728. <label>${ _('Name') }&nbsp;
  729. <input type="text" class="input-large" placeholder="${ _('Field name') }" data-bind="value: name" pattern="^(?!_version_)[a-zA-Z_][a-zA-Z0-9_]*$" title="${ _('Only alphanumeric and underscore characters and not _version_') }">
  730. </label>
  731. <!-- ko if: $root.createWizard.source.inputFormat() != 'rdbms' -->
  732. <label class="margin-left-5">${ _('Type') }&nbsp;
  733. <select class="input-small" data-bind="browserAwareSelectize: $root.createWizard.fieldTypes, value: type"></select>
  734. </label>
  735. <!-- /ko -->
  736. <!-- ko if: $root.createWizard.source.inputFormat() == 'rdbms' -->
  737. <label class="margin-left-5">${ _('Type') }&nbsp;
  738. <input type="text" class="input-small" placeholder="${ _('Field Type') }" data-bind="value: type, enable:false">
  739. </label>
  740. <!-- /ko -->
  741. <a href="javascript:void(0)" title="${ _('Show field properties') }" data-bind="css: {'inactive-action': !showProperties()}, click: function() {showProperties(!showProperties()) }"><i class="fa fa-sliders"></i></a>
  742. <span data-bind="visible: showProperties" class="field-properties">
  743. <!-- ko if: $root.createWizard.source.inputFormat() != 'rdbms' -->
  744. <label class="checkbox">
  745. <input type="checkbox" data-bind="checked: unique"> ${_('Unique')}
  746. </label>
  747. <label class="checkbox">
  748. <input type="checkbox" data-bind="checked: required"> ${_('Required')}
  749. </label>
  750. <!-- /ko -->
  751. <label class="checkbox">
  752. <input type="checkbox" data-bind="checked: keep"> ${_('Keep')}
  753. </label>
  754. </span>
  755. <!-- ko if: operations().length == 0 -->
  756. <a class="pointer margin-left-20" data-bind="click: $root.createWizard.addOperation, visible: $root.createWizard.destination.indexerRunJob" title="${_('Add Operation')}"><i class="fa fa-plus"></i> ${_('Operation')}</a>
  757. <!-- /ko -->
  758. <div class="inline-block" data-bind="template: { name: 'field-column-example' }"></div>
  759. <div data-bind="foreach: operations">
  760. <div data-bind="template: { name:'operation-template',data:{operation: $data, list: $parent.operations}}"></div>
  761. </div>
  762. <!-- ko if: operations().length > 0 -->
  763. <a class="pointer" data-bind="click: $root.createWizard.addOperation" title="${_('Add Operation')}"><i class="fa fa-plus"></i> ${_('Operation to')} <span data-bind="text: name"></span></a>
  764. <!-- /ko -->
  765. </script>
  766. <script type="text/html" id="field-column-example">
  767. <!-- ko if: $root.createWizard.source.inputFormat() != 'manual' && level() == 0 && (typeof isPartition === 'undefined' || !isPartition()) -->
  768. <!-- ko if: $root.createWizard.source.sample() && $root.createWizard.source.sample().length > 0 -->
  769. <div class="inline-block muted field-content-preview" data-bind="truncatedText: $root.createWizard.source.sample()[0][$index()]"></div>
  770. <!-- ko if: $root.createWizard.source.sample().length > 1 -->
  771. <div class="inline-block muted field-content-preview" data-bind="truncatedText: $root.createWizard.source.sample()[1][$index()]"></div>
  772. <!-- /ko -->
  773. <!-- /ko -->
  774. <!-- ko if: !$root.createWizard.source.sample() || $root.createWizard.source.sample().length === 0 -->
  775. <div class="inline-block muted field-content-preview">${ _("No sample to be shown") }</div>
  776. <!-- /ko -->
  777. <!-- /ko -->
  778. </script>
  779. <script type="text/html" id="operation-template">
  780. <div class="operation">
  781. <select data-bind="browserAwareSelectize: $root.createWizard.operationTypes.map(function(o){return o.name}), value: operation.type"></select>
  782. <!-- ko template: "args-template" --><!-- /ko -->
  783. <!-- ko if: operation.settings().outputType() == "custom_fields" -->
  784. <label class="margin-left-5">${ _('Number of expected fields') }
  785. <input type="number" class="input-mini" data-bind="value: operation.numExpectedFields">
  786. </label>
  787. <!-- /ko -->
  788. <a class="pointer margin-left-20" data-bind="click: function(){$root.createWizard.removeOperation(operation, list)}" title="${ _('Remove') }"><i class="fa fa-times"></i></a>
  789. <div class="margin-left-20" data-bind="foreach: operation.fields">
  790. <div data-bind="template: { name: 'index-field-template', data: $data }" class="margin-top-10 field index-field"></div>
  791. </div>
  792. </div>
  793. </script>
  794. <script type="text/html" id="args-template">
  795. <!-- ko foreach: {data: operation.settings().getArguments(), as: 'argument'} -->
  796. <!-- ko template: {name: 'arg-' + argument.type, data: {description: argument.description, value: $parent.operation.settings()[argument.name]}}--><!-- /ko -->
  797. <!-- /ko -->
  798. </script>
  799. <script type="text/html" id="arg-text">
  800. <label>
  801. <div data-bind="text: description"></div>
  802. <input type="text" class="input" data-bind="attr: {placeholder: description}, value: value">
  803. </label>
  804. </script>
  805. <script type="text/html" id="arg-text-delimiter">
  806. <label>
  807. <div data-bind="text: description"></div>
  808. <select data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { onOptionAdd: function(value){ $root.createWizard.customDelimiters.push({ 'value': value, 'name': value }) }, create: true, maxLength: 2 }, value: value, optionsValue: 'value', optionsText: 'name', attr: {placeholder: description}"></select>
  809. </label>
  810. </script>
  811. <script type="text/html" id="arg-checkbox">
  812. <label class="checkbox">
  813. <input type="checkbox" data-bind="checked: value">
  814. <span data-bind="text: description" style="vertical-align: middle"></span>
  815. </label>
  816. </script>
  817. <script type="text/html" id="arg-mapping">
  818. <!-- ko foreach: value-->
  819. <div>
  820. <input type="text" data-bind="value: key, attr: {placeholder: 'key'}">
  821. <input type="text" data-bind="value: value, attr: {placeholder: 'value'}">
  822. <button class="btn" data-bind="click: function(){$parent.value.remove($data)}">${_('Remove Pair')}</button>
  823. </div>
  824. <!-- /ko -->
  825. <button class="btn" data-bind="click: function(){value.push({key: ko.observable(''), value: ko.observable('')})}">${_('Add Pair')}</button>
  826. <br>
  827. </script>
  828. <script type="text/html" id="field-preview-header-template">
  829. <th data-bind="visible: keep, text: name" style="padding-right:60px"></th>
  830. <!-- ko foreach: operations -->
  831. <!--ko foreach: fields -->
  832. <!-- ko template: 'field-preview-header-template' --><!-- /ko -->
  833. <!-- /ko -->
  834. <!--/ko -->
  835. </script>
  836. <script type="text/html" id="output-generated-field-data-template">
  837. <!-- ko foreach: operations -->
  838. <!--ko foreach: fields -->
  839. <td data-bind="visible: keep">[[${_('generated')}]]</td>
  840. <!-- ko template: 'output-generated-field-data-template' --><!-- /ko -->
  841. <!-- /ko -->
  842. <!--/ko -->
  843. </script>
  844. <script type="text/html" id="importerNotebook-progress">
  845. <!-- ko with: selectedNotebook -->
  846. <!-- ko foreach: snippets -->
  847. <div class="progress-snippet progress" data-bind="css: {
  848. 'progress-starting': progress() == 0 && status() == 'running',
  849. 'progress-warning': progress() > 0 && progress() < 100,
  850. 'progress-success': progress() == 100,
  851. 'progress-danger': progress() == 0 && errors().length > 0}" style="background-color: #FFF; width: 100%; height: 4px">
  852. <div class="bar" data-bind="style: {'width': (errors().length > 0 ? 100 : Math.max(2, progress())) + '%'}"></div>
  853. </div>
  854. <div class="snippet-error-container alert alert-error alert-error-gradient" data-bind="visible: errors().length > 0">
  855. <ul class="unstyled" data-bind="foreach: errors">
  856. <li data-bind="text: message"></li>
  857. </ul>
  858. </div>
  859. <!-- /ko -->
  860. <!-- /ko -->
  861. </script>
  862. <script type="text/javascript">
  863. % if is_embeddable:
  864. var MAIN_SCROLLABLE = '.page-content';
  865. % else:
  866. var MAIN_SCROLLABLE = '.content-panel';
  867. % endif
  868. (function () {
  869. ko.options.deferUpdates = true;
  870. var MAPPINGS = {
  871. SOLR_TO_HIVE: {
  872. "string": "string",
  873. "long": "bigint",
  874. "double": "double",
  875. "date": "date"
  876. },
  877. HIVE_TO_SOLR: {
  878. "bigint": "long"
  879. },
  880. get: function(type, key, defaultValue) {
  881. return type[key] || defaultValue
  882. }
  883. }
  884. var fieldNum = 0;
  885. var getNewFieldName = function () {
  886. fieldNum++;
  887. return "new_field_" + fieldNum
  888. };
  889. var createDefaultField = function () {
  890. var defaultField = ko.mapping.fromJS(${default_field_type | n});
  891. defaultField.name = ko.observable(getNewFieldName());
  892. return defaultField;
  893. };
  894. var Operation = function (type) {
  895. var self = this;
  896. var createArgumentValue = function (arg) {
  897. if (arg.type == "mapping") {
  898. return ko.observableArray([]);
  899. }
  900. else if (arg.type == "checkbox") {
  901. return ko.observable(false);
  902. }
  903. else {
  904. return ko.observable("");
  905. }
  906. }
  907. var constructSettings = function (type) {
  908. var settings = {};
  909. var operation = viewModel.createWizard.operationTypes.find(function (currOperation) {
  910. return currOperation.name == type;
  911. });
  912. for (var i = 0; i < operation.args.length; i++) {
  913. var argVal = createArgumentValue(operation.args[i]);
  914. if (operation.args[i].type == "checkbox" && operation.outputType == "checkbox_fields") {
  915. argVal.subscribe(function (newVal) {
  916. if (newVal) {
  917. self.fields.push(createDefaultField());
  918. }
  919. else {
  920. self.fields.pop();
  921. }
  922. });
  923. }
  924. settings[operation.args[i].name] = argVal;
  925. }
  926. settings.getArguments = function () {
  927. return operation.args
  928. };
  929. settings.outputType = function () {
  930. return operation.outputType;
  931. }
  932. return settings;
  933. };
  934. var init = function () {
  935. self.fields([]);
  936. self.numExpectedFields(0);
  937. self.numExpectedFields.subscribe(function (numExpectedFields) {
  938. if (numExpectedFields < self.fields().length) {
  939. self.fields(self.fields().slice(0, numExpectedFields));
  940. }
  941. else if (numExpectedFields > self.fields().length) {
  942. var difference = numExpectedFields - self.fields().length;
  943. for (var i = 0; i < difference; i++) {
  944. self.fields.push(createDefaultField());
  945. }
  946. }
  947. });
  948. self.settings(constructSettings(self.type()));
  949. }
  950. self.load = function (data) {
  951. self.numExpectedFields(data.numExpectedFields);
  952. var newSettings = constructSettings(data.type);
  953. for (var key in data.settings) {
  954. newSettings[key] = ko.mapping.fromJS(data.settings[key]);
  955. }
  956. self.settings(newSettings);
  957. data.fields.forEach(function (field) {
  958. self.fields.push(loadField(field));
  959. });
  960. }
  961. self.type = ko.observable(type);
  962. self.fields = ko.observableArray();
  963. self.numExpectedFields = ko.observable();
  964. self.settings = ko.observable();
  965. init();
  966. self.type.subscribe(function (newType) {
  967. init();
  968. });
  969. }
  970. var FileType = function (typeName, args) {
  971. var self = this;
  972. var type;
  973. var init = function () {
  974. self.type = ko.observable(typeName);
  975. var types = viewModel.createWizard.fileTypes;
  976. for (var i = 0; i < types.length; i++) {
  977. if (types[i].name == typeName) {
  978. type = types[i];
  979. break;
  980. }
  981. }
  982. for (var i = 0; i < type.args.length; i++) {
  983. self[type.args[i].name] = ko.observable();
  984. }
  985. if (args) {
  986. loadFromObj(args);
  987. }
  988. for (var i = 0; i < type.args.length; i++) {
  989. self[type.args[i].name].subscribe(viewModel.createWizard.guessFieldTypes);
  990. }
  991. }
  992. var loadFromObj = function (args) {
  993. for (var attr in args) {
  994. self[attr] = ko.mapping.fromJS(args[attr]);
  995. }
  996. }
  997. self.getArguments = function () {
  998. return type.args;
  999. }
  1000. self.isCustomizable = function () {
  1001. return type.isCustomizable;
  1002. }
  1003. init();
  1004. }
  1005. var Source = function (vm, wizard) {
  1006. var self = this;
  1007. self.name = ko.observable('');
  1008. self.sample = ko.observableArray();
  1009. self.sampleCols = ko.observableArray();
  1010. self.inputFormat = ko.observable(wizard.prefill.source_type() == 'manual' ? 'manual' : 'file');
  1011. self.inputFormat.subscribe(function(val) {
  1012. wizard.destination.columns.removeAll();
  1013. self.sample.removeAll();
  1014. self.path('');
  1015. resizeElements();
  1016. self.rdbmsMode('');
  1017. });
  1018. self.inputFormatsAll = ko.observableArray([
  1019. {'value': 'file', 'name': 'File'},
  1020. {'value': 'manual', 'name': 'Manually'},
  1021. % if ENABLE_SQOOP.get():
  1022. {'value': 'rdbms', 'name': 'External Database'},
  1023. % endif
  1024. % if ENABLE_SQL_INDEXER.get():
  1025. {'value': 'query', 'name': 'SQL Query'},
  1026. {'value': 'table', 'name': 'Table'},
  1027. % endif
  1028. ##{'value': 'text', 'name': 'Paste Text'},
  1029. ]);
  1030. self.inputFormatsManual = ko.observableArray([
  1031. {'value': 'manual', 'name': 'Manually'}
  1032. ]);
  1033. self.inputFormats = ko.pureComputed(function() {
  1034. if (wizard.prefill.source_type() == 'manual') {
  1035. return self.inputFormatsManual();
  1036. } else {
  1037. return self.inputFormatsAll();
  1038. }
  1039. });
  1040. // File
  1041. self.path = ko.observable('');
  1042. self.path.subscribe(function(val) {
  1043. if (val) {
  1044. vm.createWizard.guessFormat();
  1045. vm.createWizard.destination.nonDefaultLocation(val);
  1046. }
  1047. resizeElements();
  1048. });
  1049. self.isObjectStore = ko.computed(function() {
  1050. return self.inputFormat() == 'file' && /^s3a:\/\/.*$/.test(self.path());
  1051. });
  1052. self.isObjectStore.subscribe(function(newVal) {
  1053. vm.createWizard.destination.useDefaultLocation(!newVal);
  1054. });
  1055. // Rdbms
  1056. self.rdbmsMode = ko.observable('');
  1057. self.rdbmsMode.subscribe(function (val) {
  1058. self.rdbmsType('');
  1059. self.rdbmsDatabaseName('');
  1060. self.rdbmsTableName('');
  1061. self.rdbmsIsAllTables(false);
  1062. self.rdbmsAllTablesSelected(false);
  1063. self.rdbmsHostname('');
  1064. self.rdbmsPort('');
  1065. self.rdbmsUsername('');
  1066. self.rdbmsPassword('');
  1067. self.rdbmsDbIsValid(false);
  1068. });
  1069. self.rdbmsTypesAll = ko.observableArray([
  1070. {'value': 'mysql', 'name': 'MySQL'},
  1071. {'value': 'oracle', 'name': 'Oracle'},
  1072. {'value': 'postgresql', 'name': 'PostgreSQL'},
  1073. {'value': 'db2', 'name': 'DB2'}
  1074. ]);
  1075. self.rdbmsTypes = ko.pureComputed(function() {
  1076. return self.rdbmsTypesAll();
  1077. });
  1078. self.rdbmsType = ko.observable('');
  1079. self.rdbmsType.subscribe(function (val) {
  1080. self.path('');
  1081. resizeElements();
  1082. if(self.rdbmsMode() == 'configRdbms') {
  1083. $.post("${ url('indexer:get_db_component') }", {
  1084. "source": ko.mapping.toJSON(self)
  1085. }, function (resp) {
  1086. if (resp.data) {
  1087. self.rdbmsDatabaseNames(resp.data);
  1088. }
  1089. });
  1090. }
  1091. });
  1092. self.rdbmsDatabaseName = ko.observable('');
  1093. self.rdbmsDatabaseName.subscribe(function (val) {
  1094. if (val != '') {
  1095. $.post("${ url('indexer:get_db_component') }", {
  1096. "source": ko.mapping.toJSON(self)
  1097. }, function (resp) {
  1098. if (resp.data) {
  1099. self.rdbmsTableNames(resp.data);
  1100. }
  1101. });
  1102. }
  1103. });
  1104. self.rdbmsDatabaseNames = ko.observableArray([]);
  1105. self.rdbmsTableName = ko.observable('');
  1106. self.rdbmsTableName.subscribe(function (val) {
  1107. if (val != '') {
  1108. wizard.guessFieldTypes();
  1109. }
  1110. });
  1111. self.rdbmsTableNames = ko.observableArray([]);
  1112. self.rdbmsHostname = ko.observable('');
  1113. self.rdbmsHostname.subscribe(function (val) {
  1114. self.rdbmsDatabaseNames([]);
  1115. });
  1116. self.rdbmsPort = ko.observable('');
  1117. self.rdbmsPort.subscribe(function (val) {
  1118. self.rdbmsDatabaseNames([]);
  1119. });
  1120. self.rdbmsUsername = ko.observable('');
  1121. self.rdbmsUsername.subscribe(function (val) {
  1122. self.rdbmsDatabaseNames([]);
  1123. });
  1124. self.rdbmsPassword = ko.observable('');
  1125. self.rdbmsPassword.subscribe(function (val) {
  1126. self.rdbmsDatabaseNames([]);
  1127. });
  1128. self.rdbmsAllTablesSelected = ko.observable(false);
  1129. self.rdbmsIsAllTables = ko.observable(false);
  1130. self.rdbmsIsAllTables.subscribe(function(newVal) {
  1131. self.rdbmsTableName('');
  1132. self.rdbmsAllTablesSelected(newVal);
  1133. });
  1134. self.rdbmsDbIsValid = ko.observable(false);
  1135. self.rdbmsCheckConnection = function() {
  1136. $.post("${ url('indexer:get_db_component') }", {
  1137. "source": ko.mapping.toJSON(self)
  1138. }, function (resp) {
  1139. if(resp.status == 0 && resp.data) {
  1140. self.rdbmsDbIsValid(true);
  1141. self.rdbmsDatabaseNames(resp.data);
  1142. } else if(resp.status == 1) {
  1143. $(document).trigger("error", "${ _('Connection Failed: ') }" + resp.message);
  1144. self.rdbmsDbIsValid(false);
  1145. }
  1146. });
  1147. };
  1148. // Table
  1149. self.table = ko.observable('');
  1150. self.tableName = ko.computed(function() {
  1151. return self.table().indexOf('.') > 0 ? self.table().split('.', 2)[1] : self.table();
  1152. });
  1153. self.databaseName = ko.computed(function() {
  1154. return self.table().indexOf('.') > 0 ? self.table().split('.', 2)[0] : 'default';
  1155. });
  1156. self.table.subscribe(function(val) {
  1157. resizeElements();
  1158. });
  1159. self.apiHelperType = ko.observable('${ source_type }');
  1160. // Queries
  1161. self.query = ko.observable('');
  1162. self.draggedQuery = ko.observable();
  1163. self.format = ko.observable();
  1164. self.format.subscribe(function(newVal) {
  1165. if (typeof newVal.hasHeader !== 'undefined') {
  1166. vm.createWizard.destination.hasHeader(newVal.hasHeader());
  1167. newVal.hasHeader.subscribe(function(newVal) {
  1168. vm.createWizard.destination.hasHeader(newVal);
  1169. });
  1170. }
  1171. if (typeof newVal.fieldSeparator !== 'undefined') {
  1172. vm.createWizard.destination.useCustomDelimiters(newVal.fieldSeparator() != ',');
  1173. vm.createWizard.destination.customFieldDelimiter(newVal.fieldSeparator());
  1174. newVal.fieldSeparator.subscribe(function(newVal) {
  1175. vm.createWizard.destination.customFieldDelimiter(newVal);
  1176. });
  1177. }
  1178. });
  1179. self.show = ko.computed(function() {
  1180. if (self.inputFormat() == 'file') {
  1181. return self.path().length > 0;
  1182. } else if (self.inputFormat() == 'table') {
  1183. return self.tableName().length > 0;
  1184. } else if (self.inputFormat() == 'query') {
  1185. return self.query();
  1186. } else if (self.inputFormat() == 'manual') {
  1187. return true;
  1188. } else if (self.inputFormat() == 'rdbms') {
  1189. return self.rdbmsDatabaseName().length > 0 && (self.rdbmsTableName().length > 0 || self.rdbmsAllTablesSelected());
  1190. }
  1191. });
  1192. };
  1193. var Destination = function (vm, wizard) {
  1194. var self = this;
  1195. self.name = ko.observable('').extend({throttle: 500});
  1196. self.nameChanged = function(name) {
  1197. var exists = false;
  1198. if (name.length == 0) {
  1199. self.isTargetExisting(false);
  1200. self.isTargetChecking(false);
  1201. }
  1202. else if (self.outputFormat() == 'file') {
  1203. // self.path()
  1204. }
  1205. else if (self.outputFormat() == 'table' && wizard.isValidDestination()) {
  1206. if (self.tableName() !== '') {
  1207. self.isTargetExisting(false);
  1208. self.isTargetChecking(true);
  1209. $.get("/" + (self.apiHelperType() == 'hive' ? 'beeswax' : self.apiHelperType()) + "/api/autocomplete/" + self.databaseName() + '/' + self.tableName(), function (data) {
  1210. self.isTargetExisting(data.code != 500 && data.code != 404);
  1211. self.isTargetChecking(false);
  1212. }).fail(function (xhr, textStatus, errorThrown) {
  1213. self.isTargetExisting(false);
  1214. self.isTargetChecking(false);
  1215. });
  1216. }
  1217. else {
  1218. self.isTargetExisting(false);
  1219. self.isTargetChecking(false);
  1220. }
  1221. }
  1222. else if (self.outputFormat() == 'hbase') {
  1223. // Todo once autocomplete is implemented for hbase
  1224. }
  1225. else if (self.outputFormat() == 'database' && wizard.isValidDestination()) {
  1226. if (self.databaseName() !== '') {
  1227. self.isTargetExisting(false);
  1228. self.isTargetChecking(true);
  1229. $.get("/" + (self.apiHelperType() == 'hive' ? 'beeswax' : self.apiHelperType()) + "/api/autocomplete/" + self.databaseName(), function (data) {
  1230. self.isTargetExisting(data.tables_meta && data.tables_meta.length > 0);
  1231. self.isTargetChecking(false);
  1232. }).fail(function (xhr, textStatus, errorThrown) {
  1233. self.isTargetExisting(false);
  1234. self.isTargetChecking(false);
  1235. });
  1236. }
  1237. else {
  1238. self.isTargetExisting(false);
  1239. self.isTargetChecking(false);
  1240. }
  1241. }
  1242. else if (self.outputFormat() == 'index') {
  1243. $.post("/search/get_collection", {
  1244. name: self.name(),
  1245. engine: 'solr'
  1246. }, function (data) {
  1247. self.isTargetExisting(data.status == 0);
  1248. self.isTargetChecking(false);
  1249. }).fail(function (xhr, textStatus, errorThrown) {
  1250. self.isTargetExisting(false);
  1251. self.isTargetChecking(false);
  1252. });
  1253. $.post("/indexer/api/configs/list/", function (data) {
  1254. if (data.status == 0) {
  1255. self.indexerConfigSets(data.configs.map(function (config) {
  1256. return {'name': config, 'value': config};
  1257. }));
  1258. } else {
  1259. $(document).trigger("error", data.message);
  1260. }
  1261. });
  1262. }
  1263. resizeElements();
  1264. };
  1265. self.name.subscribe(self.nameChanged);
  1266. self.apiHelperType = ko.observable('${ source_type }');
  1267. self.description = ko.observable('');
  1268. self.outputFormat = ko.observable(wizard.prefill.target_type() || 'table');
  1269. self.outputFormat.subscribe(function (newValue) {
  1270. if (newValue && newValue != 'database' && ((newValue == 'table' || newValue == 'index') && wizard.source.path().length > 0)) {
  1271. self.nameChanged(self.name());
  1272. wizard.guessFieldTypes();
  1273. resizeElements();
  1274. }
  1275. });
  1276. self.outputFormatsList = ko.observableArray([
  1277. {'name': 'Table', 'value': 'table'},
  1278. % if ENABLE_NEW_INDEXER.get():
  1279. {'name': 'Search index', 'value': 'index'},
  1280. % endif
  1281. {'name': 'Database', 'value': 'database'},
  1282. % if ENABLE_SQOOP.get():
  1283. {'name': 'File', 'value': 'file'},
  1284. {'name': 'HBase Table', 'value': 'hbase'},
  1285. % endif
  1286. ]);
  1287. self.outputFormats = ko.computed(function() {
  1288. return $.grep(self.outputFormatsList(), function(format) {
  1289. if (format.value == 'database' && wizard.source.inputFormat() != 'manual') {
  1290. return false;
  1291. }
  1292. if (format.value == 'file' && ['manual', 'rdbms'].indexOf(wizard.source.inputFormat()) == -1) {
  1293. return false;
  1294. }
  1295. else if (format.value == 'index' && wizard.source.inputFormat() != 'file') {
  1296. return false;
  1297. }
  1298. if (format.value == 'hbase' && wizard.source.inputFormat() != 'rdbms') {
  1299. return false;
  1300. }
  1301. return true;
  1302. })
  1303. });
  1304. wizard.prefill.target_type.subscribe(function(newValue) {
  1305. self.outputFormat(newValue || 'table');
  1306. if (newValue == 'database') {
  1307. vm.currentStep(2);
  1308. } else {
  1309. vm.currentStep(1);
  1310. }
  1311. });
  1312. self.defaultName = ko.computed(function() {
  1313. var name = ''
  1314. if (wizard.source.inputFormat() == 'file') {
  1315. if (self.outputFormat() == 'table') {
  1316. name = wizard.prefill.target_path().length > 0 ? wizard.prefill.target_path() : 'default';
  1317. if (wizard.source.path()) {
  1318. name += '.' + wizard.source.path().split('/').pop().split('.')[0];
  1319. }
  1320. } else { // Index
  1321. name = wizard.prefill.target_path().length > 0 ? wizard.prefill.target_path() : wizard.source.path().split('/').pop().split('.')[0];
  1322. }
  1323. } else if (wizard.source.inputFormat() == 'table') {
  1324. if (wizard.source.table().split('.', 2).length == 2) {
  1325. name = wizard.source.table();
  1326. }
  1327. } else if (wizard.source.inputFormat() == 'query') {
  1328. if (wizard.source.query()) {
  1329. name = wizard.source.name();
  1330. }
  1331. } else if (wizard.source.inputFormat() == 'manual') {
  1332. name = wizard.prefill.target_path().length > 0 ? wizard.prefill.target_path() + '.' : '';
  1333. }
  1334. return name.replace(/ /g, '_').toLowerCase();
  1335. });
  1336. self.defaultName.subscribe(function(newVal) {
  1337. self.name(newVal);
  1338. });
  1339. self.format = ko.observable();
  1340. self.columns = ko.observableArray();
  1341. // UI
  1342. self.bulkColumnNames = ko.observable('');
  1343. self.showProperties = ko.observable(false);
  1344. self.columns.subscribe(function (newVal) {
  1345. self.bulkColumnNames(newVal.map(function (item) {
  1346. return item.name()
  1347. }).join(','));
  1348. });
  1349. self.processBulkColumnNames = function () {
  1350. var val = self.bulkColumnNames();
  1351. try {
  1352. if (val.indexOf("\"") == -1 && val.indexOf("'") == -1) {
  1353. val = '"' + val.replace(/,/gi, '","') + '"';
  1354. }
  1355. if (val.indexOf("[") == -1) {
  1356. val = "[" + val + "]";
  1357. }
  1358. var parsed = JSON.parse(val);
  1359. self.columns().forEach(function (item, cnt) {
  1360. if ($.trim(parsed[cnt]) !== '') {
  1361. item.name($.trim(parsed[cnt]));
  1362. }
  1363. });
  1364. }
  1365. catch (err) {
  1366. }
  1367. $('#fieldsBulkEditor').modal('hide');
  1368. };
  1369. self.isTargetExisting = ko.observable();
  1370. self.isTargetChecking = ko.observable(false);
  1371. self.existingTargetUrl = ko.computed(function() { // Should open generic sample popup instead
  1372. if (self.isTargetExisting()) {
  1373. if (self.outputFormat() == 'file') {
  1374. // Todo
  1375. return '';
  1376. }
  1377. else if (self.outputFormat() == 'table') {
  1378. return '/metastore/table/' + self.databaseName() + '/' + self.tableName();
  1379. }
  1380. else if (self.outputFormat() == 'database') {
  1381. return '/metastore/tables/' + self.databaseName();
  1382. }
  1383. else if (self.outputFormat() == 'index') {
  1384. return '${ url("indexer:collections") }#edit/' + self.name();
  1385. }
  1386. }
  1387. return '';
  1388. });
  1389. // Table
  1390. self.tableName = ko.computed(function() {
  1391. return self.outputFormat() == 'table' && self.name().indexOf('.') > 0 ? self.name().split('.', 2)[1] : self.name();
  1392. });
  1393. self.databaseName = ko.computed(function() {
  1394. return self.outputFormat() == 'table' && self.name().indexOf('.') > 0 ? self.name().split('.', 2)[0] : (self.name() !== '' ? self.name() : 'default');
  1395. });
  1396. self.tableFormat = ko.observable('text');
  1397. self.tableFormat.subscribe(function(newVal) {
  1398. if (newVal == 'kudu' && self.kuduPartitionColumns().length == 0) {
  1399. self.kuduPartitionColumns.push(ko.mapping.fromJS(self.KUDU_DEFAULT_PARTITION_COLUMN));
  1400. }
  1401. });
  1402. self.KUDU_DEFAULT_RANGE_PARTITION_COLUMN = {values: [{value: ''}], name: 'VALUES', lower_val: 0, include_lower_val: '<=', upper_val: 1, include_upper_val: '<='};
  1403. self.KUDU_DEFAULT_PARTITION_COLUMN = {columns: [], range_partitions: [self.KUDU_DEFAULT_RANGE_PARTITION_COLUMN], name: 'HASH', int_val: 16};
  1404. self.tableFormats = ko.observableArray([
  1405. {'value': 'text', 'name': 'Text'},
  1406. {'value': 'parquet', 'name': 'Parquet'},
  1407. {'value': 'kudu', 'name': 'Kudu'},
  1408. {'value': 'csv', 'name': 'Csv'},
  1409. {'value': 'avro', 'name': 'Avro'},
  1410. {'value': 'json', 'name': 'Json'},
  1411. {'value': 'regexp', 'name': 'Regexp'},
  1412. {'value': 'orc', 'name': 'ORC'},
  1413. ]);
  1414. self.partitionColumns = ko.observableArray();
  1415. self.kuduPartitionColumns = ko.observableArray();
  1416. self.primaryKeys = ko.observableArray();
  1417. self.primaryKeyObjects = ko.observableArray();
  1418. self.importData = ko.observable(true);
  1419. self.useDefaultLocation = ko.observable(true);
  1420. self.nonDefaultLocation = ko.observable('');
  1421. self.hasHeader = ko.observable(true);
  1422. self.useCustomDelimiters = ko.observable(false);
  1423. self.customFieldDelimiter = ko.observable(',');
  1424. self.customCollectionDelimiter = ko.observable('\\002');
  1425. self.customMapDelimiter = ko.observable('\\003');
  1426. self.customRegexp = ko.observable('');
  1427. // Index
  1428. self.indexerRunJob = ko.observable(false);
  1429. self.indexerJobLibPath = ko.observable('${ CONFIG_INDEXER_LIBS_PATH.get() }');
  1430. self.indexerConfigSet = ko.observable('');
  1431. self.indexerConfigSets = ko.observableArray([]);
  1432. self.indexerNumShards = ko.observable(1);
  1433. self.indexerReplicationFactor = ko.observable(1);
  1434. self.indexerPrimaryKey = ko.observableArray();
  1435. self.indexerPrimaryKeyObject = ko.observableArray();
  1436. self.indexerDefaultField = ko.observableArray();
  1437. self.indexerDefaultFieldObject = ko.observableArray();
  1438. // File, Table, HBase
  1439. self.sqoopJobLibPaths = ko.observableArray([]);
  1440. self.addSqoopJobLibPath = function() {
  1441. var newValue = {
  1442. path: ko.observable('')
  1443. };
  1444. self.sqoopJobLibPaths.push(newValue);
  1445. }
  1446. self.removeSqoopJobLibPath = function (valueToRemove) {
  1447. self.sqoopJobLibPaths.remove(valueToRemove);
  1448. };
  1449. self.numMappers = ko.observable(1);
  1450. };
  1451. var CreateWizard = function (vm) {
  1452. var self = this;
  1453. var guessFieldTypesXhr;
  1454. self.fileType = ko.observable();
  1455. self.fileType.subscribe(function (newType) {
  1456. if (self.source.format()) {
  1457. self.source.format().type(newType.name);
  1458. }
  1459. });
  1460. self.fileTypeName = ko.observable();
  1461. self.fileTypeName.subscribe(function (newType) {
  1462. for (var i = 0; i < self.fileTypes.length; i++) {
  1463. if (self.fileTypes[i].name == newType) {
  1464. self.fileType(self.fileTypes[i]);
  1465. break;
  1466. }
  1467. }
  1468. });
  1469. self.operationTypes = ${operators_json | n};
  1470. self.fieldTypes = ${fields_json | n}.solr;
  1471. self.hivePrimitiveFieldTypes = ${fields_json | n}.hivePrimitive;
  1472. self.hiveFieldTypes = ${fields_json | n}.hive;
  1473. self.fileTypes = ${file_types_json | n};
  1474. self.prefill = ko.mapping.fromJS(${prefill | n});
  1475. self.prefill.source_type.subscribe(function(newValue) {
  1476. self.source.inputFormat(newValue == 'manual' ? 'manual' : 'file');
  1477. });
  1478. self.show = ko.observable(true);
  1479. self.showCreate = ko.observable(false);
  1480. self.source = new Source(vm, self);
  1481. self.destination = new Destination(vm, self);
  1482. self.customDelimiters = ko.observableArray([
  1483. {'value': ',', 'name': 'Comma (,)'},
  1484. {'value': '\\t', 'name': '^Tab (\\t)'},
  1485. {'value': '\\n', 'name': 'New line'},
  1486. {'value': ' ', 'name': 'Space'},
  1487. {'value': '"', 'name': 'Double Quote'},
  1488. {'value': '\\001', 'name': '^A (\\001)'},
  1489. {'value': '\\002', 'name': '^B (\\002)'},
  1490. {'value': '\\003', 'name': '^C (\\003)'},
  1491. ]);
  1492. self.editorId = ko.observable();
  1493. self.jobId = ko.observable();
  1494. self.editorVM = null;
  1495. self.indexingStarted = ko.observable(false);
  1496. self.isValidDestination = ko.pureComputed(function() {
  1497. return self.destination.name().length > 0 && (
  1498. (['table', 'database'].indexOf(self.destination.outputFormat()) == -1 || /^([a-zA-Z0-9_]+\.)?[a-zA-Z0-9_]+$/.test(self.destination.name())) &&
  1499. (['index'].indexOf(self.destination.outputFormat()) == -1 || /^[^\\/:]+$/.test(self.destination.name()))
  1500. );
  1501. });
  1502. self.readyToIndex = ko.computed(function () {
  1503. var validFields = self.destination.columns().length || self.destination.outputFormat() == 'database';
  1504. var validTableColumns = self.destination.outputFormat() != 'table' || ($.grep(self.destination.columns(), function(column) {
  1505. return column.name().length == 0;
  1506. }).length == 0
  1507. && $.grep(self.destination.partitionColumns(), function(column) {
  1508. return column.name().length == 0 || (self.source.inputFormat() != 'manual' && column.partitionValue().length == 0);
  1509. }).length == 0
  1510. );
  1511. var isTargetAlreadyExisting = ! self.destination.isTargetExisting() || self.destination.outputFormat() == 'index';
  1512. var isValidTable = self.destination.outputFormat() != 'table' || (
  1513. self.destination.tableFormat() != 'kudu' || (self.destination.kuduPartitionColumns().length > 0 &&
  1514. $.grep(self.destination.kuduPartitionColumns(), function(partition) { return partition.columns().length > 0 }).length == self.destination.kuduPartitionColumns().length && self.destination.primaryKeys().length > 0)
  1515. );
  1516. var validIndexFields = self.destination.outputFormat() != 'index' || ($.grep(self.destination.columns(), function(column) {
  1517. return ! (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(column.name()) && column.name() != '_version_');
  1518. }).length == 0
  1519. ) || self.destination.indexerConfigSet();
  1520. return self.isValidDestination() && validFields && validTableColumns && validIndexFields && isTargetAlreadyExisting && isValidTable;
  1521. });
  1522. self.formatTypeSubscribed = false;
  1523. self.source.format.subscribe(function (newVal) {
  1524. for (var i = 0; i < self.fileTypes.length; i++) {
  1525. if (self.fileTypes[i].name == self.source.format().type()) {
  1526. self.fileType(self.fileTypes[i]);
  1527. self.fileTypeName(self.fileTypes[i].name);
  1528. break;
  1529. }
  1530. }
  1531. if (self.source.format().type) {
  1532. if (!self.formatTypeSubscribed) {
  1533. self.formatTypeSubscribed = true;
  1534. self.source.format().type.subscribe(function (newType) {
  1535. self.source.format(new FileType(newType));
  1536. self.destination.columns.removeAll();
  1537. self.guessFieldTypes();
  1538. });
  1539. }
  1540. }
  1541. });
  1542. self.isGuessingFormat = ko.observable(false);
  1543. self.guessFormat = function () {
  1544. self.isGuessingFormat(true);
  1545. self.destination.columns.removeAll();
  1546. $.post("${ url('indexer:guess_format') }", {
  1547. "fileFormat": ko.mapping.toJSON(self.source)
  1548. }, function (resp) {
  1549. if (resp.status != 0) {
  1550. $(document).trigger("error", resp.message);
  1551. } else {
  1552. var newFormat = ko.mapping.fromJS(new FileType(resp['type'], resp));
  1553. self.source.format(newFormat);
  1554. self.guessFieldTypes();
  1555. }
  1556. self.isGuessingFormat(false);
  1557. viewModel.wizardEnabled(true);
  1558. }).fail(function (xhr, textStatus, errorThrown) {
  1559. $(document).trigger("error", xhr.responseText);
  1560. viewModel.isLoading(false);
  1561. self.isGuessingFormat(false);
  1562. });
  1563. };
  1564. self.isGuessingFieldTypes = ko.observable(false);
  1565. self.guessFieldTypes = function () {
  1566. if (guessFieldTypesXhr) {
  1567. guessFieldTypesXhr.abort();
  1568. }
  1569. self.isGuessingFieldTypes(true);
  1570. guessFieldTypesXhr = $.post("${ url('indexer:guess_field_types') }", {
  1571. "fileFormat": ko.mapping.toJSON(self.source)
  1572. }, function (resp) {
  1573. resp.columns.forEach(function (entry, i, arr) {
  1574. if (self.destination.outputFormat() === 'table') {
  1575. entry.type = MAPPINGS.get(MAPPINGS.SOLR_TO_HIVE, entry.type, 'string');
  1576. } else if (self.destination.outputFormat() === 'index') {
  1577. entry.type = MAPPINGS.get(MAPPINGS.HIVE_TO_SOLR, entry.type, entry.type);
  1578. }
  1579. arr[i] = loadField(entry, self.destination, i);
  1580. });
  1581. self.source.sampleCols(resp.sample_cols ? resp.sample_cols : resp.columns);
  1582. self.source.sample(resp.sample);
  1583. self.destination.columns(resp.columns);
  1584. self.isGuessingFieldTypes(false);
  1585. }).fail(function (xhr, textStatus, errorThrown) {
  1586. $(document).trigger("error", xhr.responseText);
  1587. self.isGuessingFieldTypes(false);
  1588. viewModel.isLoading(false);
  1589. });
  1590. };
  1591. self.isIndexing = ko.observable(false);
  1592. self.indexingError = ko.observable(false);
  1593. self.indexingSuccess = ko.observable(false);
  1594. self.indexFile = function () {
  1595. if (!self.readyToIndex()) {
  1596. return;
  1597. }
  1598. $(".jHueNotify").remove();
  1599. %if not is_embeddable:
  1600. self.indexingStarted(true);
  1601. viewModel.isLoading(true);
  1602. self.isIndexing(true);
  1603. $.post("${ url('indexer:importer_submit') }", {
  1604. "source": ko.mapping.toJSON(self.source),
  1605. "destination": ko.mapping.toJSON(self.destination)
  1606. }, function (resp) {
  1607. if (resp.status != 0) {
  1608. $(document).trigger("error", resp.message);
  1609. self.indexingStarted(false);
  1610. self.isIndexing(false);
  1611. } else if (resp.on_success_url) {
  1612. $.jHueNotify.info("${ _('Creation success.') }");
  1613. huePubSub.publish('open.link', resp.on_success_url);
  1614. } else {
  1615. self.showCreate(true);
  1616. self.editorId(resp.history_id);
  1617. self.jobId(resp.handle.id);
  1618. $('#importerNotebook').html($('#importerNotebook-progress').html());
  1619. self.editorVM = new EditorViewModel(resp.history_uuid, '', {
  1620. user: '${ user.username }',
  1621. userId: ${ user.id },
  1622. languages: [{name: "Java", type: "java"}, {name: "Hive SQL", type: "hive"}], // TODO reuse
  1623. snippetViewSettings: {
  1624. java : {
  1625. snippetIcon: 'fa-file-archive-o '
  1626. },
  1627. hive: {
  1628. placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
  1629. aceMode: 'ace/mode/hive',
  1630. snippetImage: '${ static("beeswax/art/icon_beeswax_48.png") }',
  1631. sqlDialect: true
  1632. },
  1633. impala: {
  1634. placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
  1635. aceMode: 'ace/mode/impala',
  1636. snippetImage: '${ static("impala/art/icon_impala_48.png") }',
  1637. sqlDialect: true
  1638. },
  1639. sqoop1: {
  1640. placeHolder: '${ _("Example: import --connect jdbc:hsqldb:file:db.hsqldb --table TT --target-dir hdfs://localhost:8020/user/foo -m 1") }',
  1641. snippetImage: '${ static("sqoop/art/icon_sqoop_48.png") }'
  1642. }
  1643. }
  1644. });
  1645. self.editorVM.editorMode(true);
  1646. self.editorVM.isNotificationManager(true);
  1647. ko.cleanNode($("#importerNotebook")[0]);
  1648. ko.applyBindings(self.editorVM, $("#importerNotebook")[0]);
  1649. self.editorVM.openNotebook(resp.history_uuid, null, true, function(){
  1650. self.editorVM.selectedNotebook().snippets()[0].progress.subscribe(function(val){
  1651. if (val == 100) {
  1652. self.indexingStarted(false);
  1653. self.isIndexing(false);
  1654. self.indexingSuccess(true);
  1655. }
  1656. });
  1657. self.editorVM.selectedNotebook().snippets()[0].status.subscribe(function(val){
  1658. if (val == 'failed') {
  1659. self.isIndexing(false);
  1660. self.indexingStarted(false);
  1661. self.indexingError(true);
  1662. } else if (val == 'available') {
  1663. var snippet = self.editorVM.selectedNotebook().snippets()[0]; // Could be native to editor at some point
  1664. if (!snippet.result.handle().has_more_statements) {
  1665. if (self.editorVM.selectedNotebook().onSuccessUrl()) {
  1666. var match = snippet.statement_raw().match(/CREATE TABLE `([^`]+)`/i);
  1667. if (match) {
  1668. var db = match[1];
  1669. huePubSub.publish('assist.invalidate.impala', { flush: false, database: db });
  1670. }
  1671. huePubSub.publish('assist.clear.db.cache', { sourceType: self.source.apiHelperType() });
  1672. window.location.href = self.editorVM.selectedNotebook().onSuccessUrl();
  1673. }
  1674. } else { // Perform last DROP statement execute
  1675. snippet.execute();
  1676. }
  1677. }
  1678. });
  1679. self.editorVM.selectedNotebook().snippets()[0].checkStatus();
  1680. });
  1681. }
  1682. viewModel.isLoading(false);
  1683. }).fail(function (xhr, textStatus, errorThrown) {
  1684. $(document).trigger("error", xhr.responseText);
  1685. viewModel.isLoading(false);
  1686. self.indexingStarted(false);
  1687. self.isIndexing(false);
  1688. });
  1689. % else:
  1690. $.post("${ url('indexer:importer_submit') }", {
  1691. "source": ko.mapping.toJSON(self.source),
  1692. "destination": ko.mapping.toJSON(self.destination),
  1693. "start_time": ko.mapping.toJSON((new Date()).getTime())
  1694. }, function (resp) {
  1695. if (resp.status == 0) {
  1696. if (resp.history_uuid) {
  1697. $.jHueNotify.info("${ _('Task submitted') }");
  1698. huePubSub.publish('notebook.task.submitted', resp.history_uuid);
  1699. } else if (resp.on_success_url) {
  1700. if (resp.pub_sub_url) {
  1701. huePubSub.publish(resp.pub_sub_url);
  1702. }
  1703. $.jHueNotify.info("${ _('Creation success') }");
  1704. huePubSub.publish('open.link', resp.on_success_url);
  1705. }
  1706. } else {
  1707. $(document).trigger("error", resp && resp.message ? resp.message : '${ _("Error importing") }');
  1708. }
  1709. }).fail(function (xhr, textStatus, errorThrown) {
  1710. $(document).trigger("error", xhr.responseText);
  1711. });
  1712. % endif
  1713. hueAnalytics.log('importer', 'submit/' + self.source.inputFormat() + '/' + self.destination.outputFormat());
  1714. };
  1715. self.removeOperation = function (operation, operationList) {
  1716. operationList.remove(operation);
  1717. hueAnalytics.log('importer', 'step/removeOperation');
  1718. };
  1719. self.addOperation = function (field) {
  1720. field.operations.push(new Operation("split"));
  1721. hueAnalytics.log('importer', 'step/addOperation');
  1722. };
  1723. self.load = function (state) {
  1724. self.source.name(state.name);
  1725. self.source.show(state.show);
  1726. self.source.path(state.path);
  1727. self.destination.columns.removeAll();
  1728. if (state.format && 'type' in state.format) {
  1729. var koFormat = ko.mapping.fromJS(new FileType(state.format.type, state.format));
  1730. self.source.format(koFormat);
  1731. }
  1732. if (state.columns) {
  1733. state.columns.forEach(function (currCol) {
  1734. self.destination.columns.push(loadField(currCol));
  1735. });
  1736. }
  1737. }
  1738. };
  1739. var loadDefaultField = function (options) {
  1740. if (!options.name) {
  1741. options.name = getNewFieldName();
  1742. }
  1743. return loadField($.extend({}, ${default_field_type | n}, options));
  1744. };
  1745. var loadField = function (currField, parent, idx) {
  1746. var koField = ko.mapping.fromJS(currField);
  1747. if (koField.name && parent) {
  1748. koField.name.subscribe(function (newVal) {
  1749. if (newVal.indexOf(',') > -1) {
  1750. var fields = newVal.split(',');
  1751. fields.forEach(function (val, i) {
  1752. if (i + idx < parent.columns().length) {
  1753. parent.columns()[i + idx].name(val);
  1754. }
  1755. });
  1756. }
  1757. parent.bulkColumnNames(parent.columns().map(function (item) {
  1758. return item.name()
  1759. }).join(','));
  1760. });
  1761. }
  1762. koField.operations.removeAll();
  1763. currField.operations.forEach(function (operationData) {
  1764. var operation = new Operation(operationData.type);
  1765. operation.load(operationData);
  1766. koField.operations.push(operation);
  1767. });
  1768. var autoExpand = function (newVal) {
  1769. if ((newVal == 'array' || newVal == 'map' || newVal == 'struct') && koField.nested().length == 0) {
  1770. koField.nested.push(loadDefaultField({level: koField.level() + 1}));
  1771. }
  1772. };
  1773. koField.type.subscribe(autoExpand);
  1774. koField.keyType.subscribe(autoExpand);
  1775. return koField;
  1776. };
  1777. var IndexerViewModel = function () {
  1778. var self = this;
  1779. self.apiHelper = ApiHelper.getInstance();
  1780. self.assistAvailable = ko.observable(true);
  1781. self.isLeftPanelVisible = ko.observable();
  1782. self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
  1783. self.loadDefaultField = loadDefaultField;
  1784. self.createWizard = new CreateWizard(self);
  1785. // Wizard related
  1786. self.wizardEnabled = ko.observable(false);
  1787. self.currentStep = ko.observable(self.createWizard.prefill.target_type() == 'database' ? 2 : 1);
  1788. self.currentStep.subscribe(function () {
  1789. %if is_embeddable:
  1790. $('.page-content').scrollTop(0);
  1791. %else:
  1792. $('.content-panel').scrollTop(0);
  1793. %endif
  1794. });
  1795. self.previousStepVisible = ko.pureComputed(function(){
  1796. return self.currentStep() > 1 && self.createWizard.destination.outputFormat() != 'database';
  1797. });
  1798. self.nextStepVisible = ko.pureComputed(function(){
  1799. return self.currentStep() < 3 && self.wizardEnabled();
  1800. });
  1801. self.nextStep = function () {
  1802. if (self.nextStepVisible()) {
  1803. self.currentStep(self.currentStep() + 1);
  1804. hueAnalytics.log('importer', 'step/' + self.currentStep());
  1805. }
  1806. };
  1807. self.previousStep = function () {
  1808. if (self.previousStepVisible()) {
  1809. self.currentStep(self.currentStep() - 1);
  1810. hueAnalytics.log('importer', 'step/' + self.currentStep());
  1811. }
  1812. };
  1813. self.isLoading = ko.observable(false);
  1814. };
  1815. var viewModel;
  1816. function resizeElements () {
  1817. var $contentPanel = $('#importerComponents').find('.content-panel-inner');
  1818. $('.form-actions').width($contentPanel.width() - 50);
  1819. $('.step-indicator-fixed').width($contentPanel.width());
  1820. document.styleSheets[0].addRule('.step-indicator li:first-child:before','max-width: ' + ($contentPanel.find('.step-indicator li:first-child .caption').width()) + 'px');
  1821. document.styleSheets[0].addRule('.step-indicator li:first-child:before','left: ' + ($contentPanel.find('.step-indicator li:first-child .caption').width()/2) + 'px');
  1822. document.styleSheets[0].addRule('.step-indicator li:last-child:before','max-width: ' + ($contentPanel.find('.step-indicator li:last-child .caption').width()) + 'px');
  1823. document.styleSheets[0].addRule('.step-indicator li:last-child:before','right: ' + ($contentPanel.find('.step-indicator li:last-child .caption').width()/2) + 'px');
  1824. }
  1825. $(document).ready(function () {
  1826. viewModel = new IndexerViewModel();
  1827. ko.applyBindings(viewModel, $('#importerComponents')[0]);
  1828. var draggableMeta = {};
  1829. huePubSub.subscribe('draggable.text.meta', function (meta) {
  1830. draggableMeta = meta;
  1831. });
  1832. huePubSub.subscribe('split.panel.resized', resizeElements);
  1833. hueUtils.waitForRendered('.step-indicator li:first-child .caption', function(el){ return el.width() < $('#importerComponents').find('.content-panel-inner').width()/2 }, resizeElements);
  1834. $(window).on('resize', resizeElements);
  1835. $('.content-panel').droppable({
  1836. accept: ".draggableText",
  1837. drop: function (e, ui) {
  1838. var text = ui.helper.text();
  1839. var generatedName = 'idx';
  1840. switch (draggableMeta.type){
  1841. case 'sql':
  1842. if (draggableMeta.table !== '') {
  1843. generatedName += draggableMeta.table;
  1844. viewModel.createWizard.source.inputFormat('table');
  1845. viewModel.createWizard.source.table(draggableMeta.table);
  1846. }
  1847. break;
  1848. case 'hdfs':
  1849. generatedName += draggableMeta.definition.name;
  1850. viewModel.createWizard.source.inputFormat('file');
  1851. viewModel.createWizard.source.path(draggableMeta.definition.path);
  1852. break;
  1853. case 'document':
  1854. if (draggableMeta.definition.type === 'query-hive') {
  1855. generatedName += draggableMeta.definition.name;
  1856. viewModel.createWizard.source.inputFormat('query');
  1857. viewModel.createWizard.source.draggedQuery(draggableMeta.definition.uuid);
  1858. }
  1859. break;
  1860. }
  1861. if (generatedName !== 'idx' && viewModel.createWizard.source.name() === '') {
  1862. viewModel.createWizard.source.name(generatedName);
  1863. }
  1864. }
  1865. });
  1866. });
  1867. })();
  1868. </script>
  1869. </span>
  1870. %if not is_embeddable:
  1871. ${ commonfooter(request, messages) | n,unicode }
  1872. %endif