Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File templates #25090

Merged
merged 11 commits into from
Jan 28, 2021
Merged

File templates #25090

merged 11 commits into from
Jan 28, 2021

Conversation

juliusknorr
Copy link
Member

@juliusknorr juliusknorr commented Jan 12, 2021

Fixes #22426

  • API endpoint for fetching list of available template
  • API endpoint for creating a new file from a template
  • Provide list of available templates through initial state OCP.InitialState.loadState('files', 'templates')
  • Provide template path as initial state value OCP.InitialState.loadState('files', 'template_path'), will throw an error if no template path is available
  • API endpoint for configuring the user template directory
  • Create translated "Templates" directory on skeleton file setup
  • Copy over templates from either skeleton files or provide a separate config for a template directory
  • Rename the "Templates" directory to the users language
  • Add ratio for template types
  • Frontend @skjnldsv
    • User template directory settings
    • Register file create actions for individual template types
    • Show modal on file creation
    • Open the file with the default file opener action after creating
    • We might need to update the fetched templates from initial state on the fly if the user uploads a template and then tries to create a new file without reloading
    • Option to create a new template directory if none exists

Separate pull requests

Possible follow up enhancements

Editor app integrations

API endpoints

GET /ocs/v2.php/apps/files/api/v1/templates

Example response:

{
  "ocs": {
    "meta": {
      "status": "ok",
      "statuscode": 200,
      "message": "OK"
    },
    "data": [
      {
        "app": "text",
        "label": "New text file",
        "extension": ".md",
        "mimetypes": [
          "text\/markdown"
        ],
        "templates": [
          {
            "basename": "Meeting minutes.md",
            "etag": "896c403843057e7f26cb1750cf033d3f",
            "fileid": 9577,
            "filename": "\/Templates\/Meeting minutes.md",
            "lastmod": 1610444284,
            "mime": "text\/markdown",
            "size": 78,
            "type": "file",
            "hasPreview": true
          },
          {
            "basename": "Project planning.md",
            "etag": "1ac7b187795872409738f3fd2cfc348a",
            "fileid": 9590,
            "filename": "\/Templates\/Project planning.md",
            "lastmod": 1610377506,
            "mime": "text\/markdown",
            "size": 1,
            "type": "file",
            "hasPreview": true
          }
        ]
      },
      {
        "app": "text",
        "label": "New plain text file",
        "extension": ".txt",
        "mimetypes": [
          "text\/plain"
        ],
        "templates": []
      }
    ]
  }
}
POST /ocs/v2.php/apps/files/api/v1/templates/create

Parameters:

Parameter Description
filePath (string) Absolute path to the target file that shall be created in the user home
templatePath (string) OPTIONAL Absolute path to the template file that will be used as a source, leave empty to create an empty file

200 Success

{
  "ocs": {
    "meta": {
      "status": "ok",
      "statuscode": 200,
      "message": "OK"
    },
    "data": {
      "basename": "newfa1ile.md",
      "etag": "46b90bf0b0c353819b2aed817cd2aae9",
      "fileid": 9644,
      "filename": "\/newfa1ile.md",
      "lastmod": 1610448262,
      "mime": "text\/markdown",
      "size": 78,
      "type": "file",
      "hasPreview": true
    }
  }
}

403

{
  "ocs": {
    "meta": {
      "status": "failure",
      "statuscode": 403,
      "message": "File already exists"
    },
    "data": []
  }
}
POST /ocs/v2.php/apps/files/api/v1/templates/path

Parameters:

Parameter Description
templatePath (string) Absolute path to the users template directory in the user home
copySystemTemplates (bool) OPTIONAL Set to true to copy over system templates to the newly set template path

200 Success

{
  "ocs": {
    "meta": {
      "status": "ok",
      "statuscode": 200,
      "message": "OK"
    },
    "data": []
  }
}

@skjnldsv

This comment has been minimized.

@skjnldsv
Copy link
Member

Peek 14-01-2021 14-28

@skjnldsv
Copy link
Member

  • API endpoint for configuring the user template directory

I think that is fine as is, no? Do we need a custom setting to allow users to change the folder name?

@juliusknorr
Copy link
Member Author

I think that is fine as is, no? Do we need a custom setting to allow users to change the folder name?

I think we should still offer changing the path in case you have your templates somewhere else, but I'd leave that to @jancborchardt to decide.

@jancborchardt
Copy link
Member

Yoooo super nice work @juliushaertl! Already looks very good. 2 small pieces of feedback before I look more into the design and templates:

  • Can you move the file name input into the "Pick a template" modal, on the top? Then it would be main heading "New text document" and an input field with "File name …" placeholder and below that "Pick a template".
  • "Empty file" should go first in the list of templates

I think we should still offer changing the path in case you have your templates somewhere else, but I'd leave that to @jancborchardt to decide.

Yes, probably makes sense to have that in the bottom left settings as "Templates folder". Especially if people just sync their normal folders and on different operating systems they have different naming conventions.

@juliusknorr
Copy link
Member Author

Forwarding all the praise for the nice looking UI to @skjnldsv 👏

@skjnldsv
Copy link
Member

  • Can you move the file name input into the "Pick a template" modal, on the top? Then it would be main heading "New text document" and an input field with "File name …" placeholder and below that "Pick a template".

No, that's not how the new file menu was designed.

  • "Empty file" should go first in the list of templates

👍

@juliusknorr
Copy link
Member Author

Time to get this in 🏓 for reviews

@rullzer
Copy link
Member

rullzer commented Jan 27, 2021

Found some things (maybe they can be done now or in a followup)

  • For me (so on upgrade) when I set a template folder that options remains. Only upon refresh it goes away.
  • I can't set an existing folder as template folder with the + menu
  • I can't seem to change my template folder
  • With the corresponding text branch I get 2 entries to create text documents?

Copy link
Member

@rullzer rullzer left a comment

Choose a reason for hiding this comment

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

See my comment. I guess some can be moved to follow up tickets some should be fixed here.
But the general concept with text works! Whoohoo

Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

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

some feedback on the OCP changes :)

lib/public/Files/Template/CreatedFromTemplateEvent.php Outdated Show resolved Hide resolved
lib/public/Files/Template/ITemplateManager.php Outdated Show resolved Hide resolved
lib/public/Files/Template/ITemplateManager.php Outdated Show resolved Hide resolved
lib/public/Files/Template/Template.php Outdated Show resolved Hide resolved
lib/public/Files/Template/Template.php Outdated Show resolved Hide resolved
@juliusknorr
Copy link
Member Author

some feedback on the OCP changes :)

Thanks a lot, makes all sense. I'll adjust that tomorrow morning.

juliusknorr and others added 10 commits January 28, 2021 11:59
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
…mplates by default

Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
…isting directories

Signed-off-by: Julius Härtl <jus@bitgrid.net>
…type registration lazy

Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
@juliusknorr
Copy link
Member Author

/compile amend /

/**
* Register a template type support
*
* @param callable(): TemplateFileCreator $callback A callback which returns the TemplateFileCreator instance to register
Copy link
Member

Choose a reason for hiding this comment

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

nit: @psalm-param callable():TemplateFileCreator $callback

Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

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

Code looks good

Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

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

Tested with Text and works flawless (once I figured out how it actually works, I expected new entries in the + menu somehow)

👍 💯 :shipit:

Copy link
Member

@rullzer rullzer left a comment

Choose a reason for hiding this comment

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

Whoohoo let's go

Signed-off-by: Julius Härtl <jus@bitgrid.net>
@juliusknorr
Copy link
Member Author

Ok, bundles happy after i removed the stupid random files i committed 🙈

@juliusknorr juliusknorr mentioned this pull request Jan 28, 2021
5 tasks
@juliusknorr
Copy link
Member Author

Follow up polishing tasks are in #25358

@rullzer rullzer merged commit 62fa85c into master Jan 28, 2021
@rullzer rullzer deleted the enh/file-templates branch January 28, 2021 15:17
@ChristophWurst ChristophWurst added the pending documentation This pull request needs an associated documentation update label Jan 28, 2021
@@ -198,7 +203,21 @@
iconClass: actionSpec.iconClass,
fileType: actionSpec.fileType,
actionHandler: actionSpec.actionHandler,
});
checkFilename: actionSpec.checkFilename
Copy link
Member

@skjnldsv skjnldsv Jun 9, 2022

Choose a reason for hiding this comment

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

@juliushaertl do you recall why/where we're actually using this?

Copy link
Member Author

Choose a reason for hiding this comment

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

No I cannot remember anything in that regard 🙈

Also no other occurrence in my local checkouts, so I'd say this can be dropped.

Copy link
Member

Choose a reason for hiding this comment

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

Good! I'll see with the new implementation :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement pending documentation This pull request needs an associated documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File templates
5 participants