@appscode/design-system 1.0.43-alpha.174 → 1.0.43-alpha.175
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugins/time-convert.js +49 -0
- package/vue-components/v3/long-running-tasks/LongRunningTaskItem.vue +68 -68
- package/vue-components/v3/modals/LongRunningTasksModal.vue +2 -2
- package/vue-components/v3/notification/Notification.vue +98 -0
- package/vue-components/v3/notification/NotificationItem.vue +52 -0
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import moment from "moment";
|
|
2
|
+
import { useNow, useThrottleFn } from "@vueuse/core";
|
|
3
|
+
|
|
4
|
+
const getTime = option => {
|
|
5
|
+
if (parseInt(option.time, 10) < 0 || !option.time) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
let time = option.time;
|
|
9
|
+
|
|
10
|
+
// moment(option.time).valueOf('x') needs to convert pharmer's api date to epoch time
|
|
11
|
+
time = moment(option.time).valueOf("x")
|
|
12
|
+
? moment(option.time).valueOf("x")
|
|
13
|
+
: time * 1000;
|
|
14
|
+
|
|
15
|
+
return moment(time).format("MMM DD YYYY, h:mm A");
|
|
16
|
+
};
|
|
17
|
+
const getDayDifferences = options => {
|
|
18
|
+
const past = moment(options.past).isValid()
|
|
19
|
+
? moment(options.past).valueOf("x") / 1000
|
|
20
|
+
: options.past;
|
|
21
|
+
const now = Date.now() / 1000;
|
|
22
|
+
const diff = now - past;
|
|
23
|
+
if (parseInt(options.past, 10) > 10) {
|
|
24
|
+
let ret = Math.floor(diff / 86400);
|
|
25
|
+
let unit = "";
|
|
26
|
+
if (diff < 60) {
|
|
27
|
+
ret = parseInt(diff, 10);
|
|
28
|
+
unit = " Second";
|
|
29
|
+
} else if (diff < 3600) {
|
|
30
|
+
ret = parseInt(diff / 60, 10);
|
|
31
|
+
unit = " Minute";
|
|
32
|
+
} else if (diff < 86400) {
|
|
33
|
+
ret = parseInt(diff / 3600, 10);
|
|
34
|
+
unit = " Hour";
|
|
35
|
+
} else {
|
|
36
|
+
ret = parseInt(diff / 86400, 10);
|
|
37
|
+
unit = " Day";
|
|
38
|
+
}
|
|
39
|
+
unit += ret > 1 ? "s" : "";
|
|
40
|
+
return ret + unit;
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
getTime,
|
|
47
|
+
// formatMoment,
|
|
48
|
+
getDayDifferences
|
|
49
|
+
};
|
|
@@ -6,87 +6,87 @@
|
|
|
6
6
|
</template>
|
|
7
7
|
|
|
8
8
|
<script setup lang="ts">
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import { computed, toRefs } from "vue";
|
|
10
|
+
import { TaskStatus } from "../../../typings/long-running-tasks.ts";
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const props = withDefaults(
|
|
13
|
+
defineProps<{ title: string; status: TaskStatus }>(),
|
|
14
|
+
{
|
|
15
|
+
title: "",
|
|
16
|
+
status: "Pending",
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const { status } = toRefs(props);
|
|
21
|
+
const statusClass = computed(() => `is-${status.value.toLowerCase()}`);
|
|
22
|
+
const statusIcon = computed(() => {
|
|
23
|
+
if (status.value === "Running" || status.value === "Started")
|
|
24
|
+
return "circle-o-notch";
|
|
25
|
+
else if (status.value === "Success") return "check-circle";
|
|
26
|
+
else if (status.value === "Failed") return "times-circle";
|
|
27
|
+
else return "spinner";
|
|
28
|
+
});
|
|
29
29
|
</script>
|
|
30
30
|
|
|
31
31
|
<style scoped lang="scss">
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
.task-item {
|
|
33
|
+
font-size: 14px;
|
|
34
|
+
display: block;
|
|
35
|
+
padding: 5px;
|
|
36
|
+
border-radius: 5px;
|
|
37
|
+
transition: all 0.3s ease-in-out;
|
|
38
|
+
&:hover {
|
|
39
|
+
background-color: var(--ac-white-light);
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
}
|
|
42
|
+
&.is-active {
|
|
43
|
+
background-color: var(--ac-white-light);
|
|
44
|
+
}
|
|
45
|
+
&.is-pending {
|
|
46
|
+
color: var(--ac-gray-light);
|
|
47
|
+
i {
|
|
48
|
+
visibility: hidden;
|
|
41
49
|
}
|
|
42
|
-
|
|
43
|
-
background-color:
|
|
50
|
+
&:hover {
|
|
51
|
+
background-color: transparent;
|
|
52
|
+
cursor: not-allowed;
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
background-color: transparent;
|
|
52
|
-
cursor: not-allowed;
|
|
53
|
-
}
|
|
54
|
+
}
|
|
55
|
+
&.is-aborted {
|
|
56
|
+
color: var(--ac-gray-light);
|
|
57
|
+
&:hover {
|
|
58
|
+
background-color: transparent;
|
|
59
|
+
cursor: not-allowed;
|
|
54
60
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
}
|
|
62
|
+
&.is-running,
|
|
63
|
+
&.is-started {
|
|
64
|
+
i {
|
|
65
|
+
color: var(--ac-primary);
|
|
66
|
+
animation-name: spin;
|
|
67
|
+
animation-duration: 1000ms;
|
|
68
|
+
animation-iteration-count: infinite;
|
|
69
|
+
animation-timing-function: linear;
|
|
61
70
|
}
|
|
62
|
-
&.is-running,
|
|
63
|
-
&.is-started {
|
|
64
|
-
i {
|
|
65
|
-
color: var(--ac-primary);
|
|
66
|
-
animation-name: spin;
|
|
67
|
-
animation-duration: 1000ms;
|
|
68
|
-
animation-iteration-count: infinite;
|
|
69
|
-
animation-timing-function: linear;
|
|
70
|
-
}
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
to {
|
|
77
|
-
transform: rotate(360deg);
|
|
78
|
-
}
|
|
72
|
+
@keyframes spin {
|
|
73
|
+
from {
|
|
74
|
+
transform: rotate(0deg);
|
|
79
75
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
i {
|
|
83
|
-
color: #158748;
|
|
76
|
+
to {
|
|
77
|
+
transform: rotate(360deg);
|
|
84
78
|
}
|
|
85
79
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
}
|
|
81
|
+
&.is-success {
|
|
82
|
+
i {
|
|
83
|
+
color: #158748;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
&.is-failed {
|
|
87
|
+
i {
|
|
88
|
+
color: #ff3729;
|
|
90
89
|
}
|
|
91
90
|
}
|
|
91
|
+
}
|
|
92
92
|
</style>
|
|
@@ -111,7 +111,7 @@ import {
|
|
|
111
111
|
watchEffect,
|
|
112
112
|
} from "vue";
|
|
113
113
|
import { defineAsyncComponent, ref } from "vue";
|
|
114
|
-
import { Task, TaskLog } from "
|
|
114
|
+
import { Task, TaskLog } from "../../../typings/long-running-tasks.ts";
|
|
115
115
|
import { Subscription, StringCodec } from "nats.ws";
|
|
116
116
|
|
|
117
117
|
const Modal = defineAsyncComponent(() => import("../modal/Modal.vue"));
|
|
@@ -200,7 +200,7 @@ async function subscribeToChannel(channelId: string) {
|
|
|
200
200
|
if (subscription) {
|
|
201
201
|
// listen to channel events
|
|
202
202
|
for await (const msg of subscription) {
|
|
203
|
-
console.log("
|
|
203
|
+
console.log("Long Running Tasks Modal=>");
|
|
204
204
|
console.log({ data: StringCodec().decode(msg.data) });
|
|
205
205
|
const log: TaskLog = JSON.parse(StringCodec().decode(msg.data));
|
|
206
206
|
console.log({ log });
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
@mouseenter="notificationPanelOpen = true"
|
|
4
|
+
@mouseleave="notificationPanelOpen = false"
|
|
5
|
+
>
|
|
6
|
+
<button class="button ac-nav-button">
|
|
7
|
+
<span v-if="unreadCount">{{ unreadCount }}</span>
|
|
8
|
+
<i
|
|
9
|
+
class="fa fa-bell"
|
|
10
|
+
:class="{ 'ac-shake': unreadCount }"
|
|
11
|
+
aria-hidden="true"
|
|
12
|
+
></i>
|
|
13
|
+
</button>
|
|
14
|
+
<div class="ac-menu-content is-notification">
|
|
15
|
+
<div class="notification-header">
|
|
16
|
+
<div class="left-content">
|
|
17
|
+
<p>
|
|
18
|
+
Notifications <span>({{ notifications.length }})</span>
|
|
19
|
+
</p>
|
|
20
|
+
</div>
|
|
21
|
+
<div class="right-content"></div>
|
|
22
|
+
</div>
|
|
23
|
+
<div :key="notificationPanelOpen ? 1 : 0" class="notification-body">
|
|
24
|
+
<transition-group v-if="notifications.length" name="slide-right">
|
|
25
|
+
<notification-item
|
|
26
|
+
v-for="notification in notifications"
|
|
27
|
+
:key="`${notification.id}${unreadCount}`"
|
|
28
|
+
:notification="notification"
|
|
29
|
+
/>
|
|
30
|
+
</transition-group>
|
|
31
|
+
<span v-else class="single-notification-item"
|
|
32
|
+
>No new notifications</span
|
|
33
|
+
>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
38
|
+
|
|
39
|
+
<script setup lang="ts">
|
|
40
|
+
import { NatsConnection, StringCodec, Subscription } from "nats.ws";
|
|
41
|
+
import {
|
|
42
|
+
computed,
|
|
43
|
+
defineAsyncComponent,
|
|
44
|
+
getCurrentInstance,
|
|
45
|
+
ref,
|
|
46
|
+
Ref,
|
|
47
|
+
watch,
|
|
48
|
+
} from "vue";
|
|
49
|
+
import { TaskLog } from "../../../typings/long-running-tasks";
|
|
50
|
+
import { Notification } from "../../../typings/notification";
|
|
51
|
+
|
|
52
|
+
const NotificationItem = defineAsyncComponent(
|
|
53
|
+
() => import("./NotificationItem.vue")
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const notifications: Ref<Notification[]> = ref([]);
|
|
57
|
+
const notificationsRead = ref(0);
|
|
58
|
+
const unreadCount = computed(
|
|
59
|
+
() => notifications.value.length - notificationsRead.value
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const notificationPanelOpen = ref(false);
|
|
63
|
+
watch(notificationPanelOpen, (n) => {
|
|
64
|
+
if (n) notificationsRead.value = notifications.value.length;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function addNewNotification(notification: Notification) {
|
|
68
|
+
notifications.value.unshift(notification);
|
|
69
|
+
if (notificationPanelOpen.value) {
|
|
70
|
+
notificationsRead.value = notifications.value.length;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const app = getCurrentInstance();
|
|
75
|
+
const $nats: NatsConnection = app?.appContext.config.globalProperties.$nc;
|
|
76
|
+
let subscription: Subscription;
|
|
77
|
+
|
|
78
|
+
async function subscribeToNotifcations() {
|
|
79
|
+
subscription = $nats?.subscribe("notifications");
|
|
80
|
+
console.log("Started listening to Notifications");
|
|
81
|
+
|
|
82
|
+
if (subscription) {
|
|
83
|
+
// listen to channel events
|
|
84
|
+
for await (const msg of subscription) {
|
|
85
|
+
console.log("notifications ===>");
|
|
86
|
+
console.log({ data: StringCodec().decode(msg.data) });
|
|
87
|
+
const log: TaskLog = JSON.parse(StringCodec().decode(msg.data));
|
|
88
|
+
console.log({ log });
|
|
89
|
+
const currentTime = new Date().getTime();
|
|
90
|
+
addNewNotification({ ...log, id: currentTime, time: currentTime });
|
|
91
|
+
msg.respond();
|
|
92
|
+
}
|
|
93
|
+
console.log("Stopped listening to Notifications");
|
|
94
|
+
console.log("Closed Channel Notifications");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
subscribeToNotifcations();
|
|
98
|
+
</script>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<a class="single-notification-item is-complete">
|
|
3
|
+
<p>
|
|
4
|
+
{{ notification.msg }}
|
|
5
|
+
</p>
|
|
6
|
+
<div class="notification-status">
|
|
7
|
+
<p
|
|
8
|
+
:class="{
|
|
9
|
+
'is-success': notification.status === 'Success',
|
|
10
|
+
'is-danger': notification.status === 'Failed',
|
|
11
|
+
'is-info':
|
|
12
|
+
notification.status === 'Started' ||
|
|
13
|
+
notification.status === 'Running',
|
|
14
|
+
'is-warning': notification.status === 'Pending',
|
|
15
|
+
}"
|
|
16
|
+
>
|
|
17
|
+
<i
|
|
18
|
+
class="fa mr-5"
|
|
19
|
+
:class="{
|
|
20
|
+
'fa-check': notification.status === 'Success',
|
|
21
|
+
'fa-exclamation-triangle': notification.status === 'Failed',
|
|
22
|
+
'fa-info-circle':
|
|
23
|
+
notification.status === 'Started' ||
|
|
24
|
+
notification.status === 'Pending' ||
|
|
25
|
+
notification.status === 'Running',
|
|
26
|
+
}"
|
|
27
|
+
/>
|
|
28
|
+
{{ notification.status }}
|
|
29
|
+
</p>
|
|
30
|
+
<p>{{ notificationTime }} ago</p>
|
|
31
|
+
</div>
|
|
32
|
+
</a>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script setup lang="ts">
|
|
36
|
+
import { computed, toRefs } from 'vue'
|
|
37
|
+
import { Notification } from '../../../typings/notification'
|
|
38
|
+
import TimeConvert from '../../../plugins/time-convert'
|
|
39
|
+
|
|
40
|
+
const props = withDefaults(defineProps<{ notification: Notification }>(), {
|
|
41
|
+
notification: () => ({
|
|
42
|
+
id: 0,
|
|
43
|
+
status: 'Pending',
|
|
44
|
+
time: 0,
|
|
45
|
+
}),
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const { notification } = toRefs(props)
|
|
49
|
+
const notificationTime = computed(() =>
|
|
50
|
+
TimeConvert.getDayDifferences({ past: notification.value.time })
|
|
51
|
+
)
|
|
52
|
+
</script>
|