Skip to content

Commit

Permalink
better handeling of sort functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lain-d committed Dec 14, 2017
1 parent 6990066 commit ad13d8c
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions components/app-showtable/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ class {
this.state.reverse = false;
}
this.state.sortStyle = sort;
if(sort === "date"){
this.state.data = this.state.data.sort(function (a, b) { return new Date(a.D) - new Date(b.D) || a.A[0].N.localeCompare(b.A[0].N);});
}
else if(sort === "venue"){
this.state.data = this.state.data.sort(function(a,b) {return (a.V.N > b.V.N) ? 1 : ((b.V.N > a.V.N) ? -1 : 0);} );
}
else if(sort ==="artist")
{
this.state.data = this.state.data.sort(function(a,b) {return (a.A[0].N > b.A[0].N) ? 1 : ((b.A[0].N > a.A[0].N) ? -1 : 0);} );
}
else if (sort === "city")
{
this.state.data = this.state.data.sort(function(a,b) {return (a.V.C > b.V.C) ? 1 : ((b.V.C > a.V.C) ? -1 : 0);} );
}
if(this.state.reverse === true)
{
this.state.data = this.state.data.reverse();
}
}
openMap(index, array){
window.open("https://www.google.com/maps/search/?api=1&query="+encodeURIComponent(array[index].V.N+" "+array[index].V.Ad+" "+array[index].V.C+" "+array[index].V.SC));
Expand All @@ -27,29 +45,16 @@ class {
openVenu(index, array){
window.open(array[index].V.Url);
}
onInput(input) {
this.state.data = input.events;
}
}
<ul>
<li.thh.d on-click('reSort', 'date')>Date</li>
<li.thh on-click('reSort', 'artist')>Artists</li>
<li.thh on-click('reSort', 'venue')>Venue</li>
<li.thh.c on-click('reSort', 'city')>City</li>
</ul>
$ state.data = input.events;
<if(state.sortStyle === "date")>
$ state.data = state.data.sort(function (a, b) { return new Date(a.D) - new Date(b.D) || a.A[0].N.localeCompare(b.A[0].N);});
</if>
<else-if(state.sortStyle === "venue")>
$ state.data = state.data.sort(function(a,b) {return (a.V.N > b.V.N) ? 1 : ((b.V.N > a.V.N) ? -1 : 0);} );
</else-if>
<else-if(state.sortStyle === "artist")>
$ state.data = state.data.sort(function(a,b) {return (a.A[0].N > b.A[0].N) ? 1 : ((b.A[0].N > a.A[0].N) ? -1 : 0);} );
</else-if>
<else-if(state.sortStyle === "city")>
$ state.data = state.data.sort(function(a,b) {return (a.V.C > b.V.C) ? 1 : ((b.V.C > a.V.C) ? -1 : 0);} );
</else-if>
<if(state.reverse === true)>
$ state.data = state.data.reverse();
</if>
<ul for(event in state.data | status-var=loop)>
<li.d>${new Date(event.D).toDateString().split(new Date().getFullYear())[0]}</li>
<if(event.TU !== undefined)>
Expand Down

0 comments on commit ad13d8c

Please sign in to comment.