Skip to content

Commit

Permalink
feat(ui): Client-side wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dunak-debug committed Dec 27, 2021
1 parent 8fb5ca2 commit 0290ea1
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 14 deletions.
13 changes: 6 additions & 7 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ version '1.9.0'
url 'https://github.com/overextended/oxmysql'
author 'overextended'

ui_page 'src/ui/public/index.html'

dependencies {
'/server:5104',
}

server_scripts {
'dist/build.js',
}
client_script 'ui.lua'
server_script 'dist/build.js'

files {
'src/ui/public/index.html',
'src/ui/public/**/*'
'ui/public/index.html',
'ui/public/**/*'
}

ui_page 'src/ui/public/index.html'

provide 'mysql-async'
35 changes: 28 additions & 7 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import type { CFXParameters } from '../types';
interface QueryData {
date: number;
query: string;
executionTime: number
executionTime: number;
}

type QueryLog = {
[invokingResource: string]: QueryData[];
};
type QueryLog = Record<string, QueryData[]>;

const logStorage: QueryLog = {};

Expand All @@ -22,17 +20,40 @@ export const logQuery = (invokingResource: string, query: string, executionTime:

if (!mysql_ui) return;

if (logStorage[invokingResource] === undefined) logStorage[invokingResource] = []
if (logStorage[invokingResource] === undefined) logStorage[invokingResource] = [];
logStorage[invokingResource].push({ query, executionTime, date: Date.now() });

};

RegisterCommand(
'mysql',
(source: number) => {
if (!mysql_ui) return;

emitNet(`oxmysql:openUi`, source, logStorage);
let totalQueries: number = 0;
let totalTime = 0;

for (const resource in logStorage) {
const queries = logStorage[resource];

totalQueries += queries.length;
totalTime += queries.reduce((totalTime, query) => (totalTime += query.executionTime), 0);
}

emitNet(`oxmysql:openUi`, source, {
resources: Object.keys(logStorage),
totalQueries,
totalTime,
});
},
true
);

onNet(`oxmysql:fetchResource`, (resource: string) => {
if (typeof resource !== 'string') return;

const queries = logStorage[resource];

if (!queries) return;

emitNet(`oxmysql:loadResource`, source, queries);
});
23 changes: 23 additions & 0 deletions ui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RegisterNetEvent('oxmysql:openUi', function(data)
SendNUIMessage({
action = 'init',
data = data
})
SetNuiFocus(true, true)
end)

RegisterNUICallback('exit', function(_, cb)
cb(true)
end)

RegisterNUICallback('fetchResource', function(resource, cb)
TriggerServerEvent('oxmysql:fetchResource', resource)
cb(true)
end)

RegisterNetEvent('oxmysql:loadResource', function(data)
SendNUIMessage({
action = 'loadResource',
data = data
})
end)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 0290ea1

Please sign in to comment.