Skip to content

Commit

Permalink
Move duedate to separate component
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Jul 11, 2020
1 parent e804a9e commit 37196bb
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 120 deletions.
11 changes: 4 additions & 7 deletions src/components/cards/CardBadges.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->

<template>
<div class="badges">
<div class="badges" v-if="card">
<div v-if="card.commentsUnread > 0" class="icon icon-comment" />

<div v-if="card.description && checkListCount > 0" class="card-tasks icon icon-checkmark">
Expand All @@ -34,7 +34,7 @@

<AvatarList :users="card.assignedUsers" />

<CardMenu :id="id" />
<CardMenu :id="card.id" />
</div>
</template>
<script>
Expand All @@ -45,8 +45,8 @@ export default {
name: 'CardBadges',
components: { AvatarList, CardMenu },
props: {
id: {
type: Number,
card: {
type: Object,
default: null,
},
},
Expand All @@ -57,9 +57,6 @@ export default {
checkListCheckedCount() {
return (this.card.description.match(/^\s*(\*|-|(\d\.))\s+\[\s*x\s*\](.*)$/gim) || []).length
},
card() {
return this.$store.getters.cardById(this.id)
},
},
}
</script>
Expand Down
122 changes: 9 additions & 113 deletions src/components/cards/CardItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,11 @@
<input type="button" class="icon-confirm" @click="finishedEdit(card)">
</form>

<div v-if="!editing" class="duedate right">
<transition name="zoom">
<div v-if="card.duedate" :class="dueIcon">
<span>{{ relativeDate }}</span>
</div>
</transition>
</div>
<DueDate v-if="!editing" :card="card" />

<CardMenu v-if="!editing && compactMode" :id="id" class="right" />
</div>
<transition-group v-if="card.labels.length"
<transition-group v-if="card.labels && card.labels.length"
name="zoom"
tag="ul"
class="labels"
Expand All @@ -67,7 +61,7 @@
</li>
</transition-group>
<div v-show="!compactMode" class="card-controls compact-item" @click="openCard">
<CardBadges :id="id" />
<CardBadges :card="card" />
</div>
</div>
</AttachmentDragAndDrop>
Expand All @@ -76,16 +70,16 @@
<script>
import ClickOutside from 'vue-click-outside'
import { mapState, mapGetters } from 'vuex'
import moment from 'moment'
import CardBadges from './CardBadges'
import Color from '../../mixins/color'
import labelStyle from '../../mixins/labelStyle'
import AttachmentDragAndDrop from '../AttachmentDragAndDrop'
import CardMenu from './CardMenu'
import DueDate from './badges/DueDate'

export default {
name: 'CardItem',
components: { CardBadges, AttachmentDragAndDrop, CardMenu },
components: { CardBadges, AttachmentDragAndDrop, CardMenu, DueDate },
directives: {
ClickOutside,
},
Expand Down Expand Up @@ -116,31 +110,11 @@ export default {
return this.$store.getters.cardById(this.id)
},
currentCard() {
return this.$route.params.cardId === this.id
},
relativeDate() {
const diff = moment(this.$root.time).diff(this.card.duedate, 'seconds')
if (diff >= 0 && diff < 45) {
return t('core', 'seconds ago')
}
return moment(this.card.duedate).fromNow()
},
dueIcon() {
const days = Math.floor(moment(this.card.duedate).diff(this.$root.time, 'seconds') / 60 / 60 / 24)
if (days < 0) {
return 'icon-calendar due icon overdue'
}
if (days === 0) {
return 'icon-calendar-dark due icon now'
if (this.$route) {
return this.$route.params.cardId === this.id
}
if (days === 1) {
return 'icon-calendar-dark due icon next'
}
return 'icon-calendar-dark due icon'
},
dueDateTooltip() {
return moment(this.card.duedate).format('LLLL')
},

},
methods: {
openCard() {
Expand Down Expand Up @@ -213,42 +187,7 @@ export default {
}
}

.labels {
flex-grow: 1;
flex-shrink: 1;
min-width: 0;
display: flex;
flex-direction: row;
margin-left: $card-padding;
margin-right: $card-padding;
margin-top: -5px;

li {
flex-grow: 0;
flex-shrink: 1;
display: flex;
flex-direction: row;
overflow: hidden;
padding: 0px 5px;
border-radius: 15px;
font-size: 85%;
margin-right: 3px;
margin-bottom: 3px;

&:hover {
overflow: unset;
}

span {
flex-grow: 0;
flex-shrink: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
}
@import './../../css/labels';

.card-controls {
display: flex;
Expand All @@ -267,49 +206,6 @@ export default {
align-items: flex-start;
}

.icon.due {
background-position: 4px center;
border-radius: 3px;
margin-top: 9px;
margin-bottom: 9px;
padding: 3px 4px;
padding-right: 0;
font-size: 90%;
display: flex;
align-items: center;
opacity: .5;
flex-shrink: 1;
z-index: 2;

.icon {
background-size: contain;
}

&.overdue {
background-color: var(--color-error);
color: var(--color-primary-text);
opacity: .7;
padding: 3px 4px;
}
&.now {
background-color: var(--color-warning);
opacity: .7;
padding: 3px 4px;
}
&.next {
background-color: var(--color-background-dark);
opacity: .7;
padding: 3px 4px;
}

span {
margin-left: 20px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
}

.compact {
min-height: 44px;

Expand Down
115 changes: 115 additions & 0 deletions src/components/cards/badges/DueDate.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<!--
- @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
-
- @author Julius Härtl <[email protected]>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->

<template>
<div class="duedate" v-if="card">
<transition name="zoom">
<div v-if="card.duedate" :class="dueIcon">
<span>{{ relativeDate }}</span>
</div>
</transition>
</div>
</template>

<script>
import moment from '@nextcloud/moment'

export default {
name: 'DueDate',
props: {
card: {
type: Object,
default: null,
},
},
computed: {
dueIcon() {
const days = Math.floor(moment(this.card.duedate).diff(this.$root.time, 'seconds') / 60 / 60 / 24)
if (days < 0) {
return 'icon-calendar due icon overdue'
}
if (days === 0) {
return 'icon-calendar-dark due icon now'
}
if (days === 1) {
return 'icon-calendar-dark due icon next'
}
return 'icon-calendar-dark due icon'
},
relativeDate() {
const diff = moment(this.$root.time).diff(this.card.duedate, 'seconds')
if (diff >= 0 && diff < 45) {
return t('core', 'seconds ago')
}
return moment(this.card.duedate).fromNow()
},
dueDateTooltip() {
return moment(this.card.duedate).format('LLLL')
},
}
}
</script>

<style lang="scss" coped>
.icon.due {
background-position: 4px center;
border-radius: 3px;
margin-top: 9px;
margin-bottom: 9px;
padding: 3px 4px;
padding-right: 0;
font-size: 90%;
display: flex;
align-items: center;
opacity: .5;
flex-shrink: 1;
z-index: 2;

.icon {
background-size: contain;
}

&.overdue {
background-color: var(--color-error);
color: var(--color-primary-text);
opacity: .7;
padding: 3px 4px;
}
&.now {
background-color: var(--color-warning);
opacity: .7;
padding: 3px 4px;
}
&.next {
background-color: var(--color-background-dark);
opacity: .7;
padding: 3px 4px;
}

span {
margin-left: 20px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
}
</style>
39 changes: 39 additions & 0 deletions src/css/labels.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
$card-spacing: 10px;
$card-padding: 10px;

.labels {
flex-grow: 1;
flex-shrink: 1;
min-width: 0;
display: flex;
flex-direction: row;
margin-left: $card-padding;
margin-right: $card-padding;
margin-top: -5px;

li {
flex-grow: 0;
flex-shrink: 1;
display: flex;
flex-direction: row;
overflow: hidden;
padding: 0px 5px;
border-radius: 15px;
font-size: 85%;
margin-right: 3px;
margin-bottom: 3px;

&:hover {
overflow: unset;
}

span {
flex-grow: 0;
flex-shrink: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
}

0 comments on commit 37196bb

Please sign in to comment.