bedatadriven / activityinfo-R

ActivityInfo R Language Client
https://www.activityinfo.org/support/docs/R/
18 stars 12 forks source link

Add / change folders #121

Open nickdickinson opened 5 months ago

nickdickinson commented 5 months ago

At the moment, there are no functions in the package to add or change folders. Should we consider this in a future release?

nickdickinson commented 5 months ago

Add updateResource() using https://www.activityinfo.org/support/docs/api/reference/updateDatabase.html and providing resourceUpdates with the resource to change. See folder example.

Ryo-N7 commented 4 months ago

here's an example I created for my own usage, if it might help:

create_folder_activityinfo <- function(folderId = NULL, folderLabel, databaseId, locationId = NULL) {
  ## if folderId isn't specified, create a folder
  if (is.null(folderId)) {
    ## create new folder
    request <- databaseUpdates()
    request$resourceUpdates <- list(list(
      id = cuid(), ## generate new folder using random new CUID
      parentId = databaseId, ## create it at first level of db
      type = "FOLDER",
      label = folderLabel)
    )

    result <- activityinfo:::postResource(
      sprintf("databases/%s", databaseId),
      request,
      task = sprintf("Requesting to create folder '%s' with id %s from database %s", folderLabel, folderId, databaseId)
    )
  } else {

    if (is.null(locationId)) stop("Please input a new location ID (folder ID or database ID)")

    ## move existing folder cwsp8ywlo79hmox3 to another location within db
    request <- databaseUpdates()
    request$resourceUpdates <- list(list(
      id = folderId, ## id of existing folder
      parentId = locationId, ## move to NEW location: another folder or back to top database
      type = "FOLDER")
    )

    result <- postResource(
      sprintf("databases/%s", databaseId),
      request,
      task = sprintf("Requesting to move folder '%s' with id %s from database %s", folderLabel, folderId, databaseId)
    )
  }
}
nickdickinson commented 2 weeks ago

Will add a function to the package and add this to the tutorial on how to add and manipulate forms