Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add campaign finance. #420

Closed
fgregg opened this issue May 31, 2024 · 2 comments
Closed

add campaign finance. #420

fgregg opened this issue May 31, 2024 · 2 comments

Comments

@fgregg
Copy link
Member

fgregg commented May 31, 2024

vibe off of this

<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, minimum-scale=1.0, user-scalable=no"
    />
    <title>Illinois Campaign Finance - Datasette DataTable example</title>
    <link rel="stylesheet" type="text/css" href="./jquery.dataTables.css" />
    <script
      type="text/javascript"
      language="javascript"
      src="https://code.jquery.com/jquery-3.5.1.js"
    ></script>
    <script
      type="text/javascript"
      language="javascript"
      src="./jquery.dataTables.js"
    ></script>
    <script type="text/javascript" language="javascript" class="init">
      $(document).ready(function () {
        $("#example tfoot th").each(function () {
          const title = $(this).text();
          $(this).html(
            '<input type="text" placeholder="Search ' + title + '" />',
          );
        });

        $("#example").DataTable({
          columns: [
            { data: "committee_name" },
            { data: "received_date" },
            {
              data: "amount",
              render: $.fn.dataTable.render.number(",", ".", 0, "$"),
              className: "dt-body-right",
            },
            { data: "type" },
            { data: "name" },
            { data: "occupation" },
            { data: "employer" },
            { data: "city_state_zip" },
            {
              data: "filed_doc_id",
              defaultContent: "",
              render: function (data, type, row, meta) {
                if (type === "display") {
                  const encoded_doc_id = encodeURIComponent(row.filed_doc_id);
                  let path = "";
                  switch (row.doc_name) {
                    case "A-1":
                      path = `A1List.aspx?FiledDocID=${encoded_doc_id}&ContributionType=wOGh3QTPfKqV2YWjeRmjTeStk426RfVK&Archived=Gl5sibpnFrQ%3d`;
                      break;
                    case "Final":
                      path = `D2Semiannual.aspx?id=${encoded_doc_id}`;
                      break;
                    default:
                      path = `D2Quarterly.aspx?id=${encoded_doc_id}`;
                  }
                  return `<a href="https://www.elections.il.gov/CampaignDisclosure/${path}">${row.filed_doc_id}</a>`;
                }
              },
            },
          ],
          order: [[1, "desc"]],
          processing: true,
          serverSide: true,
          searching: true,
          ajax: "https://puddle.bunkum.us/il_campaign_disclosure.datatable?sql=select%0D%0A++committees.name+AS+committee_name%2C%0D%0A++strftime+(%27%25Y-%25m-%25d%27%2C+received_date)+AS+received_date%2C%0D%0A++amount%2C%0D%0A++CASE%0D%0A++++WHEN+d2_part+%3D+%271A%27+THEN+%27individual+contribution%27%0D%0A++++WHEN+d2_part+%3D+%272A%27+THEN+%27transfer%27%0D%0A++++WHEN+d2_part+%3D+%273A%27+THEN+%27loan%27%0D%0A++++WHEN+d2_part+%3D+%274A%27+THEN+%27other+receipts%27%0D%0A++++WHEN+d2_part+%3D+%275A%27+THEN+%27in-kind%27%0D%0A++END+AS+type%2C%0D%0A++CASE%0D%0A++++WHEN+first_name+IS+NOT+NULL+THEN+first_name+||+%27+%27+||+last_name%0D%0A++++ELSE+last_name%0D%0A++END+AS+name%2C%0D%0A++occupation%2C%0D%0A++employer%2C%0D%0A++receipts.city+||+%27%2C+%27+||+receipts.state+||+%27+%27+||+receipts.zipcode+AS+city_state_zip%2C%0D%0A++filed_doc_id%2C%0D%0A++doc_name%0D%0Afrom%0D%0A++committee_candidate_links%0D%0A++inner+join+committees+on+committee_candidate_links.committee_id+%3D+committees.id%0D%0A++inner+join+receipts+using+(committee_id)%0D%0A++INNER+JOIN+filed_docs+ON+filed_doc_id+%3D+filed_docs.id%0D%0Awhere%0D%0A++candidate_id+%3D+25264%0D%0A++and+type+!%3D+%27Political+Action%27%0D%0A++and+receipts.archived+%3D+0",
          initComplete: function () {
            const delay = 500;

            // Apply the search
            this.api()
              .columns()
              .every(function () {
                const that = this;
                const searchInput = $("input", this.footer());
                let searchTimeout;

                searchInput.on("keyup clear", function () {
                  clearTimeout(searchTimeout);
                  searchTimeout = setTimeout(function () {
                    if (that.search() !== searchInput.val()) {
                      that.search(searchInput.val()).draw();
                    }
                  }, delay);
                });
              });
          },
        });
      });
    </script>
  </head>
  <body>
    <div class="container">
      <div class="demo-html"></div>
      <table id="example" class="display" style="width: 100%">
        <thead>
          <tr>
            <th>Commitee Name</th>
            <th>Received Date</th>
            <th>Amount</th>
            <th>Type</th>
            <th>Donor Name</th>
            <th>Occupation</th>
            <th>Employer</th>
            <th>City, State Zip</th>
            <th>Filing</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th>Commitee Name</th>
            <th>Received Date</th>
            <th>Amount</th>
            <th>Type</th>
            <th>Donor Name</th>
            <th>Occupation</th>
            <th>Employer</th>
            <th>City, State Zip</th>
            <th>Filing</th>
          </tr>
        </tfoot>
      </table>
    </div>
  </body>
</html>
@derekeder
Copy link
Member

closed via #421

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants