Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/WiiLink24/room-server
Browse files Browse the repository at this point in the history
  • Loading branch information
oscie57 committed Jul 5, 2024
2 parents 020df4e + 7fcddba commit 2fc025b
Show file tree
Hide file tree
Showing 19 changed files with 389 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Add second primary_key to RoomMiis
Revision ID: 6ebdcbc733bf
Revises: 4b7420e6c104
Create Date: 2024-07-04 22:31:59.115483
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "6ebdcbc733bf"
down_revision = "4b7420e6c104"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("room_miis", schema=None) as batch_op:
batch_op.alter_column("room_id", existing_type=sa.INTEGER(), nullable=False)
batch_op.drop_constraint("room_miis_room_id_key", type_="unique")
batch_op.create_unique_constraint(None, ["mii_id"])

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("room_miis", schema=None) as batch_op:
batch_op.drop_constraint(None, type_="unique")
batch_op.create_unique_constraint("room_miis_room_id_key", ["room_id"])
batch_op.alter_column("room_id", existing_type=sa.INTEGER(), nullable=False)

# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Make Mii ID the primary key for Room Miis
Revision ID: b21847b05808
Revises: e40c6d93a515
Create Date: 2024-07-04 22:37:35.247186
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "b21847b05808"
down_revision = "e40c6d93a515"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("room_miis", schema=None) as batch_op:
batch_op.drop_constraint("room_miis_room_id_key", type_="unique")

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("room_miis", schema=None) as batch_op:
batch_op.create_unique_constraint("room_miis_room_id_key", ["room_id"])

# ### end Alembic commands ###
41 changes: 41 additions & 0 deletions migrations/versions/da8e2f3e9887_add_seq_to_roommiis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Add seq to RoomMiis
Revision ID: da8e2f3e9887
Revises: b21847b05808
Create Date: 2024-07-04 22:41:48.173083
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "da8e2f3e9887"
down_revision = "b21847b05808"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("room_miis", schema=None) as batch_op:
batch_op.add_column(sa.Column("seq", sa.Integer()))

op.execute("UPDATE room_miis SET seq = 1")
op.alter_column(
"room_miis",
"seq",
existing_type=sa.Integer(),
nullable=False,
)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("room_miis", schema=None) as batch_op:
batch_op.drop_column("seq")

# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Double primary key for RoomMiis
Revision ID: e40c6d93a515
Revises: 6ebdcbc733bf
Create Date: 2024-07-04 22:34:30.018315
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "e40c6d93a515"
down_revision = "6ebdcbc733bf"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("room_miis", schema=None) as batch_op:
batch_op.create_unique_constraint(None, ["room_id"])

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("room_miis", schema=None) as batch_op:
batch_op.drop_constraint(None, type_="unique")

# ### end Alembic commands ###
7 changes: 4 additions & 3 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,13 @@ class Rooms(db.Model):


class RoomMiis(db.Model):
room_id = db.Column(
db.Integer, db.ForeignKey("rooms.room_id"), primary_key=True, unique=True
room_id = db.Column(db.Integer, db.ForeignKey("rooms.room_id"), nullable=False)
mii_id = db.Column(
db.Integer, db.ForeignKey("mii_data.mii_id"), unique=True, primary_key=True
)
mii_id = db.Column(db.Integer, db.ForeignKey("mii_data.mii_id"), nullable=False)
# Same thing as intro_msg in Rooms.
mii_msg = db.Column(db.String)
seq = db.Column(db.Integer, nullable=False)


class EvaluateData(db.Model):
Expand Down
117 changes: 115 additions & 2 deletions templates/room_action.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@
</div>

{{ form.has_mascot.label }}: {{ form.has_mascot(class_="block") }}
{{ form.mii.label(class_="label") }} {{ form.mii(class_="input block") }}
{{ form.mii_msg.label(class_="label") }} {{ form.mii_msg(class="textarea") }}

{{ form.mii }}
<br>
<button type="button" class="button is-info" id="addNewField">Add Mii</button>
<button type="button" class="button is-danger" id="removeField">Remove Mii</button>
<br>
<br>
{{ form.intro_msg.label(class_="label") }} {{ form.intro_msg(class_="textarea") }}
{{ form.news.label(class_="label") }} {{ form.news(class_="input block") }}
{{ form.contact.label(class_="label") }} {{ form.contact(class_="input block") }}
Expand All @@ -63,4 +68,112 @@
</p>
<p>{{ form.submit(class_="button is-success block") }}</p>
</form>

<script>
var fieldNum = 0;
function createMiiPair() {
// Mii ID
var newLabel = document.createElement("label")
newLabel.className = "label"
newLabel.htmlFor = "mii-" + fieldNum;
newLabel.textContent = "Mii ID"

var newTextArea = document.createElement("input");
newTextArea.className = "input";
newTextArea.id = "mii-" + fieldNum;
newTextArea.name = "mii-" + fieldNum;
fieldNum++;

// Mii Message
var newLabelName = document.createElement("label")
newLabelName.className = "label"
newLabelName.htmlFor = "mii-" + fieldNum;
newLabelName.textContent = "Mii Message"

var newTextAreaName = document.createElement("textarea");
newTextAreaName.className = "textarea";
newTextAreaName.id = "mii-" + fieldNum;
newTextAreaName.name = "mii-" + fieldNum;
fieldNum++;

document.getElementById("mii").appendChild(newLabel);
document.getElementById("mii").appendChild(newTextArea);
document.getElementById("mii").appendChild(document.createElement("br"));

document.getElementById("mii").appendChild(newLabelName);
document.getElementById("mii").appendChild(newTextAreaName);
document.getElementById("mii").appendChild(document.createElement("br"));

doDisableButtons()
}

function doDisableButtons() {
if (fieldNum === 2) {
document.getElementById("removeField").disabled = true;
} else if (fieldNum === 6) {
document.getElementById("addNewField").disabled = true;
} else {
document.getElementById("addNewField").disabled = false;
document.getElementById("removeField").disabled = false;
}
}

document.getElementById("addNewField").addEventListener("click", createMiiPair);
document.getElementById("removeField").addEventListener("click", function(){
// Remove last field pair
for (var i = 0; i < 6; i++) {
document.getElementById("mii").removeChild(document.getElementById("mii").lastChild);
}

// Finally decrement the fieldNum
fieldNum -= 2;
console.log(fieldNum);

doDisableButtons();
})

{% if miis|length == 0 %}
document.addEventListener("DOMContentLoaded", createMiiPair);
{% else %}
document.addEventListener("DOMContentLoaded", function () {
{% for mii in miis %}
// Mii ID
var newLabel = document.createElement("label")
newLabel.className = "label"
newLabel.htmlFor = "mii-" + fieldNum;
newLabel.textContent = "Mii ID"

var newTextArea = document.createElement("input");
newTextArea.className = "input";
newTextArea.id = "mii-" + fieldNum;
newTextArea.name = "mii-" + fieldNum;
newTextArea.value = "{{ mii.mii_id }}";
fieldNum++;

// Mii Message
var newLabelName = document.createElement("label")
newLabelName.className = "label"
newLabelName.htmlFor = "mii-" + fieldNum;
newLabelName.textContent = "Mii Message"

var newTextAreaName = document.createElement("textarea");
newTextAreaName.className = "textarea";
newTextAreaName.id = "mii-" + fieldNum;
newTextAreaName.name = "mii-" + fieldNum;
newTextAreaName.value = `{{ mii.mii_msg }}`
fieldNum++;

document.getElementById("mii").appendChild(newLabel);
document.getElementById("mii").appendChild(newTextArea);
document.getElementById("mii").appendChild(document.createElement("br"));

document.getElementById("mii").appendChild(newLabelName);
document.getElementById("mii").appendChild(newTextAreaName);
document.getElementById("mii").appendChild(document.createElement("br"));

doDisableButtons()
{% endfor %}
});
{% endif %}
</script>
{% endblock %}
2 changes: 1 addition & 1 deletion templates/room_add_coupon.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{ form.movie.label(class_="label") }} {{ form.movie(size=32) }}
<br>
<br>
{{ form.title.label(class_="label") }} {{ form.title(class_="input") }}
{{ form.title.label(class_="label") }} {{ form.title(class_="textarea") }}
<br>
<br>
{{ form.tv.label(class_="label") }} {{ form.tv(size=32) }}
Expand Down
2 changes: 1 addition & 1 deletion templates/room_add_delivery.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{ form.movie.label(class_="label") }} {{ form.movie(size=32) }}
<br>
<br>
{{ form.title.label(class_="label") }} {{ form.title(class_="input") }}
{{ form.title.label(class_="label") }} {{ form.title(class_="textarea") }}
<br>
<br>
{{ form.tv.label(class_="label") }} {{ form.tv(size=32) }}
Expand Down
2 changes: 1 addition & 1 deletion templates/room_add_link.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{ form.movie.label(class_="label") }} {{ form.movie(size=32) }}
<br>
<br>
{{ form.title.label(class_="label") }} {{ form.title(class_="input") }}
{{ form.title.label(class_="label") }} {{ form.title(class_="textarea") }}
<br>
<br>
{{ form.link.label(class_="label") }} {{ form.link(class_="input") }}
Expand Down
2 changes: 1 addition & 1 deletion templates/room_add_mov.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<p>
{{ form.hidden_tag() }}
<br>
{{ form.title.label(class_="label") }} {{ form.title(class_="input") }}
{{ form.title.label(class_="label") }} {{ form.title(class_="textarea") }}
<br>
<br>
{{ form.movie_id.label(class_="label") }} {{ form.movie_id(class_="input") }}
Expand Down
2 changes: 1 addition & 1 deletion templates/room_add_pic.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
</div>
<br>
{{ form.title.label(class_="label") }} {{ form.title(class_="input") }}
{{ form.title.label(class_="label") }} {{ form.title(class_="textarea") }}
<br>
<br>
{{ form.tv.label(class_="label") }} {{ form.tv(size=32) }}
Expand Down
4 changes: 2 additions & 2 deletions templates/room_add_vote.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<p>
{{ form.hidden_tag() }}
<br>
{{ form.title.label(class_="label") }} {{ form.title(class_="input") }}
{{ form.title.label(class_="label") }} {{ form.title(class_="textarea") }}
<br>
<br>
{{ form.question.label(class_="label") }} {{ form.question(class_="input") }}
<br>
<br>
{{ form.mii_msg.label(class_="label") }} {{ form.mii_msg(class_="input") }}
{{ form.mii_msg.label(class_="label") }} {{ form.mii_msg(class_="textarea") }}
<br>
<br>
{{ form.tv.label(class_="label") }} {{ form.tv(size=32) }}
Expand Down
Loading

0 comments on commit 2fc025b

Please sign in to comment.