Subversion Repositories SmartDukaan

Rev

Rev 4198 | Rev 5323 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4198 Rev 5291
Line 7... Line 7...
7
	
7
	
8
	function roundNumber(num, dec) {
8
	function roundNumber(num, dec) {
9
		return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
9
		return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
10
	}
10
	}
11
	
11
	
-
 
12
	function updateWithSecondaryCrawledData()	{
-
 
13
		$.ajax({
-
 
14
			url: '/feedback-url',
-
 
15
			type: 'GET',
-
 
16
			success: function(data){
-
 
17
				
-
 
18
				$.each(data, function(entityId, sourceData){
-
 
19
					
-
 
20
					$.each(sourceData, function(source, productData){
-
 
21
						
-
 
22
						var tr = $('#' + entityId);
-
 
23
						var td = $(tr).children('td[source=' + source +']')[0];
-
 
24
						var anchor = $(td).children('a')[0];
-
 
25
						
-
 
26
						$(anchor).attr('href', productData['product_url']);
-
 
27
						$(anchor).html(productData['price']);
-
 
28
						
-
 
29
						$(td).children('span.url-feedback-link').addClass('url-saved');
-
 
30
					});
-
 
31
				});
-
 
32
			}
-
 
33
		});
-
 
34
	}
-
 
35
	
12
	function updateWithFeedback()	{
36
	function updateWithFeedback()	{
13
		$.ajax({
37
		$.ajax({
14
			url: '/feedback',
38
			url: '/feedback',
15
			type: 'GET',
39
			type: 'GET',
16
			success: function(data){
40
			success: function(data){
Line 25... Line 49...
25
						
49
						
26
						if($(td).hasClass('conflict'))	updateCellWithFeedback(td, feedback_instruction);
50
						if($(td).hasClass('conflict'))	updateCellWithFeedback(td, feedback_instruction);
27
					});
51
					});
28
					markBestPrice(tr);
52
					markBestPrice(tr);
29
				});
53
				});
-
 
54
				updateWithSecondaryCrawledData();
30
			}
55
			}
31
		})
56
		})
32
	}
57
	}
33
	
58
	
34
	function updateCellWithFeedback(td, feedback)	{
59
	function updateCellWithFeedback(td, feedback)	{
35
		var anchor = $(td).children('.link-conflict');
60
		var anchor = $(td).children('.link-conflict');
36
		
61
		
37
		var source = $(td).attr('source');
62
		var source = $(td).attr('source');
-
 
63
		var cellActionLinks = $(td).children('.url-feedback-link, .reject-link').clone();
38
		$(anchor).html('Filtered');
64
		$(anchor).html('Filtered');
39
		
65
		
40
		if(feedback.type == 'reject')	{
66
		if(feedback.type == 'reject')	{
41
			$(td).html('Not Found ' + $('<a>').append($(anchor).clone()).remove().html()).addClass('with-feedback');
67
			$(td).html('Not Found ' + $('<a>').append($(anchor).clone()).remove().html()).addClass('with-feedback');
-
 
68
			$(td).append(cellActionLinks);
-
 
69
			$(td).children('span.reject-link').addClass('rejected')
42
			
70
			
43
		} else	{
71
		} else	{
44
			var itemInfo = lookupInfoForItem(eval($(td).attr('data')), feedback.selected_item);
72
			var itemInfo = lookupInfoForItem(eval($(td).attr('data')), feedback.selected_item);
45
			
73
			
46
			if (itemInfo != null)	{
74
			if (itemInfo != null)	{
Line 71... Line 99...
71
 		
99
 		
72
 		$(this).find('td').each(function(){
100
 		$(this).find('td').each(function(){
73
 			if($(this).hasClass('conflict'))	$(this).children('a').addClass('link-conflict');
101
 			if($(this).hasClass('conflict'))	$(this).children('a').addClass('link-conflict');
74
 			
102
 			
75
 			if(! $(this).hasClass('diff') && ! $(this).hasClass('name') && ! $(this).hasClass('saholic'))	{
103
 			if(! $(this).hasClass('diff') && ! $(this).hasClass('name') && ! $(this).hasClass('saholic'))	{
-
 
104
 				$(this).append('<span class="reject-link" title="Click to reject the displayed figure">X</span>&nbsp;');
76
 				$(this).append('<span class="url-feedback-link" title="Click to map a product page URL">U</span>');
105
 				$(this).append('<span class="url-feedback-link" title="Click to map a product page URL">U</span>');
77
 			}
106
 			}
78
 		});
107
 		});
79
	});
108
	});
80
	
109
	
81
	updateWithFeedback();
110
	updateWithFeedback();
82
	
111
	
83
	function markBestPrice(trNode)	{
112
	function markBestPrice(trNode)	{
84
		$(trNode).children().removeClass('best');
113
		$(trNode).children().removeClass('best');
85
		var tdBestPrice = $(trNode).children('.saholic').html();
114
		var tdBestPrice = $(trNode).children('.saholic')[0];
86
		var saholicPrice = parseInt(tdBestPrice);
115
		var saholicPrice = parseInt($(tdBestPrice).html());
87
		var bestPrice = saholicPrice;
116
		var bestPrice = saholicPrice;
88
		var maxPrice = saholicPrice;
117
		var maxPrice = saholicPrice;
89
		
118
		
90
		$(trNode).find('a[href!="#"]').each(function(index, a){
119
		$(trNode).find('a[href!="#"]').each(function(index, a){
91
			var price = getPriceAsInt(a.innerHTML);
120
			var price = getPriceAsInt(a.innerHTML);
92
 
121
			
93
			if (price < bestPrice)	{
122
			if (price < bestPrice)	{
94
				bestPrice = price;
123
				bestPrice = price;
95
				tdBestPrice = $(a).parent();
124
				tdBestPrice = $(a).parent();
96
			}
125
			}
97
			
126
			
Line 119... Line 148...
119
 
148
 
120
	var baseUrl = {
149
	var baseUrl = {
121
		'flipkart': 'http://www.flipkart.com',
150
		'flipkart': 'http://www.flipkart.com',
122
		'homeshop18': '',
151
		'homeshop18': '',
123
		'infibeam': 'http://www.infibeam.com',
152
		'infibeam': 'http://www.infibeam.com',
124
		'letsbuy': ''
153
		'letsbuy': '',
-
 
154
		'snapdeal': 'http://www.snapdeal.com/'
125
	};
155
	};
126
	
156
	
127
	$('.conflict a').live('click', function(){
157
	$('.conflict a').live('click', function(){
128
		var td = $(this).parent();
158
		var td = $(this).parent();
129
		
159
		
Line 207... Line 237...
207
			data: feedback,
237
			data: feedback,
208
			success: function(msg)	{
238
			success: function(msg)	{
209
				
239
				
210
				if (feedbackType == 'reject')	{
240
				if (feedbackType == 'reject')	{
211
					$("input:radio[name='chosen_one_" + entityId + "']:checked").prop('checked', false);
241
					$("input:radio[name='chosen_one_" + entityId + "']:checked").prop('checked', false);
212
				} else	{
-
 
213
					
-
 
214
				}
242
				}
215
				var td = $('#' + feedback.entityId).children('td[source=' + feedback.source + ']')[0];
243
				var td = $('#' + feedback.entityId).children('td[source=' + feedback.source + ']')[0];
216
				updateCellWithFeedback(td, {type: feedback.type, selected_item: feedback.selected});
244
				updateCellWithFeedback(td, {type: feedback.type, selected_item: feedback.selected});
-
 
245
				
-
 
246
				if(table && table != 'undefined')	{
217
				showMsg(table, false, 'Your feedback has been saved successfully.');
247
					showMsg(table, false, 'Your feedback has been saved successfully.');
-
 
248
				}
218
				markBestPrice($(td).parent());
249
				markBestPrice($(td).parent());
219
			},
250
			},
220
			error: function(msg)	{
251
			error: function(msg)	{
221
				showMsg(table, true, 'Error! please try again.');
252
				showMsg(table, true, 'Error! please try again.');
222
			}
253
			}
Line 261... Line 292...
261
			beforeSend: function(){
292
			beforeSend: function(){
262
				$('#url-feedback, #submit-url-feedback').attr('disabled', 'disabled');
293
				$('#url-feedback, #submit-url-feedback').attr('disabled', 'disabled');
263
				$('#submit-url-feedback').val('Saving...').after('<img src="/static/images/loading.gif" width="24" />');
294
				$('#submit-url-feedback').val('Saving...').after('<img src="/static/images/loading.gif" width="24" />');
264
			},
295
			},
265
			success: function(data){
296
			success: function(data){
266
				console.log(data);
-
 
267
				var html = '<table>';
297
				var html = '<table>';
268
				html += '<tr><td class="msg" colspan="2" align="center">The URL is saved and will be crawled next time</td></tr>';
298
				html += '<tr><td class="msg" colspan="2" align="center">The URL is saved and will be crawled next time</td></tr>';
-
 
299
				html += '<tr><td colspan="2">&nbsp;</td></tr>';
269
				html += '<tr><td align="center">' + data.name + '</td><td align="center">Rs.' + data.price + '</td></tr>';
300
				html += '<tr><td align="center">' + data.name + '</td><td align="center">Rs.' + data.price + '</td></tr>';
270
				html += '<tr><td colspan="2" align="center">Please refresh the page to see the changes</td></tr>';
-
 
271
				html += '</table>';
301
				html += '</table>';
272
				var form = $('#facebox').find('.content').html(html);
302
				var form = $('#facebox').find('.content').html(html);
-
 
303
 
-
 
304
				var tr = $('#' + data.entityId);
-
 
305
				var td = $(tr).children('td[source=' + data.source +']')[0];
-
 
306
				var anchor = $(td).children('a')[0];
-
 
307
				
-
 
308
				$(anchor).attr('href', data.product_url);
-
 
309
				$(anchor).html(data.price);
-
 
310
				
-
 
311
				$(td).children('span').addClass('url-saved');
273
			}
312
			}
274
		});
313
		});
275
	});
314
	});
276
	
315
	
-
 
316
	$('.reject-link').live('click', function(){
-
 
317
		var source = $(this).parent().attr('source');
-
 
318
		var entity = $(this).parent().parent().attr('id');
-
 
319
		
-
 
320
		if($(this).hasClass('rejected'))	{
-
 
321
			var td = $(this).parent();
-
 
322
			
-
 
323
			var url = $(td).attr('url');
-
 
324
			var price = $(td).attr('price');
-
 
325
			
-
 
326
			var cellActionLinks = $(td).children('.url-feedback-link, .reject-link');
-
 
327
			$(td).html('<a target="_blank" href="' + url + '">' + price + '</a>');
-
 
328
			$(td).append(cellActionLinks);
-
 
329
			console.log($(td).children('.reject-link'));
-
 
330
			$($(td).children('.reject-link')[0]).removeClass('rejected');
-
 
331
			
-
 
332
		} else	{
-
 
333
			var feedback = {
-
 
334
					type: 'reject',
-
 
335
					entityId: entity,
-
 
336
					source: source
-
 
337
			};
-
 
338
			
-
 
339
			//Setting rejected URL in the cell's DOM
-
 
340
			var td = $('#' + entity).children('td[source=' + source + ']')[0];
-
 
341
			var anchor = $(td).children('a')[0];
-
 
342
			$(td).attr('price', $.trim($(anchor).html()));
-
 
343
			$(td).attr('url', $(anchor).attr('href'));
-
 
344
			
-
 
345
			postFeedback(feedback);
-
 
346
		}
-
 
347
	});
-
 
348
	
277
	$('#howTo').click(function(){
349
	$('#howTo').click(function(){
278
		html = '<ul>\n\
350
		html = '<ul>\n\
279
			<li class="first">The price data is crawled directly from competitor websites at 8:00 AM everyday</li>\n\
351
			<li class="first">The price data is crawled directly from competitor websites at 8:00 AM everyday</li>\n\
280
			<li class="first">All price figures are linked to their respective product pages</li>\n\
352
			<li class="first">All price figures are linked to their respective product pages</li>\n\
281
			<li class="first">Cells showing "Not Found" are linked to search result page of relevant website.</li>\n\
353
			<li class="first">Cells showing "Not Found" are linked to search result page of relevant website.</li>\n\
Line 294... Line 366...
294
			<li class="first">In case of further clarification, email your query at varun.gupta@shop2020.in</li>\n\
366
			<li class="first">In case of further clarification, email your query at varun.gupta@shop2020.in</li>\n\
295
			</ul>';
367
			</ul>';
296
		$.facebox(html);
368
		$.facebox(html);
297
	});
369
	});
298
	
370
	
-
 
371
	$('#all').click(function(){
-
 
372
		$('tbody tr').show();
-
 
373
	});
-
 
374
	
-
 
375
	$('#watchlist').click(function(){
-
 
376
		$('tbody tr .watchlist-icon').each(function(){
-
 
377
			if(! $(this).hasClass('on-watchlist'))	$(this).parent().parent().hide();
-
 
378
		});
-
 
379
	});
-
 
380
	
299
	$('#facebox .close').live('click', function(){});
381
	$('#facebox .close').live('click', function(){});
-
 
382
	
-
 
383
	var watchList = {
-
 
384
			get: function()	{
-
 
385
				$.ajax({
-
 
386
					type: 'GET',
-
 
387
					url: '/watchlist',
-
 
388
					
-
 
389
					error: function(jqXHR, textStatus, errorThrown)	{
-
 
390
						console.log(jqXHR, textStatus, errorThrown);
-
 
391
						alert('Could not get WatchList. Try again later.');
-
 
392
					},
-
 
393
					success: function(data, textStatus, jqXHR)	{
-
 
394
						console.log(data, textStatus, jqXHR);
-
 
395
						entities = eval('(' + data + ')');
-
 
396
						
-
 
397
						$.each(entities, function(index, entity)	{
-
 
398
							var elementId = '#' + entity;
-
 
399
							var tr = $(elementId);
-
 
400
							$($('#' + entity).find('.watchlist-icon')[0]).addClass('on-watchlist');
-
 
401
						});
-
 
402
					}
-
 
403
				});
-
 
404
			},
-
 
405
			add: function(entity)	{
-
 
406
				$.ajax({
-
 
407
					type: 'POST',
-
 
408
					url: '/watchlist',
-
 
409
					data: {'type': 'save', 'entity': entity},
-
 
410
					
-
 
411
					error: function(jqXHR, textStatus, errorThrown)	{
-
 
412
						console.log(jqXHR, textStatus, errorThrown);
-
 
413
						alert('Could not add this item to WatchList. Try again later.');
-
 
414
					},
-
 
415
					success: function(data, textStatus, jqXHR)	{
-
 
416
						console.log(data, textStatus, jqXHR);
-
 
417
						$($('#' + entity).find('.watchlist-icon')[0]).addClass('on-watchlist');
-
 
418
					}
-
 
419
				});
-
 
420
			},
-
 
421
			remove: function(entity)	{
-
 
422
				$.ajax({
-
 
423
					type: 'POST',
-
 
424
					url: '/watchlist',
-
 
425
					data: {'type': 'delete', 'entity': entity},
-
 
426
					
-
 
427
					error: function(jqXHR, textStatus, errorThrown)	{
-
 
428
						console.log(jqXHR, textStatus, errorThrown);
-
 
429
						alert('Could not remove this item from WatchList. Try again later.');
-
 
430
					},
-
 
431
					success: function(data, textStatus, jqXHR)	{
-
 
432
						console.log(data, textStatus, jqXHR);
-
 
433
						$($('#' + entity).find('.watchlist-icon')[0]).removeClass('on-watchlist');
-
 
434
					}
-
 
435
				});
-
 
436
			}
-
 
437
	};
-
 
438
	
-
 
439
	watchList.get();
-
 
440
	
-
 
441
	$('.watchlist-icon').click(function(){
-
 
442
		
-
 
443
		var entity = $(this).parent().parent().attr('id');
-
 
444
		
-
 
445
		if($(this).hasClass('on-watchlist'))	{
-
 
446
			watchList.remove(entity);
-
 
447
		} else	{
-
 
448
			watchList.add(entity);
-
 
449
		}
-
 
450
	});
300
});
451
});
301
452