activityinfo-R icon indicating copy to clipboard operation
activityinfo-R copied to clipboard

Add / change folders

Open nickdickinson opened this issue 1 year ago • 3 comments

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

nickdickinson avatar Jun 05 '24 10:06 nickdickinson

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

nickdickinson avatar Jun 27 '24 12:06 nickdickinson

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)
    )
  }
}

Ryo-N7 avatar Jul 05 '24 05:07 Ryo-N7

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

nickdickinson avatar Nov 06 '24 13:11 nickdickinson