winter icon indicating copy to clipboard operation
winter copied to clipboard

Add "Duplicate" feature to mediamanager

Open damsfx opened this issue 1 year ago • 17 comments

Add a button for duplicating files or folders in the Media Manager menu bar.

Single item selection:

If a file or folder is selected, the user is prompted for the new name of the duplicated file/folder.

Multiple item selection:

If multiple files and/or folders are selected, a warning is displayed to the user that the files/folders will be duplicated with an automatically generated name.

Automatically generated names :

"-x" is added to the name of the item to be duplicated, where x is a numeric counter. The folder where the item is located is scanned for occurrences with identical names.

For example, myfile.pdf will give myfile-1.pdf. If myfile-1.pdf is already present, then the new name will be myfile-2.pdf.

Required: https://github.com/wintercms/storm/pull/186

damsfx avatar Mar 11 '24 11:03 damsfx

@damsfx can you add some screenshots?

LukeTowers avatar Aug 02 '24 09:08 LukeTowers

@LukeTowers WinterCMS_Mediamanager_Duplicate.webm

New button : image

Popup to give new name (with suggested one) : image

Popup for multiple selected files or folders : image

Automatically generated names :

"_x" is added to the name of the item to be duplicated, where x is a numeric counter. The folder where the item is located is scanned for occurrences with identical names.

For example, myfile.pdf will give myfile_1.pdf. If myfile_1.pdf is already present, then the new name will be myfile_2.pdf. If myfile_1.pdf and myfile_4.pdf is already present, then the new name will be myfile_5.pdf.

damsfx avatar Aug 02 '24 14:08 damsfx

Fantastic @damsfx! What happens if they rename the proposed name in the duplicate file popup to the original name (ignoring the suggested name)?

LukeTowers avatar Aug 04 '24 05:08 LukeTowers

@LukeTowers the golden question! I don't remember to have make that test. It use storage facade copy method witch is just a return of the PHP native one.

The php copy manual says:

Warning If the destination file already exists, it will be overwritten.

So I think it may be the same here.

Test needed and if it's the case, maybe ask the user to confirm the overwrite?

damsfx avatar Aug 05 '24 01:08 damsfx

@LukeTowers I can confirm that a file with the same name is overwritten.

What solution do you plan to use to solve this problem?
An alert informing the user/requesting his confirmation, a return with no action other than a flash message?

damsfx avatar Aug 20 '24 16:08 damsfx

@damsfx I would say probably start with just throwing an ApplicationException which will popup the error. I'm not sure how we're currently handling it in the rename popup and / or on file upload, maybe take a quick look there and then we can standardize across all three?

LukeTowers avatar Aug 20 '24 20:08 LukeTowers

@LukeTowers At this time, both upload and rename actions simply replace an existing file, no errors, no warnings.

damsfx avatar Aug 24 '24 17:08 damsfx

@damsfx thats what I thought, I think there was an issue at some point to fix that by auto renaming to the suffixed form, any thoughts on the approach that we should take for all of the scenarios so that we can standardize on that? I think the options are:

  • Do nothing and silently allow the replacement
  • throw an applicationexception refusing to overwrite an existing file
  • allow the file put but force a rename to an auto suffixed filename
  • present a dialog offering the choice to the user

The last option is slightly more difficult to implement but I think is the best option. Do you have any other thoughts or perhaps any options I missed?

Also would like to get input from any of the other maintainers if they're available (@bennothommo, @mjauvin, @jaxwilko).

LukeTowers avatar Aug 24 '24 18:08 LukeTowers

I would definitely prefer the following option:

allow the file put but force a rename to an auto suffixed filename

mjauvin avatar Aug 24 '24 21:08 mjauvin

I agree with @mjauvin. It's the least intrusive and destructive. If someone wants to be clever with their naming, they will most certainly be skilled enough to find the file with an additional suffix.

bennothommo avatar Aug 26 '24 04:08 bennothommo

It's hard to say ...

Allowing an existing file to be overwritten (without warning) can be an advantage, but it can also be a risk.

Having a warning before any file overwrite action would be a bonus, but perhaps this behaviour should be configurable in the backend settings?

damsfx avatar Aug 26 '24 14:08 damsfx

The way it's typically handled in OS level file managers is to present a dialog that asks the user if they want to Replace, Keep Both (auto rename), or Cancel. That would be my preferred way to handle it here, but I'm also fine with defaulting to Keep Both if that's easier to implement to start with.

LukeTowers avatar Aug 26 '24 16:08 LukeTowers

@LukeTowers , @mjauvin , @bennothommo Would you prefer this PR to include the changes so that the existing files are no longer overwritten by the uploaded/renamed/duplicated files, or would you prefer this to be done at a later date with a new PR?

damsfx avatar Sep 04 '24 18:09 damsfx

I prefer to include it in this PR

mjauvin avatar Sep 04 '24 22:09 mjauvin

looking GREAT! This will be used a lot by my team creating the content

AIC-BV avatar Sep 10 '24 13:09 AIC-BV

@AIC-BV As a user likely to use this function a lot, what are your feelings about overwriting files already present with the same name (see previous messages)?

damsfx avatar Sep 10 '24 16:09 damsfx

@AIC-BV As a user likely to use this function a lot, what are your feelings about overwriting files already present with the same name (see previous messages)?

It can work both ways but I think that the correct way, or the expected UX default behaviour, is to not automatically overwrite it. Preventing accidental data loss is the most important. Overwriting it is a risk, like you said above, and I think you should avoid risk if you can choose to.

When you do this in Windows File Explorer it automatically changes the name to 'filename - Copy' which makes sense to me. Just like you did with the _1, _2, _3, ... It is up to the content creater to name the files correct, or remove the duplicate ones.

For me it doesn't need a popup, just the 'version' behind the string. A popup can work too but that is not the default file explorer behaviour, but perhaps its different on Mac

AIC-BV avatar Sep 10 '24 18:09 AIC-BV