Skip to content

Commit 7ea7d84

Browse files
committed
chore: fix usage of deprecated functions and adjust code style
This solves 57 ESLint warnings by replacing deprecated code with `@nextcloud/` libraries, as well as adding missing type information, importing jQuery instead of relying on global one, and the same with Moment.js. Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent a740e60 commit 7ea7d84

File tree

11 files changed

+32
-29
lines changed

11 files changed

+32
-29
lines changed

apps/files_sharing/src/components/SharingEntryLink.vue

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@
156156
:share="share" />
157157

158158
<!-- external legacy sharing via url (social...) -->
159-
<NcActionLink v-for="({ icon, url, name }, index) in externalLegacyLinkActions"
160-
:key="index"
159+
<NcActionLink v-for="({ icon, url, name }, actionIndex) in externalLegacyLinkActions"
160+
:key="actionIndex"
161161
:href="url(shareLink)"
162162
:icon="icon"
163163
target="_blank">
@@ -213,11 +213,12 @@
213213

214214
<script>
215215
import { emit } from '@nextcloud/event-bus'
216-
import { generateUrl } from '@nextcloud/router'
216+
import { generateUrl, getBaseUrl } from '@nextcloud/router'
217217
import { showError, showSuccess } from '@nextcloud/dialogs'
218-
import { Type as ShareTypes } from '@nextcloud/sharing'
219-
import Vue from 'vue'
218+
import { ShareType } from '@nextcloud/sharing'
220219
import VueQrcode from '@chenfengyuan/vue-qrcode'
220+
import moment from '@nextcloud/moment'
221+
import Vue from 'vue'
221222
222223
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
223224
import NcActionInput from '@nextcloud/vue/dist/Components/NcActionInput.js'
@@ -510,7 +511,7 @@ export default {
510511
* @return {string}
511512
*/
512513
shareLink() {
513-
return window.location.protocol + '//' + window.location.host + generateUrl('/s/') + this.share.token
514+
return generateUrl('/s/{toen}', { token: this.share.token }, { baseURL: getBaseUrl() })
514515
},
515516
516517
/**
@@ -553,7 +554,7 @@ export default {
553554
* @return {Array}
554555
*/
555556
externalLinkActions() {
556-
const filterValidAction = (action) => (action.shareType.includes(ShareTypes.SHARE_TYPE_LINK) || action.shareType.includes(ShareTypes.SHARE_TYPE_EMAIL)) && !action.advanced
557+
const filterValidAction = (action) => (action.shareType.includes(ShareType.Link) || action.shareType.includes(ShareType.Email)) && !action.advanced
557558
// filter only the registered actions for said link
558559
return this.ExternalShareActions.actions
559560
.filter(filterValidAction)
@@ -585,7 +586,7 @@ export default {
585586
}
586587
587588
const shareDefaults = {
588-
share_type: ShareTypes.SHARE_TYPE_LINK,
589+
share_type: ShareType.Link,
589590
}
590591
if (this.config.isDefaultExpireDateEnforced) {
591592
// default is empty string if not set
@@ -671,7 +672,7 @@ export default {
671672
const path = (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
672673
const options = {
673674
path,
674-
shareType: ShareTypes.SHARE_TYPE_LINK,
675+
shareType: ShareType.Link,
675676
password: share.password,
676677
expireDate: share.expireDate,
677678
attributes: JSON.stringify(this.fileInfo.shareAttributes),

apps/settings/src/admin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5+
6+
import $ from 'jquery'
7+
58
window.addEventListener('DOMContentLoaded', () => {
69
$('#loglevel').change(function() {
710
$.post(OC.generateUrl('/settings/admin/log/level'), { level: $(this).val() }, () => {

apps/settings/src/components/Users/UserRow.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,6 @@ export default {
621621
622622
/**
623623
* Set user displayName
624-
*
625-
* @param {string} displayName The display name
626624
*/
627625
async updateDisplayName() {
628626
this.loading.displayName = true
@@ -643,8 +641,6 @@ export default {
643641
644642
/**
645643
* Set user password
646-
*
647-
* @param {string} password The email address
648644
*/
649645
async updatePassword() {
650646
this.loading.password = true
@@ -668,8 +664,6 @@ export default {
668664
669665
/**
670666
* Set user mailAddress
671-
*
672-
* @param {string} mailAddress The email address
673667
*/
674668
async updateEmail() {
675669
this.loading.mailAddress = true

core/src/OC/l10n.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const L10n = {
4040
* @deprecated 26.0.0 use `register` from https://www.npmjs.com/package/@nextcloud/l10
4141
*
4242
* @param {string} appName name of the app
43-
* @param {Object<string, string>} bundle bundle
43+
* @param {Record<string, string>} bundle bundle
4444
*/
4545
register,
4646

core/src/OC/notification.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export default {
120120
* Updates (replaces) a sanitized notification.
121121
*
122122
* @param {string} text Message to display
123-
* @return {jQuery} JQuery element for notificaiton row
123+
* @return {jQuery} JQuery element for notification row
124124
* @deprecated 17.0.0 use the `@nextcloud/dialogs` package
125125
*/
126126
showUpdate(text) {
@@ -141,7 +141,7 @@ export default {
141141
* @param {number} [options.timeout] timeout in seconds, if this is 0 it will show the message permanently
142142
* @param {boolean} [options.isHTML] an indicator for HTML notifications (true) or text (false)
143143
* @param {string} [options.type] notification type
144-
* @return {JQuery} the toast element
144+
* @return {jQuery} the toast element
145145
* @deprecated 17.0.0 use the `@nextcloud/dialogs` package
146146
*/
147147
showTemporary(text, options) {

core/src/OC/query-string.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import $ from 'jquery'
99
* Parses a URL query string into a JS map
1010
*
1111
* @param {string} queryString query string in the format param1=1234&param2=abcde&param3=xyz
12-
* @return {Object<string, string>} map containing key/values matching the URL parameters
12+
* @return {Record<string, string>} map containing key/values matching the URL parameters
1313
*/
1414
export const parse = queryString => {
1515
let pos
@@ -58,7 +58,7 @@ export const parse = queryString => {
5858
/**
5959
* Builds a URL query from a JS map.
6060
*
61-
* @param {Object<string, string>} params map containing key/values matching the URL parameters
61+
* @param {Record<string, string>} params map containing key/values matching the URL parameters
6262
* @return {string} String containing a URL query (without question) mark
6363
*/
6464
export const build = params => {

core/src/OC/xhr-error.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ import $ from 'jquery'
88

99
import OC from './index.js'
1010
import Notification from './notification.js'
11+
import { getCurrentUser } from '@nextcloud/auth'
12+
import { showWarning } from '@nextcloud/dialogs'
1113

1214
/**
1315
* Warn users that the connection to the server was lost temporarily
1416
*
15-
* This function is throttled to prevent stacked notfications.
17+
* This function is throttled to prevent stacked notifications.
1618
* After 7sec the first notification is gone, then we can show another one
1719
* if necessary.
1820
*/
1921
export const ajaxConnectionLostHandler = _.throttle(() => {
20-
Notification.showTemporary(t('core', 'Connection to server lost'))
22+
showWarning(t('core', 'Connection to server lost'))
2123
}, 7 * 1000, { trailing: false })
2224

2325
/**
@@ -28,13 +30,13 @@ export const ajaxConnectionLostHandler = _.throttle(() => {
2830
*/
2931
export const processAjaxError = xhr => {
3032
// purposefully aborted request ?
31-
// OC._userIsNavigatingAway needed to distinguish ajax calls cancelled by navigating away
32-
// from calls cancelled by failed cross-domain ajax due to SSO redirect
33+
// OC._userIsNavigatingAway needed to distinguish Ajax calls cancelled by navigating away
34+
// from calls cancelled by failed cross-domain Ajax due to SSO redirect
3335
if (xhr.status === 0 && (xhr.statusText === 'abort' || xhr.statusText === 'timeout' || OC._reloadCalled)) {
3436
return
3537
}
3638

37-
if (_.contains([302, 303, 307, 401], xhr.status) && OC.currentUser) {
39+
if ([302, 303, 307, 401].includes(xhr.status) && getCurrentUser()) {
3840
// sometimes "beforeunload" happens later, so need to defer the reload a bit
3941
setTimeout(function() {
4042
if (!OC._userIsNavigatingAway && !OC._reloadCalled) {

core/src/OCP/collaboration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import escapeHTML from 'escape-html'
77

88
/**
99
* @typedef TypeDefinition
10-
* @function {Function} action This action is executed to let the user select a resource
10+
* @function action This action is executed to let the user select a resource
1111
* @param {string} icon Contains the icon css class for the type
1212
* @function Object() { [native code] }
1313
*/

core/src/OCP/toast.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
showWarning,
1111
} from '@nextcloud/dialogs'
1212

13+
/** @typedef {import('toastify-js')} Toast */
14+
1315
export default {
1416
/**
1517
* @deprecated 19.0.0 use `showSuccess` from the `@nextcloud/dialogs` package instead

core/src/jquery/contactsmenu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import $ from 'jquery'
77

8-
import OC from '../OC/index.js'
8+
import { generateUrl } from '@nextcloud/router'
99
import { isA11yActivation } from '../Util/a11y.js'
1010

1111
const LIST = ''
@@ -51,7 +51,7 @@ $.fn.contactsMenu = function(shareWith, shareType, appendTo) {
5151
}
5252

5353
$list.addClass('loaded')
54-
$.ajax(OC.generateUrl('/contactsmenu/findOne'), {
54+
$.ajax(generateUrl('/contactsmenu/findOne'), {
5555
method: 'POST',
5656
data: {
5757
shareType,

0 commit comments

Comments
 (0)