Skip to content

Commit 41f65e6

Browse files
committed
Minor Fixes
- Updated Copy button - Added templates for seperating views (decoupling) - Made Textarea larger
1 parent 241842c commit 41f65e6

File tree

8 files changed

+196
-115
lines changed

8 files changed

+196
-115
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{% load staticfiles %}
2+
{% include "fork_github.html" %}
3+
4+
<!DOCTYPE html>
5+
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8">
9+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
10+
<meta name="viewport" content="width=device-width, initial-scale=1">
11+
<title>Shitty Code Share</title>
12+
<link rel="stylesheet" href="{% static 'css/normalize.css' %}">
13+
<link rel="stylesheet" href="{% static 'css/milligram.css' %}">
14+
15+
{% block css %}
16+
17+
{% endblock %}
18+
19+
</head>
20+
21+
<body>
22+
23+
<a href="{% url 'code_share:app_home'%}" style="color:inherit;">
24+
<h3 style="padding-top:10px; padding-bottom: 5px; padding-left:10px;">Shitty Code Share</h3>
25+
</a>
26+
27+
{% block body %}
28+
29+
{% endblock %}
30+
31+
32+
{% block scripts %}
33+
34+
{% endblock %}
35+
36+
37+
</body>
38+
39+
</html>
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{% extends "base.html" %}
2+
{% load staticfiles %}
3+
4+
5+
{% block css %}
6+
<link rel="stylesheet" href="{% static 'css/codeshare.css' %}">
7+
{% endblock %}
8+
9+
10+
{% block body %}
11+
12+
<div class="container">
13+
14+
{% if messages %}
15+
<ul class="messages">
16+
{% for message in messages %}
17+
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
18+
{% endfor %}
19+
</ul>
20+
{% endif %}
21+
22+
<button id="copy_button">Copy</button>
23+
<input type="url" id="link_box" style="float: right;">
24+
25+
<form action="." enctype="multipart/form-data" method="POST">
26+
{% csrf_token %}
27+
28+
{% if code_share.file_name %}
29+
<h4>File Name: {{code_share.file_name}}</h4>
30+
31+
{%endif%}
32+
33+
<textarea id="code_snippet" name="code_snippet">{{code_share.code}}</textarea><br>
34+
<input id="submit_edit" type="submit" value="edit">
35+
<br>
36+
<a href="{% url 'code_share:app_home'%}" >
37+
<div id="create">create new</div>
38+
</a><br>
39+
40+
</form>
41+
42+
<blockquote>
43+
<p><em>Share your shitty code here. nothing is necessary. Put code and submit.BAM.</em></p>
44+
</blockquote>
45+
46+
</div>
47+
48+
49+
{% endblock %}
50+
51+
52+
{% block scripts%}
53+
<script type="text/javascript" crossorigin="anonymous" src="{% static 'js/codeshare.js' %}"></script>
54+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,41 @@
1+
{% extends "base.html" %}
12
{% load staticfiles %}
23

34

4-
<!DOCTYPE html>
5+
{% block css %}
6+
<link rel="stylesheet" href="{% static 'css/codeshare.css' %}">
7+
{% endblock %}
58

6-
<html lang="en">
7-
<head>
8-
<meta charset="utf-8">
9-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
10-
<meta name="viewport" content="width=device-width, initial-scale=1">
11-
<title>Shitty Code Share</title>
12-
<link rel="stylelesheet" href="//fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
13-
<link rel="stylesheet" href="{% static 'css/normalize.css' %}">
14-
<link rel="stylesheet" href="{% static 'css/milligram.css' %}">
15-
<link rel="stylesheet" href="{% static 'css/codeshare.css' %}">
169

17-
</head>
18-
<body>
19-
<a href="{% url 'code_share:app_home'%}" style="color:inherit;">
20-
<h3 style="padding-top:10px; padding-bottom:20px; padding-left:10px;">Shitty Code Share</h3>
21-
</a>
10+
{% block body %}
2211

23-
<div class="container">
12+
<div class="container">
2413

25-
{% if messages %}
26-
<ul class="messages">
27-
{% for message in messages %}
28-
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
29-
{% endfor %}
30-
</ul>
31-
{% endif %}
14+
{% if messages %}
15+
<ul class="messages">
16+
{% for message in messages %}
17+
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
18+
{% endfor %}
19+
</ul>
20+
{% endif %}
3221

33-
<form action="." enctype="multipart/form-data" method="POST">
34-
{% csrf_token %}
35-
36-
{% if filename %}
37-
{% if code_share.file_name %}
38-
File Name:<h4>{{code_share.file_name}}</h4>
39-
40-
{%else%}
41-
unique Id:<h4>{{code_share.hash_value}}</h4>
42-
43-
{%endif%}
44-
<p id="copy_button">Copy</p>
45-
<input type="text" id="link_box">
46-
47-
<textarea id="code_snippet" name="code_snippet">{{code_share.code}}</textarea><br>
48-
<input id="submit_edit" type="submit" value="edit">
49-
<br>
50-
<a href="{% url 'code_share:app_home'%}" >
51-
<div id="create">create new</div>
52-
</a><br>
53-
54-
{%else%}
55-
<input type="text" id="file_field" name="file_name" placeholder="File Name" value="{{code_share.file_name}}">
56-
57-
<textarea id="code_snippet" name="code_snippet" placeholder="Code Snippet">{{code_share.code}}</textarea><br>
58-
<input id="submit_new" type="submit" value="submit" ><br>
59-
60-
{%endif%}
61-
62-
</form>
63-
64-
<blockquote>
65-
<p><em>Share your shitty code here. nothing is necessary. Put code and submit.BAM.</em></p>
66-
</blockquote>
22+
<form action="." enctype="multipart/form-data" method="POST">
23+
{% csrf_token %}
24+
25+
<input type="text" id="file_field" name="file_name" placeholder="File Name" value="{{code_share.file_name}}">
26+
<textarea id="code_snippet" name="code_snippet" placeholder="Code Snippet">{{code_share.code}}</textarea><br>
27+
<input id="submit_new" type="submit" value="submit" ><br>
28+
29+
</form>
6730

68-
</div>
31+
<blockquote>
32+
<p><em>Share your shitty code here. nothing is necessary. Put code and submit.BAM.</em></p>
33+
</blockquote>
34+
</div>
35+
36+
{% endblock %}
6937

70-
{% include "fork_github.html" %}
71-
<script type="text/javascript" crossorigin="anonymous" src="{% static 'js/codeshare.js' %}"></script>
72-
</body>
7338

74-
</html>
75-
39+
{% block scripts%}
40+
<script type="text/javascript" crossorigin="anonymous" src="{% static 'js/codeshare.js' %}"></script>
41+
{% endblock %}

code_share/app_code_share/views.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ def view_by_hash(request, hash_id):
7070

7171
if request.method == 'GET':
7272
code_share = CodeShare.objects.get(hash_value=hash_id)
73-
context = {'code_share': code_share, "filename": "yes"}
74-
return render(request, 'app_code_share/homepage.html', context)
73+
return render(request, 'app_code_share/code_view.html', {'code_share': code_share})
7574

7675
if request.method == 'POST':
7776
code_share = request.POST.get('code_snippet')

code_share/manage.py

100755100644
File mode changed.

code_share/static/css/codeshare.css

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
textarea{
2-
width:95%;
3-
}
41
#copy_button{
5-
border:1px solid;
6-
display: inline;
7-
cursor: pointer;
8-
padding: 7px;
9-
}
2+
float: right;
3+
margin: 0 0 0px 5px;
4+
border: 2px solid;
5+
border-radius: 7px;
6+
}

code_share/static/css/milligram.css

+19-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

code_share/static/js/codeshare.js

+47-37
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,56 @@
11
// disables the submit button upon document ready
22
window.onload = function() {
3-
var submit_new = document.getElementById("submit_new");
4-
var submit_edit = document.getElementById("submit_edit");
5-
var code_snippet = document.getElementById("code_snippet");
6-
var button = document.getElementById("copy_button");
7-
var url = document.getElementById("link_box");
8-
if(url){
3+
var submit_new = document.getElementById("submit_new");
4+
var submit_edit = document.getElementById("submit_edit");
5+
var code_snippet = document.getElementById("code_snippet");
6+
var button = document.getElementById("copy_button");
7+
var url = document.getElementById("link_box");
8+
9+
if(url){
910
url.value = window.location.href;
10-
}
11-
if (submit_new) {
12-
submit_new.disabled = true;
13-
}
14-
if (submit_edit) {
15-
submit_edit.disabled = true;
16-
}
17-
/*
18-
EventListener on Keyup on the textarea(code_snippet) calls this method.
19-
Content in the textarea is checked and according to that
20-
submit buttons are disabled/enabled.
21-
*/
22-
console.log(submit_new, submit_edit, code_snippet)
23-
code_snippet.addEventListener("keyup", function() {
24-
if (code_snippet.value != "") {
25-
if (submit_new) {
26-
submit_new.disabled = false;
27-
}
28-
if (submit_edit) {
29-
submit_edit.disabled = false;
30-
}
31-
} else {
32-
if (submit_new) {
33-
submit_new.disabled = true;
34-
}
35-
if (submit_edit) {
36-
submit_edit.disabled = true;
37-
}
11+
}
12+
13+
if (submit_new) {
14+
submit_new.disabled = true;
15+
}
16+
17+
if (submit_edit) {
18+
submit_edit.disabled = true;
19+
}
20+
21+
/*
22+
EventListener on Keyup on the textarea(code_snippet) calls this method.
23+
Content in the textarea is checked and according to that
24+
submit buttons are disabled/enabled.
25+
*/
26+
27+
code_snippet.addEventListener("keyup", function() {
28+
if (code_snippet.value != "") {
29+
30+
if (submit_new) {
31+
submit_new.disabled = false;
32+
}
33+
34+
if (submit_edit) {
35+
submit_edit.disabled = false;
3836
}
39-
});
37+
}
38+
else {
39+
40+
if (submit_new) {
41+
submit_new.disabled = true;
42+
}
43+
44+
if (submit_edit) {
45+
submit_edit.disabled = true;
46+
}
47+
}
48+
});
4049

4150

42-
/*on click of copy button it copies current url*/
43-
if(button) {
51+
/*on click of copy button it copies current url*/
52+
if(button) {
53+
4454
button.addEventListener('click', function() {
4555
url.select();
4656
document.execCommand("copy");

0 commit comments

Comments
 (0)