Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
37899 ranu 1
<style>
2
	.emi-import-box {
3
		padding: 12px;
4
		border: 1px dashed #999;
5
		background: #fafafa;
6
		margin: 8px 0 16px 0;
7
		border-radius: 4px;
8
	}
9
 
10
	.emi-table th {
11
		background: #f4f4f4;
12
	}
13
 
14
	.emi-sku {
15
		font-family: Menlo, Consolas, monospace;
16
		font-size: 12px;
17
		color: #555;
18
	}
19
 
20
	.emi-brand-badge {
21
		display: inline-block;
22
		padding: 1px 7px;
23
		border-radius: 10px;
24
		background: #eceff1;
25
		color: #37474f;
26
		font-size: 11px;
27
		font-weight: 600;
28
	}
29
 
30
	.emi-import-result {
31
		margin-top: 10px;
32
	}
33
</style>
34
 
35
<section class="wrapper">
36
	<div class="row">
37
		<div class="col-lg-12">
38
			<h3 class="page-header"><i class="icon_document_alt"></i>EMI Catalog</h3>
39
			<ol class="breadcrumb">
40
				<li><i class="fa fa-home"></i><a href="${rc.contextPath}/dashboard">Home</a></li>
41
				<li><i class="icon_document_alt"></i>EMI Catalog</li>
42
			</ol>
43
		</div>
44
	</div>
45
 
46
	<div class="emi-import-box">
47
		<h4 style="margin:0 0 8px 0;">Import EMI JSON (Pine Labs scrape)</h4>
48
		<form id="emi-cat-import-form" onsubmit="event.preventDefault(); emiCatalogImport();"
49
			  enctype="multipart/form-data">
50
			<div class="col-lg-5" style="padding-left:0;">
51
				<input type="file" id="emi-cat-import-file" accept="application/json,.json" class="form-control"
52
					   required>
53
			</div>
54
			<div class="col-lg-3">
55
				<button type="submit" class="btn btn-primary" id="emi-cat-import-btn">Import &amp; Persist</button>
56
				<span style="color:#666; font-size:11px; margin-left:8px;">Replaces existing offers per SKU.</span>
57
			</div>
58
		</form>
59
		<div class="col-lg-12 emi-import-result" id="emi-cat-import-result"></div>
60
	</div>
61
 
62
	<div class="row">
63
		<div class="col-lg-12">
64
			<table id="emi-catalog-table" class="table table-striped table-bordered table-condensed emi-table">
65
				<thead>
66
				<tr>
67
					<th>#</th>
68
					<th>Brand</th>
69
					<th>Product</th>
70
					<th>Pine SKU</th>
71
					<th>Price</th>
72
					<th>Scraped</th>
73
					<th></th>
74
				</tr>
75
				</thead>
76
				<tbody>
77
					#foreach($p in $products)
78
					<tr>
79
						<td>$p.getId()</td>
80
						<td><span class="emi-brand-badge">$p.getBrand()</span></td>
81
						<td>$p.getProductName()</td>
82
						<td class="emi-sku">$p.getPineSku()</td>
83
						<td>#if($p.getPriceDisplay())$p.getPriceDisplay()#else -#end</td>
84
						<td>#if($p.getScrapedAt())$p.getScrapedAt()#else -#end</td>
85
						<td><a href="javascript:void(0)" data-id="$p.getId()"
86
							   class="btn btn-xs btn-default emi-cat-view">View offers</a></td>
87
					</tr>
88
					#end
89
				</tbody>
90
			</table>
91
			#if(!$products || $products.isEmpty())
92
				<p class="text-muted"><em>No products imported yet. Upload a Pine Labs EMI JSON above to get
93
					started.</em></p>
94
			#end
95
		</div>
96
	</div>
97
</section>
98
 
99
<script type="text/javascript">
100
	$(document).ready(function () {
101
		$('#emi-catalog-table').DataTable({pageLength: 50, bLengthChange: true, bInfo: false});
102
	});
103
 
104
	function emiCatalogImport() {
105
		var fi = document.getElementById('emi-cat-import-file');
106
		if (!fi.files || !fi.files[0]) {
107
			alert('Pick a JSON file first');
108
			return;
109
		}
110
		var fd = new FormData();
111
		fd.append('file', fi.files[0]);
112
		var $btn = $('#emi-cat-import-btn');
113
			$btn.prop('disabled', true).text('Importing...');
114
		$('#emi-cat-import-result').html('<em>Working…</em>');
115
		$.ajax({
116
			url: context + '/emi-catalog/import',
117
			type: 'POST', data: fd, processData: false, contentType: false,
118
			success: function (res) {
119
				renderEmiCatImportResult(res);
120
			},
121
			error: function (xhr) {
122
				$('#emi-cat-import-result').html('<div class="alert alert-danger">Import failed: ' + (xhr.responseText || xhr.status) + '</div>');
123
			},
124
			complete: function () {
125
					$btn.prop('disabled', false).text('Import & Persist');
126
			}
127
		});
128
	}
129
 
130
	function renderEmiCatImportResult(r) {
131
		var html = '<div class="alert alert-success">'
132
				+ '<strong>Imported.</strong> &middot; '
133
				+ 'products: ' + (r.productsUpserted || 0) + ' &middot; '
134
				+ 'groups: ' + (r.groupsInserted || 0) + ' &middot; '
135
				+ 'plans: ' + (r.plansInserted || 0) + ' &middot; '
136
				+ 'cleared: ' + (r.groupsDeleted || 0) + ' old groups'
137
				+ '</div>';
138
		if (r.failures && r.failures.length) {
139
			html += '<div class="alert alert-danger"><strong>Failures:</strong><ul>';
140
			r.failures.forEach(function (f) {
141
				html += '<li>' + f + '</li>';
142
			});
143
			html += '</ul></div>';
144
		}
145
		if (r.productSummaries && r.productSummaries.length) {
146
			html += '<table class="table table-condensed table-bordered" style="margin-top:8px;"><thead><tr>'
147
					+ '<th>SKU</th><th>Product</th><th>Banks</th><th>Plans</th>'
148
					+ '</tr></thead><tbody>';
149
			r.productSummaries.forEach(function (p) {
150
				html += '<tr>'
151
						+ '<td class="emi-sku">' + (p.sku || '') + '</td>'
152
						+ '<td>' + (p.productName || '') + '</td>'
153
						+ '<td>' + (p.groupCount || 0) + '</td>'
154
						+ '<td>' + (p.planCount || 0) + '</td>'
155
						+ '</tr>';
156
			});
157
			html += '</tbody></table>';
158
		}
159
		html += '<p><a href="' + context + '/emi-catalog" class="btn btn-sm btn-primary" style="margin-top:6px;">Reload list</a></p>';
160
		$('#emi-cat-import-result').html(html);
161
	}
162
</script>