Mercurial Hosting > lang
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/your_courses.html.luan Thu Jul 31 22:30:26 2025 -0600 @@ -0,0 +1,68 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local ipairs = Luan.ipairs or error() +local pairs = Luan.pairs or error() +local Io = require "luan:Io.luan" +local Http = require "luan:http/Http.luan" +local Shared = require "site:/lib/Shared.luan" +local head = Shared.head or error() +local header = Shared.header or error() +local User = require "site:/lib/User.luan" +local current_user = User.current_required or error() +local Course = require "site:/lib/Course.luan" +local course_search = Course.search or error() +local languages = require "site:/lib/languages.luan" +local Logging = require "luan:logging/Logging.luan" +local logger = Logging.logger "chats.html" + + +return function() + local user = current_user() + if user == nil then return end + local courses = course_search( "course_user_id:"..user.id, "course_updated desc" ) + local select_language = #courses > 0 and courses[1].language or nil + Io.stdout = Http.response.text_writer() +%> +<!doctype html> +<html lang="en"> + <head> +<% head() %> + <style> + form { + margin-bottom: 20px; + } + td { + padding: 8px 8px; + } + </style> + </head> + <body> +<% header() %> + <div content> + <h1>Your Courses</h1> + <form action="edit_course.html"> + <select name=language> +<% for _, lang in pairs(languages) do + local code = lang.code + local selected = code==select_language and "selected" or "" +%> + <option value="<%=code%>" <%=selected%> ><%=lang.name%></option> +<% end %> + </select> + <input type=submit value="new course"> + </form> + <table> +<% for _, course in ipairs(courses) do %> + <tr> + <td><%= course.language_name() %></td> + <td><%= course.name_html() %></td> + <td><a href="new_chat.red?course=<%=course.id%>">new chat</a></td> + <td><a href="edit_course.html?course=<%=course.id%>">edit</a></td> + </tr> +<% end %> + </table> + </div> + </body> +</html> +<% +end