Search in sources :

Example 1 with DatarouterWebRequireJsV2

use of io.datarouter.web.requirejs.DatarouterWebRequireJsV2 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 2 with DatarouterWebRequireJsV2

use of io.datarouter.web.requirejs.DatarouterWebRequireJsV2 in project datarouter by hotpads.

the class JobletHandler method list.

@Handler
private Mav list(@Param(PARAM_whereStatus) OptionalString pStatus, @Param(PARAM_type) OptionalString pType) {
    Scanner<JobletRequest> requests = jobletRequestDao.scan();
    if (pStatus.isPresent() && pType.isPresent()) {
        JobletStatus status = JobletStatus.fromPersistentStringStatic(pStatus.get());
        requests = requests.include(request -> status == request.getStatus()).include(request -> request.getKey().getType().equals(pType.get()));
    } else if (pStatus.isPresent() && pType.isEmpty()) {
        JobletStatus status = JobletStatus.fromPersistentStringStatic(pStatus.get());
        requests = requests.include(request -> status == request.getStatus());
    } else if (pStatus.isEmpty() && pType.isPresent()) {
        requests = requests.include(request -> request.getKey().getType().equals(pType.get()));
    }
    Collection<JobletSummary> summaries = JobletSummary.summarizeByTypeExecutionOrderStatus(requests);
    return pageFactory.startBuilder(request).withTitle(TITLE).withRequires(DatarouterWebRequireJsV2.SORTTABLE).withContent(makeContent(summaries)).buildMav();
}
Also used : TagCreator.text(j2html.TagCreator.text) Scanner(io.datarouter.scanner.Scanner) JobletSummary(io.datarouter.joblet.dto.JobletSummary) JobletLocalLinkBuilder(io.datarouter.joblet.nav.JobletLocalLinkBuilder) TagCreator.h4(j2html.TagCreator.h4) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) JobletStatus(io.datarouter.joblet.enums.JobletStatus) Inject(javax.inject.Inject) NumberFormatter(io.datarouter.util.number.NumberFormatter) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) JobletExternalLinkBuilderSupplier(io.datarouter.joblet.nav.JobletExternalLinkBuilder.JobletExternalLinkBuilderSupplier) DatarouterJobletRequestDao(io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao) Param(io.datarouter.web.handler.types.Param) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) JobletPageFactory(io.datarouter.joblet.JobletPageFactory) DatarouterJobletCounters(io.datarouter.joblet.DatarouterJobletCounters) TagCreator.i(j2html.TagCreator.i) Collection(java.util.Collection) Mav(io.datarouter.web.handler.mav.Mav) TagCreator.a(j2html.TagCreator.a) ContainerTag(j2html.tags.ContainerTag) DomContent(j2html.tags.DomContent) TagCreator.td(j2html.TagCreator.td) BaseHandler(io.datarouter.web.handler.BaseHandler) TagCreator.div(j2html.TagCreator.div) MetricLinkBuilder(io.datarouter.instrumentation.metric.MetricLinkBuilder) JobletStatus(io.datarouter.joblet.enums.JobletStatus) JobletSummary(io.datarouter.joblet.dto.JobletSummary) JobletRequest(io.datarouter.joblet.storage.jobletrequest.JobletRequest) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 3 with DatarouterWebRequireJsV2

use of io.datarouter.web.requirejs.DatarouterWebRequireJsV2 in project datarouter by hotpads.

the class DailyDigestHandler method view.

private Mav view(DailyDigestType type) {
    ZoneId zoneId = currentSessionInfoService.getZoneId(request);
    var digestsWithContent = pluginInjector.scanInstances(DailyDigest.KEY).include(digest -> digest.getType() == type).map(dailyDigest -> new Pair<>(dailyDigest, dailyDigest.getPageContent(zoneId).orElse(null))).include(digestWithContent -> Objects.nonNull(digestWithContent.getRight())).sort(Comparator.comparing(Pair::getLeft, DailyDigest.COMPARATOR)).list();
    ContainerTag<?> content;
    if (digestsWithContent.isEmpty()) {
        content = div("No content for the daily digest.").withClass("container-fluid");
    } else {
        ContainerTag<?> header = h2("Daily Digest - " + type.display);
        ContainerTag<?> toc = ul(each(digestsWithContent, digestWithContent -> {
            DailyDigest digest = digestWithContent.getLeft();
            return li(a(digest.getTitle()).withHref("#" + digest.getId()));
        }));
        content = div(header, toc, each(digestsWithContent, digestWithContent -> div(digestWithContent.getRight()).withId(digestWithContent.getLeft().getId()))).withClass("container-fluid");
    }
    return pageFactory.startBuilder(request).withTitle("Daily Digest " + type.display).withContent(content).withRequires(DatarouterWebRequireJsV2.SORTTABLE).buildMav();
}
Also used : CurrentUserSessionInfoService(io.datarouter.web.user.session.CurrentUserSessionInfoService) PluginInjector(io.datarouter.plugin.PluginInjector) Mav(io.datarouter.web.handler.mav.Mav) TagCreator.each(j2html.TagCreator.each) TagCreator.a(j2html.TagCreator.a) TagCreator.h2(j2html.TagCreator.h2) ZoneId(java.time.ZoneId) ContainerTag(j2html.tags.ContainerTag) Objects(java.util.Objects) Inject(javax.inject.Inject) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) DailyDigestType(io.datarouter.web.digest.DailyDigest.DailyDigestType) BaseHandler(io.datarouter.web.handler.BaseHandler) TagCreator.li(j2html.TagCreator.li) Bootstrap4PageFactory(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory) Comparator(java.util.Comparator) Pair(io.datarouter.util.tuple.Pair) TagCreator.div(j2html.TagCreator.div) TagCreator.ul(j2html.TagCreator.ul) ZoneId(java.time.ZoneId) Pair(io.datarouter.util.tuple.Pair)

Example 4 with DatarouterWebRequireJsV2

use of io.datarouter.web.requirejs.DatarouterWebRequireJsV2 in project datarouter by hotpads.

the class MetricLinksHandler method view.

@Handler
public Mav view() {
    List<ContainerTag<DivTag>> tags = pluginInjector.scanInstances(MetricLinkPage.KEY).sort(Comparator.comparing(MetricLinkPage::getHtmlName)).exclude(page -> page.getMetricLinks().isEmpty()).map(this::makeContent).collect(Collectors.toList());
    DivTag content = div(each(tags, item -> TagCreator.div(item)));
    return pageFactory.startBuilder(request).withTitle("Metric Links").withContent(content).withRequires(DatarouterWebRequireJsV2.SORTTABLE).buildMav();
}
Also used : TagCreator.join(j2html.TagCreator.join) Scanner(io.datarouter.scanner.Scanner) DivTag(j2html.tags.specialized.DivTag) PluginInjector(io.datarouter.plugin.PluginInjector) TagCreator.h2(j2html.TagCreator.h2) Attr(j2html.attributes.Attr) Inject(javax.inject.Inject) MetricLinkPage(io.datarouter.web.metriclinks.MetricLinkPage) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) TagCreator(j2html.TagCreator) TagCreator.i(j2html.TagCreator.i) MetricLinkDto(io.datarouter.web.metriclinks.MetricLinkDto) Mav(io.datarouter.web.handler.mav.Mav) TagCreator.each(j2html.TagCreator.each) TagCreator.a(j2html.TagCreator.a) Collectors(java.util.stream.Collectors) ContainerTag(j2html.tags.ContainerTag) List(java.util.List) TagCreator.th(j2html.TagCreator.th) TagCreator.td(j2html.TagCreator.td) BaseHandler(io.datarouter.web.handler.BaseHandler) Comparator(java.util.Comparator) TagCreator.div(j2html.TagCreator.div) MetricLinkBuilder(io.datarouter.instrumentation.metric.MetricLinkBuilder) DivTag(j2html.tags.specialized.DivTag) MetricLinkPage(io.datarouter.web.metriclinks.MetricLinkPage) ContainerTag(j2html.tags.ContainerTag) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

BaseHandler (io.datarouter.web.handler.BaseHandler)4 Mav (io.datarouter.web.handler.mav.Mav)4 DatarouterWebRequireJsV2 (io.datarouter.web.requirejs.DatarouterWebRequireJsV2)4 TagCreator.a (j2html.TagCreator.a)4 TagCreator.div (j2html.TagCreator.div)4 ContainerTag (j2html.tags.ContainerTag)4 Inject (javax.inject.Inject)4 Scanner (io.datarouter.scanner.Scanner)3 J2HtmlTable (io.datarouter.web.html.j2html.J2HtmlTable)3 TagCreator.td (j2html.TagCreator.td)3 MetricLinkBuilder (io.datarouter.instrumentation.metric.MetricLinkBuilder)2 PluginInjector (io.datarouter.plugin.PluginInjector)2 NumberFormatter (io.datarouter.util.number.NumberFormatter)2 Param (io.datarouter.web.handler.types.Param)2 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)2 Bootstrap4PageFactory (io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory)2 TagCreator.each (j2html.TagCreator.each)2 TagCreator.h2 (j2html.TagCreator.h2)2 TagCreator.h4 (j2html.TagCreator.h4)2 TagCreator.i (j2html.TagCreator.i)2