Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
6 changes: 5 additions & 1 deletion src/components/Datetime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ export default {
type: Boolean,
default: false,
},
use12HourTimeFormat: {
type: Boolean,
default: false
},
},

computed: {
displayText() {
if (this.dateOnly) {
return this.$root.date(this.value);
} else {
return this.$root.datetime(this.value);
return this.$root.datetime(this.value, this.use12HourTimeFormat);
}
},
},
Expand Down
14 changes: 11 additions & 3 deletions src/components/PingChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export default {
type: Number,
required: true,
},
use12HourTimeFormat: {
type: Boolean,
default: false
}
},
data() {
return {
Expand All @@ -60,6 +64,10 @@ export default {
},
computed: {
chartOptions() {
const hourTimeFormat = this.use12HourTimeFormat ? "hh" : "HH";
const minuteTimeFormat = `${hourTimeFormat}:mm${
this.use12HourTimeFormat ? " A" : ""
}`;
return {
responsive: true,
maintainAspectRatio: false,
Expand Down Expand Up @@ -99,8 +107,8 @@ export default {
round: "second",
tooltipFormat: "YYYY-MM-DD HH:mm:ss",
displayFormats: {
minute: "HH:mm",
hour: "MM-DD HH:mm",
minute: minuteTimeFormat,
hour: `MM-DD ${minuteTimeFormat}`,
}
},
ticks: {
Expand Down Expand Up @@ -177,7 +185,7 @@ export default {
)
)
.map((beat) => {
const x = this.$root.datetime(beat.time);
const x = this.$root.datetime(beat.time, this.use12HourTimeFormat);
pingData.push({
x,
y: beat.ping,
Expand Down
36 changes: 36 additions & 0 deletions src/components/settings/General.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,42 @@
</select>
</div>

<!-- Time Format -->
<div class="mb-4">
<label class="form-label">
{{ $t("Time Format") }}
</label>

<div class="form-check">
<input
id="timeFormatIndex12Hour"
v-model="settings.use12HourTimeFormat"
class="form-check-input"
type="radio"
name="timeFormatIndex"
:value="true"
required
/>
<label class="form-check-label" for="timeFormatIndex12Hour">
{{ $t("12-hour") }}
</label>
</div>
<div class="form-check">
<input
id="timeFormatIndex24Hour"
v-model="settings.use12HourTimeFormat"
class="form-check-input"
type="radio"
name="timeFormatIndex"
:value="false"
required
/>
<label class="form-check-label" for="timeFormatIndex24Hour">
{{ $t("24-hour") }}
</label>
</div>
</div>

<!-- Search Engine -->
<div class="mb-4">
<label class="form-label">
Expand Down
5 changes: 4 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -838,5 +838,8 @@
"successDisabled": "Disabled Successfully.",
"successEnabled": "Enabled Successfully.",
"tagNotFound": "Tag not found.",
"foundChromiumVersion": "Found Chromium/Chrome. Version: {0}"
"foundChromiumVersion": "Found Chromium/Chrome. Version: {0}",
"Time Format": "Time Format",
"12-hour": "12 Hour",
"24-hour": "24 Hour"
}
10 changes: 8 additions & 2 deletions src/mixins/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ export default {
/**
* Return a given value in the format YYYY-MM-DD HH:mm:ss
* @param {any} value Value to format as date time
* @param {boolean} use12HourTimeFormat Whether to use 12-hour format
* @returns {string} Formatted string
*/
datetime(value) {
return this.datetimeFormat(value, "YYYY-MM-DD HH:mm:ss");
datetime(value, use12HourTimeFormat = false) {
const hourTimeFormat = use12HourTimeFormat ? "hh" : "HH";
const timeFormat =
`YYYY-MM-DD ${hourTimeFormat}:mm:ss${
use12HourTimeFormat ? " A" : ""
}`;
return this.datetimeFormat(value, timeFormat);
},

/**
Expand Down
14 changes: 13 additions & 1 deletion src/pages/DashboardHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<tr v-for="(beat, index) in displayedRecords" :key="index" :class="{ 'shadow-box': $root.windowWidth <= 550}">
<td><router-link :to="`/dashboard/${beat.monitorID}`">{{ $root.monitorList[beat.monitorID]?.name }}</router-link></td>
<td><Status :status="beat.status" /></td>
<td :class="{ 'border-0':! beat.msg}"><Datetime :value="beat.time" /></td>
<td :class="{ 'border-0':! beat.msg}"><Datetime :value="beat.time" :use12HourTimeFormat="use12HourTimeFormat" /></td>
<td class="border-0">{{ beat.msg }}</td>
</tr>

Expand Down Expand Up @@ -98,6 +98,7 @@ export default {
},
importantHeartBeatListLength: 0,
displayedRecords: [],
use12HourTimeFormat: false
};
},
watch: {
Expand All @@ -113,6 +114,7 @@ export default {
},

mounted() {
this.loadSettings();
this.getImportantHeartbeatListLength();

this.$root.emitter.on("newImportantHeartbeat", this.onNewImportantHeartbeat);
Expand Down Expand Up @@ -188,6 +190,16 @@ export default {
}

},

/**
* Retrieves important settings values.
* @returns {void}
*/
loadSettings() {
this.$root.getSocket().emit("getSettings", res => {
this.use12HourTimeFormat = res.data.use12HourTimeFormat;
});
}
},
};
</script>
Expand Down
13 changes: 11 additions & 2 deletions src/pages/Details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<div v-if="showPingChartBox" class="shadow-box big-padding text-center ping-chart-wrapper">
<div class="row">
<div class="col">
<PingChart :monitor-id="monitor.id" />
<PingChart :monitor-id="monitor.id" :use12HourTimeFormat="use12HourTimeFormat" />
</div>
</div>
</div>
Expand Down Expand Up @@ -219,7 +219,7 @@
<tbody>
<tr v-for="(beat, index) in displayedRecords" :key="index" style="padding: 10px;">
<td><Status :status="beat.status" /></td>
<td :class="{ 'border-0':! beat.msg}"><Datetime :value="beat.time" /></td>
<td :class="{ 'border-0':! beat.msg}"><Datetime :value="beat.time" :use12HourTimeFormat="use12HourTimeFormat" /></td>
<td class="border-0">{{ beat.msg }}</td>
</tr>

Expand Down Expand Up @@ -317,6 +317,7 @@ export default {
currentExample: "javascript-fetch",
code: "",
},
use12HourTimeFormat: false,
};
},
computed: {
Expand Down Expand Up @@ -413,6 +414,7 @@ export default {
},

mounted() {
this.loadSettings();
this.getImportantHeartbeatListLength();

this.$root.emitter.on("newImportantHeartbeat", this.onNewImportantHeartbeat);
Expand Down Expand Up @@ -642,7 +644,14 @@ export default {
.replace("https://example.com/api/push/key?status=up&msg=OK&ping=", this.pushURL);
this.pushMonitor.code = code;
});
},

loadSettings() {
this.$root.getSocket().emit("getSettings", res => {
this.use12HourTimeFormat = res.data.use12HourTimeFormat || false;
});
}

},
};
</script>
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ export default {
this.settings.searchEngineIndex = false;
}

if (this.settings.use12HourTimeFormat === undefined) {
this.settings.use12HourTimeFormat = false;
}

if (this.settings.entryPage === undefined) {
this.settings.entryPage = "dashboard";
}
Expand Down