artisan.blade.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <script>
  2. $(function () {
  3. var storageKey = function () {
  4. var connection = $('#connections').val();
  5. return 'la-'+connection+'-history'
  6. };
  7. $('#terminal-box').slimScroll({
  8. height: $('#pjax-container').height() - 247 +'px'
  9. });
  10. function History () {
  11. this.index = this.count() - 1;
  12. }
  13. History.prototype.store = function () {
  14. var history = localStorage.getItem(storageKey());
  15. if (!history) {
  16. history = [];
  17. } else {
  18. history = JSON.parse(history);
  19. }
  20. return history;
  21. };
  22. History.prototype.push = function (record) {
  23. var history = this.store();
  24. history.push(record);
  25. localStorage.setItem(storageKey(), JSON.stringify(history));
  26. this.index = this.count() - 1;
  27. };
  28. History.prototype.count = function () {
  29. return this.store().length;
  30. };
  31. History.prototype.up = function () {
  32. if (this.index > 0) {
  33. this.index--;
  34. }
  35. return this.store()[this.index];
  36. };
  37. History.prototype.down = function () {
  38. if (this.index < this.count() - 1) {
  39. this.index++;
  40. }
  41. return this.store()[this.index];
  42. };
  43. History.prototype.clear = function () {
  44. localStorage.removeItem(storageKey());
  45. };
  46. var history = new History;
  47. var send = function () {
  48. var $input = $('#terminal-query');
  49. $.ajax({
  50. url:location.pathname,
  51. method: 'post',
  52. data: {
  53. c: $input.val(),
  54. _token: LA.token
  55. },
  56. success: function (response) {
  57. history.push($input.val());
  58. $('#terminal-box')
  59. .append('<div class="item"><small class="label label-default"> > artisan '+$input.val()+'<\/small><\/div>')
  60. .append('<div class="item">'+response+'<\/div>')
  61. .slimScroll({ scrollTo: $("#terminal-box")[0].scrollHeight });
  62. $input.val('');
  63. }
  64. });
  65. };
  66. $('#terminal-query').on('keyup', function (e) {
  67. e.preventDefault();
  68. if (e.keyCode == 13) {
  69. send();
  70. }
  71. if (e.keyCode == 38) {
  72. $(this).val(history.up());
  73. }
  74. if (e.keyCode == 40) {
  75. $(this).val(history.down());
  76. }
  77. });
  78. $('#terminal-clear').click(function () {
  79. $('#terminal-box').text('');
  80. //history.clear();
  81. });
  82. $('.loaded-command').click(function () {
  83. $('#terminal-query').val($(this).html() + ' ');
  84. $('#terminal-query').focus();
  85. });
  86. $('#terminal-send').click(function () {
  87. send();
  88. });
  89. });
  90. </script>
  91. <!-- Chat box -->
  92. <div class="box box-primary">
  93. <div class="box-header with-border">
  94. <i class="fa fa-terminal"></i>
  95. </div>
  96. <div class="box-body chat" id="terminal-box">
  97. <!-- chat item -->
  98. <!-- /.item -->
  99. </div>
  100. <!-- /.chat -->
  101. <div class="box-footer with-border">
  102. <div style="margin-bottom: 10px;">
  103. @foreach($commands['groups'] as $group => $command)
  104. <div class="btn-group dropup">
  105. <button type="button" class="btn btn-default btn-flat">{{ $group }}</button>
  106. <button type="button" class="btn btn-default btn-flat dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
  107. <span class="caret"></span>
  108. <span class="sr-only">Toggle Dropdown</span>
  109. </button>
  110. <ul class="dropdown-menu" role="menu">
  111. @foreach($command as $item)
  112. <li><a href="#" class="loaded-command">{{$item}}</a></li>
  113. @endforeach
  114. </ul>
  115. </div>
  116. @endforeach
  117. <div class="btn-group dropup">
  118. <button type="button" class="btn btn-twitter btn-flat">Other</button>
  119. <button type="button" class="btn btn-twitter btn-flat dropdown-toggle" data-toggle="dropdown">
  120. <span class="caret"></span>
  121. <span class="sr-only">Toggle Dropdown</span>
  122. </button>
  123. <ul class="dropdown-menu" role="menu">
  124. @foreach($commands['others'] as $item)
  125. <li><a href="#" class="loaded-command">{{$item}}</a></li>
  126. @endforeach
  127. </ul>
  128. </div>
  129. <button type="button" class="btn btn-success" id="terminal-send"><i class="fa fa-paper-plane"></i> send</button>
  130. <button type="button" class="btn btn-warning" id="terminal-clear"><i class="fa fa-refresh"></i> clear</button>
  131. </div>
  132. <div class="input-group">
  133. <span class="input-group-addon" style="font-size: 18px; line-height: 1.3333333;">artisan</span>
  134. <input class="form-control input-lg" id="terminal-query" placeholder="command" style="border-left: 0px;padding-left: 0px;">
  135. </div>
  136. </div>
  137. </div>
  138. <!-- /.box (chat box) -->