forked from tedneward/ArchKatasCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkata.html
157 lines (144 loc) · 5.29 KB
/
kata.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Architectural Katas: Practicing Architecture</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<!-- Le styles -->
<link href="./css/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px;
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
</style>
<link href="./css/bootstrap-responsive.css" rel="stylesheet">
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">Architectural Katas</a>
<div class="nav-collapse">
<ul class="nav">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="rules.html">Rules</a></li>
<li><a href="contribute.html">Contribute</a></li>
<li><a href="invite.html">Invite</a></li>
<li><a href="lead.html">Lead</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span9">
<div class="hero-unit">
<h2>Your Architectural Kata is...</h2>
<h1 id="kata-title"></h1>
<p id="kata-text"></p>
<p />
<p id="bookmark-url"></p>
</div>
</div><!--/span-->
</div><!--/row-->
<hr>
<footer>
<p>© Neward & Associates 2012</p>
</footer>
</div><!--/.fluid-container-->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="./js/jquery.js"></script>
<script src="./js/bootstrap-collapse.js"></script>
<script src="./js/urlvars.js"></script>
<script>
// Github REST API has one endpoint I care about: getContents
// (documented at https://developer.github.com/v3/repos/contents/)
var githubSrcBase = 'https://api.github.com/repos/tedneward/ArchKatas/contents/'
// These functions require definition before use because browser
var fetchKata = function(filename) {
console.log('fetchKata(', filename, ')');
fetch(githubSrcBase + filename, {
headers: {
// must send media type "application/vnd.github.VERSION.raw"
// to get contents in non-Base64-encoded format; while I could
// convert it, why bother if GH can give it to me raw?
Accept: "application/vnd.github.v3.raw"
}
})
.then(response => response.json())
.then(json => {
console.log("fetchKata", json);
$('#kata-title').text(json.title);
json.description.forEach( (item) => {
$('#kata-text').append('<p>' + item + '</p>');
});
$('#bookmark-url').html('<a target="_blank" href="kata.html?kata=' + filename + '">Bookmark or click this to save your kata choice</a>');
});
};
var fetchKataList = function(listFn) {
console.log('Fetching all katas...');
fetch(githubSrcBase)
.then(response => response.json())
.then(json => {
var jsons = json.filter(
(item) => (item.type === 'file') &&
(item.name.endsWith('.json')));
listFn(jsons);
});
};
var kataname = $.getUrlVar('kata');
if (kataname === 'all') {
// Fetch a full list of katas from the repo
// and put each one, linked, in a display
fetchKataList(function(jsons) {
$('#kata-title').text("All Katas")
jsons.forEach( (kata) => {
console.log("Building out link for ", kata);
let file = kata.path;
let name = kata.path.substring(0, kata.path.length - (".json".length));
$('#kata-text').append('<p><a href="kata.html?kata=' + file + '">' + name + '</a></p>');
});
});
}
else if (kataname !== undefined) {
// We want a specific kata; we assume it exists already
fetchKata(kataname);
}
else {
// Fetch a full list of katas from the repo
// and pick one at random to fetch individually
fetchKataList(function(jsons) {
// Pick one at random
var getRandomInt = function(max) {
return Math.floor(Math.random() * Math.floor(max));
};
console.log("Choosing kata from among", jsons.length, "choices....");
var choice = getRandomInt(jsons.length);
console.log("Chose", choice, "! That's", jsons[choice].name);
fetchKata(jsons[choice].name);
});
}
</script>
</body>
</html>