Skip to content

Commit

Permalink
fix :deal with empty client
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentGuyader committed Feb 19, 2024
1 parent 0325e8a commit 6776e15
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 71 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: togglr
Title: 'Toggl.com' Api for 'Rstudio'
Version: 0.1.99.9002
Version: 0.2.1
Authors@R: c(
person("Vincent", "Guyader", , "[email protected]", role = c("aut", "cre")),
person("ThinkR", role = c("cph", "fnd"))
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export(get_context)
export(get_context_project)
export(get_current)
export(get_current_duration)
export(get_current_project_task_detail)
export(get_dashboard)
export(get_detailled_report)
export(get_project_id)
export(get_project_id_and_name)
export(get_project_task_detail)
export(get_project_total)
export(get_summary_report)
export(get_time_entries)
Expand Down
69 changes: 44 additions & 25 deletions R/get_dashboard.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ get_dashboard <- function(api_token = get_toggl_api_token(),

synthese <-
data.frame(id = out$id, out$title, time = out$time) %>%
select(-one_of(c("color","hex_color")))
select(-one_of(c("color","hex_color")))

tache <- out$items %>%
setNames(synthese$project) %>%
map( ~ {
.x$title <- .x$title$time_entry
.x
})


res <- list(synthese = synthese,
tache = tache)
Expand All @@ -58,13 +58,13 @@ get_dashboard <- function(api_token = get_toggl_api_token(),
#' @importFrom prettyunits pretty_ms
n_to_tps <- function(n) {
# format(as.POSIXct(0, origin = Sys.Date(), tz = "GMT") + n / 1000, "%H:%M:%S")
#
# difftime(as.POSIXct(0, origin = Sys.Date(), tz = "GMT") + n / 1000,Sys.Date(),units = "hour")
#
#
# library(lubridate)
# new_duration()
# duration(104046451/1000,units = "seconds") %>% format("%H:%M:%S")
#
# difftime(as.POSIXct(0, origin = Sys.Date(), tz = "GMT") + n / 1000,Sys.Date(),units = "hour")
#
#
# library(lubridate)
# new_duration()
# duration(104046451/1000,units = "seconds") %>% format("%H:%M:%S")
prettyunits::pretty_ms(n)
}

Expand All @@ -83,7 +83,7 @@ n_to_tps <- function(n) {
#' @export
#'
get_project_total <- function(project_name = get_context_project(),

api_token = get_toggl_api_token(),
workspace_id = get_workspace_id(api_token),
since = Sys.Date() - lubridate::years(1),
Expand All @@ -98,7 +98,7 @@ get_project_total <- function(project_name = get_context_project(),
dash$synthese %>% filter(project == project_name) %>% pull("time") ->tmps

(get_current_duration() + tmps) %>% as.numeric() %>% n_to_tps

}

#' Get all project's names
Expand All @@ -122,7 +122,7 @@ get_all_project_names <- function(api_token = get_toggl_api_token(),
since = since,
until = until
)

dash$synthese$project
}

Expand All @@ -148,7 +148,7 @@ get_all_client_names <- function(api_token = get_toggl_api_token(),
since = since,
until = until
)

dash$synthese$client %>% unique()
}

Expand All @@ -167,34 +167,53 @@ get_all_client_names <- function(api_token = get_toggl_api_token(),
#' @importFrom lubridate years
#'
#'
get_project_task_detail <-
get_current_project_task_detail <-
function(project_name = get_context_project(),
api_token = get_toggl_api_token(),
workspace_id = get_workspace_id(),
since = Sys.Date() - lubridate::years(1),
until = Sys.Date(),
humain = TRUE) {
out <-
gd <-
get_dashboard(
api_token = api_token,
workspace_id = workspace_id,
since = since,
until = until
)$tache[[project_name]]
)
if (isTRUE(project_name %in% names(gd$tache))) {
info <- gd$tache[[project_name]]
} else{
info <-
structure(
list(
title = character(0),
time = numeric(0),
cur = numeric(0),
sum = numeric(0),
rate = numeric(0),
local_start = character(0)
),
row.names = integer(0),
class = "data.frame"
)
}



description <- get_current(api_token = api_token)$description

if (!is.null(description)) {
if (description %in% out$title) {
out <- out %>%
if (description %in% info$title) {
info <- info %>%
mutate(time = case_when(
title == description ~
(time + get_current_duration(api_token = api_token)) %>% as.double()
,
TRUE ~ time %>% as.double()
))
} else {
out <- out %>% full_join(tribble(
info <- info %>% full_join(by = c("title", "time"),tribble(
~ title, ~ time,
description, get_current_duration(api_token = api_token) %>% as.double()

Expand All @@ -206,13 +225,13 @@ get_project_task_detail <-


}
if (humain) {
out <- out %>% to_humain()



if (humain & nrow(info)>0) {
info <- info %>% to_humain()
}
out
info
}

#' transforme time column into humain readable column
Expand Down
25 changes: 16 additions & 9 deletions R/put_project.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,31 @@ toggl_create_project <- function(
}


info <- list(active=active,
name = project_name ,
# client_name = "client",
is_private = FALSE,
project =
list(color = color,
active = active
)
)


if (client != "" & !is.null(client)){
info$client <- client
}

POST(

glue::glue("https://api.track.toggl.com/api/v9/workspaces/{workspace_id}/projects"),
verbose(),
authenticate(api_token,"api_token"),
encode="json",
body=toJSON(
list(active=active,
name = project_name ,
client_name = client,
is_private = FALSE,
project =
list(color = color,
active = active
)
),auto_unbox = TRUE)
info

,auto_unbox = TRUE)
) ->ll

ll %>% content()%>% .$id -> id
Expand Down
8 changes: 4 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ install.packages("togglr")

### From Github
```R
if (!requireNamespace("devtools")){install.packages("devtools")}
devtools::install_github("ThinkR-open/togglr")
if (!requireNamespace("remotes")){install.packages("remotes")}
remotes::install_github("ThinkR-open/togglr")
```



## Set toggl Api token

Go on toggl.com website : `https://track.toggl.com/profile`
Go on toogl.com website : `https://track.toggl.com/profile`

```{r}
togglr::open_toggl_website_profile()
Expand Down Expand Up @@ -95,7 +95,7 @@ toggl_stop()

```{r}
get_current_duration()# the current track
get_project_task_detail()# all the project (including the current track)
get_current_project_task_detail()# (including the current track)
```

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6776e15

Please sign in to comment.