-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (64 loc) · 2.31 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const baseURL = "https://api.github.com/repos/atom/atom";
const Responses = {
template: '#responses-template',
data: () => ({
issues: [],
labels: [],
searchKey: "",
query: "/issues?",
selectedState: "",
checkedLabels: [],
selectedSort: "",
direction: ""
// since: YYYY-MM-DDTHH:MM:SSZ, lazy to implement this for now :)
}),
mounted() {
this.getResponses('issues', '/issues?');
this.getResponses('labels', '/labels?');
},
methods: {
getResponses: function(type,queryToFetch) {
queryToFetch += "per_page=100&";
axios.get(baseURL + queryToFetch).then( res => {
if (res.data == null || res.data.length == 0) {
alert("Such filtering combination does not return any valid issue...");
}
if (type=="issues") {
this.issues = res.data;
} else if (type=="labels") {
this.labels = res.data;
}
}).catch( err => {
console.log(err);
})
},
generateQuery: function() {
if (this.selectedState) {
this.query += "state=" + this.selectedState + '&';
}
if (this.checkedLabels.length != 0) {
this.query += "labels=";
var index = 0;
for (index = 0; index < this.checkedLabels.length-1; ++index) {
this.query += this.checkedLabels[index] +',';
}
this.query += this.checkedLabels[index] + '&';
}
if (this.selectedSort) {
this.query += "sort=" + this.selectedSort + '&';
}
if (this.direction) {
this.query += "direction=asc&";
}
},
initiateQuery: function() {
this.generateQuery();
this.issues = this.getResponses('issues',this.query);
this.query = "/issues?";
}
}
};
Vue.component('responses', Responses);
new Vue({
el: '#app'
});