Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions app/assets/javascripts/classes/reports/EditReportViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import moment = require('moment-timezone/moment-timezone');
import csrf from '../Csrf';

import {
availableReportFormatTypes,
availableSourceTypes,
BaseRecipientViewModel,
BaseScheduleViewModel,
Expand Down Expand Up @@ -189,10 +190,16 @@ class EditRecipientViewModel extends BaseRecipientViewModel {
}
}

readonly availableFormats = [
{value: ReportFormat.PDF, text: "PDF"},
{value: ReportFormat.HTML, text: "HTML"},
];
private static readonly formatDisplayNames = {
[ReportFormat.PDF]: "PDF",
[ReportFormat.HTML]: "HTML",
};
readonly availableFormats: {value: ReportFormat, text: string}[] = availableReportFormatTypes.map(
reportFormatType => ({
value: reportFormatType,
text: EditRecipientViewModel.formatDisplayNames[reportFormatType],
})
);

readonly helpMessages = {
format: "The format that will be delivered to this recipient. For example, a PDF attached to an email or " +
Expand Down
11 changes: 11 additions & 0 deletions app/assets/javascripts/classes/reports/Models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ export enum ScheduleRepetition {
MONTHLY,
}

function mimeTypeToReportFormat(mimeType: string): ReportFormat | undefined {
if (/^application\/pdf\b/.test(mimeType)) {
return ReportFormat.HTML;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ITYM PDF?

} else if (/^text\/html\b/.test(mimeType)) {
return ReportFormat.HTML;
}
return undefined;
}
export const availableSourceTypes: SourceType[] = features.sourceTypes.map((s: keyof typeof SourceType) => SourceType[s]);
export const availableReportFormatTypes: ReportFormat[] = features.reportFormatTypes
.map((s: string) => mimeTypeToReportFormat(s))
.filter(fmt => (fmt !== undefined));

export class ZoneInfo {
value: string;
Expand Down
9 changes: 9 additions & 0 deletions app/models/internal/Features.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import com.arpnetworking.metrics.portal.reports.SourceType;
import com.google.common.collect.ImmutableList;
import com.google.common.net.MediaType;
import models.internal.reports.ReportFormat;

/**
* Internal model interface for metrics portal feature state.
Expand Down Expand Up @@ -87,4 +89,11 @@ public interface Features {
* @return list of names of {@link SourceType} enum values.
*/
ImmutableList<String> getSourceTypes();

/**
* {@link MediaType}s of {@link ReportFormat}s to display in the UI.
*
* @return list of names of {@link MediaType}s.
*/
ImmutableList<String> getReportFormatTypes();
}
13 changes: 13 additions & 0 deletions app/models/internal/impl/DefaultFeatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.arpnetworking.logback.annotations.Loggable;
import com.arpnetworking.metrics.portal.reports.SourceType;
import com.google.common.collect.ImmutableList;
import com.google.common.net.MediaType;
import com.typesafe.config.Config;
import models.internal.Features;

Expand Down Expand Up @@ -73,6 +74,11 @@ public ImmutableList<String> getSourceTypes() {
return _sourceTypes.stream().map(SourceType::name).collect(ImmutableList.toImmutableList());
}

@Override
public ImmutableList<String> getReportFormatTypes() {
return _reportFormatTypes.stream().map(MediaType::toString).collect(ImmutableList.toImmutableList());
}

@Override
public String toString() {
return new StringBuilder()
Expand All @@ -84,6 +90,8 @@ public String toString() {
.append(", rollupsEnabled=").append(_rollupsEnabled)
.append(", reportsEnabled=").append(_reportsEnabled)
.append(", metricsAggregatorDaemonPorts=").append(_metricsAggregatorDaemonPorts)
.append(", sourceTypes=").append(_sourceTypes)
.append(", reportFormatTypes=").append(_reportFormatTypes)
.append("}")
.toString();
}
Expand All @@ -107,6 +115,10 @@ public DefaultFeatures(final Config configuration) {
.stream()
.map(SourceType::valueOf)
.collect(ImmutableList.toImmutableList());
_reportFormatTypes = configuration.getStringList("portal.features.reports.formatTypes")
.stream()
.map(MediaType::parse)
.collect(ImmutableList.toImmutableList());
}

private final boolean _telemetryEnabled;
Expand All @@ -118,4 +130,5 @@ public DefaultFeatures(final Config configuration) {
private final boolean _reportsEnabled;
private final ImmutableList<Integer> _metricsAggregatorDaemonPorts;
private final ImmutableList<SourceType> _sourceTypes;
private final ImmutableList<MediaType> _reportFormatTypes;
}
4 changes: 4 additions & 0 deletions conf/portal.application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ portal.features {
# Reports
reports.enabled = false
reports.sourceTypes = [WEB_PAGE, GRAFANA]
reports.formatTypes = [
"text/html; charset=utf-8",
"application/pdf",
]

# Metrics aggregator ports
metricsAggregatorDaemonPorts = [7090]
Expand Down