Jump to content
gbligh

MIS Linked Documents widget

Recommended Posts

I think we are there now:

var data = JSON.parse(response.response[i].data);
if (data[0].child in this.receipts) {
  for (var x = 0; x < data.length; x++) {
    this.receipts[data[0].child].push(data[x]);
  }
  this.receipts[data[0].child].sort(function(a, b){return b.datetime-a.datetime});
} else {
  this.receipts[data[0].child] = data;
  this.receipts[data[0].child].sort(function(a, b){return b.datetime-a.datetime});
}

@Graham Quince please feel free to take the updated widget and app.

@simon brahan thanks for your help!

  • Thanks 1

Share this post


Link to post
Share on other sites
2 minutes ago, pconkie said:

I think we are there now:


var data = JSON.parse(response.response[i].data);
if (data[0].child in this.receipts) {
  for (var x = 0; x < data.length; x++) {
    this.receipts[data[0].child].push(data[x]);
  }
  this.receipts[data[0].child].sort(function(a, b){return b.datetime-a.datetime});
} else {
  this.receipts[data[0].child] = data;
  this.receipts[data[0].child].sort(function(a, b){return b.datetime-a.datetime});
}

@Graham Quince please feel free to take the updated widget and app.

@simon brahan thanks for your help!

Code review time!

  • Since you're using the child id a lot, it might be helpful to pull it into a variable.
  • If you move the sort line out of the if statement you can remove the duplicate line in the other branch, which means you only have to fix it once if anything changes.
  • Arrays have a concat method that can be used to add the contents of an array to the end of another array. This should be faster than pushing the entries one at a time.
  • The overall logic might be clearer in future if you handle the initialisation of this.receipts before trying to add data.

Add those together, you get something like the following:

var data = JSON.parse(response.response[i].data);
var childId = data[0].child;

// If we haven't seen any data for this child, initialise their record here
if (!(childId in this.receipts)) {
    this.receipts[childId] = [];
}

// Add the new records to the end of the old ones
this.receipts[childId] = this.receipts[childId].concat(data);

// Sort the child's records
this.receipts[childId].sort(function(a, b){return b.datetime-a.datetime});

At the moment the code will also sort the receipts for a child every time records for that child are found; it shouldn't be too big a deal here since you're only likely to have one or two records per child.

None of the above is essential, just thought you might like some insight as to how we approach things here. 🙂

  • Thanks 2

Share this post


Link to post
Share on other sites
On 04/07/2019 at 15:50, simon brahan said:

Code review time!

  • Since you're using the child id a lot, it might be helpful to pull it into a variable.
  • If you move the sort line out of the if statement you can remove the duplicate line in the other branch, which means you only have to fix it once if anything changes.
  • Arrays have a concat method that can be used to add the contents of an array to the end of another array. This should be faster than pushing the entries one at a time.
  • The overall logic might be clearer in future if you handle the initialisation of this.receipts before trying to add data.

Add those together, you get something like the following:


var data = JSON.parse(response.response[i].data);
var childId = data[0].child;

// If we haven't seen any data for this child, initialise their record here
if (!(childId in this.receipts)) {
    this.receipts[childId] = [];
}

// Add the new records to the end of the old ones
this.receipts[childId] = this.receipts[childId].concat(data);

// Sort the child's records
this.receipts[childId].sort(function(a, b){return b.datetime-a.datetime});

At the moment the code will also sort the receipts for a child every time records for that child are found; it shouldn't be too big a deal here since you're only likely to have one or two records per child.

None of the above is essential, just thought you might like some insight as to how we approach things here. 🙂

I should go on holiday more often 😛 

I quickly scanned the thread, so I am kinda up to speed - the issue was that you were trying to save something to the datastore that was using the uuid of a child for one of the parents - and it wouldn't let you, correct? In that case, I will speak to @simon brahan about this, because we do have helpers that allow us to easily check if a parent has permission to see data related to a child (e.g. they need parental responsibility over that child etc).

I'm pretty sure that the helper also checks the court order flags from your MIS systems as well. It may be worth investigating how easy it would be to alter the FDP endpoint to do this check on a passed user. I suspect it would be trivial.

Something to think about at least.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you for the new coded widget, its exactly what parents were asking for, I love it. 

We use frog to send our children their GCSE results as we are unable to email them and as we are international, its difficult for students to come and collect them. Its worth noting that students are unable to see any of the documents using the new widget and so have had to switch back to the frog one for student viewing. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...