Skip to content

Commit e912f9c

Browse files
Merge pull request #1706 from Particular/john/tails
More vue converted to TypeScript
2 parents 7978d7c + 5d9cdf3 commit e912f9c

26 files changed

+211
-173
lines changed

src/ServicePulse.Host/vue/src/components/BusyIndicator.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script setup></script>
1+
<script setup lang="ts"></script>
22

33
<template>
44
<div class="row">

src/ServicePulse.Host/vue/src/components/ConfirmDialog.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<script setup>
1+
<script setup lang="ts">
22
import { onMounted, onUnmounted } from "vue";
33
44
const emit = defineEmits(["confirm", "cancel"]);
55
6-
const settings = defineProps({
7-
heading: String,
8-
body: String,
9-
secondParagraph: String,
10-
hideCancel: Boolean,
11-
});
6+
const settings = defineProps<{
7+
heading: string;
8+
body: string;
9+
secondParagraph: string;
10+
hideCancel: boolean;
11+
}>();
1212
1313
function confirm() {
1414
emit("confirm", settings);

src/ServicePulse.Host/vue/src/components/DashboardItem.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<script setup>
2-
const props = defineProps({
3-
counter: Number,
4-
url: String,
5-
iconClass: String,
6-
});
1+
<script setup lang="ts">
2+
const props = defineProps<{
3+
counter: number;
4+
url: string;
5+
iconClass: string;
6+
}>();
77
</script>
88

99
<template>
Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
1-
<script setup>
1+
<script setup lang="ts" generic="T">
22
import { onMounted, onUnmounted, ref, watch } from "vue";
3-
import { useFetchFromServiceControl } from "../composables/serviceServiceControlUrls";
4-
import ItemsPerPage from "../components/ItemsPerPage.vue";
5-
import PaginationStrip from "../components/PaginationStrip.vue";
6-
const props = defineProps({
7-
apiUrl: String,
8-
itemsPerPageOptions: {
9-
type: Array,
10-
default: () => [20, 35, 50, 75],
11-
},
12-
itemsPerPage: {
13-
type: Number,
14-
default: 50,
15-
},
16-
autoRefreshSeconds: {
17-
type: Number,
18-
},
19-
showPagination: {
20-
type: Boolean,
21-
default: true,
22-
},
23-
showItemsPerPage: {
24-
type: Boolean,
25-
default: false,
26-
},
27-
});
3+
import { useTypedFetchFromServiceControl } from "@/composables/serviceServiceControlUrls";
4+
import ItemsPerPage from "@/components/ItemsPerPage.vue";
5+
import PaginationStrip from "@/components/PaginationStrip.vue";
6+
import type DataViewPageModel from "./DataViewPageModel";
7+
8+
const props = withDefaults(
9+
defineProps<{
10+
apiUrl: string;
11+
itemsPerPageOptions?: number[];
12+
itemsPerPage?: number;
13+
autoRefreshSeconds: number;
14+
showPagination?: boolean;
15+
showItemsPerPage?: boolean;
16+
}>(),
17+
{ itemsPerPageOptions: () => [20, 35, 50, 75], itemsPerPage: 50, showPagination: true, showItemsPerPage: false }
18+
);
19+
20+
let refreshTimer: number | undefined;
21+
const viewModel = defineModel<DataViewPageModel<T>>({ required: true });
2822
29-
const refreshTimer = ref();
30-
const items = ref([]);
3123
const pageNumber = ref(1);
3224
const itemsPerPage = ref(props.itemsPerPage);
33-
const totalCount = ref(0);
3425
3526
watch(
3627
() => props.autoRefreshSeconds,
@@ -44,30 +35,23 @@ watch(itemsPerPage, () => loadData());
4435
watch(pageNumber, () => loadData());
4536
4637
async function loadData() {
47-
try {
48-
const response = await useFetchFromServiceControl(`${props.apiUrl}?page=${pageNumber.value}&per_page=${itemsPerPage.value}`);
49-
if (response.ok) {
50-
totalCount.value = parseInt(response.headers.get("Total-Count"));
51-
const data = await response.json();
52-
items.value = data;
53-
}
54-
} catch (error) {
55-
console.log(error);
38+
const [response, data] = await useTypedFetchFromServiceControl<T[]>(`${props.apiUrl}?page=${pageNumber.value}&per_page=${itemsPerPage.value}`);
39+
if (response.ok) {
40+
viewModel.value.totalCount = parseInt(response.headers.get("Total-Count") ?? "0");
41+
viewModel.value.data = data;
5642
}
5743
}
5844
5945
function startRefreshTimer() {
6046
if (props.autoRefreshSeconds) {
61-
refreshTimer.value = setInterval(() => {
47+
refreshTimer = window.setInterval(() => {
6248
loadData();
6349
}, props.autoRefreshSeconds * 1000);
6450
}
6551
}
6652
6753
function stopRefreshTimer() {
68-
if (refreshTimer.value) {
69-
clearInterval(refreshTimer.value);
70-
}
54+
window.clearInterval(refreshTimer);
7155
}
7256
7357
onMounted(() => {
@@ -81,10 +65,10 @@ onUnmounted(() => {
8165
</script>
8266

8367
<template>
84-
<slot name="data" v-bind="items"></slot>
68+
<slot name="data"></slot>
8569
<div class="row">
8670
<ItemsPerPage v-if="showItemsPerPage" v-model="itemsPerPage" :options="itemsPerPageOptions" />
87-
<PaginationStrip v-if="showPagination" v-model="pageNumber" :totalCount="totalCount" :itemsPerPage="itemsPerPage" />
71+
<PaginationStrip v-if="showPagination" v-model="pageNumber" :totalCount="viewModel.totalCount" :itemsPerPage="itemsPerPage" />
8872
</div>
89-
<slot name="footer" :count="totalCount"></slot>
73+
<slot name="footer"></slot>
9074
</template>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default interface DataViewPageModel<T> {
2+
data: T[];
3+
totalCount: number;
4+
}

src/ServicePulse.Host/vue/src/components/EventItemShort.vue

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
<script setup>
2-
import DataView from "../components/DataView.vue";
3-
import EventLogItem from "../components/EventLogItem.vue";
1+
<script setup lang="ts">
2+
import DataView from "@/components/DataView.vue";
3+
import EventLogItem from "@/components/EventLogItem.vue";
4+
import type EventLogItemType from "@/resources/EventLogItem";
5+
import { ref } from "vue";
46
import { RouterLink } from "vue-router";
7+
8+
import type DataViewPageModel from "@/components/DataViewPageModel";
9+
10+
const pageModel = ref<DataViewPageModel<EventLogItemType>>({ data: [], totalCount: 0 });
511
</script>
612

713
<template>
814
<div class="events">
9-
<DataView api-url="eventlogitems" :auto-refresh-seconds="5" :itemsPerPage="10" :show-pagination="false">
10-
<template #data="items">
15+
<DataView api-url="eventlogitems" v-model="pageModel" :auto-refresh-seconds="5" :itemsPerPage="10" :show-pagination="false">
16+
<template #data>
1117
<div class="col-12">
1218
<h6>Last 10 events</h6>
13-
<EventLogItem v-for="item of items" :eventLogItem="item" :key="item.id" />
19+
<EventLogItem v-for="item of pageModel.data" :eventLogItem="item" :key="item.id" />
1420
</div>
1521
</template>
16-
<template #footer="{ count }">
17-
<div v-if="count > 10" class="row text-center">
22+
<template #footer>
23+
<div v-if="pageModel.totalCount > 10" class="row text-center">
1824
<div class="col-12">
1925
<RouterLink :to="{ name: 'events' }" class="btn btn-default btn-secondary btn-all-events">View all events</RouterLink>
2026
</div>

src/ServicePulse.Host/vue/src/components/EventLogItem.vue

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
<script setup>
1+
<script setup lang="ts">
22
import { useRouter } from "vue-router";
33
import TimeSince from "../components/TimeSince.vue";
4+
import type EventLogItem from "@/resources/EventLogItem";
5+
import { Severity } from "@/resources/EventLogItem";
46
5-
defineProps({
6-
eventLogItem: Object,
7-
});
7+
defineProps<{ eventLogItem: EventLogItem }>();
88
const router = useRouter();
99
10-
function navigateToEvent(eventLogItem) {
10+
function navigateToEvent(eventLogItem: EventLogItem) {
1111
switch (eventLogItem.category) {
1212
case "Endpoints":
1313
router.push({ name: "endpoint-connection" });
1414
break;
1515
case "HeartbeatMonitoring":
16-
window.location = "/a/#/endpoints";
16+
window.location.assign("/a/#/endpoints");
1717
break;
1818
case "CustomChecks":
19-
window.location = "/a/#/custom-checks";
19+
window.location.assign("/a/#/custom-checks");
2020
break;
2121
case "EndpointControl":
22-
window.location = "/a/#/endpoints";
22+
window.location.assign("/a/#/endpoints");
2323
break;
2424
case "MessageFailures":
2525
if (eventLogItem.related_to?.length && eventLogItem.related_to[0].search("message") > 0) {
@@ -39,10 +39,10 @@ function navigateToEvent(eventLogItem) {
3939
}
4040
}
4141
42-
function iconClasses(eventItem) {
42+
function iconClasses(eventItem: EventLogItem) {
4343
return {
44-
normal: eventItem.severity === "info",
45-
danger: eventItem.severity === "error",
44+
normal: eventItem.severity === Severity.Info,
45+
danger: eventItem.severity === Severity.Error,
4646
"fa-heartbeat": eventItem.category === "Endpoints" || eventItem.category === "EndpointControl" || eventItem.category === "HeartbeatMonitoring",
4747
"fa-check": eventItem.category === "CustomChecks",
4848
"fa-envelope": eventItem.category === "MessageFailures" || eventItem.category === "Recoverability",
@@ -51,12 +51,12 @@ function iconClasses(eventItem) {
5151
};
5252
}
5353
54-
function iconSubClasses(eventItem) {
54+
function iconSubClasses(eventItem: EventLogItem) {
5555
return {
56-
"fa-times fa-error": (eventItem.severity === "error" || eventItem.category === "MessageRedirects") && eventItem.severity === "error",
57-
"fa-pencil": (eventItem.severity === "error" || eventItem.category === "MessageRedirects") && eventItem.category === "MessageRedirects" && eventItem.event_type === "MessageRedirectChanged",
58-
"fa-plus": (eventItem.severity === "error" || eventItem.category === "MessageRedirects") && eventItem.category === "MessageRedirects" && eventItem.event_type === "MessageRedirectCreated",
59-
"fa-trash": (eventItem.severity === "error" || eventItem.category === "MessageRedirects") && eventItem.category === "MessageRedirects" && eventItem.event_type === "MessageRedirectRemoved",
56+
"fa-times fa-error": (eventItem.severity === Severity.Error || eventItem.category === "MessageRedirects") && eventItem.severity === Severity.Error,
57+
"fa-pencil": (eventItem.severity === Severity.Error || eventItem.category === "MessageRedirects") && eventItem.category === "MessageRedirects" && eventItem.event_type === "MessageRedirectChanged",
58+
"fa-plus": (eventItem.severity === Severity.Error || eventItem.category === "MessageRedirects") && eventItem.category === "MessageRedirects" && eventItem.event_type === "MessageRedirectCreated",
59+
"fa-trash": (eventItem.severity === Severity.Error || eventItem.category === "MessageRedirects") && eventItem.category === "MessageRedirects" && eventItem.event_type === "MessageRedirectRemoved",
6060
};
6161
}
6262
</script>
@@ -68,7 +68,7 @@ function iconSubClasses(eventItem) {
6868
<div class="col-1">
6969
<span class="fa-stack fa-lg">
7070
<i class="fa fa-stack-2x" :class="iconClasses(eventLogItem)" />
71-
<i v-if="eventLogItem.severity === 'error' || eventLogItem.category === 'MessageRedirects'" class="fa fa-o fa-stack-1x fa-inverse" :class="iconSubClasses(eventLogItem)" />
71+
<i v-if="eventLogItem.severity === Severity.Error || eventLogItem.category === 'MessageRedirects'" class="fa fa-o fa-stack-1x fa-inverse" :class="iconSubClasses(eventLogItem)" />
7272
</span>
7373
</div>
7474
<div class="col-9">
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
<script setup>
2-
const props = defineProps({
3-
type: String,
4-
});
1+
<script setup lang="ts">
2+
import { WarningLevel } from "@/components/WarningLevel";
3+
4+
const props = withDefaults(
5+
defineProps<{
6+
type: WarningLevel;
7+
}>(),
8+
{ type: WarningLevel.None }
9+
);
510
</script>
611

712
<template>
8-
<template v-if="props.type">
9-
<span class="fa fa-exclamation-triangle" :class="type"></span>
13+
<template v-if="props.type !== WarningLevel.None">
14+
<span class="fa fa-exclamation-triangle" :class="props.type"></span>
1015
</template>
1116
</template>

src/ServicePulse.Host/vue/src/components/ItemsPerPage.vue

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
<script setup>
2-
defineProps({
3-
options: {
4-
type: Array,
5-
default: () => [20, 35, 50, 75],
6-
},
7-
});
1+
<script setup lang="ts">
2+
withDefaults(
3+
defineProps<{
4+
options: number[];
5+
}>(),
6+
{ options: () => [20, 35, 50, 75] }
7+
);
88
9-
const current = defineModel({
10-
type: Number,
11-
default: 50,
12-
});
9+
const current = defineModel<number>({ default: 50 });
1310
</script>
1411

1512
<template>

src/ServicePulse.Host/vue/src/components/LicenseExpired.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script setup>
1+
<script setup lang="ts">
22
import { licenseStatus } from "../composables/serviceLicense";
33
</script>
44

0 commit comments

Comments
 (0)