text:
<repo_name>SashoLichovski/corona-website-project.github.io<file_sep>/Script/infoScript.js

let generalInfoBtn = document.getElementById("generalInfoBtn");
let generalInfoContainer = document.getElementById('generalInfoContainer');
generalInfoContainer.className = 'show';
generalInfoBtn.onclick = function(){
    if (generalInfoContainer.className == 'hide') {
        generalInfoContainer.className = 'show';
    }
    else{
        generalInfoContainer.className = 'hide'
    }
}

function togglePluMinus(e)
{   var t=e.target;

    t.style.display="none";
    var minus=document.createElement("img");
    minus.src="minus.png";
    minus.style.height="20px";
    var section=t.parentElement;

    section.appendChild(minus);

    var next=t.parentElement.nextElementSibling.nextElementSibling;//getElementById("dropdown");
    next.style.display="block";
    minus.onclick=function()
    {
        next.style.display="none";
        minus.style.display="none";
        t.style.display="flex"
    }

}

let infoBasicsBtn = document.getElementById('infoBasicsBtn');
let infoBasicsContainer = document.getElementById('infoBasicsContainer');
infoBasicsContainer.className = 'hide';
infoBasicsBtn.onclick = function(){
    if (infoBasicsContainer.className == 'hide') {
        infoBasicsContainer.className = 'show';
    }
    else{
        infoBasicsContainer.className = 'hide'
    }
}

let spreadBtn = document.getElementById('spreadBtn');
let spreadContainer = document.getElementById('spreadContainer');
spreadContainer.className = 'hide';
spreadBtn.onclick = function(){
    if (spreadContainer.className == 'hide') {
        spreadContainer.className = 'show';
    }
    else{
        spreadContainer.className = 'hide'
    }
}<file_sep>/Script/DynamicCScript.js
let newData = [];
axios.get(`https://covid-ca.azurewebsites.net/api/covid/history`,{
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }
})
.then((response) => {
    let data = JSON.parse(response.data);
    console.log(data);

    // Bar char for each country on search (default chart is for Mk)
    let countryObject;
    let infectedWeek1 = 0;let infectedWeek2 = 0;let infectedWeek3 = 0;let infectedWeek4 = 0;let infectedWeek5 = 0;let infectedWeek6 = 0;let infectedWeek7 = 0;let infectedWeek8 = 0;let infectedWeek9;
    let recoveredWeek1 = 0;let recoveredWeek2 = 0;let recoveredWeek3 = 0;let recoveredWeek4 = 0;let recoveredWeek5 = 0;let recoveredWeek6 = 0;let recoveredWeek7 = 0;let recoveredWeek8 = 0;let recoveredWeek9;
    let deathsWeek1 = 0;let deathsWeek2 = 0;let deathsWeek3 = 0;let deathsWeek4 = 0;let deathsWeek5 = 0;let deathsWeek6 = 0;let deathsWeek7 = 0;let deathsWeek8 = 0;let deathsWeek;

    function setInfectedValues(countryName){
        for (let i = 0; i < data.length; i++) {
            if (data[i].country == countryName) {
                countryObject = data[i];
                var infectedArr = Object.values(countryObject.timeline.cases);
                infectedWeek1 = parseInt(infectedArr[6]);
                infectedWeek2 = parseInt(infectedArr[13]) - parseInt(infectedArr[6]);
                infectedWeek3 = parseInt(infectedArr[20]) - parseInt(infectedArr[13]);
                infectedWeek4 = parseInt(infectedArr[27]) - parseInt(infectedArr[20]);
                infectedWeek5 = parseInt(infectedArr[34]) - parseInt(infectedArr[27]);
                infectedWeek6 = parseInt(infectedArr[41]) - parseInt(infectedArr[34]);
                infectedWeek7 = parseInt(infectedArr[48]) - parseInt(infectedArr[41]);
                infectedWeek8 = parseInt(infectedArr[infectedArr.length-1]) - parseInt(infectedArr[48]);
                break;
            }
        }
    }
    function setRecoveredValues(countryName){
        for (let i = 0; i < data.length; i++) {
            if (data[i].country == countryName) {
                countryObject = data[i];
                var infectedArr = Object.values(countryObject.timeline.recovered);
                recoveredWeek1 = parseInt(infectedArr[6]);
                recoveredWeek2 = parseInt(infectedArr[13]) - parseInt(infectedArr[6]);
                recoveredWeek3 = parseInt(infectedArr[20]) - parseInt(infectedArr[13]);
                recoveredWeek4 = parseInt(infectedArr[27]) - parseInt(infectedArr[20]);
                recoveredWeek5 = parseInt(infectedArr[34]) - parseInt(infectedArr[27]);
                recoveredWeek6 = parseInt(infectedArr[41]) - parseInt(infectedArr[34]);
                recoveredWeek7 = parseInt(infectedArr[48]) - parseInt(infectedArr[41]);
                recoveredWeek8 = parseInt(infectedArr[infectedArr.length-1]) - parseInt(infectedArr[48]);
                break;
            }
        }
    }
    function setDeathsValues(countryName){
        for (let i = 0; i < data.length; i++) {
            if (data[i].country == countryName) {
                countryObject = data[i];
                var infectedArr = Object.values(countryObject.timeline.deaths);
                deathsWeek1 = parseInt(infectedArr[6]);
                deathsWeek2 = parseInt(infectedArr[13]) - parseInt(infectedArr[6]);
                deathsWeek3 = parseInt(infectedArr[20]) - parseInt(infectedArr[13]);
                deathsWeek4 = parseInt(infectedArr[27]) - parseInt(infectedArr[20]);
                deathsWeek5 = parseInt(infectedArr[34]) - parseInt(infectedArr[27]);
                deathsWeek6 = parseInt(infectedArr[41]) - parseInt(infectedArr[34]);
                deathsWeek7 = parseInt(infectedArr[48]) - parseInt(infectedArr[41]);
                deathsWeek8 = parseInt(infectedArr[infectedArr.length-1]) - parseInt(infectedArr[48]);
                break;
            }
        }
    }
    function generateGraph(countryName){
        setInfectedValues(countryName);
        // setRecoveredValues(countryName);
        setDeathsValues(countryName);

        let chartContainer = document.getElementById('chartContainer');
        let infectedChartElement = document.createElement('canvas');
        infectedChartElement.id = 'infectedChart';
        chartContainer.appendChild(infectedChartElement);

        infectedChartElement.getContext('2d');
        let infectedChart = new Chart(infectedChartElement, {
            type: 'bar',
            data:{
                labels:['Jan 22 - Jan 29', 'Jan 30 - Feb 06', 'Feb 7 - Feb 14', 'Feb 15 - Feb 22', 'Feb 23 - Mar 01', 'Mar 02 - Mar 09', 'Mar 10 - Mar 17', 'Mar 17 - Mar 23'],
                datasets:[{
                    label:'Infected',
                    data:[
                        infectedWeek1,
                        infectedWeek2,
                        infectedWeek3,
                        infectedWeek4,
                        infectedWeek5,
                        infectedWeek6,
                        infectedWeek7,
                        infectedWeek8,
                    ],
                    backgroundColor: 'blue',
                    borderWidth:1,
                    borderColor:'grey',
                    hoverBorderWidth:3,
                    hoverBorderColor:'black',
                    fill:true
                }
                // ,{
                //     label:'Recovered',
                //     data:[
                //         recoveredWeek1,
                //         recoveredWeek2,
                //         recoveredWeek3,
                //         recoveredWeek4,
                //         recoveredWeek5,
                //         recoveredWeek6,
                //         recoveredWeek7,
                //         recoveredWeek8,
                //     ],
                //     backgroundColor: 'green',
                //     borderWidth:1,
                //     borderColor:'grey',
                //     hoverBorderWidth:3,
                //     hoverBorderColor:'black',
                //     fill:false
                // }
                ,{
                    label:'Deaths',
                    data:[
                        deathsWeek1,
                        deathsWeek2,
                        deathsWeek3,
                        deathsWeek4,
                        deathsWeek5,
                        deathsWeek6,
                        deathsWeek7,
                        deathsWeek8,
                    ],
                    backgroundColor: 'red',
                    borderWidth:1,
                    borderColor:'grey',
                    hoverBorderWidth:3,
                    hoverBorderColor:'black',
                    fill:false
                }]
            },
            options:{
                title:{
                    display:true,
                    text:`Covid-19 weekly infections in ${countryName}`,
                    fontSize:25
                },
                legend:{
                    position:'top'
                }
            }
        });
    }
    generateGraph('north macedonia');

    let graphSearch = document.getElementById('countryGraphSearch');
    let graphSearchValue;
    let chartContainer = document.getElementById('infectedChart');
    graphSearch.onkeypress = function(event){
        if (event.keyCode == 13) {
            document.getElementById('infectedChart').remove();
            graphSearchValue = graphSearch.value;
            generateGraph(graphSearchValue);
            graphSearch.value = '';
        }
    }

})
.catch(error => {
    console.log(error)
});

<file_sep>/Style/CDTStyle.css
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Noto Sans SC', sans-serif;
}

#nav{
    position: sticky;
    top: 0px;
    z-index: 2;
}

#alert{
    height: 50%;
}

.navLink{
    padding: 1%;
    border: 1px solid rgb(0, 109, 128);
    border-radius: 3px;
    margin-right: 5px;
}

.navLink:hover{
    background-color: rgb(182, 182, 182);
}

#headerContainer{
    text-align: center;
    padding: 2%;
}

#header{
    font-size: 200%;
}

.statisticContainer{
    width: 70%;
    background-color: #343a40;
    margin: 0 auto;
    text-align: center;
    border-radius: 5px 5px 40px 5px;
    margin-bottom: 4%;
}

.statisticHeader{
    font-size: 200%;
    font-weight: bolder;
    padding: 1%;
    color: #f8f9fa;
}

.tableContainer{
    padding: 2%;
}

.statistickHead{
    font-size: 120%;
    font-weight: 400;
    border-bottom: 1px solid black;
}

.statisticTable{
    text-align: center;
    margin: 0 auto;
    width: 85%;
    table-layout: fixed;
}

.statisticValues{
    font-size: 120%;
}

#countriesTableContainer{
    padding: 1%;
    margin: 0 auto;
    text-align: center;
    /* background-color: rgba(43, 42, 42, 0.247); */
}

#allCountriesHeaderContainer{
    text-align: center;
}

#allCountriesHeader{
    font-size: 2em;
}

.allCountriesStatisticHead{
    /* width: 20%; */
    font-size: 1.2em;
}

.countryTableRow{
    border: 2px solid black;
    padding: 2px 10px;
    font-size: 120%;
    font-weight: 500;
}

/* Pop up classes ------------------- */
.countryInfoContainer{
    position: absolute;
    margin-left: auto;
    margin-right: auto;
    left: 0;
    right: 0;
    top: 10%;
    width: 60%;
    text-align: center;
    border-radius: 20px;
    margin-top: 5%;
    background-color: rgba(0, 0, 0, 0.932);
}

.countryHeader{
    color: rgb(255, 255, 255);
    font-size: 2em;
    padding: 2%;
}

.countryTableHead{
    /* border: 2px solid rgb(0, 0, 0); */
    color: snow;
    font-size: 50%;
    font-weight: 300;
    padding: 2px 10px;
}

.closeCountryInfo{
    margin-bottom: 2%;
}

.popup{
    padding: 10px;
    background: whitesmoke;
    position: absolute;
    border: 1px solid black;
    border-radius: 8px 8px 8px 0px;
}

@media only screen and (max-width : 1080px){
    #countrySearch{
        width: 100px;
    }
    #nav{
        font-size: 0.8em;
    }
    #header{
        font-size: 1.2em;
    }
    .statisticContainer{
        width: 100%;
        background-color: #f8f9fa;
        text-align: center;
        margin-bottom: 4%;
        border-radius: 0%;
    }
    .tableContainer{
        padding: 0.5%;
    }
    .statistickHead{
        font-size: 70%;
    }
    .statisticHeader{
        font-size: 100%;
        font-weight: bolder;
        padding: 1%;
        color: #343a40;
    }
    .statisticValues{
        font-size: 70%;
    }
    .statisticTable{
        text-align: center;
        table-layout: fixed;
        font-size: 0.8em;
    }
    #allCountriesHeader{
        font-size: 1.1em;
    }
    .allCountriesStatisticHead{
        font-size: 1em;
    }
    .countryTableRow{
        padding: 2px 5px;
        font-size: 80%;
        font-weight: 300;
    }
    .countryInfoContainer{
        position: absolute;
        margin-left: auto;
        margin-right: auto;
        left: 0;
        right: 0;
        top: 10%;
        width: 100%;
        text-align: center;
        border-radius: 20px;
        margin-top: 5%;
        background-color: rgba(0, 0, 0, 0.932);
    }
    .countryHeader{
        color: rgb(255, 255, 255);
        font-size: 1.4em;
        padding: 2%;
    }

    .countryTableHead{
        /* border: 2px solid rgb(0, 0, 0); */
        color: snow;
        font-size: 50%;
        font-weight: 300;
        padding: 2px 10px;
    }
}

@media only screen and (max-width : 700px){
    #countrySearch{
        width: 70px;
    }
    #nav{
        font-size: 0.6em;
    }
    #header{
        font-size: 1em;
    }
    .statisticContainer{
        width: 100%;
        background-color: #f8f9fa;
        text-align: center;
        margin-bottom: 4%;
        border-radius: 0%;
    }
    .tableContainer{
        padding: 0.5%;
    }
    .statistickHead{
        font-size: 70%;
    }
    .statisticHeader{
        font-size: 100%;
        font-weight: bolder;
        padding: 1%;
        color: #343a40;
    }
    .statisticValues{
        font-size: 70%;
    }
    .statisticTable{
        text-align: center;
        table-layout: fixed;
        font-size: 0.7em;
    }
    #allCountriesHeader{
        font-size: 1.1em;
    }
    .allCountriesStatisticHead{
        font-size: 80%;
    }
    .countryTableRow{
        padding: 2px 5px;
        font-size: 60%;
        font-weight: 300;
    }
    .countryInfoContainer{
        position: absolute;
        margin-left: auto;
        margin-right: auto;
        left: 0;
        right: 0;
        top: 10%;
        width: 100%;
        text-align: center;
        border-radius: 20px;
        margin-top: 5%;
        background-color: rgba(0, 0, 0, 0.932);
    }
    .countryHeader{
        color: rgb(255, 255, 255);
        font-size: 1.4em;
        padding: 2%;
    }

    .countryTableHead{
        /* border: 2px solid rgb(0, 0, 0); */
        color: snow;
        font-size: 50%;
        font-weight: 300;
        padding: 2px 10px;
    }
}

@media only screen and (max-width : 500px){
    #nav{
        font-size: 0.4em;
    }
    #header{
        font-size: 1em;
    }
    .statisticContainer{
        width: 100%;
        background-color: #f8f9fa;
        text-align: center;
        margin-bottom: 4%;
        border-radius: 0%;
    }
    .tableContainer{
        padding: 0.5%;
    }
    .statistickHead{
        font-size: 70%;
    }
    .statisticHeader{
        font-size: 100%;
        font-weight: bolder;
        padding: 1%;
        color: #343a40;
    }
    .statisticValues{
        font-size: 70%;
    }
    .statisticTable{
        text-align: center;
        table-layout: fixed;
    }
    #allCountriesHeader{
        font-size: 1.1em;
    }
    .allCountriesStatisticHead{
        font-size: 60%;
    }
    .countryTableRow{
        padding: 2px 5px;
        font-size: 50%;
        font-weight: 300;
    }
    .countryInfoContainer{
        position: absolute;
        margin-left: auto;
        margin-right: auto;
        left: 0;
        right: 0;
        top: 10%;
        width: 100%;
        text-align: center;
        border-radius: 20px;
        margin-top: 5%;
        background-color: rgba(0, 0, 0, 0.932);
    }
    .countryHeader{
        color: rgb(255, 255, 255);
        font-size: 1.4em;
        padding: 2%;
    }

    .countryTableHead{
        /* border: 2px solid rgb(0, 0, 0); */
        color: snow;
        font-size: 50%;
        font-weight: 300;
        padding: 2px 10px;
    }
}

<file_sep>/Script/CDTScript.js
// Overview for each country
axios.get('https://covid-ca.azurewebsites.net/api/covid/countries', {
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }
})
.then((response) => {
    let data = JSON.parse(response.data);
    console.log(data);

    // General overivew world wide
    let wwsTodayCases = document.getElementById('wwsTodayCases');
    let sum = 0;
    for (let i = 0; i < data.length; i++) {
        sum += data[i].todayCases
    }
    wwsTodayCases.innerText = sum.toString();
    sum = 0;
    let wwsTodayDeaths = document.getElementById('wwsTodayDeaths');
    for (let i = 0; i < data.length; i++) {
        sum += data[i].todayDeaths
    }
    wwsTodayDeaths.innerText = sum.toString();
    sum = 0;
    let wwsCritical = document.getElementById('wwsCritical');
    for (let i = 0; i < data.length; i++) {
        sum += data[i].critical
    }
    wwsCritical.innerText = sum.toString();
    sum = 0;
    let wwsCases = document.getElementById('wwsCases');
    for (let i = 0; i < data.length; i++) {
        sum += data[i].cases;
    }
    wwsCases.innerText = sum.toString();
    sum = 0;
    let wwsDeaths = document.getElementById('wwsDeaths');
    for (let i = 0; i < data.length; i++) {
        sum += data[i].deaths;
    }
    wwsDeaths.innerText = sum.toString();
    sum = 0;
    let wwsRecovered = document.getElementById('wwsRecovered');
    for (let i = 0; i < data.length; i++) {
        sum += data[i].recovered;
    }
    wwsRecovered.innerText = sum.toString();
    // Getting MK statistics
    let mkStatisticInfo;
    for (let i = 0; i < data.length; i++) {
        if (data[i].country == 'Macedonia, the former Yugoslav Republic of') {
            mkStatisticInfo = data[i]
            break;
        }
    }
    let mksCases = document.getElementById('mksCases');
    mksCases.innerText = mkStatisticInfo.cases;
    let mksDeaths = document.getElementById('mksDeaths');
    mksDeaths.innerText = mkStatisticInfo.deaths;
    let mksRecovered = document.getElementById('mksRecovered');
    mksRecovered.innerText =mkStatisticInfo.recovered;
    let mksTodayCases = document.getElementById('mksTodayCases');
    mksTodayCases.innerText = mkStatisticInfo.todayCases;
    mksTodayDeaths.innerText = mkStatisticInfo.todayDeaths;
    mksCritical.innerText = mkStatisticInfo.critical;

    // All countries statistics
    let acTBody = document.getElementById('allCountriesTBody');
    for (let i = 0; i < data.length; i++) {
        let tr = document.createElement('tr');
        acTBody.appendChild(tr);
        let tdCountry = document.createElement('td');
        tdCountry.innerText = data[i].country;
        tdCountry.className = 'countryTableRow';
        let tdCases = document.createElement('td');
        tdCases.innerText = data[i].cases;
        tdCases.className = 'countryTableRow';
        let tdTodayCases = document.createElement('td');
        tdTodayCases.innerText = data[i].todayCases;
        tdTodayCases.className = 'countryTableRow';
        let tdDeaths = document.createElement('td');
        tdDeaths.innerText = data[i].deaths;
        tdDeaths.className = 'countryTableRow';
        let tdTodayDeaths = document.createElement('td');
        tdTodayDeaths.innerText = data[i].todayDeaths;
        tdTodayDeaths.className = 'countryTableRow';
        let tdRecovered = document.createElement('td');
        tdRecovered.innerText = data[i].recovered;
        tdRecovered.className = 'countryTableRow';
        let tdCritical = document.createElement('td');
        tdCritical.innerText = data[i].critical;
        tdCritical.className = 'countryTableRow';
        tr.appendChild(tdCountry);
        tr.appendChild(tdCases);
        tr.appendChild(tdTodayCases);
        tr.appendChild(tdDeaths);
        tr.appendChild(tdTodayDeaths);
        tr.appendChild(tdRecovered);
        tr.appendChild(tdCritical);
        let trHead = document.getElementById('trHead');
        let header = [];
        tr.onmouseover = function(){
            if (tr.previousElementSibling != null) {
                tr.className = 'bg-light';
                tr.style.color = 'black';
                tr.previousElementSibling.className = 'bg-info';
                for (let i = 0; i < tr.cells.length; i++) {
                    header.push(tr.previousElementSibling.children[i].innerText)
                    tr.previousElementSibling.children[i].innerText = trHead.children[i].innerText;
                }
            }
        }
        tr.onmouseout = function(){
            if (tr.previousElementSibling != null) {
                tr.className = '';
                tr.style.color = 'white';
                tr.previousElementSibling.className = '';
                for (let i = 0; i < tr.cells.length; i++) {
                    tr.previousElementSibling.children[i].innerText = header[i];
                }
            }
        }
        header = [];
    }

    //Top 5 infected countries
    let china;
    let italy;
    let usa;
    let spain;
    let germany;
    for (let i = 0; i < data.length; i++) {
        if (data[i].country == 'China') {
            china = data[i];
        }else if(data[i].country == 'Italy'){
            italy = data[i];
        }else if(data[i].country == 'USA'){
            usa = data[i];
        }else if(data[i].country == 'Spain'){
            spain = data[i];
        }else if(data[i].country == 'Germany'){
            germany = data[i];
        }
    }
    let radarContainer = document.getElementById('redarContainer');
    let radarElementInfected = document.createElement('canvas');
    radarContainer.appendChild(radarElementInfected);
    radarElementInfected.getContext('2d');
    //Infected
    let radarInfectedChart = new Chart(radarElementInfected, {
        type:'polarArea',
        data:{
            labels:['Infected in China','Infected in Italy', 'Infected in USA', 'Infected in Spain', 'Infected in Germany'],
            datasets:[{
                label:'Infected',
                backgroundColor:['rgba(0, 0, 255, 0.5)','rgba(0, 32, 255, 0.5)','rgba(0, 64, 255, 0.5)','rgba(0, 96, 255, 0.5)','rgba(0, 129, 255, 0.5)'],
                data:[
                    china.cases,
                    italy.cases,
                    usa.cases,
                    spain.cases,
                    germany.cases
                ]
            }]
        },
        options:{
            title:{
                display:true,
                text:`Top 5 infected countries`,
                fontSize:25
            },
            legend:{
                position:'top'
            }
        }
    })
    //Recovered
    let radarElementRecovered = document.createElement('canvas');
    radarContainer.appendChild(radarElementRecovered);
    radarElementRecovered.getContext('2d');
    let radarRecoveredChart = new Chart(radarElementRecovered, {
        type:'polarArea',
        data:{
            labels:['Recovered in China','Recovered in Italy', 'Recovered in USA', 'Recovered in Spain', 'Recovered in Germany'],
            datasets:[{
                label:'Infected',
                backgroundColor:['rgba(0, 255, 0, 0.5)','rgba(0, 225, 0, 0.5)','rgba(0, 195, 0, 0.5)','rgba(0, 165, 0, 0.5)','rgba(0, 135, 0, 0.5)'],
                data:[
                    china.recovered,
                    italy.recovered,
                    usa.recovered,
                    spain.recovered,
                    germany.recovered
                ]
            }]
        },
        options:{
            title:{
                display:true,
                text:`Recovered`,
                fontSize:25
            },
            legend:{
                position:'top'
            }
        }
    })
    //Deaths
    let radarElementDeaths = document.createElement('canvas');
    radarContainer.appendChild(radarElementDeaths);
    radarElementDeaths.getContext('2d');
    let radarDeathsChart = new Chart(radarElementDeaths, {
        type:'polarArea',
        data:{
            labels:['Deaths in China','Deaths in Italy', 'Deaths in USA', 'Deaths in Spain', 'Deaths in Germany'],
            datasets:[{
                label:'Infected',
                backgroundColor:['rgba(255, 0, 0, 0.5)','rgba(255, 0, 32, 0.5)','rgba(255, 0, 64, 0.5)','rgba(255, 0, 96, 0.5)','rgba(255, 0, 129, 0.5)'],
                data:[
                    china.deaths,
                    italy.deaths,
                    usa.deaths,
                    spain.deaths,
                    germany.deaths
                ]
            }]
        },
        options:{
            title:{
                display:true,
                text:`Deaths`,
                fontSize:25
            },
            legend:{
                position:'top'
            }
        }
    })
})
.catch(error => {
    console.log(error)
})

let searchInputValue;
let searchInput = document.getElementById('countrySearch');
let searchBtn = document.getElementById('searchBtn');
searchInput.onkeypress = function(event){
    if (event.keyCode == 13) {
        generateCountryInfo()
    }
}

function generateCountryInfo(){
    searchInput.disabled = true;
    searchInputValue = searchInput.value;
    console.log(searchInputValue);
    searchInput.value = '';

    let singleCountryContianer = document.getElementById('singleCountryContianer');
    let countryInfo = document.createElement('div');
    countryInfo.className = 'countryInfoContainer';
    singleCountryContianer.appendChild(countryInfo);

    let countryHeader = document.createElement('div');
    countryHeader.innerText = searchInputValue + ' statistics';
    countryHeader.className = 'countryHeader';
    countryInfo.appendChild(countryHeader);

    let table = document.createElement('table')
    table.style.margin = 'auto';
    table.className = 'table table-striped table-dark'
    countryHeader.appendChild(table);
    let tHead = document.createElement('thead')
    table.appendChild(tHead);
    let tr = document.createElement('tr');
    tHead.appendChild(tr)

    let thCases = document.createElement('th');
    thCases.className = 'countryTableHead';
    thCases.innerText = 'Вкупно заболени';
    let thTodayCases = document.createElement('th');
    thTodayCases.className = 'countryTableHead';
    thTodayCases.innerText = 'Денешни случаи';
    let thDeaths = document.createElement('th');
    thDeaths.className = 'countryTableHead';
    thDeaths.innerText = 'Починати';
    let thTodayDeaths = document.createElement('th');
    thTodayDeaths.className = 'countryTableHead';
    thTodayDeaths.innerText = 'Денеска починати';
    let thRecovered = document.createElement('th');
    thRecovered.className = 'countryTableHead';
    thRecovered.innerText = 'Излечени';
    let thCritical = document.createElement('th');
    thCritical.className = 'countryTableHead';
    thCritical.innerText = 'Критични';

    tr.appendChild(thCases);
    tr.appendChild(thTodayCases);
    tr.appendChild(thDeaths);
    tr.appendChild(thTodayDeaths);
    tr.appendChild(thRecovered);
    tr.appendChild(thCritical);

    let allCountriesTable = document.getElementById('allCountriesTable');
    for (let i = 0; i < allCountriesTable.rows.length; i++) {
        if (allCountriesTable.rows[i].cells[0].innerText.toLowerCase() == searchInputValue.toLowerCase()) {
            let tBody = document.createElement('tbody');
            table.appendChild(tBody);
            let bodyTr = document.createElement('tr');
            tBody.appendChild(bodyTr);
            let tdCases = document.createElement('td');
            tdCases.className = 'countryTableHead';
            tdCases.innerText = allCountriesTable.rows[i].cells[1].innerText;
            let tdTodayCases = document.createElement('td');
            tdTodayCases.className = 'countryTableHead';
            tdTodayCases.innerText = allCountriesTable.rows[i].cells[2].innerText;
            let tdDeaths = document.createElement('td');
            tdDeaths.className = 'countryTableHead';
            tdDeaths.innerText = allCountriesTable.rows[i].cells[3].innerText;
            let tdTodayDeaths = document.createElement('td');
            tdTodayDeaths.className = 'countryTableHead';
            tdTodayDeaths.innerText = allCountriesTable.rows[i].cells[4].innerText;
            let tdRecovered = document.createElement('td');
            tdRecovered.className = 'countryTableHead';
            tdRecovered.innerText = allCountriesTable.rows[i].cells[5].innerText;
            let tdCritical = document.createElement('td');
            tdCritical.innerText = allCountriesTable.rows[i].cells[6].innerText;
            tdCritical.className = 'countryTableHead';

            bodyTr.appendChild(tdCases);
            bodyTr.appendChild(tdTodayCases);
            bodyTr.appendChild(tdDeaths);
            bodyTr.appendChild(tdTodayDeaths);
            bodyTr.appendChild(tdRecovered);
            bodyTr.appendChild(tdCritical);
            break;
        }
    }

    let closeBtn = document.createElement('button');
    closeBtn.innerText = 'Close';
    closeBtn.className = 'btn btn-success closeCountryInfo';

    countryInfo.appendChild(closeBtn);
    closeBtn.onclick = function(){
        searchInput.disabled = false;
        countryInfo.remove();
    }
}

languages: JavaScript CSS

repo_language: JavaScript


text:
<file_sep>
This is a demo for [rockets](https://github.com/rtheunissen/rockets).

---

```bash
npm install rockets-demo
cd node_modules
cd rockets-demo
npm start  # or `node index.js`
```

---

<img src="demo.gif" width="512"/>
<file_sep>module.exports = class Demo

  constructor: () ->
    @client = new Client()

  run: () ->

    # Subscripe to posts and comments when connected.
    @client.on 'connect', =>
      @client.subscribe 'posts'
      @client.subscribe 'comments'

    # Attempt to reconnect when the connection is dropped.
    @client.on 'disconnect', =>
      @client.reconnect()

    # Print a comment when it is received.
    @client.on 'comment', (comment) =>
      @print comment

    # Print a post when it is received.
    @client.on 'post', (post) =>
      @print post

    # Attempt to reconnect when the connection is dropped.
    @client.on 'error', (err) ->
      console.error err

    @client.connect()

  # Pads a string to a target length with whitespace to the right.
  rpad: (string, targetLength) ->
    if string.length <= targetLength
      for _ in [0...targetLength - string.length]
        string += ' '

    return string

  # Pads a string to a target length with whitespace to the left.
  lpad: (string, targetLength) ->
    if string.length <= targetLength
      for _ in [0...targetLength - string.length]
        string = ' ' + string

    return string

  # Prints a model to the console.
  print: (model) ->
    data = model.data

    # Local time of day when the model was created
    time = new Date(data.created_utc * 1000).toTimeString().split(' ')[0]

    if model.kind is 't1'
      type = @rpad('Comment', 7)
      text = data.body.replace(/\s/g, ' ')
      subr = data.subreddit
      user = data.author

    else
      type = @rpad('Post', 7)
      text = data.title
      user = data.author
      subr = if data.subreddit then data.subreddit else '(promoted)'

    length = @lpad("#{text.length}", 5)

    user = 'u/' + @rpad(user, 21).blue.bold
    subr = 'r/' + @rpad(subr, 22).red.bold

    console.log "[#{time}] #{type} by #{user} in #{subr} #{length}".grey

branch_name: refs/heads/master

languages: Markdown CoffeeScript

repo_language: Markdown

repo_name: rockets/demo


text:
<file_sep>; potentiometer.asm
; Handles the speaker stuff.

;.ifndef POTENTIOMETER_ASM
;.equ POTENTIOMETER_ASM = 1

; TODO: Figure out the ports.
.equ POTENT_OUT = PORTK
.equ POTENT_DDR = DDRK
.equ POTENT_IN = PINK

SetupPotent:
	push temp1

	; REFS0 Internal 2.56V reference with external capacitor at external AFREF pin
	; 0 << ADLAR sets to right adjusted input
	; 0 << MUX0 && 1 << MUX5 -> selects ADC8 as analog input channel
	; 1 << ADEN -> enables the ADC
	; 1 << ADSC -> starts the first conversion
	; 1 << ADIE -> ADC conversion complete interrupt is activated
	; 5 << ADPS0 -> Division factor between xtal freq and input clock to adc?
	;				division factor = 32
	ldi temp1, (3 << REFS0) | (0 << ADLAR) | (0 << MUX0)
	sts ADMUX, temp1
	ldi temp1, (1 << MUX5)
	sts ADCSRB, temp1
	ldi temp1, (1 << ADEN) | (1 << ADSC) | (1 << ADIE) | (5 << ADPS0) | (1 << ADATE)
	sts ADCSRA, temp1
	pop temp1

	ldi temp1, FLAG_UNSET
	sts potFlag, temp1
	ret

EnablePotInterrupt:
	push temp1
	ldi temp1, (1 << ADEN) | (1 << ADSC) | (1 << ADIE) | (5 << ADPS0) | (1 << ADATE)
	sts ADCSRA, temp1

	pop temp1
	ret

DisablePotInterrupt:
	push temp1

	clr temp1
	sts ADCSRA, temp1

	pop temp1
	ret

ADCCint:
	push temp1
	in temp1, SREG
	push temp1
	push temp2
	push r16

	lds temp1, currentMode
	; RESET POT MODE
	cpi temp1, MODE_RESETPOTENT
	breq HandleResetPotMode
	; FIND POT MODE
	cpi temp1, MODE_FINDPOTENT
	breq HandleFindPotMode
	; else do nothing
	rjmp return_ADCCint

	setPotResetFlag:
		sts potFlag, r16

	return_ADCCint:
		pop r16
		pop temp2
		pop temp1
		out SREG, temp1
		pop temp1
		reti

HandleResetPotMode:
	lds temp1, ADCL
	lds temp2, ADCH
	cpi temp1, 0
	brne potIsNotZero
	cpi temp2, 0
	brne potIsNotZero
	rjmp potIsZero

potIsZero:
	lds r16, potFlag
	cpi r16, FLAG_SET
	breq setPotResetFlag
	clr r16
	sts potTimer, r16
	sts potTimer+1, r16
	ldi r16, FLAG_SET
	rjmp setPotResetFlag

potIsNotZero:
	ldi r16, FLAG_UNSET
	rjmp setPotResetFlag

.def temp3 = r20
.def temp4 = r21
HandleFindPotMode:
	lds temp1, ADCL
	lds temp2, ADCH
	lds temp3, currentDesiredPot
	lds temp4, currentDesiredPot+1

	sub temp3, temp1
	sbc temp4, temp2

	ldi r16, 0
	cpi temp3, 0
	cpc temp4, r16
	brlt PotGreaterThanDesired
	rjmp PotWithinDesiredRange

PotWithinDesiredRange:
	ldi r16, high(16)
	cpi temp3, 16
	cpc temp4, r16
	brlt PotCorrect
	ldi r16, high(32)
	cpi temp3, 32
	cpc temp4, r16
	brlt PotAlmostCorrect
	ldi r16, high(48)
	cpi temp3, 48
	cpc temp4, r16
	brlt PotAlmostAlmostCorrect

	ldi r16, FLAG_UNSET
	; TODO: do nothing
	rjmp setPotResetFlag

PotCorrect:
	; if flag already set, do nothing
	lds r16, potFlag
	cpi r16, FLAG_SET
	breq setPotResetFlag
	; else:
	;  set leds
	ldi r16, 0b11111111
	out portc, r16
	ldi r16, 0b00000011
	out portg, r16
	; reset timer
	clr r16
	sts potTimer, r16
	sts potTimer+1, r16
	; set flag
	ldi r16, FLAG_SET
	rjmp setPotResetFlag

PotAlmostCorrect:
	ldi r16, 0b11111111
	out portc, r16
	ldi r16, 0b00000001
	out portg, r16
	ldi r16, FLAG_UNSET ; unset flag
	rjmp setPotResetFlag

PotAlmostAlmostCorrect:
	ldi r16, 0b11111111
	out portc, r16
	ldi r16, 0b00000000
	out portg, r16
	ldi r16, FLAG_UNSET ; unset flag
	rjmp setPotResetFlag

PotGreaterThanDesired:
	; go back to reset pot screen
	clr r16
	out portc, r16
	out portg, r16
	rcall StartResetPotent
	ldi r16, FLAG_UNSET ; unset flag
	rjmp setPotResetFlag

.undef temp3
.undef temp4

.undef temp1
.undef temp2

<file_sep>/*
 * Macros.asm
 *
 *  Created: 18/05/2017 12:31:13 PM
 *   Author: Vince
 */
 .include "m2560def.inc"

.macro do_lcd_command
	ldi r16, @0
	rcall lcd_command
	rcall lcd_wait
.endmacro

.macro initialise_items ;intialises items with default value
	ldi r16, 1
	sts Item1Count, r16
	clr r16
	ldi r16, 2
	sts Item2Count, r16
	clr r16
	ldi r16, 3
	sts Item3Count, r16
	clr r16
	ldi r16, 4
	sts Item4Count, r16
	clr r16
	ldi r16, 5
	sts Item5Count, r16
	clr r16
	ldi r16, 6
	sts Item6Count, r16
	clr r16
	ldi r16, 7
	sts Item7Count, r16
	clr r16
	ldi r16, 8
	sts Item8Count, r16
	clr r16
	ldi r16, 9
	sts Item9Count, r16
	clr r16
	ldi r16, 1
	sts Item1Price, r16
	clr r16
	ldi r16, 2
	sts Item2Price, r16
	clr r16
	ldi r16, 1
	sts Item3Price, r16
	clr r16
	ldi r16, 2
	sts Item4Price, r16
	clr r16
	ldi r16, 1
	sts Item5Price, r16
	clr r16
	ldi r16, 2
	sts Item6Price, r16
	clr r16
	ldi r16, 1
	sts Item7Price, r16
	clr r16
	ldi r16, 2
	sts Item8Price, r16
	clr r16
	ldi r16, 1
	sts Item9Price, r16
	clr r16
	ldi r16, 5
	sts CoinsRemaining, r16;outside of the max price of 3 so theres no conflicts and can be properly intialised via user input
	clr r16
.endmacro

.macro subtract_item_count; we subtract a selected items inventory count by 1
	push temp1
	push temp2
	push temp3
	clr YL
	clr YH
	ldi YL, LOW(item1Count) ;initialising y pointer to point at the inventory in SRAM
	ldi YH, HIGH(item1Count)
	ldi temp3, 1
	lds temp2,SelectedItemNum ; the item we are subtracting from
sub_loop: ;finding the item which we are decrementing
	cp temp3,temp2
	breq decrement
	inc temp3
	inc YL
	rjmp sub_loop
decrement:
	ld temp1, Y
	dec temp1 ;subtract 1 from the number of items
	st Y,temp1; store the number of items
	pop temp3 ;restore registers
	pop temp2
	pop temp1
.endmacro

.macro do_lcd_data ; prints an lcd command or a character
	ldi r16, @0
	rcall lcd_data
	rcall lcd_wait
.endmacro

.macro do_lcd_data_register;prints the value of a register to the lcd
	mov r16, @0
	rcall lcd_data
	rcall lcd_wait
.endmacro

.macro do_select_screen ; we draw the select screen
	stop_timer ;stopping timers as there are no timer interrupts occuring while on this screen
	stop_timer2
	Reset_Coins_Remaining; number of coins remaining is rese
	do_lcd_command 0b00000001
	do_lcd_data 'S'
	do_lcd_data 'e'
	do_lcd_data 'l'
	do_lcd_data 'e'
	do_lcd_data 'c'
	do_lcd_data 't'
	do_lcd_data ' '
	do_lcd_data 'i'
	do_lcd_data 't'
	do_lcd_data 'e'
	do_lcd_data 'm'
	ldi State,SELECT ;state is changed to SELECT
.endmacro

.macro do_delivery_screen ;do delivery screen
	stop_timer2 ;potentiometer timer is stopped
	start_timer; select screen timer is started - we return to select screen after 3 seconds.

	Reset_Coins_Remaining ;reset coins remaining
	do_lcd_command 0b00000001
	do_lcd_data 'D'
	do_lcd_data 'e'
	do_lcd_data 'l'
	do_lcd_data 'i'
	do_lcd_data 'v'
	do_lcd_data 'e'
	do_lcd_data 'r'
	do_lcd_data 'i'
	do_lcd_data 'n'
	do_lcd_data 'g'
	do_lcd_data ' '
	do_lcd_data 'i'
	do_lcd_data 't'
	do_lcd_data 'e'
	do_lcd_data 'm'
	ldi State,Delivery ;change state to delivery
.endmacro
.macro do_startup_screen ;start up screen occurs when power on or reset is pressed
	do_lcd_data '2'
	do_lcd_data '1'
	do_lcd_data '2'
	do_lcd_data '1'
	do_lcd_data ' '
	do_lcd_data '1'
	do_lcd_data '7'
	do_lcd_data 's'
	do_lcd_data '1'
	do_lcd_data ' '
	do_lcd_data ' '
	do_lcd_data ' '
	do_lcd_data 'K'
	do_lcd_data '6'
	do_lcd_command 0b11000000
	do_lcd_data 'V'
	do_lcd_data 'e'
	do_lcd_data 'n'
	do_lcd_data 'd'
	do_lcd_data 'i'
	do_lcd_data 'n'
	do_lcd_data 'g'
	do_lcd_data ' '
	do_lcd_data 'M'
	do_lcd_data 'a'
	do_lcd_data 'c'
	do_lcd_data 'h'
	do_lcd_data 'i'
	do_lcd_data 'n'
	do_lcd_data 'e'
.endmacro

.macro Subtract_Coins_Remaining ; we subtract the coins remaining(value stored in SRAM) by 1
	push temp3
	lds temp3,CoinsRemaining
	dec temp3
	sts CoinsRemaining,temp3
	pop temp3
.endmacro

.macro do_coin_screen;we draw the coin screen
	stop_timer; cancel the interrupt for the select screen
	cli ; no interrupts occuring while this screen is being drawn
	push temp1
	push temp2
	push temp3
	ldi temp2,1
	ld temp1, Z
	clr YL
	clr YH
	ldi YL, LOW(item1Price)
	ldi YH, HIGH(item9Price)
	lds temp3,coinsRemaining
price_loop:
	cp temp2, temp1
	breq lcd_out
	inc YL
	inc temp2
	rjmp price_loop
lcd_out:
	ld temp1, Y
	cpi temp3,5;We compare if coins remaining is uninitialised - that is value is 5
	brne lcd_out_continue
	mov temp3, temp1

	sts CoinsRemaining,temp3;set it to default price stored in ram e.g item1Price
lcd_out_continue:
	ldi temp2, toASCII ;ASCII offsett
	add temp3,temp2
	do_lcd_command 0b00000001
	do_lcd_data 'I'
	do_lcd_data 'n'
	do_lcd_data 's'
	do_lcd_data 'e'
	do_lcd_data 'r'
	do_lcd_data 't'
	do_lcd_data ' '
	do_lcd_data 'c'
	do_lcd_data 'o'
	do_lcd_data 'i'
	do_lcd_data 'n'
	do_lcd_data 's'
	do_lcd_command 0b11000000
	do_lcd_data_register temp3
	pop temp3
	pop temp2
	pop temp1
	clr YL
	clr YH
	start_timer2 ; start the potentiometer interrupt timer
	sei; enable interrupts again
.endmacro

.macro do_empty_screen ;draws empty screen
	start_timer ;can be interrupted by select timer
	stop_timer2; but not by pentiometer timer
	push temp3
	push temp2
	lds temp3, SelectedItemNum ;load last selected item into temp3 which is empty
	ldi temp2, toASCII
	add temp3, temp2
	do_lcd_command 0b00000001
	do_lcd_data 'O'
	do_lcd_data 'u'
	do_lcd_data 't'
	do_lcd_data ' '
	do_lcd_data 'o'
	do_lcd_data 'f'
	do_lcd_data ' '
	do_lcd_data 'S'
	do_lcd_data 't'
	do_lcd_data 'o'
	do_lcd_data 'c'
	do_lcd_data 'k'
	do_lcd_command 0b11000000
	do_lcd_data_register temp3 ;temp3 represents item that is empty
	pop temp2
	pop temp3
.endmacro

.macro clear
	ldi YL, low(@0) ; load the memory address to Y
	ldi YH, high(@0)
	clr temp1
	st Y+, temp1 ; clear the two bytes at @0 in SRAM
	st Y, temp1
.endmacro

.macro stop_timer ;stop select timer
	push temp1
	ldi temp1, 0b00000000
	out TCCR0B, temp1
	pop temp1
.endmacro

.macro start_timer;start select timer
	push temp1
	ldi temp1, 0b00000000
	out TCCR0A, temp1
	ldi temp1, 0b00000010
	out TCCR0B, temp1 ; Prescaling value=8
	ldi temp1, 1<<TOIE0 ; = 128 microseconds
	sts TIMSK0, temp1 ; T/C0 interrupt enable
	pop temp1
.endmacro

.macro setup_pot ;intialises potentiometer -interrupts off
	ldi temp1, (3 << REFS0) | (0 << ADLAR) | (0 << MUX0);
	sts ADMUX, temp1
	ldi temp1, (1 << MUX5);
	sts ADCSRB, temp1
	ldi temp1, (1 << ADEN) | (1 << ADSC) | (0 << ADIE) | (5 << ADPS0)|(1 << ADATE);
	sts ADCSRA, temp1
.endmacro

.macro enable_pot_int;potentiometer interrupts are on
	push temp1
	ldi temp1, (1 << ADEN) | (1 << ADSC) | (1 << ADIE) | (5 << ADPS0)|(1 << ADATE);
	sts ADCSRA, temp1
	pop temp1
.endmacro

.macro disable_pot_int;potentiometer interrupts are off
	push temp1
	ldi temp1, (1 << ADEN) | (1 << ADSC) | (0 << ADIE) | (5 << ADPS0)|(1 << ADATE);
	sts ADCSRA, temp1
	pop temp1
.endmacro

.macro setup_timer2; setsup timer 2 with its interrupt off
	ldi temp1, 0b00000000
	sts TCCR2A, temp1
	ldi temp1, 0b00000000 ;default disable timer1
	sts TCCR2B, temp1 ; Prescaling value=8
	ldi temp1, 1<<TOIE0 ; = 128 microseconds
	sts TIMSK2, temp1 ; T/C0 interrupt enable
.endmacro

.macro stop_timer2 ;turn off interrupts for timer 2
	push temp1
	ldi temp1, 0b00000000
	sts TCCR2B, temp1
	pop temp1
.endmacro

.macro start_timer2; start interrupts for timer 2
	push temp1
	ldi temp1, 0b00000010
	sts TCCR2B, temp1
	pop temp1
.endmacro

.macro Reset_PotFlags ; reset pot left and right flags, when coin has been inserted
	push r16
	ldi r16,0
	sts PotFlag_Left,r16
	sts PotFlag_Right,r16
	pop r16
.endmacro

.macro Reset_Coins_Remaining ;resets number of cons needed to be inserted .
	push r16
	ldi r16, 5
	sts CoinsRemaining,r16
	pop r16
.endmacro<file_sep>
;
; Lab4Q3.asm
;
; Created: 10/05/2017 4:43:56 PM
; Author : Vince
;

.include "m2560def.inc"
.include "Macros.asm"

.dseg
	SecondCounter:
.byte 2 ; Two-byte counter for counting seconds.
	TempCounter:
.byte 2
	SecondCounter_2:
.byte 2 ; Two-byte counter for counting seconds.
	TempCounter_2:
.byte 2
	Item1Count: ;inventory count for all the items
.byte 1
	Item2Count:
.byte 1
	Item3Count:
.byte 1
	Item4Count:
.byte 1
	Item5Count:
.byte 1
	Item6Count:
.byte 1
	Item7Count:
.byte 1
	Item8Count:
.byte 1
	Item9Count:
.byte 1
	Item1Price:;inventory prices for all the items
.byte 1
	Item2Price:
.byte 1
	Item3Price:
.byte 1
	Item4Price:
.byte 1
	Item5Price:
.byte 1
	Item6Price:
.byte 1
	Item7Price:
.byte 1
	Item8Price:
.byte 1
	Item9Price:
.byte 1
	SelectedItemNum: ;last selected item via keypad press
.byte 1
	PotFlag_Right: ; 1 when pot has been turned fully clockwise else 0
.byte 1
	PotFlag_Left:; 1 when pot has been turned fully anticlockwise
.byte 1
	CoinsRemaining: ;num coins remaining to be inserted.
.byte 1

.cseg
.org 0
	jmp RESET
.org OVF2addr
	jmp Timer2OVF ;timer2 overflow handler
.org OVF0addr
	jmp Timer0OVF ;timer0 overflow handler
.org ADCCaddr
	jmp POT_HANDLER

.def row = r16              ; current row number
.def col = r17              ; current column number
.def rmask = r18            ; mask for current row during scan
.def cmask = r19            ; mask for current column during scan
.def temp1 = r20
.def temp2 = r21
.def temp3 = r22
.def state = r23 ; 0-start,1-select,2-empty,3-coin, states of the machine
.def temp4 = r24
.equ START = 0
.equ SELECT = 1
.equ EMPTY = 2
.equ COIN = 3
.equ DELIVERY = 4
.equ toASCII = 48 ; to offset numbers into their ASCII counterpart
.equ PORTLDIR = 0xF0        ; PH7-4: output, PH3-0, input
.equ INITCOLMASK = 0xEF     ; scan from the rightmost column,
.equ INITROWMASK = 0x01     ; scan from the top row
.equ ROWMASK = 0x0F         ; for obtaining input from Port L

POT_HANDLER:;handling the potentiometer turns
	push temp1
	push temp2
	push temp3
	push temp4
	push r16
	lds temp1, ADCL
	lds temp2, ADCH

CompareMaxClockWise:
	ldi temp3, low(0x3ff)
	ldi temp4, high(0x3ff)
	;compare if max turn clockwise on pot
	cp temp1, temp3
	cpc temp2, temp4
	breq MaxClockWise

CompareMaxAntiClockWise:
	ldi temp3, low(0)
	ldi temp4, high(0)
	;compare if max turn anti-clockwise on pot
	cp temp1, temp3
	cpc temp2, temp4
	breq MaxAntiClockWise
	jmp POT_HANDLE_FINAL
MaxClockWise:;setting pot right flag to 1
	ldi r16, 1
	sts PotFlag_Right, r16
	jmp POT_HANDLE_FINAL

MaxAntiClockWise:

	lds r16,PotFlag_Right
	cpi r16,1
	breq HalfTurn ; check if pot right is 1 if it 1 then we check if pot left has been previously flagged 1
MaxAntiClockWise_Cont:
	ldi r16, 1
	sts PotFlag_Left, r16 ;set pot left flag to 1
	jmp POT_HANDLE_FINAL

HalfTurn:
	lds r16,PotFlag_Left
	cpi r16,1
	breq Coin_Inserted ;if pot left is also 1 then we know a coin has been inserted
	jmp MaxAntiClockWise_Cont

Coin_Inserted:
	Subtract_Coins_Remaining ;we subtract 1 from the coins remaining that is stored in dseg
	lds r16,CoinsRemaining
	Reset_PotFlags	; reset pot flags
	cpi r16,0 ; if coins remaining =0
	breq Coin_Inserted_Cont
	jmp Coins_Remaining
Coin_Inserted_cont:
	do_lcd_data 'P'
	ldi State,DELIVERY
	do_delivery_screen ; show delivery screen coins remaining is 0
	subtract_item_count ;subtract inventory amount
	Reset_Coins_Remaining ; reset the number of coins remaining
	jmp POT_HANDLE_FINAL
Coins_Remaining:
	do_coin_screen ;draw updated coin screen with new coins remaining

POT_HANDLE_FINAL: ; restore registers
	pop r16
	pop temp4
	pop temp3
	pop temp2
	pop temp1
	ret

Timer2OVF:;every 1/3 second we check the turn values of the potentiometer
	in temp1, SREG
	push temp1 ; Prologue starts.
	push YH ; Save all conflict registers in the prologue.
	push YL
	push r25
	push r24 ; Prologue ends.
	; Load the value of the temporary counter.
	lds r24, TempCounter_2
	lds r25, TempCounter_2+1
	adiw r25:r24, 1 ; Increase the temporary counter by one.
	cpi r24, low(2343) ; roughly once every 1/3 of a second
	ldi temp1, high(2343) ;
	cpc r25, temp1
	brne NotSecond_2
	rcall POT_HANDLER ; we check the turn values of the potentiometer
	clear TempCounter_2 ; Reset the temporary counter.
	; Load the value of the second counter.
	lds r24, SecondCounter_2
	lds r25, SecondCounter_2+1
	adiw r25:r24, 1 ; Increase the second counter by one.
	sts SecondCounter_2, r24
	sts SecondCounter_2+1, r25
	rjmp EndIF_2

NotSecond_2:
	; Store the new value of the temporary counter.
	sts TempCounter_2, r24
	sts TempCounter_2+1, r25

EndIF_2:
	pop r24 ; Epilogue starts;
	pop r25 ; Restore all conflict registers from the stack.
	pop YL
	pop YH
	pop temp1
	out SREG, temp1
	reti ; Return from the interrupt.

Timer0OVF: ; after 3 seconds we draw the select screen
	in temp1, SREG
	push temp1 ; Prologue starts.
	push YH ; Save all conflict registers in the prologue.
	push YL
	push r25
	push r24 ; Prologue ends.
	; Load the value of the temporary counter.
	lds r24, TempCounter
	lds r25, TempCounter+1
	adiw r25:r24, 1 ; Increase the temporary counter by one.
	cpi r24, low(23436) ; Check if (r25:r24) = 7812
	ldi temp1, high(23436) ; 3 second timer
	cpc r25, temp1
	breq IsSecond
	jmp NotSecond
IsSecond:
	do_select_screen ;3 seconds is up so we draw the select screen
	;;	com leds
	;;	out PORTC, leds
	clear TempCounter ; Reset the temporary counter.
	; Load the value of the second counter.
	lds r24, SecondCounter
	lds r25, SecondCounter+1
	adiw r25:r24, 1 ; Increase the second counter by one.
	sts SecondCounter, r24
	sts SecondCounter+1, r25
	rjmp EndIF

NotSecond:
	; Store the new value of the temporary counter.
	sts TempCounter, r24
	sts TempCounter+1, r25

EndIF:
	pop r24 ; Epilogue starts;
	pop r25 ; Restore all conflict registers from the stack.
	pop YL
	pop YH
	pop temp1
	out SREG, temp1
	reti ; Return from the interrupt.

RESET:
    ldi temp1, low(RAMEND)  ; initialize the stack
    out SPL, temp1
    ldi temp1, high(RAMEND)
    out SPH, temp1
    ldi temp1, PORTLDIR     ; PB7:4/PB3:0, out/in
    sts DDRL, temp1         ; PORTB is input
    ser temp1               ; PORTC is output
    out DDRC, temp1
    out PORTC, temp1
	ldi r16, low(RAMEND)
	out SPL, r16
	ldi r16, high(RAMEND)
	out SPH, r16
	ser r16
	out DDRF, r16
	out DDRA, r16
	clr r16
	out PORTF, r16
	out PORTA, r16
	do_lcd_command 0b00111000 ; 2x5x7
	rcall sleep_5ms
	do_lcd_command 0b00111000 ; 2x5x7
	rcall sleep_1ms
	do_lcd_command 0b00111000 ; 2x5x7
	do_lcd_command 0b00111000 ; 2x5x7
	do_lcd_command 0b00001000 ; display off?
	do_lcd_command 0b00000001 ; clear display
	do_lcd_command 0b00000110 ; increment, no display shift
    do_lcd_command 0b00001100 ; Cursor on, bar, no blink
	do_startup_screen

	clear TempCounter ; Initialize the temporary counter to 0
	clear SecondCounter ; Initialize the second counter to 0
	ldi temp1, 0b00000000
	out TCCR0A, temp1
	ldi temp1, 0b00000010
	out TCCR0B, temp1 ; Prescaling value=8
	ldi temp1, 1<<TOIE0 ; = 128 microseconds
	sts TIMSK0, temp1 ; T/C0 interrupt enable
	setup_timer2
	sei ; Enable global interrupt
	ldi State,START
	initialise_items ;initialise inventory and prices
	setup_pot; setup potentiometer

	rjmp main

;we check the state of the machine
main:
	clr temp1
	cpi State,START
	brne main2
	jmp polling
main2: ; start and select both involve polling straight away
	cpi State,SELECT
	brne main3
	jmp polling
main3:
	cpi State,COIN
	brne main4
	jmp coin_selection ; go to coin selection
main4:
	cpi State,EMPTY
	brne main5
	jmp empty_screen ; go to empty stock
main5:
	cpi State,DELIVERY
	brne main6
	jmp delivery_screen; go to delivery
main6:
	jmp main
delivery_screen:
	do_delivery_screen; draw delivery screen
	rcall sleep_25ms
	rcall sleep_25ms
	jmp polling

coin_selection:
	do_coin_screen;draw coin screen
	rcall sleep_25ms
	rcall sleep_25ms
	jmp polling

empty_screen:
	do_empty_screen;draw empty screen
	rcall sleep_25ms
	rcall sleep_25ms
	jmp polling
	;;jmp halt

polling:;polling keypad press
    ldi cmask, INITCOLMASK  ; initial column mask why does 11101111
    clr col                 ; initial column start at column 0

colloop:
    cpi col, 4				; have we reached the 4th column?
    breq polling              ; scanned all keys reset and start all over.
    sts PORTL, cmask        ; Otherwise, scan a column.
    ldi temp1, 0xFF         ; Slow down the scan operation.

delay:
    dec temp1
    brne delay              ; until temp1 is zero

    lds temp1, PINL          ; Read PORTL that is port connects to keypad
    andi temp1, ROWMASK     ; Get the keypad output value remember rowmask is 1111 in binary
    cpi temp1, 0xF          ; Check if any row is low, check if temp1 is the same as rowmask
    breq nextcol            ; if not - switch to next column(

                            ; If yes, find which row is low
    ldi rmask, INITROWMASK  ; initialize for row check
    clr row

; and going into the row loop
rowloop:
    cpi row, 4              ; is row already 4?
    breq nextcol            ; the row scan is over - next column
    mov temp2, temp1		; clone temp1 please
    and temp2, rmask        ; check un-masked bit
    breq convert            ; if bit is clear, the key is pressed !!! so it sthe center 0 of the cross of 1's
    inc row                 ; else move to the next row
    lsl rmask
    jmp rowloop

nextcol:                    ; if row scan is over
     lsl cmask				; shift left i.e times by 2 so 1111 become 1110 cos overflow i think
     inc col                ; increase col value
     jmp colloop            ; go to the next column

convert:
    cpi col, 3              ; If the pressed key is in col 3
    brne convert2
	jmp letters

convert2:           ; we have letter                            ; If the key is not in col 3 and
    cpi row, 3              ; if the key is in row 3,
    brne convert3
	jmp symbols ;  we have a symbol or 0

convert3:
    mov temp1, row          ; otherwise we have a number 1-9
    lsl temp1
    add temp1, row
    add temp1, col          ; temp1 = row*3 + col
	subi temp1, -1	;111
	cpi temp1, 1
	push temp1

	cpi State,START ;interrupting the intro screen via keypad press
	breq select_interrupt

    jmp convert_end ; deciding which item is being pressed

select_interrupt:;so start screen is interuppted via keypad press
	do_select_screen
	rcall sleep_25ms
	jmp main; new state is SELECT

letters:
	do_select_screen
    jmp main

symbols:
	do_select_screen
    jmp main
star:
	do_select_screen

    jmp main
zero:
	do_select_screen
	jmp convert_end

convert_end:
	cpi State,SELECT
	breq perform_selection ;we only can select items during SELECT state otherwise we just change state to SELECT
	jmp main ;otherwise we do nothing and loop to main

perform_selection:
	sts SelectedItemNum, temp1 ;; store the item we have selected for future use in case
	clr ZL
	clr ZH
	ldi ZL, LOW(item1Count)
	ldi ZH, HIGH(item9Count)
	ldi temp3, 1

selection_loop:
	cp temp3,temp1;loop through until we find the right item in SRAM
	breq selection; Z points to that item and we exit
	inc temp3
	inc ZL
	rjmp selection_loop

selection:
	ld temp1, Z ; getting quantity of the item in stock
	cpi temp1,0
	breq empty_selection ;if nothing left we change the state to be empty
	ldi State,COIN ; otherwise the state is set to coin
	jmp main ;

empty_selection:
	ldi State,Empty ;state is set to empty
	jmp main

halt:
	rjmp halt

.equ LCD_RS = 7
.equ LCD_E = 6
.equ LCD_RW = 5
.equ LCD_BE = 4

.macro lcd_set
	sbi PORTA, @0
.endmacro
.macro lcd_clr
	cbi PORTA, @0
.endmacro
;LED commands for drawing characters and data from registers.
lcd_command:
	out PORTF, r16
	rcall sleep_1ms
	lcd_set LCD_E
	rcall sleep_1ms
	lcd_clr LCD_E
	rcall sleep_1ms
	ret

lcd_data:
	out PORTF, r16
	lcd_set LCD_RS
	rcall sleep_1ms
	lcd_set LCD_E
	rcall sleep_1ms
	lcd_clr LCD_E
	rcall sleep_1ms
	lcd_clr LCD_RS
	ret

lcd_wait:
	push r16
	clr r16
	out DDRF, r16
	out PORTF, r16
	lcd_set LCD_RW
lcd_wait_loop:
	rcall sleep_1ms
	lcd_set LCD_E
	rcall sleep_1ms
	in r16, PINF
	lcd_clr LCD_E
	sbrc r16, 7
	rjmp lcd_wait_loop
	lcd_clr LCD_RW
	ser r16
	out DDRF, r16
	pop r16
	ret

.equ F_CPU = 16000000
.equ DELAY_1MS = F_CPU / 4 / 1000 - 4
; 4 cycles per iteration - setup/call-return overhead

;delay commands for polling and to regulate the rendering of the lcd and keypad presses
sleep_1ms:
	push r24
	push r25
	ldi r25, high(DELAY_1MS)
	ldi r24, low(DELAY_1MS)
delayloop_1ms:
	sbiw r25:r24, 1
	brne delayloop_1ms
	pop r25
	pop r24
	ret

sleep_5ms:
	rcall sleep_1ms
	rcall sleep_1ms
	rcall sleep_1ms
	rcall sleep_1ms
	rcall sleep_1ms
	ret

sleep_25ms:
	rcall sleep_5ms
	rcall sleep_5ms
	rcall sleep_5ms
	rcall sleep_5ms
	rcall sleep_5ms
	ret

repo_language: Assembly

repo_name: Vincentvtt/Assembly-Project


text:
<file_sep><?php
/**
 * Created by PhpStorm.
 * User: Phongnv093
 * Date: 9/29/2015
 * Time: 8:45 PM
 */

namespace sya\payment;

use Yii;
use yii\bootstrap\Html;
use yii\widgets\InputWidget;
use yii\helpers\ArrayHelper;
use yii\web\View;

class Payment extends InputWidget
{
    CONST STATUS_TRANSFER = 'transfer';

    CONST STATUS_PAYATHOME = 'pay_at_home';

    CONST STATUS_EMPTY = '';

    private static $_instance = null;

    /**
     * @var string Name input when haven't model
     */
    public $name = '';

    /**
     * @var string value selected in input
     */
    public $selected = '';

    /**
     * @var array columns in input
     */
    public $columns = [];

    /**
     * @var array item in input
     */
    protected $items = [];

    /**
     * @var array Html attribute of input
     */
    public $options = [];

    /**
     * @return \sya\payment\Payment
     */
    public static function getInstance()
    {
        if (null === static::$_instance) {
            static::$_instance = new static();
        }

        return static::$_instance;
    }

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();

        $this->buildItems();

        if (!isset($this->options['class']))
            $this->options['class'] = 'form-control';
        else
            $this->options['class'] = $this->options['class'] . ' form-control';

        if (!isset($this->options['columnClass']))
            $this->options['columnClass'] = 'form-control';
        else
            $this->options['columnClass'] = $this->options['columnClass'] . ' form-control';

        if (!isset($this->options['onchange']))
            $this->options['onchange'] = 'changeValueStatusPayment(this);';

        $this->buildItems();
    }

    public function run() {
        $this->registerAssets();

        echo $this->renderInput();
    }

    /**
     * @return string render input
     */
    protected function renderInput()
    {
        $input = Html::dropDownList($this->name, $this->selected, $this->items, $this->options);

        // If use form model then $input use active input
        if ($this->hasModel())
            $input = Html::activeDropDownList($this->model, $this->attribute . '[status]', $this->items, $this->options);

        $input .= Html::beginTag('div', ['id' => 'status_payment', 'style' => 'margin-top: 20px;']);
            foreach ($this->columns as $status => $item) {
                $input .= Html::beginTag('div', ['class' => 'status_payment', 'id' => 'status_payment_' . $status, 'style' => 'display: none']);
                    foreach ($item as $name => $info) {
                        $column_value = Html::getAttributeValue($this->model, $this->attribute . '[infomation][' . $name . ']');
                        $placeholder = isset($info['placeholder']) ? $info['placeholder'] : null;
                        $value = !empty($column_value) ? $column_value : ArrayHelper::getValue($info, 'value');
                        $readonly = isset($info['readonly']) ? $info['readonly'] : null;

                        $input .= Html::activeInput('text', $this->model, $this->attribute . '[infomation][' . $name . ']', ['placeholder' => $placeholder, 'class' => $this->options['columnClass'], 'readonly' => $readonly, 'value' => $value, 'style' => 'margin-top: 20px;']);
                    }
                $input .= Html::endTag('div');
            }
        $input .= Html::endTag('div');

        return $input;
    }

    protected function buildItems()
    {
        $this->items = [
            self::STATUS_EMPTY => Yii::t('payment', '-- Select a payment method --'),
            self::STATUS_PAYATHOME => Yii::t('payment', 'Pay at home'),
            self::STATUS_TRANSFER => Yii::t('payment', 'Transfer')
        ];
    }

    private function registerAssets() {
        $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute . '[status]') : $this->selected;
        $this->getView()->registerJs('
            function changeValueStatusPayment(element){
                var status = $(element).val();

                $(".status_payment").hide();
                $("#status_payment_" + status).show();
            }
        ', View::POS_END);

        $this->getView()->registerJs('
            var status = "' . $value . '";
            $("#status_payment_" + status).show();
        ', View::POS_READY);
    }

    public function getStatus($status){
        if (empty($status))
            return $this->items;

        return ArrayHelper::getValue($this->items, $status);
    }
}<file_sep><?php
return [
    'Pay at home' => 'Thanh toán tại nhà',
    'Transfer' => 'Chuyển khoản',
    '-- Select a payment method --' => '-- Chọn phương thức thanh toán --',
    'Online' => 'Thanh toán online'
];
<file_sep># yii2-payment
yii2 payment

## Installation
Add

```php
"sya/yii2-payment": "dev-master"
```

to the require section of your composer.json file.

# Use
```php
use sya\payment\Payment;

$form->field($model, 'payment')->widget(Payment::className(), []);

OR

Payment::widget();
```

## License
**yii2-payment** is released under the MIT License. See the bundled LICENSE.md for details.

languages: Markdown PHP