Skip to content

Commit 2072be3

Browse files
vabarbosaglynnbird
authored andcommitted
surface missing header value (#46)
* handle schema error with field name * disable type drop down and facet checkbox on field error #45 * uncheck facet checkbox if when not facet type selected
1 parent a64cdd6 commit 2072be3

File tree

3 files changed

+63
-21
lines changed

3 files changed

+63
-21
lines changed

public/js/seams.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,22 @@ seamsApp.controller('navController', ['$scope', '$route', '$routeParams',
4343
var html = $scope.$root.renderSchema($scope.$root.schema);
4444
$('#schemacontent').html(html);
4545
var checked = 0;
46-
$('.facet_checkbox', '#schemacontent').each(function() {
47-
$(this).change(function() {
48-
if($(this).is(":checked")) {
49-
checked++;
50-
}
51-
else {
52-
checked--;
53-
}
54-
$('#importbutton').attr('disabled',checked == 0);
55-
$('#facetstatus').css('visibility', checked == 0 ? 'visible' : 'hidden');
46+
if (!$scope.$root.schemaError) {
47+
$('.facet_checkbox', '#schemacontent').each(function() {
48+
$(this).change(function() {
49+
if($(this).is(":checked")) {
50+
checked++;
51+
}
52+
else {
53+
checked--;
54+
}
55+
$('#importbutton').attr('disabled',checked == 0);
56+
$('#facetstatus').css('visibility', checked == 0 ? 'visible' : 'hidden');
57+
});
5658
});
57-
});
58-
$('#importbutton').attr('disabled',checked == 0);
59-
$('#facetstatus').css('visibility', checked == 0 ? 'visible' : 'hidden');
59+
}
60+
$('#importbutton').attr('disabled', checked == 0 || $scope.$root.schemaError);
61+
$('#facetstatus').css('visibility', (checked == 0 || $scope.$root.schemaError) ? 'visible' : 'hidden');
6062
}
6163
break;
6264
case 'search':
@@ -291,15 +293,24 @@ seamsApp.controller('seamsController', ['$scope', '$route', '$routeParams', '$lo
291293
// and whether its faceted or not, together with an example value from the
292294
// uploaded file (x.data)
293295
$scope.$root.renderSchema = function(x) {
296+
$scope.$root.schemaError = false;
294297
var html = '<table class="table_basic">\n';
295298
html += '<input type="hidden" name="upload_id" id="upload_id" value="' + x.upload_id + '"/>\n';
296299
html += "<thead>\n";
297300
html += " <th>name</th><th>type</th><th>facet</th><th>e.g</th>\n";
298301
html += "</thead>\n"
299302
for(var i in x.fields) {
300-
html += "<tr>";
301303
var f = x.fields[i];
302-
html += "<td>" + f.name + "</td>\n";
304+
if (!f.name) {
305+
f.hasError = true;
306+
$scope.$root.schemaError = true;
307+
html += "<tr class='error'>";
308+
}
309+
else {
310+
html += "<tr>";
311+
}
312+
html += '<td class="' + (f.name ? '' : 'error') + '">';
313+
html += (f.name || '&#10007; Missing field name') + '</td>\n';
303314
html += "<td>" + $scope.$root.typeWidget(f) + "</td>\n";
304315
html += "<td>" + $scope.$root.facetWidget(f) + "</td>\n";
305316
for(var j in x.data) {
@@ -330,7 +341,8 @@ seamsApp.controller('seamsController', ['$scope', '$route', '$routeParams', '$lo
330341
$scope.$root.typeWidget = function(f) {
331342
var n = f.safename;
332343
var t = f.type;
333-
var html = '<select name="' + n + '" class="input_select" onchange="datatypechange(\'' + n +'\')" data-original-name="' + f.name + '">\n';
344+
var html = '<select name="' + n + '" class="input_select" onchange="datatypechange(\'' + n +'\')" data-original-name="' + f.name;
345+
html += (f.hasError) ? '" disabled="disabled">\n' : '">\n';
334346
var opts = { "string":"String", "number":"Number", "boolean":"Boolean", "arrayofstrings":"Array of Strings" };
335347
for(var i in opts) {
336348
html += '<option value="' + i + '"';
@@ -350,7 +362,7 @@ seamsApp.controller('seamsController', ['$scope', '$route', '$routeParams', '$lo
350362
var t = f.type;
351363
var v = f.facet.toString();
352364
var html = '<input class="input_checkbox facet_checkbox" type="checkbox" value="true" name="' + n + '" id="' + n + '"';
353-
if (t == "number" || t == "boolean") {
365+
if (t == "number" || t == "boolean" || f.hasError) {
354366
html += ' disabled="disabled"';
355367
}
356368
if (v == "true") {
@@ -784,9 +796,13 @@ seamsApp.directive('previewSearchHtml', function(){
784796
var datatypechange = function(e) {
785797
var d = $('select[name=' + e + ']');
786798
var v = d.val();
787-
if(v == "string" || v == "arrayofstrings") {
788-
$('input#' + e).prop("disabled", false);
799+
var i = $('input#' + e);
800+
if (v == "string" || v == "arrayofstrings") {
801+
i.prop("disabled", false);
789802
} else {
790-
$('input#' + e).prop("disabled", true);
803+
if (i.is(':checked')) {
804+
i.prop("checked", false).trigger('change');
805+
}
806+
i.prop("disabled", true);
791807
}
792808
}

public/seams.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,23 @@
6464
right: 100px;
6565
white-space: nowrap;
6666
}
67+
68+
td.error {
69+
color: #ff0000;
70+
}
71+
72+
.alert-container.error {
73+
background: rgba(0, 0, 0, 0) repeating-linear-gradient(-55deg, #bb4444, #bb4444 1px, #bb1122 1px, #bb1122 3px) repeat scroll 0 0 !important;
74+
border-left: 2px solid #ad1625;
75+
color: #ffffff;
76+
}
77+
78+
.type_copy.alert-container {
79+
max-width: 100%;
80+
}
81+
82+
.input_select:disabled,
83+
.input_select.disabled {
84+
background-color: #92a4af;
85+
border-color: #000000;
86+
}

views/templates/import.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ <h1 class="type_heading"><mark class="type_mark">Create the Search Index</mark><
3232
</div>
3333

3434
<div ng-show="currentStatus == 'uploaded'">
35+
<div class="type_copy alert-container error"
36+
ng-show="schemaError">
37+
An error was detected with one or more fields. Verify the file and re-upload
38+
</div>
3539

3640
<div id="schemacontent" class="table_container"></div>
3741

3842
<div class="button_group">
39-
<div class="type_copy" id="facetstatus">Select a field to facet before importing</div>
43+
<div class="type_copy" id="facetstatus">
44+
{{ schemaError ? 'An error was detected with one or more fields. Verify the file and re-upload' : 'Select a field to facet before importing' }}
45+
</div>
4046
<button id="backbutton" type="button" class="button_secondary" ng-click="goToNextPage('upload')">Back</button>
4147
<button id="importbutton" type="submit" class="button_primary" ng-click="importClicked()"> Import </button>
4248
<!-- <span class="glyphicon glyphicon-refresh glyphicon-spinner import-spinner"></span> -->

0 commit comments

Comments
 (0)