Skip to content

Commit 8a1b688

Browse files
authored
Merge pull request #113 from socialblue/develop
release new sql code highlighting
2 parents efd4978 + 4f3be3a commit 8a1b688

16 files changed

+137
-63
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Publish Laravel-Query-Adviser
2222
php artisan vendor:publish --provider="Socialblue\LaravelQueryAdviser\LaravelQueryAdviserServiceProvider"
2323
```
2424

25+
** publish the front-end application after updating **
26+
```bash
27+
php artisan vendor:publish --tag=public --force
28+
```
29+
30+
2531
**When updating from `0.13.2` to `0.14.0` please use**
2632

2733
```bash

package-lock.json

+9-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
"watch": "mix watch"
88
},
99
"devDependencies": {
10-
"bulma": "^0.7.5",
10+
"bulma": "^0.9.4",
1111
"bulma-extensions": "^6.2.7",
1212
"cross-env": "^5.2.1",
13-
"highlight.js": "^11.6.0",
1413
"laravel-mix": "^6.0.49",
1514
"node-sass": "^7.0.3",
1615
"postcss": "^8.4.16",
1716
"resolve-url-loader": "^4.0.0",
1817
"sass": "^1.54.9",
1918
"sass-loader": "^12.6.0",
2019
"sql-formatter": "^10.6.0",
20+
"sql-highlight": "^4.2.1",
2121
"v-clipboard": "^2.2.3",
2222
"vue": "^2.7.10",
23-
"vue-json-pretty": "^1.9.2",
2423
"vue-loader": "^15.10.0",
2524
"vue-router": "^3.6.5",
2625
"vue-template-compiler": "^2.7.10"
27-
}
26+
},
27+
"dependencies": {}
2828
}

public/css/app.css

+1-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/app.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"/js/app.js": "/js/app.js?id=1b85ca16b9b43cd073884e9e5d4692a4",
3-
"/css/app.css": "/css/app.css?id=2d7161bbcbcf464e7be644297f4184f9"
2+
"/js/app.js": "/js/app.js?id=812eb08c08eea5cf829d679ca810bca8",
3+
"/css/app.css": "/css/app.css?id=b1e5df534d3e9de7ba4cdaa2a4ebeba4"
44
}

resources/assets/js/components/query-block.vue

+13-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</div>
4646
</template>
4747
</div>
48-
<pre class="highlight" ref="sqlcode" ><code class="language-sql">{{prettyPrint(query.sql)}}</code></pre>
48+
<sqlHighlight :sql="query.sql" />
4949
<time :datetime="dateTime">{{ dateTime }}</time>
5050

5151
</div>
@@ -72,10 +72,13 @@
7272
</template>
7373

7474
<script>
75-
import highlight from "../mixin/hightlight";
75+
import sqlHighlight from "./sql-highlight";
76+
import { format } from 'sql-formatter';
7677
7778
export default {
78-
mixins: [highlight],
79+
components: {
80+
sqlHighlight
81+
},
7982
8083
props: {
8184
query: {
@@ -115,6 +118,13 @@ export default {
115118
116119
clipboardSuccess() {
117120
window.EventBus.$emit('show-notification', {message: 'Query is copied to your clipboard'});
121+
},
122+
123+
format(sql) {
124+
return format(`${sql};`, {
125+
language: 'mysql',
126+
keywordCase: "upper",
127+
});
118128
}
119129
},
120130

resources/assets/js/components/query-execute.vue

-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@
4242
</template>
4343

4444
<script>
45-
import highlight from "../mixin/hightlight";
46-
4745
export default {
48-
mixins: [highlight],
4946
5047
data() {
5148
return {

resources/assets/js/components/session-import.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export default {
3737
method,
3838
body,
3939
headers
40-
}).then(() => this.hide());
40+
}).then(() => {
41+
this.$router.push({name: 'sessions'});
42+
});
4143
},
4244
4345
hide() {

resources/assets/js/components/session.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
7979
methods: {
8080
openSession() {
81-
this.$router.push('session', {id: this.id});
81+
this.$router.push({name: 'session', params: {id: this.id}});
8282
}
8383
}
8484
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<code class="sql-hl" >
3+
<pre><span v-for="segment in segments" :class="`sql-hl-${segment.name}`">{{segment.content}}</span></pre>
4+
</code>
5+
</template>
6+
7+
<script>
8+
import { format } from 'sql-formatter';
9+
import { getSegments } from 'sql-highlight';
10+
11+
export default {
12+
props: {
13+
sql: {
14+
type: String,
15+
default: () => "",
16+
},
17+
},
18+
19+
computed: {
20+
formatted() {
21+
return format(`${this.sql};`, {
22+
language: 'mysql',
23+
keywordCase: 'lower',
24+
tabWidth: 4,
25+
linesBetweenQueries: 2,
26+
});
27+
},
28+
29+
segments() {
30+
return getSegments(this.formatted);
31+
},
32+
},
33+
methods: {
34+
copyToClipboard() {
35+
36+
}
37+
}
38+
}
39+
40+
</script>

resources/assets/js/mixin/hightlight.js

-20
This file was deleted.

resources/assets/js/routes/web.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Vue from 'vue';
66

77
const routes = [
88
{
9-
path: '/query-adviser/session',
9+
path: '/query-adviser/session/:sessionKey',
1010
name: 'session',
1111
components: {default: Session},
1212
meta: {permission: 1},

resources/assets/js/view/sessions.vue

+22-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
<query-statistics v-bind="session" />
3131
</div>
3232
</template>
33+
<div v-else-if="loading" class="hero-body">
34+
<div class="container">
35+
<h1 class="title">
36+
Loading..
37+
</h1>
38+
</div>
39+
</div>
3340
<div v-else class="hero-body">
3441
<div class="container">
3542
<h1 class="title" v-if="sessions.length > 0">
@@ -120,6 +127,7 @@
120127
isActive: false,
121128
hasQueries: false,
122129
activeSessionsId: null,
130+
loading: false,
123131
}
124132
},
125133
@@ -144,10 +152,14 @@
144152
},
145153
146154
getList() {
155+
this.loading = true;
156+
147157
return fetch('/query-adviser/api/session/list').then((response) => {
148158
return response.json();
149159
}).then((sessions) => {
150160
this.sessions = sessions;
161+
}).finally(() => {
162+
this.loading = false;
151163
})
152164
},
153165
@@ -189,14 +201,21 @@
189201
}
190202
},
191203
192-
mounted() {
193-
this.getList();
194-
this.pollActiveSession();
204+
beforeRouteEnter(to, from, next) {
205+
206+
next((vm) => {
207+
vm.getList();
208+
vm.pollActiveSession();
209+
});
195210
},
196211
197212
beforeRouteUpdate(to, from, next) {
198213
if (to.name === 'session-export') {
199214
this.exportSession(to).then(next);
215+
} else if (to.name === 'sessions') {
216+
this.getList();
217+
this.pollActiveSession();
218+
next();
200219
} else {
201220
next();
202221
}

resources/assets/sass/app.scss

+29-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
@import "~bulma-extensions/bulma-quickview/src/sass/index.sass";
44
@import "~bulma-extensions/bulma-checkradio/src/sass/index.sass";
55
@import "~bulma-extensions/bulma-steps/src/sass/index.sass";
6-
@import "~highlight.js/styles/night-owl.css";
76

87
.component-fade-enter-active, .component-fade-leave-active {
98
transition: all 1.4s ease;
@@ -14,5 +13,34 @@
1413
opacity: 0;
1514
bottom: -200px;
1615
position: fixed;
16+
}
17+
18+
.sql-hl {
19+
padding: 0;
20+
21+
pre {
22+
display: block;
23+
background: rgba(0, 0, 0, 1);
24+
25+
.sql-hl-string {
26+
color: rgba(0, 220, 40, .9);
27+
}
28+
29+
.sql-hl-special {
30+
color: rgba(213, 213, 0, .9);
31+
}
1732

33+
.sql-hl-keyword {
34+
color: rgba(255, 150, 0, .9);
35+
text-transform: uppercase;
36+
}
37+
38+
.sql-hl-number {
39+
color: rgba(0, 120, 220, .9);
40+
}
41+
}
1842
}
43+
44+
45+
46+

routes/web.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?php
22
use Illuminate\Support\Facades\Route;
3-
4-
Route::get('/', 'QueryController@index');
5-
Route::get('/session', 'QueryController@index');
6-
3+
use Socialblue\LaravelQueryAdviser\Http\Controllers\QueryController;
74

85
/**
96
* Api routes
@@ -25,3 +22,7 @@
2522
Route::post('/session/import', 'SessionController@import');
2623
});
2724

25+
26+
Route::get('/', [QueryController::class, 'index']);
27+
Route::get('{any}', [QueryController::class, 'index'])
28+
->where('any','^(?!(api)).*$');

0 commit comments

Comments
 (0)