A few tweaks on the level up page
This commit is contained in:
parent
0b202e63fa
commit
a3886577aa
39
assets/js/B_cookies.js
Normal file
39
assets/js/B_cookies.js
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
@ -1,31 +1,55 @@
|
|||||||
|
var sortMode = "ALPHA";
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function(event) {
|
document.addEventListener("DOMContentLoaded", function(event) {
|
||||||
sortByAlpha();
|
sortMode = docCookies.getItem("levelup-sort")
|
||||||
buildList();
|
updateScreen();
|
||||||
B('#btnAlphaSort').on('click', function() {
|
B('#btnAlphaSort').on('click', function() {
|
||||||
if(sortMode == "ALPHA") {
|
if(sortMode == "ALPHA") {
|
||||||
sortMode = "ALPHA-REV";
|
sortMode = "ALPHA-REV";
|
||||||
B('#btnAlphaSort>i').removeClass('fa-sort-asc').addClass('fa-sort-desc');
|
|
||||||
} else {
|
} else {
|
||||||
sortMode = "ALPHA";
|
sortMode = "ALPHA";
|
||||||
B('#btnAlphaSort>i').removeClass('fa-sort-desc').addClass('fa-sort-asc');
|
|
||||||
}
|
}
|
||||||
sortUsers();
|
docCookies.setItem("levelup-sort", sortMode);
|
||||||
buildList();
|
updateScreen();
|
||||||
});
|
});
|
||||||
B('#btnXpSort').on('click', function() {
|
B('#btnXpSort').on('click', function() {
|
||||||
if(sortMode == "XP") {
|
if(sortMode == "XP") {
|
||||||
sortMode = "XP-REV";
|
sortMode = "XP-REV";
|
||||||
B('#btnXpSort>i').removeClass('fa-sort-desc').addClass('fa-sort-asc');
|
|
||||||
} else {
|
} else {
|
||||||
sortMode = "XP";
|
sortMode = "XP";
|
||||||
B('#btnXpSort>i').removeClass('fa-sort-asc').addClass('fa-sort-desc');
|
|
||||||
}
|
}
|
||||||
sortUsers();
|
docCookies.setItem("levelup-sort", sortMode);
|
||||||
buildList();
|
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() {
|
function clearList() {
|
||||||
B(".levelup-user").remove();
|
B(".levelup-user").remove();
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "net/http"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
)
|
|
||||||
|
|
||||||
type levelUpAchieveStatProcessor struct {
|
type levelUpAchieveStatProcessor struct {
|
||||||
Achievements []levelUpAchievement
|
Achievements []levelUpAchievement
|
||||||
@ -38,15 +34,14 @@ func (p *levelUpAchieveStatProcessor) ProcessMessage(m *Message) {
|
|||||||
}
|
}
|
||||||
var u *User
|
var u *User
|
||||||
var err error
|
var err error
|
||||||
vars := mux.Vars(req)
|
|
||||||
if u, err = getUserInfo(m.User); err != nil {
|
if u, err = getUserInfo(m.User); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p := UserLevelUpStats{Name: u.Name}
|
userStat := UserLevelUpStats{Name: u.Name}
|
||||||
p.Xp, _ = getUserStat(u.ID, "levelup-xp")
|
userStat.Xp, _ = getUserStat(u.ID, "levelup-xp")
|
||||||
p.ChannelStats = getAllLevelUpChannelXp(u.ID)
|
userStat.ChannelStats = getAllLevelUpChannelXp(u.ID)
|
||||||
p.OtherStats = getAllNonLevelUpStats(u.ID)
|
userStat.OtherStats = getAllNonLevelUpStats(u.ID)
|
||||||
|
|
||||||
}
|
}
|
||||||
func (p *levelUpAchieveStatProcessor) ProcessAdminMessage(m *Message) {}
|
func (p *levelUpAchieveStatProcessor) ProcessAdminMessage(m *Message) {}
|
||||||
|
@ -65,7 +65,7 @@ func statBotMain(slack *Slack) {
|
|||||||
registerStatProcessor(new(levelUpStatProcessor))
|
registerStatProcessor(new(levelUpStatProcessor))
|
||||||
registerStatProcessor(new(generalStatProcessor))
|
registerStatProcessor(new(generalStatProcessor))
|
||||||
|
|
||||||
levelUpAchievements := new(levelUpAchieveStatProcessor)
|
//levelUpAchievements := new(levelUpAchieveStatProcessor)
|
||||||
// Register Achievements
|
// Register Achievements
|
||||||
|
|
||||||
registerMessageProcessor(new(generalProcessor))
|
registerMessageProcessor(new(generalProcessor))
|
||||||
|
@ -92,6 +92,7 @@ func initRequest(w http.ResponseWriter, req *http.Request) {
|
|||||||
site.Scripts = make([]string, 0, 0)
|
site.Scripts = make([]string, 0, 0)
|
||||||
site.Scripts = append(site.Scripts, "/assets/js/highcharts.js")
|
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.js")
|
||||||
|
site.Scripts = append(site.Scripts, "/assets/js/B_cookies.js")
|
||||||
|
|
||||||
site.InlineScript = ""
|
site.InlineScript = ""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user