|
67 | 67 | </NcSettingsSection> |
68 | 68 | </template> |
69 | 69 |
|
70 | | -<script> |
| 70 | +<script setup lang="ts"> |
71 | 71 | import axios from '@nextcloud/axios' |
72 | | -import { |
73 | | - mdiRefresh, |
74 | | -} from '@mdi/js' |
| 72 | +import { t } from '@nextcloud/l10n' |
75 | 73 | import Moment from '@nextcloud/moment' |
76 | 74 | import { generateOcsUrl } from '@nextcloud/router' |
77 | | -import { t } from '@nextcloud/l10n' |
| 75 | +import { mdiRefresh } from '@mdi/js' |
| 76 | +import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue' |
78 | 77 |
|
79 | 78 | import NcButton from '@nextcloud/vue/components/NcButton' |
80 | | -import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper' |
81 | 79 | import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch' |
| 80 | +import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper' |
82 | 81 | import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon' |
83 | 82 | import NcSettingsSection from '@nextcloud/vue/components/NcSettingsSection' |
84 | 83 |
|
85 | | -export default { |
86 | | - name: 'ActiveSignings', |
87 | | - components: { |
88 | | - NcButton, |
89 | | - NcSettingsSection, |
90 | | - NcIconSvgWrapper, |
91 | | - NcCheckboxRadioSwitch, |
92 | | - NcLoadingIcon, |
93 | | - }, |
94 | | - setup() { |
95 | | - return { |
96 | | - mdiRefresh, |
97 | | - } |
98 | | - }, |
99 | | - data() { |
100 | | - return { |
101 | | - signings: [], |
102 | | - loading: false, |
103 | | - autoRefresh: true, |
104 | | - lastUpdateTime: '', |
105 | | - refreshInterval: null, |
106 | | - } |
107 | | - }, |
108 | | - computed: { |
109 | | - // Auto-refresh every 10 seconds when enabled |
110 | | - shouldRefresh() { |
111 | | - return this.autoRefresh |
112 | | - }, |
113 | | - }, |
114 | | - watch: { |
115 | | - autoRefresh(newValue) { |
116 | | - if (newValue) { |
117 | | - this.startAutoRefresh() |
118 | | - } else { |
119 | | - this.stopAutoRefresh() |
120 | | - } |
121 | | - }, |
122 | | - }, |
123 | | - mounted() { |
124 | | - this.refresh() |
125 | | - if (this.autoRefresh) { |
126 | | - this.startAutoRefresh() |
| 84 | +type SigningItem = { |
| 85 | + id: number |
| 86 | + name: string |
| 87 | + signerDisplayName?: string |
| 88 | + signerEmail?: string |
| 89 | + updatedAt: number |
| 90 | +} |
| 91 | +
|
| 92 | +type OcsResponse = { |
| 93 | + data?: { |
| 94 | + ocs?: { |
| 95 | + data?: SigningItem[] |
127 | 96 | } |
128 | | - }, |
129 | | - beforeUnmount() { |
130 | | - this.stopAutoRefresh() |
131 | | - }, |
132 | | - methods: { |
133 | | - t, |
134 | | -
|
135 | | - async refresh() { |
136 | | - this.loading = true |
137 | | - try { |
138 | | - const response = await axios.get( |
139 | | - generateOcsUrl('/apps/libresign/api/v1/admin/active-signings') |
140 | | - ) |
141 | | - this.signings = response.data.ocs.data || [] |
142 | | - this.updateLastRefreshTime() |
143 | | - } catch (error) { |
144 | | - console.error('Failed to fetch active signings:', error) |
145 | | - this.signings = [] |
146 | | - } finally { |
147 | | - this.loading = false |
148 | | - } |
149 | | - }, |
150 | | -
|
151 | | - startAutoRefresh() { |
152 | | - if (this.refreshInterval) { |
153 | | - clearInterval(this.refreshInterval) |
154 | | - } |
155 | | - this.refreshInterval = setInterval(() => { |
156 | | - this.refresh() |
157 | | - }, 10000) // Refresh every 10 seconds |
158 | | - }, |
159 | | -
|
160 | | - stopAutoRefresh() { |
161 | | - if (this.refreshInterval) { |
162 | | - clearInterval(this.refreshInterval) |
163 | | - this.refreshInterval = null |
164 | | - } |
165 | | - }, |
166 | | -
|
167 | | - updateLastRefreshTime() { |
168 | | - this.lastUpdateTime = Moment().format('HH:mm:ss') |
169 | | - }, |
170 | | -
|
171 | | - formatTime(timestamp) { |
172 | | - return Moment(timestamp * 1000).fromNow() |
173 | | - }, |
174 | | -
|
175 | | - getFileUrl(fileId) { |
176 | | - // Build URL to view the file |
177 | | - return `/index.php/apps/files/?fileid=${fileId}` |
178 | | - }, |
179 | | - }, |
| 97 | + } |
180 | 98 | } |
| 99 | +
|
| 100 | +defineOptions({ |
| 101 | + name: 'ActiveSignings', |
| 102 | +}) |
| 103 | +
|
| 104 | +const signings = ref<SigningItem[]>([]) |
| 105 | +const loading = ref(false) |
| 106 | +const autoRefresh = ref(true) |
| 107 | +const lastUpdateTime = ref('') |
| 108 | +const refreshInterval = ref<ReturnType<typeof setInterval> | null>(null) |
| 109 | +
|
| 110 | +const shouldRefresh = computed(() => autoRefresh.value) |
| 111 | +
|
| 112 | +async function refresh() { |
| 113 | + loading.value = true |
| 114 | + try { |
| 115 | + const response = await axios.get( |
| 116 | + generateOcsUrl('/apps/libresign/api/v1/admin/active-signings'), |
| 117 | + ) as OcsResponse |
| 118 | + signings.value = response.data?.ocs?.data || [] |
| 119 | + updateLastRefreshTime() |
| 120 | + } catch (error) { |
| 121 | + console.error('Failed to fetch active signings:', error) |
| 122 | + signings.value = [] |
| 123 | + } finally { |
| 124 | + loading.value = false |
| 125 | + } |
| 126 | +} |
| 127 | +
|
| 128 | +function startAutoRefresh() { |
| 129 | + if (refreshInterval.value) { |
| 130 | + clearInterval(refreshInterval.value) |
| 131 | + } |
| 132 | + refreshInterval.value = setInterval(() => { |
| 133 | + void refresh() |
| 134 | + }, 10000) |
| 135 | +} |
| 136 | +
|
| 137 | +function stopAutoRefresh() { |
| 138 | + if (refreshInterval.value) { |
| 139 | + clearInterval(refreshInterval.value) |
| 140 | + refreshInterval.value = null |
| 141 | + } |
| 142 | +} |
| 143 | +
|
| 144 | +function updateLastRefreshTime() { |
| 145 | + lastUpdateTime.value = Moment().format('HH:mm:ss') |
| 146 | +} |
| 147 | +
|
| 148 | +function formatTime(timestamp: number) { |
| 149 | + return Moment(timestamp * 1000).fromNow() |
| 150 | +} |
| 151 | +
|
| 152 | +function getFileUrl(fileId: number) { |
| 153 | + return `/index.php/apps/files/?fileid=${fileId}` |
| 154 | +} |
| 155 | +
|
| 156 | +watch(autoRefresh, (newValue) => { |
| 157 | + if (newValue) { |
| 158 | + startAutoRefresh() |
| 159 | + } else { |
| 160 | + stopAutoRefresh() |
| 161 | + } |
| 162 | +}) |
| 163 | +
|
| 164 | +onMounted(() => { |
| 165 | + void refresh() |
| 166 | + if (autoRefresh.value) { |
| 167 | + startAutoRefresh() |
| 168 | + } |
| 169 | +}) |
| 170 | +
|
| 171 | +onBeforeUnmount(() => { |
| 172 | + stopAutoRefresh() |
| 173 | +}) |
| 174 | +
|
| 175 | +defineExpose({ |
| 176 | + t, |
| 177 | + mdiRefresh, |
| 178 | + signings, |
| 179 | + loading, |
| 180 | + autoRefresh, |
| 181 | + lastUpdateTime, |
| 182 | + refreshInterval, |
| 183 | + shouldRefresh, |
| 184 | + refresh, |
| 185 | + startAutoRefresh, |
| 186 | + stopAutoRefresh, |
| 187 | + updateLastRefreshTime, |
| 188 | + formatTime, |
| 189 | + getFileUrl, |
| 190 | +}) |
181 | 191 | </script> |
182 | 192 |
|
183 | 193 | <style lang="scss" scoped> |
|
0 commit comments