Skip to content

Commit

Permalink
JS code enhancement (publiclab#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
somenath1435 authored and Rishabh570 committed Jan 23, 2020
1 parent 84dc307 commit 5358009
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
16 changes: 8 additions & 8 deletions examples/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ document.addEventListener('DOMContentLoaded', function () {

/*Scroll to top when arrow up clicked BEGIN*/
$(window).scroll(function() {
var height = $(window).scrollTop();
let height = $(window).scrollTop();
if (height > 100) {
$('#back2Top').fadeIn();
} else {
Expand All @@ -28,16 +28,16 @@ document.addEventListener('DOMContentLoaded', function () {
e.preventDefault();
})

var toolbox;
let toolbox;

(function() {

var org = urlHash().getUrlHashParameter('o') || 'publiclab';
var repo = urlHash().getUrlHashParameter('r') || 'plots2';
var ftoLabel = urlHash().getUrlHashParameter('f') || 'first-timers-only';
var candidateLabel = urlHash().getUrlHashParameter('c') || 'fto-candidate';
var recencyLabel = urlHash().getUrlHashParameter('l') || 'week';
var leaderboardState = urlHash().getUrlHashParameter('s') || 'week';
let org = urlHash().getUrlHashParameter('o') || 'publiclab';
let repo = urlHash().getUrlHashParameter('r') || 'plots2';
let ftoLabel = urlHash().getUrlHashParameter('f') || 'first-timers-only';
let candidateLabel = urlHash().getUrlHashParameter('c') || 'fto-candidate';
let recencyLabel = urlHash().getUrlHashParameter('l') || 'week';
let leaderboardState = urlHash().getUrlHashParameter('s') || 'week';

toolbox = CommunityToolbox(org, repo);
if (repo === 'all') {
Expand Down
8 changes: 4 additions & 4 deletions examples/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// NIGHT MODE LOGIC
//===============================================================
$(document).ready(() => {
var body=document.querySelector('body');
var toggleButton=document.getElementById('myonoffswitch');
var toggle = localStorage.getItem('currentToggle');
let body=document.querySelector('body');
let toggleButton=document.getElementById('myonoffswitch');
let toggle = localStorage.getItem('currentToggle');

// Sets images' theme accordingly when the page is loaded
setTimeout(()=> {
Expand Down Expand Up @@ -105,7 +105,7 @@
buttonClickCallbackNightTheme = (e) => {
e.preventDefault();
setTimeout(() => {
var recentContribsSectionImgs = document.getElementsByClassName('recent-contributors')[0].getElementsByTagName("img");
let recentContribsSectionImgs = document.getElementsByClassName('recent-contributors')[0].getElementsByTagName("img");
let check=localStorage.getItem('currentToggle');
let images = [...recentContribsSectionImgs ];
if(check==="night") {
Expand Down
18 changes: 9 additions & 9 deletions examples/urlHash.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
function urlHash() {
function getUrlHashParameter(param) {
var params = getUrlHashParameters();
let params = getUrlHashParameters();
return params[param];

}

function getUrlHashParameters() {

var sPageURL = window.location.hash;
let sPageURL = window.location.hash;
if (sPageURL) sPageURL = sPageURL.split('#')[1];
var pairs = sPageURL.split('&');
var object = {};
let pairs = sPageURL.split('&');
let object = {};
pairs.forEach(function(pair, i) {
pair = pair.split('=');
if (pair[0] != '') object[pair[0]] = pair[1];
Expand All @@ -22,19 +22,19 @@ function urlHash() {
// and transforms to: url.com#paramName=value&paramName1=value
function setUrlHashParameters(params) {

var keys = Object.keys(params);
var values = Object.values(params);
var pairs = [];
let keys = Object.keys(params);
let values = Object.values(params);
let pairs = [];
keys.forEach(function(key, i) {
if (key != '') pairs.push(keys[i] + '=' + values[i]);
});
var hash = pairs.join('&');
let hash = pairs.join('&');
window.location.hash = hash;

}

function setUrlHashParameter(param, value) {
var params = getUrlHashParameters();
let params = getUrlHashParameters();
params[param] = value;
setUrlHashParameters(params);

Expand Down
4 changes: 2 additions & 2 deletions src/UI/contributorsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ function insertContributors(AllContributors){
document.getElementById("spinner-icon").style.display = "none";

let totalContributors = 0;
var usernames = AllContributors.map(function getContributorUsername(c) {
let usernames = AllContributors.map(function getContributorUsername(c) {
return `@${c.login}`;
});
var avatars = AllContributors.map(function getContributorAvatarURL(c) {
let avatars = AllContributors.map(function getContributorAvatarURL(c) {
return `<a href="#" title="${c.login}"><img width="100px" src="${c.avatar_url}"></a>`;
});
totalContributors += AllContributors.length;
Expand Down
4 changes: 2 additions & 2 deletions src/UI/issuesUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var moment = require('moment');


function generateIssueHtml(title, body, githubUrl, repo) {
var repoName = githubUrl.split('/')[4],
let repoName = githubUrl.split('/')[4],
repoUrl = githubUrl.split('/').slice(0, 5).join('/'),
html = '<div class="panel panel-default">\
<div class="panel-heading">\
Expand All @@ -18,7 +18,7 @@ function generateIssueHtml(title, body, githubUrl, repo) {
}

function insertIssue(issue, el) {
var body = "";
let body = "";
body += "<div style='float:right;' class='labels'>"
issue.labels.forEach(function(label) {
body += "<a class='label label-default' href='" + label.url + "' style='background:#" + label.color + ";'>" + label.name + "</a> ";
Expand Down
10 changes: 5 additions & 5 deletions src/scripts/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function generateChart(args) {
args.label = args.label || "";
args.title = args.title || "";

var colors = {
let colors = {
"blue": "rgb(54, 162, 235)",
"red": "rgb(255, 99, 132)",
"green": "rgb(75, 192, 192)",
Expand All @@ -15,9 +15,9 @@ function generateChart(args) {
"purple": "rgb(153, 102, 255)",
"yellow": "rgb(255, 205, 86)"
}
var colorNames = Object.keys(colors);
let colorNames = Object.keys(colors);

var barChartData = {
let barChartData = {
// labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: args.label,
Expand All @@ -28,8 +28,8 @@ function generateChart(args) {
}]
}

var ctx = document.getElementById("canvas").getContext("2d");
var chart = new Chart(ctx, {
let ctx = document.getElementById("canvas").getContext("2d");
let chart = new Chart(ctx, {
type: 'bar',
data: barChartData,
options: {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/contribsUtil/fetchAllRepoContribs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function fetchAllRepoContribs(org, repo) {
return api.Repositories
.getRepoContributors(org, repo, {method: "HEAD", qs: { sort: 'pushed', direction: 'desc', per_page: 100 } })
.then(function gotContribData(contribData) {
var headers = contribData;
let headers = contribData;
if (headers.hasOwnProperty("link")) {
var parsed = parse(headers['link']);
let parsed = parse(headers['link']);
if(parsed.last.page!=undefined) {
totalPages = parseInt(parsed.last.page);
}
Expand All @@ -27,7 +27,7 @@ function fetchAllRepoContribs(org, repo) {
let promises = [];

for(let i = 1; i <= totalPages; i++) {
var currentPromise = api.Repositories
let currentPromise = api.Repositories
.getRepoContributors(org, repo, { method:"GET", qs: { sort: 'pushed', direction: 'desc', per_page: 100, page:i } })
.then(function gotRepoContributors(contributors) {
if (contributors!=undefined && (contributors != null || contributors.length > 0)) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/contribsUtil/storeAllContribsInDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let model_utils = require('../../models/utils')
function storeAllContribsInDb(org) {
let AllContributors = [];
let promises = [];
var contributorSet = new Set([]);
let contributorSet = new Set([]);
return new Promise((resolve, reject) => {
model_utils.getItem('allContributors').then((allContributors) => {
// If all contributors list is not in the database, it makes a fresh call to Github API
Expand Down
12 changes: 6 additions & 6 deletions src/utils/getRepoContributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ options = {
// get list of contributors to a repo in a given time frame
function getRepoContributors(username, repo, options){
commits = getCommitsInRange(username, repo, options);
var result = [];
var lookup = {};
for (var i=0; i<commits.length; i++){
var item = commits[i]["commit"]["author"]["name"];
var name = item;
let result = [];
let lookup = {};
for (let i=0; i<commits.length; i++){
let item = commits[i]["commit"]["author"]["name"];
let name = item;
if(!(name in lookup)){
lookup[name] = 1;
result.push(name);
Expand All @@ -37,7 +37,7 @@ function getCommitsInRange(username, repo, options){

// send GET request
function httpGet(url){
var xmlHttp = new XMLHttpRequest();
let xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", url, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
Expand Down

0 comments on commit 5358009

Please sign in to comment.