Skip to content

Commit

Permalink
Replace moment.js date with Date Object.
Browse files Browse the repository at this point in the history
Replace vue2-datepicker with native date picker for expiration date.

Signed-off-by: julia.kirschenheuter <julia.kirschenheuter@nextcloud.com>
  • Loading branch information
JuliaKirschenheuter committed Oct 4, 2022
1 parent b57115d commit 56c8106
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 103 deletions.
32 changes: 13 additions & 19 deletions apps/files_sharing/src/components/SharingEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,15 @@
</NcActionCheckbox>
<NcActionInput v-if="hasExpirationDate"
ref="expireDate"
v-tooltip.auto="{
content: errors.expireDate,
show: errors.expireDate,
trigger: 'manual'
}"
:is-native-picker="true"
:hide-label="true"
:class="{ error: errors.expireDate}"
:disabled="saving"
:lang="lang"
:value="share.expireDate"
value-type="format"
icon="icon-calendar-dark"
type="date"
:disabled-date="disabledDate"
@update:value="onExpirationChange">
:min="dateTomorrow"
:max="dateMaxEnforced"
@input="onExpirationChange">
{{ t('files_sharing', 'Enter a date') }}
</NcActionInput>

Expand Down Expand Up @@ -380,21 +375,20 @@ export default {
},
set(enabled) {
this.share.expireDate = enabled
? this.config.defaultInternalExpirationDateString !== ''
? this.config.defaultInternalExpirationDateString
: moment().format('YYYY-MM-DD')
? this.config.defaultInternalExpirationDate !== ''
? this.config.defaultInternalExpirationDate
: new Date()
: ''
},
},
dateMaxEnforced() {
if (!this.isRemote) {
return this.config.isDefaultInternalExpireDateEnforced
&& moment().add(1 + this.config.defaultInternalExpireDate, 'days')
} else {
return this.config.isDefaultRemoteExpireDateEnforced
&& moment().add(1 + this.config.defaultRemoteExpireDate, 'days')
if (!this.isRemote && this.config.isDefaultInternalExpireDateEnforced) {
return new Date(new Date().setDate(new Date().getDate() + 1 + this.config.defaultInternalExpireDate))
} else if (this.config.isDefaultRemoteExpireDateEnforced) {
return new Date(new Date().setDate(new Date().getDate() + 1 + this.config.defaultRemoteExpireDate))
}
return null
},
/**
Expand Down
47 changes: 18 additions & 29 deletions apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,13 @@
</NcActionText>
<NcActionInput v-if="pendingExpirationDate"
v-model="share.expireDate"
v-tooltip.auto="{
content: errors.expireDate,
show: errors.expireDate,
trigger: 'manual',
defaultContainer: '#app-sidebar'
}"
class="share-link-expire-date"
:disabled="saving"

:lang="lang"
icon=""
:is-native-picker="true"
:hide-label="true"
type="date"
value-type="format"
:disabled-date="disabledDate">
:min="dateTomorrow"
:max="dateMaxEnforced">
<!-- let's not submit when picked, the user
might want to still edit or copy the password -->
{{ t('files_sharing', 'Enter a date') }}
Expand Down Expand Up @@ -220,22 +213,16 @@
</NcActionCheckbox>
<NcActionInput v-if="hasExpirationDate"
ref="expireDate"
v-tooltip.auto="{
content: errors.expireDate,
show: errors.expireDate,
trigger: 'manual',
defaultContainer: '#app-sidebar'
}"
:is-native-picker="true"
:hide-label="true"
class="share-link-expire-date"
:class="{ error: errors.expireDate}"
:disabled="saving"
:lang="lang"
:value="share.expireDate"
value-type="format"
icon="icon-calendar-dark"
type="date"
:disabled-date="disabledDate"
@update:value="onExpirationChange">
:min="dateTomorrow"
:max="dateMaxEnforced"
@input="onExpirationChange">
{{ t('files_sharing', 'Enter a date') }}
</NcActionInput>

Expand Down Expand Up @@ -435,20 +422,22 @@ export default {
|| !!this.share.expireDate
},
set(enabled) {
let dateString = moment(this.config.defaultExpirationDateString)
if (!dateString.isValid()) {
dateString = moment()
let defaultExpirationDate = this.config.defaultExpirationDate
if (!defaultExpirationDate) {
defaultExpirationDate = new Date()
}
this.share.state.expiration = enabled
? dateString.format('YYYY-MM-DD')
? defaultExpirationDate
: ''
console.debug('Expiration date status', enabled, this.share.expireDate)
},
},
dateMaxEnforced() {
return this.config.isDefaultExpireDateEnforced
&& moment().add(1 + this.config.defaultExpireDate, 'days')
if (this.config.isDefaultExpireDateEnforced) {
return new Date(new Date().setDate(new Date().getDate() + 1 + this.config.defaultExpireDate))
}
return null
},
/**
Expand Down Expand Up @@ -631,7 +620,7 @@ export default {
if (this.config.isDefaultExpireDateEnforced) {
// default is empty string if not set
// expiration is the share object key, not expireDate
shareDefaults.expiration = this.config.defaultExpirationDateString
shareDefaults.expiration = this.config.defaultExpirationDate
}
if (this.config.enableLinkPasswordByDefault) {
shareDefaults.password = await GeneratePassword()
Expand Down
26 changes: 5 additions & 21 deletions apps/files_sharing/src/mixins/SharesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default {
},

dateTomorrow() {
return moment().add(1, 'days')
return new Date(new Date().setDate(new Date().getDate() + 1))
},

// Datepicker language
Expand Down Expand Up @@ -142,7 +142,7 @@ export default {
}
}
if (share.expirationDate) {
const date = moment(share.expirationDate)
const date = share.expirationDate
if (!date.isValid()) {
return false
}
Expand All @@ -151,16 +151,12 @@ export default {
},

/**
* ActionInput can be a little tricky to work with.
* Since we expect a string and not a Date,
* we need to process the value here
* Save given value to expireDate and trigger queueUpdate
*
* @param {Date} date js date to be parsed by moment.js
* @param {Date} date
*/
onExpirationChange(date) {
// format to YYYY-MM-DD
const value = moment(date).format('YYYY-MM-DD')
this.share.expireDate = value
this.share.expireDate = date
this.queueUpdate('expireDate')
},

Expand Down Expand Up @@ -318,17 +314,5 @@ export default {
debounceQueueUpdate: debounce(function(property) {
this.queueUpdate(property)
}, 500),

/**
* Returns which dates are disabled for the datepicker
*
* @param {Date} date date to check
* @return {boolean}
*/
disabledDate(date) {
const dateMoment = moment(date)
return (this.dateTomorrow && dateMoment.isBefore(this.dateTomorrow, 'day'))
|| (this.dateMaxEnforced && dateMoment.isSameOrAfter(this.dateMaxEnforced, 'day'))
},
},
}
9 changes: 4 additions & 5 deletions apps/files_sharing/src/models/Share.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ export default class Share {
}

/**
* Get the expiration date as a string format
* Get the expiration date
*
* @return {string}
* @return {Date|null}
* @readonly
* @memberof Share
*/
Expand All @@ -259,10 +259,9 @@ export default class Share {
}

/**
* Set the expiration date as a string format
* e.g. YYYY-MM-DD
* Set the expiration date
*
* @param {string} date the share expiration date
* @param {Date|null} date the share expiration date
* @memberof Share
*/
set expireDate(date) {
Expand Down
51 changes: 25 additions & 26 deletions apps/files_sharing/src/services/ConfigService.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,57 +60,45 @@ export default class Config {
}

/**
* Get the default link share expiration date as string
* Get the default link share expiration date
*
* @return {string}
* @return {Date|null}
* @readonly
* @memberof Config
*/
get defaultExpirationDateString() {
let expireDateString = ''
get defaultExpirationDate() {
if (this.isDefaultExpireDateEnabled) {
const date = window.moment.utc()
const expireAfterDays = this.defaultExpireDate
date.add(expireAfterDays, 'days')
expireDateString = date.format('YYYY-MM-DD')
return new Date(new Date().setDate(new Date().getDate() + this.defaultExpireDate))
}
return expireDateString
return null
}

/**
* Get the default internal expiration date as string
* Get the default internal expiration date
*
* @return {string}
* @return {Date|null}
* @readonly
* @memberof Config
*/
get defaultInternalExpirationDateString() {
let expireDateString = ''
get defaultInternalExpirationDate() {
if (this.isDefaultInternalExpireDateEnabled) {
const date = window.moment.utc()
const expireAfterDays = this.defaultInternalExpireDate
date.add(expireAfterDays, 'days')
expireDateString = date.format('YYYY-MM-DD')
return new Date(new Date().setDate(new Date().getDate() + this.defaultInternalExpireDate))
}
return expireDateString
return null
}

/**
* Get the default remote expiration date as string
* Get the default remote expiration date
*
* @return {string}
* @return {Date|null}
* @readonly
* @memberof Config
*/
get defaultRemoteExpirationDateString() {
let expireDateString = ''
if (this.isDefaultRemoteExpireDateEnabled) {
const date = window.moment.utc()
const expireAfterDays = this.defaultRemoteExpireDate
date.add(expireAfterDays, 'days')
expireDateString = date.format('YYYY-MM-DD')
return new Date(new Date().setDate(new Date().getDate() + this.defaultRemoteExpireDate))
}
return expireDateString
return null
}

/**
Expand Down Expand Up @@ -190,6 +178,17 @@ export default class Config {
return OC.appConfig.core.defaultInternalExpireDateEnabled === true
}

/**
* Is there a default expiration date for new remote shares ?
*
* @return {boolean}
* @readonly
* @memberof Config
*/
get isDefaultRemoteExpireDateEnabled() {
return OC.appConfig.core.defaultRemoteExpireDateEnabled === true
}

/**
* Are users on this server allowed to send shares to other servers ?
*
Expand Down
4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-files_sharing_tab.js.map

Large diffs are not rendered by default.

0 comments on commit 56c8106

Please sign in to comment.