mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-15 02:21:21 +01:00
CSS Variables fix
This commit is contained in:
parent
3c83641a55
commit
a293b89b8c
@ -18,7 +18,7 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
op.add_column('user_css', sa.Column('css_variables', sa.Text(), nullable=True))
|
op.add_column('user_css', sa.Column('css_variables', sa.Text()))
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,259 @@
|
|||||||
|
"""Add css variable toggle column
|
||||||
|
|
||||||
|
Revision ID: f65629d470c6
|
||||||
|
Revises: 058f970b85db
|
||||||
|
Create Date: 2017-09-07 23:08:34.344304
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'f65629d470c6'
|
||||||
|
down_revision = '058f970b85db'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('administrators', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('authenticated_users', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('authenticated_users', 'last_timestamp',
|
||||||
|
existing_type=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
type_=sa.TIMESTAMP(),
|
||||||
|
existing_nullable=False,
|
||||||
|
existing_server_default=sa.text('now()'))
|
||||||
|
op.alter_column('cosmetics', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('guild_members', 'discriminator',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('guild_members', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('guilds', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('guilds', 'mentions_limit',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
existing_nullable=False,
|
||||||
|
existing_server_default=sa.text('(-1)::bigint'))
|
||||||
|
op.alter_column('keyvalue_properties', 'expiration',
|
||||||
|
existing_type=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
type_=sa.TIMESTAMP(),
|
||||||
|
existing_nullable=True)
|
||||||
|
op.alter_column('keyvalue_properties', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('messages', 'edited_timestamp',
|
||||||
|
existing_type=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
type_=sa.TIMESTAMP(),
|
||||||
|
existing_nullable=True)
|
||||||
|
op.alter_column('messages', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('messages', 'timestamp',
|
||||||
|
existing_type=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
type_=sa.TIMESTAMP(),
|
||||||
|
nullable=False)
|
||||||
|
op.alter_column('titan_tokens', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('titan_tokens', 'tokens',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('token_transactions', 'end_tokens',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('token_transactions', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('token_transactions', 'net_tokens',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('token_transactions', 'start_tokens',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('token_transactions', 'timestamp',
|
||||||
|
existing_type=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
type_=sa.TIMESTAMP(),
|
||||||
|
existing_nullable=False,
|
||||||
|
existing_server_default=sa.text('now()'))
|
||||||
|
op.alter_column('unauthenticated_bans', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('unauthenticated_bans', 'last_discriminator',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('unauthenticated_bans', 'timestamp',
|
||||||
|
existing_type=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
type_=sa.TIMESTAMP(),
|
||||||
|
existing_nullable=False,
|
||||||
|
existing_server_default=sa.text('now()'))
|
||||||
|
op.alter_column('unauthenticated_users', 'discriminator',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('unauthenticated_users', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('unauthenticated_users', 'last_timestamp',
|
||||||
|
existing_type=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
type_=sa.TIMESTAMP(),
|
||||||
|
existing_nullable=False,
|
||||||
|
existing_server_default=sa.text('now()'))
|
||||||
|
op.add_column('user_css', sa.Column('css_var_bool', sa.Boolean(), nullable=False, server_default="0"))
|
||||||
|
op.alter_column('user_css', 'css_variables',
|
||||||
|
existing_type=sa.TEXT())
|
||||||
|
op.alter_column('user_css', 'id',
|
||||||
|
existing_type=sa.BIGINT(),
|
||||||
|
type_=sa.Integer(),
|
||||||
|
autoincrement=True)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('user_css', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('user_css', 'css_variables',
|
||||||
|
existing_type=sa.TEXT(),
|
||||||
|
nullable=True)
|
||||||
|
op.drop_column('user_css', 'css_var_bool')
|
||||||
|
op.alter_column('unauthenticated_users', 'last_timestamp',
|
||||||
|
existing_type=sa.TIMESTAMP(),
|
||||||
|
type_=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
existing_nullable=False,
|
||||||
|
existing_server_default=sa.text('now()'))
|
||||||
|
op.alter_column('unauthenticated_users', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('unauthenticated_users', 'discriminator',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('unauthenticated_bans', 'timestamp',
|
||||||
|
existing_type=sa.TIMESTAMP(),
|
||||||
|
type_=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
existing_nullable=False,
|
||||||
|
existing_server_default=sa.text('now()'))
|
||||||
|
op.alter_column('unauthenticated_bans', 'last_discriminator',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('unauthenticated_bans', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('token_transactions', 'timestamp',
|
||||||
|
existing_type=sa.TIMESTAMP(),
|
||||||
|
type_=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
existing_nullable=False,
|
||||||
|
existing_server_default=sa.text('now()'))
|
||||||
|
op.alter_column('token_transactions', 'start_tokens',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('token_transactions', 'net_tokens',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('token_transactions', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('token_transactions', 'end_tokens',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('titan_tokens', 'tokens',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('titan_tokens', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('messages', 'timestamp',
|
||||||
|
existing_type=sa.TIMESTAMP(),
|
||||||
|
type_=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
nullable=True)
|
||||||
|
op.alter_column('messages', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('messages', 'edited_timestamp',
|
||||||
|
existing_type=sa.TIMESTAMP(),
|
||||||
|
type_=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
existing_nullable=True)
|
||||||
|
op.alter_column('keyvalue_properties', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('keyvalue_properties', 'expiration',
|
||||||
|
existing_type=sa.TIMESTAMP(),
|
||||||
|
type_=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
existing_nullable=True)
|
||||||
|
op.alter_column('guilds', 'mentions_limit',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
existing_nullable=False,
|
||||||
|
existing_server_default=sa.text('(-1)::bigint'))
|
||||||
|
op.alter_column('guilds', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('guild_members', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('guild_members', 'discriminator',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('cosmetics', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('authenticated_users', 'last_timestamp',
|
||||||
|
existing_type=sa.TIMESTAMP(),
|
||||||
|
type_=postgresql.TIMESTAMP(timezone=True),
|
||||||
|
existing_nullable=False,
|
||||||
|
existing_server_default=sa.text('now()'))
|
||||||
|
op.alter_column('authenticated_users', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
op.alter_column('administrators', 'id',
|
||||||
|
existing_type=sa.Integer(),
|
||||||
|
type_=sa.BIGINT(),
|
||||||
|
autoincrement=True)
|
||||||
|
# ### end Alembic commands ###
|
@ -114,7 +114,9 @@ def edit_custom_css_get(css_id):
|
|||||||
abort(404)
|
abort(404)
|
||||||
if css.user_id != session['user_id']:
|
if css.user_id != session['user_id']:
|
||||||
abort(403)
|
abort(403)
|
||||||
variables = json.loads(css.css_variables)
|
variables = css.css_variables
|
||||||
|
if variables:
|
||||||
|
variables = json.loads(variables)
|
||||||
return render_template("usercss.html.j2", new=False, css=css, variables=variables)
|
return render_template("usercss.html.j2", new=False, css=css, variables=variables)
|
||||||
|
|
||||||
@user.route("/custom_css/edit/<css_id>", methods=["POST"])
|
@user.route("/custom_css/edit/<css_id>", methods=["POST"])
|
||||||
@ -131,6 +133,7 @@ def edit_custom_css_post(css_id):
|
|||||||
name = request.form.get("name", None)
|
name = request.form.get("name", None)
|
||||||
css = request.form.get("css", "")
|
css = request.form.get("css", "")
|
||||||
variables = request.form.get("variables", None)
|
variables = request.form.get("variables", None)
|
||||||
|
variables_enabled = request.form.get("variables_enabled", False) in ["true", True]
|
||||||
if not name:
|
if not name:
|
||||||
abort(400)
|
abort(400)
|
||||||
else:
|
else:
|
||||||
@ -139,6 +142,7 @@ def edit_custom_css_post(css_id):
|
|||||||
dbcss.name = name
|
dbcss.name = name
|
||||||
dbcss.css = css
|
dbcss.css = css
|
||||||
dbcss.css_variables = variables
|
dbcss.css_variables = variables
|
||||||
|
dbcss.css_var_bool = variables_enabled
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return jsonify({"id": dbcss.id})
|
return jsonify({"id": dbcss.id})
|
||||||
|
|
||||||
|
@ -5,11 +5,13 @@ class UserCSS(db.Model):
|
|||||||
id = db.Column(db.Integer, primary_key=True) # Auto increment id
|
id = db.Column(db.Integer, primary_key=True) # Auto increment id
|
||||||
name = db.Column(db.String(255), nullable=False) # CSS Name
|
name = db.Column(db.String(255), nullable=False) # CSS Name
|
||||||
user_id = db.Column(db.String(255), nullable=False) # Discord client ID of the owner of the css (can edit)
|
user_id = db.Column(db.String(255), nullable=False) # Discord client ID of the owner of the css (can edit)
|
||||||
|
css_var_bool = db.Column(db.Boolean(), nullable=False, server_default="0") # If css variables should be taken into consideration
|
||||||
css_variables = db.Column(db.Text()) # Customizeable CSS Variables
|
css_variables = db.Column(db.Text()) # Customizeable CSS Variables
|
||||||
css = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql')) # CSS contents
|
css = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql')) # CSS contents
|
||||||
|
|
||||||
def __init__(self, name, user_id, css_variables=None, css=None):
|
def __init__(self, name, user_id, css_var_bool=False, css_variables=None, css=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
|
self.css_var_bool = css_var_bool
|
||||||
self.css_variables = css_variables
|
self.css_variables = css_variables
|
||||||
self.css = css
|
self.css = css
|
||||||
|
@ -4,12 +4,13 @@
|
|||||||
|
|
||||||
function postForm() {
|
function postForm() {
|
||||||
var name = $('#css_name').val();
|
var name = $('#css_name').val();
|
||||||
|
var var_enabled = $("#toggleCSSVar").is(':checked');
|
||||||
var variables = JSON.stringify(formatCSSVars());
|
var variables = JSON.stringify(formatCSSVars());
|
||||||
var css = editor.getValue();
|
var css = editor.getValue();
|
||||||
var funct = $.ajax({
|
var funct = $.ajax({
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data: {"name": name, "variables": variables, "css": css}
|
data: {"name": name, "variables_enabled": var_enabled, "variables": variables, "css": css}
|
||||||
});
|
});
|
||||||
return funct.promise();
|
return funct.promise();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
{% include 'google_analytics.html.j2' %}
|
{% include 'google_analytics.html.j2' %}
|
||||||
|
|
||||||
{% if css is not none %}
|
{% if css is not none %}
|
||||||
<style id="user-defined-css">{% if cssvariables is not none %}{{ cssvariables }}{% endif %} {{ css.css }}</style>
|
<style id="user-defined-css">{% if cssvariables is not none and css.css_var_bool %}{{ cssvariables }}{% endif %} {{ css.css }}</style>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -18,7 +18,7 @@ will have CSS cosmetic privilages removed, if caught. Please don't, we check the
|
|||||||
<p><strong>This user defined CSS has a unique ID of <em style="font-size: 130%;">{{ css.id }}</em>.</strong></p>
|
<p><strong>This user defined CSS has a unique ID of <em style="font-size: 130%;">{{ css.id }}</em>.</strong></p>
|
||||||
<p>To use this CSS in the embed, you must apped a <code>?css={{ css.id }}</code> to the embed URL.</p>
|
<p>To use this CSS in the embed, you must apped a <code>?css={{ css.id }}</code> to the embed URL.</p>
|
||||||
<p>Something like this will work:</p>
|
<p>Something like this will work:</p>
|
||||||
<input readonly value="https://titanembeds.com/embed/1234567890987654321?css={{ css.id }}" id="disabled" type="text" onClick="this.setSelectionRange(48, this.value.length)">
|
<input readonly value="https://titanembeds.com/embed/1234567890987654321?css={{ css.id }}" id="disabled" type="text" onClick="this.setSelectionRange(this.value.indexOf("?"), this.value.length)">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -33,6 +33,10 @@ will have CSS cosmetic privilages removed, if caught. Please don't, we check the
|
|||||||
</div>
|
</div>
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
<p class="flow-text">Propose Predefined CSS variables here</p>
|
<p class="flow-text">Propose Predefined CSS variables here</p>
|
||||||
|
<p>
|
||||||
|
<input type="checkbox" id="toggleCSSVar" {% if css.css_var_bool %}checked{% endif %}/>
|
||||||
|
<label for="toggleCSSVar">CSS Variables Enabled</label>
|
||||||
|
</p>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col m6 s12">
|
<div class="col m6 s12">
|
||||||
<span>Modal Background Color (<code>--modal</code>):<span>
|
<span>Modal Background Color (<code>--modal</code>):<span>
|
||||||
|
Loading…
Reference in New Issue
Block a user