Search in sources :

Example 1 with J2HtmlTable

use of io.datarouter.web.html.j2html.J2HtmlTable in project datarouter by hotpads.

the class DatarouterSnapshotEntriesHandler method buildTable.

private DomContent buildTable(SnapshotKey snapshotKey, long offset, long limit) {
    SnapshotGroup group = groups.getGroup(snapshotKey.groupId);
    var reader = new ScanningSnapshotReader(snapshotKey, exec, 2, groups, 1);
    SnapshotRecordStringDecoder decoder = ReflectionTool.create(group.getSnapshotEntryDecoderClass());
    List<SnapshotRecordStrings> rows = reader.scan(0).skip(offset).limit(limit).map(decoder::decode).list();
    var table = new J2HtmlTable<SnapshotRecordStrings>().withClasses("sortable table table-sm table-striped my-4 border").withColumn("id", row -> row.id).withColumn(decoder.keyName(), row -> row.key).withColumn(decoder.valueName(), row -> {
        if (row.value == null) {
            return "";
        } else if (row.value.length() < 64) {
            return row.value;
        } else {
            return row.value.subSequence(0, 64) + "...";
        }
    }).withHtmlColumn("details", row -> {
        String href = new URIBuilder().setPath(request.getContextPath() + snapshotPaths.datarouter.snapshot.individual.entry.toSlashedString()).addParameter(DatarouterSnapshotEntryHandler.P_groupId, snapshotKey.groupId).addParameter(DatarouterSnapshotEntryHandler.P_snapshotId, snapshotKey.snapshotId).addParameter(DatarouterSnapshotEntryHandler.P_id, Long.toString(row.id)).toString();
        return td(a("view").withHref(href));
    }).build(rows);
    return table;
}
Also used : ScanningSnapshotReader(io.datarouter.filesystem.snapshot.reader.ScanningSnapshotReader) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) URIBuilder(org.apache.http.client.utils.URIBuilder) Mav(io.datarouter.web.handler.mav.Mav) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) ReflectionTool(io.datarouter.util.lang.ReflectionTool) TagCreator.a(j2html.TagCreator.a) DatarouterSnapshotWebExecutor(io.datarouter.filesystem.snapshot.web.DatarouterSnapshotExecutors.DatarouterSnapshotWebExecutor) OptionalLong(io.datarouter.web.handler.types.optional.OptionalLong) Inject(javax.inject.Inject) DomContent(j2html.tags.DomContent) List(java.util.List) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) ScanningSnapshotReader(io.datarouter.filesystem.snapshot.reader.ScanningSnapshotReader) SnapshotGroups(io.datarouter.filesystem.snapshot.group.SnapshotGroups) TagCreator.td(j2html.TagCreator.td) BaseHandler(io.datarouter.web.handler.BaseHandler) Bootstrap4PageFactory(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) Param(io.datarouter.web.handler.types.Param) TagCreator.div(j2html.TagCreator.div) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 2 with J2HtmlTable

use of io.datarouter.web.html.j2html.J2HtmlTable in project datarouter by hotpads.

the class DatarouterSnapshotEntryHandler method buildTable.

private ContainerTag<?> buildTable(SnapshotKey snapshotKey, long id) {
    SnapshotGroup group = groups.getGroup(snapshotKey.groupId);
    var reader = new SnapshotIdReader(snapshotKey, groups);
    SnapshotRecord record = reader.getRecord(id);
    SnapshotRecordStringDecoder decoder = ReflectionTool.create(group.getSnapshotEntryDecoderClass());
    SnapshotRecordStrings decoded = decoder.decode(record);
    List<Twin<String>> rows = new ArrayList<>();
    rows.add(new Twin<>("id", Long.toString(record.id)));
    rows.add(new Twin<>(decoder.keyName(), decoded.key));
    rows.add(new Twin<>(decoder.valueName(), decoded.value));
    IntStream.range(0, decoded.columnValues.size()).mapToObj(column -> new Twin<>(decoder.columnValueName(column), decoded.columnValues.get(column))).forEach(rows::add);
    var table = new J2HtmlTable<Twin<String>>().withClasses("sortable table table-sm table-striped my-4 border").withColumn("field", twin -> twin.getLeft()).withColumn("value", twin -> twin.getRight()).build(rows);
    return table;
}
Also used : IntStream(java.util.stream.IntStream) SnapshotRecord(io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord) Twin(io.datarouter.util.tuple.Twin) Mav(io.datarouter.web.handler.mav.Mav) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) ReflectionTool(io.datarouter.util.lang.ReflectionTool) ArrayList(java.util.ArrayList) ContainerTag(j2html.tags.ContainerTag) Inject(javax.inject.Inject) List(java.util.List) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) SnapshotGroups(io.datarouter.filesystem.snapshot.group.SnapshotGroups) BaseHandler(io.datarouter.web.handler.BaseHandler) Bootstrap4PageFactory(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) Param(io.datarouter.web.handler.types.Param) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) SnapshotIdReader(io.datarouter.filesystem.snapshot.reader.SnapshotIdReader) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) ArrayList(java.util.ArrayList) SnapshotRecord(io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord) SnapshotIdReader(io.datarouter.filesystem.snapshot.reader.SnapshotIdReader) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) Twin(io.datarouter.util.tuple.Twin)

Example 3 with J2HtmlTable

use of io.datarouter.web.html.j2html.J2HtmlTable in project datarouter by hotpads.

the class S3BucketHandler method index.

@Handler(defaultHandler = true)
public Mav index(@Param(P_client) String client, @Param(P_bucket) String bucket, @Param(P_prefix) OptionalString prefix, @Param(P_after) OptionalString after, @Param(P_offset) OptionalInteger offset, @Param(P_limit) OptionalInteger limit, @Param(P_currentDirectory) OptionalBoolean currentDirectory, @Param(P_delimiter) OptionalString delimiter) {
    var form = new HtmlForm().withMethod("get");
    form.addTextField().withDisplay("Client").withName(P_client).withPlaceholder("theClientName").withValue(client);
    form.addTextField().withDisplay("Bucket").withName(P_bucket).withPlaceholder("the.bucket.name").withValue(bucket);
    form.addTextField().withDisplay("Prefix").withName(P_prefix).withValue(prefix.orElse(""));
    form.addTextField().withDisplay("After").withName(P_after).withValue(after.orElse(""));
    form.addTextField().withDisplay("Offset").withName(P_offset).withValue(offset.orElse(0) + "");
    form.addTextField().withDisplay("Limit").withName(P_limit).withValue(limit.orElse(100) + "");
    form.addTextField().withDisplay("Delimiter").withName(P_delimiter).withValue(delimiter.orElse(""));
    form.addCheckboxField().withDisplay("currentDirectory").withName(P_currentDirectory).withChecked(currentDirectory.orElse(false));
    form.addButton().withDisplay("Submit").withValue("");
    var htmlForm = Bootstrap4FormHtml.render(form).withClass("card card-body bg-light");
    ClientId clientId = clients.getClientId(client);
    DatarouterS3Client s3Client = s3ClientManager.getClient(clientId);
    List<DirectoryDto> objects = s3Client.scanSubdirectories(bucket, prefix.orElse(null), after.orElse(null), delimiter.orElse(null), limit.orElse(100), currentDirectory.orElse(false)).list();
    int sizePadding = sizePadding(objects);
    ContainerTag<?> table = new J2HtmlTable<DirectoryDto>().withClasses("sortable table table-sm table-striped my-4 border").withHtmlColumn("Key", object -> {
        String name = object.name;
        if (object.isDirectory) {
            return td(makePrefixLink(client, bucket, name, "/"));
        }
        return td(name);
    }).withHtmlColumn("Directory", object -> {
        boolean isDirectory = object.isDirectory;
        if (isDirectory) {
            String href = new URIBuilder().setPath(request.getContextPath() + paths.datarouter.clients.awsS3.countObjects.toSlashedString()).addParameter(P_client, client).addParameter(P_bucket, bucket).addParameter(P_prefix, object.name).toString();
            return td(a("true, view count").withHref(href));
        }
        return td(String.valueOf(isDirectory));
    }).withHtmlColumn("Size", object -> {
        String commas = NumberFormatter.addCommas(object.size);
        String padded = StringTool.pad(commas, ' ', sizePadding);
        String escaped = padded.replaceAll(" ", "&nbsp;");
        return td(rawHtml(escaped));
    }).withColumn("Last Modified", object -> object.lastModified).withColumn("Storage Class", object -> object.storageClass).build(objects);
    ContainerTag<?> tableWrapper = table.withStyle("font-family:monospace; font-size:.9em;");
    var content = div(htmlForm, h4(bucket), tableWrapper).withClass("container-fluid my-4");
    return pageFactory.startBuilder(request).withTitle("S3 Bucket").withRequires(DatarouterWebRequireJsV2.SORTTABLE).withContent(content).buildMav();
}
Also used : Scanner(io.datarouter.scanner.Scanner) DatarouterS3Client(io.datarouter.aws.s3.DatarouterS3Client) LoggerFactory(org.slf4j.LoggerFactory) TagCreator.h4(j2html.TagCreator.h4) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) AtomicReference(java.util.concurrent.atomic.AtomicReference) S3ClientManager(io.datarouter.aws.s3.client.S3ClientManager) Inject(javax.inject.Inject) NumberFormatter(io.datarouter.util.number.NumberFormatter) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) ClientId(io.datarouter.storage.client.ClientId) Param(io.datarouter.web.handler.types.Param) Bootstrap4FormHtml(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4FormHtml) OptionalInteger(io.datarouter.web.handler.types.optional.OptionalInteger) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) DatarouterClients(io.datarouter.storage.client.DatarouterClients) TagCreator.rawHtml(j2html.TagCreator.rawHtml) Logger(org.slf4j.Logger) URIBuilder(org.apache.http.client.utils.URIBuilder) DatarouterAwsS3Paths(io.datarouter.aws.s3.config.DatarouterAwsS3Paths) Mav(io.datarouter.web.handler.mav.Mav) StringTool(io.datarouter.util.string.StringTool) TagCreator.a(j2html.TagCreator.a) ContainerTag(j2html.tags.ContainerTag) OptionalBoolean(io.datarouter.web.handler.types.optional.OptionalBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) DirectoryDto(io.datarouter.storage.node.op.raw.read.DirectoryDto) HtmlForm(io.datarouter.web.html.form.HtmlForm) TagCreator.td(j2html.TagCreator.td) BaseHandler(io.datarouter.web.handler.BaseHandler) Bootstrap4PageFactory(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory) Comparator(java.util.Comparator) TagCreator.div(j2html.TagCreator.div) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) URIBuilder(org.apache.http.client.utils.URIBuilder) DirectoryDto(io.datarouter.storage.node.op.raw.read.DirectoryDto) HtmlForm(io.datarouter.web.html.form.HtmlForm) DatarouterS3Client(io.datarouter.aws.s3.DatarouterS3Client) ClientId(io.datarouter.storage.client.ClientId) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 4 with J2HtmlTable

use of io.datarouter.web.html.j2html.J2HtmlTable in project datarouter by hotpads.

the class AwsMemcachedWebInspector method getDetails.

@Override
protected Pair<Integer, DivTag> getDetails(ClientId clientId) {
    MemcachedClientMode mode = options.getClientMode(clientId.getName());
    Pair<Integer, DivTag> nodeCountByNodeTag = new Pair<>();
    if (mode == MemcachedClientMode.DYNAMIC) {
        List<AwsMemcachedNodeEndpointDto> nodeEndpointDtos = Scanner.of(getSpyClient(clientId).getAllNodeEndPoints()).map(nodeEndPoint -> new AwsMemcachedNodeEndpointDto(nodeEndPoint.getHostName(), nodeEndPoint.getIpAddress(), nodeEndPoint.getPort())).list();
        var table = new J2HtmlTable<AwsMemcachedNodeEndpointDto>().withClasses("sortable table table-sm table-striped my-4 border").withColumn("HostName", dto -> dto.hostName).withColumn("IpAddress", dto -> dto.ipAddress).withColumn("Port", dto -> dto.port).build(nodeEndpointDtos);
        DivTag divTable = div(table).withClass("container-fluid my-4").withStyle("padding-left: 0px");
        nodeCountByNodeTag.setLeft(nodeEndpointDtos.size());
        nodeCountByNodeTag.setRight(divTable);
    } else {
        List<LiTag> socketAddresses = Scanner.of(getSpyClient(clientId).getAvailableServers()).map(Object::toString).map(TagCreator::li).list();
        DivTag div = div(ul(socketAddresses.toArray(new ContainerTag[0])));
        nodeCountByNodeTag.setLeft(socketAddresses.size());
        nodeCountByNodeTag.setRight(div);
    }
    return nodeCountByNodeTag;
}
Also used : Scanner(io.datarouter.scanner.Scanner) MemcachedClientMode(io.datarouter.aws.memcached.client.MemcachedClientMode) DivTag(j2html.tags.specialized.DivTag) LiTag(j2html.tags.specialized.LiTag) MemcachedWebInspector(io.datarouter.client.memcached.web.MemcachedWebInspector) ContainerTag(j2html.tags.ContainerTag) Inject(javax.inject.Inject) List(java.util.List) ClientId(io.datarouter.storage.client.ClientId) Pair(io.datarouter.util.tuple.Pair) TagCreator.div(j2html.TagCreator.div) AwsMemcachedOptions(io.datarouter.aws.memcached.client.options.AwsMemcachedOptions) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) TagCreator(j2html.TagCreator) TagCreator.ul(j2html.TagCreator.ul) DivTag(j2html.tags.specialized.DivTag) LiTag(j2html.tags.specialized.LiTag) MemcachedClientMode(io.datarouter.aws.memcached.client.MemcachedClientMode) Pair(io.datarouter.util.tuple.Pair)

Example 5 with J2HtmlTable

use of io.datarouter.web.html.j2html.J2HtmlTable in project datarouter by hotpads.

the class JobletExceptionHandler method makeContent.

private ContainerTag<?> makeContent(List<JobletRequest> rows) {
    var title = h4(TITLE).withClass("mt-2");
    var table = new J2HtmlTable<JobletRequest>().withClasses("sortable table table-sm table-striped border").withHtmlColumn("Exception ID", row -> {
        String id = row.getExceptionRecordId();
        return externalLinkBuilder.get().exception(request.getContextPath(), id).map(href -> td(a(id).withHref(href))).orElse(td(id));
    }).withColumn("Type", row -> row.getKey().getType()).withColumn("Execution order", row -> row.getKey().getExecutionOrder()).withColumn("Batch sequence", row -> row.getKey().getBatchSequence()).withColumn("Data ID", JobletRequest::getJobletDataId).withColumn("Reserved by", JobletRequest::getReservedBy).withColumn("Created ago", JobletRequest::getCreatedAgo).withColumn("Restartable", JobletRequest::getRestartable).withColumn("Num items", JobletRequest::getNumItems).withColumn("Queue ID", JobletRequest::getQueueId).build(rows);
    return div(title, table).withClass("container-fluid");
}
Also used : J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) JobletPageFactory(io.datarouter.joblet.JobletPageFactory) JobletTypeFactory(io.datarouter.joblet.type.JobletTypeFactory) Mav(io.datarouter.web.handler.mav.Mav) TagCreator.h4(j2html.TagCreator.h4) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) TagCreator.a(j2html.TagCreator.a) JobletStatus(io.datarouter.joblet.enums.JobletStatus) ContainerTag(j2html.tags.ContainerTag) Inject(javax.inject.Inject) List(java.util.List) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) JobletExternalLinkBuilderSupplier(io.datarouter.joblet.nav.JobletExternalLinkBuilder.JobletExternalLinkBuilderSupplier) TagCreator.td(j2html.TagCreator.td) BaseHandler(io.datarouter.web.handler.BaseHandler) DatarouterJobletRequestDao(io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao) Param(io.datarouter.web.handler.types.Param) TagCreator.div(j2html.TagCreator.div) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest)

Aggregations

J2HtmlTable (io.datarouter.web.html.j2html.J2HtmlTable)11 Inject (javax.inject.Inject)11 TagCreator.div (j2html.TagCreator.div)10 List (java.util.List)10 ContainerTag (j2html.tags.ContainerTag)9 Mav (io.datarouter.web.handler.mav.Mav)8 Scanner (io.datarouter.scanner.Scanner)7 BaseHandler (io.datarouter.web.handler.BaseHandler)7 TagCreator.td (j2html.TagCreator.td)7 Bootstrap4PageFactory (io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory)6 TagCreator.a (j2html.TagCreator.a)6 Param (io.datarouter.web.handler.types.Param)5 DatarouterWebRequireJsV2 (io.datarouter.web.requirejs.DatarouterWebRequireJsV2)5 ClientId (io.datarouter.storage.client.ClientId)4 Comparator (java.util.Comparator)4 URIBuilder (org.apache.http.client.utils.URIBuilder)4 NumberFormatter (io.datarouter.util.number.NumberFormatter)3 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)3 TagCreator.h4 (j2html.TagCreator.h4)3 DatarouterS3Client (io.datarouter.aws.s3.DatarouterS3Client)2