diff --git a/src/index.html b/src/index.html index 4f13778..04d60b7 100644 --- a/src/index.html +++ b/src/index.html @@ -27,14 +27,38 @@

All active projects

Type Name Last activity + Branch + Up to Date + +
+ +
+
+

Add new project

+ +
+ + + + + + + + + + + + +
+
@@ -44,6 +68,7 @@

Add new project

+
diff --git a/src/projects.js b/src/projects.js index 6c11b49..d723238 100644 --- a/src/projects.js +++ b/src/projects.js @@ -1,8 +1,98 @@ -function Project(id, type, name, lastActivity) { +$(document).ready(function() { + getBranches(); +}); + +//// here I call an index of the branches (very minimal information) +var getBranches = function(){ + + var request = $.ajax({ + url: "https://api.github.com/repos/andrewdonato/webdev-exercise/branches", + type: "get" + }) + request.done(function(serverData){ + var branches = serverData; + viewEachBranch(branches); + }) + request.fail(function(serverData){ + console.log(serverData); + console.log('server request failed'); + }) +}; + + +//// Warning!! This makes many queries at once. Watch your rate limit ~ 60/hr +//// Here I view the show of each branch and add it to an array of all of the branch shows +var allBranchShows = []; +var viewEachBranch = function(branches){ + for (var i = 0; i < branches.length; i++){ + + var branchName = branches[i].name + + if (branchName === "master"){ + indexOfMaster = i + }; + + var request = $.ajax({ + url: "https://api.github.com/repos/andrewdonato/webdev-exercise/branches/" + branchName, + type: "get" + }) + request.done(function(serverData){ + var branchShow = serverData; + allBranchShows.push(branchShow) + }) + request.fail(function(serverData){ + console.log(serverData); + console.log('server request failed'); + }) + }; + compareBranchDatesToMaster(allBranchShows, indexOfMaster) +}; + +//// here I compare the date of each branch with the date of master. +//// I added "upToDateStatus" to each branch show object +var compareBranchDatesToMaster = function(allBranches, indexOfMaster){ + + dateOfMaster = allBranches[indexOfMaster].commit.commit.author.date + + for (var i = 0; i < allBranches.length; i++){ + var dateOfBranch + + if (dateOfBranch < dateOfMaster){ + allBranches[i].upToDateStatus = false + } + else { + allBranches[i].upToDateStatus = true + }; + }; + + updateDOM(allBranches) +}; + +//// here I update the branch name and whether or it "Up To Date" +var updateDOM = function (allBranches) { + debugger + + // I've run out of time. + // To finish, I would use jquery to determine the branch of each project. + // I would also use jqeury to populate the branch drop down menu + // I would then go to the parent row, and then append the "upToDateStatus" which would be either true or false. + + +} + + + + + + + + +function Project(id, type, name, lastActivity, branch, upToDate) { this.id = id; this.type = type; this.name = name; this.lastActivity = lastActivity; + this.branch = branch; } // The list of all projects currently in the system. @@ -17,13 +107,15 @@ var CURRENT_PROJECTS = [ var MAX_ID = Math.max.apply(null, $.map(CURRENT_PROJECTS, function(pj) { return pj.id; })); $(function(){ + var loadProjects = function($container, projects) { $.fn.append.apply($container, $.map(projects, function(pj) { return $("").append( $("").text(pj.id), $("").text(pj.type), $("").text(pj.name), - $("").text(pj.lastActivity.toString()) + $("").text(pj.lastActivity.toString()), + $("").text(pj.branch) ); })); }; @@ -34,7 +126,9 @@ $(function(){ MAX_ID + 1, $form.find("#project-type").val(), $form.find("#project-name").val(), - new Date() + new Date(), + $form.find("#project-branch").val() + // this is where I would put whether or not the project is up to date with master ); }; @@ -42,6 +136,7 @@ $(function(){ var resetForm = function($form) { $form.find("#project-type").val(""); $form.find("#project-name").val(""); + $form.find("#project-branch").val(""); $form.find("input:first").focus(); };