Ktor Panel¶
A lightweight, customisable admin interface library for Ktor applications. Ktor Panel provides a simple way to manage your database models through an intuitive web interface with minimal configuration.
Installation¶
Gradle (Kotlin DSL)¶
dependencies {
implementation("xyz.daimones:ktor-panel:0.0.1")
}
Gradle (Groovy)¶
dependencies {
implementation 'xyz.daimones:ktor-panel:0.0.1'
}
Maven¶
<dependency>
<groupId>xyz.daimones</groupId>
<artifactId>ktor-panel</artifactId>
<version>0.0.1</version>
</dependency>
Quick Start¶
Basic Setup¶
// Import necessary components
import xyz.daimones.ktor.panel.Admin
import xyz.daimones.ktor.panel.Configuration
import xyz.daimones.ktor.panel.ModelView
import org.jetbrains.exposed.sql.Database
fun Application.configureAdminPanel() {
// Setup your database connection
val database = Database.connect(
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
driver = "org.h2.Driver"
)
// Create admin configuration
val config = Configuration(
url = "admin", // Access at /admin
adminName = "My App Admin"
)
// Initialize admin panel
val admin = Admin(this, database, config)
// Add your models to the admin panel
admin.addView(ModelView(Users))
admin.addView(ModelView(Products))
}
Add to your Ktor application¶
fun Application.module() {
// Configure other Ktor features
install(ContentNegotiation) {
json()
}
// Install Mustache for templates
install(Mustache) {
mustacheFactory = DefaultMustacheFactory("templates")
}
// Add admin panel
configureAdminPanel()
}
Customisation¶
Custom Configuration¶
val config = Configuration(
url = "dashboard", // Change URL to /dashboard
endpoint = "/", // Set index endpoint
setAuthentication = true, // Enable authentication
adminName = "Custom Admin" // Change admin panel name
)
Custom Templates¶
Create your own Mustache templates in your resources directory to override the defaults:
kt-panel-index.hbs
- Main dashboard templatekt-panel-list.hbs
- List view for database recordskt-panel-create.hbs
- Form for creating new recordskt-panel-details.hbs
- Detailed view of a recordkt-panel-update.hbs
- Form for updating existing records
Testing¶
To run the tests for this project, you can use the following Gradle command:
./gradlew test
After running the tests, you can find:
Test reports in the
lib/build/reports/tests/test/
directoryTest coverage reports in the
lib/build/reports/jacoco/test/
directory
Contributing¶
Contributions are welcome! Please feel free to submit a Pull Request.
Fork the repository
Create your feature branch (
git checkout -b feature/amazing-feature
)Commit your changes (
git commit -m 'Add some amazing feature'
)Push to the branch (
git push origin feature/amazing-feature
)Open a Pull Request
License¶
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
Acknowledgments¶
Ktor - Kotlin async web framework
Exposed - Kotlin SQL library
Mustache - Logic-less templates
Flask-Admin - Inspiration for this project