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: if time:
# all other keys that will not be changed by clicking another filter # 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}) 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 += "to <input id='dateselect_to' onchange='datechange()' type='date' value='" + "-".join(todate) + "'/>"
# html += "</div>" # html += "</div>"
from malojatime import today, thisweek, thismonth, thisyear from malojatime import today, thisweek, thismonth, thisyear, alltime
### 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))
# relative to current range # relative to current range
html += "<div>" 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: if timekeys.get("timerange").next(-1) is not None:
prevrange = timekeys.get("timerange").next(-1) prevrange = timekeys.get("timerange").next(-1)
@ -639,101 +620,78 @@ def module_filterselection(keys,time=True,delimit=False):
# predefined ranges # predefined ranges
delimit_ranges = {
"Today":today(),
"This Week":thisweek(),
"This Month":thismonth(),
"This Year":thisyear(),
"All Time":alltime()
}
html += "<div>" optionlist = []
if timekeys.get("timerange") == today(): for option in delimit_ranges:
html += "<span class='stat_selector' style='opacity:0.5;'>Today</span>" 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: else:
html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"today"}) + "'><span class='stat_selector'>Today</span></a>" optionlist.append("<a href='" + link + "'><span class='stat_selector'>" + option + "</span></a>")
html += " | "
if timekeys.get("timerange") == thisweek(): html += "<div>" + " | ".join(optionlist) + "</div>"
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 += " | "
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: if delimit:
#keystr = "?" + compose_querystring(keys,exclude=["step","stepn"])
unchangedkeys = internal_to_uri({**filterkeys,**timekeys,**extrakeys}) unchangedkeys = internal_to_uri({**filterkeys,**timekeys,**extrakeys})
# STEP
# only for this element (delimit selector consists of more than one) # 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"]}) unchangedkeys_sub = internal_to_uri({k:delimitkeys[k] for k in delimitkeys if k not in ["step","stepn"]})
html += "<div>" delimit_steps = {
if delimitkeys.get("step") == "day" and delimitkeys.get("stepn") == 1: "Daily":{"step":"day","stepn":1},
html += "<span class='stat_selector' style='opacity:0.5;'>Daily</span>" "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: else:
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"step":"day"}) + "'><span class='stat_selector'>Daily</span></a>" optionlist.append("<a href='" + link + "'><span class='stat_selector'>" + option + "</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>"
html += "<div>" + " | ".join(optionlist) + "</div>"
# TRAIL
unchangedkeys_sub = internal_to_uri({k:delimitkeys[k] for k in delimitkeys if k != "trail"}) unchangedkeys_sub = internal_to_uri({k:delimitkeys[k] for k in delimitkeys if k != "trail"})
html += "<div>" delimit_trails = {
if delimitkeys.get("trail") == 1: "Standard":1,
html += "<span class='stat_selector' style='opacity:0.5;'>Standard</span>" "Trailing":2,
else: "Long Trailing":3,
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"1"}) + "'><span class='stat_selector'>Standard</span></a>" "Inert":10,
html += " | " "Cumulative":math.inf
}
if delimitkeys.get("trail") == 2: optionlist = []
html += "<span class='stat_selector' style='opacity:0.5;'>Trailing</span>" for option in delimit_trails:
else: value = delimit_trails[option]
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"2"}) + "'><span class='stat_selector'>Trailing</span></a>" link = "?" + compose_querystring(unchangedkeys,unchangedkeys_sub,internal_to_uri({"trail":value}))
html += " | "
if delimitkeys.get("trail") == 3: if delimitkeys.get("trail") == value:
html += "<span class='stat_selector' style='opacity:0.5;'>Long Trailing</span>" optionlist.append("<span class='stat_selector' style='opacity:0.5;'>" + option + "</span>")
else: else:
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"3"}) + "'><span class='stat_selector'>Long Trailing</span></a>" optionlist.append("<a href='" + link + "'><span class='stat_selector'>" + option + "</span></a>")
html += " | "
if delimitkeys.get("trail") == math.inf: html += "<div>" + " | ".join(optionlist) + "</div>"
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>"
return html return html

View File

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

View File

@ -11,3 +11,4 @@ countas RenoakRhythm Approaching Nirvana
countas Shirley Manson Garbage countas Shirley Manson Garbage
countas Lewis Brindley The Yogscast countas Lewis Brindley The Yogscast
countas Sips 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() { actuallyupdate() {
this.messageID++; this.messageID++;
//console.log("Update! Our page is " + this.page + ", our tab id " + this.tabId) //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":"sites/" + pages[this.page]["script"]});
chrome.tabs.executeScript(this.tabId,{"file":"sitescript.js"}); 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; this.alreadyQueued = false;
} }