controls.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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. var searchRenderers = {
  17. 'rowkey': { //class to tag selection
  18. select: /([^,]+\[[^\]\[]+\]|[^,]+)/g, //select the substring to process, useful as JS has no lookbehinds old: ([^,]+\[([^,]+(,|)+)+\]|[^,]+)
  19. tag: /.+/g, //select the matches to wrap with tags
  20. strip: /,(?![^\[\]\:]+[^\]\[]+\])/g, //strip delimiters and post-process string to make nice
  21. nested: {
  22. 'scan': { select: /\+[0-9 ]+/g, tag: /.+/g, strip: /a^/g },
  23. 'columns': { select: /\[.+\]/g, tag: /[^:,\[\]]+:([^,\[\]]+|)/g, strip: /a^/g }, //forced to do this select due to lack of lookbehinds /[\[\]]/g
  24. 'prefix': { select: /[^\*]+\*/g, tag: /\*/g, strip: /a^/g }
  25. }
  26. }
  27. };
  28. var DataTableViewModel = function(options)
  29. {
  30. var self = this, _defaults = {
  31. name: '',
  32. columns: [],
  33. items: [],
  34. reload: function()
  35. {
  36. },
  37. el:''
  38. };
  39. options = ko.utils.extend(_defaults,options);
  40. ListViewModel.apply(this, [options]);
  41. self.name = ko.observable(options.name);
  42. self.searchQuery.subscribe(function(value)
  43. {
  44. self._table.fnFilter(value);
  45. });
  46. self.columns = ko.observableArray(options.columns);
  47. self._el = $('table[data-datasource="' + options.el + '"]');
  48. self._table = null;
  49. self._initTable = function()
  50. {
  51. if(!self._table)
  52. {
  53. self._table = self._el.dataTable({
  54. "aoColumnDefs": [
  55. { "bSortable": false, "aTargets": [ 0 ] }
  56. ],
  57. "sDom": 'tr',//this has to be in, change to sDom so you can call filter()
  58. 'bAutoWidth':false,
  59. "iDisplayLength": -1});
  60. return self._table;
  61. }
  62. };
  63. self.sort = function(viewModel, event) {
  64. var el = $(event.currentTarget);
  65. };
  66. var _reload = self.reload;
  67. self.reload = function(callback)
  68. {
  69. if(self._table)
  70. {
  71. self._table.fnClearTable();
  72. self._table.fnDestroy();
  73. self._table = null;
  74. }
  75. _reload(function()
  76. {
  77. self._initTable();
  78. if(callback!=null)
  79. callback();
  80. });
  81. };
  82. };
  83. //a Listview of Listviews
  84. var SmartViewModel = function(options)
  85. {
  86. var self = this;
  87. options = ko.utils.extend({
  88. name: '',
  89. items: [],
  90. reload: function()
  91. {
  92. },
  93. el:'',
  94. sortFields: {
  95. 'Row Key': function(a, b)
  96. {
  97. return a.row.localeCompare(b.row);
  98. },
  99. 'Column Count': function(a, b)
  100. {
  101. a = a.items().length;
  102. b = b.items().length;
  103. if(a > b)
  104. return 1;
  105. if(a < b)
  106. return -1;
  107. return 0;
  108. },
  109. 'Row Key Length': function(a, b)
  110. {
  111. a = a.row.length;
  112. b = b.row.length;
  113. if(a > b)
  114. return 1;
  115. if(a < b)
  116. return -1;
  117. return 0;
  118. }
  119. }
  120. }, options);
  121. ListViewModel.apply(this, [options]); //items: [ListView.items[],ListView.items[]]
  122. self.columnFamilies = ko.observableArray();
  123. self.name = ko.observable(options.name);
  124. self.name.subscribe(function(){
  125. self.querySet.removeAll();
  126. self.querySet.push(new QuerySetPeice({
  127. 'row_key': 'null',
  128. 'scan_length': 10,
  129. 'prefix': 'false'
  130. }));
  131. self._reloadcfs();
  132. }); //fix and decouple
  133. self.lastReloadTime = ko.observable(1);
  134. //self.columnFamilies.subscribe(function(){self.reload();});
  135. self.searchQuery.subscribe(function goToRow(value) //make this as nice as the renderfucnction and split into two, also fire not down on keyup events
  136. {
  137. var inputs = value.split(searchRenderers['rowkey']['select']);
  138. self.querySet.removeAll();
  139. for(var i=0;i<inputs.length;i++)
  140. {
  141. if(inputs[i].trim() != "" && inputs[i].trim() != ',')
  142. {
  143. var p = inputs[i].split('+');
  144. var scan = p.length > 1 ? parseInt(p[1]) : 0;
  145. var extract = inputs[i].match(searchRenderers['rowkey']['nested']['columns']['select']);
  146. var columns = extract != null ? extract[0].match(searchRenderers['rowkey']['nested']['columns']['tag']) : [];
  147. self.querySet.push(new QuerySetPeice({
  148. 'row_key': p[0].replace(/\[.+\]|\*/g,'').trim(), //clean up with column regex selectors instead
  149. 'scan_length': scan ? scan + 1 : 1,
  150. 'columns': columns,
  151. 'prefix': inputs[i].match(searchRenderers['rowkey']['nested']['prefix']['select']) != null
  152. }));
  153. }
  154. }
  155. routie(app.cluster() + '/' + app.views.tabledata.name() +'/query/' + value);
  156. self.evaluateQuery();
  157. });
  158. self._reloadcfs = function()
  159. {
  160. return API.queryTable("getColumnDescriptors").done(function(data)
  161. {
  162. self.columnFamilies.removeAll();
  163. var keys = Object.keys(data);
  164. for(var i=0;i<keys.length;i++)
  165. {
  166. self.columnFamilies.push(new ColumnFamily({name:keys[i], enabled:false}));
  167. }
  168. self.reload();
  169. });
  170. };
  171. self.columnQuery = ko.observable("");
  172. self.columnQuery.subscribe(function(query)
  173. {
  174. $(self.items()).each(function()
  175. {
  176. this.searchQuery(query);
  177. });
  178. });
  179. self.rows = ko.computed(function()
  180. {
  181. var a = [];
  182. var items = this.items();
  183. for(var i=0; i<items.length; i++)
  184. {
  185. a.push(items[i].row);
  186. }
  187. return a;
  188. }, self);
  189. self.querySet = ko.observableArray();
  190. self.validateQuery = function()
  191. {
  192. $(self.querySet()).each(function()
  193. {
  194. this.validate();
  195. this.editing(false);
  196. });
  197. };
  198. self.addQuery = function()
  199. {
  200. self.validateQuery();
  201. self.querySet.push(new QuerySetPeice({onValidate: function()
  202. {
  203. //self.reload();
  204. }}))
  205. };
  206. self.evaluateQuery = function(callback)
  207. {
  208. self.validateQuery();
  209. self.reload(callback);
  210. };
  211. var _reload = self.reload;
  212. self.reload = function(callback)
  213. {
  214. self.truncated = ko.observable(false);
  215. var queryStart = new Date();
  216. _reload(function()
  217. {
  218. self.lastReloadTime((new Date() - queryStart)/1000);
  219. if(callback!=null)
  220. callback();
  221. self.isLoading(false);
  222. });
  223. };
  224. self.truncated = ko.observable(false);
  225. self.truncateLimit = ko.observable(1500);
  226. self.truncateCount = ko.observable(0);
  227. };
  228. var SmartViewDataRow = function(options)
  229. {
  230. var self = this;
  231. options = ko.utils.extend({
  232. sortFields: {
  233. 'Column Family': function(a, b)
  234. {
  235. return a.name.localeCompare(b.name);
  236. },
  237. 'Column Name': function(a, b)
  238. {
  239. return a.name.split(':')[1].localeCompare(b.name.split(':')[1]);
  240. },
  241. 'Cell Value': function(a, b)
  242. {
  243. a = a.value.length;
  244. b = b.value.length;
  245. if(a > b)
  246. return 1;
  247. if(a < b)
  248. return -1;
  249. return 0;
  250. },
  251. 'Timestamp': function(a, b)
  252. {
  253. a = parseInt(a.timestamp);
  254. b = parseInt(b.timestamp);
  255. if(a > b)
  256. return 1;
  257. if(a < b)
  258. return -1;
  259. return 0;
  260. },
  261. 'MIME Type': function()
  262. {
  263. },
  264. 'Column Name Length': function(a, b)
  265. {
  266. a = a.name.split(':')[1].length;
  267. b = b.name.split(':')[1].length;
  268. if(a > b)
  269. return 1;
  270. if(a < b)
  271. return -1;
  272. return 0;
  273. }
  274. }
  275. }, options);
  276. DataRow.apply(self,[options]);
  277. ListViewModel.apply(self,[options]);
  278. self.displayedItems = ko.observableArray();
  279. self.displayRangeStart = 0;
  280. self.displayRangeLength = 20;
  281. self.items.subscribe(function()
  282. {
  283. self.displayedItems([]);
  284. self.updateDisplayedItems();
  285. });
  286. self.searchQuery.subscribe(function(searchValue)
  287. {
  288. self.scrollLoadSource = ko.computed(function(){
  289. return self.items().filter(function(column)
  290. {
  291. return column.name.toLowerCase().indexOf(searchValue.toLowerCase()) != -1;
  292. });
  293. });
  294. self.displayRangeLength = 20;
  295. self.updateDisplayedItems();
  296. });
  297. self.scrollLoadSource = self.items;
  298. self.updateDisplayedItems = function()
  299. {
  300. var x = self.displayRangeStart;
  301. self.displayedItems(self.scrollLoadSource().slice(x, x + self.displayRangeLength));
  302. };
  303. self.resetScrollLoad = function()
  304. {
  305. self.scrollLoadSource = self.items;
  306. self.updateDisplayedItems();
  307. };
  308. self.toggleSelectedCollapse = function()
  309. {
  310. if(self.displayedItems().length == self.displayRangeStart + self.displayRangeLength)
  311. {
  312. self.displayedItems(self.displayedItems().filter(function(item)
  313. {
  314. return item.isSelected();
  315. }));
  316. self.scrollLoadSource = self.displayedItems;
  317. }
  318. else
  319. {
  320. self.resetScrollLoad();
  321. }
  322. };
  323. self.onScroll = function(target, ev)
  324. {
  325. if($(ev.target).scrollLeft() == ev.target.scrollWidth - ev.target.clientWidth && self.displayedItems().length < self.scrollLoadSource().length)
  326. {
  327. self.displayRangeLength += 15;
  328. self.updateDisplayedItems();
  329. }
  330. };
  331. self.drop = function(cont)
  332. {
  333. function doDrop()
  334. {
  335. self.isLoading(true);
  336. return API.queryTable('deleteAllRow', self.row, "{}").complete(function()
  337. {
  338. app.views.tabledata.items.remove(self); //decouple later
  339. self.isLoading(false);
  340. });
  341. }
  342. (cont === true) ? doDrop() : confirm("Confirm Delete", 'Delete row ' + self.row + '? (This cannot be undone)', doDrop);
  343. };
  344. self.setItems = function(cols)
  345. {
  346. var colKeys = Object.keys(cols);
  347. var items = [];
  348. for(var q=0;q<colKeys.length;q++)
  349. {
  350. items.push(new ColumnRow({name: colKeys[q],
  351. timestamp: cols[colKeys[q]].timestamp,
  352. value: cols[colKeys[q]].value,
  353. parent: self}));
  354. }
  355. self.items(items);
  356. return self.items();
  357. };
  358. self.selectAllVisible = function(){
  359. for(t=0;t<self.displayedItems().length;t++)
  360. self.displayedItems()[t].isSelected(true);
  361. return self;
  362. };
  363. self.toggleSelectAllVisible = function()
  364. {
  365. if(self.selected().length != self.displayedItems().length)
  366. return self.selectAllVisible();
  367. return self.deselectAll();
  368. };
  369. self.push = function(item)
  370. {
  371. var column = new ColumnRow(item);
  372. self.items.push(column);
  373. };
  374. var _reload = self.reload;
  375. self.reload = function(callback)
  376. {
  377. _reload(function()
  378. {
  379. if(callback!=null)
  380. callback();
  381. self.isLoading(false);
  382. });
  383. };
  384. };
  385. var ColumnRow = function(options)
  386. {
  387. var self = this;
  388. ko.utils.extend(self,options);
  389. DataRow.apply(self,[options]);
  390. self.value = ko.observable(self.value);
  391. self.history = new CellHistoryPage({row: self.parent.row, column: self.name, timestamp: self.timestamp, items: []});
  392. self.drop = function(cont)
  393. {
  394. function doDrop()
  395. {
  396. self.parent.isLoading(true);
  397. return API.queryTable('deleteColumn', self.parent.row, self.name).done(function(data)
  398. {
  399. self.parent.items.remove(self);
  400. if(self.parent.items().length > 0)
  401. self.parent.reload(); //change later
  402. self.parent.isLoading(false);
  403. });
  404. }
  405. (cont === true) ? doDrop() : confirm("Confirm Delete", "Are you sure you want to drop this column?", doDrop);
  406. };
  407. self.reload = function(callback, skipPut)
  408. {
  409. self.isLoading(true);
  410. API.queryTable('get', self.parent.row, self.name, 'null').done(function(data)
  411. {
  412. if(data.length > 0 && !skipPut)
  413. self.value(data[0].value);
  414. callback();
  415. self.isLoading(false);
  416. });
  417. };
  418. self.value.subscribe(function(value)
  419. {
  420. //change transport prep to object wrapper
  421. logGA();
  422. API.queryTable('putColumn', self.parent.row, self.name, "hbase-post-key-" + value).done(function(data)
  423. {
  424. self.reload(function(){}, true);
  425. });
  426. self.editing(false);
  427. });
  428. self.editing = ko.observable(false);
  429. self.isLoading = ko.observable(false); //move to baseclass
  430. };
  431. var SortDropDownView = function(options)
  432. {
  433. var self = this;
  434. options = ko.utils.extend({
  435. sortFields: {},
  436. target: null
  437. }, options);
  438. BaseModel.apply(self,[options]);
  439. self.target = options.target;
  440. self.sortAsc = ko.observable(true);
  441. self.sortAsc.subscribe(function(){self.sort()});
  442. self.sortField = ko.observable("");
  443. self.sortField.subscribe(function(){self.sort()});
  444. self.sortFields = ko.observableArray(Object.keys(options.sortFields)); // change to ko.computed?
  445. self.sortFunctionHash = ko.observable(options.sortFields);
  446. self.toggleSortMode = function()
  447. {
  448. self.sortAsc(!self.sortAsc());
  449. };
  450. self.sort = function()
  451. {
  452. if (!self.target || !(self.sortFields().length > 0)) return;
  453. self.target.sort(function(a, b)
  454. {
  455. return (self.sortAsc() ? 1 : -1) * self.sortFunctionHash()[self.sortField() ? self.sortField() : self.sortFields()[0]](a,b); //all sort functions must sort by ASC for default
  456. });
  457. };
  458. };
  459. var TableDataRow = function(options)
  460. {
  461. var self = this;
  462. options = ko.utils.extend({
  463. name:"",
  464. enabled:true
  465. }, options);
  466. DataRow.apply(self,[options]);
  467. self.name = options['name'];
  468. self.enabled = ko.observable(options['enabled']);
  469. self.toggle = function(viewModel,event){
  470. var action = ['enable','disable'][self.enabled() << 0], el = $(event.currentTarget);
  471. confirm("Confirm "+action, "Are you sure you want to " + action + " this table?", function() //gotta i18n this!
  472. {
  473. el.showIndicator();
  474. return self[action](el).complete(function()
  475. {
  476. el.hideIndicator();
  477. });
  478. });
  479. };
  480. self.enable = function(el)
  481. {
  482. return API.queryCluster('enableTable',self.name).complete(function()
  483. {
  484. self.enabled(true);
  485. });
  486. };
  487. self.disable = function(el)
  488. {
  489. return API.queryCluster('disableTable',self.name).complete(function()
  490. {
  491. self.enabled(false);
  492. });
  493. };
  494. self.drop = function(el)
  495. {
  496. return API.queryCluster('deleteTable',self.name);
  497. };
  498. };
  499. var QuerySetPeice = function(options)
  500. {
  501. var self = this;
  502. options = ko.utils.extend({
  503. row_key: "null",
  504. scan_length: 1,
  505. prefix: false,
  506. columns: [],
  507. onValidate: function(){}
  508. }, options);
  509. BaseModel.apply(self,[options]);
  510. self.row_key = ko.observable(options.row_key);
  511. self.scan_length = ko.observable(options.scan_length);
  512. self.columns = ko.observableArray(options.columns);
  513. self.prefix = ko.observable(options.prefix);
  514. self.editing = ko.observable(true);
  515. self.validate = function()
  516. {
  517. if(self.scan_length() <= 0 || self.row_key() == "")
  518. return app.views.tabledata.querySet.remove(self); //change later
  519. return options.onValidate();
  520. };
  521. self.row_key.subscribe(self.validate.bind());
  522. self.scan_length.subscribe(self.validate.bind());
  523. };
  524. var ColumnFamily = function(options)
  525. {
  526. this.name = options.name;
  527. this.enabled = ko.observable(options.enabled);
  528. this.toggle = function()
  529. {
  530. this.enabled(!this.enabled());
  531. app.views.tabledata.reload();
  532. };
  533. }
  534. //tagsearch
  535. var tagsearch = function()
  536. {
  537. var self = this;
  538. self.tags = ko.observableArray();
  539. self.mode = ko.observable('idle');
  540. self.cur_input = ko.observable('');
  541. self.hints = ko.observableArray([
  542. {
  543. hint: 'End Query',
  544. shortcut: ',',
  545. mode: ['rowkey', 'prefix', 'scan'],
  546. selected: false
  547. },
  548. {
  549. hint: 'Mark Row Prefix',
  550. shortcut: '*',
  551. mode: ['rowkey'],
  552. selected: false
  553. },
  554. {
  555. hint: 'Start Scan',
  556. shortcut: '+',
  557. mode: ['rowkey', 'prefix'],
  558. selected: false
  559. },
  560. {
  561. hint: 'Start Select Columns',
  562. shortcut: '[',
  563. mode: ['rowkey', 'prefix'],
  564. selected: false
  565. },
  566. {
  567. hint: 'End Column/Family',
  568. shortcut: ',',
  569. mode: ['columns'],
  570. selected: false
  571. },
  572. {
  573. hint: 'End Select Columns',
  574. shortcut: ']',
  575. mode: ['columns'],
  576. selected: false
  577. }
  578. ]);
  579. self.activeHints = ko.computed(function()
  580. {
  581. var ret = [];
  582. $(self.hints()).each(function(i, hint)
  583. {
  584. if (hint.mode.indexOf(self.mode()) > -1)
  585. ret.push(hint);
  586. });
  587. return ret;
  588. });
  589. self.activeHint = ko.observable(-1);
  590. self.modes =
  591. {
  592. 'rowkey': {
  593. hint: 'Row Key Value',
  594. type: 'String'
  595. },
  596. 'scan': {
  597. hint: 'Length of Scan or Row Key',
  598. type: 'Integer'
  599. },
  600. 'columns': {
  601. hint: 'Column Family: Column Name',
  602. type: 'String'
  603. },
  604. 'prefix': {
  605. hint: 'Rows starting with',
  606. type: 'String'
  607. }
  608. }
  609. self.modeQueue = ['idle'];
  610. self.focused = ko.observable(false);
  611. self.insertTag = function(tag)
  612. {
  613. var mode = tag.indexOf('+') != -1 ? 'scan' : 'rowkey';
  614. var tag = {value: tag, tag: mode} //parse mode
  615. self.tags.push(tag);
  616. }
  617. self.render = function(input, renderers)
  618. {
  619. var keys = Object.keys(renderers);
  620. for(var i=0; i<keys.length; i++)
  621. {
  622. input = input.replace(renderers[keys[i]].select, function(selected)
  623. {
  624. var hasMatched = false;
  625. var processed = selected.replace(renderers[keys[i]].tag, function(tagged)
  626. {
  627. hasMatched = true;
  628. return "<span class='" + keys[i] + " tagsearchTag' title='" + keys[i] + "' data-toggle='tooltip'>" + ('nested' in renderers[keys[i]] ? self.render(tagged, renderers[keys[i]].nested) : tagged) + "</span>";
  629. });
  630. if(hasMatched)
  631. processed = processed.replace(renderers[keys[i]].strip, '');
  632. return processed;
  633. });
  634. }
  635. return input;
  636. };
  637. self.updateMode = function(value)
  638. {
  639. var selection = value.slice(0, self.selectionEnd());
  640. var endindex = selection.slice(selection.lastIndexOf(',')).indexOf(',');
  641. if(endindex == -1) endindex = selection.length;
  642. var lastbit = value.substring(selection.lastIndexOf(','), endindex).trim();
  643. if(lastbit == "," || lastbit == "")
  644. {
  645. self.mode('idle');
  646. return;
  647. }
  648. var tokens = "[]+,-";
  649. var m = 'rowkey';
  650. for(var i=selection.length - 1; i>=0; i--)
  651. {
  652. if(tokens.indexOf(selection[i]) != -1)
  653. {
  654. if(selection[i] == '[')
  655. m = 'columns';
  656. else if(selection[i] == ']')
  657. m = 'rowkey';
  658. else if(selection[i] == '+')
  659. m = 'scan';
  660. else if(selection[i] == '-')
  661. m = 'prefix';
  662. break;
  663. }
  664. }
  665. self.mode(m.trim());
  666. };
  667. self.selectionStart = ko.observable(0);
  668. self.selectionEnd = ko.observable(0);
  669. self.hintText = ko.computed(function()
  670. {
  671. var value = self.cur_input();
  672. var selection = value.slice(0, self.selectionEnd());
  673. var index = selection.lastIndexOf(',') + 1;
  674. var endindex = value.slice(index).indexOf(',');
  675. endindex = endindex == -1 ? value.length : endindex;
  676. var pre = value.substring(index, index + endindex);
  677. var s = self.selectionStart() - index, e = self.selectionEnd() - index;
  678. if(s == e)
  679. e += 1;
  680. s = s < 0 ? 0 : s;
  681. e = e > pre.length ? pre.length : e;
  682. return pre.slice(0, s) + "<span class='selection'>" + pre.slice(s, e) + "</span>" + pre.slice(e);
  683. });
  684. self.onKeyDown = function(target, ev)
  685. {
  686. if(ev.keyCode == 13 && self.cur_input().slice(self.cur_input().lastIndexOf(',')).trim() != ",")
  687. {
  688. self.evaluate();
  689. return false;
  690. }
  691. setTimeout(self.updateMenu, 1);
  692. return true;
  693. };
  694. self.updateMenu = function() {
  695. try{
  696. var pos = getEditablePosition(document.getElementById('search-tags'));
  697. self.selectionStart(pos);
  698. self.selectionEnd(pos);
  699. } catch (err) {}
  700. self.updateMode(self.cur_input());
  701. };
  702. self.evaluate = function()
  703. {
  704. app.views.tabledata.searchQuery(self.cur_input());
  705. };
  706. $('#search-tags').blur(function(){
  707. self.focused(false);
  708. });
  709. self.doBlur = function() {
  710. if(self.cur_input().trim() == "") {
  711. function doClick() {
  712. $('#search-tags').html('');
  713. setTimeout(function() {
  714. $('#search-tags').focus();
  715. }, 1);
  716. }
  717. $('#search-tags').html('<small>' + $('#search-tags').data("placeholder") + '</small>').one('click', doClick).find('small').on('mousedown', doClick);
  718. }
  719. }
  720. $('#search-tags').focus(function(){
  721. self.focused(true);
  722. });
  723. };
  724. var CellHistoryPage = function(options)
  725. {
  726. var self = this;
  727. self.items = ko.observableArray(options.items);
  728. self.loading = ko.observable(false);
  729. self.reload = function(timestamp, append)
  730. {
  731. if(!timestamp)
  732. timestamp = options.timestamp
  733. API.queryTable("getVerTs", options.row, options.column, timestamp, 10, 'null').done(function(res)
  734. {
  735. self.loading = ko.observable(true);
  736. if(!append)
  737. self.items(res);
  738. else
  739. self.items(self.items() + res);
  740. self.loading = ko.observable(false);
  741. });
  742. };
  743. };