forked from PWD-MARS/shiny-fieldwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.R
More file actions
65 lines (51 loc) · 2.13 KB
/
Copy pathutils.R
File metadata and controls
65 lines (51 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
### This script is a centralized location for utility functions that will be
### used in multiple modules within the Fieldwork Application. It was created
### to contain the function used to write the log of INSERT and UPDATE queries
### sent to the MARS database created by Brian Cruice in 8/2024. It should be
### used as a place to store similar functions moving forward. Several functions
### originally housed in app.R have been moved to this page
#Not in logical
`%!in%` <- Negate(`%in%`)
#replace special characters with friendlier characters
special_char_replace <- function(note){
note_fix <- note %>%
str_replace_all(c("•" = "-", "ï‚§" = "-", "“" = '"', '”' = '"'))
return(note_fix)
}
#function to highlight datatables based on NAs/blanks
newstyleEqual <- function (levels, values, default = NULL)
{
n = length(levels)
if (n != length(values))
stop("length(levels) must be equal to length(values)")
if (!is.null(default) && (!is.character(default) || length(default) !=
1))
stop("default must be null or a string")
if (n == 0)
return("''")
levels = DT:::jsValues(levels)
values = DT:::jsValues(values)
js = ""
for (i in seq_len(n)) {
if(levels[i]=="\"NA\""){ # needed because jsValues converts NA to a string
js = paste0(js, sprintf("isNaN(parseFloat(value)) ? %s : ",
values[i]))
}else{
js = paste0(js, sprintf("value == %s ? %s : ", levels[i],
values[i]))
}
}
default = if (is.null(default))
"value"
else jsValues(default)
DT::JS(paste0(js, default))
}
# function to send log of the INSERT/UPDATE queries run within the app
insert.query.log <- function(poolConn, input_query, tab_name, session){
log_query <- paste0("INSERT INTO log.tbl_fieldwork_app_queries (username, query_text, tab, date_time_sent)
VALUES ('", session$user,
"', '",gsub(input_query,pattern="'",replacement="''"),
"', '", tab_name, "', '",
Sys.time(),"')")
odbc::dbGetQuery(poolConn, log_query)
}