From 9281378a67f13c2cb7b542fb85bfb037fd8a0c0f Mon Sep 17 00:00:00 2001 From: Valle Date: Mon, 31 Aug 2020 18:55:43 +0200 Subject: [PATCH] added history length option --- administrator/components/com_media/config.xml | 12 ++++++++ .../com_media/tmpl/file/default.php | 1 + .../com_media/tmpl/media/default.php | 1 + administrator/language/en-GB/com_media.ini | 2 ++ .../com_media/js/edit-images.es6.js | 29 ++++++++++++------- installation/sql/mysql/base.sql | 2 +- installation/sql/postgresql/base.sql | 2 +- language/en-GB/com_media.ini | 2 ++ 8 files changed, 39 insertions(+), 12 deletions(-) diff --git a/administrator/components/com_media/config.xml b/administrator/components/com_media/config.xml index d571a7107e54f..644542fa7a087 100644 --- a/administrator/components/com_media/config.xml +++ b/administrator/components/com_media/config.xml @@ -109,6 +109,17 @@ default="text/html" showon="restrict_uploads:1" /> + +
+ diff --git a/administrator/components/com_media/tmpl/file/default.php b/administrator/components/com_media/tmpl/file/default.php index 33813f0998ff4..f8e1f7778a2a1 100644 --- a/administrator/components/com_media/tmpl/file/default.php +++ b/administrator/components/com_media/tmpl/file/default.php @@ -46,6 +46,7 @@ 'allowedUploadExtensions' => $params->get('upload_extensions', ''), 'maxUploadSizeMb' => $params->get('upload_maxsize', 10), 'contents' => $this->file->content, + 'historyLength' => $params->get('history_length', 25), ]; $this->document->addScriptOptions('com_media', $config); diff --git a/administrator/components/com_media/tmpl/media/default.php b/administrator/components/com_media/tmpl/media/default.php index e478562ea7c4f..368e99048c6ef 100644 --- a/administrator/components/com_media/tmpl/media/default.php +++ b/administrator/components/com_media/tmpl/media/default.php @@ -45,6 +45,7 @@ 'editViewUrl' => Uri::root() . 'administrator/index.php?option=com_media&view=file' . (!empty($tmpl) ? ('&tmpl=' . $tmpl) : ''), 'allowedUploadExtensions' => $params->get('upload_extensions', ''), 'maxUploadSizeMb' => $params->get('upload_maxsize', 10), + 'historyLength' => $params->get('history_length', 25), 'providers' => (array) $this->providers, 'currentPath' => $this->currentPath, 'isModal' => $tmpl === 'component', diff --git a/administrator/language/en-GB/com_media.ini b/administrator/language/en-GB/com_media.ini index 7076975beadc8..9fddd585aa691 100644 --- a/administrator/language/en-GB/com_media.ini +++ b/administrator/language/en-GB/com_media.ini @@ -55,6 +55,8 @@ COM_MEDIA_FOLDER="Folder" COM_MEDIA_FOLDER_NAME="Folder Name" COM_MEDIA_FOLDERS="Media Folders" COM_MEDIA_FOLDERS_PATH_LABEL="Warning! Path Folder
Changing the 'Path to files folder' from the default of 'images' may break your links.
The 'Path to images' folder has to be the same or a subfolder of 'Path to files'." +COM_MEDIA_HISTORY_LENGTH_DESC="Set the number of states stored in the history to a value between 1 and 100." +COM_MEDIA_HISTORY_LENGTH_LABEL="History States" COM_MEDIA_INCREASE_GRID="Increase grid size" COM_MEDIA_MEDIA_DATE_CREATED="Date Created" COM_MEDIA_MEDIA_DATE_MODIFIED="Date Modified" diff --git a/build/media_source/com_media/js/edit-images.es6.js b/build/media_source/com_media/js/edit-images.es6.js index e7d65330162e1..d9d9ba89bb00c 100644 --- a/build/media_source/com_media/js/edit-images.es6.js +++ b/build/media_source/com_media/js/edit-images.es6.js @@ -27,10 +27,10 @@ Joomla.MediaManager = Joomla.MediaManager || {}; const addHistoryPoint = (data) => { if (Joomla.MediaManager.Edit.original !== Joomla.MediaManager.Edit.current.contents) { - let key = Object.keys(Joomla.MediaManager.Edit.history).length; - key = key > 0 ? key - 1 : key; + const key = Joomla.MediaManager.Edit.history.lastKey; if (Joomla.MediaManager.Edit.history[key] && Joomla.MediaManager.Edit.history[key - 1] - && Joomla.MediaManager.Edit.history[key].file === Joomla.MediaManager.Edit.history[key - 1].file) { + && Joomla.MediaManager.Edit.history[key].file + === Joomla.MediaManager.Edit.history[key - 1].file) { return; } Joomla.MediaManager.Edit.history[key + 1] = {}; @@ -45,10 +45,17 @@ Joomla.MediaManager = Joomla.MediaManager || {}; } else { Object.assign(Joomla.MediaManager.Edit.history[key + 1].data, data.detail); } + // eslint-disable-next-line max-len Joomla.MediaManager.Edit.history[key + 1].data[data.detail.plugin] = data.detail[data.detail.plugin]; } - Joomla.MediaManager.Edit.history.current = Number(Joomla.MediaManager.Edit.history.current) + 1; + // eslint-disable-next-line max-len + Joomla.MediaManager.Edit.history.lastKey = Number(Joomla.MediaManager.Edit.history.lastKey) + 1; + Joomla.MediaManager.Edit.history.current = Number(Joomla.MediaManager.Edit.history.lastKey); + if (Joomla.MediaManager.Edit.history.lastKey > options.historyLength) { + // eslint-disable-next-line max-len + delete Joomla.MediaManager.Edit.history[Joomla.MediaManager.Edit.history.lastKey - options.historyLength]; + } } }; @@ -84,6 +91,7 @@ Joomla.MediaManager = Joomla.MediaManager || {}; // Set first history point if (Object.keys(Joomla.MediaManager.Edit.history).length === 0) { Joomla.MediaManager.Edit.history.current = 0; + Joomla.MediaManager.Edit.history.lastKey = 0; addHistoryPoint('reset'); } }; @@ -111,10 +119,7 @@ Joomla.MediaManager = Joomla.MediaManager || {}; Joomla.MediaManager.Edit[link.id.replace('tab-attrib-', '').toLowerCase()].Deactivate(); - let data = Joomla.MediaManager.Edit.current; - if (!current || (current && current !== true)) { - data = Joomla.MediaManager.Edit.original; - } + const data = Joomla.MediaManager.Edit.current; link.click(); @@ -133,7 +138,10 @@ Joomla.MediaManager = Joomla.MediaManager || {}; }); Joomla.MediaManager.Edit.Undo = () => { - if (Joomla.MediaManager.Edit.history.current && Joomla.MediaManager.Edit.history.current - 1 > 0) { + if (Joomla.MediaManager.Edit.history.current && Joomla.MediaManager.Edit.history.current - 1 + > Joomla.MediaManager.Edit.history.lastKey + - Object.keys(Joomla.MediaManager.Edit.history).length + 2) { + // eslint-disable-next-line max-len Joomla.MediaManager.Edit.history.current = Number(Joomla.MediaManager.Edit.history.current) - 1; Joomla.MediaManager.Edit.Reset(Joomla.MediaManager.Edit.history.current); } @@ -141,7 +149,8 @@ Joomla.MediaManager = Joomla.MediaManager || {}; Joomla.MediaManager.Edit.Redo = () => { if (Joomla.MediaManager.Edit.history.current && Joomla.MediaManager.Edit.history.current + 1 - < Object.keys(Joomla.MediaManager.Edit.history).length) { + < Joomla.MediaManager.Edit.history.lastKey) { + // eslint-disable-next-line max-len Joomla.MediaManager.Edit.history.current = Number(Joomla.MediaManager.Edit.history.current) + 1; Joomla.MediaManager.Edit.Reset(Joomla.MediaManager.Edit.history.current); } diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index ef29483c5c720..ee05da707c38b 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -152,7 +152,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'com_installer', 'component', 'com_installer', '', 1, 1, 1, 1, 1, '', '{"cachetimeout":"6","minimum_stability":"4"}'), (0, 'com_languages', 'component', 'com_languages', '', 1, 1, 1, 1, 1, '', '{"administrator":"en-GB","site":"en-GB"}'), (0, 'com_login', 'component', 'com_login', '', 1, 1, 1, 1, 1, '', ''), -(0, 'com_media', 'component', 'com_media', '', 1, 1, 0, 1, 1, '', '{"upload_extensions":"bmp,csv,doc,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,txt,xcf,xls,BMP,CSV,DOC,GIF,ICO,JPG,JPEG,ODG,ODP,ODS,ODT,PDF,PNG,PPT,TXT,XCF,XLS","upload_maxsize":"10","file_path":"images","image_path":"images","restrict_uploads":"1","allowed_media_usergroup":"3","check_mime":"1","image_extensions":"bmp,gif,jpg,png","ignore_extensions":"","upload_mime":"image\\/jpeg,image\\/gif,image\\/png,image\\/bmp,application\\/msword,application\\/excel,application\\/pdf,application\\/powerpoint,text\\/plain,application\\/x-zip","upload_mime_illegal":"text\\/html"}'), +(0, 'com_media', 'component', 'com_media', '', 1, 1, 0, 1, 1, '', '{"upload_extensions":"bmp,csv,doc,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,txt,xcf,xls,BMP,CSV,DOC,GIF,ICO,JPG,JPEG,ODG,ODP,ODS,ODT,PDF,PNG,PPT,TXT,XCF,XLS","upload_maxsize":"10","file_path":"images","image_path":"images","restrict_uploads":"1","allowed_media_usergroup":"3","check_mime":"1","image_extensions":"bmp,gif,jpg,png","ignore_extensions":"","upload_mime":"image\\/jpeg,image\\/gif,image\\/png,image\\/bmp,application\\/msword,application\\/excel,application\\/pdf,application\\/powerpoint,text\\/plain,application\\/x-zip","upload_mime_illegal":"text\\/html", "history_length":"25"}'), (0, 'com_menus', 'component', 'com_menus', '', 1, 1, 1, 1, 1, '', '{"page_title":"","show_page_heading":0,"page_heading":"","pageclass_sfx":""}'), (0, 'com_messages', 'component', 'com_messages', '', 1, 1, 1, 1, 1, '', ''), (0, 'com_modules', 'component', 'com_modules', '', 1, 1, 1, 1, 1, '', ''), diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql index c9d032931bb7c..ed384105a3a0c 100644 --- a/installation/sql/postgresql/base.sql +++ b/installation/sql/postgresql/base.sql @@ -158,7 +158,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'com_installer', 'component', 'com_installer', '', 1, 1, 1, 1, 1, '', '{"cachetimeout":"6","minimum_stability":"4"}', 0, 0), (0, 'com_languages', 'component', 'com_languages', '', 1, 1, 1, 1, 1, '', '{"administrator":"en-GB","site":"en-GB"}', 0, 0), (0, 'com_login', 'component', 'com_login', '', 1, 1, 1, 1, 1, '', '', 0, 0), -(0, 'com_media', 'component', 'com_media', '', 1, 1, 0, 1, 1, '', '{"upload_extensions":"bmp,csv,doc,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,txt,xcf,xls,BMP,CSV,DOC,GIF,ICO,JPG,JPEG,ODG,ODP,ODS,ODT,PDF,PNG,PPT,TXT,XCF,XLS","upload_maxsize":"10","file_path":"images","image_path":"images","restrict_uploads":"1","allowed_media_usergroup":"3","check_mime":"1","image_extensions":"bmp,gif,jpg,png","ignore_extensions":"","upload_mime":"image\\/jpeg,image\\/gif,image\\/png,image\\/bmp,application\\/msword,application\\/excel,application\\/pdf,application\\/powerpoint,text\\/plain,application\\/x-zip","upload_mime_illegal":"text\\/html"}', 0, 0), +(0, 'com_media', 'component', 'com_media', '', 1, 1, 0, 1, 1, '', '{"upload_extensions":"bmp,csv,doc,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,txt,xcf,xls,BMP,CSV,DOC,GIF,ICO,JPG,JPEG,ODG,ODP,ODS,ODT,PDF,PNG,PPT,TXT,XCF,XLS","upload_maxsize":"10","file_path":"images","image_path":"images","restrict_uploads":"1","allowed_media_usergroup":"3","check_mime":"1","image_extensions":"bmp,gif,jpg,png","ignore_extensions":"","upload_mime":"image\\/jpeg,image\\/gif,image\\/png,image\\/bmp,application\\/msword,application\\/excel,application\\/pdf,application\\/powerpoint,text\\/plain,application\\/x-zip","upload_mime_illegal":"text\\/html","history_length":"25"}', 0, 0), (0, 'com_menus', 'component', 'com_menus', '', 1, 1, 1, 1, 1, '', '{"page_title":"","show_page_heading":0,"page_heading":"","pageclass_sfx":""}', 0, 0), (0, 'com_messages', 'component', 'com_messages', '', 1, 1, 1, 1, 1, '', '', 0, 0), (0, 'com_modules', 'component', 'com_modules', '', 1, 1, 1, 1, 1, '', '', 0, 0), diff --git a/language/en-GB/com_media.ini b/language/en-GB/com_media.ini index 61a1fa3dd278e..c90365ad9be65 100644 --- a/language/en-GB/com_media.ini +++ b/language/en-GB/com_media.ini @@ -76,6 +76,8 @@ COM_MEDIA_FILESIZE="File size" COM_MEDIA_FOLDER="Folder" COM_MEDIA_FOLDER_NAME="Folder Name" COM_MEDIA_FOLDERS="Folders" +COM_MEDIA_HISTORY_LENGTH_DESC="Set the number of states stored in the history to a value between 1 and 100." +COM_MEDIA_HISTORY_LENGTH_LABEL="History States" COM_MEDIA_IMAGE_DESCRIPTION="Image Description" COM_MEDIA_IMAGE_URL="Image URL" COM_MEDIA_INCREASE_GRID="Increase grid size"