an updated and hopefully faster version of the ST Toolbox
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

116 lines
2.9 KiB

package cli
import (
"fmt"
"marmic/servicetrade-toolbox/internal/api"
"marmic/servicetrade-toolbox/internal/ui"
"marmic/servicetrade-toolbox/internal/utils"
)
func HandleJobs(session *api.Session) {
for {
ui.DisplayMenu([]string{
"Search Job by ID",
"List Recent Jobs",
"Create New Job",
"Manage Job Attachments",
"View Deficiencies",
"Back to Main Menu",
}, "Jobs Menu")
choice, err := utils.GetUserChoice(6)
if err != nil {
ui.DisplayError("Invalid input:", err)
utils.PressEnterToContinue()
continue
}
switch choice {
case 1:
searchJobByID(session)
case 2:
listRecentJobs(session)
case 3:
createNewJob(session)
case 4:
manageJobAttachments(session)
case 5:
viewDeficiencyById(session)
case 6:
return
}
}
}
func searchJobByID(session *api.Session) {
ui.ClearScreen()
ui.DisplayMessage("Search Job by ID:")
jobID := utils.PromptForInput("Enter Job ID: ")
// TODO: Implement job search logic using the API
ui.DisplayMessage(fmt.Sprintf("Searching for job with ID: %s", jobID))
utils.PressEnterToContinue()
}
func listRecentJobs(session *api.Session) {
ui.ClearScreen()
ui.DisplayMessage("Listing recent jobs...")
// TODO: Implement recent jobs listing logic using the API
utils.PressEnterToContinue()
}
func createNewJob(session *api.Session) {
ui.ClearScreen()
ui.DisplayMessage("Creating a new job...")
// TODO: Implement job creation logic using the API
utils.PressEnterToContinue()
}
func manageJobAttachments(session *api.Session) {
ui.ClearScreen()
jobID := utils.PromptForInput("Enter Job ID: ")
attachments, err := session.GetAttachmentsForJob(jobID)
if err != nil {
ui.DisplayError("Failed to retrieve attachments:", err)
utils.PressEnterToContinue()
return
}
ui.DisplayMessage(fmt.Sprintf("Attachments for Job %s:", jobID))
if dataMap, ok := attachments["data"].(map[string]interface{}); ok {
if attachmentsList, ok := dataMap["attachments"].([]interface{}); ok {
for i, attachment := range attachmentsList {
if att, ok := attachment.(map[string]interface{}); ok {
ui.DisplayMessage(fmt.Sprintf("%d. %s", i+1, att["fileName"]))
}
}
}
}
// TODO: Implement attachment deletion logic
utils.PressEnterToContinue()
}
func viewDeficiencyById(session *api.Session) {
ui.ClearScreen()
deficiencyID := utils.PromptForInput("Enter Deficiency ID: ")
ui.DisplayMessage(fmt.Sprintf("Fetching information for Deficiency %s...", deficiencyID))
deficiencies, err := session.GetDeficiencyInfoForJob(deficiencyID)
if err != nil {
ui.DisplayError("Failed to retrieve deficiency information:", err)
utils.PressEnterToContinue()
return
}
for _, deficiency := range deficiencies {
ui.DisplayMessage(fmt.Sprintf("ID: %v", deficiency["id"]))
ui.DisplayMessage(fmt.Sprintf("Description: %v", deficiency["description"]))
ui.DisplayMessage(fmt.Sprintf("Status: %v", deficiency["status"]))
ui.DisplayMessage("---")
}
utils.PressEnterToContinue()
}