1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Refactored selectors for easier extensibility

This commit is contained in:
Krateng 2019-06-26 17:11:46 +02:00
parent 3d78d124ef
commit 92edca3521
4 changed files with 63 additions and 97 deletions

View File

@ -579,7 +579,6 @@ def module_filterselection(keys,time=True,delimit=False):
if time:
# all other keys that will not be changed by clicking another filter
#keystr = "?" + compose_querystring(keys,exclude=["since","to","in"])
unchangedkeys = internal_to_uri({**filterkeys,**delimitkeys,**extrakeys})
@ -601,28 +600,10 @@ def module_filterselection(keys,time=True,delimit=False):
# html += "to <input id='dateselect_to' onchange='datechange()' type='date' value='" + "-".join(todate) + "'/>"
# html += "</div>"
from malojatime import today, thisweek, thismonth, thisyear
### temp!!! this will not allow weekly rank changes
# weekday = ((now.isoweekday()) % 7)
# weekbegin = now - datetime.timedelta(days=weekday)
# weekend = weekbegin + datetime.timedelta(days=6)
# weekbegin = [weekbegin.year,weekbegin.month,weekbegin.day]
# weekend = [weekend.year,weekend.month,weekend.day]
# weekbeginstr = "/".join((str(num) for num in weekbegin))
# weekendstr = "/".join((str(num) for num in weekend))
from malojatime import today, thisweek, thismonth, thisyear, alltime
# relative to current range
html += "<div>"
# if timekeys.get("timerange").next(-1) is not None:
# html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"timerange":timekeys.get("timerange").next(-1)})) + "'><span class='stat_selector'>«</span></a>"
# if timekeys.get("timerange").next(-1) is not None or timekeys.get("timerange").next(1) is not None:
# html += " " + timekeys.get("timerange").desc() + " "
# if timekeys.get("timerange").next(1) is not None:
# html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"timerange":timekeys.get("timerange").next(1)})) + "'><span class='stat_selector'>»</span></a>"
if timekeys.get("timerange").next(-1) is not None:
prevrange = timekeys.get("timerange").next(-1)
@ -639,101 +620,78 @@ def module_filterselection(keys,time=True,delimit=False):
# predefined ranges
delimit_ranges = {
"Today":today(),
"This Week":thisweek(),
"This Month":thismonth(),
"This Year":thisyear(),
"All Time":alltime()
}
html += "<div>"
if timekeys.get("timerange") == today():
html += "<span class='stat_selector' style='opacity:0.5;'>Today</span>"
optionlist = []
for option in delimit_ranges:
value = delimit_ranges[option]
link = "?" + compose_querystring(unchangedkeys,internal_to_uri({"timerange":value}))
if timekeys.get("timerange") == value:
optionlist.append("<span class='stat_selector' style='opacity:0.5;'>" + option + "</span>")
else:
html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"today"}) + "'><span class='stat_selector'>Today</span></a>"
html += " | "
optionlist.append("<a href='" + link + "'><span class='stat_selector'>" + option + "</span></a>")
if timekeys.get("timerange") == thisweek():
html += "<span class='stat_selector' style='opacity:0.5;'>This Week</span>"
else:
html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"week"}) + "'><span class='stat_selector'>This Week</span></a>"
html += " | "
html += "<div>" + " | ".join(optionlist) + "</div>"
if timekeys.get("timerange") == thismonth():
html += "<span class='stat_selector' style='opacity:0.5;'>This Month</span>"
else:
html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"month"}) + "'><span class='stat_selector'>This Month</span></a>"
html += " | "
if timekeys.get("timerange") == thisyear():
html += "<span class='stat_selector' style='opacity:0.5;'>This Year</span>"
else:
html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"year"}) + "'><span class='stat_selector'>This Year</span></a>"
html += " | "
if timekeys.get("timerange") is None or timekeys.get("timerange").unlimited():
html += "<span class='stat_selector' style='opacity:0.5;'>All Time</span>"
else:
html += "<a href='?" + compose_querystring(unchangedkeys) + "'><span class='stat_selector'>All Time</span></a>"
html += "</div>"
if delimit:
#keystr = "?" + compose_querystring(keys,exclude=["step","stepn"])
unchangedkeys = internal_to_uri({**filterkeys,**timekeys,**extrakeys})
# STEP
# only for this element (delimit selector consists of more than one)
unchangedkeys_sub = internal_to_uri({k:delimitkeys[k] for k in delimitkeys if k not in ["step","stepn"]})
html += "<div>"
if delimitkeys.get("step") == "day" and delimitkeys.get("stepn") == 1:
html += "<span class='stat_selector' style='opacity:0.5;'>Daily</span>"
delimit_steps = {
"Daily":{"step":"day","stepn":1},
"Weekly":{"step":"week","stepn":1},
"Fortnightly":{"step":"week","stepn":2},
"Monthly":{"step":"month","stepn":1},
"Quarterly":{"step":"month","stepn":3},
"Yearly":{"step":"year","stepn":1}
}
optionlist = []
for option in delimit_steps:
values = delimit_steps[option]
link = "?" + compose_querystring(unchangedkeys,unchangedkeys_sub,internal_to_uri(values))
if delimitkeys.get("step") == values["step"] and delimitkeys.get("stepn") == values["stepn"]:
optionlist.append("<span class='stat_selector' style='opacity:0.5;'>" + option + "</span>")
else:
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"step":"day"}) + "'><span class='stat_selector'>Daily</span></a>"
html += " | "
if delimitkeys.get("step") == "week" and delimitkeys.get("stepn") == 1:
html += "<span class='stat_selector' style='opacity:0.5;'>Weekly</span>"
else:
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"step":"week"}) + "'><span class='stat_selector'>Weekly</span></a>"
html += " | "
if delimitkeys.get("step") == "month" and delimitkeys.get("stepn") == 1:
html += "<span class='stat_selector' style='opacity:0.5;'>Monthly</span>"
else:
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"step":"month"}) + "'><span class='stat_selector'>Monthly</span></a>"
html += " | "
if delimitkeys.get("step") == "year" and delimitkeys.get("stepn") == 1:
html += "<span class='stat_selector' style='opacity:0.5;'>Yearly</span>"
else:
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"step":"year"}) + "'><span class='stat_selector'>Yearly</span></a>"
html += "</div>"
optionlist.append("<a href='" + link + "'><span class='stat_selector'>" + option + "</span></a>")
html += "<div>" + " | ".join(optionlist) + "</div>"
# TRAIL
unchangedkeys_sub = internal_to_uri({k:delimitkeys[k] for k in delimitkeys if k != "trail"})
html += "<div>"
if delimitkeys.get("trail") == 1:
html += "<span class='stat_selector' style='opacity:0.5;'>Standard</span>"
else:
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"1"}) + "'><span class='stat_selector'>Standard</span></a>"
html += " | "
delimit_trails = {
"Standard":1,
"Trailing":2,
"Long Trailing":3,
"Inert":10,
"Cumulative":math.inf
}
if delimitkeys.get("trail") == 2:
html += "<span class='stat_selector' style='opacity:0.5;'>Trailing</span>"
else:
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"2"}) + "'><span class='stat_selector'>Trailing</span></a>"
html += " | "
optionlist = []
for option in delimit_trails:
value = delimit_trails[option]
link = "?" + compose_querystring(unchangedkeys,unchangedkeys_sub,internal_to_uri({"trail":value}))
if delimitkeys.get("trail") == 3:
html += "<span class='stat_selector' style='opacity:0.5;'>Long Trailing</span>"
if delimitkeys.get("trail") == value:
optionlist.append("<span class='stat_selector' style='opacity:0.5;'>" + option + "</span>")
else:
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"3"}) + "'><span class='stat_selector'>Long Trailing</span></a>"
html += " | "
optionlist.append("<a href='" + link + "'><span class='stat_selector'>" + option + "</span></a>")
if delimitkeys.get("trail") == math.inf:
html += "<span class='stat_selector' style='opacity:0.5;'>Cumulative</span>"
else:
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"cumulative":"yes"}) + "'><span class='stat_selector'>Cumulative</span></a>"
html += "</div>"
html += "<div>" + " | ".join(optionlist) + "</div>"
return html

View File

@ -620,6 +620,8 @@ def thismonth():
def thisyear():
tod = datetime.datetime.utcnow()
return MTime(tod.year)
def alltime():
return MRange(None,None)
#def _get_start_of(timestamp,unit):
# date = datetime.datetime.utcfromtimestamp(timestamp)

View File

@ -11,3 +11,4 @@ countas RenoakRhythm Approaching Nirvana
countas Shirley Manson Garbage
countas Lewis Brindley The Yogscast
countas Sips The Yogscast
countas Sjin The Yogscast

Can't render this file because it has a wrong number of fields in line 5.

View File

@ -178,8 +178,13 @@ class Controller {
actuallyupdate() {
this.messageID++;
//console.log("Update! Our page is " + this.page + ", our tab id " + this.tabId)
try {
chrome.tabs.executeScript(this.tabId,{"file":"sites/" + pages[this.page]["script"]});
chrome.tabs.executeScript(this.tabId,{"file":"sitescript.js"});
}
catch (e) {
console.log("Could not run site script. Tab probably closed or something idk.")
}
this.alreadyQueued = false;
}