Compare commits

...

4 Commits

Author SHA1 Message Date
431dd106c9 First attempt at fixing windows auth.
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
2026-06-19 21:56:10 +01:00
696b457978 Improved product creation.
Some checks are pending
farmcontrol/farmcontrol-ui/pipeline/head Build started...
2026-06-19 21:49:53 +01:00
53dce0e024 Excluded reference from summary. 2026-06-19 21:49:41 +01:00
de72d1f554 Enhance ApiServerProvider to validate model name before processing filters. 2026-06-19 21:39:32 +01:00
23 changed files with 139 additions and 43 deletions

View File

@ -8,7 +8,9 @@ import {
createWindow, createWindow,
setupMainWindowIPC, setupMainWindowIPC,
setupMainWindowAppEvents, setupMainWindowAppEvents,
setupDevAuthServer setupDevAuthServer,
setupSingleInstanceLock,
handleDeepLinkFromArgv
} from './mainWindow.js' } from './mainWindow.js'
// --- Keytar-backed auth session storage (main process) --- // --- Keytar-backed auth session storage (main process) ---
@ -27,14 +29,19 @@ try {
const KEYTAR_SERVICE = app.name || 'Farm Control' const KEYTAR_SERVICE = app.name || 'Farm Control'
const KEYTAR_ACCOUNT = 'authSession' const KEYTAR_ACCOUNT = 'authSession'
app.whenReady().then(() => { const gotTheLock = setupSingleInstanceLock(app)
createWindow()
registerGlobalShortcuts() if (gotTheLock) {
setupSpotlightIPC() app.whenReady().then(() => {
setupMainWindowIPC() createWindow()
setupMainWindowAppEvents(app) registerGlobalShortcuts()
setupDevAuthServer() setupSpotlightIPC()
}) setupMainWindowIPC()
setupMainWindowAppEvents(app)
setupDevAuthServer()
handleDeepLinkFromArgv()
})
}
app.on('will-quit', () => { app.on('will-quit', () => {
globalShortcut.unregisterAll() globalShortcut.unregisterAll()

View File

@ -7,6 +7,72 @@ const __dirname = dirname(__filename)
let win let win
const PROTOCOL_PREFIX = 'farmcontrol://'
function findProtocolUrl(args) {
return args.find(
(arg) => typeof arg === 'string' && arg.startsWith(PROTOCOL_PREFIX)
)
}
function sendNavigateToRenderer(redirectPath) {
const deliver = () => {
win.webContents.send('navigate', redirectPath)
win.show()
win.focus()
}
if (!win || win.isDestroyed()) {
createWindow()
win.webContents.once('did-finish-load', () => {
setTimeout(deliver, 100)
})
return
}
if (win.webContents.isLoading()) {
win.webContents.once('did-finish-load', () => {
setTimeout(deliver, 100)
})
return
}
deliver()
}
export function handleDeepLink(url) {
if (!url?.startsWith(`${PROTOCOL_PREFIX}app`)) return
const redirectPath = url.replace(`${PROTOCOL_PREFIX}app`, '') || '/'
sendNavigateToRenderer(redirectPath)
}
export function handleDeepLinkFromArgv() {
if (process.platform === 'darwin') return
const url = findProtocolUrl(process.argv)
if (url) handleDeepLink(url)
}
export function setupSingleInstanceLock(app) {
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
return false
}
app.on('second-instance', (_event, commandLine) => {
const url = findProtocolUrl(commandLine)
if (url) {
handleDeepLink(url)
} else if (win && !win.isDestroyed()) {
if (win.isMinimized()) win.restore()
win.show()
win.focus()
}
})
return true
}
function attachKeyboardShortcuts(browserWindow) { function attachKeyboardShortcuts(browserWindow) {
if (!browserWindow) return if (!browserWindow) return
// Keyboard shortcuts for the main window can be added here if needed // Keyboard shortcuts for the main window can be added here if needed
@ -155,13 +221,7 @@ export function setupMainWindowAppEvents(app) {
app.on('open-url', (event, url) => { app.on('open-url', (event, url) => {
event.preventDefault() event.preventDefault()
if (url.startsWith('farmcontrol://app')) { handleDeepLink(url)
// Extract the path/query after 'farmcontrol://app'
const redirectPath = url.replace('farmcontrol://app', '') || '/'
if (win && win.webContents) {
win.webContents.send('navigate', redirectPath)
}
}
}) })
} }

View File

@ -36,6 +36,7 @@ const NewFilamentStock = ({ onOk, reset, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -36,6 +36,7 @@ const NewPartStock = ({ onOk, reset, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -36,6 +36,7 @@ const NewStockAudit = ({ onOk, reset, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -32,6 +32,7 @@ const NewStockLocation = ({ onOk, reset }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -53,6 +53,7 @@ const NewCourierService = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -46,6 +46,7 @@ const NewCourier = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -50,6 +50,7 @@ const NewDocumentPrinter = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -32,6 +32,7 @@ const NewDocumentSize = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -50,6 +50,7 @@ const NewDocumentTemplate = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -46,6 +46,7 @@ const NewFilament = ({ onOk }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -46,6 +46,7 @@ const NewMaterial = ({ onOk }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -51,6 +51,7 @@ const NewNoteType = ({ onOk }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -88,6 +88,7 @@ const NewPart = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -32,6 +32,7 @@ const NewProductCategory = ({ onOk }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -25,7 +25,13 @@ const NewProduct = ({ onOk, defaultValues }) => {
visibleProperties={{ visibleProperties={{
priceMode: false, priceMode: false,
margin: false, margin: false,
amount: false amount: false,
priceTaxRate: false,
cost: false,
costTaxRate: false,
costWithTax: false,
price: false,
priceWithTax: false
}} }}
/> />
) )
@ -44,7 +50,13 @@ const NewProduct = ({ onOk, defaultValues }) => {
visibleProperties={{ visibleProperties={{
priceMode: true, priceMode: true,
margin: true, margin: true,
amount: true amount: true,
priceTaxRate: true,
cost: true,
costTaxRate: true,
costWithTax: true,
price: true,
priceWithTax: true
}} }}
/> />
) )
@ -73,6 +85,7 @@ const NewProduct = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -46,6 +46,7 @@ const NewTaxRate = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -46,6 +46,7 @@ const NewTaxRecord = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -49,6 +49,7 @@ const NewVendor = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}

View File

@ -49,6 +49,7 @@ const NewClient = ({ onOk, defaultValues }) => {
bordered={false} bordered={false}
visibleProperties={{ visibleProperties={{
_id: false, _id: false,
_reference: false,
createdAt: false, createdAt: false,
updatedAt: false updatedAt: false
}} }}
@ -84,4 +85,3 @@ NewClient.propTypes = {
} }
export default NewClient export default NewClient

View File

@ -802,12 +802,14 @@ const ApiServerProvider = ({ children }) => {
if (filter != null && Object.keys(filter).length > 0) { if (filter != null && Object.keys(filter).length > 0) {
const model = getModelByName(type) const model = getModelByName(type)
for (const key of Object.keys(filter)) { if (model.name !== 'unknown') {
const property = model?.properties?.find((p) => p.name === key) for (const key of Object.keys(filter)) {
if (property && property.type === 'object') { const property = model?.properties?.find((p) => p.name === key)
const value = filter[key] if (property && property.type === 'object') {
newFilter[`${key}._id`] = value?._id ?? value const value = filter[key]
delete newFilter[key] newFilter[`${key}._id`] = value?._id ?? value
delete newFilter[key]
}
} }
} }
} }

View File

@ -178,7 +178,7 @@ export const Product = {
{ {
name: 'cost', name: 'cost',
label: 'Cost', label: 'Cost',
required: false, required: true,
type: 'number', type: 'number',
prefix: '£', prefix: '£',
min: 0, min: 0,
@ -188,7 +188,7 @@ export const Product = {
{ {
name: 'costWithTax', name: 'costWithTax',
label: 'Cost w/ Tax', label: 'Cost w/ Tax',
required: false, required: true,
readOnly: true, readOnly: true,
type: 'number', type: 'number',
prefix: '£', prefix: '£',
@ -197,14 +197,13 @@ export const Product = {
columnWidth: 150, columnWidth: 150,
value: (objectData) => { value: (objectData) => {
const cost = objectData?.cost const cost = objectData?.cost
if (!cost) return undefined if (!cost) return 0
if (objectData?.costTaxRate?.rateType == 'percentage') { if (objectData?.costTaxRate?.rateType == 'percentage') {
return ( return (
(cost * (1 + objectData?.costTaxRate?.rate / 100)).toFixed(2) || (cost * (1 + objectData?.costTaxRate?.rate / 100)).toFixed(2) || 0
undefined
) )
} else if (objectData?.costTaxRate?.rateType == 'amount') { } else if (objectData?.costTaxRate?.rateType == 'amount') {
return (cost + objectData?.costTaxRate?.rate).toFixed(2) || undefined return (cost + objectData?.costTaxRate?.rate).toFixed(2) || 0
} }
return cost return cost
} }
@ -212,7 +211,7 @@ export const Product = {
{ {
name: 'costTaxRate', name: 'costTaxRate',
label: 'Cost Tax Rate', label: 'Cost Tax Rate',
required: false, required: true,
type: 'object', type: 'object',
objectType: 'taxRate', objectType: 'taxRate',
showHyperlink: true, showHyperlink: true,
@ -221,14 +220,14 @@ export const Product = {
{ {
name: 'priceMode', name: 'priceMode',
label: 'Price Mode', label: 'Price Mode',
required: false, required: true,
type: 'priceMode', type: 'priceMode',
columnWidth: 150 columnWidth: 150
}, },
{ {
name: 'price', name: 'price',
label: 'Price', label: 'Price',
required: false, required: true,
type: 'number', type: 'number',
prefix: '£', prefix: '£',
min: 0, min: 0,
@ -243,8 +242,7 @@ export const Product = {
objectData?.cost != null objectData?.cost != null
) { ) {
return ( return (
(objectData.cost * (1 + objectData.margin / 100)).toFixed(2) || (objectData.cost * (1 + objectData.margin / 100)).toFixed(2) || 0
undefined
) )
} }
return objectData?.price return objectData?.price
@ -253,7 +251,7 @@ export const Product = {
{ {
name: 'margin', name: 'margin',
label: 'Margin', label: 'Margin',
required: false, required: true,
type: 'number', type: 'number',
disabled: (objectData) => objectData?.priceMode == 'amount', disabled: (objectData) => objectData?.priceMode == 'amount',
suffix: '%', suffix: '%',
@ -265,7 +263,7 @@ export const Product = {
{ {
name: 'priceWithTax', name: 'priceWithTax',
label: 'Price w/ Tax', label: 'Price w/ Tax',
required: false, required: true,
readOnly: true, readOnly: true,
type: 'number', type: 'number',
prefix: '£', prefix: '£',
@ -283,14 +281,13 @@ export const Product = {
} else { } else {
price = objectData?.price price = objectData?.price
} }
if (!price) return undefined if (!price) return 0
if (objectData?.priceTaxRate?.rateType == 'percentage') { if (objectData?.priceTaxRate?.rateType == 'percentage') {
return ( return (
(price * (1 + objectData?.priceTaxRate?.rate / 100)).toFixed(2) || (price * (1 + objectData?.priceTaxRate?.rate / 100)).toFixed(2) || 0
undefined
) )
} else if (objectData?.priceTaxRate?.rateType == 'amount') { } else if (objectData?.priceTaxRate?.rateType == 'amount') {
return (price + objectData?.priceTaxRate?.rate).toFixed(2) || undefined return (price + objectData?.priceTaxRate?.rate).toFixed(2) || 0
} }
return price return price
} }
@ -298,7 +295,7 @@ export const Product = {
{ {
name: 'priceTaxRate', name: 'priceTaxRate',
label: 'Price Tax Rate', label: 'Price Tax Rate',
required: false, required: true,
type: 'object', type: 'object',
objectType: 'taxRate', objectType: 'taxRate',
showHyperlink: true, showHyperlink: true,