importer.mako 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  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
  21. %>
  22. <%namespace name="actionbar" file="actionbar.mako" />
  23. <%namespace name="assist" file="/assist.mako" />
  24. %if not is_embeddable:
  25. ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
  26. ## TODO lot of those re-imported
  27. <script src="${ static('desktop/js/autocomplete/sql.js') }"></script>
  28. <script src="${ static('desktop/js/sqlAutocompleter.js') }"></script>
  29. <script src="${ static('desktop/js/sqlAutocompleter2.js') }"></script>
  30. <script src="${ static('desktop/js/hdfsAutocompleter.js') }"></script>
  31. <script src="${ static('desktop/js/autocompleter.js') }"></script>
  32. <script src="${ static('desktop/js/hue.json.js') }"></script>
  33. <script src="${ static('desktop/js/jquery.hiveautocomplete.js') }" type="text/javascript" charset="utf-8"></script>
  34. <script src="${ static('desktop/ext/js/jquery/plugins/jquery-ui-1.10.4.custom.min.js') }"></script>
  35. <script src="${ static('desktop/js/jquery.huedatatable.js') }"></script>
  36. <script src="${ static('desktop/ext/js/selectize.min.js') }"></script>
  37. <script src="${ static('desktop/js/apiHelper.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. <style type="text/css">
  53. % if conf.CUSTOM.BANNER_TOP_HTML.get():
  54. .show-assist {
  55. top: 110px!important;
  56. }
  57. .main-content {
  58. top: 112px!important;
  59. }
  60. % endif
  61. .path {
  62. margin-bottom: 0!important;
  63. border-right: none!important;
  64. }
  65. .step .card-heading.simple {
  66. font-size: 17px;
  67. }
  68. .step .card-body {
  69. margin-top: 14px;
  70. }
  71. .step label > div:first-child {
  72. width: 120px;
  73. text-align: right;
  74. padding-right: 8px;
  75. display: inline-block;
  76. vertical-align: top;
  77. padding-top: 6px;
  78. }
  79. .step label.checkbox {
  80. margin-left: 130px;
  81. }
  82. .step .index-field label.checkbox {
  83. margin-left: 5px;
  84. }
  85. .step .index-field label > div:first-child {
  86. width: initial;
  87. }
  88. .step .field-properties label.checkbox {
  89. margin-left: 10px;
  90. }
  91. .step label:not(.checkbox) {
  92. display: inline-block;
  93. vertical-align: middle;
  94. }
  95. .step input[type='text'] {
  96. margin-bottom: 0;
  97. }
  98. .step .selectize-control {
  99. display: inline-block;
  100. vertical-align: middle;
  101. width: 578px !important;
  102. }
  103. .step .form-inline .selectize-control {
  104. width: 120px !important;
  105. margin-bottom: -8px;
  106. }
  107. .step .inline-labels {
  108. display: table;
  109. }
  110. .step .inline-labels .selectize-control {
  111. width: 120px !important;
  112. vertical-align: -12px;
  113. }
  114. .step .selectize-input {
  115. max-height: 31px;
  116. }
  117. .step .selectize-control.multi .selectize-input {
  118. padding-top: 3px!important;
  119. }
  120. .step .show-edit-on-hover i {
  121. opacity: 0;
  122. -webkit-transition: opacity 0.2s linear;
  123. -moz-transition: opacity 0.2s linear;
  124. -ms-transition: opacity 0.2s linear;
  125. -o-transition: opacity 0.2s linear;
  126. transition: opacity 0.2s linear;
  127. }
  128. .step .show-edit-on-hover:hover i {
  129. opacity: 1;
  130. }
  131. .step .show-edit-on-hover .inactive-action {
  132. margin-left: 6px;
  133. vertical-align: middle;
  134. }
  135. .step .fa-padding-top {
  136. padding-top: 8px;
  137. }
  138. .kudu-partitions li {
  139. width: 578px !important;
  140. padding: 5px;
  141. }
  142. .kudu-partitions li:hover {
  143. background-color: #F7F7F7;
  144. }
  145. .kudu-partitions .range-partition {
  146. padding: 5px;
  147. }
  148. .kudu-partitions .range-partition:hover {
  149. background-color: #F1F1F1;
  150. }
  151. .step .kudu-partitions li .selectize-control {
  152. width: 100px !important;
  153. vertical-align: top;
  154. }
  155. .field {
  156. padding: 4px;
  157. padding-left: 10px;
  158. border-left: 4px solid #DBE8F1;
  159. }
  160. .operation {
  161. border-left: 4px solid #EEE;
  162. padding-left: 10px;
  163. margin-top: 5px;
  164. margin-bottom: 5px;
  165. margin-left: 10px;
  166. }
  167. .field-content-preview {
  168. width: 180px;
  169. margin-left: 20px;
  170. }
  171. .table-preview {
  172. margin:auto;
  173. text-align:left;
  174. }
  175. .table-preview td, .table-preview th {
  176. white-space: nowrap;
  177. }
  178. .content-panel {
  179. overflow-x: hidden;
  180. }
  181. .content-panel-inner {
  182. margin: 10px;
  183. margin-bottom: 100px;
  184. }
  185. .fileChooserBtn {
  186. height: 29px;
  187. }
  188. .form-control.path {
  189. vertical-align: top;
  190. }
  191. .form-actions {
  192. position: fixed;
  193. bottom: 0;
  194. margin: 0;
  195. z-index: 1000;
  196. border-top: 1px solid #e5e5e5;
  197. }
  198. #importerNotebook {
  199. height: 5px;
  200. margin-top: 10px;
  201. }
  202. .inline-table {
  203. display: inline-table;
  204. }
  205. </style>
  206. <span id="importerComponents" class="notebook">
  207. <div class="navbar navbar-inverse navbar-fixed-top">
  208. <div class="navbar-inner">
  209. <div class="container-fluid">
  210. <div class="nav-collapse">
  211. <ul class="nav">
  212. <li class="currentApp">
  213. <a href="${ url('indexer:importer') }">
  214. <i class="fa fa-database app-icon"></i> ${_('Importer')}</a>
  215. </a>
  216. </li>
  217. </ul>
  218. </div>
  219. </div>
  220. </div>
  221. </div>
  222. %if not is_embeddable:
  223. <a title="${_('Toggle Assist')}" class="pointer show-assist" data-bind="visible: !$root.isLeftPanelVisible() && $root.assistAvailable(), click: function() { $root.isLeftPanelVisible(true); }">
  224. <i class="fa fa-chevron-right"></i>
  225. </a>
  226. %endif
  227. <div class="main-content">
  228. <div class="vertical-full container-fluid" data-bind="style: { 'padding-left' : $root.isLeftPanelVisible() ? '0' : '20px' }">
  229. <div class="vertical-full">
  230. <div class="vertical-full row-fluid panel-container">
  231. %if not is_embeddable:
  232. <div class="assist-container left-panel" data-bind="visible: $root.isLeftPanelVisible() && $root.assistAvailable()">
  233. <a title="${_('Toggle Assist')}" class="pointer hide-assist" data-bind="click: function() { $root.isLeftPanelVisible(false) }">
  234. <i class="fa fa-chevron-left"></i>
  235. </a>
  236. <div class="assist" data-bind="component: {
  237. name: 'assist-panel',
  238. params: {
  239. user: '${user.username}',
  240. onlySql: false,
  241. sql: {
  242. sourceTypes: [{
  243. name: 'hive',
  244. type: 'hive'
  245. }],
  246. navigationSettings: {
  247. openItem: false,
  248. showStats: true
  249. }
  250. },
  251. visibleAssistPanels: ['sql', 'hdfs', 'documents']
  252. }
  253. }"></div>
  254. </div>
  255. <div class="resizer" data-bind="visible: $root.isLeftPanelVisible() && $root.assistAvailable(), splitDraggable : { appName: 'notebook', leftPanelVisible: $root.isLeftPanelVisible }"><div class="resize-bar">&nbsp;</div></div>
  256. %endif
  257. <div class="content-panel">
  258. <div class="content-panel-inner">
  259. <!-- ko template: 'create-index-wizard' --><!-- /ko -->
  260. </div>
  261. </div>
  262. </div>
  263. </div>
  264. </div>
  265. </div>
  266. <div id="chooseFile" class="modal hide fade">
  267. <div class="modal-header">
  268. <a href="#" class="close" data-dismiss="modal">&times;</a>
  269. <h3>${_('Choose a file')}</h3>
  270. </div>
  271. <div class="modal-body">
  272. <div id="filechooser"></div>
  273. </div>
  274. <div class="modal-footer"></div>
  275. </div>
  276. <script type="text/html" id="create-index-wizard">
  277. <div data-bind="visible: createWizard.show">
  278. <div class="step-indicator-fixed">
  279. <ol class="list-inline text-center step-indicator">
  280. <li data-bind="css: { 'active': currentStep() == 1, 'complete': currentStep() > 1, 'pointer': currentStep() > 1 }, click: function() { currentStep(1) }">
  281. <div class="step" title="${ _('Go to Step 1') }">
  282. <!-- ko if: currentStep() == 1 -->
  283. <!-- ko if: createWizard.isGuessingFormat -->
  284. <span class="fa fa-spinner fa-spin"></span>
  285. <!-- /ko -->
  286. <!-- ko ifnot: createWizard.isGuessingFormat -->
  287. 1
  288. <!-- /ko -->
  289. <!-- /ko -->
  290. <!-- ko ifnot: currentStep() == 1 -->
  291. <span class="fa fa-check"></span>
  292. <!-- /ko -->
  293. </div>
  294. <div class="caption">
  295. <!-- ko if: createWizard.source.inputFormat() != 'manual' -->
  296. ${ _('Pick data from ') }<span data-bind="text: createWizard.source.inputFormat"></span> <span data-bind="text: createWizard.source.path"></span>
  297. <!-- /ko -->
  298. <!-- ko if: createWizard.source.inputFormat() == 'manual' -->
  299. ${ _('No source data') }
  300. <!-- /ko -->
  301. </div>
  302. </li>
  303. <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); }}">
  304. <div class="step" title="${ _('Go to Step 2') }">
  305. <!-- ko if: currentStep() < 3 -->
  306. <!-- ko if: createWizard.isGuessingFieldTypes -->
  307. <span class="fa fa-spinner fa-spin"></span>
  308. <!-- /ko -->
  309. <!-- ko ifnot: createWizard.isGuessingFieldTypes -->
  310. 2
  311. <!-- /ko -->
  312. <!-- /ko -->
  313. </div>
  314. <div class="caption">
  315. <!-- ko if: createWizard.source.inputFormat() != 'manual' -->
  316. ${ _('Move it to ') }
  317. <!-- /ko -->
  318. <!-- ko if: createWizard.source.inputFormat() == 'manual' -->
  319. ${ _('Create') }
  320. <!-- /ko -->
  321. <span data-bind="text: createWizard.destination.outputFormat"></span> <span data-bind="text: createWizard.destination.name"></span>
  322. </div>
  323. </li>
  324. </ol>
  325. </div>
  326. <div class="vertical-spacer"></div>
  327. <!-- ko if: currentStep() == 1 -->
  328. <div class="card step">
  329. <h3 class="card-heading simple">${_('Source')}</h3>
  330. <div class="card-body">
  331. <div>
  332. <div class="control-group" data-bind="visible: !createWizard.prefill.target_type || !createWizard.prefill.target_type() || createWizard.prefill.source_type() == 'all'">
  333. <label for="sourceType" class="control-label"><div>${ _('Type') }</div>
  334. <select id="sourceType" data-bind="selectize: createWizard.source.inputFormats, value: createWizard.source.inputFormat, optionsText: 'name', optionsValue: 'value'"></select>
  335. </label>
  336. </div>
  337. <div class="control-group" data-bind="visible: createWizard.prefill.target_type && createWizard.prefill.target_type() == 'database'">
  338. <label for="sourceType" class="control-label">${ _('No source is needed for creating a database.') }</label>
  339. </div>
  340. <div class="control-group" data-bind="visible: createWizard.source.inputFormat() == 'file'">
  341. <label for="path" class="control-label"><div>${ _('Path') }</div>
  342. <input type="text" class="form-control path 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') }">
  343. </label>
  344. <!-- ko if: createWizard.source.path().length > 0 -->
  345. <a data-bind="attr: {href: '/filebrowser/view=' + createWizard.source.path() }" target="_blank" title="${ _('Open') }">
  346. <i class="fa fa-external-link-square"></i>
  347. </a>
  348. <!-- /ko -->
  349. </div>
  350. <div class="control-group" data-bind="visible: createWizard.source.inputFormat() == 'table'">
  351. <label for="path" class="control-label"><div>${ _('Table') }</div>
  352. <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: $('.content-panel')" placeholder="${ _('Table name or <database>.<table>') }">
  353. </label>
  354. </div>
  355. <div class="control-group" data-bind="visible: createWizard.source.inputFormat() == 'query'">
  356. <label for="path" class="control-label"><div>${ _('Query') }</div>
  357. <select placeholder="${ _('Search your documents...') }" data-bind="documentChooser: { dependentValue: createWizard.source.draggedQuery, mappedDocument: createWizard.source.query }"></select>
  358. </label>
  359. </div>
  360. </div>
  361. </div>
  362. </div>
  363. <!-- ko if: createWizard.source.show() && createWizard.source.inputFormat() != 'manual' -->
  364. <div class="card step">
  365. <!-- ko if: createWizard.isGuessingFormat -->
  366. <h3 class="card-heading simple">${_('Guessing format...')} <i class="fa fa-spinner fa-spin"></i></h3>
  367. <!-- /ko -->
  368. <!-- ko ifnot: createWizard.isGuessingFormat -->
  369. <h3 class="card-heading simple">${_('Format')}</h3>
  370. <div class="card-body">
  371. <label data-bind="visible: (! createWizard.prefill.source_type) && createWizard.source.inputFormat() != 'table'">
  372. <div>${_('File Type')}</div>
  373. <select data-bind="selectize: $root.createWizard.fileTypes, value: $root.createWizard.fileTypeName, optionsText: 'description', optionsValue: 'name'"></select>
  374. </label>
  375. <span class="inline-labels" data-bind="with: createWizard.source.format, visible: createWizard.source.show">
  376. <span data-bind="foreach: getArguments()">
  377. <!-- ko template: {name: 'arg-' + $data.type, data:{description: $data.description, value: $parent[$data.name]}}--><!-- /ko -->
  378. </span>
  379. </span>
  380. </div>
  381. <!-- /ko -->
  382. </div>
  383. <div class="card step" style="min-height: 310px;">
  384. <!-- ko ifnot: createWizard.isGuessingFormat -->
  385. <!-- ko if: createWizard.isGuessingFieldTypes -->
  386. <h3 class="card-heading simple">${_('Generating preview...')} <i class="fa fa-spinner fa-spin"></i></h3>
  387. <!-- /ko -->
  388. <!-- ko ifnot: createWizard.isGuessingFieldTypes -->
  389. <h3 class="card-heading simple">${_('Preview')}</h3>
  390. <div class="card-body">
  391. <div style="overflow: auto">
  392. <table class="table table-striped table-condensed table-preview">
  393. <thead>
  394. <tr data-bind="foreach: createWizard.source.sampleCols">
  395. ##<!-- ko template: 'field-preview-header-template' --><!-- /ko -->
  396. <th data-bind="truncatedText: name" style="padding-right:60px"></th>
  397. ## TODO nested
  398. </tr>
  399. </thead>
  400. <tbody data-bind="foreach: createWizard.source.sample">
  401. <tr data-bind="foreach: $data">
  402. ##<!-- ko if: $index() < $root.createWizard.source.columns().length -->
  403. ##<td data-bind="visible: $root.createWizard.source.columns()[$index()].keep, text: $data"></td>
  404. <td data-bind="truncatedText: $data"></td>
  405. ##<!-- ko with: $root.createWizard.source.columns()[$index()] -->
  406. ## <!-- ko template: 'output-generated-field-data-template' --> <!-- /ko -->
  407. ##<!-- /ko -->
  408. ##<!-- /ko -->
  409. </tr>
  410. </tbody>
  411. </table>
  412. </div>
  413. </div>
  414. <!-- /ko -->
  415. <!-- /ko -->
  416. </div>
  417. <!-- /ko -->
  418. <!-- /ko -->
  419. <!-- ko if: currentStep() == 2 -->
  420. <!-- ko with: createWizard.destination -->
  421. <div class="card step">
  422. <h3 class="card-heading simple">${_('Destination')}</h3>
  423. <div class="card-body">
  424. <div class="control-group">
  425. <label for="destinationType" class="control-label" data-bind="visible: ! $parent.createWizard.prefill.target_type"><div>${ _('Type') }</div>
  426. <select id="destinationType" data-bind="selectize: outputFormats, value: outputFormat, optionsValue: 'value', optionsText: 'name'"></select>
  427. </label>
  428. </div>
  429. <div class="control-group">
  430. <label for="collectionName" class="control-label "><div>${ _('Name') }</div></label>
  431. <!-- ko if: outputFormat() != 'table' && outputFormat() != 'database' -->
  432. <input type="text" class="form-control input-xlarge" id="collectionName" data-bind="value: name, valueUpdate: 'afterkeydown'" placeholder="${ _('Name') }">
  433. <!-- /ko -->
  434. <!-- ko if: outputFormat() == 'table' || outputFormat() == 'database' -->
  435. <input type="text" data-bind="value: name, hivechooser: name, skipColumns: true, skipTables: outputFormat() == 'database', valueUpdate: 'afterkeydown', apiHelperUser: '${ user }', apiHelperType: apiHelperType, mainScrollable: $('.content-panel'), 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') }">
  436. <!-- /ko -->
  437. <span class="help-inline muted" data-bind="visible: ! isTargetExisting()">
  438. ${ _('Create a new ') } <span data-bind="text: outputFormat"></span>
  439. </span>
  440. <span class="help-inline muted" data-bind="visible: isTargetExisting(), click: function(){ window.open(existingTargetUrl()) }">
  441. <!-- ko if: outputFormat() == 'index' -->
  442. ${ _('Adding data to the existing ') } <span data-bind="text: outputFormat"></span>
  443. <!-- /ko -->
  444. <!-- ko if: outputFormat() != 'index' -->
  445. <i class="fa fa-warning" style="color: #c09853"></i> ${ _('Already existing') } <span data-bind="text: outputFormat"></span>
  446. <!-- /ko -->
  447. <a href="javascript:void(0)" data-bind="attr: { href: existingTargetUrl() }, text: name" target="_blank"></a>
  448. </span>
  449. </div>
  450. </div>
  451. </div>
  452. <!-- ko if: outputFormat() == 'table' -->
  453. <div class="card step">
  454. <h3 class="card-heading simple">${_('Properties')}</h3>
  455. <div class="card-body">
  456. <div class="control-group">
  457. <label for="destinationFormat" class="control-label"><div>${ _('Format') }</div>
  458. <select id="destinationFormat" data-bind="selectize: tableFormats, value: tableFormat, optionsValue: 'value', optionsText: 'name'"></select>
  459. </label>
  460. </div>
  461. <div class="control-group">
  462. <label class="checkbox inline-block" data-bind="visible: tableFormat() != 'kudu'">
  463. <input type="checkbox" data-bind="checked: useDefaultLocation"> ${_('Store in Default location')}
  464. </label>
  465. </div>
  466. <div class="control-group" data-bind="visible: ! useDefaultLocation()">
  467. <label for="path" class="control-label"><div>${ _('External location') }</div>
  468. <input type="text" class="form-control path input-xxlarge" data-bind="value: nonDefaultLocation, filechooser: nonDefaultLocation, filechooserOptions: { linkMarkup: true, skipInitialPathIfEmpty: true }, valueUpdate: 'afterkeydown'">
  469. </label>
  470. </div>
  471. <div class="control-group">
  472. <label class="control-label"><div>${ _('Extras') }</div>
  473. <a href="javascript:void(0)" data-bind="css: {'inactive-action': !showProperties()}, click: function() {showProperties(!showProperties()) }" title="${ _('Show extra properties') }">
  474. <i class="fa fa-sliders fa-padding-top"></i>
  475. </a>
  476. </label>
  477. </div>
  478. <span data-bind="visible: showProperties">
  479. <div class="control-group">
  480. <label class="checkbox inline-block" data-bind="visible: $root.createWizard.source.inputFormat() != 'manual'">
  481. <input type="checkbox" data-bind="checked: importData, disable: ! useDefaultLocation() && $parent.createWizard.source.path() == nonDefaultLocation();"> ${_('Import data')}
  482. </label>
  483. </div>
  484. <div class="control-group">
  485. <label><div>${ _('Description') }</div>
  486. <input type="text" class="form-control input-xxlarge" data-bind="value: description, valueUpdate: 'afterkeydown'" placeholder="${ _('Description') }">
  487. </label>
  488. </div>
  489. <div class="control-group" data-bind="visible: $root.createWizard.source.inputFormat() == 'file'">
  490. <label class="checkbox inline-block">
  491. <input type="checkbox" data-bind="checked: hasHeader"> ${_('Use first row as header')}
  492. </label>
  493. </div>
  494. <div class="control-group" data-bind="visible: tableFormat() == 'text'">
  495. <label class="checkbox inline-block">
  496. <input type="checkbox" data-bind="checked: useCustomDelimiters"> ${_('Custom char delimiters')}
  497. </label>
  498. </div>
  499. <span class="inline-labels" data-bind="visible: tableFormat() == 'text' && useCustomDelimiters()">
  500. <label for="fieldDelimiter" class="control-label"><div>${ _('Field') }</div>
  501. <select id="fieldDelimiter" data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { create: true, maxLength: 2 }, value: customFieldDelimiter, optionsValue: 'value', optionsText: 'name'"></select>
  502. </label>
  503. <label for="collectionDelimiter" class="control-label"><div>${ _('Array, Map') }</div>
  504. <select id="collectionDelimiter" data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { create: true, maxLength: 2 }, value: customCollectionDelimiter, optionsValue: 'value', optionsText: 'name'"></select>
  505. </label>
  506. <label for="structDelimiter" class="control-label"><div>${ _('Struct') }</div>
  507. <select id="structDelimiter" data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { create: true, maxLength: 2 }, value: customMapDelimiter, optionsValue: 'value', optionsText: 'name'"></select>
  508. </label>
  509. </span>
  510. </span>
  511. <div class="control-group" data-bind="visible: tableFormat() == 'regexp'">
  512. <label for="customRegexp" class="control-label"><div>${ _('Regexp') }</div>
  513. <input id="customRegexp" class="input-xxlarge" type="text" data-bind="value: customRegexp" placeholder='([^]*) ([^]*) ([^]*) (-|\\[^\\]*\\]) ([^ \"]*|\"[^\"]*\") (-|[0-9]*) (-|[0-9]*)(?: ([^ \"]*|\".*\") ([^ \"]*|\".*\"))?'>
  514. </label>
  515. </div>
  516. <div class="control-group" data-bind="visible: tableFormat() == 'kudu'">
  517. <label for="kuduPks" class="control-label"><div>${ _('Primary keys') }</div>
  518. ## At least one selected
  519. <select id="kuduPks" data-bind="selectize: columns, selectedOptions: primaryKeys, selectedObjects: primaryKeyObjects, optionsValue: 'name', optionsText: 'name', innerSubscriber: 'name'" size="3" multiple="true"></select>
  520. </label>
  521. </div>
  522. <label class="control-label"><div>${ _('Partitions') }</div>
  523. <!-- ko if: tableFormat() != 'kudu' -->
  524. <div class="inline-table">
  525. <div class="form-inline" data-bind="foreach: partitionColumns">
  526. <a class="pointer pull-right margin-top-20" data-bind="click: function() { $parent.partitionColumns.remove($data); }"><i class="fa fa-minus"></i></a>
  527. <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field inline-block"></div>
  528. <div class="clearfix"></div>
  529. </div>
  530. <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>
  531. </div>
  532. <!-- /ko -->
  533. <!-- ko if: tableFormat() == 'kudu' -->
  534. <div class="form-inline inline-table">
  535. <ul class="unstyled kudu-partitions" data-bind="foreach: kuduPartitionColumns">
  536. <li>
  537. <a class="pointer pull-right" data-bind="click: function() { $parent.kuduPartitionColumns.remove($data); }"><i class="fa fa-minus"></i></a>
  538. <select data-bind="selectize: $parent.primaryKeyObjects, selectedOptions: columns, optionsValue: 'name', optionsText: 'name', selectizeOptions: { placeholder: '${ _ko('Columns...') }' }" size="3" multiple="true"></select>
  539. <select data-bind="selectize: ['RANGE BY', 'HASH'], value: name"></select>
  540. <!-- ko if: name() == 'HASH' -->
  541. <input class="input-small" type="number" data-bind="value: int_val">
  542. <!-- /ko -->
  543. <!-- ko if: name() == 'RANGE BY' -->
  544. <div class="form-inline" data-bind="foreach: range_partitions">
  545. <div class="range-partition">
  546. <a class="pull-right" data-bind="click: function() { $parent.range_partitions.remove($data); }"><i class="fa fa-minus"></i></a>
  547. <!-- ko if: name() == 'VALUES' -->
  548. <input type="text" class="input-small" data-bind="value: lower_val">
  549. <select data-bind="selectize: ['<', '<='], value: include_lower_val"></select>
  550. <select data-bind="selectize: ['VALUES', 'VALUE'], value: name"></select>
  551. <select data-bind="selectize: ['<', '<='], value: include_upper_val"></select>
  552. <input type="text" class="input-small" data-bind="value: upper_val">
  553. <!-- /ko -->
  554. <!-- ko if: name() == 'VALUE' -->
  555. <select data-bind="selectize: ['VALUES', 'VALUE'], value: name"></select>
  556. <div class="inline-block" data-bind="foreach: values" style="max-width: 370px">
  557. <input class="input-small" type="text" data-bind="textInput: value" style="margin-bottom: 5px">
  558. <a data-bind="click: function() { $parent.values.remove($data); }"><i class="fa fa-minus"></i></a>
  559. </div>
  560. <a class="inline-block" data-bind="click: function() { values.push(ko.mapping.fromJS({value: ''})); }" title="${_('Add value')}"><i class="fa fa-plus"></i></a>
  561. <div class="clearfix"></div>
  562. <!-- /ko -->
  563. </div>
  564. </div>
  565. <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>
  566. <!-- /ko -->
  567. <!-- /ko -->
  568. </li>
  569. </ul>
  570. <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>
  571. </div>
  572. <!-- /ko -->
  573. </label>
  574. </div>
  575. </div>
  576. <!-- /ko -->
  577. <!-- ko if: outputFormat() == 'table' || outputFormat() == 'index' -->
  578. <div class="card step">
  579. <h3 class="card-heading simple show-edit-on-hover">${_('Fields')} <a class="inactive-action pointer" data-bind="visible: columns().length > 0" href="#fieldsBulkEditor" data-toggle="modal"><i class="fa fa-edit"></i></a></h3>
  580. <div class="card-body no-margin-top">
  581. <form class="form-inline inline-table" data-bind="foreach: columns">
  582. <!-- ko if: $parent.outputFormat() == 'table' -->
  583. <!-- ko if: $root.createWizard.source.inputFormat() == 'manual' -->
  584. <a class="pointer pull-right margin-top-20" data-bind="click: function() { $parent.columns.remove($data); }"><i class="fa fa-minus"></i></a>
  585. <!-- /ko -->
  586. <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field inline-block"></div>
  587. <div class="clearfix"></div>
  588. <!-- /ko -->
  589. <!-- ko if: $parent.outputFormat() == 'index' -->
  590. <div data-bind="template: { name: 'index-field-template', data: $data }" class="margin-top-10 field inline-block index-field"></div>
  591. <div class="clearfix"></div>
  592. <!-- /ko -->
  593. </form>
  594. <div class="clearfix"></div>
  595. <!-- ko if: $root.createWizard.source.inputFormat() == 'manual' && outputFormat() == 'table' -->
  596. <a data-bind="click: function() { columns.push($root.loadDefaultField({})); }" class="pointer" title="${_('Add Field')}"><i class="fa fa-plus"></i> ${_('Add Field')}</a>
  597. <!-- /ko -->
  598. </div>
  599. </div>
  600. <!-- /ko -->
  601. <!-- ko if: outputFormat() == 'database' -->
  602. <div class="card step">
  603. <h3 class="card-heading simple">${_('Properties')}</h3>
  604. <div class="card-body">
  605. <label><div>${ _('Description') }</div>
  606. <input type="text" class="form-control input-xlarge" data-bind="value: description, valueUpdate: 'afterkeydown'" placeholder="${ _('Description') }">
  607. </label>
  608. <label class="checkbox">
  609. <input type="checkbox" data-bind="checked: useDefaultLocation"> ${_('Default location')}
  610. </label>
  611. <span data-bind="visible: ! useDefaultLocation()">
  612. <label for="path" class="control-label"><div>${ _('External location') }</div>
  613. <input type="text" class="form-control path input-xxlarge" data-bind="value: nonDefaultLocation, filechooser: nonDefaultLocation, filechooserOptions: { linkMarkup: true, skipInitialPathIfEmpty: true }, valueUpdate: 'afterkeydown'">
  614. </label>
  615. </span>
  616. </div>
  617. </div>
  618. <!-- /ko -->
  619. <!-- /ko -->
  620. <!-- /ko -->
  621. <div class="form-actions">
  622. <!-- ko if: previousStepVisible -->
  623. <button class="btn" data-bind="click: previousStep">${ _('Back') }</button>
  624. <!-- /ko -->
  625. <!-- ko if: currentStep() == 1 -->
  626. <button class="btn" data-bind="enable: !createWizard.isGuessingFormat() && createWizard.source.show(), click: function() { currentStep(2); }">
  627. ${_('Next')}
  628. </button>
  629. <!-- /ko -->
  630. <!-- ko if: currentStep() == 2 -->
  631. <button class="btn btn-primary disable-feedback" data-bind="click: createWizard.indexFile, enable: createWizard.readyToIndex() && ! createWizard.indexingStarted()">
  632. ${ _('Submit') } <i class="fa fa-spinner fa-spin" data-bind="visible: createWizard.indexingStarted"></i>
  633. </button>
  634. <!-- /ko -->
  635. <span data-bind="visible: createWizard.editorId">
  636. <a href="javascript:void(0)" class="btn btn-success" data-bind="attr: {href: '${ url('notebook:editor') }?editor=' + createWizard.editorId() }" target="_blank" title="${ _('Open') }">
  637. ${_('Status')}
  638. </a>
  639. </span>
  640. <div id="importerNotebook"></div>
  641. </div>
  642. </div>
  643. <div id="fieldsBulkEditor" class="modal hide fade">
  644. <div class="modal-header">
  645. <a href="#" class="close" data-dismiss="modal">&times;</a>
  646. <h3>${ _('Write or paste comma separated field names') }</h3>
  647. </div>
  648. <div class="modal-body">
  649. <input type="text" class="input-xxlarge" placeholder="${ _('e.g. id, name, salary') }" data-bind="textInput: createWizard.destination.bulkColumnNames">
  650. </div>
  651. <div class="modal-footer">
  652. <button class="btn" data-dismiss="modal" aria-hidden="true">${ _('Cancel') }</button>
  653. <button class="btn btn-primary" data-bind="click: createWizard.destination.processBulkColumnNames">${ _('Change field names') }</button>
  654. </div>
  655. </div>
  656. </script>
  657. <script type="text/html" id="table-field-template">
  658. <div>
  659. <label data-bind="visible: level() == 0 || ($parent.type() != 'array' && $parent.type() != 'map')">${ _('Name') }&nbsp;
  660. <input type="text" class="input-large" placeholder="${ _('Field name') }" required data-bind="textInput: name">
  661. </label>
  662. <label class="margin-left-5">${ _('Type') }&nbsp;
  663. <!-- ko if: ! (level() > 0 && $parent.type() == 'map') -->
  664. <select class="input-small" data-bind="selectize: $root.createWizard.hiveFieldTypes, value: type"></select>
  665. <!-- /ko -->
  666. <!-- ko if: level() > 0 && $parent.type() == 'map' -->
  667. <select class="input-small" data-bind="selectize: $root.createWizard.hivePrimitiveFieldTypes, value: keyType"></select>
  668. <select class="input-small" data-bind="selectize: $root.createWizard.hiveFieldTypes, value: type"></select>
  669. <!-- /ko -->
  670. <input type="number" class="input-small" placeholder="${ _('Length') }" data-bind="value: length, visible: type() == 'varchar' || type() == 'char'">
  671. </label>
  672. <span data-bind="visible: level() == 0 || ($parent.type() != 'array' && $parent.type() != 'map')">
  673. <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>
  674. <span data-bind="visible: showProperties">
  675. <input type="text" class="input-medium margin-left-5" placeholder="${ _('Field comment') }" data-bind="value: comment">
  676. </span>
  677. </span>
  678. <!-- ko if: level() > 0 && $parent.type() == 'struct' && $parent.nested().length > 1 -->
  679. <a data-bind="click: function() { $parent.nested.remove($data); }"><i class="fa fa-minus"></i></a>
  680. <!-- /ko -->
  681. <!-- ko if: $root.createWizard.source.inputFormat() != 'manual' && level() == 0 && (typeof isPartition === 'undefined' || !isPartition()) -->
  682. <div class="inline-block muted field-content-preview" data-bind="truncatedText: $root.createWizard.source.sample()[0][$index()]"></div>
  683. <div class="inline-block muted field-content-preview" data-bind="truncatedText: $root.createWizard.source.sample()[1][$index()]"></div>
  684. <!-- /ko -->
  685. <!-- ko if: type() == 'array' || type() == 'map' || type() == 'struct' -->
  686. <div class="operation" data-bind="template: { name: 'table-field-template', foreach: nested }"></div>
  687. <a data-bind="click: function() { nested.push($root.loadDefaultField({level: level() + 1})); }, visible: type() == 'struct'"><i class="fa fa-plus"></i></a>
  688. <!-- /ko -->
  689. </div>
  690. </script>
  691. <script type="text/html" id="index-field-template">
  692. <label>${ _('Name') }&nbsp;
  693. <input type="text" class="input-large" placeholder="${ _('Field name') }" data-bind="value: name">
  694. </label>
  695. <label class="margin-left-5">${ _('Type') }&nbsp;
  696. <select class="input-small" data-bind="selectize: $root.createWizard.fieldTypes, value: type"></select>
  697. </label>
  698. <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>
  699. <span data-bind="visible: showProperties" class="field-properties">
  700. <label class="checkbox">
  701. <input type="checkbox" data-bind="checked: unique"> ${_('Unique')}
  702. </label>
  703. <label class="checkbox">
  704. <input type="checkbox" data-bind="checked: keep"> ${_('Keep in index')}
  705. </label>
  706. <label class="checkbox">
  707. <input type="checkbox" data-bind="checked: required"> ${_('Required')}
  708. </label>
  709. </span>
  710. <!-- ko if: operations().length == 0 -->
  711. <a class="pointer margin-left-20" data-bind="click: $root.createWizard.addOperation" title="${_('Add Operation')}"><i class="fa fa-plus"></i> ${_('Operation')}</a>
  712. <!-- /ko -->
  713. <div data-bind="foreach: operations">
  714. <div data-bind="template: { name:'operation-template',data:{operation: $data, list: $parent.operations}}"></div>
  715. </div>
  716. <!-- ko if: operations().length > 0 -->
  717. <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>
  718. <!-- /ko -->
  719. </script>
  720. <script type="text/html" id="operation-template">
  721. <div class="operation">
  722. <select data-bind="selectize: $root.createWizard.operationTypes.map(function(o){return o.name}), value: operation.type"></select>
  723. <!-- ko template: "args-template" --><!-- /ko -->
  724. <!-- ko if: operation.settings().outputType() == "custom_fields" -->
  725. <label class="margin-left-5">${ _('Number of expected fields') }
  726. <input type="number" class="input-mini" data-bind="value: operation.numExpectedFields">
  727. </label>
  728. <!-- /ko -->
  729. <a class="pointer margin-left-20" data-bind="click: function(){$root.createWizard.removeOperation(operation, list)}" title="${ _('Remove') }"><i class="fa fa-times"></i></a>
  730. <div class="margin-left-20" data-bind="foreach: operation.fields">
  731. <div data-bind="template: { name:'index-field-template', data:$data }" class="margin-top-10 field index-field"></div>
  732. </div>
  733. </div>
  734. </script>
  735. <script type="text/html" id="args-template">
  736. <!-- ko foreach: {data: operation.settings().getArguments(), as: 'argument'} -->
  737. <!-- ko template: {name: 'arg-' + argument.type, data: {description: argument.description, value: $parent.operation.settings()[argument.name]}}--><!-- /ko -->
  738. <!-- /ko -->
  739. </script>
  740. <script type="text/html" id="arg-text">
  741. <label>
  742. <div data-bind="text: description"></div>
  743. <input type="text" class="input" data-bind="attr: {placeholder: description}, value: value">
  744. </label>
  745. </script>
  746. <script type="text/html" id="arg-text-delimiter">
  747. <label>
  748. <div data-bind="text: description"></div>
  749. <select data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { create: true, maxLength: 2 }, value: value, optionsValue: 'value', optionsText: 'name', attr: {placeholder: description}"></select>
  750. </label>
  751. </script>
  752. <script type="text/html" id="arg-checkbox">
  753. <label class="checkbox">
  754. <input type="checkbox" data-bind="checked: value">
  755. <span data-bind="text: description" style="vertical-align: middle"></span>
  756. </label>
  757. </script>
  758. <script type="text/html" id="arg-mapping">
  759. <!-- ko foreach: value-->
  760. <div>
  761. <input type="text" data-bind="value: key, attr: {placeholder: 'key'}">
  762. <input type="text" data-bind="value: value, attr: {placeholder: 'value'}">
  763. <button class="btn" data-bind="click: function(){$parent.value.remove($data)}">${_('Remove Pair')}</button>
  764. </div>
  765. <!-- /ko -->
  766. <button class="btn" data-bind="click: function(){value.push({key: ko.observable(''), value: ko.observable('')})}">${_('Add Pair')}</button>
  767. <br>
  768. </script>
  769. <script type="text/html" id="field-preview-header-template">
  770. <th data-bind="visible: keep, text: name" style="padding-right:60px"></th>
  771. <!-- ko foreach: operations -->
  772. <!--ko foreach: fields -->
  773. <!-- ko template: 'field-preview-header-template' --><!-- /ko -->
  774. <!-- /ko -->
  775. <!--/ko -->
  776. </script>
  777. <script type="text/html" id="output-generated-field-data-template">
  778. <!-- ko foreach: operations -->
  779. <!--ko foreach: fields -->
  780. <td data-bind="visible: keep">[[${_('generated')}]]</td>
  781. <!-- ko template: 'output-generated-field-data-template' --><!-- /ko -->
  782. <!-- /ko -->
  783. <!--/ko -->
  784. </script>
  785. <script type="text/html" id="importerNotebook-progress">
  786. <!-- ko with: selectedNotebook -->
  787. <!-- ko foreach: snippets -->
  788. <div class="progress-snippet progress active" data-bind="css: {
  789. 'progress-starting': progress() == 0 && status() == 'running',
  790. 'progress-warning': progress() > 0 && progress() < 100,
  791. 'progress-success': progress() == 100,
  792. 'progress-danger': progress() == 0 && errors().length > 0}" style="background-color: #FFF; width: 100%; height: 4px">
  793. <div class="bar" data-bind="style: {'width': (errors().length > 0 ? 100 : Math.max(2, progress())) + '%'}"></div>
  794. </div>
  795. <div class="snippet-error-container alert alert-error alert-error-gradient" data-bind="visible: errors().length > 0">
  796. <ul class="unstyled" data-bind="foreach: errors">
  797. <li data-bind="text: message"></li>
  798. </ul>
  799. </div>
  800. <!-- /ko -->
  801. <!-- /ko -->
  802. </script>
  803. <script type="text/javascript" charset="utf-8">
  804. (function () {
  805. ko.options.deferUpdates = true;
  806. var MAPPINGS = {
  807. SOLR_TO_HIVE: {
  808. "string": "string",
  809. "long": "bigint",
  810. "double": "double",
  811. "date": "date"
  812. },
  813. get: function(type, key, defaultValue) {
  814. return type[key] || defaultValue
  815. }
  816. }
  817. var fieldNum = 0;
  818. var getNewFieldName = function () {
  819. fieldNum++;
  820. return "new_field_" + fieldNum
  821. };
  822. var createDefaultField = function () {
  823. var defaultField = ko.mapping.fromJS(${default_field_type | n});
  824. defaultField.name = ko.observable(getNewFieldName());
  825. return defaultField;
  826. };
  827. var Operation = function (type) {
  828. var self = this;
  829. var createArgumentValue = function (arg) {
  830. if (arg.type == "mapping") {
  831. return ko.observableArray([]);
  832. }
  833. else if (arg.type == "checkbox") {
  834. return ko.observable(false);
  835. }
  836. else {
  837. return ko.observable("");
  838. }
  839. }
  840. var constructSettings = function (type) {
  841. var settings = {};
  842. var operation = viewModel.createWizard.operationTypes.find(function (currOperation) {
  843. return currOperation.name == type;
  844. });
  845. for (var i = 0; i < operation.args.length; i++) {
  846. var argVal = createArgumentValue(operation.args[i]);
  847. if (operation.args[i].type == "checkbox" && operation.outputType == "checkbox_fields") {
  848. argVal.subscribe(function (newVal) {
  849. if (newVal) {
  850. self.fields.push(createDefaultField());
  851. }
  852. else {
  853. self.fields.pop();
  854. }
  855. });
  856. }
  857. settings[operation.args[i].name] = argVal;
  858. }
  859. settings.getArguments = function () {
  860. return operation.args
  861. };
  862. settings.outputType = function () {
  863. return operation.outputType;
  864. }
  865. return settings;
  866. };
  867. var init = function () {
  868. self.fields([]);
  869. self.numExpectedFields(0);
  870. self.numExpectedFields.subscribe(function (numExpectedFields) {
  871. if (numExpectedFields < self.fields().length) {
  872. self.fields(self.fields().slice(0, numExpectedFields));
  873. }
  874. else if (numExpectedFields > self.fields().length) {
  875. var difference = numExpectedFields - self.fields().length;
  876. for (var i = 0; i < difference; i++) {
  877. self.fields.push(createDefaultField());
  878. }
  879. }
  880. });
  881. self.settings(constructSettings(self.type()));
  882. }
  883. self.load = function (data) {
  884. self.numExpectedFields(data.numExpectedFields);
  885. var newSettings = constructSettings(data.type);
  886. for (var key in data.settings) {
  887. newSettings[key] = ko.mapping.fromJS(data.settings[key]);
  888. }
  889. self.settings(newSettings);
  890. data.fields.forEach(function (field) {
  891. self.fields.push(loadField(field));
  892. });
  893. }
  894. self.type = ko.observable(type);
  895. self.fields = ko.observableArray();
  896. self.numExpectedFields = ko.observable();
  897. self.settings = ko.observable();
  898. init();
  899. self.type.subscribe(function (newType) {
  900. init();
  901. });
  902. }
  903. var FileType = function (typeName, args) {
  904. var self = this;
  905. var type;
  906. var init = function () {
  907. self.type = ko.observable(typeName);
  908. var types = viewModel.createWizard.fileTypes;
  909. for (var i = 0; i < types.length; i++) {
  910. if (types[i].name == typeName) {
  911. type = types[i];
  912. break;
  913. }
  914. }
  915. for (var i = 0; i < type.args.length; i++) {
  916. self[type.args[i].name] = ko.observable();
  917. }
  918. if (args) {
  919. loadFromObj(args);
  920. }
  921. for (var i = 0; i < type.args.length; i++) {
  922. self[type.args[i].name].subscribe(viewModel.createWizard.guessFieldTypes);
  923. }
  924. }
  925. var loadFromObj = function (args) {
  926. for (var attr in args) {
  927. self[attr] = ko.mapping.fromJS(args[attr]);
  928. }
  929. }
  930. self.getArguments = function () {
  931. return type.args;
  932. }
  933. self.isCustomizable = function () {
  934. return type.isCustomizable;
  935. }
  936. init();
  937. }
  938. var Source = function (vm, wizard) {
  939. var self = this;
  940. self.name = ko.observable('');
  941. self.sample = ko.observableArray();
  942. self.sampleCols = ko.observableArray();
  943. self.inputFormat = ko.observable('file');
  944. self.inputFormat.subscribe(function(val) {
  945. wizard.destination.columns.removeAll();
  946. if (val === 'table'){
  947. huePubSub.publish('assist.database.get', function (activeDBEntry) {
  948. self.table(activeDBEntry.databaseName + '.');
  949. });
  950. }
  951. resizeElements();
  952. });
  953. self.inputFormats = ko.observableArray([
  954. {'value': 'file', 'name': 'File'},
  955. {'value': 'manual', 'name': 'Manually'},
  956. % if ENABLE_NEW_INDEXER.get():
  957. {'value': 'query', 'name': 'SQL Query'},
  958. {'value': 'table', 'name': 'Table'},
  959. % endif
  960. ##{'value': 'dbms', 'name': 'DBMS'},
  961. ##{'value': 'text', 'name': 'Paste Text'},
  962. ]);
  963. if (wizard.prefill.source_type) {
  964. self.inputFormats([
  965. {'value': 'file', 'name': 'File'},
  966. {'value': 'manual', 'name': 'Manually'},
  967. ]);
  968. if (wizard.prefill.source_type() == 'manual') {
  969. self.inputFormat(wizard.prefill.source_type());
  970. }
  971. }
  972. // File
  973. self.path = ko.observable('');
  974. self.path.subscribe(function(val) {
  975. if (val) {
  976. vm.createWizard.guessFormat();
  977. vm.createWizard.destination.nonDefaultLocation(val);
  978. }
  979. resizeElements();
  980. });
  981. self.isObjectStore = ko.computed(function() {
  982. return self.inputFormat() == 'file' && /^s3a:\/\/.*$/.test(self.path());
  983. });
  984. self.isObjectStore.subscribe(function(newVal) {console.log(newVal);
  985. vm.createWizard.destination.useDefaultLocation(! newVal);
  986. });
  987. // Table
  988. self.table = ko.observable('');
  989. self.tableName = ko.computed(function() {
  990. return self.table().indexOf('.') > 0 ? self.table().split('.', 2)[1] : self.table();
  991. });
  992. self.databaseName = ko.computed(function() {
  993. return self.table().indexOf('.') > 0 ? self.table().split('.', 2)[0] : 'default';
  994. });
  995. self.table.subscribe(function(val) {
  996. resizeElements();
  997. });
  998. self.apiHelperType = ko.observable('hive');
  999. // Queries
  1000. self.query = ko.observable('');
  1001. self.draggedQuery = ko.observable();
  1002. self.format = ko.observable();
  1003. self.format.subscribe(function(newVal) {
  1004. if (typeof newVal.hasHeader !== 'undefined') {
  1005. vm.createWizard.destination.hasHeader(newVal.hasHeader());
  1006. newVal.hasHeader.subscribe(function(newVal) {
  1007. vm.createWizard.destination.hasHeader(newVal);
  1008. });
  1009. }
  1010. if (typeof newVal.fieldSeparator !== 'undefined') {
  1011. vm.createWizard.destination.useCustomDelimiters(newVal.fieldSeparator() != ',');
  1012. vm.createWizard.destination.customFieldDelimiter(newVal.fieldSeparator());
  1013. newVal.fieldSeparator.subscribe(function(newVal) {
  1014. vm.createWizard.destination.customFieldDelimiter(newVal);
  1015. });
  1016. }
  1017. });
  1018. self.show = ko.computed(function() {
  1019. if (self.inputFormat() == 'file') {
  1020. return self.path().length > 0;
  1021. } else if (self.inputFormat() == 'table') {
  1022. return self.tableName().length > 0;
  1023. } else if (self.inputFormat() == 'query') {
  1024. return self.query();
  1025. } else if (self.inputFormat() == 'manual') {
  1026. return true;
  1027. }
  1028. });
  1029. self.defaultName = ko.computed(function() {
  1030. var name = ''
  1031. if (self.inputFormat() == 'file') {
  1032. if (self.path()) {
  1033. name = self.path().split('/').pop().split('.')[0];
  1034. }
  1035. } else if (self.inputFormat() == 'table') {
  1036. if (self.table().split('.', 2).length == 2) {
  1037. name = self.table();
  1038. }
  1039. } else if (self.inputFormat() == 'query') {
  1040. if (self.query()) {
  1041. name = self.name();
  1042. }
  1043. } else if (self.inputFormat() == 'manual') {
  1044. name = wizard.prefill.target_path ? wizard.prefill.target_path() + '.' : '';
  1045. }
  1046. return name.replace(/ /g, '_').toLowerCase();
  1047. });
  1048. self.defaultName.subscribe(function(newVal) {
  1049. vm.createWizard.destination.name(newVal);
  1050. });
  1051. };
  1052. var Destination = function (vm, wizard) {
  1053. var self = this;
  1054. self.name = ko.observable('').extend({throttle: 500});
  1055. self.name.subscribe(function (name) {
  1056. var exists = false;
  1057. if (name.length == 0) {
  1058. self.isTargetExisting(false);
  1059. }
  1060. else if (self.outputFormat() == 'file') {
  1061. // Todo
  1062. // self.path()
  1063. }
  1064. else if (self.outputFormat() == 'table') {
  1065. if (self.tableName() !== '') {
  1066. self.isTargetExisting(false);
  1067. $.get("/beeswax/api/autocomplete/" + self.databaseName() + '/' + self.tableName(), function (data) {
  1068. self.isTargetExisting(data.code != 500);
  1069. }).fail(function (xhr, textStatus, errorThrown) { self.isTargetExisting(false); });
  1070. }
  1071. else {
  1072. self.isTargetExisting(false);
  1073. }
  1074. }
  1075. else if (self.outputFormat() == 'index') {
  1076. $.post("/search/get_collection", {
  1077. name: self.name()
  1078. }, function (data) {
  1079. self.isTargetExisting(data.status == 0);
  1080. }).fail(function (xhr, textStatus, errorThrown) { self.isTargetExisting(false); });
  1081. }
  1082. resizeElements();
  1083. });
  1084. self.apiHelperType = ko.observable('hive');
  1085. self.description = ko.observable('');
  1086. self.outputFormat = ko.observable('table');
  1087. self.outputFormat.subscribe(function (newValue) {
  1088. if (newValue != 'database') {
  1089. wizard.guessFieldTypes();
  1090. resizeElements();
  1091. }
  1092. });
  1093. self.outputFormatsList = ko.observableArray([
  1094. {'name': 'Table', 'value': 'table'},
  1095. {'name': 'Solr index', 'value': 'index'},
  1096. {'name': 'File', 'value': 'file'},
  1097. {'name': 'Database', 'value': 'database'},
  1098. ]);
  1099. self.outputFormats = ko.computed(function() {
  1100. return $.grep(self.outputFormatsList(), function(format) {
  1101. if (format.value == 'database' && wizard.source.inputFormat() != 'manual') {
  1102. return false;
  1103. }
  1104. else if (format.value == 'file' && wizard.source.inputFormat() != 'manual') {
  1105. return false;
  1106. }
  1107. return true;
  1108. })
  1109. });
  1110. if (wizard.prefill.target_type) {
  1111. self.outputFormat(wizard.prefill.target_type());
  1112. if (wizard.prefill.target_type() == 'database') {
  1113. vm.currentStep(2);
  1114. };
  1115. }
  1116. self.format = ko.observable();
  1117. self.columns = ko.observableArray();
  1118. // UI
  1119. self.bulkColumnNames = ko.observable('');
  1120. self.showProperties = ko.observable(false);
  1121. self.columns.subscribe(function (newVal) {
  1122. self.bulkColumnNames(newVal.map(function (item) {
  1123. return item.name()
  1124. }).join(','));
  1125. });
  1126. self.processBulkColumnNames = function () {
  1127. var val = self.bulkColumnNames();
  1128. try {
  1129. if (val.indexOf("\"") == -1 && val.indexOf("'") == -1) {
  1130. val = '"' + val.replace(/,/gi, '","') + '"';
  1131. }
  1132. if (val.indexOf("[") == -1) {
  1133. val = "[" + val + "]";
  1134. }
  1135. var parsed = JSON.parse(val);
  1136. self.columns().forEach(function (item, cnt) {
  1137. if ($.trim(parsed[cnt]) !== '') {
  1138. item.name($.trim(parsed[cnt]));
  1139. }
  1140. });
  1141. }
  1142. catch (err) {
  1143. }
  1144. $('#fieldsBulkEditor').modal('hide');
  1145. }
  1146. self.isTargetExisting = ko.observable();
  1147. self.existingTargetUrl = ko.computed(function() { // Should open generic sample popup instead
  1148. if (self.isTargetExisting()) {
  1149. if (self.outputFormat() == 'file') {
  1150. // Todo
  1151. return '';
  1152. }
  1153. else if (self.outputFormat() == 'table') {
  1154. return '/metastore/table/' + self.databaseName() + '/' + self.tableName();
  1155. }
  1156. else if (self.outputFormat() == 'index') {
  1157. return '${ url("indexer:collections") }#edit/' + self.name();
  1158. }
  1159. }
  1160. return '';
  1161. });
  1162. // Table
  1163. self.tableName = ko.computed(function() {
  1164. return self.outputFormat() == 'table' && self.name().indexOf('.') > 0 ? self.name().split('.', 2)[1] : self.name();
  1165. });
  1166. self.databaseName = ko.computed(function() {
  1167. return self.outputFormat() == 'table' && self.name().indexOf('.') > 0 ? self.name().split('.', 2)[0] : 'default';
  1168. });
  1169. self.tableFormat = ko.observable('text');
  1170. self.tableFormat.subscribe(function(newVal) {
  1171. if (newVal == 'kudu' && self.kuduPartitionColumns().length == 0) {
  1172. self.kuduPartitionColumns.push(ko.mapping.fromJS(self.KUDU_DEFAULT_PARTITION_COLUMN));
  1173. }
  1174. });
  1175. self.KUDU_DEFAULT_RANGE_PARTITION_COLUMN = {values: [{value: ''}], name: 'VALUES', lower_val: 0, include_lower_val: '<=', upper_val: 1, include_upper_val: '<='};
  1176. self.KUDU_DEFAULT_PARTITION_COLUMN = {columns: [], range_partitions: [self.KUDU_DEFAULT_RANGE_PARTITION_COLUMN], name: 'HASH', int_val: 16};
  1177. self.tableFormats = ko.observableArray([
  1178. {'value': 'text', 'name': 'Text'},
  1179. {'value': 'parquet', 'name': 'Parquet'},
  1180. {'value': 'kudu', 'name': 'Kudu'},
  1181. {'value': 'csv', 'name': 'Csv'},
  1182. {'value': 'json', 'name': 'Json'},
  1183. {'value': 'regexp', 'name': 'Regexp'},
  1184. {'value': 'orc', 'name': 'ORC'},
  1185. ]);
  1186. self.partitionColumns = ko.observableArray();
  1187. self.kuduPartitionColumns = ko.observableArray();
  1188. self.primaryKeys = ko.observableArray();
  1189. self.primaryKeyObjects = ko.observableArray();
  1190. self.importData = ko.observable(true);
  1191. self.useDefaultLocation = ko.observable(true);
  1192. self.nonDefaultLocation = ko.observable('');
  1193. self.hasHeader = ko.observable(true);
  1194. self.useCustomDelimiters = ko.observable(false);
  1195. self.customFieldDelimiter = ko.observable(',');
  1196. self.customCollectionDelimiter = ko.observable('\\002');
  1197. self.customMapDelimiter = ko.observable('\\003');
  1198. self.customRegexp = ko.observable('');
  1199. // Index
  1200. };
  1201. var CreateWizard = function (vm) {
  1202. var self = this;
  1203. var guessFieldTypesXhr;
  1204. self.fileType = ko.observable();
  1205. self.fileType.subscribe(function (newType) {
  1206. if (self.source.format()) {
  1207. self.source.format().type(newType.name);
  1208. }
  1209. });
  1210. self.fileTypeName = ko.observable();
  1211. self.fileTypeName.subscribe(function (newType) {
  1212. for (var i = 0; i < self.fileTypes.length; i++) {
  1213. if (self.fileTypes[i].name == newType) {
  1214. self.fileType(self.fileTypes[i]);
  1215. break;
  1216. }
  1217. }
  1218. });
  1219. self.operationTypes = ${operators_json | n};
  1220. self.fieldTypes = ${fields_json | n}.solr;
  1221. self.hivePrimitiveFieldTypes = ${fields_json | n}.hivePrimitive;
  1222. self.hiveFieldTypes = ${fields_json | n}.hive;
  1223. self.fileTypes = ${file_types_json | n};
  1224. self.prefill = ko.mapping.fromJS(${prefill | n});
  1225. self.show = ko.observable(true);
  1226. self.showCreate = ko.observable(false);
  1227. self.source = new Source(vm, self);
  1228. self.destination = new Destination(vm, self);
  1229. self.customDelimiters = ko.observable([
  1230. {'value': ',', 'name': 'Comma (,)'},
  1231. {'value': '\\t', 'name': '^Tab (\\t)'},
  1232. {'value': '\\n', 'name': 'New line'},
  1233. {'value': ' ', 'name': 'Space'},
  1234. {'value': '"', 'name': 'Double Quote'},
  1235. {'value': '\\001', 'name': '^A (\\001)'},
  1236. {'value': '\\002', 'name': '^B (\\002)'},
  1237. {'value': '\\003', 'name': '^C (\\003)'},
  1238. ]);
  1239. self.editorId = ko.observable();
  1240. self.jobId = ko.observable();
  1241. self.editorVM = null;
  1242. self.indexingStarted = ko.observable(false);
  1243. self.readyToIndex = ko.computed(function () {
  1244. var validFields = self.destination.columns().length || self.destination.outputFormat() == 'database';
  1245. var validDestination = self.destination.name().length > 0 && (['table', 'database'].indexOf(self.destination.outputFormat()) == -1 || /^([a-zA-Z0-9_]+\.)?[a-zA-Z0-9_]*$/.test(self.destination.name()));
  1246. var validTableColumns = self.destination.outputFormat() != 'table' || $.grep(self.destination.columns(), function(column) {
  1247. return column.name().length == 0;
  1248. }).length == 0;
  1249. var isTargetAlreadyExisting = ! self.destination.isTargetExisting() || self.destination.outputFormat() == 'index';
  1250. return validDestination && validFields && validTableColumns && isTargetAlreadyExisting;
  1251. });
  1252. self.formatTypeSubscribed = false;
  1253. self.source.format.subscribe(function (newVal) {
  1254. for (var i = 0; i < self.fileTypes.length; i++) {
  1255. if (self.fileTypes[i].name == self.source.format().type()) {
  1256. self.fileType(self.fileTypes[i]);
  1257. self.fileTypeName(self.fileTypes[i].name);
  1258. break;
  1259. }
  1260. }
  1261. if (self.source.format().type) {
  1262. if (!self.formatTypeSubscribed) {
  1263. self.formatTypeSubscribed = true;
  1264. self.source.format().type.subscribe(function (newType) {
  1265. self.source.format(new FileType(newType));
  1266. self.destination.columns.removeAll();
  1267. self.guessFieldTypes();
  1268. });
  1269. }
  1270. }
  1271. });
  1272. self.isGuessingFormat = ko.observable(false);
  1273. self.guessFormat = function () {
  1274. self.isGuessingFormat(true);
  1275. self.destination.columns.removeAll();
  1276. $.post("${ url('indexer:guess_format') }", {
  1277. "fileFormat": ko.mapping.toJSON(self.source)
  1278. }, function (resp) {
  1279. if (resp.status != 0) {
  1280. $(document).trigger("error", resp.message);
  1281. } else {
  1282. var newFormat = ko.mapping.fromJS(new FileType(resp['type'], resp));
  1283. self.source.format(newFormat);
  1284. self.guessFieldTypes();
  1285. }
  1286. self.isGuessingFormat(false);
  1287. viewModel.wizardEnabled(true);
  1288. }).fail(function (xhr, textStatus, errorThrown) {
  1289. $(document).trigger("error", xhr.responseText);
  1290. viewModel.isLoading(false);
  1291. self.isGuessingFormat(false);
  1292. });
  1293. };
  1294. self.isGuessingFieldTypes = ko.observable(false);
  1295. self.guessFieldTypes = function () {
  1296. if (guessFieldTypesXhr) {
  1297. guessFieldTypesXhr.abort();
  1298. }
  1299. self.isGuessingFieldTypes(true);
  1300. guessFieldTypesXhr = $.post("${ url('indexer:guess_field_types') }", {
  1301. "fileFormat": ko.mapping.toJSON(self.source)
  1302. }, function (resp) {
  1303. resp.columns.forEach(function (entry, i, arr) {
  1304. if (self.destination.outputFormat() === 'table'){
  1305. entry.type = MAPPINGS.get(MAPPINGS.SOLR_TO_HIVE, entry.type, 'string');
  1306. }
  1307. arr[i] = loadField(entry, self.destination.columns, i);
  1308. });
  1309. self.source.sampleCols(resp.sample_cols ? resp.sample_cols : resp.columns);
  1310. self.source.sample(resp.sample);
  1311. self.destination.columns(resp.columns);
  1312. self.isGuessingFieldTypes(false);
  1313. }).fail(function (xhr, textStatus, errorThrown) {
  1314. $(document).trigger("error", xhr.responseText);
  1315. self.isGuessingFieldTypes(false);
  1316. viewModel.isLoading(false);
  1317. });
  1318. };
  1319. self.isIndexing = ko.observable(false);
  1320. self.indexingError = ko.observable(false);
  1321. self.indexingSuccess = ko.observable(false);
  1322. self.indexFile = function () {
  1323. if (! self.readyToIndex()) {
  1324. return;
  1325. }
  1326. %if not is_embeddable:
  1327. self.indexingStarted(true);
  1328. viewModel.isLoading(true);
  1329. self.isIndexing(true);
  1330. $.post("${ url('indexer:importer_submit') }", {
  1331. "source": ko.mapping.toJSON(self.source),
  1332. "destination": ko.mapping.toJSON(self.destination)
  1333. }, function (resp) {
  1334. if (resp.status != 0) {
  1335. $(document).trigger("error", resp.message);
  1336. self.indexingStarted(false);
  1337. self.isIndexing(false);
  1338. } else {
  1339. self.showCreate(true);
  1340. self.editorId(resp.history_id);
  1341. self.jobId(resp.handle.id);
  1342. $('#importerNotebook').html($('#importerNotebook-progress').html());
  1343. self.editorVM = new EditorViewModel(resp.history_uuid, '', {
  1344. user: '${ user.username }',
  1345. userId: ${ user.id },
  1346. languages: [{name: "Java", type: "java"}, {name: "Hive SQL", type: "hive"}], // TODO reuse
  1347. snippetViewSettings: {
  1348. java : {
  1349. snippetIcon: 'fa-file-archive-o '
  1350. },
  1351. hive: {
  1352. placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
  1353. aceMode: 'ace/mode/hive',
  1354. snippetImage: '${ static("beeswax/art/icon_beeswax_48.png") }',
  1355. sqlDialect: true
  1356. },
  1357. impala: {
  1358. placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
  1359. aceMode: 'ace/mode/impala',
  1360. snippetImage: '${ static("impala/art/icon_impala_48.png") }',
  1361. sqlDialect: true
  1362. }
  1363. }
  1364. });
  1365. self.editorVM.editorMode(true);
  1366. self.editorVM.isNotificationManager(true);
  1367. ko.cleanNode($("#importerNotebook")[0]);
  1368. ko.applyBindings(self.editorVM, $("#importerNotebook")[0]);
  1369. self.editorVM.openNotebook(resp.history_uuid, null, true, function(){
  1370. self.editorVM.selectedNotebook().snippets()[0].progress.subscribe(function(val){
  1371. if (val == 100){
  1372. self.indexingStarted(false);
  1373. self.isIndexing(false);
  1374. self.indexingSuccess(true);
  1375. }
  1376. });
  1377. self.editorVM.selectedNotebook().snippets()[0].status.subscribe(function(val){
  1378. if (val == 'failed'){
  1379. self.isIndexing(false);
  1380. self.indexingStarted(false);
  1381. self.indexingError(true);
  1382. } else if (val == 'available') {
  1383. var snippet = self.editorVM.selectedNotebook().snippets()[0]; // Could be native to editor at some point
  1384. if (! snippet.result.handle().has_more_statements) {
  1385. if (self.editorVM.selectedNotebook().onSuccessUrl()) {
  1386. huePubSub.publish('assist.clear.db.cache', {sourceType: 'hive'});
  1387. window.location.href = self.editorVM.selectedNotebook().onSuccessUrl();
  1388. }
  1389. } else { // Perform last DROP statement execute
  1390. snippet.execute();
  1391. }
  1392. }
  1393. });
  1394. self.editorVM.selectedNotebook().snippets()[0].checkStatus();
  1395. });
  1396. }
  1397. viewModel.isLoading(false);
  1398. }).fail(function (xhr, textStatus, errorThrown) {
  1399. $(document).trigger("error", xhr.responseText);
  1400. viewModel.isLoading(false);
  1401. self.indexingStarted(false);
  1402. self.isIndexing(false);
  1403. });
  1404. % else:
  1405. $.post("${ url('indexer:importer_submit') }", {
  1406. "source": ko.mapping.toJSON(self.source),
  1407. "destination": ko.mapping.toJSON(self.destination)
  1408. }, function (resp) {
  1409. if (resp.history_uuid) {
  1410. $.jHueNotify.info("${ _('Task ') }" + resp.history_uuid + "${_(' submitted.') }");
  1411. huePubSub.publish('notebook.task.submitted', resp.history_uuid);
  1412. } else {
  1413. $(document).trigger("error", data.message);
  1414. }
  1415. }).fail(function (xhr, textStatus, errorThrown) {
  1416. $(document).trigger("error", xhr.responseText);
  1417. });
  1418. % endif
  1419. }
  1420. self.removeOperation = function (operation, operationList) {
  1421. operationList.remove(operation);
  1422. }
  1423. self.addOperation = function (field) {
  1424. field.operations.push(new Operation("split"));
  1425. }
  1426. self.load = function (state) {
  1427. self.source.name(state.name);
  1428. self.source.show(state.show);
  1429. self.source.path(state.path);
  1430. self.destination.columns.removeAll();
  1431. if (state.format && 'type' in state.format) {
  1432. var koFormat = ko.mapping.fromJS(new FileType(state.format.type, state.format));
  1433. self.source.format(koFormat);
  1434. }
  1435. if (state.columns){
  1436. state.columns.forEach(function (currCol) {
  1437. self.destination.columns.push(loadField(currCol));
  1438. });
  1439. }
  1440. }
  1441. };
  1442. var loadDefaultField = function (options) {
  1443. if (! options.name) {
  1444. options.name = getNewFieldName();
  1445. }
  1446. return loadField($.extend({}, ${default_field_type | n}, options));
  1447. }
  1448. var loadField = function (currField, parent, idx) {
  1449. var koField = ko.mapping.fromJS(currField);
  1450. if (koField.name && parent) {
  1451. koField.name.subscribe(function (newVal) {
  1452. if (newVal.indexOf(',') > -1) {
  1453. var fields = newVal.split(',');
  1454. fields.forEach(function (val, i) {
  1455. if (parent.length <= i + idx && parent()[i + idx]) {
  1456. parent()[i + idx].name(val);
  1457. }
  1458. });
  1459. }
  1460. });
  1461. }
  1462. koField.operations.removeAll();
  1463. currField.operations.forEach(function (operationData) {
  1464. var operation = new Operation(operationData.type);
  1465. operation.load(operationData);
  1466. koField.operations.push(operation);
  1467. });
  1468. var autoExpand = function (newVal) {
  1469. if ((newVal == 'array' || newVal == 'map' || newVal == 'struct') && koField.nested().length == 0) {
  1470. koField.nested.push(loadDefaultField({level: koField.level() + 1}));
  1471. }
  1472. };
  1473. koField.type.subscribe(autoExpand);
  1474. koField.keyType.subscribe(autoExpand);
  1475. return koField;
  1476. }
  1477. var IndexerViewModel = function (options) {
  1478. var self = this;
  1479. self.apiHelper = ApiHelper.getInstance(options);
  1480. self.assistAvailable = ko.observable(true);
  1481. self.isLeftPanelVisible = ko.observable();
  1482. self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
  1483. self.loadDefaultField = loadDefaultField;
  1484. // Wizard related
  1485. self.wizardEnabled = ko.observable(false);
  1486. self.currentStep = ko.observable(1);
  1487. self.currentStep.subscribe(function () {
  1488. $('.content-panel').scrollTop(0);
  1489. });
  1490. self.previousStepVisible = ko.pureComputed(function(){
  1491. return self.currentStep() > 1;
  1492. });
  1493. self.nextStepVisible = ko.pureComputed(function(){
  1494. return self.currentStep() < 3 && self.wizardEnabled();
  1495. });
  1496. self.nextStep = function () {
  1497. if (self.nextStepVisible()){
  1498. self.currentStep(self.currentStep() + 1);
  1499. }
  1500. }
  1501. self.previousStep = function () {
  1502. if (self.previousStepVisible()){
  1503. self.currentStep(self.currentStep() - 1);
  1504. }
  1505. }
  1506. self.createWizard = new CreateWizard(self);
  1507. self.isLoading = ko.observable(false);
  1508. };
  1509. var viewModel;
  1510. function resizeElements () {
  1511. var $contentPanel = $('#importerComponents').find('.content-panel-inner');
  1512. $('.form-actions').width($contentPanel.width() - 50);
  1513. $('.step-indicator-fixed').width($contentPanel.width());
  1514. document.styleSheets[0].addRule('.step-indicator li:first-child:before','max-width: ' + ($contentPanel.find('.step-indicator li:first-child .caption').width()) + 'px');
  1515. document.styleSheets[0].addRule('.step-indicator li:first-child:before','left: ' + ($contentPanel.find('.step-indicator li:first-child .caption').width()/2) + 'px');
  1516. document.styleSheets[0].addRule('.step-indicator li:last-child:before','max-width: ' + ($contentPanel.find('.step-indicator li:last-child .caption').width()) + 'px');
  1517. document.styleSheets[0].addRule('.step-indicator li:last-child:before','right: ' + ($contentPanel.find('.step-indicator li:last-child .caption').width()/2) + 'px');
  1518. //document.styleSheets[0].addRule('.step-indicator li::before','max-width: ' + (($contentPanel.width()/2) + ($contentPanel.find('.step-indicator .step').width()/2)) + 'px');
  1519. }
  1520. $(document).ready(function () {
  1521. var options = {
  1522. user: '${ user.username }',
  1523. i18n: {
  1524. errorLoadingDatabases: "${ _('There was a problem loading the databases') }",
  1525. errorLoadingTablePreview: "${ _('There was a problem loading the table preview.') }"
  1526. }
  1527. }
  1528. viewModel = new IndexerViewModel(options);
  1529. ko.applyBindings(viewModel, $('#importerComponents')[0]);
  1530. var draggableMeta = {};
  1531. huePubSub.subscribe('draggable.text.meta', function (meta) {
  1532. draggableMeta = meta;
  1533. });
  1534. huePubSub.subscribe('split.panel.resized', resizeElements);
  1535. resizeElements();
  1536. $(window).on('resize', resizeElements);
  1537. $('.content-panel').droppable({
  1538. accept: ".draggableText",
  1539. drop: function (e, ui) {
  1540. var text = ui.helper.text();
  1541. var generatedName = 'idx';
  1542. switch (draggableMeta.type){
  1543. case 'sql':
  1544. if (draggableMeta.table !== ''){
  1545. generatedName += draggableMeta.table;
  1546. viewModel.createWizard.source.inputFormat('table');
  1547. viewModel.createWizard.source.table(draggableMeta.table);
  1548. }
  1549. break;
  1550. case 'hdfs':
  1551. generatedName += draggableMeta.definition.name;
  1552. viewModel.createWizard.source.inputFormat('file');
  1553. viewModel.createWizard.source.path(draggableMeta.definition.path);
  1554. break;
  1555. case 'document':
  1556. if (draggableMeta.definition.type === 'query-hive'){
  1557. generatedName += draggableMeta.definition.name;
  1558. viewModel.createWizard.source.inputFormat('query');
  1559. viewModel.createWizard.source.draggedQuery(draggableMeta.definition.uuid);
  1560. }
  1561. break;
  1562. }
  1563. if (generatedName !== 'idx' && viewModel.createWizard.source.name() === ''){
  1564. viewModel.createWizard.source.name(generatedName);
  1565. }
  1566. }
  1567. });
  1568. });
  1569. })();
  1570. </script>
  1571. </span>
  1572. %if not is_embeddable:
  1573. ${ commonfooter(request, messages) | n,unicode }
  1574. %endif