Skip to content

Commit 4bd40b0

Browse files
ShGKmebackportbot[bot]
authored andcommitted
fix(files): combine navigation and files list into single Vue app
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
1 parent 4d43b6e commit 4bd40b0

File tree

7 files changed

+51
-75
lines changed

7 files changed

+51
-75
lines changed

apps/files/lib/Controller/ViewController.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,9 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
283283
$this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false);
284284
$this->initialState->provideInitialState('templates', $this->templateManager->listCreators());
285285

286-
$params = [
287-
'fileNotFound' => $fileNotFound ? 1 : 0,
288-
'id-app-content' => '#app-content-vue',
289-
'id-app-navigation' => '#app-navigation-vue',
290-
];
291-
292286
$response = new TemplateResponse(
293287
Application::APP_ID,
294288
'index',
295-
$params
296289
);
297290
$policy = new ContentSecurityPolicy();
298291
$policy->addAllowedFrameDomain('\'self\'');

apps/files/src/FilesApp.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<NcContent app-name="files">
3+
<Navigation />
4+
<FilesList />
5+
</NcContent>
6+
</template>
7+
8+
<script lang="ts">
9+
import { defineComponent } from 'vue'
10+
11+
import NcContent from '@nextcloud/vue/dist/Components/NcContent.js'
12+
13+
import Navigation from './views/Navigation.vue'
14+
import FilesList from './views/FilesList.vue'
15+
16+
export default defineComponent({
17+
name: 'FilesApp',
18+
19+
components: {
20+
NcContent,
21+
FilesList,
22+
Navigation,
23+
},
24+
})
25+
</script>

apps/files/src/main.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import router from './router/router'
99
import RouterService from './services/RouterService'
1010
import SettingsModel from './models/Setting.js'
1111
import SettingsService from './services/Settings.js'
12+
import FilesApp from './FilesApp.vue'
1213

1314
// @ts-expect-error __webpack_nonce__ is injected by webpack
1415
__webpack_nonce__ = btoa(getRequestToken())
@@ -42,23 +43,8 @@ const Settings = new SettingsService()
4243
Object.assign(window.OCA.Files, { Settings })
4344
Object.assign(window.OCA.Files.Settings, { Setting: SettingsModel })
4445

45-
// Init Navigation View
46-
const View = Vue.extend(NavigationView)
47-
const FilesNavigationRoot = new View({
48-
name: 'FilesNavigationRoot',
49-
propsData: {
50-
Navigation,
51-
},
46+
const FilesAppVue = Vue.extend(FilesApp)
47+
new FilesAppVue({
5248
router,
5349
pinia,
54-
})
55-
FilesNavigationRoot.$mount('#app-navigation-files')
56-
57-
// Init content list view
58-
const ListView = Vue.extend(FilesListView)
59-
const FilesList = new ListView({
60-
name: 'FilesListRoot',
61-
router,
62-
pinia,
63-
})
64-
FilesList.$mount('#app-content-vue')
50+
}).$mount('#content')

apps/files/src/views/Navigation.cy.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import router from '../router/router'
77
import { useViewConfigStore } from '../store/viewConfig'
88
import { Folder, View, getNavigation } from '@nextcloud/files'
99

10+
import Vue from 'vue'
11+
1012
describe('Navigation renders', () => {
1113
delete window._nc_navigation
1214
const Navigation = getNavigation()
1315

1416
before(() => {
17+
Vue.prototype.$navigation = Navigation
18+
1519
cy.mockInitialState('files', 'storageStats', {
1620
used: 1000 * 1000 * 1000,
1721
quota: -1,
@@ -22,9 +26,6 @@ describe('Navigation renders', () => {
2226

2327
it('renders', () => {
2428
cy.mount(NavigationView, {
25-
propsData: {
26-
Navigation,
27-
},
2829
global: {
2930
plugins: [createTestingPinia({
3031
createSpy: cy.spy,
@@ -42,6 +43,10 @@ describe('Navigation API', () => {
4243
delete window._nc_navigation
4344
const Navigation = getNavigation()
4445

46+
before(() => {
47+
Vue.prototype.$navigation = Navigation
48+
})
49+
4550
it('Check API entries rendering', () => {
4651
Navigation.register(new View({
4752
id: 'files',
@@ -52,9 +57,6 @@ describe('Navigation API', () => {
5257
}))
5358

5459
cy.mount(NavigationView, {
55-
propsData: {
56-
Navigation,
57-
},
5860
global: {
5961
plugins: [createTestingPinia({
6062
createSpy: cy.spy,
@@ -79,9 +81,6 @@ describe('Navigation API', () => {
7981
}))
8082

8183
cy.mount(NavigationView, {
82-
propsData: {
83-
Navigation,
84-
},
8584
global: {
8685
plugins: [createTestingPinia({
8786
createSpy: cy.spy,
@@ -107,9 +106,6 @@ describe('Navigation API', () => {
107106
}))
108107

109108
cy.mount(NavigationView, {
110-
propsData: {
111-
Navigation,
112-
},
113109
global: {
114110
plugins: [createTestingPinia({
115111
createSpy: cy.spy,
@@ -159,13 +155,14 @@ describe('Quota rendering', () => {
159155
delete window._nc_navigation
160156
const Navigation = getNavigation()
161157

158+
before(() => {
159+
Vue.prototype.$navigation = Navigation
160+
})
161+
162162
afterEach(() => cy.unmockInitialState())
163163

164164
it('Unknown quota', () => {
165165
cy.mount(NavigationView, {
166-
propsData: {
167-
Navigation,
168-
},
169166
global: {
170167
plugins: [createTestingPinia({
171168
createSpy: cy.spy,
@@ -183,9 +180,6 @@ describe('Quota rendering', () => {
183180
})
184181

185182
cy.mount(NavigationView, {
186-
propsData: {
187-
Navigation,
188-
},
189183
global: {
190184
plugins: [createTestingPinia({
191185
createSpy: cy.spy,
@@ -206,9 +200,6 @@ describe('Quota rendering', () => {
206200
})
207201

208202
cy.mount(NavigationView, {
209-
propsData: {
210-
Navigation,
211-
},
212203
global: {
213204
plugins: [createTestingPinia({
214205
createSpy: cy.spy,
@@ -230,9 +221,6 @@ describe('Quota rendering', () => {
230221
})
231222

232223
cy.mount(NavigationView, {
233-
propsData: {
234-
Navigation,
235-
},
236224
global: {
237225
plugins: [createTestingPinia({
238226
createSpy: cy.spy,

apps/files/src/views/Navigation.vue

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
</template>
7676

7777
<script lang="ts">
78-
import { emit, subscribe } from '@nextcloud/event-bus'
78+
import { emit } from '@nextcloud/event-bus'
7979
import { translate } from '@nextcloud/l10n'
8080
import Cog from 'vue-material-design-icons/Cog.vue'
8181
import NcAppNavigation from '@nextcloud/vue/dist/Components/NcAppNavigation.js'
@@ -85,7 +85,7 @@ import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js
8585
import { setPageHeading } from '../../../../core/src/OCP/accessibility.js'
8686
import { useViewConfigStore } from '../store/viewConfig.ts'
8787
import logger from '../logger.js'
88-
import type { Navigation, View } from '@nextcloud/files'
88+
import type { View } from '@nextcloud/files'
8989
import NavigationQuota from '../components/NavigationQuota.vue'
9090
import SettingsModal from './Settings.vue'
9191
@@ -101,14 +101,6 @@ export default {
101101
SettingsModal,
102102
},
103103
104-
props: {
105-
// eslint-disable-next-line vue/prop-name-casing
106-
Navigation: {
107-
type: Object as Navigation,
108-
required: true,
109-
},
110-
},
111-
112104
setup() {
113105
const viewConfigStore = useViewConfigStore()
114106
return {
@@ -132,7 +124,7 @@ export default {
132124
},
133125
134126
views(): View[] {
135-
return this.Navigation.views
127+
return this.$navigation.views
136128
},
137129
138130
parentViews(): View[] {
@@ -164,7 +156,7 @@ export default {
164156
watch: {
165157
currentView(view, oldView) {
166158
if (view.id !== oldView?.id) {
167-
this.Navigation.setActive(view)
159+
this.$navigation.setActive(view)
168160
logger.debug('Navigation changed', { id: view.id, view })
169161
170162
this.showView(view)
@@ -183,14 +175,15 @@ export default {
183175
showView(view: View) {
184176
// Closing any opened sidebar
185177
window?.OCA?.Files?.Sidebar?.close?.()
186-
this.Navigation.setActive(view)
178+
this.$navigation.setActive(view)
187179
setPageHeading(view.name)
188180
emit('files:navigation:changed', view)
189181
},
190182
191183
/**
192184
* Expand/collapse a a view with children and permanently
193185
* save this setting in the server.
186+
* @param view
194187
*/
195188
onToggleExpand(view: View) {
196189
// Invert state
@@ -203,6 +196,7 @@ export default {
203196
/**
204197
* Check if a view is expanded by user config
205198
* or fallback to the default value.
199+
* @param view
206200
*/
207201
isExpanded(view: View): boolean {
208202
return typeof this.viewConfigStore.getConfig(view.id)?.expanded === 'boolean'
@@ -212,6 +206,7 @@ export default {
212206
213207
/**
214208
* Generate the route to a view
209+
* @param view
215210
*/
216211
generateToNavigation(view: View) {
217212
if (view.params) {

apps/files/templates/index.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
<!-- File navigation -->
2-
<div id="app-navigation-files" role="navigation"></div>
1+
<?php
32

4-
<!-- File list vue container -->
5-
<div id="app-content-vue" class="hidden"></div>
6-
7-
<!-- config hints for javascript -->
8-
<input type="hidden" name="filesApp" id="filesApp" value="1" />
9-
<input type="hidden" name="fileNotFound" id="fileNotFound" value="<?php p($_['fileNotFound']); ?>" />
3+
// Empty template

apps/files/tests/Controller/ViewControllerTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,6 @@ public function testIndexWithRegularBrowser() {
184184
$expected = new Http\TemplateResponse(
185185
'files',
186186
'index',
187-
[
188-
'fileNotFound' => 0,
189-
'id-app-content' => '#app-content-vue',
190-
'id-app-navigation' => '#app-navigation-vue',
191-
]
192187
);
193188
$policy = new Http\ContentSecurityPolicy();
194189
$policy->addAllowedWorkerSrcDomain('\'self\'');

0 commit comments

Comments
 (0)