x x x
Only portrait mode is currently supported - please rotate your device.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

HTML
<script>

// GLOBAL VARIABLES:
// var isStartupInfoOverlayOpen = false;
var pageName = AJS.params.pageTitle;
var currResultsStart = 0;
var maxResults = 24;
var resultsTotal = 0;

var isSuperAdmin = false;
var currUserGroups = [];
var investorProfileData = null;
var isInvestorUser = false;
var savedStartupsKeys = [];
var investorSavedStartups = null;

// Comments object 
var comment_obj = {};

// Jira profile by key
var startupProfByJK = {};

const getCurrentUserGroups = async () => {
  let res = await jQuery.ajax({
    url: "/rest/api/user/memberof?username=" + AJS.params.remoteUser, 
    type: "get", 
    dataType: 'json', 
    async: true
  }).then(res => res);

  res = res.results;
  let groupNames = [];
  for(var i = 0; i < res.length; i++){
    groupNames.push(res[i].name);
  }

  currUserGroups = groupNames;
  return groupNames;
}

const getInvestorUserProfile = async (userEmail) => {
  let jql = `issuetype = "Investor Profile" AND "VC EWC Account Email" ~ "${userEmail}" ORDER BY created DESC, priority DESC, updated DESC`;

  let jiraResponse = await jQuery.ajax({
    url: "/rest/scriptrunner/latest/custom/searchEWCJiraTicketsPaginated",
    headers: {
      'X-Atlassian-Token' : 'nocheck',
      'Content-type' : 'application/json'
    },
    type: "POST",
    dataType: 'json',
    data: JSON.stringify({
      "jql": jql,
      "startAt": 0,
      "maxResults": 10
    })
  }).then(res => res);

  console.log("Investor Profile Jira Response:", jiraResponse);

  return jiraResponse;
}

const setInvestorVarsWithProfileData = (res) => {
  if (res.issues && res.issues.length > 0) {
    investorProfileData = res.issues[0];

    let savedStartupsStr = investorProfileData.fields.customfield_10902;
    if (savedStartupsStr && savedStartupsStr.length > 0) {
      savedStartupsKeys = savedStartupsStr.split(",");
    } else {
      savedStartupKeys = [];
    }
  }

  console.log("investorProfileData: ", res);
}

const pingVCStartupsWebhook = async () => {
  let url = "https://judging.entrepreneurshipworldcup.com/rest/cb-automation/latest/hooks/ad58eb19b8ef205132eb5696cd38e3e167198488";
  let webhookData = {};
  webhookData["jk"] = investorProfileData.key;
  webhookData["customfield_10902"] = savedStartupsKeys.join(",");

  console.log("webhookData: ", webhookData);

  let response = await jQuery.ajax({
    url: "/rest/scriptrunner/latest/custom/pingJiraWebhook",
    headers: {
      'X-Atlassian-Token' : 'nocheck',
      'Content-type' : 'application/json'
    },
    type: "POST",
    dataType: 'json',
    data: JSON.stringify({
      url, webhookData
    })
  }).then(res => res);

  console.log("pingVCStartupsWebhook Response:", response);
  return response;
}

const setWatchlistButtonOnPopup = () => {
  let watchlistLink = document.getElementById("startup-watchlist-button");

  if (currStartupJiraKey && savedStartupsKeys.includes(currStartupJiraKey)) {
    // Button is "Remove from Watchlist"
    watchlistLink.innerText = "REMOVE FROM WATCHLIST";
    watchlistLink.classList.add("watchlist-remove");
  } else if (currStartupJiraKey) {
    // Button is "Add to Watchlist" 
    watchlistLink.innerText = "ADD TO WATCHLIST";
    watchlistLink.classList.remove("watchlist-remove");
  }
}

const trackAddToWatchlist = () => {
  let startupData = $(".startupcard[data-jk='"+currStartupJiraKey+"']").data();
  console.log("trackAddToWatchlist startupData:", startupData);

  if (!startupData) {
    return;
  }

  let companyName = startupData.name;
  let companyCountry = startupData.country; 
  let verticals = startupData.verticals ? startupData.verticals : "N/A"; 
  let stage = startupData.stage; 
  let subs = startupData.sub ? startupData.sub : "N/A"; 
  let numberOfUsers = startupData.users ? parseInt(startupData.users) : "N/A";
  let arr = startupData.arr ? parseInt(startupData.arr.replace(/,|\$/g, "")) : "N/A";
  let raised = startupData.raised ? startupData.raised : "N/A";
  let founded = startupData.founded ? startupData.founded : "N/A"; 
  let teamSize = startupData.teamsize ? parseInt(startupData.teamsize) : "N/A";

  let payload = {
    companyName, companyCountry, verticals, stage, subs, numberOfUsers, arr, raised, founded, teamSize
  }

  console.log("TRACKADDTOWATCHLIST: ", payload);

  analytics.track("AddedToWatchlist", payload);
}

const handleWatchlistButtonClick = () => {
  console.log("currStartupJiraKey: ", currStartupJiraKey);

  if (currStartupJiraKey && savedStartupsKeys.includes(currStartupJiraKey)) {
    // Remove startup from watchlist
    console.log("REMOVE FROM WATCHLIST");
    let newKeys = [];
    savedStartupsKeys.forEach(key => {
      if (key !== currStartupJiraKey) {
        newKeys.push(key);
      }
    });
    savedStartupsKeys = newKeys;
    console.log(newKeys);
    console.log("NEW SAVED STARTUP KEYS:", savedStartupsKeys);

    pingVCStartupsWebhook().then(() => {
      setWatchlistButtonOnPopup();
    });
  } else if (currStartupJiraKey) {
    // Add startup to Watchlist
    savedStartupsKeys.push(currStartupJiraKey);
    console.log("ADD TO WATCHLIST");

    trackAddToWatchlist();

    pingVCStartupsWebhook().then(() => {
      setWatchlistButtonOnPopup();
    });
  }
}

const countryObj = {
  "Afghanistan": "AF", "Albania": "AL", "Algeria": "DZ", "Andorra": "AD", "Angola": "AO", "Antigua Barbuda": "AG", 
  "Argentina": "AR", "Armenia": "AM", "Aruba": "AW", "Australia": "AU", "Austria": "AT", "Azerbaijan": "AZ", "Bahamas": "BS", 
  "Bahrain": "BH", "Bangladesh": "BD", "Barbados": "BB", "Belarus": "BY", "Belgium": "BE", "Belize": "BZ", "Benin": "BJ", 
  "Bermuda": "BM", "Bhutan": "BT", "Bolivia": "BO", "Bonaire": "BQ", "Bosnia and Herzegovina": "BA", "Botswana": "BW", 
  "Brazil": "BR", "Brunei": "BN", "Bulgaria": "BG", "Burkina Faso": "BF", "Burundi": "BI", "Cambodia": "KH", "Cameroon": "CM", 
  "Canada": "CA", "CapeVerde": "CV", "Central African Republic": "CF", "Chad": "TD", "Chile": "CL", "China": "CN", "ChineseTaipei": "TW", 
  "Colombia": "CO", "Comoros": "KM", "Congo Democratic Republic": "CD", "Congo, Republic of the": "CG", "Costa Rica": "CR", 
  "Croatia": "HR", "Cuba": "CU", "Curacao": "CW", "Cyprus": "CY", "Czech Republic": "CZ", "Denmark": "DK", "Djibouti": "DJ", 
  "Dominica": "DM", "Dominican Republic": "DO", "East Timor": "TP", "Ecuador": "EC", "Egypt": "EG", "El Salvador": "SV", 
  "Equatorial Guinea": "GQ", "Eritrea": "ER", "Estonia": "EE", "Eswatini": "SZ", "Ethiopia": "ET", "Fiji": "FJ", "Finland": "FI", 
  "France": "FR", "Gabon": "GA", "Gambia": "GM", "Georgia": "GE", "Germany": "DE", "Ghana": "GH", "Gibraltar": "GI", "Greece": "GR", 
  "Greenland": "GL", "Grenada": "GD", "Guatemala": "GT", "Guinea": "GN", "Guinea-Bissau": "GW", "Guyana": "GY", "Haiti": "HT", 
  "Honduras": "HN", "Hungary": "HU", "Iceland": "IS", "India": "IN", "Indonesia": "ID", "Iraq": "IQ", "Ireland": "IE", "Italy": "IT", 
  "Ivory Coast": "CI", "Jamaica": "JM", "Japan": "JP", "Jordan": "JO", "Kazakhstan": "KZ", "Kenya": "KE", "Kiribati": "KI", "Kosovo": "XK", 
  "Kuwait": "KW", "Kyrgyz Republic": "KG", "Laos": "LA", "Latvia": "LV", "Lebanon": "LB", "Lesotho": "LS", "Liberia": "LR", "Libya": "LY", 
  "Liechtenstein": "LI", "Lithuania": "LT", "Luxembourg": "LU", "Madagascar": "MG", "Malawi": "MW", "Malaysia": "MY", "Maldives": "MV", 
  "Mali": "ML", "Malta": "MT", "Marshall Islands": "MH", "Mauritania": "MR", "Mauritius": "MU", "Mexico": "MX", "Micronesia": "FM", 
  "Moldova": "MD", "Monaco": "MC", "Mongolia": "MN", "Montenegro": "ME", "Morocco": "MA", "Mozambique": "MZ", "Myanmar": "MM", "Namibia": "NA", 
  "Nauru": "NR", "Nepal": "NP", "Netherlands": "NL", "New Zealand": "NZ", "Nicaragua": "NI", "Niger": "NE", "Nigeria": "NG", "North Korea": "KP", 
  "North Macedonia": "MK", "Norway": "NO", "Oman": "OM", "Pakistan": "PK", "Palau": "PW", "Palestine": "PS", "Panama": "PA", "Papua New Guinea": "PG", 
  "Paraguay": "PY", "Peru": "PE", "Philippines": "PH", "Poland": "PL", "Portugal": "PT", "Romania": "RO", "Russia": "RU", "Rwanda": "RW", 
  "Samoa": "WS", "Saba": "BQSA", "San Marino": "SM", "Sao Tome Principe": "ST", "Saudi Arabia": "SA", "Senegal": "SN", "Serbia": 
  "RS", "Seychelles": "SC", "Sierra Leone": "SL", "Singapore": "SG", "Slovakia": "SK", "Slovenia": "SI", "Solomon Islands": "SB", "Somalia": "SO", 
  "South Africa": "ZA", "South Korea": "KR", "South Sudan": "SS", "Spain": "ES", "Sri Lanka": "LK", "Saint Eustatius": "SEBQ", 
  "Saint Kitts Nevis": "KN", "Saint Lucia": "LC", "Saint Maarten": "MF", "Saint Vincent and the Grenadines": "VC", "Sudan": "SD", 
  "Suriname": "SR", "Sweden": "SE", "Switzerland": "CH", "Syria": "SY", "Tajikistan": "TJ", "Tanzania": "TZ", "Thailand": "TH", "Togo": "TG", 
  "Tonga": "TO", "Trinidad and Tobago": "TT", "Tunisia": "TN", "Turkey": "TR", "Turkmenistan": "TM", "Tuvalu": "TV", "Uganda": "UG", "Ukraine": "UA", 
  "United Arab Emirates": "AE", "United Kingdom": "GB", "United States": "US", "Uruguay": "UY", "Uzbekistan": "UZ", "Vanuatu": "VU", "Venezuela": "VE", 
  "Vietnam": "VN", "Yemen": "YE", "Zambia": "ZM", "Zimbabwe": "ZW", "Zranesia": "ZRAN", "Global Pool": "GP", "United States Idea": "USI",
}

// AJAX call to dynamically fetch startups for event from Jira using evCountryCode and roundName
const getStartupsFromJira = async (jql_str, startAt, maxResults) => {
  console.log('Jira jql:', jql_str);
  
  let jiraResponse = await jQuery.ajax({
    url: "/rest/scriptrunner/latest/custom/searchEWCJiraTicketsPaginated",
    headers: {
      'X-Atlassian-Token' : 'nocheck',
      'Content-type' : 'application/json'
    },
    type: "POST",
    dataType: 'json',
    data: JSON.stringify({
      "jql": jql_str,
      "startAt": startAt,
      "maxResults": maxResults
    })
  }).then(res => res);

  console.log("Jira API Response:", jiraResponse);

  resultsTotal = jiraResponse.total;
  return jiraResponse;
}

const convertJiraDataToArray = (data, isShuffled=false) => {
  let startupsArr = [];
  for (let i = 0; i < data.issues.length; i++) {
    let currIssue = data.issues[i];
    let startupObj = {};

    startupObj["jk"] = currIssue.key;
    startupObj["name"] = currIssue.fields.customfield_10108;
    if (!countryObj[currIssue.fields.customfield_10200] && !countryObj[currIssue.fields.project.name]) {
      console.log("Broken Ticket: ", currIssue);
      continue;
    }
    let countryCode = countryObj[currIssue.fields.customfield_10200] ? countryObj[currIssue.fields.customfield_10200].toLowerCase() : countryObj[currIssue.fields.project.name].toLowerCase();
    startupObj["cc"] = countryCode;
    startupObj["imageurl"] = `https://passport-media.gsvlabsportal.com/EWC/Flags/${countryCode.toUpperCase()}.jpg`;
    startupObj["website"] = currIssue.fields.customfield_10252;
    startupObj["elevatorpitch"] = currIssue.fields.customfield_10116;
    startupObj["foundername"] = currIssue.fields.customfield_10109;
    startupObj["founderemail"] = currIssue.fields.customfield_10110;
    startupObj["verticals"] = currIssue.fields.customfield_10221;
    startupObj["companydescription"] = currIssue.fields.customfield_10226;
    startupObj["country"] = currIssue.fields.customfield_10200;
    startupObj["jk"] = currIssue.key;
    startupObj["teamdesc"] = currIssue.fields.customfield_10203;
    startupObj["milestones"] = currIssue.fields.customfield_10223;
    startupObj["vision"] = currIssue.fields.customfield_10228;
    startupObj["usecase"] = currIssue.fields.customfield_10227;
    startupObj["kpis"] = currIssue.fields.customfield_10230;
    startupObj["compadv"] = currIssue.fields.customfield_10229;
    startupObj["additional"] = currIssue.fields.customfield_10236;
    startupObj["raised"] = currIssue.fields.customfield_10224;
    startupObj["arr"] = currIssue.fields.customfield_10232;
    startupObj["users"] = currIssue.fields.customfield_10234;
    startupObj["sub"] = currIssue.fields.customfield_10231;
	
	let optoutVal = currIssue.fields.customfield_10920;
	if (!optoutVal) {
		startupObj["optout"] = false;
	} else {
		optoutVal = JSON.parse(optoutVal);
		startupObj["optout"] = optoutVal;
	}
	// startupObj["optout"] = currIssue.fields.customfield_10920;

    let attachmentsArr = currIssue.fields.attachment;
    let fixedAttachments = [];
    attachmentsArr.forEach(obj => {
      // Prevent quotes in filename from breaking html
      let newFileName = obj.filename.replace("'", "_").replace('"', "_");
      obj.filename = newFileName;
      fixedAttachments.push(obj);
    });
    startupObj["attachment"] = fixedAttachments;
    
    startupObj["status"] = currIssue.fields.status.name;
    startupObj["project"] = currIssue.fields.project.key;

    startupObj["founded"] = currIssue.fields.customfield_10113;
    startupObj["teamsize"] = currIssue.fields.customfield_10204;
    startupObj["stage"] = currIssue.fields.customfield_10202;

    comment_obj[currIssue.key] = currIssue.fields.comment.comments;

    let subtasksarr = [];
    if(currIssue.fields.subtasks){
      for(let k = 0; k < currIssue.fields.subtasks.length; k++){
        let currSubtask = currIssue.fields.subtasks[k];
        subtasksarr.push(currSubtask.fields.status.name);
      }
    }
    startupObj["subtasksarr"] = subtasksarr;

    startupProfByJK[currIssue.key] = startupObj;

    startupsArr.push(startupObj);
  }

  console.log("Startups Arr:", startupsArr);
  return startupsArr;
}


const generateStartupCardHTML = (startup) => {

  // Prevent quotes in string from startup data from breaking html
  Object.keys(startup).forEach(key => {
    if (startup[key] && key !== "attachment" && key !== "subtasksarr" && key !== "optout") {
      startup[key] = startup[key].replace(/"/g, '"');
    } else if (startup[key] && key === "attachment") {
      startup["attachment"] = JSON.stringify(startup["attachment"]);
    } else if (startup[key] && key === "subtasksarr") {
      startup["subtasksarr"] = JSON.stringify(startup["subtasksarr"]);
    }
  });

  let {
    country,
    jk,
    name
  } = startup;

  if (startup.verticals) {
    startup.verticals = startup.verticals.split(",").join(", ");
  }

  let countryHTML = "";
  if (country) {
    countryHTML = `<p style="color: white; font-size: 13px; font-weight: bold; text-shadow: -1px 1px 5px black;">${country}</p>`;
  }

  return (
  `<div class="startupcard" onclick="toggleStartupInfoOverlay(event, this)" data-jk="${jk}" data-name="${name}">
    <div class="img-container">
      <img src="${startup.imageurl}"></img>
    </div>
    <div class="text-container">
        <div class="top" style="padding: 9px 10px;">
          ${countryHTML}
        </div>
        <div class="bottom">
            <div class="title">${startup.name}</div>
            <div class="subtitle">${startup.verticals}</div>
            <div class="preview-text">${startup.elevatorpitch}</div>
        </div>
    </div>
  </div>`
 );
}

const renderStartupCardsFromData = (data, sectionSelector) => {
  if (!data.issues) {
    // No Jira data returned 
    return;
  }

  let startupsArr = convertJiraDataToArray(data);
  let startupCardsHTML = "";
  for (let i = 0; i < startupsArr.length; i++) {
    startupCardsHTML += generateStartupCardHTML(startupsArr[i]);
  }

  $(sectionSelector)[0].innerHTML = startupCardsHTML;
}

const displayGlobalFinalists = (sectionSelector) => {
  let jql_str = `project = ZRAN AND issuetype = Task AND status in ('EWC 100 - Approved', 'Global Finalist - Approved', 'Global Finalist - In Review', 'Global Finals - Judge Assigned', 'Global Finals - Judging Completed',
    'National Finals - Judge Assigned', 'National Finals - Judging Completed', 
    'Semi-Finals 1 - Judge Assigned', 'Semi-Finals 1 - Judging Completed', 'Semi-Finals 2 - Judge Assigned', 'Semi-Finals 2 - Judging Completed', 
    'Semi-Finals 3 - Judge Assigned', 'Semi-Finals 3 - Judging Completed', 'Semi-Finals 4 - Judge Assigned', 'Semi-Finals 4 - Judging Completed') ORDER BY 'Company Name' ASC, priority DESC, updated DESC`;
  getStartupsFromJira(jql_str, currResultsStart, maxResults).then(data => renderStartupCardsFromData(data, sectionSelector));
}

const displayNationalFinalists = (sectionSelector) => {
  let jql_str = `issuetype = Task AND issueFunction in parentsOf("status in ('National Finals - Judge Assigned', 'National Finals - Judging Completed')") ORDER BY 'Company Name' ASC, priority DESC, updated DESC`;
  getStartupsFromJira(jql_str, currResultsStart, maxResults).then(data => renderStartupCardsFromData(data, sectionSelector));
}

function changeCardsPage (direction) {
  if (direction == "next") {
    currResultsStart += maxResults;
  } else if (direction == "prev") {
    currResultsStart -= maxResults;
  }
  if (currResultsStart < 0) {
    currResultsStart = 0;
  }
  if (currResultsStart === 0) {
    $("#results-prev").hide();
  } else {
    $("#results-prev").show();
  }
  if (currResultsStart + maxResults >= resultsTotal) {
    $("#results-next").hide();
  } else {
    $("#results-next").show();
  }
  let cardsHeight = $("#startup-cards-grid").height();

  $("#startup-cards-grid")[0].innerHTML = `<div class="loading-container" style="display: flex; justify-content: center; align-items: center; width: 100%; height:${cardsHeight}px"><div class="loader"> </div></div>`;

  if (pageName.toLowerCase().includes("global")) {
    displayGlobalFinalists("#startup-cards-grid");
  } else if (pageName.toLowerCase().includes("national")) {
    displayNationalFinalists("#startup-cards-grid");
  }
}

const handleNonInvestorView = () => {
  $(".startup-info-header").hide();
  $(".startup-info-team-container").hide();
  $(".startup-other-info-container").hide();
  $("#startup-watchlist-button").hide();
}

const handleInvestorOrAdminView = () => {
  $(".startup-info-header").show();
  $(".startup-info-team-container").show();
  $(".startup-other-info-container").show();
}

const handleInvestorView = () => {
  $("#startup-watchlist-button").show();
}



window.addEventListener('DOMContentLoaded', () => {

  if (pageName.toLowerCase().includes("global")) {
    displayGlobalFinalists("#startup-cards-grid");
    document.getElementById("startups-main-banner-title").innerHTML = pageName;
  } else if (pageName.toLowerCase().includes("national")) {
    displayNationalFinalists("#startup-cards-grid");
    document.getElementById("startups-main-banner-title").innerHTML = pageName;
  }

  if (AJS.params.remoteUser && AJS.params.remoteUser.length > 0) {
    getCurrentUserGroups().then((groups) => {
      if (groups.includes("vcs-judges")) {
        isInvestorUser = true;
      }
      if (groups.includes("confluence-administrators")) {
        isSuperAdmin = true;
      } 
      if (groups.includes("judging-administrators")) {
        isSuperAdmin = true;
      }
  
      if (isInvestorUser) {
        handleInvestorView();
        handleInvestorOrAdminView();
        getInvestorUserProfile(AJS.params.remoteUser).then((res) => {
          setInvestorVarsWithProfileData(res);
        });
      } else if (isSuperAdmin) {
        handleInvestorOrAdminView();
        $("#startup-watchlist-button").hide();
      } else {
        handleNonInvestorView();
      }
    });
  } else {
    handleNonInvestorView();
  }

  $("#results-prev").hide();
});

</script>

...