Skip to content

Commit

Permalink
Add dev-ui and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed May 22, 2024
1 parent a72af3d commit d8dc28e
Show file tree
Hide file tree
Showing 19 changed files with 391 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@

import jakarta.inject.Singleton;

import io.quarkiverse.statiq.runtime.FixedStaticPagesProvider;
import io.quarkiverse.statiq.runtime.StatiqGenerator;
import io.quarkiverse.statiq.runtime.StatiqGeneratorConfig;
import io.quarkiverse.statiq.runtime.StatiqRecorder;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import io.quarkus.vertx.http.deployment.VertxWebRouterBuildItem;
import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem;
import io.quarkus.vertx.http.runtime.VertxHttpRecorder;
import io.quarkus.vertx.http.deployment.spi.StaticResourcesBuildItem;

class StatiqProcessor {

Expand All @@ -45,32 +46,38 @@ SyntheticBeanBuildItem produceGeneratorConfig(StatiqConfig config, OutputTargetB
}

@BuildStep
AdditionalBeanBuildItem produceStatiqGenerator() {
return AdditionalBeanBuildItem.unremovableOf(StatiqGenerator.class);
void produceBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeanProducer) {
additionalBeanProducer.produce(AdditionalBeanBuildItem.unremovableOf(StatiqGenerator.class));
additionalBeanProducer.produce(AdditionalBeanBuildItem.unremovableOf(FixedStaticPagesProvider.class));
}

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
void initHandler(
VertxWebRouterBuildItem router,
void initHandler(List<NotFoundPageDisplayableEndpointBuildItem> notFoundPageDisplayableEndpoints,
StaticResourcesBuildItem staticResourcesBuildItem,
StatiqRecorder recorder) {

Set<String> staticPaths = new HashSet<>(staticResourcesBuildItem.getPaths());
staticPaths.addAll(notFoundPageDisplayableEndpoints.stream()
.filter(not(NotFoundPageDisplayableEndpointBuildItem::isAbsolutePath))
.map(NotFoundPageDisplayableEndpointBuildItem::getEndpoint)
.toList());
recorder.setStatiqPages(staticPaths);
}

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
void initHandler(BuildProducer<RouteBuildItem> routes,
NonApplicationRootPathBuildItem nonApplicationRootPath,
List<NotFoundPageDisplayableEndpointBuildItem> notFoundPageDisplayableEndpoints,
StatiqRecorder recorder,
VertxHttpRecorder vertxHttpRecorder) {
StatiqRecorder recorder) {

final RouteBuildItem route = nonApplicationRootPath.routeBuilder()
.management()
.route("statiq/generate")
.handler(recorder.createGenerateHandler(notFoundPageDisplayableEndpoints.stream()
.filter(not(NotFoundPageDisplayableEndpointBuildItem::isAbsolutePath))
.map(NotFoundPageDisplayableEndpointBuildItem::getEndpoint)
.toList()))
.handler(recorder.createGenerateHandler())
.build();
// Can't use RouteBuildItem because of cycles
if (router.getFrameworkRouter() != null) {
vertxHttpRecorder.addRoute(router.getFrameworkRouter(), route.getRouteFunction(), route.getHandler(),
route.getType());
}

routes.produce(route);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkiverse.statiq.deployment.devui;

import io.quarkiverse.statiq.runtime.devui.StatiqJsonRPCService;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;

public class StatiqDevUIProcessor {
@BuildStep(onlyIf = IsDevelopment.class)
CardPageBuildItem create(CurateOutcomeBuildItem bi) {
CardPageBuildItem pageBuildItem = new CardPageBuildItem();
pageBuildItem.addPage(Page.webComponentPageBuilder()
.title("Pages")
.componentLink("qwc-statiq.js")
.icon("font-awesome-solid:link"));

return pageBuildItem;
}

@BuildStep(onlyIf = IsDevelopment.class)
JsonRPCProvidersBuildItem createJsonRPCServiceForCache() {
return new JsonRPCProvidersBuildItem(StatiqJsonRPCService.class);
}

}
117 changes: 117 additions & 0 deletions deployment/src/main/resources/dev-ui/qwc-statiq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { LitElement, html, css} from 'lit';
import { JsonRpc } from 'jsonrpc';
import '@vaadin/icon';
import '@vaadin/button';
import '@vaadin/text-field';
import '@vaadin/text-area';
import '@vaadin/form-layout';
import '@vaadin/progress-bar';
import '@vaadin/checkbox';
import '@vaadin/grid';
import { columnBodyRenderer } from '@vaadin/grid/lit.js';
import '@vaadin/grid/vaadin-grid-sort-column.js';

export class QwcStatiq extends LitElement {

jsonRpc = new JsonRpc(this);

// Component style
static styles = css`
.button {
background-color: transparent;
cursor: pointer;
}
.clearIcon {
color: orange;
}
`;

// Component properties
static properties = {
"_pages": {state: true},
}

constructor() {
super();
}

// Components callbacks

/**
* Called when displayed
*/
connectedCallback() {
super.connectedCallback();
this.jsonRpc.getPages().then(jsonRpcResponse => {
this._pages = [];
jsonRpcResponse.result.forEach(c => {
this._pages.push(c);
});
});
}

/**
* Called when it needs to render the components
* @returns {*}
*/
render() {
if (this._pages) {
return this._renderTable();
} else {
return html`<span>Loading pages...</span>`;
}
}

// View / Templates

_renderTable() {
return html`
<div class="menubar">
<a href="/q/statiq/generate" target="_blank">
<vaadin-button id="start-cnt-testing-btn" theme="tertiary" tabindex="0" role="button">
<vaadin-icon icon="font-awesome-solid:play"></vaadin-icon>
Generate
</vaadin-button>
</a>
</div>
<vaadin-grid .items="${this._pages}" class="datatable" theme="no-border">
<vaadin-grid-column auto-width
header="Path"
flex-grow="1"
${columnBodyRenderer(this._pathRenderer, [])}>
</vaadin-grid-column>
<vaadin-grid-column auto-width
header="File"
flex-grow="1"
${columnBodyRenderer(this._fileRenderer, [])}>
</vaadin-grid-column>
<vaadin-grid-column path="type" flex-grow="0" width="12em"></vaadin-grid-column>
<vaadin-grid-column header="Link"
width="6em"
flex-grow="0"
${columnBodyRenderer(this._linkRenderer, [])}>
</vaadin-grid-column>
</vaadin-grid>
`;
}

_fileRenderer(page) {
return html`${page.outputPath}`;
}

_pathRenderer(page) {
return html`${page.path}`;
}

_linkRenderer(page) {
return html`<a href="${page.path}" style="color: white" target="_blank"><vaadin-icon class="linkOut"
icon="font-awesome-solid:up-right-from-square"/></a>`;
}



}
customElements.define('qwc-statiq', QwcStatiq);
12 changes: 11 additions & 1 deletion integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.web-bundler</groupId>
<artifactId>quarkus-web-bundler</artifactId>
<version>999-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.qute.web</groupId>
<artifactId>quarkus-qute-web</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.statiq</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.quarkiverse.statiq.it;

import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Singleton;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;

import io.quarkiverse.statiq.runtime.StatiqPage;
import io.quarkiverse.statiq.runtime.StatiqPages;

@Path("/statiq")
@ApplicationScoped
public class StatiqResource {
// add some rest methods here

@GET
public String hello() {
return "Hello statiq";
@Produces(MediaType.TEXT_PLAIN)
public String hello(@QueryParam("name") String name) {
return "Hello " + name;
}

@Produces
@Singleton
@Transactional
StatiqPages produce() {
return new StatiqPages(List.of(
new StatiqPage("/statiq?name=foo"),
new StatiqPage("/statiq?name=bar")));
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.statiq.fixed=/,/static/**,/assets/**,/some-page
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Hello</h1>
<img src="/static/logo.svg" />
2 changes: 2 additions & 0 deletions integration-tests/src/main/resources/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Hello</h1>
<img src="assets/vector.svg" />
1 change: 1 addition & 0 deletions integration-tests/src/main/resources/web/static/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d8dc28e

Please sign in to comment.