diff options
author | Robert Jaros <rjaros@finn.pl> | 2017-09-25 10:30:25 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2017-09-25 10:31:27 +0200 |
commit | 089447dd370314276531836e39afa2224eb8f6b8 (patch) | |
tree | ce26e9cee19bcdae06fb7c39a1b1fab344dce95d /src/main/kotlin/pl/treksoft | |
parent | 726a42ad5643840f84c289c9a6b56d6c3c9067b4 (diff) | |
download | kvision-089447dd370314276531836e39afa2224eb8f6b8.tar.gz kvision-089447dd370314276531836e39afa2224eb8f6b8.tar.bz2 kvision-089447dd370314276531836e39afa2224eb8f6b8.zip |
Code style fixes
Diffstat (limited to 'src/main/kotlin/pl/treksoft')
15 files changed, 58 insertions, 61 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt index 9ac623a8..283a9236 100644 --- a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt +++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt @@ -175,9 +175,9 @@ class Showcase : ApplicationBase() { root.add(button3) println("init routing") - routing.on({ -> println("root") }) - .on("/abc", { -> println("abc") }) - .on("/test", { -> println("test") }) + routing.on({ _ -> println("root") }) + .on("/abc", { _ -> println("abc") }) + .on("/test", { _ -> println("test") }) .resolve() // jQuery(document).off(".data-api") @@ -204,6 +204,6 @@ class Showcase : ApplicationBase() { } override fun dispose(): Map<String, Any> { - return mapOf<String, Any>() + return mapOf() } } diff --git a/src/main/kotlin/pl/treksoft/kvision/core/KVManager.kt b/src/main/kotlin/pl/treksoft/kvision/core/KVManager.kt index dfcbc87c..e75167e1 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/KVManager.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/KVManager.kt @@ -8,11 +8,9 @@ import com.github.snabbdom.datasetModule import com.github.snabbdom.eventListenersModule import com.github.snabbdom.propsModule import com.github.snabbdom.styleModule -import org.w3c.dom.Node import pl.treksoft.jquery.jQuery import pl.treksoft.kvision.require import pl.treksoft.kvision.routing.routing -import pl.treksoft.kvision.snabbdom.obj import kotlin.browser.document import kotlin.dom.clear diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Root.kt b/src/main/kotlin/pl/treksoft/kvision/core/Root.kt index 49b3a6f4..21bdca04 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Root.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Root.kt @@ -46,10 +46,10 @@ class Root(id: String, private val fluid: Boolean = true) : Container() { private val roots: MutableList<Root> = mutableListOf() internal fun getLastRoot(): Root? { - if (roots.size > 0) - return roots[roots.size - 1] + return if (roots.size > 0) + roots[roots.size - 1] else - return null + null } } } diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt index 4c818063..846dde1b 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt @@ -113,12 +113,12 @@ open class Widget(classes: Set<String> = setOf()) : KVObject { } protected open fun getSnOn(): com.github.snabbdom.On? { - if (listeners.size > 0) { + return if (listeners.size > 0) { val handlers = on(this) listeners.forEach { l -> (handlers::apply)(l) } - return handlers + handlers } else { - return null + null } } @@ -217,7 +217,7 @@ open class Widget(classes: Set<String> = setOf()) : KVObject { protected open fun createLabelWithIcon(label: String, icon: String? = null, image: ResString? = null): Array<out Any> { return if (icon != null) { - if (icon.startsWith("fa-") == true) { + if (icon.startsWith("fa-")) { arrayOf(KVManager.virtualize("<i class='fa $icon fa-lg'></i>"), " " + label) } else { arrayOf(KVManager.virtualize("<span class='glyphicon glyphicon-$icon'></span>"), " " + label) diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt index 780cc4e3..b145f721 100644 --- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt @@ -1,7 +1,6 @@ package pl.treksoft.kvision.dropdown import com.github.snabbdom.VNode -import org.w3c.dom.CustomEvent import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.ResString import pl.treksoft.kvision.core.Widget @@ -32,7 +31,7 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri set(value) { button.text = value } - var elements = elements + private var elements = elements set(value) { field = elements setChildrenFromElements() @@ -67,7 +66,7 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri set(value) { button.image = value } - var dropup = dropup + private var dropup = dropup set(value) { field = value refresh() @@ -197,7 +196,7 @@ open class DropDownListTag(private val ariaId: String, classes: Set<String> = se } @Suppress("UnsafeCastFromDynamic") - internal fun showInternal() { + private fun showInternal() { if (getElementJQueryD()?.`is`(":hidden")) { getElementJQueryD()?.dropdown("toggle") } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Image.kt b/src/main/kotlin/pl/treksoft/kvision/html/Image.kt index a03d673a..c9566531 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Image.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Image.kt @@ -14,27 +14,27 @@ enum class IMAGESHAPE(val className: String) { open class Image(src: ResString, alt: String? = null, responsive: Boolean = false, shape: IMAGESHAPE? = null, centered: Boolean = false, classes: Set<String> = setOf()) : Widget(classes) { - var src = src + private var src = src set(value) { field = value refresh() } - var alt = alt + private var alt = alt set(value) { field = value refresh() } - var responsive = responsive + private var responsive = responsive set(value) { field = value refresh() } - var shape = shape + private var shape = shape set(value) { field = value refresh() } - var centered = centered + private var centered = centered set(value) { field = value refresh() diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt index 4f333482..dc93d0e7 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt @@ -7,22 +7,22 @@ import pl.treksoft.kvision.snabbdom.StringPair open class Link(label: String, url: String, icon: String? = null, image: ResString? = null, classes: Set<String> = setOf()) : Container(classes) { - var label = label + private var label = label set(value) { field = value refresh() } - var url = url + private var url = url set(value) { field = value refresh() } - var icon = icon + private var icon = icon set(value) { field = value refresh() } - var image = image + private var image = image set(value) { field = value refresh() diff --git a/src/main/kotlin/pl/treksoft/kvision/html/List.kt b/src/main/kotlin/pl/treksoft/kvision/html/List.kt index 24978f8d..c6298ddf 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/List.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/List.kt @@ -22,12 +22,12 @@ open class ListTag(type: LIST, elements: List<String>? = null, rich: Boolean = f field = value refresh() } - var elements = elements + private var elements = elements set(value) { field = value refresh() } - var rich = rich + private var rich = rich set(value) { field = value refresh() @@ -40,10 +40,10 @@ open class ListTag(type: LIST, elements: List<String>? = null, rich: Boolean = f element(if (index % 2 == 0) "dt" else "dd", el, rich) } }?.toTypedArray() - if (childrenElements != null) { - return kvh(type.tagName, childrenElements + childrenVNodes()) + return if (childrenElements != null) { + kvh(type.tagName, childrenElements + childrenVNodes()) } else { - return kvh(type.tagName, childrenVNodes()) + kvh(type.tagName, childrenVNodes()) } } @@ -69,21 +69,20 @@ open class ListTag(type: LIST, elements: List<String>? = null, rich: Boolean = f } private fun element(name: String, value: String, rich: Boolean): VNode { - if (rich) { - return h(name, arrayOf(KVManager.virtualize("<span>$value</span>"))) + return if (rich) { + h(name, arrayOf(KVManager.virtualize("<span>$value</span>"))) } else { - return h(name, value) + h(name, value) } } override fun getSnClass(): List<StringBoolPair> { val cl = super.getSnClass().toMutableList() - if (type == LIST.UNSTYLED) { - cl.add("list-unstyled" to true) - } else if (type == LIST.INLINE) { - cl.add("list-inline" to true) - } else if (type == LIST.DL_HORIZ) { - cl.add("dl-horizontal" to true) + @Suppress("NON_EXHAUSTIVE_WHEN") + when (type) { + LIST.UNSTYLED -> cl.add("list-unstyled" to true) + LIST.INLINE -> cl.add("list-inline" to true) + LIST.DL_HORIZ -> cl.add("dl-horizontal" to true) } return cl } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt index 109e5509..cb8330ac 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt @@ -73,7 +73,7 @@ open class Tag(type: TAG, text: String? = null, rich: Boolean = false, align: AL } override fun render(): VNode { - val ret = if (text != null) { + return if (text != null) { if (rich) { kvh(type.tagName, arrayOf(KVManager.virtualize("<span>$text</span>")) + childrenVNodes()) } else { @@ -82,7 +82,6 @@ open class Tag(type: TAG, text: String? = null, rich: Boolean = false, align: AL } else { kvh(type.tagName, childrenVNodes()) } - return ret } override fun getSnClass(): List<StringBoolPair> { diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt index a7820b30..c04449c2 100644 --- a/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt +++ b/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt @@ -26,7 +26,7 @@ open class Alert(caption: String? = null, text: String? = null, rich: Boolean = content.align = value } - val content = Tag(TAG.SPAN, text, rich, align) + private val content = Tag(TAG.SPAN, text, rich, align) init { body.add(content) diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt index 366eec52..aa4e8b88 100644 --- a/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt +++ b/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt @@ -26,14 +26,14 @@ open class Confirm(caption: String? = null, text: String? = null, rich: Boolean set(value) { content.align = value } - var cancelVisible = cancelVisible + private var cancelVisible = cancelVisible set(value) { field = value refreshCancelButton() } - val content = Tag(TAG.SPAN, text, rich, align) - val cancelButton = Button("Cancel", "remove") + private val content = Tag(TAG.SPAN, text, rich, align) + private val cancelButton = Button("Cancel", "remove") init { body.add(content) diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt index c587e977..564a9f6f 100644 --- a/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt +++ b/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt @@ -1,7 +1,6 @@ package pl.treksoft.kvision.modal import com.github.snabbdom.VNode -import org.w3c.dom.CustomEvent import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.Root import pl.treksoft.kvision.core.Widget @@ -20,15 +19,15 @@ enum class MODALSIZE(val className: String) { @Suppress("TooManyFunctions") open class Modal(caption: String? = null, closeButton: Boolean = true, - size: MODALSIZE? = null, animation: Boolean = true, val escape: Boolean = true, + size: MODALSIZE? = null, animation: Boolean = true, private val escape: Boolean = true, classes: Set<String> = setOf()) : Container(classes) { - var caption + private var caption get() = captionTag.text set(value) { captionTag.text = value checkHeaderVisibility() } - var closeButton + private var closeButton get() = closeIcon.visible set(value) { closeIcon.visible = value @@ -39,18 +38,18 @@ open class Modal(caption: String? = null, closeButton: Boolean = true, set(value) { dialog.size = value } - var animation = animation + private var animation = animation set(value) { field = value refresh() } - protected val dialog = ModalDialog(size) - protected val header = Container(setOf("modal-header")) + private val dialog = ModalDialog(size) + private val header = Container(setOf("modal-header")) protected val closeIcon = CloseIcon() - protected val captionTag = Tag(TAG.H4, caption, classes = setOf("modal-title")) + private val captionTag = Tag(TAG.H4, caption, classes = setOf("modal-title")) protected val body = Container(setOf("modal-body")) - protected val footer = Container(setOf("modal-footer")) + private val footer = Container(setOf("modal-footer")) init { this.hide() @@ -73,6 +72,7 @@ open class Modal(caption: String? = null, closeButton: Boolean = true, content.add(footer) val root = Root.getLastRoot() if (root != null) { + @Suppress("LeakingThis") root.addModal(this) } else { println("At least one Root object is required to create a modal!") diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt index be51149e..57519833 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt @@ -13,10 +13,11 @@ enum class DIRECTION(val dir: String) { VERTICAL("vertical") } -open class SplitPanel(val direction: DIRECTION = DIRECTION.VERTICAL, +open class SplitPanel(private val direction: DIRECTION = DIRECTION.VERTICAL, classes: Set<String> = setOf()) : Container(classes + ("splitpanel-" + direction.dir)) { - internal val splitter = Splitter(this, direction) + @Suppress("LeakingThis") + private val splitter = Splitter(this, direction) @Suppress("UnsafeCastFromDynamic") internal fun afterInsertSplitter() { @@ -54,7 +55,7 @@ open class SplitPanel(val direction: DIRECTION = DIRECTION.VERTICAL, } } -class Splitter(val splitPanel: SplitPanel, direction: DIRECTION) : Tag(TAG.DIV, +class Splitter(private val splitPanel: SplitPanel, direction: DIRECTION) : Tag(TAG.DIV, classes = setOf("splitter-" + direction.dir)) { private val idc = "kv_splitter_" + counter diff --git a/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt b/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt index dc6877a1..f1a79a76 100644 --- a/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt +++ b/src/main/kotlin/pl/treksoft/kvision/snabbdom/Types.kt @@ -21,6 +21,7 @@ fun obj(init: dynamic.() -> Unit): dynamic { @Suppress("UnsafeCastFromDynamic") private fun vNodeData(): VNodeData = js("({})") +@Suppress("UnsafeCastFromDynamic") class KvEvent(type: String, eventInitDict: CustomEventInit) : CustomEvent(type, eventInitDict) { override val detail: JQueryEventObject = obj({}) } diff --git a/src/main/kotlin/pl/treksoft/kvision/tabs/Tabs.kt b/src/main/kotlin/pl/treksoft/kvision/tabs/Tabs.kt index 4bc4d4b6..b21b1713 100644 --- a/src/main/kotlin/pl/treksoft/kvision/tabs/Tabs.kt +++ b/src/main/kotlin/pl/treksoft/kvision/tabs/Tabs.kt @@ -9,9 +9,9 @@ import pl.treksoft.kvision.html.Tag import pl.treksoft.kvision.panel.StackPanel open class Tabs : Container(setOf()) { - internal var nav = Tag(TAG.UL, classes = setOf("nav", "nav-tabs")) - internal var content = StackPanel(false) - var activeIndex + private var nav = Tag(TAG.UL, classes = setOf("nav", "nav-tabs")) + private var content = StackPanel(false) + private var activeIndex get() = content.activeIndex set(value) { content.activeIndex = value |