From 5a9930161b32d021977b848f2dabfe48dcc77654 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Tue, 27 Jul 2021 09:53:06 +0700 Subject: [PATCH] Task: Fixed server routes loop and add server layout for vaadin flow backend from java code design and rename theme name to fusion and updated the views and add mock users for show data grid and fixed all views --- frontend/routes.ts | 26 +++++++++++------ .../main-layout.css | 0 .../{fusionmanagement => fusion}/styles.css | 0 .../{fusionmanagement => fusion}/theme.json | 0 .../views/admin-view.css | 0 .../views/home-view.css | 0 .../views/profile-view.css | 0 frontend/views/server-layout.ts | 10 +++++++ .../kotlin/com/cubetiqs/fusion/Application.kt | 8 ++--- .../fusion/frontend/views/test/TestView.kt | 9 ++++-- .../fusion/frontend/views/user/UserView.kt | 29 +++++++++++++++++++ src/main/resources/application-dev.yml | 2 ++ src/main/resources/application.yml | 5 ++-- 13 files changed, 71 insertions(+), 18 deletions(-) rename frontend/themes/{fusionmanagement => fusion}/main-layout.css (100%) rename frontend/themes/{fusionmanagement => fusion}/styles.css (100%) rename frontend/themes/{fusionmanagement => fusion}/theme.json (100%) rename frontend/themes/{fusionmanagement => fusion}/views/admin-view.css (100%) rename frontend/themes/{fusionmanagement => fusion}/views/home-view.css (100%) rename frontend/themes/{fusionmanagement => fusion}/views/profile-view.css (100%) create mode 100644 frontend/views/server-layout.ts create mode 100644 src/main/kotlin/com/cubetiqs/fusion/frontend/views/user/UserView.kt create mode 100644 src/main/resources/application-dev.yml diff --git a/frontend/routes.ts b/frontend/routes.ts index 540a278..733f922 100644 --- a/frontend/routes.ts +++ b/frontend/routes.ts @@ -9,6 +9,9 @@ const { serverSideRoutes } = new Flow({ imports: () => import('../target/frontend/generated-flow-imports'), }); + +console.log("serverSideRoutes", serverSideRoutes) + export type ViewRoute = Route & { title?: string; icon?: string; @@ -67,15 +70,6 @@ export const views: ViewRoute[] = [ }, ]; export const routes: ViewRoute[] = [ - { - path: '', - component: 'main-layout', - children: [ - ...views, - // for server-side, the next magic line sends all unmatched routes: - ...serverSideRoutes, // IMPORTANT: this must be the last entry in the array - ], - }, { path: 'login', component: 'login-view', @@ -86,4 +80,18 @@ export const routes: ViewRoute[] = [ return; }, }, + { + path: '', + component: 'main-layout', + children: [ + ...views, + ], + }, + { + path: '', + component: 'server-layout', + children: [ + ...serverSideRoutes, + ] + } ]; diff --git a/frontend/themes/fusionmanagement/main-layout.css b/frontend/themes/fusion/main-layout.css similarity index 100% rename from frontend/themes/fusionmanagement/main-layout.css rename to frontend/themes/fusion/main-layout.css diff --git a/frontend/themes/fusionmanagement/styles.css b/frontend/themes/fusion/styles.css similarity index 100% rename from frontend/themes/fusionmanagement/styles.css rename to frontend/themes/fusion/styles.css diff --git a/frontend/themes/fusionmanagement/theme.json b/frontend/themes/fusion/theme.json similarity index 100% rename from frontend/themes/fusionmanagement/theme.json rename to frontend/themes/fusion/theme.json diff --git a/frontend/themes/fusionmanagement/views/admin-view.css b/frontend/themes/fusion/views/admin-view.css similarity index 100% rename from frontend/themes/fusionmanagement/views/admin-view.css rename to frontend/themes/fusion/views/admin-view.css diff --git a/frontend/themes/fusionmanagement/views/home-view.css b/frontend/themes/fusion/views/home-view.css similarity index 100% rename from frontend/themes/fusionmanagement/views/home-view.css rename to frontend/themes/fusion/views/home-view.css diff --git a/frontend/themes/fusionmanagement/views/profile-view.css b/frontend/themes/fusion/views/profile-view.css similarity index 100% rename from frontend/themes/fusionmanagement/views/profile-view.css rename to frontend/themes/fusion/views/profile-view.css diff --git a/frontend/views/server-layout.ts b/frontend/views/server-layout.ts new file mode 100644 index 0000000..a3cefa8 --- /dev/null +++ b/frontend/views/server-layout.ts @@ -0,0 +1,10 @@ +import { html } from 'lit'; +import { customElement } from 'lit/decorators.js'; +import {Layout} from "./view"; + +@customElement('server-layout') +export class AdminView extends Layout { + render() { + return html`<>`; + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/cubetiqs/fusion/Application.kt b/src/main/kotlin/com/cubetiqs/fusion/Application.kt index 4d1bcb3..ef872d7 100644 --- a/src/main/kotlin/com/cubetiqs/fusion/Application.kt +++ b/src/main/kotlin/com/cubetiqs/fusion/Application.kt @@ -4,13 +4,13 @@ import com.vaadin.flow.component.dependency.NpmPackage import com.vaadin.flow.component.page.AppShellConfigurator import com.vaadin.flow.server.PWA import com.vaadin.flow.theme.Theme -import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication import org.springframework.boot.web.servlet.support.SpringBootServletInitializer @SpringBootApplication -@Theme(value = "fusionmanagement") -@PWA(name = "Fusion Management", shortName = "Fusion Management", offlineResources = ["images/logo.png"]) +@Theme(value = "fusion") +@PWA(name = "CUBETIQ Fusion", shortName = "Fusion", offlineResources = ["images/logo.png"]) @NpmPackage.Container( NpmPackage(value = "@fontsource/roboto", version = "4.5.0"), NpmPackage(value = "@adobe/lit-mobx", version = "2.0.0-rc.4"), @@ -20,5 +20,5 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer class Application : SpringBootServletInitializer(), AppShellConfigurator fun main(args: Array) { - SpringApplication.run(Application::class.java, *args) + runApplication(*args) } \ No newline at end of file diff --git a/src/main/kotlin/com/cubetiqs/fusion/frontend/views/test/TestView.kt b/src/main/kotlin/com/cubetiqs/fusion/frontend/views/test/TestView.kt index dc22355..d4fd8c0 100644 --- a/src/main/kotlin/com/cubetiqs/fusion/frontend/views/test/TestView.kt +++ b/src/main/kotlin/com/cubetiqs/fusion/frontend/views/test/TestView.kt @@ -1,11 +1,16 @@ package com.cubetiqs.fusion.frontend.views.test +import com.vaadin.flow.component.button.Button import com.vaadin.flow.component.html.Div import com.vaadin.flow.router.Route +import com.vaadin.flow.server.auth.AnonymousAllowed -@Route("/views/test") +@Route("/test") +@AnonymousAllowed class TestView : Div() { init { - add("Hello World") + add( + Button("Hello World") + ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/cubetiqs/fusion/frontend/views/user/UserView.kt b/src/main/kotlin/com/cubetiqs/fusion/frontend/views/user/UserView.kt new file mode 100644 index 0000000..79feb4d --- /dev/null +++ b/src/main/kotlin/com/cubetiqs/fusion/frontend/views/user/UserView.kt @@ -0,0 +1,29 @@ +package com.cubetiqs.fusion.frontend.views.user + +import com.vaadin.flow.component.grid.Grid +import com.vaadin.flow.component.html.Div +import com.vaadin.flow.router.PageTitle +import com.vaadin.flow.router.Route +import com.vaadin.flow.server.auth.AnonymousAllowed + +@Route("/users") +@PageTitle("All Users") +@AnonymousAllowed +class UserView : Div() { + private fun generateUsers(): Collection { + val users = mutableListOf() + for (i in 1..1000000) { + users.add(User(i, "user-${"$i".padStart(6, '0')}", "MY USER - $i", "$i".padEnd(9, '0'))) + } + + return users + } + + init { + val grid = Grid(User::class.java) + grid.setItems(generateUsers()) + add(grid) + } + + data class User(val id: Int, val username: String, val name: String, val phone: String) +} \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..54b155f --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,2 @@ +server: + port: 8081 \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 50c332d..48c6c9b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,12 +1,11 @@ -server: - port: ${PORT:8080} - logging: level: org: atmosphere: warn spring: + profiles: + active: ${APP_PROFILE:dev} mustache: check-template-location: false