Skip to content

Conversation

@azul
Copy link
Contributor

@azul azul commented Jun 16, 2020

Summary

Add a button to the menu bubble that links to local files.
See #308 for descriptions of the approach.

  • open in new tab on middle click and ctrl-click.
  • change dir param according to relative Path.
  • Open the file directly in viewer
  • Create urls that work everywhere - even from talk.
  • Make all strings translateable.
  • Fix creating links in workspace (currently uses wrong url for PROPFIND) - also seems to be an issue with images

@azul azul force-pushed the enh/link-to-files branch 2 times, most recently from 3bcae6a to 0e48993 Compare June 18, 2020 05:03
@azul
Copy link
Contributor Author

azul commented Jun 18, 2020

Here's a little demo of the basic functionality:
link-demo

@juliusknorr juliusknorr added 3. to review enhancement New feature or request labels Jun 18, 2020
@azul
Copy link
Contributor Author

azul commented Jun 18, 2020

I think this is enough for a first PR.

Things that i know are missing:

  • changing the browser title when following links
  • history / back button to go back after following a link
  • linking from within the workspace area.
    (links work but creating them is broken just like inserting images is -> fix: path for workspaces #888 )

I'd be happy to see this merged as is. But maybe i can get to some of those before a review is ready.

@juliusknorr
Copy link
Member

Wow, amazing contribution ❤️

I'll give this a detailed review later, the general approach seems all good to me.

changing the browser title when following links
history / back button to go back after following a link

Might be that those two are things we need to fix in viewer or the files app.

if (query.dir && fragment.relPath) {
const filename = fragment.relPath.split('/').pop()
const path = `${query.dir}/${filename}`
OCA.Viewer.open({ path })
Copy link
Contributor Author

@azul azul Jun 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not have the fileId as a fallback.
Sharing may lead to different directory layouts for different users.
If the calculated path is wrong for the current user... there is no way for the Viewer to recover from that.

We could find out the right path by looking up the exact file path by fileid.
But that adds complexity and another roundtrip.
This is an optimization to open links more smoothly then with window.location.
So it would be nice to avoid the roundtrip.

Not sure what the best approach here is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm also not sure what to do in that regards.

@azul
Copy link
Contributor Author

azul commented Jun 19, 2020

@juliushaertl You are right about the history navigation. There's no onPopState handler in the files app yet.

nextcloud/viewer#497 is an attempt to move in that direction.

@juliusknorr
Copy link
Member

@azul Just a sidenode to make the rebasing process a bit easier, feel free to not commit the bundles until it is approved, and then we just add them right before the merge.

Copy link
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments to the code, otherwise fine to get this in as a first step 👍

@azul azul force-pushed the enh/link-to-files branch 2 times, most recently from ea01a65 to d02a594 Compare June 25, 2020 07:59
@azul
Copy link
Contributor Author

azul commented Jun 25, 2020

@juliushaertl I rebased everything and added the regex fix you proposed.

@azul azul requested a review from juliusknorr June 25, 2020 08:04
@jancborchardt
Copy link
Member

Wow @azul, that is amazing! Especially the linking to other markdown files – it’s the Hypertext! :)

@azul
Copy link
Contributor Author

azul commented Jul 13, 2020

@juliushaertl I rebased again.

I think i addressed your comments. Please approve or let me know what else is missing.

Thanks 😃

@jancborchardt
Copy link
Member

By the way @azul, we have a chat channel "Text team" on our Nextcloud Talk instance. I can invite you for a guest account via your email address if you like? :)

@azul
Copy link
Contributor Author

azul commented Jul 24, 2020

I can invite you for a guest account via your email address if you like? :)

@jancborchardt, please do 😃

Copy link
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this 👍

azul and others added 13 commits August 11, 2020 15:19
Tries both approaches: from the menu bubble and the menu bar

Menu bubble works quite well so far.
Only uses absolute paths.

Menu bar uses relative paths.

Pass filepath to Menu bubble so it cat
* start there
* calculate relative paths

Move the logic for relative paths to helper.

Make all strings translateable.

Render relative links properly.
The way we do this for img tags serves as an example.

Signed-off-by: Azul <azul@riseup.net>
Since the menu bubble deals with links
it makes more sense to add the button here.

Moved it to the initial part of the menu bubble
as an alternative to the link form.

Hand current path to menu bubble and use it
* to start from there when picking the file to link to
* to calculate the relative path.

Signed-off-by: Azul <azul@riseup.net>
The short relative links used in markdown
need to be converted to working urls in the href attributes.

In order to properly serialize the content
the full urls in html need to be converted to relative links as well.

This commit splits out the href handling into a new helper.
This way it can be easily tested.

Signed-off-by: Azul <azul@riseup.net>
The markdown we create for links to local files looks like this:
```
[Check this out!](subdir/file.md?fileid=123)
```

Turn this into a link like this
```
<a href="?dir=/current&openfile=123&relPath=subdir/file.md">
  Check this out!
</a>
```

The `relPath` part of the url is needed
to convert it back to the original markdown.

Includes a test.

Next steps:
* open links to local files in same tab.
* change dir param according to relative Path.

Signed-off-by: Azul <azul@riseup.net>
When navigating between different text documents
one does not expect to open new windows all the time.

Next steps:

* open in new tab on middle click.

Signed-off-by: Azul <azul@riseup.net>
also take into account `ctrl` keys.

Use the href from html rather than markdown.
This is an actual link that will work in nextcloud.

Signed-off-by: Azul <azul@riseup.net>
Signed-off-by: Azul <azul@riseup.net>
rather than opening a completely new page

Signed-off-by: Azul <azul@riseup.net>
This way they also work if the viewer was opened from other apps
than the file app.

Also move the `relPath` param into the fragment.
It is only used to remember the relative path
for generating the short markdown form from the link.

Signed-off-by: Azul <azul@riseup.net>
Signed-off-by: Azul <azul@riseup.net>
This used to be working but was broken
by having full hrefs rather than just the query part.

Now we check if the domain remains the same
and if we have a `dir` param in the query
and a `relPath` param in the fragment.

This should be a pretty good check for links
that we can open in the viewer right away.

Signed-off-by: Azul <azul@riseup.net>
Signed-off-by: Azul <azul@riseup.net>
make sure there are decimals in the fileId

Co-authored-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Azul <azul@riseup.net>
@azul azul force-pushed the enh/link-to-files branch from f9be824 to aa7fc93 Compare August 11, 2020 13:49
This is more relyable then parsing the window location query for dir:
* ?dir does not change when navigating between files right now
* ?dir is not present when the viewer is used from within other apps.

We used to fallback to the viewer state which solved the latter.
However it is easier and less error prone
to just rely on viewer state in the first place.

Signed-off-by: Azul <azul@riseup.net>
@azul azul force-pushed the enh/link-to-files branch from aa7fc93 to e955b5a Compare August 11, 2020 14:10
@juliusknorr
Copy link
Member

/compile /

@juliusknorr
Copy link
Member

Cypress failures are unrelated.

Signed-off-by: npmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com>
@juliusknorr juliusknorr merged commit 69690ff into master Aug 12, 2020
@juliusknorr juliusknorr deleted the enh/link-to-files branch August 12, 2020 05:43
@jochenstu
Copy link

Linking to a docx file leads to an "There is no plugin available to display this file type" Error with OnlyOffice installed.

@azul
Copy link
Contributor Author

azul commented Nov 3, 2020

@jochenstu I created a new issue for this so it does not get lost here.

tasmo pushed a commit to prototypefund/nextcloud-collectives that referenced this pull request Dec 2, 2020
That is also the format proposed for the nextcloud text app
in nextcloud/text#879.

This commit changes the router-links in the nav.
It also works with links created by NC text
but it will open them in new tabs
because that is what tiptap does by default.
@kevinde91
Copy link

Great work so far!
As I was looking for relPaths in Nextcloud I came up here.

So the case that a file is moved is allready mentioned, but what if the file is copied?
A new fileid will be generated and the link will redirect to the old file, right?

Is it possible to link a file with unknown id while the relPath (including file name) is known?

Thanks for your help!

@azul
Copy link
Contributor Author

azul commented Jan 12, 2021

@kevinde91 I am not sure i understand the situation you are describing. Let me try to rephrase what i understood:

  • I create a file called original.md - it gets some file id say 123
  • I link to that file from another file in the text editor - the link will point to original.md?fileId=123
  • I copy the file to copy.md - the new file gets a id say 234.

Now the link will still point to original.md with it's file id. This seems intuitive to me. Would you like this behaviour to change?

Another thing we were discussing was allowing the creation of links to yet to be created files:

  • I link to copy.md even though it does not exist yet.
  • When clicking the link it will create the file and allow me to edit it.
  • When copying original.md to copy.md the link will start pointing to the copied file.

Is that what you were talking about?
My understanding is that this currently does not work with the text app. It lacks

  • The ui for generating links to arbitrary (possibly non-existing file names)
    (It should very much be possible by editing the markdown with other means.)
  • Handling links to missing docs by creating the doc.

@kevinde91
Copy link

@azul thanks for the fast reply, and sorry for the confusion.

I tried to recreated my problem and this time it behaved exactly how it should:

  1. Create a folder 'Original'
  2. Create a folder 'Subfolder' in 'Original'
  3. Create file 'linked_file.md' in 'Subfolder' with some text and create file 'test.md' with a link to 'linked_file.md'
  4. Create a folder 'Copy' in the root dir
  5. Copy 'Subfolder' from 'Original' to 'Copy'
  6. Change text in 'Copy/Subfolder/linked_file.md'
  7. Open 'Copy/Subfolder/test.md' and click on the link, the new 'linked_file.md' with changed text will be openend.

Sorry again for wasting your time, not sure what I did wrong yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4. to release enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Easily add links to other nextcloud files

6 participants