Subversion Repositories SmartDukaan

Rev

Rev 37899 | Details | Compare with Previous | 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
			</div>
37903 ranu 57
			<div class="col-lg-12" style="margin-top:6px;">
58
				<label style="font-weight: normal; cursor: pointer;">
59
					<input type="checkbox" id="emi-cat-wipe-all" checked>
60
					<strong>Wipe all existing EMI offers before import</strong>
61
					<span style="color:#666; font-size:11px;">
62
						&nbsp;&mdash; recommended for a daily full-catalog refresh. Uncheck for partial / brand-scoped imports.
63
					</span>
64
				</label>
65
			</div>
37899 ranu 66
		</form>
67
		<div class="col-lg-12 emi-import-result" id="emi-cat-import-result"></div>
68
	</div>
69
 
70
	<div class="row">
71
		<div class="col-lg-12">
72
			<table id="emi-catalog-table" class="table table-striped table-bordered table-condensed emi-table">
73
				<thead>
74
				<tr>
75
					<th>#</th>
76
					<th>Brand</th>
77
					<th>Product</th>
78
					<th>Pine SKU</th>
79
					<th>Price</th>
80
					<th>Scraped</th>
81
					<th></th>
82
				</tr>
83
				</thead>
84
				<tbody>
85
					#foreach($p in $products)
86
					<tr>
87
						<td>$p.getId()</td>
88
						<td><span class="emi-brand-badge">$p.getBrand()</span></td>
89
						<td>$p.getProductName()</td>
90
						<td class="emi-sku">$p.getPineSku()</td>
91
						<td>#if($p.getPriceDisplay())$p.getPriceDisplay()#else -#end</td>
92
						<td>#if($p.getScrapedAt())$p.getScrapedAt()#else -#end</td>
93
						<td><a href="javascript:void(0)" data-id="$p.getId()"
94
							   class="btn btn-xs btn-default emi-cat-view">View offers</a></td>
95
					</tr>
96
					#end
97
				</tbody>
98
			</table>
99
			#if(!$products || $products.isEmpty())
100
				<p class="text-muted"><em>No products imported yet. Upload a Pine Labs EMI JSON above to get
101
					started.</em></p>
102
			#end
103
		</div>
104
	</div>
105
</section>
106
 
107
<script type="text/javascript">
108
	$(document).ready(function () {
109
		$('#emi-catalog-table').DataTable({pageLength: 50, bLengthChange: true, bInfo: false});
110
	});
111
 
112
	function emiCatalogImport() {
113
		var fi = document.getElementById('emi-cat-import-file');
114
		if (!fi.files || !fi.files[0]) {
115
			alert('Pick a JSON file first');
116
			return;
117
		}
118
		var fd = new FormData();
119
		fd.append('file', fi.files[0]);
37903 ranu 120
		fd.append('wipeAll', $('#emi-cat-wipe-all').is(':checked'));
37899 ranu 121
		var $btn = $('#emi-cat-import-btn');
122
			$btn.prop('disabled', true).text('Importing...');
123
		$('#emi-cat-import-result').html('<em>Working…</em>');
124
		$.ajax({
125
			url: context + '/emi-catalog/import',
126
			type: 'POST', data: fd, processData: false, contentType: false,
127
			success: function (res) {
128
				renderEmiCatImportResult(res);
129
			},
130
			error: function (xhr) {
131
				$('#emi-cat-import-result').html('<div class="alert alert-danger">Import failed: ' + (xhr.responseText || xhr.status) + '</div>');
132
			},
133
			complete: function () {
134
					$btn.prop('disabled', false).text('Import & Persist');
135
			}
136
		});
137
	}
138
 
139
	function renderEmiCatImportResult(r) {
37903 ranu 140
		var wipedMsg = (r.wipedBeforeImport > 0)
141
				? '<span style="color:#c62828;">wiped ' + r.wipedBeforeImport + ' old products before import</span> &middot; '
142
				: '';
37899 ranu 143
		var html = '<div class="alert alert-success">'
144
				+ '<strong>Imported.</strong> &middot; '
37903 ranu 145
				+ wipedMsg
37899 ranu 146
				+ 'products: ' + (r.productsUpserted || 0) + ' &middot; '
147
				+ 'groups: ' + (r.groupsInserted || 0) + ' &middot; '
148
				+ 'plans: ' + (r.plansInserted || 0) + ' &middot; '
37903 ranu 149
				+ 'cleared: ' + (r.groupsDeleted || 0) + ' per-product group refreshes'
37899 ranu 150
				+ '</div>';
151
		if (r.failures && r.failures.length) {
152
			html += '<div class="alert alert-danger"><strong>Failures:</strong><ul>';
153
			r.failures.forEach(function (f) {
154
				html += '<li>' + f + '</li>';
155
			});
156
			html += '</ul></div>';
157
		}
158
		if (r.productSummaries && r.productSummaries.length) {
159
			html += '<table class="table table-condensed table-bordered" style="margin-top:8px;"><thead><tr>'
160
					+ '<th>SKU</th><th>Product</th><th>Banks</th><th>Plans</th>'
161
					+ '</tr></thead><tbody>';
162
			r.productSummaries.forEach(function (p) {
163
				html += '<tr>'
164
						+ '<td class="emi-sku">' + (p.sku || '') + '</td>'
165
						+ '<td>' + (p.productName || '') + '</td>'
166
						+ '<td>' + (p.groupCount || 0) + '</td>'
167
						+ '<td>' + (p.planCount || 0) + '</td>'
168
						+ '</tr>';
169
			});
170
			html += '</tbody></table>';
171
		}
172
		html += '<p><a href="' + context + '/emi-catalog" class="btn btn-sm btn-primary" style="margin-top:6px;">Reload list</a></p>';
173
		$('#emi-cat-import-result').html(html);
174
	}
175
</script>