Skip to content

Commit

Permalink
Merge pull request #2759 from nextcloud/fix/noid/nc25-sharing-changes
Browse files Browse the repository at this point in the history
Nextcloud 25 - Share changes
  • Loading branch information
max-nextcloud authored Jul 29, 2022
2 parents 463f6d8 + e4d06d2 commit cfa8c30
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 103 deletions.
20 changes: 14 additions & 6 deletions cypress/e2e/files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@
*
*/

describe('Files default view', function() {
beforeEach(function() {
cy.login('admin', 'admin')
import { randHash } from '../utils/index.js'

const randUser = randHash()

describe('Files default view', () => {
before(() => {
cy.nextcloudCreateUser(randUser, randUser)
})

beforeEach(() => {
cy.login(randUser, randUser)
})

it('See the default files list', function() {
cy.get('.files-fileList tr').should('contain', 'welcome.txt')
it('See the default files list', () => {
cy.get('#app-content-files table tr').should('contain', 'welcome.txt')
})

it('Take screenshot', function() {
it('Take screenshot', () => {
cy.screenshot()
})
})
86 changes: 37 additions & 49 deletions cypress/e2e/share.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,12 @@ describe('Open test.md in viewer', function() {
cy.get('#app-sidebar-vue button.new-share-link').trigger('click')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => {
cy.visit(href)
cy.window().then(win => {
win.OC.appswebroots.files_texteditor = true
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
})
.then((href) => cy.visit(href))
.then(() => {
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
})
})

Expand All @@ -80,20 +77,17 @@ describe('Open test.md in viewer', function() {
cy.get(checkboxAllowEditing).first().should('be.checked')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => {
cy.visit(href)
cy.window().then(win => {
win.OC.appswebroots.files_texteditor = true
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
.then((href) => cy.visit(href))
.then(() => {
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')

cy.getMenu().should('be.visible')
cy.getActionEntry('undo').should('be.visible')
cy.getActionEntry('redo').should('be.visible')
cy.getActionEntry('bold').should('be.visible')
})
cy.getMenu().should('be.visible')
cy.getActionEntry('undo').should('be.visible')
cy.getActionEntry('redo').should('be.visible')
cy.getActionEntry('bold').should('be.visible')
})
})

Expand All @@ -107,22 +101,19 @@ describe('Open test.md in viewer', function() {
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => {
cy.logout()
cy.visit(href)
cy.window().then(win => {
win.OC.appswebroots.files_texteditor = true
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1000)
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
return cy.logout()
.then(() => cy.visit(href))
})
.then(() => {
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')

cy.getMenu().should('be.visible')
cy.getActionEntry('undo').should('be.visible')
cy.getActionEntry('redo').should('be.visible')
cy.getActionEntry('bold').should('be.visible')
})
cy.getMenu().should('be.visible')
cy.getActionEntry('undo').should('be.visible')
cy.getActionEntry('redo').should('be.visible')
cy.getActionEntry('bold').should('be.visible')
})
})

Expand All @@ -136,18 +127,15 @@ describe('Open test.md in viewer', function() {
cy.get('#app-sidebar-vue button.new-share-link').trigger('click')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => {
cy.visit(href)
cy.window().then(win => {
win.OC.appswebroots.files_texteditor = true
cy.get('#rich-workspace').should('contain', 'Hello world')
cy.openFile('test.md')
cy.get('#editor-container').should('be.visible')
cy.get('#editor .ProseMirror').should('contain', 'Hello world')
cy.get('#editor .ProseMirror h2').should('contain', 'Hello world')
cy.get('.modal-header button.header-close').click()
cy.get('.modal-mask').should('not.exist')
})
.then((href) => cy.visit(href))
.then(() => {
cy.get('#rich-workspace').should('contain', 'Hello world')
cy.openFile('test.md')
cy.get('#editor-container').should('be.visible')
cy.get('#editor .ProseMirror').should('contain', 'Hello world')
cy.get('#editor .ProseMirror h2').should('contain', 'Hello world')
cy.get('.modal-header button.header-close').click()
cy.get('.modal-mask').should('not.exist')
})
})

Expand Down
4 changes: 2 additions & 2 deletions js/editor-rich.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor-rich.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ const registerFileCreate = () => {

const registerFileActionFallback = () => {
const sharingToken = document.getElementById('sharingToken') ? document.getElementById('sharingToken').value : null
const dir = document.getElementById('dir').value
const filesTable = document.querySelector('#preview table.files-filestable')

if (!sharingToken || dir !== '') {
if (!sharingToken || !filesTable) {
const ViewerRoot = document.createElement('div')
ViewerRoot.id = 'text-viewer-fallback'
document.body.appendChild(ViewerRoot)
Expand Down
75 changes: 44 additions & 31 deletions src/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,61 @@ import store from './store.js'
__webpack_nonce__ = btoa(OC.requestToken) // eslint-disable-line
__webpack_public_path__ = OC.linkTo('text', 'js/') // eslint-disable-line

const loadEditor = ({ sharingToken, mimetype, $el }) => {
const container = document.createElement('div')
container.id = 'texteditor'

document.getElementById('app-content').appendChild(container)

Promise.all([
import(/* webpackChunkName: "vendor" */'vue'),
import(/* webpackChunkName: "editor" */'./components/EditorWrapper.vue'),
])
.then(([vue, editor]) => ({
Vue: vue.default,
Editor: editor.default,
}))
.then(({ Vue, Editor }) => {
Vue.prototype.t = window.t
Vue.prototype.OCA = window.OCA

new Vue({
render: h => h(Editor, {
props: {
active: true,
shareToken: sharingToken,
mime: mimetype,
},
}),
store,
})
.$mount($el)

})
.catch(console.error)
}

documentReady(() => {
const dir = document.getElementById('dir').value
const mimetype = document.getElementById('mimetype').value
const sharingToken = document.getElementById('sharingToken') ? document.getElementById('sharingToken').value : null

if (!sharingToken) {
return
}

if (dir !== '') {
const filesTable = document.querySelector('#preview table.files-filestable')

// list of files - dir sharing
if (filesTable) {
OC.Plugins.register('OCA.Files.FileList', FilesWorkspacePlugin)
registerFileActionFallback()
registerFileCreate()
} else {
// single file share
const container = document.createElement('div')
container.id = 'texteditor'
const body = document.getElementById('app-content')
body.appendChild(container)

if (openMimetypes.indexOf(mimetype) !== -1) {
Promise.all([
import(/* webpackChunkName: "vendor" */'vue'),
import(/* webpackChunkName: "editor" */'./components/EditorWrapper.vue'),
]).then((imports) => {
const Vue = imports[0].default
Vue.prototype.t = window.t
Vue.prototype.OCA = window.OCA
const Editor = imports[1].default
const vm = new Vue({
render: h => h(Editor, {
props: {
active: true,
shareToken: sharingToken,
mime: mimetype,
},
}),
store,
})
vm.$mount(document.getElementById('preview'))
})
}
return
}

// single file share
if (openMimetypes.indexOf(mimetype) !== -1) {
loadEditor({ mimetype, sharingToken, $el: document.getElementById('preview') })
}
})

Expand Down

0 comments on commit cfa8c30

Please sign in to comment.