Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Complete rework #32

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

NewEditOfficial
Copy link

@NewEditOfficial NewEditOfficial commented Nov 25, 2023

Description

This pull request focus on revamping/improving the backend logic overall, and adjusting the frontend to work perfectly with those changes.

State: WIP

TODO

  • Create function which checks if user is able to perform those tasks: CREATE, PUBLISH, DELETE
  • Create buy news paper function with proper validation.
  • On resource restart hook the clear of the ped from having any attached entities and so on.
  • Define support for ESX & ox_inventory.

feat: (LOCALES): Added locales and basic translation function to it.
chore: (FRONTEND): Adjusted logic for frontend with fetchStories, which allows to refresh data from backend.
BUILDED_ASSETS
fix: (DATABASE): Added validation for each function
fix: (RESOURCE_STARTUP): This should fix the sync issue, sometimes data not occuring on client.
feat: (NUI) Added resync  of data and handleMenu function which allows to show/hide menu.
feat: (STORIES): Create cache when insert data into database and sync them to all users on server.
feat: (LOCALES): Added missing locales.
feat: (RESET_PED_RESOURCE_RESTART): Added reset state when resource is restarted.
fix: (IS_REPORTER_VALIDATION): Added function to validate if user has job as reporter to allow him perform specific actions.
chore: (STORIES_SORTING): Add sorting of recent stories by date, to show in proper order.
feat: (QBCORE): Define item list for qb-core based inventories
feat: (OX): Define item list for ox_inventory
chore: (INVENTORY_IMAGES): Moved to assets/inventoryIcons/
feat: (FRAMEWORK_API): Added basic framework bridge for ESX/QBCore
feat: (INVENTORY_API): Added basic hook of ox_inventory / qb-inventories that can be used with the resource.
feat: (INIT_DEBUG): Show on resource start relevant server/resource information.
chore: (CONFIG): Added supported inventories, some variables, refactor
chore: (DEBUG) Improve print to be look better + added future todo for frontend timestamp / date.
Copy link
Owner

@xFutte xFutte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments. I'll re-review when updated/answered.


ui_page 'web/public/index.html'

--[[ Resource Information ]]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a "github" property as well? The upcoming ps-core can detect if the latest version is installed by this, and this might be added in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, what should be there? Let me know 👍

server/framework/qbcore.lua Outdated Show resolved Hide resolved
server/framework/qbcore.lua Outdated Show resolved Hide resolved
server/framework/standalone.lua Outdated Show resolved Hide resolved
local jailTime = prisonerData and prisonerData.jailTime or 0
local prisonerName = prisonerData and prisonerData.name

-- TODO: Requires to modify frontend with some variable with prefix jail format (seconds/mins/hours/days) to make proper sense.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something you need from me? ps-core is going to come with utility functions for formatting dates, so we can use that if that was the intention?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is now that is strictly to months in frontend when you see, related to create definition for locales of UI? 🤔

Link

There is no problem to format it in backend, the thing why the note its there it will require refactor / adjustment in the frontend itself to make sense 👍

Comment on lines +77 to +115
if player and data then
if not IsReporter(playerId) then
Framework.showNotify(playerId, l('NOT_ALLOWED'), 'error')
return
end

local storyType = data.type and data.type:upper()

if storyType then
if STORIES_CACHE[storyType] then
local id = #STORIES_CACHE[storyType] + 1

STORIES_CACHE[storyType][id] = {
title = data.title,
story_type = storyType,
image = data.image,
jailed_player = '',
jailed_time = 0,
id = id,
publisher = player.charName,
body = data.body,
date = data.date,
}

table.sort(STORIES_CACHE[storyType], function(a, b)
return a.date > b.date
end)

Database.PublishStory(data, player.charName)

SyncStories(-1, STORIES_CACHE)

Framework.showNotify(playerId, l('STORY_PUBLISHED'), 'success')
else
print('futte-newspaper:server:publishStory: storyType is not valid')
end
else
print('futte-newspaper:server:publishStory: storyType is nil')
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of it already has it, but could a couple of things be refactored to it has guardclauses instead? I think that would be more clean.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure we can improve this part + i will make 1 function which can handle this for the rest since we are using it for:

UPDATE, CREATE, DELETE 👍

RegisterNetEvent('futte-newspaper:server:deleteStory', function(data)
local playerId = source
local player = Framework.getPlayer(playerId)
local storyId = data and data.id
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be a bit nit picky, but this variable name is not so representative of what it does.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will come with better variable naming.

server/sv-main.lua Show resolved Hide resolved
local itemState = Framework.DoesItemExist(Config.Items.NEWSPAPER) or 'UNK'
local jobState = Framework.DoesJobExist(Config.Job.name) or 'UNK'

sprint('\n^3%s^0\nVersion: ^3%s^0\nFramework: ^3%s^0\n^0Inventory: ^3%s\n^0\n^0Is required item [%s] registered: ^3%s^0\n^0Is required job [%s] registered in your FW: ^3%s\n^0', GetCurrentResourceName(), currentVersion, Config.Framework, Config.Inventory, Config.Items.NEWSPAPER, itemState and 'YES' or 'PLEASE DEFINE THE REQUIRED ITEM IN YOUR INVENTORY!', Config.Job.name, jobState and 'YES' or 'PLEASE DEFINE THE REQUIRED JOB IN YOUR FRAMEWORK!')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be print instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will refactor this and define proper naming. 👍

const placeholderStory = {
id: 0,
title: 'Welcome to futte-newspaper',
body: "<p>futte-newspaper is a standalone ressource for FiveM. It has the following dependencies:</p><p><ul><li>qb-target</li><li>oxmysql</li></ul></p><p>I hope you'll enjoy the resource. Feel free to open issues if you find a bug/wish new functionality. This story will automatically delete itself as soon as you write a new one.</p><p>- xFutte</p>",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I guess it is not a standalone resource..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep it ESX/QBCORE, standalone version could be sorted out in future if needed really. 👍

chore: (JOB_STRUCTURE_NOTE): Removed leftover note for myself when i was working with framework job data.
chore: (getPlayer): Note for framework job data, removed it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants