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