A few tweaks on the level up page

This commit is contained in:
Brian Buller 2015-11-09 15:20:41 -06:00
parent 0b202e63fa
commit a3886577aa
5 changed files with 82 additions and 23 deletions

39
assets/js/B_cookies.js Normal file
View File

@ -0,0 +1,39 @@
var docCookies = {
getItem: function (sKey) {
if (!sKey) { return null; }
return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
},
setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return false; }
var sExpires = "";
if (vEnd) {
switch (vEnd.constructor) {
case Number:
sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
break;
case String:
sExpires = "; expires=" + vEnd;
break;
case Date:
sExpires = "; expires=" + vEnd.toUTCString();
break;
}
}
document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
return true;
},
removeItem: function (sKey, sPath, sDomain) {
if (!this.hasItem(sKey)) { return false; }
document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "");
return true;
},
hasItem: function (sKey) {
if (!sKey) { return false; }
return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
},
keys: function () {
var aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/);
for (var nLen = aKeys.length, nIdx = 0; nIdx < nLen; nIdx++) { aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]); }
return aKeys;
}
};

View File

@ -1,31 +1,55 @@
var sortMode = "ALPHA";
document.addEventListener("DOMContentLoaded", function(event) {
sortByAlpha();
buildList();
sortMode = docCookies.getItem("levelup-sort")
updateScreen();
B('#btnAlphaSort').on('click', function() {
if(sortMode == "ALPHA") {
sortMode = "ALPHA-REV";
B('#btnAlphaSort>i').removeClass('fa-sort-asc').addClass('fa-sort-desc');
} else {
sortMode = "ALPHA";
B('#btnAlphaSort>i').removeClass('fa-sort-desc').addClass('fa-sort-asc');
}
sortUsers();
buildList();
docCookies.setItem("levelup-sort", sortMode);
updateScreen();
});
B('#btnXpSort').on('click', function() {
if(sortMode == "XP") {
sortMode = "XP-REV";
B('#btnXpSort>i').removeClass('fa-sort-desc').addClass('fa-sort-asc');
} else {
sortMode = "XP";
B('#btnXpSort>i').removeClass('fa-sort-asc').addClass('fa-sort-desc');
}
sortUsers();
buildList();
docCookies.setItem("levelup-sort", sortMode);
updateScreen();
});
});
})
var sortMode = "ALPHA";
function updateScreen() {
sortUsers();
styleButtons();
buildList();
}
function styleButtons() {
var alphaBtn = B('#btnAlphaSort>i'),
xpBtn = B('#btnXpSort>i');
alphaBtn.removeClass('fa-sort-asc').removeClass('fa-sort-desc');
xpBtn.removeClass('fa-sort-asc').removeClass('fa-sort-desc');
switch(sortMode) {
case "ALPHA":
alphaBtn.addClass('fa-sort-desc');
break;
case "ALPHA-REV":
alphaBtn.addClass('fa-sort-asc');
break;
case "XP":
xpBtn.addClass('fa-sort-desc');
break;
default:
sortMode = "XP-REV";
xpBtn.addClass('fa-sort-asc');
break;
}
}
function clearList() {
B(".levelup-user").remove();

View File

@ -1,10 +1,6 @@
package main
import (
"net/http"
"github.com/gorilla/mux"
)
import "net/http"
type levelUpAchieveStatProcessor struct {
Achievements []levelUpAchievement
@ -38,15 +34,14 @@ func (p *levelUpAchieveStatProcessor) ProcessMessage(m *Message) {
}
var u *User
var err error
vars := mux.Vars(req)
if u, err = getUserInfo(m.User); err != nil {
return
}
p := UserLevelUpStats{Name: u.Name}
p.Xp, _ = getUserStat(u.ID, "levelup-xp")
p.ChannelStats = getAllLevelUpChannelXp(u.ID)
p.OtherStats = getAllNonLevelUpStats(u.ID)
userStat := UserLevelUpStats{Name: u.Name}
userStat.Xp, _ = getUserStat(u.ID, "levelup-xp")
userStat.ChannelStats = getAllLevelUpChannelXp(u.ID)
userStat.OtherStats = getAllNonLevelUpStats(u.ID)
}
func (p *levelUpAchieveStatProcessor) ProcessAdminMessage(m *Message) {}

View File

@ -65,7 +65,7 @@ func statBotMain(slack *Slack) {
registerStatProcessor(new(levelUpStatProcessor))
registerStatProcessor(new(generalStatProcessor))
levelUpAchievements := new(levelUpAchieveStatProcessor)
//levelUpAchievements := new(levelUpAchieveStatProcessor)
// Register Achievements
registerMessageProcessor(new(generalProcessor))

View File

@ -92,6 +92,7 @@ func initRequest(w http.ResponseWriter, req *http.Request) {
site.Scripts = make([]string, 0, 0)
site.Scripts = append(site.Scripts, "/assets/js/highcharts.js")
site.Scripts = append(site.Scripts, "/assets/js/B.js")
site.Scripts = append(site.Scripts, "/assets/js/B_cookies.js")
site.InlineScript = ""