-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: add support for regions (add, edit, filter)
- Loading branch information
Showing
16 changed files
with
369 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from . import static # noqa | ||
from . import login # noqa | ||
from . import package_list, package_info, version_info # noqa | ||
from . import package_info # noqa | ||
from . import package_list # noqa | ||
from . import regions # noqa | ||
from . import static # noqa | ||
from . import version_info # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import flask | ||
|
||
from ..app import app | ||
from ..helpers import get_regions | ||
|
||
|
||
@app.route("/regions") | ||
def region_search(): | ||
query = flask.request.args.get("search") | ||
|
||
if not query: | ||
return flask.jsonify({"result": []}) | ||
|
||
regions = get_regions() | ||
|
||
query = query.strip() | ||
if len(query) < 2: | ||
return flask.jsonify({"result": []}) | ||
|
||
matches = [] | ||
for region in regions.values(): | ||
if query.lower() in region["name"].lower(): | ||
matches.append(region) | ||
if query.lower() in region["code"].lower(): | ||
matches.append(region) | ||
|
||
return flask.jsonify({"result": matches}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use strict"; | ||
|
||
let xhr = new XMLHttpRequest(); | ||
|
||
function regionClick(event) { | ||
let region = event.target.dataset.region; | ||
let regions = document.getElementById("regions"); | ||
regions.value += region + "\n"; | ||
} | ||
|
||
function searchResult(regions) { | ||
let list = document.getElementById("region-list"); | ||
list.innerHTML = ""; | ||
for (let region of regions["result"]) { | ||
let li = document.createElement("li"); | ||
|
||
li.dataset.region = region["code"]; | ||
li.textContent = region["code"] + ": " + region["name"]; | ||
|
||
li.addEventListener("click", regionClick); | ||
list.appendChild(li); | ||
} | ||
} | ||
|
||
function searchRequest() { | ||
let search = document.getElementById("region-search"); | ||
let value = search.value; | ||
|
||
xhr.abort(); | ||
|
||
xhr.open("GET", "/regions?search=" + encodeURIComponent(value)); | ||
xhr.send(); | ||
|
||
xhr.onload = function() { | ||
if (xhr.status != 200) { | ||
alert("Error: " + xhr.status + " " + xhr.statusText); | ||
return; | ||
} | ||
|
||
let regions = JSON.parse(xhr.responseText); | ||
searchResult(regions); | ||
}; | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", function(event) { | ||
let search = document.getElementById("region-search"); | ||
let search_timer; | ||
|
||
/* Search for regions when the user stops typing for 300ms. */ | ||
search.addEventListener("input", function(event) { | ||
if (search_timer) { | ||
clearTimeout(search_timer); | ||
} | ||
search_timer = setTimeout(searchRequest, 300); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.