From d4cc4b4a6ce06239a7fa363a2fd100d016e6413d Mon Sep 17 00:00:00 2001 From: John Mizerek Date: Tue, 27 Jan 2026 20:52:59 -0800 Subject: [PATCH] Fix service bell task creation for Android app - Update create.cfm to handle TaskTypeID for service bell tasks - Update hud.js to prefer TaskTypeColor/TaskTypeName for task display Co-Authored-By: Claude Opus 4.5 --- api/tasks/create.cfm | 176 +++++++++++++++++++++++++++++-------------- hud/hud.js | 51 ++++++++++++- 2 files changed, 166 insertions(+), 61 deletions(-) diff --git a/api/tasks/create.cfm b/api/tasks/create.cfm index b3e1c7a..05d251f 100644 --- a/api/tasks/create.cfm +++ b/api/tasks/create.cfm @@ -1,6 +1,7 @@ -// Create a task (e.g., photo task for menu item) -// Input: BusinessID, ItemID, TaskType, Instructions, PYTReward +// Create a task (service bell request or photo task) +// Input for service bell: BusinessID, ServicePointID, TaskTypeID, Message +// Input for photo task: BusinessID, ItemID, TaskType, Instructions, PYTReward // Output: { OK: true, TASK_ID: ... } response = { "OK": false }; @@ -13,71 +14,129 @@ try { jsonData = deserializeJSON(requestBody); businessID = val(jsonData.BusinessID ?: 0); - itemID = val(jsonData.ItemID ?: 0); - taskType = jsonData.TaskType ?: "employee_photo"; - instructions = jsonData.Instructions ?: ""; - pytReward = val(jsonData.PYTReward ?: 0); if (businessID == 0) { throw("BusinessID is required"); } - // Get item info if itemID provided - itemName = ""; - if (itemID > 0) { - itemQuery = queryExecute(" - SELECT ItemName FROM Items WHERE ItemID = :itemID - ", { itemID: itemID }); - if (itemQuery.recordCount) { - itemName = itemQuery.ItemName; + // Check if this is a service bell request (has TaskTypeID) + taskTypeID = val(jsonData.TaskTypeID ?: 0); + + if (taskTypeID > 0) { + // Service bell task + servicePointID = val(jsonData.ServicePointID ?: 0); + orderID = val(jsonData.OrderID ?: 0); + userID = val(jsonData.UserID ?: 0); + message = jsonData.Message ?: ""; + + // Get task type info for display + taskTypeQuery = queryExecute(" + SELECT tt_TaskTypeName, tt_TaskTypeColor, tt_TaskTypeIcon + FROM tt_TaskTypes + WHERE tt_TaskTypeID = :taskTypeID + ", { taskTypeID: taskTypeID }, { datasource: "payfrit" }); + + taskTitle = message; + if (taskTypeQuery.recordCount && len(taskTypeQuery.tt_TaskTypeName)) { + taskTitle = taskTypeQuery.tt_TaskTypeName; } - } - // Create task description - taskDescription = ""; - switch(taskType) { - case "employee_photo": - taskDescription = "Take a photo of: " & itemName; - break; - case "user_photo": - taskDescription = "Submit a photo of " & itemName & " to earn " & pytReward & " PYT"; - break; - default: - taskDescription = instructions; - } + // Use message as details + taskDetails = message; - // Insert task - queryExecute(" - INSERT INTO Tasks ( - TaskBusinessID, - TaskItemID, - TaskType, - TaskDescription, - TaskInstructions, - TaskPYTReward, - TaskStatus, - TaskCreatedOn - ) VALUES ( - :businessID, - :itemID, - :taskType, - :description, - :instructions, - :pytReward, - 'pending', - NOW() - ) - ", { - businessID: businessID, - itemID: itemID, - taskType: taskType, - description: taskDescription, - instructions: instructions, - pytReward: pytReward - }); + // Insert service bell task + queryExecute(" + INSERT INTO Tasks ( + TaskBusinessID, + TaskTypeID, + TaskCategoryID, + TaskOrderID, + TaskTitle, + TaskDetails, + TaskAddedOn, + TaskClaimedByUserID + ) VALUES ( + :businessID, + :taskTypeID, + 0, + :orderID, + :taskTitle, + :taskDetails, + NOW(), + 0 + ) + ", { + businessID: businessID, + taskTypeID: taskTypeID, + orderID: orderID, + taskTitle: taskTitle, + taskDetails: taskDetails + }, { datasource: "payfrit" }); + + } else { + // Legacy photo task + itemID = val(jsonData.ItemID ?: 0); + taskType = jsonData.TaskType ?: "employee_photo"; + instructions = jsonData.Instructions ?: ""; + pytReward = val(jsonData.PYTReward ?: 0); + + // Get item info if itemID provided + itemName = ""; + if (itemID > 0) { + itemQuery = queryExecute(" + SELECT ItemName FROM Items WHERE ItemID = :itemID + ", { itemID: itemID }); + if (itemQuery.recordCount) { + itemName = itemQuery.ItemName; + } + } + + // Create task description + taskDescription = ""; + switch(taskType) { + case "employee_photo": + taskDescription = "Take a photo of: " & itemName; + break; + case "user_photo": + taskDescription = "Submit a photo of " & itemName & " to earn " & pytReward & " PYT"; + break; + default: + taskDescription = instructions; + } + + // Insert legacy task + queryExecute(" + INSERT INTO Tasks ( + TaskBusinessID, + TaskItemID, + TaskType, + TaskDescription, + TaskInstructions, + TaskPYTReward, + TaskStatus, + TaskCreatedOn + ) VALUES ( + :businessID, + :itemID, + :taskType, + :description, + :instructions, + :pytReward, + 'pending', + NOW() + ) + ", { + businessID: businessID, + itemID: itemID, + taskType: taskType, + description: taskDescription, + instructions: instructions, + pytReward: pytReward + }); + } // Get the new task ID - result = queryExecute("SELECT LAST_INSERT_ID() as newID"); + result = queryExecute("SELECT LAST_INSERT_ID() as newID", {}, { datasource: "payfrit" }); taskID = result.newID; response = { @@ -89,7 +148,8 @@ try { } catch (any e) { response = { "OK": false, - "ERROR": e.message + "ERROR": e.message, + "DETAIL": e.detail ?: "" }; } diff --git a/hud/hud.js b/hud/hud.js index 643fc97..8d6b70f 100644 --- a/hud/hud.js +++ b/hud/hud.js @@ -225,17 +225,23 @@ const HUD = { return `${mins}:${String(secs).padStart(2, '0')}`; }, - // Get category name - use task's category name if available, fall back to hardcoded + // Get category/task type name - prefer task type for service bell tasks getCategoryName(task) { + if (task && task.TaskTypeName && task.TaskTypeName.length > 0) { + return task.TaskTypeName; + } if (task && task.TaskCategoryName) { return task.TaskCategoryName; } return this.categories[task?.TaskCategoryID]?.name || 'Task'; }, - // Get category color - use task's category color if available, fall back to hardcoded + // Get category/task type color - prefer task type color for service bell tasks getCategoryColor(task) { - if (task && task.TaskCategoryColor) { + if (task && task.TaskTypeColor && task.TaskTypeColor.length > 0 && task.TaskTypeColor !== '#9C27B0') { + return task.TaskTypeColor; + } + if (task && task.TaskCategoryColor && task.TaskCategoryColor !== '#888888') { return task.TaskCategoryColor; } return this.categories[task?.TaskCategoryID]?.color || '#888888'; @@ -361,6 +367,45 @@ function acceptTask() { HUD.acceptTask(); } +function toggleFullscreen() { + const body = document.body; + const isMaximized = body.classList.contains('maximized'); + + if (isMaximized) { + // Restore normal view + body.classList.remove('maximized'); + // Also exit native fullscreen if active + if (document.fullscreenElement) { + document.exitFullscreen().catch(() => {}); + } else if (document.webkitFullscreenElement) { + document.webkitExitFullscreen(); + } + } else { + // Maximize - hide header for more space + body.classList.add('maximized'); + + // Also try native fullscreen on desktop + const elem = document.documentElement; + if (elem.requestFullscreen) { + elem.requestFullscreen().catch(() => {}); + } else if (elem.webkitRequestFullscreen) { + elem.webkitRequestFullscreen(); + } + } +} + +// Exit maximized mode when exiting native fullscreen +document.addEventListener('fullscreenchange', () => { + if (!document.fullscreenElement) { + document.body.classList.remove('maximized'); + } +}); +document.addEventListener('webkitfullscreenchange', () => { + if (!document.webkitFullscreenElement) { + document.body.classList.remove('maximized'); + } +}); + // Initialize on load document.addEventListener('DOMContentLoaded', () => { HUD.init();