{"size": 1757, "ext": "js", "max_stars_repo_path": "static/js/app.js", "max_stars_repo_name": "Aspace-dev/Austin-Spacek---Homework-10", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "static/js/app.js", "max_issues_repo_name": "Aspace-dev/Austin-Spacek---Homework-10", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "static/js/app.js", "max_forks_repo_name": "Aspace-dev/Austin-Spacek---Homework-10", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.4637681159, "max_line_length": 72, "alphanum_fraction": 0.6027319294}
// Defining some variables
const tableData = data
const tbody = d3.select('tbody')
const dateIn = d3.select('#datetime')

// buildTable(tableData) - Building the datatable
function buildTable(data) {
    tbody.html('')  // Clear existing data

    data.forEach(row => {
        const currentRow = tbody.append('tr')  // append row
        Object.values(row).forEach(value => {
            const cell = currentRow.append('td')
            cell.text(value)
        })
    })
}

// defining the handle
const handleClick = () => {
    d3.event.preventDefault()

    const date = d3.select('#datetime').property('value')
    let filteredData = tableData;

    if (date)
        filteredData = filteredData.filter(row => row.datetime === date)
    
    tbody.html('')  // Clear existing data

    data.forEach(row => {
        const currentRow = tbody.append('tr')  // append row
        Object.values(row).forEach(value => {
            const cell = currentRow.append('td')
            cell.text(value)
        })
    })
}

d3.selectAll('#filter-btn').on('click', handleClick)

// Applying the filter
filBtn = d3.select('#filter-btn')
const applFilter = () => {
    d3.event.preventDefault()

    let filterData = tableData
    const dateSearch = d3.select('#datetime').property('value')

    if (dateSearch)
        filterData = filterData.filter(row => 
            row.datetime == dateSearch
            )
    tbody.html('')

    filterData.forEach(row => {
        const currentRow = tbody.append('tr')
        Object.values(row).forEach(value => {
            const cell = currentRow.append('td')
            cell.text(value)
        })
    })
}

// Calling the functions
buildTable(tableData)
dateIn.on('change', applFilter)
filBtn.on('click', applFilter)
