From e5c06776c22871af3ca6a7285091c9663ea348db Mon Sep 17 00:00:00 2001 From: Nadia Lefebvre <95084122+nadialefebvre@users.noreply.github.com> Date: Thu, 17 Feb 2022 14:04:18 +0100 Subject: [PATCH 01/28] updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1613a3b0..26648795 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# GitHub Tracker +# Week 7: GitHub tracker Replace this readme with your own information about your project. From 4e5ccbfc899fd4b12501fa7e1accd133f92f4f80 Mon Sep 17 00:00:00 2001 From: Nadia Lefebvre <95084122+nadialefebvre@users.noreply.github.com> Date: Thu, 17 Feb 2022 17:50:15 +0100 Subject: [PATCH 02/28] added first fetch requests --- code/script.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ code/style.css | 6 ++++++ 2 files changed, 53 insertions(+) diff --git a/code/script.js b/code/script.js index e69de29b..4f6b9f42 100644 --- a/code/script.js +++ b/code/script.js @@ -0,0 +1,47 @@ +const projects = document.getElementById('projects') +const API_REPOS = 'https://api.github.com/users/nadialefebvre/repos' + +const options = { + method: 'GET', + headers: { + Authorization: 'token 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' + } +} + +fetch(API_REPOS, options) // options object is passed as 2nd argument to fetch() function. + .then(res => res.json()) + .then(data => { + console.log(data) + projects.innerHTML = ` + +

Username: ${data[0].owner.login}

+ ` + const filteredRepos = data.filter(repo => repo.fork === true && repo.name.startsWith('project')) + console.log(filteredRepos) + filteredRepos.forEach((repo) => { + fetch(`https://api.github.com/repos/nadialefebvre/${repo.name}`, options) + .then(res => res.json()) + .then(data => { + console.log(data) + console.log(repo.pushed_at) + const options = { day: 'numeric', month: 'long', year: 'numeric' } + projects.innerHTML += ` +
+

Repo name: ${repo.name}

+

Repo URL: ${repo.html_url}

+

Default branch: ${repo.default_branch}

+

Repo last push: ${new Date(repo.pushed_at).toLocaleDateString('en-GB', options)}

+
+ ` + }) + fetch(`https://api.github.com/repos/nadialefebvre/${repo.name}/commits`) + .then(res => res.json()) + .then(data => { + console.log(data) + console.log(data.length) + document.getElementById(`${repo.name}`).innerHTML += ` +

Number of commits: ${data.length}

+ ` + }) + }) + }) diff --git a/code/style.css b/code/style.css index 7c8ad447..0bd4c055 100644 --- a/code/style.css +++ b/code/style.css @@ -1,3 +1,9 @@ body { background: #FFECE9; +} + +.repo { + border: solid 1px red; + padding: 10px; + margin-bottom: 10px; } \ No newline at end of file From b1bf1a53d470e9ba485c0caa9b918cbedec5aff1 Mon Sep 17 00:00:00 2001 From: Nadia Lefebvre <95084122+nadialefebvre@users.noreply.github.com> Date: Fri, 18 Feb 2022 17:17:49 +0100 Subject: [PATCH 03/28] added a basic graph with projects --- code/chart.js | 61 +++++++++++++++++++++++++ code/index.html | 16 +++++-- code/script.js | 115 +++++++++++++++++++++++++++++++++--------------- 3 files changed, 154 insertions(+), 38 deletions(-) diff --git a/code/chart.js b/code/chart.js index 92e85a30..6b64feff 100644 --- a/code/chart.js +++ b/code/chart.js @@ -2,3 +2,64 @@ const ctx = document.getElementById('chart').getContext('2d') //"Draw" the chart here 👇 + + +// what's not working below is commented out +// global options +// Chart.defaults.global.defaultFontFamily = 'Lato'; +// Chart.defaults.global.defaultFontSize = 18; +// Chart.defaults.global.defaultFontColor = 'grey'; + +const drawProjectsChart = (amount) => { + new Chart(ctx, { + type: 'bar', // bar, horizontalBar, pie, line, doughnut, radar, polarArea + data: { + labels: ['Completed', 'To do'], + datasets: [{ + barPercentage: 1, + barThickness: 100, + maxBarThickness: 200, + minBarLength: 2, + label: 'Projects', + data: [ + amount, + 19 - amount + ], + backgroundColor: [ + 'red', + 'green' + ], + borderWidth: 2, + borderColor: 'black', + hoverBorderWidth: 5, + hoverBorderColor: 'brown' + } + ] + } + // options: { + // title: { + // display: true, + // text: 'Largest Cities in Massachussets', + // fontSize:24 + // }, + // legend:{ + // display:false, + // position:'right', + // labels:{ + // fontColor:'black' + // } + // layout: { + // padding: { + // left: 0, + // right: 0, + // bottom: 0, + // top: 0 + // } + // }, + // tooltips:{ + // enabled:false + // } + // } + }) +} + diff --git a/code/index.html b/code/index.html index 2fb5e0ae..63e6a1e9 100644 --- a/code/index.html +++ b/code/index.html @@ -1,21 +1,31 @@ + Project GitHub Tracker + + +

GitHub Tracker

-

Projects:

-
+
+
+
+
- +
+ +
+ + \ No newline at end of file diff --git a/code/script.js b/code/script.js index 4f6b9f42..db3bcfdf 100644 --- a/code/script.js +++ b/code/script.js @@ -1,47 +1,92 @@ +const username = 'nadialefebvre' +const API_USER = `https://api.github.com/users/${username}` +const API_REPOS = `https://api.github.com/users/${username}/repos` // const or let ? +const profile = document.getElementById('profile') const projects = document.getElementById('projects') -const API_REPOS = 'https://api.github.com/users/nadialefebvre/repos' -const options = { - method: 'GET', - headers: { - Authorization: 'token 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' - } + + + + +const createProfile = () => { + fetch(API_USER) + .then(res => res.json()) + .then(data => { + profile.innerHTML = ` +

${data.name}

+ + ` + }) } -fetch(API_REPOS, options) // options object is passed as 2nd argument to fetch() function. - .then(res => res.json()) - .then(data => { - console.log(data) - projects.innerHTML = ` - -

Username: ${data[0].owner.login}

- ` - const filteredRepos = data.filter(repo => repo.fork === true && repo.name.startsWith('project')) - console.log(filteredRepos) - filteredRepos.forEach((repo) => { - fetch(`https://api.github.com/repos/nadialefebvre/${repo.name}`, options) - .then(res => res.json()) - .then(data => { - console.log(data) - console.log(repo.pushed_at) - const options = { day: 'numeric', month: 'long', year: 'numeric' } - projects.innerHTML += ` + + + + + + + +const createRepoCard = () => { + fetch(API_REPOS) // options object is passed as 2nd argument to fetch() function. // TO REMOVE BEFORE GIT PUSH + .then(res => res.json()) + .then(data => { + const filteredRepos = data.filter(repo => repo.fork === true && repo.name.startsWith('project-')) + drawProjectsChart(filteredRepos.length) + filteredRepos.forEach(repo => { + const options = { day: 'numeric', month: 'long', year: 'numeric' } + projects.innerHTML += `

Repo name: ${repo.name}

-

Repo URL: ${repo.html_url}

+

Repo URL: ${repo.name}

Default branch: ${repo.default_branch}

Repo last push: ${new Date(repo.pushed_at).toLocaleDateString('en-GB', options)}

` - }) - fetch(`https://api.github.com/repos/nadialefebvre/${repo.name}/commits`) - .then(res => res.json()) - .then(data => { - console.log(data) - console.log(data.length) - document.getElementById(`${repo.name}`).innerHTML += ` -

Number of commits: ${data.length}

- ` - }) + fetch(`https://api.github.com/repos/${username}/${repo.name}/commits`) + .then(res => res.json()) + .then(data => { + console.log(data) + const userCommits = data.filter((item) => item.commit.author.name === 'Nadia Lefebvre') + + document.getElementById(repo.name).innerHTML += ` +

Number of commits from the user: ${userCommits.length} on a total of ${data.length}

+

Commit messages:

+ ` + userCommits.forEach(item => { + document.getElementById(repo.name).innerHTML += ` +
  • ${item.commit.message}
  • + ` + }) + }) + }) }) +} + + +createProfile() +createRepoCard() + + + + + + +//Remember to pass along your filtered repos as an argument when +//you are calling this function + +const getPullRequests = (repos) => { + //Get all the PRs for each project. + repos.forEach(repo => { + fetch('https://api.github.com/repos/technigo/' + repo.name + '/pulls') + .then(res => res.json()) + .then(data => { + //TODO + //1. Find only the PR that you made by comparing pull.user.login + // with repo.owner.login + //2. Now you're able to get the commits for each repo by using + // the commits_url as an argument to call another function + //3. You can also get the comments for each PR by calling + // another function with the review_comments_url as argument + }) }) + } From 9ad406dc069c41185c9ae3237b025c2e031fb20b Mon Sep 17 00:00:00 2001 From: Nadia Lefebvre <95084122+nadialefebvre@users.noreply.github.com> Date: Sat, 19 Feb 2022 21:37:30 +0100 Subject: [PATCH 04/28] added vertical tabs for repocard --- code/chart.js | 132 ++++++++++++++++++++-------- code/index.html | 11 ++- code/script.js | 225 +++++++++++++++++++++++++++++++++++++++--------- code/style.css | 72 ++++++++++++++++ 4 files changed, 359 insertions(+), 81 deletions(-) diff --git a/code/chart.js b/code/chart.js index 6b64feff..407f8a32 100644 --- a/code/chart.js +++ b/code/chart.js @@ -1,26 +1,22 @@ //DOM-selector for the canvas 👇 -const ctx = document.getElementById('chart').getContext('2d') - +const projectsChart = document.getElementById('projectsChart').getContext('2d') //"Draw" the chart here 👇 // what's not working below is commented out // global options -// Chart.defaults.global.defaultFontFamily = 'Lato'; -// Chart.defaults.global.defaultFontSize = 18; -// Chart.defaults.global.defaultFontColor = 'grey'; +Chart.defaults.font.family = 'Lato'; +Chart.defaults.font.size = 18; +Chart.defaults.color = 'blue'; + const drawProjectsChart = (amount) => { - new Chart(ctx, { + new Chart(projectsChart, { type: 'bar', // bar, horizontalBar, pie, line, doughnut, radar, polarArea data: { labels: ['Completed', 'To do'], datasets: [{ - barPercentage: 1, - barThickness: 100, - maxBarThickness: 200, - minBarLength: 2, - label: 'Projects', + // label: 'Projects', data: [ amount, 19 - amount @@ -34,32 +30,96 @@ const drawProjectsChart = (amount) => { hoverBorderWidth: 5, hoverBorderColor: 'brown' } - ] + ] + }, + options: { + indexAxis: 'y', // for horizontal bar graph instead of vertical + plugins: { + title: { + display: true, + text: 'Projects', + fontSize: 24 + }, + legend: { + display: false, + position: 'top', + labels: { + fontColor: 'red' + } + }, + layout: { + padding: { + left: 50, + right: 0, + bottom: 0, + top: 0 + } + }, + tooltip: { + enabled: true + } + } } - // options: { - // title: { - // display: true, - // text: 'Largest Cities in Massachussets', - // fontSize:24 - // }, - // legend:{ - // display:false, - // position:'right', - // labels:{ - // fontColor:'black' - // } - // layout: { - // padding: { - // left: 0, - // right: 0, - // bottom: 0, - // top: 0 - // } - // }, - // tooltips:{ - // enabled:false - // } - // } }) } + +const drawLanguagesChart = (htmlPercentage, cssPercentage, jsPercentage, idChart) => { + + const languagesChart = document.getElementById(idChart).getContext('2d') + + + new Chart(languagesChart, { + type: 'pie', // bar, horizontalBar, pie, line, doughnut, radar, polarArea + data: { + labels: ['HTML', 'CSS', 'JavaScript'], + datasets: [{ + label: 'Languages', // où cela apparaît-il?? + data: [ + htmlPercentage, + cssPercentage, + jsPercentage + ], + backgroundColor: [ + 'red', + 'green', + 'yellow' + ], + borderWidth: 2, + borderColor: 'black', + hoverBorderWidth: 5, + hoverBorderColor: 'brown' + } + ] + }, + options: { + plugins: { + title: { + display: false, + text: 'Languages', + fontSize: 24 + }, + legend: { + display: false, + position: 'top', + labels: { + fontColor: 'red' + } + }, + layout: { + padding: { + left: 0, + right: 0, + bottom: 0, + top: 0 + } + }, + tooltip: { + enabled: true + } + } + } + }) +} + + diff --git a/code/index.html b/code/index.html index 63e6a1e9..5407a61b 100644 --- a/code/index.html +++ b/code/index.html @@ -6,9 +6,12 @@ Project GitHub Tracker + + + + - @@ -19,10 +22,12 @@

    GitHub Tracker

    -
    - +
    +
    + + diff --git a/code/script.js b/code/script.js index db3bcfdf..2d2ecf70 100644 --- a/code/script.js +++ b/code/script.js @@ -3,13 +3,34 @@ const API_USER = `https://api.github.com/users/${username}` const API_REPOS = `https://api.github.com/users/${username}/repos` // const or let ? const profile = document.getElementById('profile') const projects = document.getElementById('projects') +const projects2 = document.getElementById('projects2') + + + + +function openCity(evt, cityName) { + var i, tabcontent, tablinks + tabcontent = document.getElementsByClassName("tabcontent") + for (i = 0; i < tabcontent.length; i++) { + tabcontent[i].style.display = "none" + } + tablinks = document.getElementsByClassName("tablinks") + for (i = 0; i < tablinks.length; i++) { + tablinks[i].className = tablinks[i].className.replace(" active", "") + } + document.getElementById(cityName).style.display = "block" + evt.currentTarget.className += " active" +} + + + const createProfile = () => { - fetch(API_USER) + fetch(API_USER, options) .then(res => res.json()) .then(data => { profile.innerHTML = ` @@ -19,74 +40,194 @@ const createProfile = () => { }) } +const addCommits = (repo) => { + fetch(`https://api.github.com/repos/${username}/${repo.name}/commits`, options) + .then(res => res.json()) + .then(data => { + const userCommits = data.filter((item) => item.commit.author.name === 'Nadia Lefebvre') + // document.getElementById(repo.name).innerHTML += ` + //

    Number of commits from the user: ${userCommits.length} on a total of ${data.length}

    + //

    Commit messages:

    + // ` + + // TEST + document.getElementById(`${repo.name}-repoInfos`).innerHTML += ` +

    Number of commits from the user: ${userCommits.length} on a total of ${data.length}

    + ` + + + const userFiveLastCommits = userCommits.slice(1, 5) + console.log(userFiveLastCommits) + userFiveLastCommits.forEach(item => { + // document.getElementById(repo.name).innerHTML += ` + //
  • ${item.commit.message}
  • + // ` + + // TEST + document.getElementById(`${repo.name}-repoCommitMessages`).innerHTML += ` +
  • ${item.commit.message}
  • + ` + + + + + + }) + }) +} + +const addLanguageChart = (repo) => { + + fetch(`https://api.github.com/repos/${username}/${repo.name}/languages`, options) + .then(res => res.json()) + .then(languages => { + + // gros paquet de gogosses pour calculer les pourcentages : reste à ajouter le % maintenant... + const html = languages.HTML === undefined ? 0 : languages.HTML + const css = languages.CSS === undefined ? 0 : languages.CSS + const js = languages.JavaScript === undefined ? 0 : languages.JavaScript + const htmlPercentage = Math.round(html / (html + css + js) * 1000) / 10 + const cssPercentage = Math.round(css / (html + css + js) * 1000) / 10 + const jsPercentage = Math.round(js / (html + css + js) * 1000) / 10 + + const idChart = `${repo.name}Chart` + + // TEST + document.getElementById(`${repo.name}-repoLanguages`).innerHTML += ` +
    + +
    +` + + + + + // document.getElementById(repo.name).innerHTML += ` + //
    + // + //
    + // ` + drawLanguagesChart(htmlPercentage, cssPercentage, jsPercentage, idChart) + }) +} + + +// À ARRANGER +const addPullComments = (repo) => { + fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls`, options) + .then(res => res.json()) + .then(data => { + const userPulls = data.filter((item) => item.user.login === 'nadialefebvre') + userPulls.forEach(pull => { + fetch(pull.review_comments_url) + .then(res => res.json()) + .then(data => { + console.log(repo.name) + console.log(data) + data.forEach(comment => { + // document.getElementById(repo.name).innerHTML += ` + //

    Comments from PR: ${comment.body}

    + // ` + // TEST + document.getElementById(`${repo.name}-repoPullComments`).innerHTML = ` +
  • ${comment.body}
  • +` + + + }) + }) + }) + }) +} + const createRepoCard = () => { - fetch(API_REPOS) // options object is passed as 2nd argument to fetch() function. // TO REMOVE BEFORE GIT PUSH + fetch(API_REPOS, options) // options object is passed as 2nd argument to fetch() function. // TO REMOVE BEFORE GIT PUSH .then(res => res.json()) .then(data => { const filteredRepos = data.filter(repo => repo.fork === true && repo.name.startsWith('project-')) drawProjectsChart(filteredRepos.length) filteredRepos.forEach(repo => { const options = { day: 'numeric', month: 'long', year: 'numeric' } + // projects.innerHTML += ` + //
    + //

    Name: ${repo.name}

    + //

    URL: ${repo.name}

    + //

    Default branch: ${repo.default_branch}

    + //

    Last push: ${new Date(repo.pushed_at).toLocaleDateString('en-GB', options)}

    + //
    + // ` + + + + + // TEST projects.innerHTML += ` -
    -

    Repo name: ${repo.name}

    -

    Repo URL: ${repo.name}

    -

    Default branch: ${repo.default_branch}

    -

    Repo last push: ${new Date(repo.pushed_at).toLocaleDateString('en-GB', options)}

    +
    +
    + + + + +
    + +
    +

    Name: ${repo.name}

    +
    +
    + +
    +

    Languages

    +
    +
    + +
    +

    Commit messages

    +
    +
    + +
    +

    Code review comments:

    +
    (none)
    +
    ` - fetch(`https://api.github.com/repos/${username}/${repo.name}/commits`) - .then(res => res.json()) - .then(data => { - console.log(data) - const userCommits = data.filter((item) => item.commit.author.name === 'Nadia Lefebvre') - document.getElementById(repo.name).innerHTML += ` -

    Number of commits from the user: ${userCommits.length} on a total of ${data.length}

    -

    Commit messages:

    - ` - userCommits.forEach(item => { - document.getElementById(repo.name).innerHTML += ` -
  • ${item.commit.message}
  • - ` - }) - }) + document.getElementById(`${repo.name}-repoInfos`).innerHTML += ` +

    URL: ${repo.name}

    +

    Default branch : ${repo.default_branch}

    +

    Last push: ${new Date(repo.pushed_at).toLocaleDateString('en-GB', options)}

    + ` + + // Get the element with id="defaultOpen" and click on it + document.getElementById(`${repo.name}-defaultOpen`).click() + + + + + + addCommits(repo) + addPullComments(repo) + addLanguageChart(repo) + + }) }) } -createProfile() -createRepoCard() -//Remember to pass along your filtered repos as an argument when -//you are calling this function -const getPullRequests = (repos) => { - //Get all the PRs for each project. - repos.forEach(repo => { - fetch('https://api.github.com/repos/technigo/' + repo.name + '/pulls') - .then(res => res.json()) - .then(data => { - //TODO - //1. Find only the PR that you made by comparing pull.user.login - // with repo.owner.login - //2. Now you're able to get the commits for each repo by using - // the commits_url as an argument to call another function - //3. You can also get the comments for each PR by calling - // another function with the review_comments_url as argument - }) - }) - } +createProfile() +createRepoCard() diff --git a/code/style.css b/code/style.css index 0bd4c055..498f475d 100644 --- a/code/style.css +++ b/code/style.css @@ -2,8 +2,80 @@ body { background: #FFECE9; } +img { + max-width: 50px; +} + .repo { border: solid 1px red; padding: 10px; margin-bottom: 10px; +} + +.chart-container { + width: 50%; + min-width: 100px; + max-width: 200px; +} + +.chart-container.main { + width: 100%; + min-width: 100px; + max-width: 400px; + +} + +.projects { + display: flex; + flex-direction: column; +} + + + +* {box-sizing: border-box} +body {font-family: "Lato", sans-serif;} + +/* Style the tab */ +.tab { + float: left; + border: 1px solid #ccc; + background-color: #f1f1f1; + width: 30%; + height: 300px; +} + +/* Style the buttons inside the tab */ +.tab button { + display: block; + background-color: inherit; + color: black; + padding: 22px 16px; + width: 100%; + border: none; + outline: none; + text-align: left; + cursor: pointer; + transition: 0.3s; + font-size: 17px; +} + +/* Change background color of buttons on hover */ +.tab button:hover { + background-color: #ddd; +} + +/* Create an active/current "tab button" class */ +.tab button.active { + background-color: #ccc; +} + +/* Style the tab content */ +.tabcontent { + float: left; + background-color: #f1f1f1; + padding: 0px 12px; + border: 1px solid #ccc; + width: 70%; + border-left: none; + height: 300px; } \ No newline at end of file From 77ca55ecb26a256d88d4e950a2c9d2487ad24529 Mon Sep 17 00:00:00 2001 From: Nadia Lefebvre <95084122+nadialefebvre@users.noreply.github.com> Date: Sun, 20 Feb 2022 18:00:48 +0100 Subject: [PATCH 05/28] added some sorting options --- code/script.js | 269 +++++++++++++++++++++++-------------------------- code/style.css | 4 +- 2 files changed, 131 insertions(+), 142 deletions(-) diff --git a/code/script.js b/code/script.js index 2d2ecf70..e3898f15 100644 --- a/code/script.js +++ b/code/script.js @@ -1,34 +1,30 @@ const username = 'nadialefebvre' const API_USER = `https://api.github.com/users/${username}` -const API_REPOS = `https://api.github.com/users/${username}/repos` // const or let ? +const API_REPOS = `https://api.github.com/users/${username}/repos` const profile = document.getElementById('profile') const projects = document.getElementById('projects') -const projects2 = document.getElementById('projects2') -function openCity(evt, cityName) { - var i, tabcontent, tablinks - tabcontent = document.getElementsByClassName("tabcontent") - for (i = 0; i < tabcontent.length; i++) { - tabcontent[i].style.display = "none" +const openTab = (event, tabName) => { + let i + let tabContent = event.currentTarget.parentNode.parentNode.getElementsByClassName("tab-content") + for (i = 0; i < tabContent.length; i++) { + tabContent[i].style.display = "none" } - tablinks = document.getElementsByClassName("tablinks") - for (i = 0; i < tablinks.length; i++) { - tablinks[i].className = tablinks[i].className.replace(" active", "") + let tabButton = event.currentTarget.parentNode.getElementsByClassName("tab-button") + for (i = 0; i < tabButton.length; i++) { + tabButton[i].className = tabButton[i].className.replace(" active", "") } - document.getElementById(cityName).style.display = "block" - evt.currentTarget.className += " active" + document.getElementById(tabName).style.display = "block" + event.currentTarget.className += " active" } - - - const createProfile = () => { fetch(API_USER, options) .then(res => res.json()) @@ -40,38 +36,84 @@ const createProfile = () => { }) } -const addCommits = (repo) => { - fetch(`https://api.github.com/repos/${username}/${repo.name}/commits`, options) +const createRepoCard = () => { + fetch(API_REPOS, options) // options object is passed as 2nd argument to fetch() function. // TO REMOVE BEFORE GIT PUSH .then(res => res.json()) .then(data => { - const userCommits = data.filter((item) => item.commit.author.name === 'Nadia Lefebvre') - // document.getElementById(repo.name).innerHTML += ` - //

    Number of commits from the user: ${userCommits.length} on a total of ${data.length}

    - //

    Commit messages:

    - // ` + const filteredRepos = data.filter(repo => repo.fork === true && repo.name.startsWith('project-')) +console.log(filteredRepos) + // sortByDate(filteredRepos) + // sortByReverseDate(filteredRepos) + // sortByReverseName(filteredRepos) + // sortByCommits() - // TEST - document.getElementById(`${repo.name}-repoInfos`).innerHTML += ` -

    Number of commits from the user: ${userCommits.length} on a total of ${data.length}

    - ` + drawProjectsChart(filteredRepos.length) + filteredRepos.forEach(repo => { + const options = { day: 'numeric', month: 'long', year: 'numeric' } + projects.innerHTML += ` +
    +
    + + + + +
    +
    +

    Name: ${repo.name}

    +
    +
    - const userFiveLastCommits = userCommits.slice(1, 5) - console.log(userFiveLastCommits) - userFiveLastCommits.forEach(item => { - // document.getElementById(repo.name).innerHTML += ` - //
  • ${item.commit.message}
  • - // ` + - // TEST - document.getElementById(`${repo.name}-repoCommitMessages`).innerHTML += ` -
  • ${item.commit.message}
  • - ` + + + +
    + ` + document.getElementById(`${repo.name}-repoInfos`).innerHTML += ` +

    URL: ${repo.name}

    +

    Default branch : ${repo.default_branch}

    +

    Last push: ${new Date(repo.pushed_at).toLocaleDateString('en-GB', options)}

    + ` + // Get the element with id="defaultOpen" and click on it + document.getElementById(`${repo.name}-defaultOpen`).click() + addCommits(repo) + fetchPullRequest(repo) + addLanguageChart(repo) + }) + }) +} +const addCommits = (repo) => { + fetch(`https://api.github.com/repos/${username}/${repo.name}/commits`, options) + .then(res => res.json()) + .then(data => { + // why item.author.login === username doesn't work here?? + const userCommits = data.filter((item) => item.commit.author.name === 'Nadia Lefebvre') + + document.getElementById(`${repo.name}-repoInfos`).innerHTML += ` +

    Number of commits from the user: ${userCommits.length} on a total of ${data.length}

    + ` + + const userFiveLastCommits = userCommits.slice(1, 5) + userFiveLastCommits.forEach(item => { + document.getElementById(`${repo.name}-repoCommitMessages`).innerHTML += ` +
  • ${item.commit.message}
  • + ` }) }) } @@ -81,8 +123,7 @@ const addLanguageChart = (repo) => { fetch(`https://api.github.com/repos/${username}/${repo.name}/languages`, options) .then(res => res.json()) .then(languages => { - - // gros paquet de gogosses pour calculer les pourcentages : reste à ajouter le % maintenant... + // many variables for percentage calculation : needs to find a way to add % now... const html = languages.HTML === undefined ? 0 : languages.HTML const css = languages.CSS === undefined ? 0 : languages.CSS const js = languages.JavaScript === undefined ? 0 : languages.JavaScript @@ -92,142 +133,88 @@ const addLanguageChart = (repo) => { const idChart = `${repo.name}Chart` - // TEST document.getElementById(`${repo.name}-repoLanguages`).innerHTML += `
    ` - - - - // document.getElementById(repo.name).innerHTML += ` - //
    - // - //
    - // ` drawLanguagesChart(htmlPercentage, cssPercentage, jsPercentage, idChart) }) } - - -// À ARRANGER -const addPullComments = (repo) => { - fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls`, options) +const fetchPullRequest = (repo) => { + // fix it because only 1 page of 30 PR is fetched, link: https://docs.github.com/en/rest/reference/pulls#list-pull-requests (added ?per_page=100&page=1 to URL, but it doesn't fix the problem for when the PR will go to page 2-3-4...) + fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100&page=1`, options) .then(res => res.json()) .then(data => { - const userPulls = data.filter((item) => item.user.login === 'nadialefebvre') + const userPulls = data.filter((item) => item.user.login === username) userPulls.forEach(pull => { fetch(pull.review_comments_url) .then(res => res.json()) .then(data => { - console.log(repo.name) - console.log(data) - data.forEach(comment => { - // document.getElementById(repo.name).innerHTML += ` - //

    Comments from PR: ${comment.body}

    - // ` - - - // TEST - document.getElementById(`${repo.name}-repoPullComments`).innerHTML = ` -
  • ${comment.body}
  • -` - - - }) + const reviewID = data[0].pull_request_review_id + addCodeReviewInfos(repo, pull, reviewID) }) }) }) } +const addCodeReviewInfos = (repo, pull, reviewID) => { - - -const createRepoCard = () => { - fetch(API_REPOS, options) // options object is passed as 2nd argument to fetch() function. // TO REMOVE BEFORE GIT PUSH + fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls/${pull.number}/reviews/${reviewID}`) .then(res => res.json()) .then(data => { - const filteredRepos = data.filter(repo => repo.fork === true && repo.name.startsWith('project-')) - drawProjectsChart(filteredRepos.length) - filteredRepos.forEach(repo => { - const options = { day: 'numeric', month: 'long', year: 'numeric' } - // projects.innerHTML += ` - //
    - //

    Name: ${repo.name}

    - //

    URL: ${repo.name}

    - //

    Default branch: ${repo.default_branch}

    - //

    Last push: ${new Date(repo.pushed_at).toLocaleDateString('en-GB', options)}

    - //
    - // ` - - - - - // TEST - projects.innerHTML += ` -
    -
    - - - - -
    - -
    -

    Name: ${repo.name}

    -
    -
    - -
    -

    Languages

    -
    -
    - -
    -

    Commit messages

    -
    -
    - -
    -

    Code review comments:

    -
    (none)
    -
    -
    - ` - - document.getElementById(`${repo.name}-repoInfos`).innerHTML += ` -

    URL: ${repo.name}

    -

    Default branch : ${repo.default_branch}

    -

    Last push: ${new Date(repo.pushed_at).toLocaleDateString('en-GB', options)}

    - ` - - // Get the element with id="defaultOpen" and click on it - document.getElementById(`${repo.name}-defaultOpen`).click() - - - - - - addCommits(repo) - addPullComments(repo) - addLanguageChart(repo) - - - }) + document.getElementById(`${repo.name}-repoPullComments`).innerHTML = ` +

    ${data.body}

    +

    Full code review

    + ` }) } +const sortByDate = (filteredRepos) => { + filteredRepos.sort(function (a, b) { + return new Date(a.created_at) - new Date(b.created_at) + }) +} +const sortByReverseDate = (filteredRepos) => { + filteredRepos.sort(function (a, b) { + return new Date(b.created_at) - new Date(a.created_at) + }) +} +const sortByReverseName = (filteredRepos) => { + filteredRepos.sort(function (a, b) { + var nameA = a.name.toUpperCase() // ignore upper and lowercase + var nameB = b.name.toUpperCase() // ignore upper and lowercase + if (nameA > nameB) { + return -1 + } + if (nameA < nameB) { + return 1 + } + // names must be equal + return 0 + }) +} +// const sortByCommits = () => { +// fetch(`https://api.github.com/repos/${username}/${repo.name}/commits`, options) +// .then(res => res.json()) +// .then(data => { +// // why item.author.login === username doesn't work here?? +// const userCommits = data.filter((item) => item.commit.author.name === 'Nadia Lefebvre') +// console.log(userCommits.length) - +// userCommits.sort(function (a, b) { +// return a.length - b.length +// }) +// }) +// } createProfile() -createRepoCard() +createRepoCard() \ No newline at end of file diff --git a/code/style.css b/code/style.css index 498f475d..7d69bdbf 100644 --- a/code/style.css +++ b/code/style.css @@ -42,6 +42,7 @@ body {font-family: "Lato", sans-serif;} background-color: #f1f1f1; width: 30%; height: 300px; + margin-bottom: 20px; } /* Style the buttons inside the tab */ @@ -70,7 +71,7 @@ body {font-family: "Lato", sans-serif;} } /* Style the tab content */ -.tabcontent { +.tab-content { float: left; background-color: #f1f1f1; padding: 0px 12px; @@ -78,4 +79,5 @@ body {font-family: "Lato", sans-serif;} width: 70%; border-left: none; height: 300px; + overflow: auto; } \ No newline at end of file From af62a90ecdc522aaba8d6cbbeaacc0db031ae54f Mon Sep 17 00:00:00 2001 From: Nadia Lefebvre <95084122+nadialefebvre@users.noreply.github.com> Date: Sun, 20 Feb 2022 21:02:40 +0100 Subject: [PATCH 06/28] added a dropdown for selecting sorting option --- code/index.html | 7 +++ code/script.js | 112 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 90 insertions(+), 29 deletions(-) diff --git a/code/index.html b/code/index.html index 5407a61b..1ba1bf1b 100644 --- a/code/index.html +++ b/code/index.html @@ -27,6 +27,13 @@

    GitHub Tracker

    + + diff --git a/code/script.js b/code/script.js index e3898f15..74343534 100644 --- a/code/script.js +++ b/code/script.js @@ -3,6 +3,8 @@ const API_USER = `https://api.github.com/users/${username}` const API_REPOS = `https://api.github.com/users/${username}/repos` const profile = document.getElementById('profile') const projects = document.getElementById('projects') +const sortMenu = document.getElementById('sortMenu') + @@ -25,6 +27,7 @@ const openTab = (event, tabName) => { + const createProfile = () => { fetch(API_USER, options) .then(res => res.json()) @@ -36,18 +39,36 @@ const createProfile = () => { }) } -const createRepoCard = () => { +const createRepoCard = (reposToUse = null) => { fetch(API_REPOS, options) // options object is passed as 2nd argument to fetch() function. // TO REMOVE BEFORE GIT PUSH .then(res => res.json()) .then(data => { - const filteredRepos = data.filter(repo => repo.fork === true && repo.name.startsWith('project-')) -console.log(filteredRepos) - // sortByDate(filteredRepos) - // sortByReverseDate(filteredRepos) - // sortByReverseName(filteredRepos) - // sortByCommits() - - drawProjectsChart(filteredRepos.length) + const selectSorting = () => { + console.log(sortMenu.value) + if (sortMenu.value === 'Z to A') { + sortByNameZA(filteredRepos) + } else if (sortMenu.value === 'Recent to old') { + sortByDateRecentOld(filteredRepos) + } else if (sortMenu.value === 'Old to recent') { + sortByDateOldRecent(filteredRepos) + } else { + sortByNameAZ(filteredRepos) + } + console.log(filteredRepos) + projects.innerHTML = '' + createRepoCard(filteredRepos) + } + + let filteredRepos + if (reposToUse === null) + { + filteredRepos = data.filter(repo => repo.fork === true && repo.name.startsWith('project-')) + sortMenu.addEventListener('change', selectSorting) + } else { + filteredRepos = reposToUse + } + + //drawProjectsChart(filteredRepos.length) filteredRepos.forEach(repo => { const options = { day: 'numeric', month: 'long', year: 'numeric' } projects.innerHTML += ` @@ -109,8 +130,9 @@ const addCommits = (repo) => {

    Number of commits from the user: ${userCommits.length} on a total of ${data.length}

    ` - const userFiveLastCommits = userCommits.slice(1, 5) - userFiveLastCommits.forEach(item => { + // const userFiveLastCommits = userCommits.slice(1, 5) + // userFiveLastCommits.forEach(item => { + userCommits.forEach(item => { document.getElementById(`${repo.name}-repoCommitMessages`).innerHTML += `
  • ${item.commit.message}
  • ` @@ -174,23 +196,25 @@ const addCodeReviewInfos = (repo, pull, reviewID) => { } - -const sortByDate = (filteredRepos) => { - filteredRepos.sort(function (a, b) { - return new Date(a.created_at) - new Date(b.created_at) - }) -} - -const sortByReverseDate = (filteredRepos) => { - filteredRepos.sort(function (a, b) { - return new Date(b.created_at) - new Date(a.created_at) +const sortByNameAZ = (filteredRepos) => { + filteredRepos.sort(function(a, b) { + const nameA = a.name.toLowerCase() // ignore upper and lowercase + const nameB = b.name.toLowerCase() // ignore upper and lowercase + if (nameA < nameB) { + return -1 + } + if (nameA > nameB) { + return 1 + } + // names must be equal + return 0 }) } -const sortByReverseName = (filteredRepos) => { - filteredRepos.sort(function (a, b) { - var nameA = a.name.toUpperCase() // ignore upper and lowercase - var nameB = b.name.toUpperCase() // ignore upper and lowercase +const sortByNameZA = (filteredRepos) => { + filteredRepos.sort(function(a, b) { + const nameA = a.name.toLowerCase() // ignore upper and lowercase + const nameB = b.name.toLowerCase() // ignore upper and lowercase if (nameA > nameB) { return -1 } @@ -202,6 +226,39 @@ const sortByReverseName = (filteredRepos) => { }) } +const sortByDateRecentOld = (filteredRepos) => { + filteredRepos.sort(function(a, b) { + return new Date(b.created_at) - new Date(a.created_at) + }) +} + +const sortByDateOldRecent = (filteredRepos) => { + filteredRepos.sort(function(a, b) { + return new Date(a.created_at) - new Date(b.created_at) + }) +} + + +// const selectSorting = (filteredRepos) => { +// console.log(sortMenu.value) +// if (sortMenu.value === 'Z to A') { +// sortByNameZA(filteredRepos) +// } else if (sortMenu.value === 'Recent to old') { +// sortByDateRecentOld(filteredRepos) +// } else if (sortMenu.value === 'Old to recent') { +// sortByDateOldRecent(filteredRepos) +// } else { +// sortByNameAZ(filteredRepos) +// } +// } + + +createProfile() +createRepoCard() + + + +// sortByCommits() // const sortByCommits = () => { // fetch(`https://api.github.com/repos/${username}/${repo.name}/commits`, options) // .then(res => res.json()) @@ -214,7 +271,4 @@ const sortByReverseName = (filteredRepos) => { // return a.length - b.length // }) // }) -// } - -createProfile() -createRepoCard() \ No newline at end of file +// } \ No newline at end of file From e32befa7fd936eb841710c715bbe2e612976ac6d Mon Sep 17 00:00:00 2001 From: Nadia Lefebvre <95084122+nadialefebvre@users.noreply.github.com> Date: Mon, 21 Feb 2022 20:42:35 +0100 Subject: [PATCH 07/28] added some styling --- code/chart.js | 129 +++++++++++++++++++++++++++++++++-------------- code/index.html | 31 ++++++------ code/script.js | 124 ++++++++++++++++++++------------------------- code/style.css | 130 ++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 264 insertions(+), 150 deletions(-) diff --git a/code/chart.js b/code/chart.js index 407f8a32..0dd17d03 100644 --- a/code/chart.js +++ b/code/chart.js @@ -5,16 +5,15 @@ const projectsChart = document.getElementById('projectsChart').getContext('2d') // what's not working below is commented out // global options -Chart.defaults.font.family = 'Lato'; -Chart.defaults.font.size = 18; -Chart.defaults.color = 'blue'; - +Chart.defaults.font.family = 'Lato' +Chart.defaults.font.size = 18 +Chart.defaults.color = 'white' const drawProjectsChart = (amount) => { new Chart(projectsChart, { type: 'bar', // bar, horizontalBar, pie, line, doughnut, radar, polarArea data: { - labels: ['Completed', 'To do'], + labels: ['Done', 'To do'], datasets: [{ // label: 'Projects', data: [ @@ -22,18 +21,27 @@ const drawProjectsChart = (amount) => { 19 - amount ], backgroundColor: [ - 'red', - 'green' - ], - borderWidth: 2, - borderColor: 'black', - hoverBorderWidth: 5, - hoverBorderColor: 'brown' + '#DBE2EF', + '#3F72AF' + ] } ] }, options: { indexAxis: 'y', // for horizontal bar graph instead of vertical + scales: { + // grid lines are not shown for y axis + y: { + grid: { + display: false, + borderColor: 'white', + } + }, + // x axis is not shown + x: { + display: false, + } + }, plugins: { title: { display: true, @@ -44,7 +52,7 @@ const drawProjectsChart = (amount) => { display: false, position: 'top', labels: { - fontColor: 'red' + fontColor: '#112D4E' } }, layout: { @@ -56,7 +64,19 @@ const drawProjectsChart = (amount) => { } }, tooltip: { - enabled: true + backgroundColor: '#F9F7F7', + bodyColor: '#112D4E', + titleColor: '#112D4E', + titleAlign: 'center', + bodyAlign: 'center', + titleFont: { + weight: '700' + }, + bodyFont: { + weight: '700' + }, + cornerRadius: 4, + displayColors: false } } } @@ -64,47 +84,59 @@ const drawProjectsChart = (amount) => { } -const drawLanguagesChart = (htmlPercentage, cssPercentage, jsPercentage, idChart) => { +// const titleTooltip = (tooltipItems) => { +// return 'Test' +// } +// const labelTooltip = () + +const drawLanguagesChart = (html, css, js, idChart) => { const languagesChart = document.getElementById(idChart).getContext('2d') new Chart(languagesChart, { - type: 'pie', // bar, horizontalBar, pie, line, doughnut, radar, polarArea + type: 'polarArea', // bar, horizontalBar, pie, line, doughnut, radar, polarArea data: { - labels: ['HTML', 'CSS', 'JavaScript'], + labels: ['HTML', 'CSS', 'JS'], datasets: [{ - label: 'Languages', // où cela apparaît-il?? data: [ - htmlPercentage, - cssPercentage, - jsPercentage + html, + css, + js ], backgroundColor: [ - 'red', - 'green', - 'yellow' - ], - borderWidth: 2, - borderColor: 'black', - hoverBorderWidth: 5, - hoverBorderColor: 'brown' + '#DBE2EF', + '#3F72AF', + '#112D4E' + ] } ] }, options: { + scales: { + r: { + ticks: { + display: false // removes vertical numbers + }, + grid: { + display: false // removes circular lines + } + } + }, plugins: { title: { - display: false, - text: 'Languages', - fontSize: 24 + display: false }, legend: { - display: false, - position: 'top', + display: true, + position: 'left', labels: { - fontColor: 'red' - } + color: '#112D4E', + usePointStyle: true, + pointStyle: 'rect', + }, + // removes on click event: not able to strike through a label by clicking on it + onClick: null, }, layout: { padding: { @@ -115,7 +147,30 @@ const drawLanguagesChart = (htmlPercentage, cssPercentage, jsPercentage, idChart } }, tooltip: { - enabled: true + enabled: false, + backgroundColor: '#F9F7F7', + bodyColor: '#112D4E', + titleColor: '#112D4E', + bodyFont: { + weight: '700' + }, + cornerRadius: 4 + // callbacks: { + // body: titleTooltip + + // // label: function(context) { + // // let label = context.dataset.label || ''; + + // // if (label) { + // // label += ': '; + // // } + // // if (context.parsed.y !== null) { + // // label += new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(context.parsed.y); + // // } + // // return label; + // // } + // } + } } } diff --git a/code/index.html b/code/index.html index 1ba1bf1b..d4008756 100644 --- a/code/index.html +++ b/code/index.html @@ -5,38 +5,37 @@ - Project GitHub Tracker - - + + Project GitHub Tracker -

    GitHub Tracker

    -
    -
    -
    -
    - - -
    - -
    +
    + +

    GitHub Tracker

    +
    + +
    +
    - - + +
    + - + diff --git a/code/script.js b/code/script.js index 74343534..86463659 100644 --- a/code/script.js +++ b/code/script.js @@ -1,7 +1,7 @@ const username = 'nadialefebvre' const API_USER = `https://api.github.com/users/${username}` const API_REPOS = `https://api.github.com/users/${username}/repos` -const profile = document.getElementById('profile') +const userProfile = document.getElementById('userProfile') const projects = document.getElementById('projects') const sortMenu = document.getElementById('sortMenu') @@ -28,13 +28,15 @@ const openTab = (event, tabName) => { -const createProfile = () => { + + +const createHeader = () => { fetch(API_USER, options) .then(res => res.json()) .then(data => { - profile.innerHTML = ` -

    ${data.name}

    - + userProfile.innerHTML = ` + +

    ${data.name}

    ` }) } @@ -44,7 +46,6 @@ const createRepoCard = (reposToUse = null) => { .then(res => res.json()) .then(data => { const selectSorting = () => { - console.log(sortMenu.value) if (sortMenu.value === 'Z to A') { sortByNameZA(filteredRepos) } else if (sortMenu.value === 'Recent to old') { @@ -54,60 +55,28 @@ const createRepoCard = (reposToUse = null) => { } else { sortByNameAZ(filteredRepos) } - console.log(filteredRepos) projects.innerHTML = '' createRepoCard(filteredRepos) } let filteredRepos - if (reposToUse === null) - { + if (reposToUse === null) { filteredRepos = data.filter(repo => repo.fork === true && repo.name.startsWith('project-')) + drawProjectsChart(filteredRepos.length) sortMenu.addEventListener('change', selectSorting) } else { filteredRepos = reposToUse - } + } - //drawProjectsChart(filteredRepos.length) filteredRepos.forEach(repo => { - const options = { day: 'numeric', month: 'long', year: 'numeric' } - projects.innerHTML += ` -
    -
    - - - - -
    - -
    -

    Name: ${repo.name}

    -
    -
    - - - - - - -
    - ` + setRepoCardStructure(repo) + const options = { day: 'numeric', month: 'long', year: 'numeric' } document.getElementById(`${repo.name}-repoInfos`).innerHTML += `

    URL: ${repo.name}

    Default branch : ${repo.default_branch}

    Last push: ${new Date(repo.pushed_at).toLocaleDateString('en-GB', options)}

    ` - // Get the element with id="defaultOpen" and click on it document.getElementById(`${repo.name}-defaultOpen`).click() @@ -118,6 +87,38 @@ const createRepoCard = (reposToUse = null) => { }) } +const setRepoCardStructure = (repo) => { + projects.innerHTML += ` +
    +
    + + + + +
    + +
    +

    Name: ${repo.name}

    +
    +
    + + + + + + +
    + ` +} const addCommits = (repo) => { fetch(`https://api.github.com/repos/${username}/${repo.name}/commits`, options) @@ -127,7 +128,7 @@ const addCommits = (repo) => { const userCommits = data.filter((item) => item.commit.author.name === 'Nadia Lefebvre') document.getElementById(`${repo.name}-repoInfos`).innerHTML += ` -

    Number of commits from the user: ${userCommits.length} on a total of ${data.length}

    +

    Number of commits for this fork: ${userCommits.length} on a total of ${data.length}

    ` // const userFiveLastCommits = userCommits.slice(1, 5) @@ -145,23 +146,20 @@ const addLanguageChart = (repo) => { fetch(`https://api.github.com/repos/${username}/${repo.name}/languages`, options) .then(res => res.json()) .then(languages => { - // many variables for percentage calculation : needs to find a way to add % now... + // variables so data will be 0 and not undefined if = 0 const html = languages.HTML === undefined ? 0 : languages.HTML const css = languages.CSS === undefined ? 0 : languages.CSS const js = languages.JavaScript === undefined ? 0 : languages.JavaScript - const htmlPercentage = Math.round(html / (html + css + js) * 1000) / 10 - const cssPercentage = Math.round(css / (html + css + js) * 1000) / 10 - const jsPercentage = Math.round(js / (html + css + js) * 1000) / 10 const idChart = `${repo.name}Chart` document.getElementById(`${repo.name}-repoLanguages`).innerHTML += ` -
    +
    ` - drawLanguagesChart(htmlPercentage, cssPercentage, jsPercentage, idChart) + drawLanguagesChart(html, css, js, idChart) }) } @@ -190,14 +188,14 @@ const addCodeReviewInfos = (repo, pull, reviewID) => { .then(data => { document.getElementById(`${repo.name}-repoPullComments`).innerHTML = `

    ${data.body}

    -

    Full code review

    +

    Pull request with code review

    ` }) } const sortByNameAZ = (filteredRepos) => { - filteredRepos.sort(function(a, b) { + filteredRepos.sort(function (a, b) { const nameA = a.name.toLowerCase() // ignore upper and lowercase const nameB = b.name.toLowerCase() // ignore upper and lowercase if (nameA < nameB) { @@ -212,7 +210,7 @@ const sortByNameAZ = (filteredRepos) => { } const sortByNameZA = (filteredRepos) => { - filteredRepos.sort(function(a, b) { + filteredRepos.sort(function (a, b) { const nameA = a.name.toLowerCase() // ignore upper and lowercase const nameB = b.name.toLowerCase() // ignore upper and lowercase if (nameA > nameB) { @@ -227,33 +225,19 @@ const sortByNameZA = (filteredRepos) => { } const sortByDateRecentOld = (filteredRepos) => { - filteredRepos.sort(function(a, b) { + filteredRepos.sort(function (a, b) { return new Date(b.created_at) - new Date(a.created_at) }) } const sortByDateOldRecent = (filteredRepos) => { - filteredRepos.sort(function(a, b) { + filteredRepos.sort(function (a, b) { return new Date(a.created_at) - new Date(b.created_at) }) } -// const selectSorting = (filteredRepos) => { -// console.log(sortMenu.value) -// if (sortMenu.value === 'Z to A') { -// sortByNameZA(filteredRepos) -// } else if (sortMenu.value === 'Recent to old') { -// sortByDateRecentOld(filteredRepos) -// } else if (sortMenu.value === 'Old to recent') { -// sortByDateOldRecent(filteredRepos) -// } else { -// sortByNameAZ(filteredRepos) -// } -// } - - -createProfile() +createHeader() createRepoCard() diff --git a/code/style.css b/code/style.css index 7d69bdbf..1c7c011d 100644 --- a/code/style.css +++ b/code/style.css @@ -1,55 +1,107 @@ +* { + box-sizing: border-box; +} + body { - background: #FFECE9; + font-family: "Lato", sans-serif; + background-color: #112d4e; + color: white; + padding: 20px; } -img { - max-width: 50px; +a { + color: #3f72af; + font-weight: bold; + text-decoration: none; } -.repo { - border: solid 1px red; - padding: 10px; - margin-bottom: 10px; +.main-page { + display: flex; + flex-direction: column; + justify-content: center; } -.chart-container { - width: 50%; - min-width: 100px; - max-width: 200px; +.header-box { + display: flex; + flex-direction: column; + justify-content: space-between; + align-items: center; } -.chart-container.main { - width: 100%; - min-width: 100px; - max-width: 400px; +.header-box .title { + background-color: #DBE2EF; + padding: 20px; + color: #3f72af; + border-radius: 4px; +} +.user-profile { + text-align: center; } -.projects { +.user-profile img { + max-width: 200px; + border-radius: 50%; +} + +.sorting-dropdown { display: flex; - flex-direction: column; + flex-direction: row; + justify-content: flex-end; } +select { + display: flex; + align-self: center; + border: transparent; + border-radius: 2px; + outline: none; + font-size: inherit; + color: #112d4e; + width: fit-content; + text-align: center; + margin-bottom: 20px; +} + +.languages-chart { + width: 75%; + /* min-width: 250px; + max-width: 300px; */ +} + +.projects-chart { + width: 275px; + /* width: auto; */ + margin-bottom: 20px; +} +.projects { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: space-evenly; + color: #112d4e; +} -* {box-sizing: border-box} -body {font-family: "Lato", sans-serif;} +.tab-card { + margin: 20px; + width: 500px; +} /* Style the tab */ .tab { float: left; - border: 1px solid #ccc; - background-color: #f1f1f1; + /* border: 1px solid #3f72af; */ + background-color: #f9f7f7; width: 30%; height: 300px; - margin-bottom: 20px; } /* Style the buttons inside the tab */ .tab button { display: block; background-color: inherit; - color: black; + color: #112d4e; padding: 22px 16px; width: 100%; border: none; @@ -62,22 +114,46 @@ body {font-family: "Lato", sans-serif;} /* Change background color of buttons on hover */ .tab button:hover { - background-color: #ddd; + background-color: #dbe2ef; } /* Create an active/current "tab button" class */ .tab button.active { - background-color: #ccc; + background-color: #3f72af; + color: white; } /* Style the tab content */ .tab-content { float: left; - background-color: #f1f1f1; + background-color: #f9f7f7; padding: 0px 12px; - border: 1px solid #ccc; + /* border: 1px solid #3f72af; */ width: 70%; border-left: none; height: 300px; overflow: auto; +} + +@media only screen and (min-width: 800px) { + .header-box { + flex-direction: row; + justify-content: space-between; + /* align-items: center; */ + } + + .header-box .title { + width: 175px; +text-align: center; + } + + .user-profile { + width: 275px; + } + + .projects-chart { + width: 275px; + } + + } \ No newline at end of file From 8b11f88ab50967f1a449876f0acd5df6205050ed Mon Sep 17 00:00:00 2001 From: Nadia Lefebvre <95084122+nadialefebvre@users.noreply.github.com> Date: Tue, 22 Feb 2022 09:41:42 +0100 Subject: [PATCH 08/28] working on the styling --- code/chart.js | 16 ---------------- code/script.js | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/code/chart.js b/code/chart.js index 0dd17d03..c5fbc6b4 100644 --- a/code/chart.js +++ b/code/chart.js @@ -155,22 +155,6 @@ const drawLanguagesChart = (html, css, js, idChart) => { weight: '700' }, cornerRadius: 4 - // callbacks: { - // body: titleTooltip - - // // label: function(context) { - // // let label = context.dataset.label || ''; - - // // if (label) { - // // label += ': '; - // // } - // // if (context.parsed.y !== null) { - // // label += new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(context.parsed.y); - // // } - // // return label; - // // } - // } - } } } diff --git a/code/script.js b/code/script.js index 86463659..358bb821 100644 --- a/code/script.js +++ b/code/script.js @@ -28,10 +28,17 @@ const openTab = (event, tabName) => { +// TO REMOVE BEFORE GIT PUSH +// TO REMOVE BEFORE GIT PUSH + + + + + const createHeader = () => { - fetch(API_USER, options) + fetch(API_USER) .then(res => res.json()) .then(data => { userProfile.innerHTML = ` @@ -42,7 +49,7 @@ const createHeader = () => { } const createRepoCard = (reposToUse = null) => { - fetch(API_REPOS, options) // options object is passed as 2nd argument to fetch() function. // TO REMOVE BEFORE GIT PUSH + fetch(API_REPOS) // options object is passed as 2nd argument to fetch() function. // TO REMOVE BEFORE GIT PUSH .then(res => res.json()) .then(data => { const selectSorting = () => { @@ -121,7 +128,7 @@ const setRepoCardStructure = (repo) => { } const addCommits = (repo) => { - fetch(`https://api.github.com/repos/${username}/${repo.name}/commits`, options) + fetch(`https://api.github.com/repos/${username}/${repo.name}/commits`) .then(res => res.json()) .then(data => { // why item.author.login === username doesn't work here?? @@ -143,7 +150,7 @@ const addCommits = (repo) => { const addLanguageChart = (repo) => { - fetch(`https://api.github.com/repos/${username}/${repo.name}/languages`, options) + fetch(`https://api.github.com/repos/${username}/${repo.name}/languages`) .then(res => res.json()) .then(languages => { // variables so data will be 0 and not undefined if = 0 @@ -166,7 +173,7 @@ const addLanguageChart = (repo) => { const fetchPullRequest = (repo) => { // fix it because only 1 page of 30 PR is fetched, link: https://docs.github.com/en/rest/reference/pulls#list-pull-requests (added ?per_page=100&page=1 to URL, but it doesn't fix the problem for when the PR will go to page 2-3-4...) - fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100&page=1`, options) + fetch(`https://api.github.com/repos/technigo/${repo.name}/pulls?per_page=100&page=1`) .then(res => res.json()) .then(data => { const userPulls = data.filter((item) => item.user.login === username) From 5483f47fc975428fd71250bdcf3f0e2a18b08fae Mon Sep 17 00:00:00 2001 From: Nadia Lefebvre <95084122+nadialefebvre@users.noreply.github.com> Date: Tue, 22 Feb 2022 15:40:47 +0100 Subject: [PATCH 09/28] still on styling --- code/chart.js | 13 +++-- code/favicon.ico | Bin 0 -> 15406 bytes code/index.html | 40 ++++++++++++---- code/script.js | 64 ++++++++++++------------- code/style.css | 120 ++++++++++++++++++++++++++++++----------------- 5 files changed, 149 insertions(+), 88 deletions(-) create mode 100644 code/favicon.ico diff --git a/code/chart.js b/code/chart.js index c5fbc6b4..30e6611c 100644 --- a/code/chart.js +++ b/code/chart.js @@ -1,16 +1,16 @@ //DOM-selector for the canvas 👇 -const projectsChart = document.getElementById('projectsChart').getContext('2d') +const reposChart = document.getElementById('reposChart').getContext('2d') //"Draw" the chart here 👇 // what's not working below is commented out // global options -Chart.defaults.font.family = 'Lato' +Chart.defaults.font.family = 'Roboto' Chart.defaults.font.size = 18 Chart.defaults.color = 'white' -const drawProjectsChart = (amount) => { - new Chart(projectsChart, { +const drawReposChart = (amount) => { + new Chart(reposChart, { type: 'bar', // bar, horizontalBar, pie, line, doughnut, radar, polarArea data: { labels: ['Done', 'To do'], @@ -129,11 +129,14 @@ const drawLanguagesChart = (html, css, js, idChart) => { }, legend: { display: true, - position: 'left', + position: 'top', labels: { color: '#112D4E', usePointStyle: true, pointStyle: 'rect', + font: { + size: 12 + } }, // removes on click event: not able to strike through a label by clicking on it onClick: null, diff --git a/code/favicon.ico b/code/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..db384e627f6627bdaac40ce526190706d96b3b0f GIT binary patch literal 15406 zcmeHNU2qgd5FV9x;lcMjQ9SbGYYwISDNBn7m6D1|iKhH13*(6p2{8fui3L$pgdjqK z;t$5c3l|cTaJl0M`5`D3^9L6q5H%N~MBpSLm*lSPo@6(>d%N6T_Po6_GgWi5JJUV= zO>a-%_D(Z)7rTcoUCOY{VlOXY?0&{rR@UtOie-#dV&BS@bK}byYrBuJ6-a|D$T8cG zjc)lNFT2q7W_B1WBv`{1cqLgXxpmu~fX1C`r7_-mN}dDvmWTOuIxo*8s{qT?%n{+AFW4ThiQK0v(&qeCtr_8 z*=Lo%Vf#~jeaboUTD1o>WAfS!`mO9i&a3Mb66hp9lZDlRmHd-YDJo)jyYd_bxQ?K~ zTH>vBA>%=k$z?ma?1ju>oo7~dD%Y*WY^Q83mbANXKbQ|^4i$oT*9(T&I;ysD8c)gd zDjM=p#M@E1Rn?z}jfZdD;C^<{|GnWH(V1yZbD`;wie{ksYu-N-o>27*`R3neg#Ly7 z(Iyi6&&dBc@HINZ{ml7>DwUr}rvJGayadPIUagv+{8-a_&v4oF({;2|HJ(iQG=H$C z1&(ihOqNme)&ua{Pfaw$i|^xHd5o|nQ$D>r14Lo!_AMCcYlT0$yf8i%oRbVOu}!k& zQ~Y!Ga4|^!P!^0AH--nHamUlDwI@rych?5+mF7bIyKDIT?#&ND$H8}?$6XHHt}+c_l=vzy>*!Azh*u4F~7HHeQDQ0hIb+yRv?TmqV9BP~X z)iH1?^$>Jn>`U>t(RYEx(of$>@DnXtkM&O9NpP4|=dQjNzkB7loY`$?GZVJijn4nA z2Ft`OMn?`|=GZqQ_Pp$Jq?^>xrn7&VB+S)>o%Ehr*d@K9zGa({`ZB9ce|wLo&vf3a z@vw{W`2H?!bmT944FdS>Z@_ni*ApM)n8FtDd?oYrxGRun{(MF9*K|%H%{$Qi4UfO1 zv1GNs9Q_2(ho^MAjzo0|@=c zevdF~L&AQ9{g|~CJvw1O!hZDZ!fc$E7Tzflgg|JMc%Q!f@`p5;(T$L0wFw`+(=L5+0SP{L`4bL-Bik;TpKmSOt{J zV^sbb9fH<<&O7e)ROr9y{dLfZc~6~R6hTK-0o3L{D(kbM_(|xg*#pB}KA@b*zb^g^ zm)nm+=aPBhkCnXk z*B=0X*{kw@qm_9Duf2AeA^OkcGswAof((7m{QNqz^9OkDNv7s+D05Keb0N}sKg{RP QVD1U!&xj&4U_}G}0`C - + + - Project GitHub Tracker + + Nadia Lefebvre - GitHub Tracker
    - +

    GitHub Tracker

    -
    - +
    +
    -
    - -
    +
    +
    + Created by Nadia Lefebvre + + + + + + + +
    diff --git a/code/script.js b/code/script.js index 358bb821..3974776f 100644 --- a/code/script.js +++ b/code/script.js @@ -1,9 +1,9 @@ const username = 'nadialefebvre' const API_USER = `https://api.github.com/users/${username}` const API_REPOS = `https://api.github.com/users/${username}/repos` -const userProfile = document.getElementById('userProfile') -const projects = document.getElementById('projects') -const sortMenu = document.getElementById('sortMenu') +const userBox = document.getElementById('userBox') +const reposBox = document.getElementById('reposBox') +const sortingDropdown = document.getElementById('sortingDropdown') @@ -11,9 +11,9 @@ const sortMenu = document.getElementById('sortMenu') const openTab = (event, tabName) => { let i - let tabContent = event.currentTarget.parentNode.parentNode.getElementsByClassName("tab-content") - for (i = 0; i < tabContent.length; i++) { - tabContent[i].style.display = "none" + let repoContent = event.currentTarget.parentNode.parentNode.getElementsByClassName("repo-content") + for (i = 0; i < repoContent.length; i++) { + repoContent[i].style.display = "none" } let tabButton = event.currentTarget.parentNode.getElementsByClassName("tab-button") for (i = 0; i < tabButton.length; i++) { @@ -28,10 +28,6 @@ const openTab = (event, tabName) => { -// TO REMOVE BEFORE GIT PUSH -// TO REMOVE BEFORE GIT PUSH - - @@ -41,8 +37,8 @@ const createHeader = () => { fetch(API_USER) .then(res => res.json()) .then(data => { - userProfile.innerHTML = ` - + userBox.innerHTML = ` +

    ${data.name}

    ` }) @@ -53,24 +49,24 @@ const createRepoCard = (reposToUse = null) => { .then(res => res.json()) .then(data => { const selectSorting = () => { - if (sortMenu.value === 'Z to A') { + if (sortingDropdown.value === 'Z to A') { sortByNameZA(filteredRepos) - } else if (sortMenu.value === 'Recent to old') { + } else if (sortingDropdown.value === 'Recent to old') { sortByDateRecentOld(filteredRepos) - } else if (sortMenu.value === 'Old to recent') { + } else if (sortingDropdown.value === 'Old to recent') { sortByDateOldRecent(filteredRepos) } else { sortByNameAZ(filteredRepos) } - projects.innerHTML = '' + reposBox.innerHTML = '' createRepoCard(filteredRepos) } let filteredRepos if (reposToUse === null) { filteredRepos = data.filter(repo => repo.fork === true && repo.name.startsWith('project-')) - drawProjectsChart(filteredRepos.length) - sortMenu.addEventListener('change', selectSorting) + drawReposChart(filteredRepos.length) + sortingDropdown.addEventListener('change', selectSorting) } else { filteredRepos = reposToUse } @@ -78,7 +74,7 @@ const createRepoCard = (reposToUse = null) => { filteredRepos.forEach(repo => { setRepoCardStructure(repo) - const options = { day: 'numeric', month: 'long', year: 'numeric' } + const options = { day: 'numeric', month: 'numeric', year: 'numeric' } document.getElementById(`${repo.name}-repoInfos`).innerHTML += `

    URL: ${repo.name}

    Default branch : ${repo.default_branch}

    @@ -95,32 +91,33 @@ const createRepoCard = (reposToUse = null) => { } const setRepoCardStructure = (repo) => { - projects.innerHTML += ` -
    -
    - + reposBox.innerHTML += ` +
    +
    +
    -
    -

    Name: ${repo.name}

    +
    +

    ${repo.name}

    -