Closed Ryo-N7 closed 1 year ago
createDatabase()
should be something like this:
activityinfo:::postResource("databases", body = list(id = cuid(), label = "my new db!", templateId = "blank"), task = sprintf("Creating test database '%s' post request", label))
for uploading a NEW form (that doesn't exist in ActivityInfo yet), be able to grab a data.frame (imported into R as CSV or Excel, etc.) and then run it through a function to create a ActivityInfo schema structure from which we can use to upload into ActivityInfo: either via the activityinfo::addForm()
or the add Form >> paste field list
on the UI
EDIT: the above separated out into a separate issue, #44 as it ties into separate improvements to importTable()
as well rather than just the form schema stuff
some kind of function to inspect all possible field types available in ActivityInfo (quantity, FREE_TEXT, Date, etc.)
getFormSchema()
has a method that allows you to transform it into a data.frame
but getDatabaseSchema()
currently does not.
it'll be nice to get the database schema into a data.frame format as well so that updates to the database schema can also be handled via data.frames , similar to #33
of course it's more difficult to do this for the DB schema since it has several very distinct elements (tables, roles, users as their own list-of-lists) so maybe helper functions to extract these specific bits of a db schema would be helpful:
afda_schema <- getDatabaseSchema("c5h9mudkz3sqce52")
## Tables come from the "resources" list
## turn below code into a function
## Get table labels
tab_label <- afda_schema %>%
purrr::pluck("resources") %>%
purrr::map(pluck("label")) %>% unlist()
## Get table IDs
tab_id <- afda_schema %>%
purrr::pluck("resources") %>%
purrr::map(pluck("id")) %>%
unlist()
## put 'em together to create a nice look-up
data.frame(
Table = tab_label,
table_id = tab_id
)
## separate function to extract all users and user info
## separate function to extract all roles and role info....
Great example! Thanks!
Checklist
createDatabase()
functionHelper functions to extract elements of the database schema and turn into a nicie data.frame similar to form schema method:
Form schema helpers: be able to build a form schema from the ground-up
Ideal workflow:
createDatabase()
for a blank databaseaddForm()
At the moment, the following branch https://github.com/bedatadriven/activityinfo-R/tree/version-4.32
can be tested. I will add more form fields and the other help functions now but the main work has been done.
Added are:
createDatabase();
deleteDatabase();
formFieldSchema();
asFormFieldSchema();
validateFormFieldSchema();
formSchema();
asFormSchema();
validateFormSchema()
deleteForm();
addForm()
Text, Barcode, and Serial Code Form field functions (constructor and validation):
barcodeFieldSchema()
textFieldSchema()
serialNumberFieldSchema()
validateBarcodeFieldSchema()
validateTextFieldSchema()
validateSerialNumberFieldSchema()
Added s3 generics for some chaining when creating and modifying forms and their fields. Updated and improved tests and documentation
Here is an example from an actual test:
dbTest <- createDatabase("Another test database on the fly!")
fmSchm <- formSchema(databaseId = dbTest$databaseId, label = paste0("R form with multiple fields test ", cuid()))
fmSchm <- fmSchm |>
addFormField(barcodeFieldSchema(label = "A barcode field")) |>
addFormField(textFieldSchema(label = "A text field")) |>
addFormField(serialNumberFieldSchema(label = "A serial number field"))
dbMetadata <- addForm(databaseId = databaseId, schema = fmSchm)
fmSchm2 <- getFormSchema(formId = fmSchm$id)
deleteForm(databaseId = databaseId, formId = fmSchm2$id)
result <- deleteDatabase(databaseId = dbTest$databaseId)
One thing we try to do is harmonize verbs, both in the user interface in the code base.
Can you change createDatabase() to addDatabase() ?
On Tue, Jan 31, 2023 at 2:33 PM Nicolas Dickinson @.***> wrote:
At the moment, the following branch https://github.com/bedatadriven/activityinfo-R/tree/version-4.32 can be tested. I will add more form fields and the other help functions now but the main work has been done.
Added are:
createDatabase(); deleteDatabase(); formFieldSchema(); asFormFieldSchema(); validateFormFieldSchema(); formSchema(); asFormSchema(); validateFormSchema() deleteForm(); addForm()
Text, Barcode, and Serial Code Form field functions (constructor and validation):
barcodeFieldSchema() textFieldSchema() serialNumberFieldSchema() validateBarcodeFieldSchema() validateTextFieldSchema() validateSerialNumberFieldSchema()
Added s3 generics for some chaining when creating and modifying forms and their fields. Updated and improved tests and documentation
Here is an example from an actual test:
dbTest <- createDatabase("Another test database on the fly!")
fmSchm <- formSchema(databaseId = dbTest$databaseId, label = paste0("R form with multiple fields test ", cuid()))
fmSchm <- fmSchm |> addFormField(barcodeFieldSchema(label = "A barcode field")) |> addFormField(textFieldSchema(label = "A text field")) |> addFormField(serialNumberFieldSchema(label = "A serial number field"))
dbMetadata <- addForm(databaseId = databaseId, schema = fmSchm) fmSchm2 <- getFormSchema(formId = fmSchm$id)
deleteForm(databaseId = databaseId, formId = fmSchm2$id)
result <- deleteDatabase(databaseId = dbTest$databaseId)
— Reply to this email directly, view it on GitHub https://github.com/bedatadriven/activityinfo-R/issues/32#issuecomment-1410364758, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADO5Q5DQLYDEJKPX4XAMV3WVEIDXANCNFSM6AAAAAASLDBRJA . You are receiving this because you are subscribed to this thread.Message ID: @.***>
--
Alexander Bertram
Executive Director
ActivityInfo https://www.activityinfo.org/ - BeDataDriven BV http://www.bedatadriven.com/
Email: @.***
Mobile/Whatsapp: +31647205388
Timezone: GMT+1
Join the ActivityInfo community https://activityinfo.org!
Follow ActivityInfo on LinkedIn https://www.linkedin.com/showcase/activityinfo & @Twitter https://twitter.com/activityinfo
Skype: akbertram
Binckhorstlaan 36, unit C3.56, 2516 BE The Hague, The Netherlands
This was brought up in the most recent
ActivityInfo with R webinar
, some helper function for users to set up the structure of the ActivityInfo form schema when using theaddForm()
function, kind of like thepermissions()
helper function we have forupdateUserRole()
? This same helper function can be applied toupdateFormSchema()
.Can also extend this for setting up the structure of Database schema as well and then updating the database schema/tree? Somewhat related, I also remember seeing a
createDatabase()
function in an older webinar from 2018, but its not in the current R package anymore.