Ktor Panel

` Kotlin Ktor License

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 template

  • kt-panel-list.hbs - List view for database records

  • kt-panel-create.hbs - Form for creating new records

  • kt-panel-details.hbs - Detailed view of a record

  • kt-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/ directory

  • Test coverage reports in the lib/build/reports/jacoco/test/ directory

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository

  2. Create your feature branch (git checkout -b feature/amazing-feature)

  3. Commit your changes (git commit -m 'Add some amazing feature')

  4. Push to the branch (git push origin feature/amazing-feature)

  5. Open a Pull Request

License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

Acknowledgments