Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
workbook
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs205
workbook
Commits
7bbabc00
Commit
7bbabc00
authored
8 years ago
by
Wade Fagen-Ulmschneider (waf)
Browse files
Options
Downloads
Patches
Plain Diff
Add "New Discovery" feature
parent
dda20d3c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
static/templates/mainPage.html
+74
-19
74 additions, 19 deletions
static/templates/mainPage.html
workbook.py
+19
-1
19 additions, 1 deletion
workbook.py
workbook_utilities.py
+27
-0
27 additions, 0 deletions
workbook_utilities.py
with
120 additions
and
20 deletions
static/templates/mainPage.html
+
74
−
19
View file @
7bbabc00
{% extends "static/templates/base.html" %}
{% block content %}
<script>
var
updateNewProjectForm
=
function
()
{
// Read project name, return if empty
var
projectName
=
$
(
"
#inputProjectName
"
).
val
();
if
(
projectName
==
""
)
{
$
(
"
#dirName
"
).
html
(
"
—
"
);
$
(
"
#hiddenDirName
"
).
val
(
""
);
return
;
}
// Read project type, fix it for directory type
var
projectType
=
$
(
"
#selectProjectType option:selected
"
).
val
();
if
(
projectType
==
"
Personal
"
)
{
projectType
=
"
per
"
;
}
else
if
(
projectType
==
"
Demo
"
)
{
projectType
=
"
demo
"
;
}
else
if
(
projectType
==
"
Experience
"
)
{
projectType
=
"
exp
"
;
}
else
if
(
projectType
==
"
Project
"
)
{
projectType
=
"
proj
"
;
}
// Create the directory name
var
dirName
=
projectType
+
"
_
"
+
projectName
;
// Remove spaces
dirName
=
dirName
.
replace
(
/
\s
+/g
,
''
);
// Remove any non-words
dirName
=
dirName
.
replace
(
/
[^\w]
/gi
,
''
)
// Update HTML
$
(
"
#dirName
"
).
html
(
dirName
);
$
(
"
#hiddenDirName
"
).
val
(
dirName
);
};
</script>
<div
class=
"row"
>
<div
class=
"col-sm-4"
>
<h3>
Add New Project
</h3>
<form
class=
"form-horizontal"
>
<h3>
Add New Discovery
</h3>
<p>
<i>
This form simply populates a new directory with a base set of files for
a CS 205
"
Discovery
"
. You can use it to quickly set up a
new directory for working on a new discovery.
</i>
</p>
<hr>
<form
class=
"form-horizontal"
action=
"/"
method=
"post"
>
{% if error %}
<div
class=
"alert alert-danger"
role=
"alert"
>
{{error | safe}}
</div>
{% endif %}
{% if success %}
<div
class=
"alert alert-success"
role=
"alert"
>
{{success | safe}}
</div>
{% endif %}
<div
class=
"form-group"
>
<label
for=
"inputProjectName"
class=
"col-sm-2 control-label"
>
Name:
</label>
<div
class=
"col-sm-10"
>
<input
type=
"text"
class=
"form-control"
id=
"inputProjectName"
placeholder=
"Project Name"
>
<input
oninput=
"updateNewProjectForm()"
type=
"text"
class=
"form-control"
name=
"projectName"
id=
"inputProjectName"
placeholder=
"Project Name"
>
</div>
</div>
<div
class=
"form-group"
>
<label
for=
"
inpu
tProject
Nam
e"
class=
"col-sm-2 control-label"
>
Type:
</label>
<label
for=
"
selec
tProject
Typ
e"
class=
"col-sm-2 control-label"
>
Type:
</label>
<div
class=
"col-sm-10"
>
<select
class=
"form-control"
>
<option>
Personal
</option>
<option>
Demo
</option>
<option>
Experience
</option>
<option>
Project
</option>
<select
class=
"form-control"
id=
"selectProjectType"
name=
"projectType"
onchange=
"updateNewProjectForm()"
>
<option
value=
"Personal"
>
Personal
</option>
<option
value=
"Demo"
>
Demo
</option>
<option
value=
"Experience"
>
Experience
</option>
<option
value=
"Project"
>
Project
</option>
</select>
</div>
</div>
...
...
@@ -27,24 +79,28 @@
<b>
Dir.:
</b>
</div>
<div
class=
"col-sm-10"
>
<tt
class=
"dirName"
>
#dirName
</tt>
<tt
id=
"dirName"
>
—
</tt>
<input
type=
"hidden"
id=
"hiddenDirName"
name=
"dirName"
value=
""
>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"col-sm-6 col-sm-push-6"
>
<button
type=
"submit"
class=
"btn btn-primary form-control"
>
<button
type=
"submit"
class=
"btn btn-primary form-control"
id=
"buttonSubmit"
>
<span
class=
"glyphicon glyphicon-plus-sign"
></span>
Create Project
</button>
</div>
</div>
</form>
<hr
/>
This form does the same thing as creating a directory and creating
<tt>
project.json
</tt>
,
<tt>
web
</tt>
,
<tt>
py
</tt>
, and
<tt>
res
</tt>
directories.
</div>
<div
class=
"col-sm-4"
>
<h3>
Personal
</h3>
<ul>
{% for item in navigation.personal|sort(attribute="index") %}
<li><a
href=
"/{{item.dir}}/"
>
{{item.title}}
</a></li>
{% endfor %}
</ul>
<hr>
<h3>
Demos
</h3>
<ul>
{% for item in navigation.demos|sort(attribute="index") %}
...
...
@@ -59,8 +115,7 @@
<li><a
href=
"/{{item.dir}}/"
>
{{item.title}}
</a></li>
{% endfor %}
</ul>
</div>
<div
class=
"col-sm-4"
>
<hr>
<h3>
Projects
</h3>
<ul>
{% for item in navigation.projects|sort(attribute="index") %}
...
...
This diff is collapsed.
Click to expand it.
workbook.py
+
19
−
1
View file @
7bbabc00
...
...
@@ -4,7 +4,7 @@ import logging
logger
=
logging
.
getLogger
(
"
workbook
"
)
# helper functions
from
workbook_utilities
import
run_compute_py
,
read_project_json
,
construct_navigation
,
read_metadata_json
from
workbook_utilities
import
run_compute_py
,
read_project_json
,
construct_navigation
,
read_metadata_json
,
create_new_dir
# flask
from
flask
import
Flask
,
render_template
,
jsonify
,
send_file
,
send_from_directory
,
request
...
...
@@ -30,6 +30,22 @@ app.logger.setLevel(logging.ERROR)
#
# Route the base URL to the main page
#
@app.route
(
'
/
'
,
methods
=
[
"
POST
"
])
def
home_createDir
():
logger
.
info
(
"
Processing index POST...
"
)
error
=
None
success
=
None
newDirName
=
request
.
form
[
"
dirName
"
]
if
os
.
path
.
isdir
(
newDirName
):
error
=
"
Directory <b>
"
+
newDirName
+
"
</b> already exists!
"
else
:
create_new_dir
(
newDirName
,
request
.
form
[
"
projectName
"
],
request
.
form
[
"
projectType
"
])
success
=
"
New directory <b>
"
+
newDirName
+
"
</b> created!
"
navigation
=
construct_navigation
()
return
render_template
(
'
static/templates/mainPage.html
'
,
navigation
=
navigation
,
error
=
error
,
success
=
success
)
@app.route
(
'
/
'
)
def
home
():
navigation
=
construct_navigation
()
...
...
@@ -81,6 +97,8 @@ def fetchExercise(projectDir):
# Get the project info
projectInfo
=
read_project_json
(
projectDir
)
if
projectInfo
==
None
:
return
"
No project.json found.
"
metadata
=
read_metadata_json
(
projectDir
)
# Figure out what to do based on the value of `show`
...
...
This diff is collapsed.
Click to expand it.
workbook_utilities.py
+
27
−
0
View file @
7bbabc00
...
...
@@ -7,6 +7,29 @@ logger = logging.getLogger("workbook")
# save the starting cwd
basecwd
=
os
.
getcwd
()
def
create_new_dir
(
newDirName
,
projectName
,
projectType
):
import
datetime
import
shutil
# copy files
os
.
chdir
(
basecwd
)
shutil
.
copytree
(
"
static/newDirFiles
"
,
newDirName
)
# replace project.json with accurate info
with
open
(
os
.
path
.
join
(
basecwd
,
newDirName
,
"
project.json
"
)
)
as
f
:
file_str
=
f
.
read
()
file_str
=
file_str
.
replace
(
"
{{TITLE}}
"
,
projectName
)
file_str
=
file_str
.
replace
(
"
{{TYPE}}
"
,
projectType
)
d
=
datetime
.
date
.
today
()
file_str
=
file_str
.
replace
(
"
{{INDEX}}
"
,
d
.
strftime
(
"
%Y%m%d
"
))
with
open
(
os
.
path
.
join
(
basecwd
,
newDirName
,
"
project.json
"
),
"
w
"
)
as
f
:
f
.
write
(
file_str
)
def
load_src
(
name
,
fpath
):
logger
.
info
(
"
-:Loading Python script:%s
"
,
fpath
)
...
...
@@ -33,6 +56,10 @@ def read_project_json(dir, project_data = {}):
project_data
[
"
dir
"
]
=
dir
fileName
=
os
.
path
.
join
(
basecwd
,
dir
,
"
project.json
"
)
if
not
os
.
path
.
isfile
(
fileName
):
logger
.
debug
(
"
%s:No project.json
"
,
dir
)
return
None
logger
.
debug
(
"
%s:Reading project.json
"
,
dir
)
with
open
(
fileName
)
as
json_file
:
json_data
=
json
.
load
(
json_file
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment