0
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
4
|
3 local ipairs = Luan.ipairs or error()
|
23
|
4 local pairs = Luan.pairs or error()
|
0
|
5 local Io = require "luan:Io.luan"
|
|
6 local Http = require "luan:http/Http.luan"
|
|
7 local Shared = require "site:/lib/Shared.luan"
|
|
8 local head = Shared.head or error()
|
|
9 local header = Shared.header or error()
|
46
|
10 local languages = Shared.languages or error()
|
4
|
11 local User = require "site:/lib/User.luan"
|
24
|
12 local current_user = User.current_required or error()
|
4
|
13 local Chat = require "site:/lib/Chat.luan"
|
|
14 local chat_search = Chat.search or error()
|
23
|
15 local Logging = require "luan:logging/Logging.luan"
|
|
16 local logger = Logging.logger "chats.html"
|
0
|
17
|
|
18
|
|
19 return function()
|
4
|
20 local user = current_user()
|
24
|
21 if user == nil then return end
|
4
|
22 local chats = chat_search( "chat_user_id:"..user.id, "chat_updated desc" )
|
23
|
23 local select_language = #chats > 0 and chats[1].language or nil
|
0
|
24 Io.stdout = Http.response.text_writer()
|
|
25 %>
|
|
26 <!doctype html>
|
|
27 <html lang="en">
|
|
28 <head>
|
|
29 <% head() %>
|
21
|
30 <style>
|
23
|
31 form {
|
|
32 margin-bottom: 20px;
|
|
33 }
|
21
|
34 td {
|
|
35 padding: 8px 8px;
|
|
36 }
|
|
37 </style>
|
0
|
38 </head>
|
|
39 <body>
|
|
40 <% header() %>
|
|
41 <div content>
|
15
|
42 <h1>Your Chats</h1>
|
24
|
43 <form action="lang_courses.html">
|
23
|
44 <select name=language>
|
46
|
45 <% for code, name in pairs(languages) do
|
23
|
46 local selected = code==select_language and "selected" or ""
|
|
47 %>
|
46
|
48 <option value="<%=code%>" <%=selected%> ><%=name%></option>
|
23
|
49 <% end %>
|
|
50 </select>
|
48
|
51 <input type=submit value="New chat">
|
23
|
52 </form>
|
21
|
53 <table>
|
4
|
54 <% for _, chat in ipairs(chats) do %>
|
21
|
55 <tr>
|
|
56 <td><%= chat.language_name() %></td>
|
|
57 <td><a href="chat.html?chat=<%=chat.id%>"><%= chat.name_html() %></a></td>
|
|
58 </tr>
|
4
|
59 <% end %>
|
21
|
60 </table>
|
0
|
61 </div>
|
|
62 </body>
|
|
63 </html>
|
|
64 <%
|
|
65 end
|