-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
390 lines (314 loc) · 10.5 KB
/
index.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<html>
<head>
<link href="css/shop.css" rel="stylesheet">
<link href="css/jquery-ui.min.css" rel="stylesheet">
<script src="js/vue.js"></script>
<script src="js/vue-resource.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="https://simple-notification.mybluemix.net/sns-client.js"></script>
<script src="js/sample-data.js"></script>
<title>The Poster Shop | Simple Suite Service</title>
</head>
<body>
<header>
<div>
<h1><a href="#">the poster shop</a></h1>
</div>
</header>
<div id="shop">
<div class="toast">
<strong>Watch out!</strong> {{ notificationData }}
</div>
<section class="col search-wrapper" v-show="cards[currentCard].searchVisible && !cards[currentCard].backOfSite">
<form class="search" v-on:submit.prevent="search">
<label>Search</label>
<input type="text" name="title" v-model="title" id="title" placeholder="e.g. Misery or Brad Pitt" data-autocomplete>
<button type="submit">Search</button>
</form>
<form class="search" v-on:submit.prevent="advancedSearch" v-show="cards[currentCard].advancedSearchVisible">
<label>Advanced Search</label>
<input type="text" name="cast" v-model="cast" id="cast" placeholder="e.g. Brad Pitt" data-autocomplete>
<input type="text" name="year" v-model="year" id="year" placeholder="e.g. 1995" data-autocomplete>
<input type="text" name="genre" v-model="genre" id="genre" placeholder="e.g. Thriller" data-autocomplete>
<input type="text" name="director" v-model="director" id="director" placeholder="e.g. Quentin Tarantino" data-autocomplete>
<button type="button" v-on:click="formReset">Reset</button>
<button type="submit">Search</button>
</form>
<ul class="facets" v-show="cards[currentCard].facetsVisible">
<li v-show="facets.genre">
<span>Genre</span>
<ul class="genre-list" style="display:none">
<li v-on:click="setFacet('genre', genre)" v-for="count,genre in facets.genre">
<span>{{ genre }}</span> <span class="badge">{{ count }}</span>
</li>
</ul>
</li>
<li v-show="facets.year">
<span>Year</span>
<ul class="genre-list" style="display:none">
<li v-on:click="setFacet('year', year)" v-for="count,year in facets.year">
<span>{{ year }}</span> <span class="badge">{{ count }}</span>
</li>
</ul>
</li>
</ul>
</section>
<div class="shop-steps-wrapper">
<section class="col full-site-wrapper shop-wrapper" v-show="cards[currentCard].backOfSite">
<h1>How does this all work?</h1>
<div>
<img src="img/schematic.png">
</div>
</section>
<section class="col shop-wrapper" v-show="!cards[currentCard].backOfSite" v-bind:class="{ 'full-site-wrapper': !currentCard }">
<div v-show="movies.length > 0">
<h1>Welcome to the Poster Shop</h1>
<ul>
<li v-show="movies.length" v-for="movie in movies">
<h3 class="text-nowrap">{{ movie.title }}</h3>
<img v-on:click="moreDetails(movie)" v-bind:src="movie.poster" class="poster img-responsive">
</li>
</ul>
<modal v-bind:movieinfo="popup" v-if="showModal" @close="showModal = false"></modal>
</div>
<div v-show="movies.length == 0">
<h1 class="text-nowrap">There are no results for your search</h1>
</div>
</section>
<section class="col steps-wrapper" v-bind:class="{ 'no-search-steps-wrapper': !currentCard || cards[currentCard].backOfSite }">
<div class="step">
<h1>{{ cards[currentCard].title }}</h1>
<p>{{ cards[currentCard].description1 }}</p>
<p>{{ cards[currentCard].description2 }}</p>
<p>{{ cards[currentCard].description3 }}</p>
<h3>{{ cards[currentCard].description4 }}</h3>
<div class="button-group">
<button v-if="currentCard < (cards.length - 1)" class="btn" v-on:click="nextCard">Next</button>
<button v-if="currentCard == (cards.length - 1)" class="btn" v-on:click="reset">Restart The Demo</button>
</div>
<p v-show="cards[currentCard].cta.url"><a target="_blank" :href="cards[currentCard].cta.url">{{ cards[currentCard].cta.label}}</a></p>
</div>
<div class="log" v-show="cards[currentCard].logsVisible">
<h1>Logging</h1>
<span v-for="log in logs">{{ JSON.stringify(log) }}</span>
</div>
</section>
</div>
</div>
</body>
<script type="text/x-template" id="modal-template">
<transition name="modal">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
<slot name="header">
<h4>{{ movieinfo.title || '' }} ({{ movieinfo.year || '' }})</h4>
</slot>
<button class="modal-default-button" @click="$emit('close')">×</button>
</div>
<div class="modal-body">
<slot name="body">
<h4>£{{ movieinfo.price || 0 }}</h4>
<p><b>Cast:</b> {{ movieinfo.cast && movieinfo.cast.join(", ") }}</p>
<p><b>Director:</b> {{ movieinfo.director || '' }}</p>
<p>{{ movieinfo.genre && movieinfo.genre.join(" / ") }}</p>
<div><img :src="movieinfo.poster"/></div>
</slot>
</div>
</div>
</div>
</div>
</transition>
</script>
<script type="text/javascript">
var sns = new SNSClient("shop", {
userData: {
type: "shop"
},
userQuery: {
type: "shop"
}
})
sns.on('notification', function() {
app.renderNotification()
});
Vue.component('modal', {
template: '#modal-template',
props: ['movieinfo']
})
var app = new Vue({
el: '#shop',
data: {
movies: sampleData,
facets: {},
title: "",
cast: "",
year: "",
director: "",
genre: "",
autocompletes: ["cast", "director", "year", "genre", "title"],
logs:[],
popup: {},
cards: cardData,
currentCard: 0,
realtimeMovies: [],
notificationData: null,
showModal: false
},
watch: {
currentCard: function(val, oldVal) {
var disabled = !this.cards[val].autoCompleteOn;
var oldDisabled = !this.cards[oldVal].autoCompleteOn;
var inputs = $("input[data-autocomplete]");
inputs.autocomplete( "option", "disabled", disabled );
if (disabled === false && disabled !== oldDisabled) {
inputs.animate({
backgroundColor: "#f00"
}, 1000, function() {
inputs.animate({
backgroundColor: "#fff"
}, 1000)
} );
}
}
},
created: function() {
$(document).ready(function() {
this.autocompletes.forEach(function(a) {
$("#"+a).autocomplete({
source: "https://autocomplete-discovery.mybluemix.net/api/movie_" + encodeURIComponent(a),
select: function( event, ui ) {
this[a] = ui.item.value;
this.log({
action: "autocomplete selected",
index: a,
value: ui.item.value
})
}.bind(this),
search: function(event, ui) {
this.log({
action: "autocomplete",
index: a,
term: this[a]
})
}.bind(this),
disabled: true
})
}.bind(this))
$('ul.facets > li > span')
.hover(function() {
if (!$(this).hasClass('active')) {
$('ul.facets > li > span.active')
.removeClass('active')
.siblings('ul.genre-list')
.hide(500);
$(this)
.addClass('active')
.siblings('ul.genre-list').show(750);
}
});
}.bind(this))
this.log({
action: "page load"
})
},
methods: {
search: function() {
if (!this.title) return;
this.$http.get('https://search-discovery.mybluemix.net/search?q=' + encodeURIComponent(this.title))
.then(function(response) {
this.movies = response.data.rows;
this.facets = response.data.counts;
if (this.realtimeMovies.length == 0) {
this.realtimeMovies = response.data.rows;
}
this.log({
action: "search",
query: this.title,
number_of_results: response.data.rows.length
})
})
},
advancedSearch: function() {
var q = [];
var fields = ["cast", "year", "director", "genre"];
if (this.title) {
q.push(this.title);
}
fields.forEach(function(f) {
if (this[f]) {
q.push(f + ':"' + this[f] + '"')
}
}.bind(this))
if (q.length === 0) return;
this.$http.get('https://search-discovery.mybluemix.net/search?q=' + encodeURIComponent(q.join(" AND ")))
.then(function(response) {
this.movies = response.data.rows;
this.facets = response.data.counts;
this.log({
action: "advanced search",
query: q.join(" AND "),
number_of_results: response.data.rows.length
})
})
},
log: function(log) {
if (typeof log !== "object") return;
log.timestamp = new Date().getTime()
this.logs.unshift(log);
},
moreDetails: function(movie) {
this.popup = movie;
this.showModal = true;
this.log({
action: "popup",
movie: movie.title
})
},
nextCard: function() {
this.currentCard++;
},
setFacet: function(facetName, value) {
this[facetName] = value;
this.advancedSearch();
},
renderNotification: function(n) {
if (this.cards[this.currentCard].notificationsOn === false) return;
if (this.realtimeMovies.length == 0) return;
var movie = this.realtimeMovies.shift();
this.realtimeMovies.push(movie);
this.notificationData = movie.title + " is running low on stock";
this.log({ action: "notification", type: "low stock", movie: movie.title })
$('.toast').removeClass('fadeout')
$('.toast').addClass('fadein')
setTimeout(function() {
$('.toast').removeClass('fadein')
$('.toast').addClass('fadeout')
}.bind(this), 3500)
},
reset: function() {
this.movies = sampleData;
this.facets = {};
this.title = "";
this.cast = "";
this.year = "";
this.director = "";
this.genre = "";
this.logs = [];
this.currentCard = 0;
this.realtimeMovies = [];
this.notificationData = null;
},
formReset: function() {
this.title = "";
this.cast = "";
this.year = "";
this.director = "";
this.genre = "";
}
}
});
</script>
</html>