Skip to content

Commit

Permalink
Merge pull request #40551 from nextcloud/fix/init-script
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Sep 21, 2023
2 parents ef87ff1 + bf467ad commit 472440b
Show file tree
Hide file tree
Showing 118 changed files with 360 additions and 407 deletions.
1 change: 1 addition & 0 deletions apps/comments/lib/Listener/LoadAdditionalScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ public function handle(Event $event): void {
// TODO: make sure to only include the sidebar script when
// we properly split it between files list and sidebar
Util::addScript(Application::APP_ID, 'comments');
Util::addInitScript(Application::APP_ID, 'init');
}
}
6 changes: 4 additions & 2 deletions apps/comments/src/actions/inlineUnreadCommentsAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('Inline unread comments action display name tests', () => {

expect(action).toBeInstanceOf(FileAction)
expect(action.id).toBe('comments-unread')
expect(action.displayName([file], view)).toBe('1 new comment')
expect(action.displayName([file], view)).toBe('')
expect(action.title!([file], view)).toBe('1 new comment')
expect(action.iconSvgInline([], view)).toBe('<svg>SvgMock</svg>')
expect(action.enabled!([file], view)).toBe(true)
expect(action.inline!(file, view)).toBe(true)
Expand All @@ -64,7 +65,8 @@ describe('Inline unread comments action display name tests', () => {
},
})

expect(action.displayName([file], view)).toBe('2 new comments')
expect(action.displayName([file], view)).toBe('')
expect(action.title!([file], view)).toBe('2 new comments')
})
})

Expand Down
14 changes: 8 additions & 6 deletions apps/comments/src/actions/inlineUnreadCommentsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { FileAction, Node, registerFileAction } from '@nextcloud/files'
import { FileAction, Node } from '@nextcloud/files'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
import commentProcessingSvg from '@mdi/svg/svg/comment-processing.svg?raw'
import CommentProcessingSvg from '@mdi/svg/svg/comment-processing.svg?raw'

import logger from '../logger'

export const action = new FileAction({
id: 'comments-unread',

displayName(nodes: Node[]) {
title(nodes: Node[]) {
const unread = nodes[0].attributes['comments-unread'] as number
if (unread >= 0) {
return n('comments', '1 new comment', '{unread} new comments', unread, { unread })
}
return t('comments', 'Comment')
},

iconSvgInline: () => commentProcessingSvg,
// Empty string when rendered inline
displayName: () => '',

iconSvgInline: () => CommentProcessingSvg,

enabled(nodes: Node[]) {
const unread = nodes[0].attributes['comments-unread'] as number|undefined
Expand All @@ -57,5 +61,3 @@ export const action = new FileAction({

order: -140,
})

registerFileAction(action)
1 change: 0 additions & 1 deletion apps/comments/src/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@
import './app.js'
import './templates.js'
import './activitytabviewplugin.js'
import './actions/inlineUnreadCommentsAction.ts'

window.OCA.Comments = OCA.Comments
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

/**
* @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
*
Expand All @@ -21,3 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { registerFileAction } from '@nextcloud/files'
import { action } from './actions/inlineUnreadCommentsAction'

registerFileAction(action)
1 change: 1 addition & 0 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
}

// Load the files we need
\OCP\Util::addInitScript('files', 'init');
\OCP\Util::addStyle('files', 'merged');
\OCP\Util::addScript('files', 'merged-index', 'files');
\OCP\Util::addScript('files', 'main');
Expand Down
4 changes: 1 addition & 3 deletions apps/files/src/actions/deleteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
import { emit } from '@nextcloud/event-bus'
import { Permission, Node, View, registerFileAction, FileAction } from '@nextcloud/files'
import { Permission, Node, View, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import TrashCanSvg from '@mdi/svg/svg/trash-can.svg?raw'
Expand Down Expand Up @@ -62,5 +62,3 @@ export const action = new FileAction({

order: 100,
})

registerFileAction(action)
4 changes: 1 addition & 3 deletions apps/files/src/actions/downloadAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
import { generateUrl } from '@nextcloud/router'
import { registerFileAction, FileAction, Permission, Node, FileType, View } from '@nextcloud/files'
import { FileAction, Permission, Node, FileType, View } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import ArrowDownSvg from '@mdi/svg/svg/arrow-down.svg?raw'

Expand Down Expand Up @@ -86,5 +86,3 @@ export const action = new FileAction({

order: 30,
})

registerFileAction(action)
6 changes: 1 addition & 5 deletions apps/files/src/actions/editLocallyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { encodePath } from '@nextcloud/paths'
import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { registerFileAction, FileAction, Permission, type Node } from '@nextcloud/files'
import { FileAction, Permission, type Node } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
Expand Down Expand Up @@ -66,7 +66,3 @@ export const action = new FileAction({

order: 25,
})

if (!/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) {
registerFileAction(action)
}
4 changes: 1 addition & 3 deletions apps/files/src/actions/favoriteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
import { emit } from '@nextcloud/event-bus'
import { generateUrl } from '@nextcloud/router'
import { Permission, type Node, View, registerFileAction, FileAction } from '@nextcloud/files'
import { Permission, type Node, View, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import Vue from 'vue'
Expand Down Expand Up @@ -101,5 +101,3 @@ export const action = new FileAction({

order: -50,
})

registerFileAction(action)
4 changes: 1 addition & 3 deletions apps/files/src/actions/openFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
import { join } from 'path'
import { Permission, Node, FileType, View, registerFileAction, FileAction, DefaultType } from '@nextcloud/files'
import { Permission, Node, FileType, View, FileAction, DefaultType } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import FolderSvg from '@mdi/svg/svg/folder.svg?raw'

Expand Down Expand Up @@ -66,5 +66,3 @@ export const action = new FileAction({
default: DefaultType.HIDDEN,
order: -100,
})

registerFileAction(action)
6 changes: 1 addition & 5 deletions apps/files/src/actions/openInFilesAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
*
*/
import { translate as t } from '@nextcloud/l10n'
import { FileType, type Node } from '@nextcloud/files'

import { registerFileAction, FileAction, DefaultType } from '@nextcloud/files'
import { type Node, FileType, FileAction, DefaultType } from '@nextcloud/files'

/**
* TODO: Move away from a redirect and handle
Expand Down Expand Up @@ -53,5 +51,3 @@ export const action = new FileAction({
order: -1000,
default: DefaultType.HIDDEN,
})

registerFileAction(action)
4 changes: 1 addition & 3 deletions apps/files/src/actions/renameAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
import { emit } from '@nextcloud/event-bus'
import { Permission, type Node, registerFileAction, FileAction } from '@nextcloud/files'
import { Permission, type Node, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import PencilSvg from '@mdi/svg/svg/pencil.svg?raw'

Expand All @@ -45,5 +45,3 @@ export const action = new FileAction({

order: 10,
})

registerFileAction(action)
4 changes: 1 addition & 3 deletions apps/files/src/actions/sidebarAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { Permission, type Node, View, registerFileAction, FileAction, FileType } from '@nextcloud/files'
import { Permission, type Node, View, FileAction, FileType } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import InformationSvg from '@mdi/svg/svg/information-variant.svg?raw'

Expand Down Expand Up @@ -73,5 +73,3 @@ export const action = new FileAction({

order: -50,
})

registerFileAction(action)
4 changes: 1 addition & 3 deletions apps/files/src/actions/viewInFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { Node, FileType, Permission, View, registerFileAction, FileAction } from '@nextcloud/files'
import { Node, FileType, Permission, View, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import FolderMoveSvg from '@mdi/svg/svg/folder-move.svg?raw'

Expand Down Expand Up @@ -64,5 +64,3 @@ export const action = new FileAction({

order: 80,
})

registerFileAction(action)
15 changes: 13 additions & 2 deletions apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@
:class="'files-list__row-action-' + action.id"
:close-after-click="true"
:data-cy-files-list-row-action="action.id"
:title="action.title?.([source], currentView)"
@click="onActionClick(action)">
<template #icon>
<NcLoadingIcon v-if="loading === action.id" :size="18" />
<CustomSvgIconRender v-else :svg="action.iconSvgInline([source], currentView)" />
</template>
{{ action.displayName([source], currentView) }}
{{ actionDisplayName(action) }}
</NcActionButton>
</NcActions>
</td>
Expand Down Expand Up @@ -180,7 +181,7 @@ import { debounce } from 'debounce'
import { emit } from '@nextcloud/event-bus'
import { extname } from 'path'
import { generateUrl } from '@nextcloud/router'
import { getFileActions, DefaultType, FileType, formatFileSize, Permission, Folder, File, Node } from '@nextcloud/files'
import { getFileActions, DefaultType, FileType, formatFileSize, Permission, Folder, File, Node, FileAction } from '@nextcloud/files'
import { Type as ShareType } from '@nextcloud/sharing'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate } from '@nextcloud/l10n'
Expand Down Expand Up @@ -918,6 +919,16 @@ export default Vue.extend({
return document.querySelector('.app-content > .files-list')
},

actionDisplayName(action: FileAction) {
if (this.filesListWidth < 768 && action.inline && typeof action.title === 'function') {
// if an inline action is rendered in the menu for
// lack of space we use the title first if defined
const title = action.title([this.source], this.currentView)
if (title) return title
}
return action.displayName([this.source], this.currentView)
},

t: translate,
formatFileSize,
},
Expand Down
4 changes: 0 additions & 4 deletions apps/files/src/components/FilesListVirtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,6 @@ export default Vue.extend({
// Remove bold from default button styling
font-weight: normal;
}
&:not(:hover, :focus, :active) .button-vue__wrapper {
// Also apply color-text-maxcontrast to non-active button
color: var(--color-text-maxcontrast);
}
}
}

Expand Down
59 changes: 59 additions & 0 deletions apps/files/src/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license AGPL-3.0-or-later
*
* 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/>.
*
*/
import { action as deleteAction } from './actions/deleteAction'
import { action as downloadAction } from './actions/downloadAction'
import { action as editLocallyAction } from './actions/editLocallyAction'
import { action as favoriteAction } from './actions/favoriteAction'
import { action as openFolderAction } from './actions/openFolderAction'
import { action as openInFilesAction } from './actions/openInFilesAction'
import { action as renameAction } from './actions/renameAction'
import { action as sidebarAction } from './actions/sidebarAction'
import { action as viewInFolderAction } from './actions/viewInFolderAction'
import { entry as newFolderEntry } from './newMenu/newFolder'

import registerFavoritesView from './views/favorites'
import registerRecentView from './views/recent'
import registerFilesView from './views/files'
import registerPreviewServiceWorker from './services/ServiceWorker.js'
import { addNewFileMenuEntry, registerFileAction } from '@nextcloud/files'

// Register file actions
registerFileAction(deleteAction)
registerFileAction(downloadAction)
registerFileAction(editLocallyAction)
registerFileAction(favoriteAction)
registerFileAction(openFolderAction)
registerFileAction(openInFilesAction)
registerFileAction(renameAction)
registerFileAction(sidebarAction)
registerFileAction(viewInFolderAction)

// Register new menu entry
addNewFileMenuEntry(newFolderEntry)

// Register files views
registerFavoritesView()
registerFilesView()
registerRecentView()

// Register preview service worker
registerPreviewServiceWorker()
23 changes: 0 additions & 23 deletions apps/files/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import './templates.js'
import './legacy/filelistSearch.js'

import './actions/deleteAction'
import './actions/downloadAction'
import './actions/editLocallyAction'
import './actions/favoriteAction'
import './actions/openFolderAction'
import './actions/openInFilesAction.js'
import './actions/renameAction'
import './actions/sidebarAction'
import './actions/viewInFolderAction'
import './newMenu/newFolder'

import Vue from 'vue'
import { createPinia, PiniaVuePlugin } from 'pinia'
import { getNavigation } from '@nextcloud/files'
import { getRequestToken } from '@nextcloud/auth'

import FilesListView from './views/FilesList.vue'
import NavigationView from './views/Navigation.vue'
import registerFavoritesView from './views/favorites'
import registerRecentView from './views/recent'
import registerFilesView from './views/files'
import registerPreviewServiceWorker from './services/ServiceWorker.js'
import router from './router/router'
import RouterService from './services/RouterService'
import SettingsModel from './models/Setting.js'
Expand Down Expand Up @@ -80,11 +65,3 @@ const FilesList = new ListView({
pinia,
})
FilesList.$mount('#app-content-vue')

// Init legacy and new files views
registerFavoritesView()
registerFilesView()
registerRecentView()

// Register preview service worker
registerPreviewServiceWorker()
Loading

0 comments on commit 472440b

Please sign in to comment.