mirror of
https://github.com/kac5a/k5_documents.git
synced 2026-08-04 19:45:09 -04:00
add server document, better version check
This commit is contained in:
41
README.md
41
README.md
@@ -15,7 +15,6 @@ Watch the demo here: [YouTube](https://www.youtube.com/watch?v=cRgh2nqzROI)
|
||||
|
||||
## Help
|
||||
|
||||
|
||||
If you need any help, you can check out my [Discord](https://discord.com/invite/WmANgpdrgZ)
|
||||
|
||||
# Download & Installation
|
||||
@@ -52,6 +51,46 @@ Only job bosses can access and edit the templates, that is shown in the demo vid
|
||||
|
||||
You can also change colors and texts if you scroll down in the config.
|
||||
|
||||
## Server side document creation
|
||||
|
||||
You can call the `k5_documents:createServerDocument` server event with a single data parameter. This will create a copy to the specified document and give it to the players "My Documents" table.
|
||||
|
||||
### Example to add a vehicle purchase document:
|
||||
|
||||
TriggerServerEvent('k5_documents:createServerDocument', {
|
||||
name = "Vehicle Purchase Document",
|
||||
description = "This is an official purchase document",
|
||||
fields = {
|
||||
{
|
||||
name = "Firstname",
|
||||
value = result.firstname
|
||||
},
|
||||
{
|
||||
name = "Lastname",
|
||||
value = result.lastname
|
||||
},
|
||||
{
|
||||
name = "Vehicle Type",
|
||||
value = GetDisplayNameFromVehicleModel(GetHashKey(vehicleData.model))
|
||||
},
|
||||
{
|
||||
name = "Plate Number",
|
||||
value = generatedPlate
|
||||
}
|
||||
},
|
||||
infoName = "INFORMATION",
|
||||
infoValue = "This vehicle was purchased by ".. result.firstname .. " " .. result.lastname .. ".\nThis paper is an official document that proves the original owner of the vehicle.",
|
||||
isCopy = true ,
|
||||
issuer = {
|
||||
firstname = "Simeon",
|
||||
lastname = "Yetarian",
|
||||
birthDate = "1954. 05. 26.",
|
||||
jobName = "Dealership Owner"
|
||||
}
|
||||
})
|
||||
|
||||
### More information can be found in the `server.lua` file.
|
||||
|
||||
## ⚛ React
|
||||
|
||||
If you are a React developer, or you'd like to edit the React parts, you can do that too.
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
fx_version "cerulean"
|
||||
|
||||
description "K5 Documents"
|
||||
description "A better document management script"
|
||||
author "K5 Scripts"
|
||||
<<<<<<< HEAD
|
||||
version '1.1.2'
|
||||
update "Design changes, added version check"
|
||||
=======
|
||||
version '1.1.3'
|
||||
update "Added option to create documents from other scripts"
|
||||
>>>>>>> e5cfc1b (add server document, better version check)
|
||||
repository 'https://github.com/kac5a/k5_documents'
|
||||
|
||||
lua54 'yes'
|
||||
|
||||
@@ -22,12 +22,43 @@ Citizen.CreateThread(function()
|
||||
local currentVersion = GetResourceMetadata(resource, 'version', 0)
|
||||
PerformHttpRequest('https://raw.githubusercontent.com/kac5a/k5_documents/master/fxmanifest.lua',function(error, result, headers)
|
||||
if not result then print('K5 Documents: ^1Couldn\'t check version.^0') end
|
||||
|
||||
local update = (string.sub(result, string.find(result, 'update [^\n]+')))
|
||||
update = (string.sub(update, string.find(update, '[^update ].+'))):gsub('"', "")
|
||||
|
||||
local version = string.sub(result, string.find(result, "%d.%d.%d"))
|
||||
local version_N = tonumber((version:gsub("%D+", "")))
|
||||
local currentVersion_N = tonumber((currentVersion:gsub("%D+", "")))
|
||||
|
||||
if version_N > currentVersion_N then
|
||||
print('^1!!! ^4[K5 DOCUMENTS]^0: New update available on GitHub. ^1'..currentVersion.. '^0 -> ^2'..version..' ^1!!!^0')
|
||||
local title = "^4| K5 Documents |"
|
||||
local message = '^4|^0 New version available on GitHub: ^1'..currentVersion.. '^0 -> ^2'..version..'^0'
|
||||
local messageLength = #(message) - 12
|
||||
local updateMessage = '^4| ^3Update: ^2'..update
|
||||
local updateMessageLength = #(updateMessage) - 6
|
||||
|
||||
local length = 120
|
||||
|
||||
for i=1, length - updateMessageLength do
|
||||
updateMessage = updateMessage.." "
|
||||
end
|
||||
updateMessage = updateMessage .. "^4|^0"
|
||||
|
||||
for i=1, length - messageLength do
|
||||
message = message.." "
|
||||
end
|
||||
message = message .. "^4|^0"
|
||||
|
||||
local border = "^4="
|
||||
for i=1, length do
|
||||
border = border .. "="
|
||||
end
|
||||
|
||||
print(border)
|
||||
print(title)
|
||||
print(message)
|
||||
print(updateMessage)
|
||||
print(border.."^0")
|
||||
end
|
||||
end,'GET')
|
||||
end)
|
||||
@@ -146,6 +177,63 @@ RegisterCallback('k5_documents:createDocument', function(source, cb, data)
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('k5_documents:createServerDocument')
|
||||
AddEventHandler('k5_documents:createServerDocument', function(data)
|
||||
local src = source
|
||||
local PlayerIdentifier = GetPlayerIdentifier(src)
|
||||
data.createdAt = os.date()
|
||||
|
||||
-- Example values. This data should be created on the
|
||||
-- client side and passed as the data parameter. You can
|
||||
-- delete this part.
|
||||
|
||||
local firstname = "Thomas"
|
||||
local lastname = "Edison"
|
||||
|
||||
local example_data = {
|
||||
name = "Vehicle Purchase Document",
|
||||
description = "This is an official purchase document",
|
||||
-- Any data that you can imagine. You can create up to 6 field sets.
|
||||
fields = {
|
||||
{
|
||||
name = "Firstname",
|
||||
value = firstname -- Get the players firstname from the client
|
||||
},
|
||||
{
|
||||
name = "Lastname",
|
||||
value = lastname -- Get the players lastname from the client
|
||||
},
|
||||
{
|
||||
name = "Vehicle Type",
|
||||
value = "Nissan R35" -- Get the vehicle name from the client
|
||||
},
|
||||
{
|
||||
name = "Price",
|
||||
value = "$100 000" -- Get the price from the client
|
||||
},
|
||||
},
|
||||
infoName = "INFORMATION",
|
||||
infoValue = "This vehicle was purchased by ".. firstname .. " " .. lastname .. ".\nThis paper is an official document that proves the original owner of the vehicle.",
|
||||
isCopy = true, -- This has to be true, so it shows up in the "My documents" tab
|
||||
issuer = {
|
||||
-- Any data that you can imagine. This can be a fake person, but the fields have to be the same (firstname, lastname, ...)
|
||||
firstname = "Simeon",
|
||||
lastname = "Yetarian",
|
||||
birthDate = "1954. 05. 26.",
|
||||
jobName = "Dealership Owner"
|
||||
}
|
||||
}
|
||||
|
||||
-- DON'T DELETE THIS PART
|
||||
|
||||
MySQL.Async.insert('INSERT INTO k5_documents (data, ownerId, isCopy) VALUES (@data, @ownerId, @isCopy)', {
|
||||
['@data'] = json.encode(data),
|
||||
['@ownerId'] = PlayerIdentifier,
|
||||
['@isCopy'] = true
|
||||
}, function(result)
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterCallback('k5_documents:deleteDocument', function(source, cb, data)
|
||||
MySQL.Async.execute('DELETE FROM k5_documents WHERE id = @id', {
|
||||
['@id'] = data
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"files": {
|
||||
"main.js": "/web/build/static/js/main.44da7001.js",
|
||||
"main.js": "/web/build/static/js/main.dc2b4499.js",
|
||||
"static/media/city_logo.png": "/web/build/static/media/city_logo.008b591a2d4e6445d96c.png",
|
||||
"index.html": "/web/build/index.html",
|
||||
"main.44da7001.js.map": "/web/build/static/js/main.44da7001.js.map"
|
||||
"main.dc2b4499.js.map": "/web/build/static/js/main.dc2b4499.js.map"
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/js/main.44da7001.js"
|
||||
"static/js/main.dc2b4499.js"
|
||||
]
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/><link href="https://fonts.googleapis.com/css2?family=Oooh+Baby&display=swap" rel="stylesheet"/><title>K5 Documents</title><script type="text/javascript" src="/web/build/config.js"></script><script defer="defer" src="/web/build/static/js/main.44da7001.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/><link href="https://fonts.googleapis.com/css2?family=Oooh+Baby&display=swap" rel="stylesheet"/><title>K5 Documents</title><script type="text/javascript" src="/web/build/config.js"></script><script defer="defer" src="/web/build/static/js/main.dc2b4499.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
web/build/static/js/main.dc2b4499.js.map
Normal file
1
web/build/static/js/main.dc2b4499.js.map
Normal file
File diff suppressed because one or more lines are too long
@@ -143,7 +143,7 @@ const IssuedDocuments = () => {
|
||||
handleAgree={handleDelete}
|
||||
handleCancel={handleCancel}
|
||||
title={texts.deleteDocumentTitle}
|
||||
text={`${texts.deleteDocumentQuestion} ${documentToDelete?.documentName || ""}`}
|
||||
text={`${texts.deleteDocumentQuestion} ${documentToDelete?.name || ""}`}
|
||||
/>
|
||||
<DocumentView/>
|
||||
</>
|
||||
|
||||
@@ -86,6 +86,9 @@ const MyDocuments = () => {
|
||||
columns={columns}
|
||||
loading={documentCopiesLoading}
|
||||
pageSize={5}
|
||||
initialState={{
|
||||
sorting: {sortModel: [{field: "createdAt", sort: 'desc'}]}
|
||||
}}
|
||||
rowsPerPageOptions={[5]}
|
||||
disableSelectionOnClick
|
||||
/>
|
||||
@@ -95,7 +98,7 @@ const MyDocuments = () => {
|
||||
handleAgree={handleDelete}
|
||||
handleCancel={handleCancel}
|
||||
title={texts.deleteDocumentTitle}
|
||||
text={`${texts.deleteDocumentQuestion} ${documentToDelete?.documentName || ""}`}
|
||||
text={`${texts.deleteDocumentQuestion} ${documentToDelete?.name || ""}`}
|
||||
/>
|
||||
<DocumentView />
|
||||
</>
|
||||
|
||||
1
web/src/components/types.d.ts
vendored
1
web/src/components/types.d.ts
vendored
@@ -27,7 +27,6 @@ declare type Field = {
|
||||
declare type K5Document = {
|
||||
id?: string
|
||||
name: string
|
||||
documentName: string
|
||||
createdAt: string
|
||||
description: string
|
||||
fields: Field[]
|
||||
|
||||
Reference in New Issue
Block a user