-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/cursor #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Feature/cursor #307
Changes from 13 commits
8bbca9c
056adc5
914a808
05660da
8312440
0db4d2b
53de34a
6dd0219
fc72d95
25ca2d3
4d2195e
2114a33
4ce2c74
4f06799
f569f3c
e289578
44da8b7
7b616ec
8b0cd21
dbae35d
03e21d1
458fb3f
df699f6
c847b41
479f580
b01c459
969bcb1
d0336bf
01456c8
5b54d04
0fdce31
7dcfc02
021881b
8e057c5
2ec4a77
d050246
a1a9f66
6d2bcf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
http://www.rw-designer.com/cursor-set/material-amber | ||
http://www.rw-designer.com/cursor-set/windows-xp-style | ||
http://www.rw-designer.com/cursor-set/material-3d | ||
http://www.rw-designer.com/cursor-set/cloudflix | ||
subscorp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
http://www.rw-designer.com/cursor-set/primogem | ||
subscorp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
http://www.rw-designer.com/cursor-set/paper-plane | ||
http://www.rw-designer.com/cursor-set/yodalighsaber | ||
http://www.rw-designer.com/cursor-set/valentine-heart | ||
http://www.rw-designer.com/cursor-set/icy-ice | ||
http://www.rw-designer.com/cursor-set/wii-hand-1 | ||
http://www.rw-designer.com/cursor-set/minecraft-sets |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import json | ||
from pathlib import Path | ||
from typing import List, Optional, Tuple | ||
|
||
from app.database.models import User, UserSettings | ||
from app.dependencies import CURSORS_PATH, get_db, templates | ||
from fastapi import APIRouter, Depends, Form, Request | ||
from sqlalchemy.orm.session import Session | ||
from starlette.responses import RedirectResponse | ||
from starlette.status import HTTP_302_FOUND | ||
from app.internal.security.dependancies import current_user | ||
|
||
router = APIRouter( | ||
prefix="/cursor", | ||
tags=["cursor"], | ||
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we need a route for every setting option. This should probably be routers.setting.py and the calls should be:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean that there shouldn't be a [setting_type].py file for each setting type? |
||
responses={404: {"description": "Not found"}}, | ||
) | ||
|
||
|
||
@router.get("/settings") | ||
def cursor_settings( | ||
request: Request, | ||
user: User = Depends(current_user), | ||
session: Session = Depends(get_db), | ||
) -> templates.TemplateResponse: | ||
"""A route to the cursor settings. | ||
|
||
Args: | ||
request (Request): the http request. | ||
session (Session): the database. | ||
|
||
Returns: | ||
templates.TemplateResponse: renders the cursor_settings.html page | ||
with the relevant information. | ||
""" | ||
cursors = ["default"] + [ | ||
path.stem for path in Path(CURSORS_PATH).glob("**/*.cur") | ||
] | ||
|
||
return templates.TemplateResponse( | ||
"cursor_settings.html", | ||
{ | ||
"request": request, | ||
"cursors": cursors, | ||
}, | ||
) | ||
|
||
|
||
@router.post("/settings") | ||
async def get_cursor_choices( | ||
session: Session = Depends(get_db), | ||
user: User = Depends(current_user), | ||
primary_cursor: str = Form(...), | ||
secondary_cursor: str = Form(...), | ||
) -> RedirectResponse: | ||
"""The form in which the user choses primary and secondary | ||
cursors. | ||
|
||
Args: | ||
session (Session, optional): the database. | ||
user (User, optional): [description]. temp user. | ||
primary_cursor (str, optional): name of the primary cursor. | ||
the primary cursor. | ||
secondary_cursor (str, optional): name of the secondary cursor. | ||
|
||
Returns: | ||
RedirectResponse: redirects to the homepage. | ||
""" | ||
cursor_choices = { | ||
"primary_cursor": primary_cursor, | ||
"secondary_cursor": secondary_cursor, | ||
} | ||
save_cursor_settings(session, user, cursor_choices) | ||
|
||
return RedirectResponse("/", status_code=HTTP_302_FOUND) | ||
|
||
|
||
@router.get("/load_cursor") | ||
subscorp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async def load_cursor( | ||
session: Session = Depends(get_db), | ||
user: User = Depends(current_user), | ||
) -> RedirectResponse: | ||
"""loads cursors according to cursor settings. | ||
|
||
Args: | ||
session (Session): the database. | ||
user (User): the user. | ||
|
||
Returns: | ||
RedirectResponse: redirect the user to the homepage. | ||
""" | ||
primary_cursor, secondary_cursor = get_cursor_settings( | ||
session, | ||
user.user_id, | ||
) | ||
|
||
return json.dumps( | ||
{ | ||
"primary_cursor": primary_cursor, | ||
"secondary_cursor": secondary_cursor, | ||
}, | ||
) | ||
|
||
|
||
def get_cursor_settings( | ||
session: Session, | ||
user_id: int, | ||
) -> Tuple[Optional[List[str]], Optional[int], Optional[str], Optional[int]]: | ||
"""Retrieves cursor settings from the database. | ||
|
||
Args: | ||
session (Session): the database. | ||
user_id (int, optional): the users' id. | ||
|
||
Returns: | ||
Tuple[str, Optional[List[str]], Optional[int], | ||
str, Optional[str], Optional[int]]: the cursor settings. | ||
""" | ||
primary_cursor, secondary_cursor = None, None | ||
cursor_settings = ( | ||
session.query(UserSettings).filter_by(user_id=user_id).first() | ||
) | ||
if cursor_settings: | ||
primary_cursor = cursor_settings.primary_cursor | ||
secondary_cursor = cursor_settings.secondary_cursor | ||
|
||
return primary_cursor, secondary_cursor | ||
|
||
|
||
def save_cursor_settings( | ||
session: Session, | ||
user: User, | ||
cursor_choices: List[str], | ||
): | ||
"""Saves cursor choices in the db. | ||
|
||
Args: | ||
session (Session): the database. | ||
user (User): current user. | ||
cursor_choices (List[str]): primary and secondary cursors. | ||
""" | ||
cursor_settings = ( | ||
session.query(UserSettings).filter_by(user_id=user.user_id).first() | ||
) | ||
if cursor_settings: | ||
session.query(UserSettings).filter_by( | ||
user_id=cursor_settings.user_id, | ||
).update(cursor_choices) | ||
session.commit() | ||
else: | ||
cursor_settings = UserSettings(user_id=user.user_id, **cursor_choices) | ||
session.add(cursor_settings) | ||
session.commit() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
CURSORS_PATH = "/media/cursors/"; | ||
subscorp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
window.addEventListener("load", get_cursor_choices); | ||
|
||
/** | ||
* @summary This function gets cursor choices from the db. | ||
*/ | ||
function get_cursor_choices() { | ||
let request = new XMLHttpRequest(); | ||
request.open("GET", "/cursor/load_cursor", true); | ||
request.onload = change_cursor; | ||
request.send(); | ||
} | ||
|
||
/** | ||
* @summary This function changes the primary cursor and the secondary | ||
* cursor according to users' choices. | ||
*/ | ||
function change_cursor() { | ||
let cursor_settings = JSON.parse(JSON.parse(this.response)); | ||
let primary_cursor = cursor_settings["primary_cursor"]; | ||
let primary_cursor_val = `url(${CURSORS_PATH}${primary_cursor}), auto`; | ||
let secondary_cursor = cursor_settings["secondary_cursor"]; | ||
let secondary_cursor_val = `url(${CURSORS_PATH}${secondary_cursor}), auto`; | ||
subscorp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (primary_cursor != "default.cur") { | ||
primary_val = primary_cursor_val; | ||
subscorp marked this conversation as resolved.
Show resolved
Hide resolved
subscorp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
primary_val = ""; | ||
} | ||
document.body.style.cursor = primary_val; | ||
let links = document.querySelectorAll("a, button, input, select, label"); | ||
if (secondary_cursor != "default.cur") { | ||
secondary_val = secondary_cursor_val; | ||
} else { | ||
secondary_val = ""; | ||
} | ||
subscorp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
links.forEach((element) => { | ||
element.style.cursor = secondary_val; | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,9 @@ | |
<li class="nav-item"> | ||
<a class="nav-link" href="{{ url_for('agenda') }}">Agenda</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{{ url_for('cursor_settings') }}">Cursor Settings</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{{ url_for('view_invitations') }}">Invitations</a> | ||
</li> | ||
|
@@ -81,6 +84,8 @@ | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js" integrity="sha512-d9xgZrVZpmmQlfonhQUvTR7lMPtO7NkZMkA0ABN3PHCbKA5nqylQ/yWlFAyY6hYgdF1Qh6nYiuADWwKB4C2WSw==" crossorigin="anonymous"></script> | ||
<script type="text/javascript" src="{{ url_for('static', path='/popover.js') }}"></script> | ||
<script defer type="text/javascript" src="{{ url_for('static', path='/cursor.js') }}"></script> | ||
|
||
<!-- This bootstrap version is needed here because of the toggler bug in the beta version--> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha2/js/bootstrap.bundle.min.js" integrity="sha384-BOsAfwzjNJHrJ8cZidOg56tcQWfp6y72vEJ8xQ9w6Quywb24iOsW913URv1IS4GD" crossorigin="anonymous"></script> | ||
<script src="{{ url_for('static', path='/horoscope.js') }}"></script> | ||
|
@@ -89,4 +94,4 @@ | |
|
||
</body> | ||
|
||
</html> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<div class="container mt-4"> | ||
<h1>Cursor Settings</h1> | ||
<form action="{{ url_for('get_cursor_choices') }}" method="post" id="cursor-form"> | ||
<label for="primary-cusor">Select primary cursor :</label> <br> | ||
<select name="primary_cursor" id="primary-cursor" class="form-control"> | ||
{% for cursor in cursors %} | ||
<option value="{{ cursor }}.cur">{{cursor}}</option> | ||
{% endfor %} | ||
</select> | ||
<br> | ||
<label for="secondary-cusor">Select secondary cursor :</label> <br> | ||
<select name="secondary_cursor" id="secondary-cursor" class="form-control"> | ||
{% for cursor in cursors %} | ||
<option value="{{ cursor }}.cur">{{cursor}}</option> | ||
{% endfor %} | ||
</select> | ||
<br> | ||
<button id="activate-cursor" type="submit" form="cursor-form" class="btn btn-primary"> | ||
Activate | ||
</button> | ||
<br> | ||
</form> | ||
</div> | ||
|
||
{% endblock %} |
Uh oh!
There was an error while loading. Please reload this page.