Skip to content

Commit

Permalink
boilerplate 0.0.1.2
Browse files Browse the repository at this point in the history
* fixed issue in `boilerplate_manage_measures()`: now, if 'n' is selected for new database name, the manager will return to the main menu instead of charging along.
  • Loading branch information
go-bayes committed Aug 26, 2024
1 parent fd5bcbf commit a6e36b7
Show file tree
Hide file tree
Showing 27 changed files with 443 additions and 32 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: boilerplate
Title: Tools for Managing and Compiling Manuscript Templates
Version: 0.0.1.1
Version: 0.0.1.2
Authors@R:
person("Joseph", "Bulbulia", email = "joseph.bulbulia@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-5861-2056"))
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## boilerplate (development version)

## [24-08-2024] boilerplate 0.0.1.2

### Improved

* fixed issue in `boilerplate_manage_measures()`: now, if 'n' is selected for new database name, the manager will return to the main menu instead of charging along.

## [24-08-2024] boilerplate 0.0.1.1-alpha

### New
Expand Down
33 changes: 27 additions & 6 deletions R/boilerplate_manage_measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ UserInterface <- R6::R6Class("UserInterface",
}
)
)
# runs the graphical user interface for the measures database manager
boilerplate_manage_measures <- function(measures_path = NULL) {
if (is.null(measures_path)) {
measures_path <- here::here()
}

measures_path <- measures_path %||% here::here()
db <- MeasuresDatabase$new(measures_path)
ui <- UserInterface$new()

run_gui(db, ui)
}

# runs the graphical user interface for the measures database manager
run_gui <- function(db, ui) {
cli::cli_h1("Welcome to the Boilerplate Measures Database Manager")
Expand All @@ -225,9 +238,13 @@ run_gui <- function(db, ui) {
choice <- ui$get_choice("Enter your choice: ", length(options))

if (choice == 1) {
create_new_database(db, ui)
if (create_new_database(db, ui)) {
break # Only break if database was successfully created
}
} else if (choice == 2) {
open_existing_database(db, ui)
if (open_existing_database(db, ui)) {
break # Only break if database was successfully opened
}
} else if (choice == 3) {
list_rds_files(db$path)
} else if (choice == 4) {
Expand All @@ -237,13 +254,12 @@ run_gui <- function(db, ui) {
return()
}
}

if (choice == 1 || choice == 2) break
}

manage_database(db, ui)
}


# creates a new measures database
create_new_database <- function(db, ui) {
cli::cli_h2("Creating a new measures database")
Expand Down Expand Up @@ -276,12 +292,16 @@ create_new_database <- function(db, ui) {
# opens an existing measures database
open_existing_database <- function(db, ui) {
files <- list_rds_files(db$path)
if (is.null(files)) return()
if (is.null(files)) return(FALSE)

file_choice <- ui$get_choice("Enter the number of the file you want to open: ", length(files))

file_name <- files[file_choice]
db$load_data(file_name)
if (db$load_data(file_name)) {
return(TRUE)
} else {
return(FALSE)
}
}

# lists available .rds files in the specified directory
Expand Down Expand Up @@ -604,3 +624,4 @@ review_and_save_measure <- function(db, ui, measure, is_new = TRUE) {
}
}
}

Loading

0 comments on commit a6e36b7

Please sign in to comment.