generated from alpas/starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WelcomeController.kt
70 lines (58 loc) · 2.34 KB
/
WelcomeController.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.load.more.controllers
import com.load.more.entities.Images
import dev.alpas.http.HttpCall
import dev.alpas.routing.Controller
import dev.alpas.ozone.latest
import dev.alpas.toJson
import me.liuwj.ktorm.entity.take
import me.liuwj.ktorm.entity.drop
import me.liuwj.ktorm.entity.toList
// https://alpas.dev/docs/controllers
class WelcomeController : Controller() {
fun index(call: HttpCall) {
val images = Images
.latest()
.take(5)
.toList()
call.render("welcome"){"images" to images}
}
fun showmore(call: HttpCall){
if(call.isAjax){
var num: Int = call.intParam("id") as Int
val images = Images
.latest()
.drop(num)
.take(5)
.toList()
var content = ""
var last_id = num + 5
if (num < 15){
for (image in images){
content += """
<li class="p-4 bg-white rounded-lg mb-3 flex flex-st">
<div class="flex">
<div class="self-center">
<a href="${image.src}" target="_blank">
<img class="h-20 w-20 object-cover rounded-lg" src="${image.src}">
</a>
</div>
<div class="ml-6 pr-4 flex-1">
<div class="text-xl font-bold text-gray-900"> ${image.name} </div>
</div>
</div>
</li>
""".trimIndent()
}
content += """
<button type="button" name="show_more_button" class="font-semibold uppercase py-2 px-4 rounded-lg inline-flex" data-id="${last_id}" id="show_more_button">
<svg class="fill-current h-4 w-4 mr-2 mt-1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/></svg>
<span>Show More</span>
</button>
""".trimIndent()
}else {
content = "🏙 That's all! 👋"
}
call.reply(content)
}
}
}