This repository has been archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiser.html
291 lines (256 loc) · 10.9 KB
/
wiser.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WAIZ</title>
<!-- CSS -->
<!--fonts-->
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono:400,500|Roboto+Slab:400,700|Roboto:400,500" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<!--fonts-->
<link rel="stylesheet" href="./css/mini.css">
<link rel="stylesheet" href="./css/main.css">
<!-- CSS -->
<!-- JS -->
<script type="text/javascript" src="./node_modules/pouchdb/dist/pouchdb.js"></script>
<script type="text/javascript" src="./node_modules/pouchdb/dist/pouchdb.find.js"></script>
<script type="text/javascript" src="./node_modules/handlebars/dist/handlebars.js"></script>
<script type="text/javascript" src="./js/main.js"></script>
<!-- JS -->
</head>
<body>
<!--BEGIN: Title Section-->
<div class='row'>
<!--BEGIN: Project Name-->
<div class="col-lg-2 col-md-4 col-sm-10">
<h4 class="hidden-sm">
<a href='index.html'>
<< WAIZ
</a>
<span class="hidden-md">
<small>(That's how wise is pronounced)</small>
<small>Project Status: MVP</small>
</span>
</h4>
<!--BEGIN: REAL DEAL - the dimension important for the user-->
<div class="col-sm-10">
<h4 class="hidden-md hidden-lg">
<a href='index.html'><<</a>
</h4>
<div id='dimensions'>
<!--HANDLEBARS-->
</div>
</div>
<!--END: Data Dimensions or simply the filters-->
</div>
<!--END: Project Name-->
<!--BEGIN: Query Results-->
<div id='title' class="col-lg-10 col-md-10 col-sm-12">
<!-- HANDLEBARS -->
<!-- title-template -->
</div>
<!--END: Query Results-->
</div>
<!--END: Title Section-->
<div id='content'>
<!--BEGIN: RESULT: Would be in for loop-->
<!--HANDLEBARS-->
<!-- result-template -->
<!--END: RESULT: end loop-->
</div>
</body>
<footer>
<p>
<h4>
You think you can do one better?
</h4>
<form>
<label for='summary_link'>A better link</label>
<input type='text' name='summary_link'>
<label for='why_summary_link'>Why?</label>
<input type='text' name='why_summary_link'>
<input type="submit" name="submit" title="submit">
</form>
</p>
</footer>
<script id="dimensions-template" type="text/x-handlebars-template">
{{display}}
<br>
<select id="dimensions-select">
<option value="-1">*</option>
{{#each values}}
<option value="{{this}}">{{this}} {{../unit}}</option>
{{/each}}
</select>
</script>
<script id="title-template" type="text/x-handlebars-template">
<div class="row">
<!--BEGIN: Query Topic-->
<div class="col-sm-6">
<h2>
<a href='{{data.wisdom.wisdom.metadata.stores.goodreads}}' target="_blank" >
{{data.wisdom.wisdom.title}}
</a>
<small>{{data.wisdom.wisdom.sub-title}}</small>
</h2>
</div>
<!--END: Query Topic-->
<!--BEGIN: Topic Author-->
<div class="col-sm-6">
<h2>
<a href='{{data.wisdom.author.social.twitter.link}}' target="_blank" >
@{{data.wisdom.author.social.twitter.username}}
</a>
<small>{{data.wisdom.author.name}}</small>
</h2>
</div>
<!--END: Topic Author-->
<!--BEGIN: Main Idea-->
<p>
{{data.wisdom.wisdom.metadata.summary}}
</p>
<!--END: Main Idea-->
</div>
</script>
<script id="result-template" type="text/x-handlebars-template">
<!--BEGIN: SAMPLE RESULT 1-->
{{#each data.wisdom.wisdom.metadata.wisdom}}
<div class='result row'>
<!--BEGIN: Content-->
<!--BEGIN: Author & source: Always a priority -->
<!--BEGIN: AUTHOR-->
<div class="col-lg-2 col-md-2 col-sm-12">
<h5>
<a href='{{author.social.twitter.link}}'>@{{author.social.twitter.username}}</a>
<small>{{author.name}}</small>
</h5>
</span>
</div>
<!--END: AUTHOR-->
<!--BEGIN: Main Highlight for the content-->
<div class="col-lg-10 col-md-10 col-sm-12">
<p>
{{summary}}
</p>
</div>
<!--END: Main Highlight for the content-->
<!-- BEGIN: Reader's Reaction-->
<div class='col-lg-12 col-md-12 col-sm-12 reaction'>
<span>
<a href='{{link}}'><i class="fas fa-link"></i></a>
</span>
<span><i class="far fa-heart featureunavailable text-red"></i></span>
<span><i class="far fa-thumbs-down featureunavailable text-orange"></i></span>
</div>
<!-- END: Reader's Reaction-->
<!--END: Author & source: Always a priority -->
<!--BEGIN: Content Metadata -->
<div class="row dimension">
<span><b>Dimensions:</b></span>
{{#each dimensions}}
<span class='shaded {{#if primary}}primary{{/if}}'>{{display}}: {{value}} {{unit}}</span>
{{/each}}
</div>
<!--END: Content Metadata -->
<!--END: Content-->
</div>
{{/each}}
<!--END: SAMPLE RESULT 1-->
</script>
<script type="text/javascript">
function set_title(context) {
var source = document.getElementById("title-template").innerHTML;
var template = Handlebars.compile(source);
var html = template(context);
// TITLE
document.getElementById('title').insertAdjacentHTML('beforeend', html);
}
function set_results(context) {
var source = document.getElementById("result-template").innerHTML;
var template = Handlebars.compile(source);
var html = template(context);
// RESULTS
document.getElementById('content').innerHTML = "";
document.getElementById('content').insertAdjacentHTML('beforeend', html);
}
function set_dimensions(context) {
var display = null;
var key = null;
var unit = null;
var values = [];
// TODO: Improve this mess - probably by restructring the data
for(var i=0; i<context.data.wisdom.wisdom.metadata.wisdom.length; i++) {
var dims = context.data.wisdom.wisdom.metadata.wisdom[i].dimensions;
for (var j=0; j<dims.length; j++) {
if (dims[j].primary == true) {
display = dims[j].display;
key = dims[j].key;
unit = dims[j].unit;
if (!(values.includes(dims[j].value))) {
values.push(dims[j].value);
}
}
}
}
var context = {
display: display,
values: values.sort(),
key: key,
unit: unit
}
var source = document.getElementById("dimensions-template").innerHTML;
var template = Handlebars.compile(source);
var html = template(context);
// TITLE
document.getElementById('dimensions').insertAdjacentHTML('beforeend', html);
}
// what happens on filter change? DB query? - no, we have the data available
// TODO - with pagination enabled - query the database
function on_dimension_change() {
var x = document.getElementById("dimensions-select");
// x.value = x.value.toUpperCase();
var new_context = JSON.parse(JSON.stringify(filtered_results));
var chaged_context = [];
var filter_these = new_context.data.wisdom.wisdom.metadata.wisdom;
// TODO: Improve this mess - probably by restructring the data
if (x.value != -1) {
for(var i=0; i<filter_these.length; i++) {
var dims = filter_these[i].dimensions;
for (var j=0; j<dims.length; j++) {
if ( (dims[j].primary == true) && (dims[j].value <= x.value) ) {
chaged_context.push(filter_these[i]);
}
}
}
new_context.data.wisdom.wisdom.metadata.wisdom = chaged_context;
} else {
new_context = JSON.parse(JSON.stringify(filtered_results));
}
set_results(new_context);
}
// draw GUI
function set_templates(result_set) {
var context = result_set[0]; // get only the first result
filtered_results = context; // data to play with
set_title(context);
set_results(context);
set_dimensions(context);
document.getElementById("dimensions-select").addEventListener("change", on_dimension_change);
}
</script>
<script type="text/javascript">
var db = new PouchDB('wise');
var remoteCouch = false;
var filtered_results;
id = getParameterByName('id');
rev = getParameterByName('rev');
filterWisdomById(
db,
{
id: id,
rev: rev
},
set_templates
);
</script>
</html>