handlers

package
v0.0.0-...-646b7d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package handlers can compile to both WASM and any server-side compilation target. It is the first package which is reached in the flow of a request after the main command code. It does things like updating Data documents when a POST request is made, responding to GET requests, and calling application-specific code contained in Actions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AltShellHTML

func AltShellHTML(ux *common.UX, altShellName string) ([]byte, error)

AltShellHTML returns an alternative app shell into which you place additional content.

func AppShellHTML

func AppShellHTML(ux *common.UX) ([]byte, error)

AppShellHTML returns the app shell you could place additional content inside of.

func CheckGoalsSatisfied

func CheckGoalsSatisfied(t *common.Task, d *common.Data, appendIDToKey bool) (userErrors map[string]gen.FormError, err error)

CheckGoalsSatisfied goes through every Goal in the Task and checks if it is satisfied. userErrors map from Data keys to Alerts which specify severity and the error message. userErrors are complete sentences you should show underneath a field if it has an error.

appendIDToKey is typically true if the Task / Data are for a subtask or part of an array with itemwise validation (itemwise validation is not implemented right now).

func GETDataTable

func GETDataTable(request common.DataTableRequest) (common.DataTableResponse, error)

GETDataTable performs a GET for the DataTables.net data table request.

func GETDataTableSearchAllColumns

func GETDataTableSearchAllColumns(request common.DataTableRequest) (common.DataTableResponse, error)

GETDataTableSearchAllColumns searches permutations of the input string across all columns.

func GETFullTextSearch

GETFullTextSearch performs a search among the specified collection's Name and (if available) Help Text fields. Support is limited to.

func GETSelectSearch

GETSelectSearch performs a search among the specified collection and looks for a field which matches the input.

func HandleGET

func HandleGET(request common.GETRequest) (common.GETResponse, error)

HandleGET takes a common.GETRequest and returns a common.GETResponse.

This function has GOOS-specific handling since GOOS=js does not need the app shell packaged with the common.GETResponse. It is done like this because the alternative is for both JS and the server to have a copy of the app shell. This is difficult, but not impossible, for the client because it would have to store the directory structure of public/ in IndexedDB or a cache. Instead the client caches '/' responses (which contain the shell) and handles inserting the inner HTML into the shell in Javascript.

func HandleMultipleBlobs

func HandleMultipleBlobs(d common.Data, key string, URL *url.URL) ([]byte, error)

func HandlePOST

func HandlePOST(request common.POSTRequest) (common.POSTResponse, error)

HandlePOST routes the incoming POST request to the appropriate handler.

func HandleUploads

func HandleUploads(body io.ReadCloser, getRequest common.GETRequest, field string, filesLength string, metadata map[string]string, expectedLength int) error

HandleUploads handles a PUT request. This is typically a large file upload.

func InnerHTML

func InnerHTML(request common.GETRequest) (*common.UX, string, []common.ModDOM, error)

InnerHTML returns the task - like HTML in a GET common.GETRequest.

*common.UX contains the innerHTML of the webpage. string is a redirectURL. error != nil if there were any problems.

func InnerIntoAppShell

func InnerIntoAppShell(innerHTML []byte, appShell []byte) (string, error)

innerIntoAppShell places the inner HTML of a Task into the HTML of the App Shell This is substantially similar to the client function

func InternalGET

func InternalGET(request common.GETRequest) (common.GETResponse, error)

InternalGET is the entry point for responding ot all internal GET requests.

func InternalPOST

func InternalPOST(request common.POSTRequest) (common.POSTResponse, error)

InternalPOST is the entry point for responding ot all internal POST requests.

Internal calls are used for testing, like test pages at /test/

func POSTUpdate

func POSTUpdate(request *common.POSTRequest, isSubTask bool) (pr common.POSTResponse, hasUserErrors bool, err error)

POSTUpdate performs POST-related actions for this dataID, given the full Data object from the request.

IndustryID is this task (or sub-task's) Industry ID, probably taking into account overrides. Same for domainId, dataID, taskID.

schemaID is probably the ID of the Schema.

requestData is all of the data passed up from the client as part of this request.

newURL is from the request, and is set to FinishURL if necessary.

isSubTask is true if this "request" is not the parent Task.

func RoleAuthorize

func RoleAuthorize(user *common.User, request common.GETRequest, roleID string, accessByte byte) error

RoleAuthorize verifies that the objects in the request can be accessed by the User. This check is done based on the Roles assigned to a user. To improve lookup speed users can provide a "roleID". Access will first be checked in the roleID.

func RunAction

func RunAction(action common.Action, currentData *common.Data, task *common.Task, request *common.POSTRequest, response *common.POSTResponse) error

RunAction executes a function if it is in the whitelist for action funcs.

action is the Action being performed.

actionData is a map from IDs of Data documents to the *common.Data. It should include all *common.Data needed by action.

currentData is the Data from the DataID document passed in from the request; it is implied as being relevant to Actions as explained in the documentation for common.Action

task is the Task which this currentData is a part of. This is mostly provided to allow access to task.BotStaticData

request is from this request.

func RunBot

func RunBot(bot *common.Bot, data *common.Data, task *common.Task, request *common.POSTRequest, response *common.POSTResponse) error

RunBot executes a Bot with the given data as the "currentData" in the page. It does not do any substantial security checks.

func UserErrorModDOMs

func UserErrorModDOMs(formWrappingID string, userErrors map[string]gen.FormError, wipe bool) ([]common.ModDOM, error)

UserErrorModDOMs returns an array of ModDOM objects you can use to show user errors.

userErrors is the output of CheckGoalsSatisfied. Errors are placed just below the fields they occurred in if possible.

formWrappingID is the div wrapping the form. Task level errors are placed just after this. If the form contains a "Done" button you could use that ID instead.

The first 2 entries always wipes out all error entries if wipe is true. This is sort of a legacy code path; it may be removed after July if it's still in use.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL