Skip to content

Commit

Permalink
Add OCA.Files.Sidebar
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv authored and danxuliu committed Oct 29, 2019
1 parent ea6f423 commit fd90af5
Show file tree
Hide file tree
Showing 46 changed files with 4,607 additions and 109 deletions.
5 changes: 4 additions & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
plugins: ['@babel/plugin-syntax-dynamic-import'],
plugins: [
'@babel/plugin-syntax-dynamic-import',
['@babel/plugin-proposal-class-properties', { loose: true }]
],
presets: [
[
'@babel/preset-env',
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lint-fix-watch:
clean:
rm -rf apps/accessibility/js/
rm -rf apps/comments/js/
rm -rf apps/files/js/dist/
rm -rf apps/files_sharing/js/dist/
rm -rf apps/files_trashbin/js/
rm -rf apps/files_versions/js/
Expand All @@ -47,6 +48,7 @@ clean-dev:
clean-git: clean
git checkout -- apps/accessibility/js/
git checkout -- apps/comments/js/
git checkout -- apps/files/js/dist/
git checkout -- apps/files_sharing/js/dist/
git checkout -- apps/files_trashbin/js/
git checkout -- apps/files_versions/js/
Expand Down
2 changes: 1 addition & 1 deletion apps/comments/src/filesplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
actionHandler: function(fileName, context) {
context.$file.find('.action-comment').tooltip('hide')
// open sidebar in comments section
context.fileList.showDetailsView(fileName, 'commentsTabView')
context.fileList.showDetailsView(fileName, 'comments')
}
})

Expand Down
3 changes: 2 additions & 1 deletion apps/files/css/files.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@
}

/* fit app list view heights */
.app-files #app-content>.viewcontainer {
.app-files #app-content > .viewcontainer {
min-height: 0%;
width: 100%;
}

.app-files #app-content {
Expand Down
6 changes: 6 additions & 0 deletions apps/files/js/fileactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,12 @@
}
context.fileList.do_delete(fileName, context.dir);
$('.tipsy').remove();

// close sidebar on delete
const path = context.dir + '/' + fileName
if (OCA.Files.Sidebar && OCA.Files.Sidebar.file === path) {
OCA.Files.Sidebar.file = undefined
}
}
});

Expand Down
69 changes: 27 additions & 42 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,11 @@
* @param {string} [tabId] optional tab id to select
*/
showDetailsView: function(fileName, tabId) {
console.warn('showDetailsView is deprecated! Use OCA.Files.Sidebar.activeTab. It will be removed in nextcloud 20.');
this._updateDetailsView(fileName);
if (tabId) {
this._detailsView.selectTab(tabId);
OCA.Files.Sidebar.activeTab = tabId;
}
OC.Apps.showAppSidebar(this._detailsView.$el);
},

/**
Expand All @@ -623,48 +623,23 @@
* @param {string|OCA.Files.FileInfoModel} fileName file name from the current list or a FileInfoModel object
* @param {boolean} [show=true] whether to open the sidebar if it was closed
*/
_updateDetailsView: function(fileName, show) {
if (!this._detailsView) {
_updateDetailsView: function(fileName) {
if (!(OCA.Files && OCA.Files.Sidebar)) {
console.error('No sidebar available');
return;
}

// show defaults to true
show = _.isUndefined(show) || !!show;
var oldFileInfo = this._detailsView.getFileInfo();
if (oldFileInfo) {
// TODO: use more efficient way, maybe track the highlight
this.$fileList.children().filterAttr('data-id', '' + oldFileInfo.get('id')).removeClass('highlighted');
oldFileInfo.off('change', this._onSelectedModelChanged, this);
}

if (!fileName) {
this._detailsView.setFileInfo(null);
if (this._currentFileModel) {
this._currentFileModel.off();
}
this._currentFileModel = null;
OC.Apps.hideAppSidebar(this._detailsView.$el);
return;
OCA.Files.Sidebar.file = null
return
} else if (typeof fileName !== 'string') {
fileName = ''
}

if (show && this._detailsView.$el.hasClass('disappear')) {
OC.Apps.showAppSidebar(this._detailsView.$el);
}

if (fileName instanceof OCA.Files.FileInfoModel) {
var model = fileName;
} else {
var $tr = this.findFileEl(fileName);
var model = this.getModelForFile($tr);
$tr.addClass('highlighted');
}

this._currentFileModel = model;

this._replaceDetailsViewElementIfNeeded();

this._detailsView.setFileInfo(model);
this._detailsView.$el.scrollTop(0);
// open sidebar and set file
const dir = `${this.dirInfo.path}/${this.dirInfo.name}`
const path = `${dir}/${fileName}`
OCA.Files.Sidebar.file = path.replace('//', '/')
},

/**
Expand Down Expand Up @@ -1404,6 +1379,13 @@
return OC.MimeType.getIconUrl('dir-external');
} else if (fileInfo.mountType !== undefined && fileInfo.mountType !== '') {
return OC.MimeType.getIconUrl('dir-' + fileInfo.mountType);
} else if (fileInfo.shareTypes && (
fileInfo.shareTypes.indexOf(OC.Share.SHARE_TYPE_LINK) > -1
|| fileInfo.shareTypes.indexOf(OC.Share.SHARE_TYPE_EMAIL) > -1)
) {
return OC.MimeType.getIconUrl('dir-public')
} else if (fileInfo.shareTypes && fileInfo.shareTypes.length > 0) {
return OC.MimeType.getIconUrl('dir-shared')
}
return OC.MimeType.getIconUrl('dir');
}
Expand Down Expand Up @@ -3654,17 +3636,20 @@
* Register a tab view to be added to all views
*/
registerTabView: function(tabView) {
if (this._detailsView) {
this._detailsView.addTabView(tabView);
console.warn('registerTabView is deprecated! It will be removed in nextcloud 20.');
const name = tabView.getLabel()
if (name) {
OCA.Files.Sidebar.registerTab(new OCA.Files.Sidebar.Tab(name, tabView, true))
}
},

/**
* Register a detail view to be added to all views
*/
registerDetailView: function(detailView) {
if (this._detailsView) {
this._detailsView.addDetailView(detailView);
console.warn('registerDetailView is deprecated! It will be removed in nextcloud 20.');
if (detailView.el) {
OCA.Files.Sidebar.registerSecondaryView(detailView)
}
},

Expand Down
47 changes: 24 additions & 23 deletions apps/files/js/merged-index.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
[
"dist/sidebar.js",
"app.js",
"templates.js",
"file-upload.js",
"newfilemenu.js",
"jquery.fileupload.js",
"jquery-visibility.js",
"fileinfomodel.js",
"filesummary.js",
"filemultiselectmenu.js",
"breadcrumb.js",
"filelist.js",
"search.js",
"favoritesfilelist.js",
"recentfilelist.js",
"tagsplugin.js",
"gotoplugin.js",
"favoritesplugin.js",
"recentplugin.js",
"detailfileinfoview.js",
"sidebarpreviewmanager.js",
"sidebarpreviewtext.js",
"detailtabview.js",
"semaphore.js",
"mainfileinfodetailview.js",
"operationprogressbar.js",
"detailsview.js",
"detailtabview.js",
"favoritesfilelist.js",
"favoritesplugin.js",
"file-upload.js",
"fileactions.js",
"fileactionsmenu.js",
"fileinfomodel.js",
"filelist.js",
"filemultiselectmenu.js",
"files.js",
"filesummary.js",
"gotoplugin.js",
"jquery-visibility.js",
"jquery.fileupload.js",
"keyboardshortcuts.js",
"navigation.js"
"mainfileinfodetailview.js",
"navigation.js",
"newfilemenu.js",
"operationprogressbar.js",
"recentfilelist.js",
"recentplugin.js",
"search.js",
"semaphore.js",
"sidebarpreviewmanager.js",
"sidebarpreviewtext.js",
"tagsplugin.js",
"templates.js"
]
89 changes: 89 additions & 0 deletions apps/files/src/components/LegacyTab.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!--
- @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
-
- @author John Molakvoæ <skjnldsv@protonmail.com>
-
- @license GNU AGPL version 3 or any later version
-
- 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/>.
-
-->

<template>
<AppSidebarTab :icon="icon"
:name="name"
:active-tab="activeTab" />
</template>
<script>
import AppSidebarTab from 'nextcloud-vue/dist/Components/AppSidebarTab'

export default {
name: 'LegacyTab',
components: {
AppSidebarTab: AppSidebarTab
},
props: {
component: {
type: Object,
required: true
},
name: {
type: String,
default: '',
required: true
},
fileInfo: {
type: Object,
default: () => {},
required: true
}
},
computed: {
icon() {
return this.component.getIcon()
},
id() {
// copied from AppSidebarTab
return this.name.toLowerCase().replace(/ /g, '-')
},
order() {
return this.component.order
? this.component.order
: 0
},
// needed because AppSidebarTab also uses $parent.activeTab
activeTab() {
return this.$parent.activeTab
}
},
watch: {
activeTab(activeTab) {
if (activeTab === this.id && this.fileInfo) {
this.setFileInfo(this.fileInfo)
}
}
},
mounted() {
// append the backbone element and set the FileInfo
this.component.$el.appendTo(this.$el)
},
methods: {
setFileInfo(fileInfo) {
this.component.setFileInfo(new OCA.Files.FileInfoModel(fileInfo))
}
}
}
</script>
<style>
</style>
59 changes: 59 additions & 0 deletions apps/files/src/components/LegacyView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!--
- @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
-
- @author John Molakvoæ <skjnldsv@protonmail.com>
-
- @license GNU AGPL version 3 or any later version
-
- 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/>.
-
-->

<template>
<div />
</template>
<script>
export default {
name: 'LegacyView',
props: {
component: {
type: Object,
required: true
},
fileInfo: {
type: Object,
default: () => {},
required: true
}
},
watch: {
fileInfo(fileInfo) {
// update the backbone model FileInfo
this.setFileInfo(fileInfo)
}
},
mounted() {
// append the backbone element and set the FileInfo
this.component.$el.replaceAll(this.$el)
this.setFileInfo(this.fileInfo)
},
methods: {
setFileInfo(fileInfo) {
this.component.setFileInfo(new OCA.Files.FileInfoModel(fileInfo))
}
}
}
</script>
<style>
</style>
Loading

0 comments on commit fd90af5

Please sign in to comment.