From 653be95364a958cd04ee6dfde359066ee923c273 Mon Sep 17 00:00:00 2001 From: aajhp Date: Sat, 31 Mar 2018 17:43:20 +0100 Subject: [PATCH 1/2] Completion of tech test As a client I want to be able to view information about all the fund managers on one page so that users are able to view this information in a simple and responsive design. For this project I used JSON functions in JQuery to get all the data from the api, I was able to fix my previous issue that did not load all the managers in alphabetical order by using a sort function once every new manager was collected. --- index.html | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..d61a1ff --- /dev/null +++ b/index.html @@ -0,0 +1,171 @@ + + + + + + CoInvestor + + + + + + + + +
+ + \ No newline at end of file From a48500c9a63fa471862bc1ba2f4c7d64c9f15bd8 Mon Sep 17 00:00:00 2001 From: aajhp Date: Sat, 31 Mar 2018 17:44:01 +0100 Subject: [PATCH 2/2] Update that fixes the sorting of names --- index.html | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index d61a1ff..34a5f20 100644 --- a/index.html +++ b/index.html @@ -14,15 +14,14 @@ $individuals = []; $.fn.populate = function() { //Get pages - $.getJSON("https://api.coinvestor.co.uk/v2/company/sponsor?sort=name",function(data) { - var $numbOfPages = data.meta.pagination.total_pages; - var $totalIndividuals = data.meta.pagination.total; + $.getJSON("https://api.coinvestor.co.uk/v2/company/sponsor?sort=name",function($data) { + var $numbOfPages = $data.meta.pagination.total_pages; + var $totalIndividuals = $data.meta.pagination.total; //Get page urls for(var $i = 1; $i <= $numbOfPages;$i ++) { $.fn.getPageData("https://api.coinvestor.co.uk/v2/company/sponsor?sort=name&page="+$i); } - setTimeout(function() {alert($individuals.length)},500); }); //Get data for each page //Get individual data @@ -30,9 +29,9 @@ } $.fn.getPageData = function($url) { $.getJSON($url,function($data) { - $.each($data.data,function(index,value) { + $.each($data.data,function($index,$value) { //alert(value.attributes.name); - $indiObj = $.fn.getIndividualData(value.id); + $indiObj = $.fn.getIndividualData($value.id); }) }); } @@ -59,6 +58,7 @@ }); $individuals.push($object); $.fn.addIndividual($object); + $.fn.sortUsers(); }) } $.fn.addIndividual = function($data) { @@ -84,6 +84,17 @@ $panelBody.appendTo($panel); $("#content").append($panel); } + $.fn.sortUsers = function() { + $individuals.sort(function($a, $b){ + if($a.name < $b.name) return -1; + if($a.name > $b.name) return 1; + return 0; + }) + $("#content").empty(); + for(var $i = 0; $i < $individuals.length; $i++) { + $.fn.addIndividual($individuals[$i]); + } + }