Mercurial Hosting > lang
comparison src/your_courses.html.luan @ 24:87fe70201aa8
courses work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 31 Jul 2025 22:30:26 -0600 |
parents | src/chats.html.luan@0c17c233c45a |
children | cc20eebaa74a |
comparison
equal
deleted
inserted
replaced
23:0c17c233c45a | 24:87fe70201aa8 |
---|---|
1 local Luan = require "luan:Luan.luan" | |
2 local error = Luan.error | |
3 local ipairs = Luan.ipairs or error() | |
4 local pairs = Luan.pairs or error() | |
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() | |
10 local User = require "site:/lib/User.luan" | |
11 local current_user = User.current_required or error() | |
12 local Course = require "site:/lib/Course.luan" | |
13 local course_search = Course.search or error() | |
14 local languages = require "site:/lib/languages.luan" | |
15 local Logging = require "luan:logging/Logging.luan" | |
16 local logger = Logging.logger "chats.html" | |
17 | |
18 | |
19 return function() | |
20 local user = current_user() | |
21 if user == nil then return end | |
22 local courses = course_search( "course_user_id:"..user.id, "course_updated desc" ) | |
23 local select_language = #courses > 0 and courses[1].language or nil | |
24 Io.stdout = Http.response.text_writer() | |
25 %> | |
26 <!doctype html> | |
27 <html lang="en"> | |
28 <head> | |
29 <% head() %> | |
30 <style> | |
31 form { | |
32 margin-bottom: 20px; | |
33 } | |
34 td { | |
35 padding: 8px 8px; | |
36 } | |
37 </style> | |
38 </head> | |
39 <body> | |
40 <% header() %> | |
41 <div content> | |
42 <h1>Your Courses</h1> | |
43 <form action="edit_course.html"> | |
44 <select name=language> | |
45 <% for _, lang in pairs(languages) do | |
46 local code = lang.code | |
47 local selected = code==select_language and "selected" or "" | |
48 %> | |
49 <option value="<%=code%>" <%=selected%> ><%=lang.name%></option> | |
50 <% end %> | |
51 </select> | |
52 <input type=submit value="new course"> | |
53 </form> | |
54 <table> | |
55 <% for _, course in ipairs(courses) do %> | |
56 <tr> | |
57 <td><%= course.language_name() %></td> | |
58 <td><%= course.name_html() %></td> | |
59 <td><a href="new_chat.red?course=<%=course.id%>">new chat</a></td> | |
60 <td><a href="edit_course.html?course=<%=course.id%>">edit</a></td> | |
61 </tr> | |
62 <% end %> | |
63 </table> | |
64 </div> | |
65 </body> | |
66 </html> | |
67 <% | |
68 end |