Skip to content

Commit

Permalink
Display success/failure messages from import: #25
Browse files Browse the repository at this point in the history
Show any API errors returned by POST-ing records from the import.  Also
let the user know when items were imported correctly.

Unrelated, but also move the function that gets information about the
logged-in user so that it is only run on page load, not every time we
switch to the search page view.
  • Loading branch information
cecilia-donnelly committed Jul 26, 2016
1 parent 7ec5a87 commit df0fad6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/controllers/client.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ exports.addClient = function(req, res) {
var data = []
res_post.on('data', function (chunk) {
console.log('DEBUG: Response: ' + chunk);
data.push(chunk);
});
res_post.on('end', function() {
res.send(data.join(''));
Expand Down
23 changes: 20 additions & 3 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ function getClients(token) {
var ssn_array = [];
// get all existing ssn's
// full set of data retrieved via API
// when does this get refreshed?
var dataset = $("#index").data("full-data");
for (var client in dataset){
ssn_array.push(dataset[client]['ssn']);
}
var duplicate_lines = "";
// assigning handler
reader.onloadend = function(evt) {
reader.onloadend = function(evt) {
lines = evt.target.result.split(/\r?\n/);
var line_counter = 0;
// Possible values are:
Expand Down Expand Up @@ -1116,13 +1117,13 @@ function getClients(token) {
var line = line_object['data'][0];
// test whether the line is defined
if (line) {
// check for duplicate SSN
if (ssn_array.indexOf(line[7]) > 0) {
return_array[0] = true; //also pass first and last name
return_array[1] = line[2];
return_array[2] = line[4];
}
//
// if it doesn't, POST that record to the API
// if it isn't a dupe, POST the record to the API
else {
// get line into correct format for POSTing
var new_client = {};
Expand Down Expand Up @@ -1159,6 +1160,22 @@ function getClients(token) {
method: "POST",
data: new_client,
always: console.log("finished post")
}).done( function (response) {
// give user feedback about success of import
var result = JSON.parse(response);
if (result.error){
// TBD: see issue #35's comment about making
// these API errors more human-friendly
var message = result.error.errors[0]['message'];
var problem = result.error.errors[0]['problem'];
// add message to the results display
var failure_line = "Line " + line_counter + " had an import error: " + problem + "<br/>";
$("#results").append(failure_line);
}
else {
var success_line = "Line " + line_counter + " (" + result.data.item.firstName + " " + result.data.item.lastName + ") imported correctly. <br/>";
$("#results").append(success_line);
}
});

}
Expand Down
5 changes: 2 additions & 3 deletions public/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ $(function() {
if (id_token) {
getClients(id_token);
switchToSearch(false);
// fill in account that was used to log in
getLoginInfo(id_token);
}
else {
switchToLogin(false);
Expand Down Expand Up @@ -69,9 +71,6 @@ function switchToSearch(keepResults) {
$("#searchForm #addNewClient").prop("disabled", true);
}
$("#search").css("display", "block");
// fill in account that was used to log in
var id_token = getIdCookie();
getLoginInfo(id_token);
$("#intake").css("display", "none");
$("#login").css("display", "none");
$("#warning").css("display", "none");
Expand Down

0 comments on commit df0fad6

Please sign in to comment.