Skip to content

Commit

Permalink
Dev UI Move info to menu item and format page for known items
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Apr 18, 2023
1 parent e6d8ca3 commit d480ef8
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@

import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.MenuPageBuildItem;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.info.runtime.InfoRecorder;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
import io.quarkus.vertx.http.runtime.management.ManagementInterfaceBuildTimeConfig;

/**
* This processor is responsible for the dev ui widget.
*/
public class InfoDevUiProcessor {
public class InfoDevUIProcessor {

@BuildStep(onlyIf = IsDevelopment.class)
@Record(ExecutionTime.STATIC_INIT)
CardPageBuildItem create(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
MenuPageBuildItem create(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
InfoBuildTimeConfig config,
ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig,
LaunchModeBuildItem launchModeBuildItem,
InfoRecorder unused) {
CardPageBuildItem pageBuildItem = new CardPageBuildItem();
LaunchModeBuildItem launchModeBuildItem) {
MenuPageBuildItem pageBuildItem = new MenuPageBuildItem();

var path = nonApplicationRootPathBuildItem.resolveManagementPath(config.path(),
managementInterfaceBuildTimeConfig, launchModeBuildItem);
pageBuildItem.addPage(Page.externalPageBuilder("App Information")

pageBuildItem.addBuildTimeData("infoUrl", path);

pageBuildItem.addPage(Page.webComponentPageBuilder()
.title("Information")
.icon("font-awesome-solid:circle-info")
.componentLink("qwc-info.js"));
pageBuildItem.addPage(Page.externalPageBuilder("Raw")
.url(path)
.icon("font-awesome-solid:circle-info")
.isJsonContent());

return pageBuildItem;
Expand Down
149 changes: 149 additions & 0 deletions extensions/info/deployment/src/main/resources/dev-ui/qwc-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { LitElement, html, css} from 'lit';
import { columnBodyRenderer } from '@vaadin/grid/lit.js';
import { infoUrl } from 'build-time-data';
import '@vaadin/progress-bar';
import 'qui-card';
import '@vaadin/icon';

/**
* This component shows the Info Screen
*/
export class QwcInfo extends LitElement {

static styles = css`
:host {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(450px, 1fr));
gap: 1em;
padding: 10px;
}
qui-card {
display: flex;
}
.cardContent {
display: flex;
align-items: center;
padding: 10px;
gap: 10px;
}
vaadin-icon {
font-size: xx-large;
}
`;

static properties = {
_infoUrl: {state: false},
_info: {state: true},
};

constructor() {
super();
this._infoUrl = infoUrl;
this._info = null;
}

async connectedCallback() {
super.connectedCallback();
await this.load();
}

async load() {
const response = await fetch(this._infoUrl)
const data = await response.json();
this._info = data;
}

render() {
if (this._info) {
return html`
${this._renderOsInfo(this._info)}
${this._renderJavaInfo(this._info)}
${this._renderGitInfo(this._info)}
${this._renderBuildInfo(this._info)}
`;
}else{
return html`
<div style="color: var(--lumo-secondary-text-color);width: 95%;" >
<div>Fetching infomation...</div>
<vaadin-progress-bar indeterminate></vaadin-progress-bar>
</div>
`;
}
}

_renderOsInfo(info){
if(info.os){
let os = info.os;
return html`<qui-card title="Operating System">
<div class="cardContent" slot="content">
${this._renderOsIcon(os.name)}
<table class="table">
<tr><td>Name</td><td>${os.name}</td></tr>
<tr><td>Version</td><td>${os.version}</td></tr>
<tr><td>Arch</td><td>${os.arch}</td></tr>
</table>
</div>
</qui-card>`;
}
}

_renderJavaInfo(info){
if(info.java){
let java = info.java;
return html`<qui-card title="Java">
<div class="cardContent" slot="content">
<vaadin-icon icon="font-awesome-brands:java"></vaadin-icon>
<table class="table">
<tr><td>Version</td><td>${java.version}</td></tr>
</table>
</div>
</qui-card>`;
}
}

_renderOsIcon(osname){

if(osname){
if(osname.toLowerCase().startsWith("linux")){
return html`<vaadin-icon icon="font-awesome-brands:linux"></vaadin-icon>`;
}else if(osname.toLowerCase().startsWith("mac") || osname.toLowerCase().startsWith("darwin")){
return html`<vaadin-icon icon="font-awesome-brands:apple"></vaadin-icon>`;
}else if(osname.toLowerCase().startsWith("win")){
return html`<vaadin-icon icon="font-awesome-brands:windows"></vaadin-icon>`;
}
}
}

_renderGitInfo(info){
if(info.git){
let git = info.git;
return html`<qui-card title="Git">
<div class="cardContent" slot="content">
<vaadin-icon icon="font-awesome-brands:git"></vaadin-icon>
<table class="table">
<tr><td>Branch</td><td>${git.branch}</td></tr>
<tr><td>Commit</td><td>${git.commit.id}</td></tr>
<tr><td>Time</td><td>${git.commit.time}</td></tr>
</table>
</div>
</qui-card>`;
}
}

_renderBuildInfo(info){
if(info.build){
let build = info.build;
return html`<qui-card title="Build">
<div class="cardContent" slot="content">
<table class="table">
<tr><td>Group</td><td>${build.group}</td></tr>
<tr><td>Artifact</td><td>${build.artifact}</td></tr>
<tr><td>Version</td><td>${build.version}</td></tr>
<tr><td>Time</td><td>${build.time}</td></tr>
</table>
</div>
</qui-card>`;
}
}
}
customElements.define('qwc-info', QwcInfo);
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import io.quarkus.devui.spi.DevUIContent;
import io.quarkus.devui.spi.buildtime.QuteTemplateBuildItem;
import io.quarkus.devui.spi.buildtime.StaticContentBuildItem;
import io.quarkus.devui.spi.page.AbstractPageBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.FooterPageBuildItem;
import io.quarkus.devui.spi.page.MenuPageBuildItem;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.devui.spi.page.PageBuilder;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
Expand Down Expand Up @@ -67,6 +70,8 @@ InternalImportMapBuildItem createKnownInternalImportMap(NonApplicationRootPathBu
internalImportMapBuildItem.add("qwc-server-log", contextRoot + "qwc/qwc-server-log.js");
// Quarkus UI
internalImportMapBuildItem.add("qui/", contextRoot + "qui/");
internalImportMapBuildItem.add("qui-card", contextRoot + "qui/qui-card.js");

internalImportMapBuildItem.add("qui-badge", contextRoot + "qui/qui-badge.js");
internalImportMapBuildItem.add("qui-alert", contextRoot + "qui/qui-alert.js");
// Echarts
Expand Down Expand Up @@ -101,26 +106,49 @@ InternalImportMapBuildItem createKnownInternalImportMap(NonApplicationRootPathBu
* @param buildTimeConstProducer
*/
@BuildStep(onlyIf = IsDevelopment.class)
void mapPageBuildTimeData(List<CardPageBuildItem> pageBuildItems,
void mapPageBuildTimeData(List<CardPageBuildItem> cards,
List<MenuPageBuildItem> menus,
List<FooterPageBuildItem> footers,
CurateOutcomeBuildItem curateOutcomeBuildItem,
BuildProducer<BuildTimeConstBuildItem> buildTimeConstProducer) {

for (CardPageBuildItem pageBuildItem : pageBuildItems) {
String extensionPathName = pageBuildItem.getExtensionPathName(curateOutcomeBuildItem);
Map<String, Object> buildTimeData = getBuildTimeData(curateOutcomeBuildItem, pageBuildItem);
for (CardPageBuildItem card : cards) {
String extensionPathName = card.getExtensionPathName(curateOutcomeBuildItem);
Map<String, Object> buildTimeData = getBuildTimeDataForCard(curateOutcomeBuildItem, card);
if (!buildTimeData.isEmpty()) {
buildTimeConstProducer.produce(
new BuildTimeConstBuildItem(extensionPathName, buildTimeData));
}
}
for (MenuPageBuildItem menu : menus) {
String extensionPathName = menu.getExtensionPathName(curateOutcomeBuildItem);
Map<String, Object> buildTimeData = getBuildTimeDataForPage(menu);
if (!buildTimeData.isEmpty()) {
buildTimeConstProducer.produce(
new BuildTimeConstBuildItem(extensionPathName, buildTimeData));
}
}
for (FooterPageBuildItem footer : footers) {
String extensionPathName = footer.getExtensionPathName(curateOutcomeBuildItem);
Map<String, Object> buildTimeData = getBuildTimeDataForPage(footer);
if (!buildTimeData.isEmpty()) {
buildTimeConstProducer.produce(
new BuildTimeConstBuildItem(extensionPathName, buildTimeData));
}
}
}

private Map<String, Object> getBuildTimeData(CurateOutcomeBuildItem curateOutcomeBuildItem,
CardPageBuildItem pageBuildItem) {
private Map<String, Object> getBuildTimeDataForPage(AbstractPageBuildItem pageBuildItem) {
Map<String, Object> m = new HashMap<>();
if (pageBuildItem.hasBuildTimeData()) {
m.putAll(pageBuildItem.getBuildTimeData());
}
return m;
}

private Map<String, Object> getBuildTimeDataForCard(CurateOutcomeBuildItem curateOutcomeBuildItem,
CardPageBuildItem pageBuildItem) {
Map<String, Object> m = getBuildTimeDataForPage(pageBuildItem);

if (pageBuildItem.getOptionalCard().isPresent()) {
// Make the pages available for the custom card
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { LitElement, html, css} from 'lit';

/**
* Card UI Component
*/
export class QuiCard extends LitElement {

static styles = css`
.card {
display: flex;
flex-direction: column;
justify-content: space-between;
border: 1px solid var(--lumo-contrast-10pct);
border-radius: 4px;
filter: brightness(90%);
}
.card-header {
font-size: var(--lumo-font-size-l);
line-height: 1;
height: 25px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 10px 10px;
background-color: var(--lumo-contrast-5pct);
border-bottom: 1px solid var(--lumo-contrast-10pct);
}
.card-footer {
height: 20px;
padding: 10px 10px;
color: var(--lumo-contrast-50pct);
display: flex;
flex-direction: row;
justify-content: space-between;
visibility:hidden;
}`;

static properties = {
title: {type: String},
width: {state: true},
_hasFooter: {state: true},
};

constructor(){
super();
this.width = "100%";
this._hasFooter = false;
}

connectedCallback() {
super.connectedCallback()
}

render() {
return html`<div class="card" style="width: ${this.width};">
${this._headerTemplate()}
<slot name="content"></slot>
${this._footerTemplate()}
</div>`;
}

firstUpdated(){
const footerSlot = this.shadowRoot.querySelector("#footer");
if (footerSlot && footerSlot.assignedNodes().length>0){
console.log('No content is available')
this._hasFooter = true;
}
}

_headerTemplate() {
return html`<div class="card-header">
<div>${this.title}</div>
</div>
`;
}

_footerTemplate() {
if(this._hasFooter){
return html`
<div class="card-footer">
<slot id="footer" name="footer"></slot>
</div>
`;
}
}

}
customElements.define('qui-card', QuiCard);

0 comments on commit d480ef8

Please sign in to comment.