importer.mako 71 KB

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