Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor clean up to prevent circular dependency on OC.js #40536

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/files_versions/src/components/Version.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@
<form class="version-label-modal"
@submit.prevent="setVersionLabel(formVersionLabelValue)">
<label>
<div class="version-label-modal__title">{{ t('photos', 'Version name') }}</div>
<div class="version-label-modal__title">{{ t('files_versions', 'Version name') }}</div>
<NcTextField ref="labelInput"
:value.sync="formVersionLabelValue"
:placeholder="t('photos', 'Version name')"
:placeholder="t('files_versions', 'Version name')"
:label-outside="true" />
</label>

<div class="version-label-modal__info">
{{ t('photos', 'Named versions are persisted, and excluded from automatic cleanups when your storage quota is full.') }}
{{ t('files_versions', 'Named versions are persisted, and excluded from automatic cleanups when your storage quota is full.') }}
</div>

<div class="version-label-modal__actions">
Expand Down
32 changes: 0 additions & 32 deletions core/src/OC/admin.js

This file was deleted.

5 changes: 3 additions & 2 deletions core/src/OC/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
*/

import { getCapabilities as realGetCapabilities } from '@nextcloud/capabilities'
import logger from './logger.js'

/**
* Returns the capabilities
*
* @return {Array} capabilities
* @return {object} capabilities
*
* @since 14.0.0
*/
export const getCapabilities = () => {
OC.debug && console.warn('OC.getCapabilities is deprecated and will be removed in Nextcloud 21. See @nextcloud/capabilities')
logger.warn('OC.getCapabilities is deprecated and will be removed in Nextcloud 21. See @nextcloud/capabilities')
return realGetCapabilities()
}
12 changes: 6 additions & 6 deletions core/src/OC/contactsmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import _ from 'underscore'
import $ from 'jquery'
import { Collection, Model, View } from 'backbone'

import OC from './index.js'
import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl } from '@nextcloud/router'

/**
* @class Contact
Expand Down Expand Up @@ -361,9 +361,9 @@ const ContactsMenuView = View.extend({
contacts: viewData.contacts,
searchTerm: searchTerm,
contactsAppEnabled: viewData.contactsAppEnabled,
contactsAppURL: OC.generateUrl('/apps/contacts'),
canInstallApp: OC.isUserAdmin(),
contactsAppMgmtURL: OC.generateUrl('/settings/apps/social/contacts')
contactsAppURL: generateUrl('/apps/contacts'),
canInstallApp: getCurrentUser()?.isAdmin,
contactsAppMgmtURL: generateUrl('/settings/apps/social/contacts')
}))
this.$('#contactsmenu-contacts').html(list.$el)
},
Expand Down Expand Up @@ -427,7 +427,7 @@ ContactsMenu.prototype = {
* @returns {Promise}
*/
_getContacts: function(searchTerm) {
var url = OC.generateUrl('/contactsmenu/contacts')
var url = generateUrl('/contactsmenu/contacts')
return Promise.resolve($.ajax(url, {
method: 'POST',
data: {
Expand Down
16 changes: 9 additions & 7 deletions core/src/OC/dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ import $ from 'jquery'
import IconMove from '@mdi/svg/svg/folder-move.svg?raw'
import IconCopy from '@mdi/svg/svg/folder-multiple.svg?raw'

import OC from './index.js'
import { FilePickerType, getFilePickerBuilder } from '@nextcloud/dialogs'
import moment from '@nextcloud/moment'
import { formatFileSize } from '@nextcloud/files'
import { generateFilePath } from '@nextcloud/router'
import { basename } from 'path'

/**
Expand Down Expand Up @@ -608,12 +610,12 @@ const Dialogs = {
$conflict.data('data', data)

$conflict.find('.filename').text(original.name)
$originalDiv.find('.size').text(OC.Util.humanFileSize(original.size))
$originalDiv.find('.mtime').text(OC.Util.formatDate(original.mtime))
$originalDiv.find('.size').text(formatFileSize(original.size))
$originalDiv.find('.mtime').text(moment(original.mtime).format('LLL'))
// ie sucks
if (replacement.size && replacement.lastModified) {
$replacementDiv.find('.size').text(OC.Util.humanFileSize(replacement.size))
$replacementDiv.find('.mtime').text(OC.Util.formatDate(replacement.lastModified))
$replacementDiv.find('.size').text(formatFileSize(replacement.size))
$replacementDiv.find('.mtime').text(moment(replacement.lastModified).format('LLL'))
}
var path = original.directory + '/' + original.name
var urlSpec = {
Expand Down Expand Up @@ -833,7 +835,7 @@ const Dialogs = {
var defer = $.Deferred()
if (!this.$messageTemplate) {
var self = this
$.get(OC.filePath('core', 'templates', 'message.html'), function(tmpl) {
$.get(generateFilePath('core', 'templates', 'message.html'), function(tmpl) {
self.$messageTemplate = $(tmpl)
defer.resolve(self.$messageTemplate)
})
Expand All @@ -849,7 +851,7 @@ const Dialogs = {
var defer = $.Deferred()
if (!this.$fileexistsTemplate) {
var self = this
$.get(OC.filePath('files', 'templates', 'fileexists.html'), function(tmpl) {
$.get(generateFilePath('files', 'templates', 'fileexists.html'), function(tmpl) {
self.$fileexistsTemplate = $(tmpl)
defer.resolve(self.$fileexistsTemplate)
})
Expand Down
17 changes: 11 additions & 6 deletions core/src/OC/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
TAG_FAVORITE,
} from './constants.js'
import ContactsMenu from './contactsmenu.js'
import { currentUser, getCurrentUser } from './currentuser.js'
import { getCurrentUser } from '@nextcloud/auth'
import Dialogs from './dialogs.js'
import EventSource from './eventsource.js'
import { get, set } from './get_set.js'
Expand All @@ -78,7 +78,6 @@ import {
showMenu,
unregisterMenu,
} from './menu.js'
import { isUserAdmin } from './admin.js'
import L10N from './l10n.js'
import {
getCanonicalLocale,
Expand Down Expand Up @@ -146,10 +145,13 @@ export default {
/**
* Currently logged in user or null if none
*
* @type {string}
* @deprecated use `getCurrentUser` from https://www.npmjs.com/package/@nextcloud/auth
* @type {string|undefined}
* @deprecated 28.0.0 use `getCurrentUser` from https://www.npmjs.com/package/@nextcloud/auth
*/
currentUser: getCurrentUser()?.uid,
/**
* @deprecated 28.0.0 https://www.npmjs.com/package/@nextcloud/dialogs
*/
currentUser,
dialogs: Dialogs,
EventSource,
/**
Expand All @@ -160,7 +162,10 @@ export default {
* @deprecated 19.0.0 use `getCurrentUser` from https://www.npmjs.com/package/@nextcloud/auth
*/
getCurrentUser,
isUserAdmin,
/**
* @deprecated 19.0.0 use `getCurrentUser` from https://www.npmjs.com/package/@nextcloud/auth
*/
isUserAdmin: () => getCurrentUser()?.isAdmin,
L10N,

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/**
* Copyright (c) 2015
* @copyright 2023 Louis Chmn <[email protected]>
*
* @author Julius Härtl <[email protected]>
* @author Robin Appelman <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author Vincent Petry <[email protected]>
* @author 2023 Louis Chmn <[email protected]>
*
* @license AGPL-3.0-or-later
*
Expand All @@ -22,3 +19,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { getLoggerBuilder } from '@nextcloud/logger'

export default getLoggerBuilder()
.setApp('core')
.detectUser()
.build()
14 changes: 7 additions & 7 deletions core/src/OC/password-confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

import _ from 'underscore'
import $ from 'jquery'
import moment from 'moment'
import moment from '@nextcloud/moment'
import { generateUrl } from '@nextcloud/router'

import OC from './index.js'
import { translate as t } from '@nextcloud/l10n'
import dialogs from './dialogs.js'

/**
* @namespace OC.PasswordConfirmation
Expand Down Expand Up @@ -61,7 +61,7 @@ export default {
title: t('core', 'Authentication required'),
text: t(
'core',
'This action requires you to confirm your password'
'This action requires you to confirm your password',
),
confirm: t('core', 'Confirm'),
label: t('core', 'Password'),
Expand All @@ -73,7 +73,7 @@ export default {
const self = this

if (this.requiresPasswordConfirmation()) {
OC.dialogs.prompt(
dialogs.prompt(
config.text,
config.title,
function(result, password) {
Expand All @@ -85,7 +85,7 @@ export default {
},
true,
config.label,
true
true,
).then(function() {
const $dialog = $('.oc-dialog:visible')
$dialog.find('.ui-icon').remove()
Expand Down Expand Up @@ -124,7 +124,7 @@ export default {
},
error() {
config.error = t('core', 'Failed to authenticate, try again')
OC.PasswordConfirmation.requirePasswordConfirmation(self.callback, config)
self.requirePasswordConfirmation(self.callback, config)
},
})
},
Expand Down
16 changes: 10 additions & 6 deletions core/src/OC/util-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
*/

import _ from 'underscore'
import OC from './index.js'

import {
build as buildQueryString,
parse as parseQueryString,
} from './query-string.js'

/**
* Utility class for the history API,
Expand All @@ -45,14 +49,14 @@ export default {
* or a map
* @param {string} [url] URL to be used, otherwise the current URL will be used,
* using the params as query string
* @param {boolean} [replace=false] whether to replace instead of pushing
* @param {boolean} [replace] whether to replace instead of pushing
*/
_pushState(params, url, replace) {
let strParams
if (typeof (params) === 'string') {
strParams = params
} else {
strParams = OC.buildQueryString(params)
strParams = buildQueryString(params)
}

if (window.history.pushState) {
Expand Down Expand Up @@ -157,10 +161,10 @@ export default {
let params
// try and parse from URL hash first
if (query) {
params = OC.parseQueryString(this._decodeQuery(query))
params = parseQueryString(this._decodeQuery(query))
}
// else read from query attributes
params = _.extend(params || {}, OC.parseQueryString(this._decodeQuery(location.search)))
params = _.extend(params || {}, parseQueryString(this._decodeQuery(location.search)))
return params || {}
},

Expand All @@ -175,7 +179,7 @@ export default {
}
params = (e && e.state)
if (_.isString(params)) {
params = OC.parseQueryString(params)
params = parseQueryString(params)
} else if (!params) {
params = this.parseUrlQuery() || {}
}
Expand Down
13 changes: 7 additions & 6 deletions core/src/OC/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
*
*/

import moment from 'moment'
import moment from '@nextcloud/moment'

import History from './util-history.js'
import OC from './index.js'
import logger from './logger.js'
import { getLanguage } from '@nextcloud/l10n'
import { formatFileSize as humanFileSize } from '@nextcloud/files'

/**
Expand Down Expand Up @@ -74,7 +75,7 @@ export default {
* Inspired by computerFileSize in helper.php
*
* @param {string} string file size in human-readable format
* @return {number} or null if string could not be parsed
* @return {number|null} or null if string could not be parsed
*
*
*/
Expand Down Expand Up @@ -124,7 +125,7 @@ export default {
*/
formatDate(timestamp, format) {
if (window.TESTING === undefined) {
OC.debug && console.warn('OC.Util.formatDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment')
logger.warn('OC.Util.formatDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment')
}
format = format || 'LLL'
return moment(timestamp).format(format)
Expand All @@ -136,7 +137,7 @@ export default {
*/
relativeModifiedDate(timestamp) {
if (window.TESTING === undefined) {
OC.debug && console.warn('OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment')
logger.warn('OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment')
}
const diff = moment().diff(moment(timestamp))
if (diff >= 0 && diff < 45000) {
Expand Down Expand Up @@ -219,7 +220,7 @@ export default {
} else {
// Note: This locale setting isn't supported by all browsers but for the ones
// that do there will be more consistency between client-server sorting
return aa[x].localeCompare(bb[x], OC.getLanguage())
return aa[x].localeCompare(bb[x], getLanguage())
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions core/src/OC/xhr-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import _ from 'underscore'
import $ from 'jquery'

import OC from './index.js'
import Notification from './notification.js'

/**
Expand Down Expand Up @@ -65,7 +64,7 @@ export const processAjaxError = xhr => {
OC.reload()
}
timer++
}, 1000 // 1 second interval
}, 1000, // 1 second interval
)

// only call reload once
Expand Down
Loading