Skip to content

Commit bac8c84

Browse files
committed
add poll status to widget
Signed-off-by: dartcafe <github@dartcafe.de>
1 parent a2a7a4d commit bac8c84

3 files changed

Lines changed: 77 additions & 12 deletions

File tree

lib/Provider/ReferenceProvider.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public function extractPollId(string $referenceText): int {
6161
public function resolveReference(string $referenceText): ?IReference {
6262
if ($this->matchReference($referenceText)) {
6363
$pollId = $this->extractPollId($referenceText);
64+
$expired = false;
65+
$expiry = 0;
66+
$participated = false;
67+
6468

6569
if ($pollId) {
6670
try {
@@ -70,6 +74,9 @@ public function resolveReference(string $referenceText): ?IReference {
7074
$ownerId = $poll->getUser()->getId();
7175
$ownerDisplayName = $poll->getUser()->getDisplayName();
7276
$url = $poll->getVoteUrl();
77+
$expired = $poll->getExpired();
78+
$expiry = $poll->getExpire();
79+
$participated = $poll->getCurrentUserVotes() ? true : false;
7380

7481
} catch (NotFoundException $e) {
7582
$pollId = 0;
@@ -105,6 +112,9 @@ public function resolveReference(string $referenceText): ?IReference {
105112
'ownerDisplayName' => $ownerDisplayName,
106113
'ownerId' => $ownerId,
107114
'url' => $url,
115+
'expired' => $expired,
116+
'expiry' => $expiry,
117+
'participated' => $participated,
108118
],
109119
]);
110120
return $reference;

src/components/PollList/PollItem.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<script setup lang="ts">
77
import { RouterLink } from 'vue-router'
88
import { computed } from 'vue'
9-
import moment from '@nextcloud/moment'
9+
import { DateTime } from 'luxon'
1010
import { t } from '@nextcloud/l10n'
1111
import {
1212
usePollStore,
@@ -41,12 +41,13 @@ const closeToClosing = computed(
4141
() =>
4242
!poll.status.isExpired
4343
&& poll.configuration.expire
44-
&& moment.unix(poll.configuration.expire).diff() < 86400000,
44+
&& DateTime.fromMillis(poll.configuration.expire * 1000).diffNow('hours')
45+
.hours < 36,
4546
)
4647
4748
const timeExpirationRelative = computed(() => {
4849
if (poll.configuration.expire) {
49-
return moment.unix(poll.configuration.expire).fromNow()
50+
return DateTime.fromMillis(poll.configuration.expire * 1000).toRelative()
5051
}
5152
return t('polls', 'never')
5253
})
@@ -67,14 +68,16 @@ const expiryClass = computed(() => {
6768
return StatusResults.Success
6869
})
6970
70-
const timeCreatedRelative = computed(() =>
71-
moment.unix(poll.status.created).fromNow(),
71+
const timeCreatedRelative = computed(
72+
() => DateTime.fromMillis(poll.status.created * 1000).toRelative() as string,
7273
)
7374
7475
const descriptionLine = computed(() => {
7576
if (poll.status.isArchived) {
76-
return t('polls', 'Archived {relativeTIme}', {
77-
relativeTIme: moment.unix(poll.status.archivedDate).fromNow(),
77+
return t('polls', 'Archived {relativeTime}', {
78+
relativeTime: DateTime.fromMillis(
79+
poll.status.archivedDate * 1000,
80+
).toRelative() as string,
7881
})
7982
}
8083
return t('polls', 'Started {relativeTime} from {ownerName}', {

src/views/Reference.vue

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
<script setup lang="ts">
77
import NcUserBubble from '@nextcloud/vue/components/NcUserBubble'
88
import { PollsAppIcon } from '../components/AppIcons'
9+
import ExpirationIcon from 'vue-material-design-icons/CalendarEnd.vue'
10+
import BadgeSmallDiv from '../components/Base/modules/BadgeSmallDiv.vue'
11+
import { t } from '@nextcloud/l10n'
12+
import { DateTime } from 'luxon'
13+
import { StatusResults } from '../Types'
914
1015
type RichObject = {
1116
id: number
@@ -16,32 +21,71 @@ type RichObject = {
1621
ownerDisplayName: string
1722
ownerId: string
1823
url: string
24+
participated: boolean
25+
expiry: number
26+
expired: boolean
1927
}
2028
}
2129
2230
interface Props {
2331
richObject?: RichObject
2432
}
25-
const { richObject = null } = defineProps<Props>()
33+
34+
const { richObject } = defineProps<Props>()
35+
// const expiryClass2 = (() => {
36+
// if (!richObject?.poll?.expiry) {
37+
// return ''
38+
// }
39+
// if (DateTime.fromMillis(richObject.poll.expiry * 1000).diffNow('hours').hours < 36) {
40+
// return StatusResults.Warning
41+
// }
42+
// return StatusResults.Success
43+
// })
44+
const expiryClass = richObject?.poll?.expiry
45+
? DateTime.fromMillis(richObject.poll.expiry * 1000).diffNow('hours').hours < 36
46+
? StatusResults.Warning
47+
: StatusResults.Success
48+
: ''
2649
</script>
2750

2851
<template>
2952
<div v-if="richObject" class="polls_widget">
3053
<div class="widget_header">
3154
<PollsAppIcon :size="20" class="title-icon" />
32-
<span class="title">
55+
<a class="title" :href="richObject.poll.url" target="_blank">
3356
{{ richObject.poll.title }}
34-
</span>
57+
</a>
58+
<BadgeSmallDiv v-if="richObject.poll.participated" class="success">
59+
{{ t('polls', 'participated') }}
60+
</BadgeSmallDiv>
61+
<BadgeSmallDiv v-else-if="richObject.poll.expired" class="error">
62+
{{ t('polls', 'closed') }}
63+
</BadgeSmallDiv>
64+
<BadgeSmallDiv
65+
v-else-if="richObject.poll.expiry > 0"
66+
:class="expiryClass">
67+
<template #icon>
68+
<ExpirationIcon :size="16" />
69+
</template>
70+
{{ DateTime.fromMillis(richObject.poll.expiry * 1000).toRelative() }}
71+
</BadgeSmallDiv>
3572
</div>
3673
<div class="description">
3774
<span class="clamped">
3875
{{ richObject.poll.description }}
3976
</span>
4077
</div>
41-
<div class="owner">
78+
<div class="widget_footer">
79+
<span>{{ t('polls', 'By:') }}</span>
4280
<NcUserBubble
4381
:user="richObject.poll.ownerId"
4482
:display-name="richObject.poll.ownerDisplayName" />
83+
<span
84+
v-if="richObject.poll.expiry > 0 && !richObject.poll.expired"
85+
class="expiration">
86+
{{ t('polls', 'Ends in') }}
87+
{{ DateTime.fromMillis(richObject.poll.expiry * 1000).toRelative() }}
88+
</span>
4589
</div>
4690
</div>
4791
</template>
@@ -50,17 +94,25 @@ const { richObject = null } = defineProps<Props>()
5094
.polls_widget {
5195
padding: 0.6rem;
5296
}
53-
.widget_header {
97+
.widget_header,
98+
.widget_footer {
5499
display: flex;
100+
column-gap: 0.3rem;
55101
}
56102
103+
.badge-small {
104+
flex: 0;
105+
}
57106
.polls_app_icon {
58107
flex: 0 0 1.4rem;
59108
}
60109
.title {
61110
flex: 1;
62111
font-weight: bold;
63112
padding-left: 0.6rem;
113+
text-wrap: nowrap;
114+
overflow: hidden;
115+
text-overflow: ellipsis;
64116
}
65117
.description {
66118
margin-left: 1.4rem;

0 commit comments

Comments
 (0)