Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package.json
package-lock.json
node_modules
public/.sass-cache
Procfile
.Procfile
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# project_what_have_you_done
Build an application to help track the legislative activities of your local representatives.

Heroku App: https://ancient-plateau-43269.herokuapp.com/
77 changes: 77 additions & 0 deletions models/info_wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const base_uri = "https://congress.api.sunlightfoundation.com";
const request = require('request');

var Wrapper = {

locate_legislators: function(zip){
var url_param = `legislators/locate?zip=${zip}`;
var url = this.generate_url(url_param);
return Wrapper.make_request(url);
},

get_bills_voted_on: function(bioguide_id){

var url = Wrapper.generate_url(`votes?voter_ids.${bioguide_id}__exists=true&per_page=50`);
return Wrapper.make_request(url);
},

get_single_bill: function(bill_id){
var url = Wrapper.generate_url(`bills?bill_id=${bill_id}`);
return Wrapper.make_request(url);
},

//fix: if/else variable assign in one function doesn't work for
//whateve reason
get_bill_information: function(bill, ids=false){
var arr = [];
for(var b in bill){
var bill_id = bill[b].bill_id;
var url = Wrapper.generate_url(`bills?bill_id=${bill_id}`);
var resolved = Promise.resolve(Wrapper.make_request(url));
arr.push(Promise.resolve(resolved))
}
return Promise.all(arr);
},

get_bill_by_id: function(bill){
var arr = [];
for(var b in bill){
var bill_id = bill[b];
var url = Wrapper.generate_url(`bills?bill_id=${bill_id}`);
var resolved = Promise.resolve(Wrapper.make_request(url));
arr.push(Promise.resolve(resolved))
}
return Promise.all(arr);
},


locate_legislator: function(name){
var name = name.split("-");
var first_name = name[0];
var last_name = name[1];
var url = Wrapper.generate_url(`legislators?first_name=${first_name}&last_name=${last_name}`);
console.log(url);

return Wrapper.make_request(url);
},


generate_url: function(url){
return `${base_uri}/${url}`;
},

make_request: function(url){
return new Promise(function(resolve, reject){
request(url,
function(err, response, body){
if(err){
reject(err)
}
resolve( JSON.parse(body) );
});
})
}
}


module.exports = Wrapper;
4 changes: 4 additions & 0 deletions public/js/jquery-3.2.1.min.js

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions public/js/legislator-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
$(document).ready(function(){
App.init();
})

var App = {
init: function(){
App.remove_duplicates();
App.remove_empty_elems();
App.color_links();
},

remove_duplicates: function(){
//API returns many duplicate bills, this removes them.
var seen = {};
$(".my-votes div").each(function(){
var title_text = $("h3", $(this)).text();
if(seen[title_text]){
$(this).remove();
}
else{
seen[title_text] = true;
}
})
},

color_links: function(){
var bill = $(".bill-title");
bill.each(function(){
if($(this).attr('id') == 'pass'){
$(this).css('color', 'green');
}
else{
$(this).css('color', 'red')
}
})
},

remove_empty_elems: function(){
$(".my-votes div").each(function(){
var title_text = $("h3", $(this)).text();
var body_text = $("p", $(this));

if(title_text.length == 0 || body_text.length == 0){
$(this).remove();
}
});
}
}
42 changes: 42 additions & 0 deletions public/js/mainindex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
$(document).ready(function(){
App.init();
})

var App = {

init: function(){
App.set_event_listeners();
},

set_event_listeners: function(){
$("#locate input[type='submit']").click( App.validate_form );
},

validate_form: function(e){
e.preventDefault();
if($("#zipenter").val().length !=5 || $("#zipenter").val().match(/[0-9]{5}/) == null){
View.invalid_form(true);
}
else{
View.invalid_form(false);
var zip = $("#zipenter").val();
var zip_url = `/${zip}`;
$("#zip-link").attr("onclick", `window.location='${zip_url}'`);
}
}
}

var View = {

invalid_form: function(invalid){
if(invalid){
$("#zipenter").addClass("invalid");
$("#error").text("Please fix your errors");
}
else{
$("zipenter").removeClass("invalid");
$("#error").text("");
}
}
}

29 changes: 29 additions & 0 deletions public/style/scss/_bill.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#bill{
padding: 15px;
background-color:$light-gray;

h3{
text-align: center;
padding: 10px;
}

ul{
list-style: none;
text-align: center;
margin: 0 auto;
}

li{
margin-bottom: 12px;

}
}

#related-bills{
margin-top: 25px;
ul{
list-style: none;
}

#title{ margin: 0; }
}
37 changes: 37 additions & 0 deletions public/style/scss/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.invalid{
border-left: 20px solid red;
}

p{
text-align: center;
}

#locate{
margin-top: 30px;
background-color: $light-gray;
padding: 20px;

input[type='submit']{
display: block;
margin: 0 auto;
}
}

#rep-list{

.rep{
padding-top: 12px;
width: 50%;
display: block;
margin: 50px auto;
}

p{
text-align: left;
}

div{
background-color: $light-gray;
padding: 15px;
}
}
32 changes: 32 additions & 0 deletions public/style/scss/_legislator.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#legislator{

section{
margin-top: 27px;
margin-bottom: 27px;
}

#contact{
background-color: $light-gray;
padding: 20px;
list-style: none;
text-align: center;

li{
line-height: 2em;
font-size: 1.3em;
}
}

.my-votes{
padding: 20px 10px;
margin-top: 0px;

div{
background-color: $light-gray;
padding: 15px;
width: 70%;
margin: 20px auto;
}

}
}
30 changes: 30 additions & 0 deletions public/style/scss/base.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
$light-gray: #E5E5E5;
$gray: #b3b3b3;
$black: #242325;
$text: #333333;

body{
p{
color: $text;
}
}

nav{
padding: 15px;
background-color: $light-gray;
margin-bottom: 30px;

ul{
margin-left:10px;
}

a{
color: $black;
font-weight: bold;
font-size: 1.2em;
}
}

@import 'index';
@import 'legislator';
@import 'bill';
Loading