Skip to content

Commit

Permalink
added history length option
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaucht committed Aug 31, 2020
1 parent 0ec77e7 commit 9281378
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 12 deletions.
12 changes: 12 additions & 0 deletions administrator/components/com_media/config.xml
Expand Up @@ -109,6 +109,17 @@
default="text/html"
showon="restrict_uploads:1"
/>

<field
name="history_length"
type="number"
label="COM_MEDIA_HISTORY_LENGTH_LABEL"
description="COM_MEDIA_HISTORY_LENGTH_DESC"
validate="number"
min="1"
max="100"
default="25"
/>
</fieldset>

<fieldset
Expand All @@ -127,4 +138,5 @@
section="component"
/>
</fieldset>

</config>
1 change: 1 addition & 0 deletions administrator/components/com_media/tmpl/file/default.php
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions administrator/components/com_media/tmpl/media/default.php
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/com_media.ini
Expand Up @@ -55,6 +55,8 @@ COM_MEDIA_FOLDER="Folder"
COM_MEDIA_FOLDER_NAME="Folder Name"
COM_MEDIA_FOLDERS="Media Folders"
COM_MEDIA_FOLDERS_PATH_LABEL="<strong>Warning! Path Folder</strong><br>Changing the 'Path to files folder' from the default of 'images' may break your links.<br>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"
Expand Down
29 changes: 19 additions & 10 deletions build/media_source/com_media/js/edit-images.es6.js
Expand Up @@ -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] = {};
Expand All @@ -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];
}
}
};

Expand Down Expand Up @@ -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');
}
};
Expand Down Expand Up @@ -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();

Expand All @@ -133,15 +138,19 @@ 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);
}
};

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);
}
Expand Down
2 changes: 1 addition & 1 deletion installation/sql/mysql/base.sql
Expand Up @@ -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, '', ''),
Expand Down
2 changes: 1 addition & 1 deletion installation/sql/postgresql/base.sql
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions language/en-GB/com_media.ini
Expand Up @@ -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"
Expand Down

0 comments on commit 9281378

Please sign in to comment.