Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add / change folders #121

Open
nickdickinson opened this issue Jun 5, 2024 · 3 comments
Open

Add / change folders #121

nickdickinson opened this issue Jun 5, 2024 · 3 comments
Assignees
Milestone

Comments

@nickdickinson
Copy link
Collaborator

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

@nickdickinson
Copy link
Collaborator Author

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 nickdickinson added this to the Release 4.38 milestone Jun 27, 2024
@nickdickinson nickdickinson self-assigned this Jun 27, 2024
@Ryo-N7
Copy link
Collaborator

Ryo-N7 commented Jul 5, 2024

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
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants