Skip to content

Commit

Permalink
[update]
Browse files Browse the repository at this point in the history
  • Loading branch information
boke0 committed Mar 7, 2021
1 parent 3e399ef commit 4841e59
Show file tree
Hide file tree
Showing 12 changed files with 1,209 additions and 12 deletions.
22 changes: 21 additions & 1 deletion kyokusui/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import magic

from .model import db, Board, Thread, Res, Permission
from .forms import CreateBoardForm, CreateThreadForm, SettingForm
from .forms import CreateBoardForm, CreateThreadForm, SettingForm, UpdateThreadForm, UpdateBoardForm
from .utils import hiroyuki

class HomeController(Controller):
Expand Down Expand Up @@ -59,6 +59,16 @@ def retrieve(self, request):
"boards": Board.list_subscribed(request.user)
})

def update(self, request):
board = Board.retrieve(request.params['board'])
form = UpdateBoardForm(request.post())
board.name = form['name']
board.update()
return Response.json({
"_id": board._id,
"name": board.name,
})

def subscribe(self, request):
board = Board.retrieve(request.params['board'])
board.subscribers.append(request.user)
Expand Down Expand Up @@ -117,6 +127,16 @@ def retrieve(self, request):
"boards": Board.list_subscribed(request.user)
})

def update(self, request):
thread = Thread.retrieve(request.params['thread'])
form = UpdateThreadForm(request.post())
thread.title = form['title']
thread.update()
return Response.json({
"_id": thread._id,
"title": thread.title,
})

class WebSocketController(Controller):
streams = {}
def handle(self, request):
Expand Down
6 changes: 6 additions & 0 deletions kyokusui/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ class CreateThreadForm(Form):

class SettingForm(Form):
permissions = DictField(label="権限", listed=True)

class UpdateThreadForm(Form):
title = Field(label="タイトル", required=True)

class UpdateBoardForm(Form):
name = Field(label="タイトル", required=True)
4 changes: 3 additions & 1 deletion kyokusui/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from mitama.app import App, Router
from mitama.utils.controllers import static_files
from mitama.utils.middlewares import SessionMiddleware
from mitama.app.method import view, post
from mitama.app.method import view, post, put

from .controller import HomeController, BoardController, ThreadController, WebSocketController, UserController
from .model import Board, Thread, Res, Permission
Expand All @@ -19,9 +19,11 @@ class App(App):
view("/<board>/<thread>", ThreadController, 'retrieve'),
view("/user/<user>/icon", UserController, 'icon'),
post("/api/v0/board", BoardController, 'create'),
put("/api/v0/board/<board>", BoardController, 'update'),
post("/api/v0/board/<board>", ThreadController, 'create'),
post("/api/v0/board/<board>/subscribe", BoardController, 'subscribe'),
post("/api/v0/board/<board>/unsubscribe", BoardController, 'unsubscribe'),
put("/api/v0/board/<board>/<thread>", ThreadController, 'update'),
view("/api/v0/board/<board>/<thread>/socket", WebSocketController),
],
middlewares=[SessionMiddleware]
Expand Down
23 changes: 22 additions & 1 deletion kyokusui/templates/board.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
{% include "components/thread_form.html" %}
<div class='container'>
<div class='d-flex justify-content-between'>
<h2>{{ board.name }}</h2>
<h2 id='title'>{{ board.name }}</h2>
<div>
{% if request.user in board.subscribers %}
<button class='btn bi bi-bookmark-plus-fill text-primary' onclick='unsubscribe()'></button>
{% else %}
<button class='btn bi bi-bookmark-plus-fill' onclick='subscribe()'></button>
{% endif %}
{% if board.owner.object == request.user or board.owner.object in request.user.groups %}
<button class='btn bi bi-gear-fill' onclick='edit()'></button>
{% endif %}
<button class='btn btn-primary' data-bs-toggle='modal' data-bs-target='#thread_form'>スレッドを立てる</button>
</div>
</div>
Expand Down Expand Up @@ -43,6 +46,24 @@ <h5 class='mb-1'>
location.reload()
})
}
function edit() {
const input = document.createElement("input")
input.classList.add("form-control")
input.value = title.innerHTML
input.onblur = () => {
const form = new FormData()
form.append("name", input.value)
fetch("{{ url("/api/v0/board/" + board._id) }}", {
method: "PUT",
credentials: "include",
body: form
}).then(res => res.json()).then(res => {
title.innerHTML = res.name
})
}
title.innerHTML = "";
title.append(input)
}
</script>
</div>
{% endblock %}
28 changes: 26 additions & 2 deletions kyokusui/templates/thread.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<div id='messages'>
<header class='card mb-3'>
<div class='card-body'>
<h2 class='card-title mb-4'>{{ thread.title }}</h2>
{{ lists.userItem(request.user, small=True) }}
<h2 id="title" class='card-title mb-4'>{{ thread.title }}</h2>
<div class='d-flex justify-content-between'>
{{ lists.userItem(request.user, small=True) }}
{% if thread.user == request.user %}
<button class='btn bi bi-gear-fill' onclick='edit()'></button>
{% endif %}
</div>
<div class='card-text d-flex justify-content-end'><small class='text-muted'>{{ thread.created.strftime('%Y-%m-%d %H:%M:%S') }}</small></div>
</div>
</header>
Expand Down Expand Up @@ -80,6 +85,7 @@ <h5 class='modal-title'>スレッドを締めますか?</h5>
<script>
var counter = {{ thread.res|length }}
var images = []
const title = document.querySelector("#title")
const textarea = document.querySelector("#message")
const image_form = document.querySelector("#image")
const image2send = document.querySelector("#image2send")
Expand Down Expand Up @@ -176,6 +182,24 @@ <h5 class='modal-title'>スレッドを締めますか?</h5>
ws.close()
const form = document.querySelector("#message_form");
form.parentNode.removeChild(form)
}
function edit() {
const input = document.createElement("input")
input.classList.add("form-control")
input.value = title.innerHTML
input.onblur = () => {
const form = new FormData()
form.append("title", input.value)
fetch("{{ url("/api/v0/board/" + board._id + "/" + thread._id) }}", {
method: "PUT",
credentials: "include",
body: form
}).then(res => res.json()).then(res => {
title.innerHTML = res.title
})
}
title.innerHTML = "";
title.append(input)
}
</script>
</div>
Expand Down
59 changes: 57 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ authors = ["boke0 <[email protected]>"]
license = "MIT"

include = [
"izanami/templates/*.html",
"izanami/templates/**/*.html",
"izanami/static/*",
"izanami/static/**/*",
"kyokusui/templates/*.html",
"kyokusui/templates/**/*.html",
"kyokusui/static/*",
"kyokusui/static/**/*",
]

[tool.poetry.dependencies]
python = "^3.6"
mitama = "^4.5.4"
mitama = "^4.5.8"

[tool.poetry.dev-dependencies]
unittest = "^0.0"
Expand Down
4 changes: 4 additions & 0 deletions tests/docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data/
__pycache__/
uwsgi.log
.tmp/
24 changes: 24 additions & 0 deletions tests/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3"
services:
mysql:
image: mysql:latest
container_name: mitama_mysql
command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci
volumes:
- "./data:/var/lib/mysql"
ports:
- 3306:3306
environment:
- MYSQL_USER=mitama
- MYSQL_PASSWORD=mitama
- MYSQL_DATABASE=mitama
- MYSQL_RANDOM_ROOT_PASSWORD=yes
mitama:
image: mitama:latest-mysql
depends_on:
- mysql
volumes:
- "./:/project"
ports:
- 8080:80

Loading

0 comments on commit 4841e59

Please sign in to comment.