From 8ca1803b6eaa3b7a43d24f946f1c306515ce3020 Mon Sep 17 00:00:00 2001 From: tpetr Date: Sun, 8 Nov 2015 13:25:09 -0500 Subject: [PATCH 1/2] support custom timestamp formatting in the UI --- .../hubspot/singularity/config/UIConfiguration.java | 10 ++++++++++ .../java/com/hubspot/singularity/views/IndexView.java | 9 +++++++++ SingularityUI/app/assets/_index.mustache | 1 + SingularityUI/app/handlebarsHelpers.coffee | 6 +++--- SingularityUI/config.coffee | 1 + 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/SingularityService/src/main/java/com/hubspot/singularity/config/UIConfiguration.java b/SingularityService/src/main/java/com/hubspot/singularity/config/UIConfiguration.java index 1ad1f483ac..57bd1db849 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/config/UIConfiguration.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/config/UIConfiguration.java @@ -66,6 +66,9 @@ public static RootUrlMode parse(String value) { @NotNull private String taskS3LogOmitPrefix = ""; + @NotEmpty + private String timestampFormat = "lll"; + public boolean isHideNewDeployButton() { return hideNewDeployButton; } @@ -150,4 +153,11 @@ public void setTaskS3LogOmitPrefix(String taskS3LogOmitPrefix) { this.taskS3LogOmitPrefix = taskS3LogOmitPrefix; } + public String getTimestampFormat() { + return timestampFormat; + } + + public void setTimestampFormat(String timestampFormat) { + this.timestampFormat = timestampFormat; + } } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/views/IndexView.java b/SingularityService/src/main/java/com/hubspot/singularity/views/IndexView.java index b1abae7ba7..08ddb6358a 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/views/IndexView.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/views/IndexView.java @@ -39,6 +39,8 @@ public class IndexView extends View { private final Integer warnIfScheduledJobIsRunningPastNextRunPct; + private final String timestampFormat; + public IndexView(String singularityUriBase, String appRoot, SingularityConfiguration configuration) { super("index.mustache"); @@ -76,6 +78,8 @@ public IndexView(String singularityUriBase, String appRoot, SingularityConfigura this.taskS3LogOmitPrefix = configuration.getUiConfiguration().getTaskS3LogOmitPrefix(); this.warnIfScheduledJobIsRunningPastNextRunPct = configuration.getWarnIfScheduledJobIsRunningPastNextRunPct(); + + this.timestampFormat = configuration.getUiConfiguration().getTimestampFormat(); } public String getAppRoot() { @@ -158,6 +162,10 @@ public Integer getWarnIfScheduledJobIsRunningPastNextRunPct() { return warnIfScheduledJobIsRunningPastNextRunPct; } + public String getTimestampFormat() { + return timestampFormat; + } + @Override public String toString() { return "IndexView[" + @@ -180,6 +188,7 @@ public String toString() { ", finishedTaskLogPath='" + finishedTaskLogPath + '\'' + ", commonHostnameSuffixToOmit='" + commonHostnameSuffixToOmit + '\'' + ", warnIfScheduledJobIsRunningPastNextRunPct='" + warnIfScheduledJobIsRunningPastNextRunPct + '\'' + + ", timestampFormat='" + timestampFormat + '\'' + ']'; } } diff --git a/SingularityUI/app/assets/_index.mustache b/SingularityUI/app/assets/_index.mustache index a563c6aee4..78185f581a 100644 --- a/SingularityUI/app/assets/_index.mustache +++ b/SingularityUI/app/assets/_index.mustache @@ -37,6 +37,7 @@ taskS3LogOmitPrefix: "{{{ taskS3LogOmitPrefix }}}", slaveHttpPort: {{{slaveHttpPort}}}, warnIfScheduledJobIsRunningPastNextRunPct: {{{warnIfScheduledJobIsRunningPastNextRunPct}}}, + timestampFormat: localStorage.getItem('timestampFormatOverride') || "{{{timestampFormat}}}", {{#slaveHttpsPort}} slaveHttpsPort: {{{slaveHttpsPort}}} {{/slaveHttpsPort}} diff --git a/SingularityUI/app/handlebarsHelpers.coffee b/SingularityUI/app/handlebarsHelpers.coffee index 5447eb67ab..bff5f03897 100644 --- a/SingularityUI/app/handlebarsHelpers.coffee +++ b/SingularityUI/app/handlebarsHelpers.coffee @@ -60,7 +60,7 @@ Handlebars.registerHelper 'withLast', (list, options) -> Handlebars.registerHelper 'timestampFromNow', (timestamp) -> return '' if not timestamp timeObject = moment timestamp - "#{timeObject.fromNow()} (#{ timeObject.format 'lll'})" + "#{timeObject.fromNow()} (#{ timeObject.format window.config.timestampFormat})" Handlebars.registerHelper 'ifTimestampInPast', (timestamp, options) -> return options.inverse @ if not timestamp @@ -81,12 +81,12 @@ Handlebars.registerHelper 'timestampDuration', (timestamp) -> Handlebars.registerHelper 'timestampFormatted', (timestamp) -> return '' if not timestamp timeObject = moment timestamp - timeObject.format 'lll' + timeObject.format window.config.timestampFormat Handlebars.registerHelper 'timestampFormattedWithSeconds', (timestamp) -> return '' if not timestamp timeObject = moment timestamp - timeObject.format 'lll:ss' + timeObject.format window.config.timestampFormat + ':ss' # 'DRIVER_NOT_RUNNING' => 'Driver not running' Handlebars.registerHelper 'humanizeText', (text) -> diff --git a/SingularityUI/config.coffee b/SingularityUI/config.coffee index 537869624d..36ca903051 100644 --- a/SingularityUI/config.coffee +++ b/SingularityUI/config.coffee @@ -55,6 +55,7 @@ exports.config = commonHostnameSuffixToOmit: process.env.SINGULARITY_COMMON_HOSTNAME_SUFFIX_TO_OMIT ? "" taskS3LogOmitPrefix: process.env.SINGULARITY_TASK_S3_LOG_OMIT_PREFIX ? '' warnIfScheduledJobIsRunningPastNextRunPct: process.env.SINGULARITY_WARN_IF_SCHEDULED_JOB_IS_RUNNING_PAST_NEXT_RUN_PCT ? 200 + timestampFormat: process.env.SINGULARITY_TIMESTAMP_FORMAT ? 'lll' compiledTemplate = handlebars.compile(indexTemplate)(templateData) fs.writeFileSync destination, compiledTemplate From 9bb11f00bed9a6ade957fcfb540d2028f828d71b Mon Sep 17 00:00:00 2001 From: tpetr Date: Sun, 8 Nov 2015 13:42:22 -0500 Subject: [PATCH 2/2] timestampWithSecondsFormat, too --- .../hubspot/singularity/config/UIConfiguration.java | 11 +++++++++++ .../java/com/hubspot/singularity/views/IndexView.java | 9 +++++++++ SingularityUI/app/assets/_index.mustache | 1 + SingularityUI/app/handlebarsHelpers.coffee | 2 +- SingularityUI/config.coffee | 1 + 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/SingularityService/src/main/java/com/hubspot/singularity/config/UIConfiguration.java b/SingularityService/src/main/java/com/hubspot/singularity/config/UIConfiguration.java index 57bd1db849..52782baa5b 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/config/UIConfiguration.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/config/UIConfiguration.java @@ -69,6 +69,9 @@ public static RootUrlMode parse(String value) { @NotEmpty private String timestampFormat = "lll"; + @NotEmpty + private String timestampWithSecondsFormat = "lll:ss"; + public boolean isHideNewDeployButton() { return hideNewDeployButton; } @@ -160,4 +163,12 @@ public String getTimestampFormat() { public void setTimestampFormat(String timestampFormat) { this.timestampFormat = timestampFormat; } + + public String getTimestampWithSecondsFormat() { + return timestampWithSecondsFormat; + } + + public void setTimestampWithSecondsFormat(String timestampWithSecondsFormat) { + this.timestampWithSecondsFormat = timestampWithSecondsFormat; + } } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/views/IndexView.java b/SingularityService/src/main/java/com/hubspot/singularity/views/IndexView.java index 08ddb6358a..cb991315dd 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/views/IndexView.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/views/IndexView.java @@ -41,6 +41,8 @@ public class IndexView extends View { private final String timestampFormat; + private final String timestampWithSecondsFormat; + public IndexView(String singularityUriBase, String appRoot, SingularityConfiguration configuration) { super("index.mustache"); @@ -80,6 +82,8 @@ public IndexView(String singularityUriBase, String appRoot, SingularityConfigura this.warnIfScheduledJobIsRunningPastNextRunPct = configuration.getWarnIfScheduledJobIsRunningPastNextRunPct(); this.timestampFormat = configuration.getUiConfiguration().getTimestampFormat(); + + this.timestampWithSecondsFormat = configuration.getUiConfiguration().getTimestampWithSecondsFormat(); } public String getAppRoot() { @@ -166,6 +170,10 @@ public String getTimestampFormat() { return timestampFormat; } + public String getTimestampWithSecondsFormat() { + return timestampWithSecondsFormat; + } + @Override public String toString() { return "IndexView[" + @@ -189,6 +197,7 @@ public String toString() { ", commonHostnameSuffixToOmit='" + commonHostnameSuffixToOmit + '\'' + ", warnIfScheduledJobIsRunningPastNextRunPct='" + warnIfScheduledJobIsRunningPastNextRunPct + '\'' + ", timestampFormat='" + timestampFormat + '\'' + + ", timestampWithSecondsFormat='" + timestampWithSecondsFormat + '\'' + ']'; } } diff --git a/SingularityUI/app/assets/_index.mustache b/SingularityUI/app/assets/_index.mustache index 78185f581a..655dc5a63f 100644 --- a/SingularityUI/app/assets/_index.mustache +++ b/SingularityUI/app/assets/_index.mustache @@ -38,6 +38,7 @@ slaveHttpPort: {{{slaveHttpPort}}}, warnIfScheduledJobIsRunningPastNextRunPct: {{{warnIfScheduledJobIsRunningPastNextRunPct}}}, timestampFormat: localStorage.getItem('timestampFormatOverride') || "{{{timestampFormat}}}", + timestampWithSecondsFormat: localStorage.getItem('timestampWithSecondsFormatOverride') || "{{{timestampWithSecondsFormat}}}", {{#slaveHttpsPort}} slaveHttpsPort: {{{slaveHttpsPort}}} {{/slaveHttpsPort}} diff --git a/SingularityUI/app/handlebarsHelpers.coffee b/SingularityUI/app/handlebarsHelpers.coffee index bff5f03897..9e4e21b158 100644 --- a/SingularityUI/app/handlebarsHelpers.coffee +++ b/SingularityUI/app/handlebarsHelpers.coffee @@ -86,7 +86,7 @@ Handlebars.registerHelper 'timestampFormatted', (timestamp) -> Handlebars.registerHelper 'timestampFormattedWithSeconds', (timestamp) -> return '' if not timestamp timeObject = moment timestamp - timeObject.format window.config.timestampFormat + ':ss' + timeObject.format window.config.timestampWithSecondsFormat # 'DRIVER_NOT_RUNNING' => 'Driver not running' Handlebars.registerHelper 'humanizeText', (text) -> diff --git a/SingularityUI/config.coffee b/SingularityUI/config.coffee index 36ca903051..8abc52328a 100644 --- a/SingularityUI/config.coffee +++ b/SingularityUI/config.coffee @@ -56,6 +56,7 @@ exports.config = taskS3LogOmitPrefix: process.env.SINGULARITY_TASK_S3_LOG_OMIT_PREFIX ? '' warnIfScheduledJobIsRunningPastNextRunPct: process.env.SINGULARITY_WARN_IF_SCHEDULED_JOB_IS_RUNNING_PAST_NEXT_RUN_PCT ? 200 timestampFormat: process.env.SINGULARITY_TIMESTAMP_FORMAT ? 'lll' + timestampWithSecondsFormat: process.env.SINGULARITY_TIMESTAMP_WITH_SECONDS_FORMAT ? 'lll:ss' compiledTemplate = handlebars.compile(indexTemplate)(templateData) fs.writeFileSync destination, compiledTemplate