Skip to content

Commit 2f486f1

Browse files
committed
Adding in app code
1 parent 2885b7e commit 2f486f1

File tree

6 files changed

+222
-0
lines changed

6 files changed

+222
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.Ruserdata

app.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
library(shiny)
2+
library(shinyAce)
3+
library(shinyjs)
4+
5+
source("mods/mod-commitq1.R")
6+
source("mods/mod-commitq2.R")
7+
ui <- fluidPage(
8+
includeCSS("www/style.css"),
9+
shinyjs::useShinyjs(),
10+
navbarPage("Git in theory",
11+
tabPanel("Commiting",
12+
tabsetPanel(type = "tabs",
13+
tabPanel("Q1",
14+
commitq1_ui("q1")),
15+
tabPanel("Q2",
16+
commitq2_ui("q2"))
17+
)
18+
19+
),
20+
tabPanel("Making Branches"
21+
),
22+
tabPanel("Merging Branches")
23+
)
24+
)
25+
26+
27+
server <- function(input, output, session) {
28+
commitq1_server("q1")
29+
commitq2_server("q2")
30+
}
31+
32+
shinyApp(ui = ui, server = server)

git-app.Rproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX

mods/mod-commitq1.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
commitq1_ui <- function(id){
2+
ns <- NS(id)
3+
tagList(
4+
textInput(ns("input_text"), "Enter Commit Message:"),
5+
actionButton(ns("commit_btn"), "Commit"),
6+
actionButton(ns("undo_btn"), "Undo"),
7+
div(id = ns("commit_ls"), class = "branch")
8+
)
9+
}
10+
11+
commitq1_server <- function(id){
12+
moduleServer(
13+
id,
14+
function(input, output, session){
15+
ns <- session$ns
16+
17+
observeEvent(input$commit_btn, {
18+
if (input$input_text != "") {
19+
insertUI(
20+
selector = paste0("#", ns("commit_ls")),
21+
where = "beforeEnd",
22+
ui = div(
23+
class = "dot",
24+
message = input$input_text
25+
)
26+
)
27+
updateTextInput(session, "input_text", value = "")
28+
}
29+
})
30+
31+
observeEvent(input$undo_btn, {
32+
removeUI(selector = ".dot")
33+
})
34+
35+
}
36+
)
37+
}

mods/mod-commitq2.R

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
init <- 'print("hello [My Name]")'
2+
3+
commitq2_ui <- function(id){
4+
ns <- NS(id)
5+
splitLayout(
6+
cellWidths = c("50%", "50%"),
7+
aceEditor(ns("code_box"), "Code Box", value = init),
8+
column(
9+
width = 12,
10+
textInput(ns("commit_msg"), "Commit Message", ""),
11+
actionButton(ns("commit_btn"), "Commit", width = "100%"),
12+
div(id = ns("commit_ls"), class = "branch",
13+
div(
14+
class = "dot",
15+
message = "My first commit"
16+
)
17+
18+
)
19+
)
20+
)
21+
}
22+
23+
commitq2_server <- function(id){
24+
moduleServer(
25+
id,
26+
function(input, output, session){
27+
ns <- session$ns
28+
29+
observeEvent(input$code_box, {
30+
if(input$code_box != init){
31+
shinyjs::enable("commit_msg")
32+
} else {
33+
shinyjs::disable("commit_msg")
34+
shinyjs::disable("commit_btn")
35+
}
36+
})
37+
38+
39+
observeEvent(input$commit_msg, {
40+
if (input$commit_msg != "") {
41+
shinyjs::enable("commit_btn")
42+
} else {
43+
shinyjs::disable("commit_btn")
44+
}
45+
})
46+
47+
observeEvent(input$commit_btn, {
48+
insertUI(
49+
selector = paste0("#", ns("commit_ls")),
50+
where = "beforeEnd",
51+
ui = div(
52+
class = "dot",
53+
message = input$commit_msg
54+
)
55+
)
56+
57+
updateTextInput(session, "commit_msg", value = "")
58+
})
59+
60+
61+
}
62+
)
63+
}

www/style.css

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
:root{
2+
--radius: 5em;
3+
--radius2 : 2.5em; /*should be 1/2 radius*/
4+
}
5+
6+
body{
7+
background-color: #f2e5e1;
8+
}
9+
10+
.dot {
11+
display: inline-block;
12+
width: var(--radius);
13+
height: var(--radius);
14+
border-radius: 50%;
15+
background-color: #337535;
16+
margin: var(--radius2);
17+
position: relative;
18+
}
19+
20+
.dot:before,
21+
.dot:after
22+
{
23+
content:'';
24+
width:var(--radius);
25+
border-bottom:3px solid;
26+
position:absolute;
27+
top:50%;
28+
color: #49392C;
29+
}
30+
31+
.dot:before {
32+
content: attr(message);
33+
position:absolute;
34+
35+
/* vertically center */
36+
top:50%;
37+
transform:translateY(-50%);
38+
39+
/* move to right */
40+
left:100%;
41+
margin-left:15px; /* and add a small left margin */
42+
43+
z-index: 1; /* Add this line to ensure tooltip appears above other dots */
44+
45+
/* basic styles */
46+
width:200px;
47+
padding:10px;
48+
border-radius:10px;
49+
background:#000;
50+
color: #fff;
51+
text-align:center;
52+
53+
display:none; /* hide by default */
54+
}
55+
56+
.dot:hover:before {
57+
display:block;
58+
}
59+
60+
:after {
61+
left:100%;
62+
}
63+
:before {
64+
right:100%;
65+
}
66+
67+
.dot:last-of-type:after {
68+
display:none;
69+
}
70+
71+
.branch {
72+
white-space:nowrap;
73+
}

0 commit comments

Comments
 (0)