Skip to content

Commit

Permalink
New: Label to display only the contents of a master folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm committed Dec 12, 2023
1 parent a727249 commit ff35144
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

##### 🚀 New Features

- Option to set maximum size of temporary files, preserving them when closing the app
- Option to set maximum size of temporary files, preserving them when closing the app [`a727249`](https://github.com/ollm/OpenComic/commit/a7272499407191064f9d6bd7c42ecf3bb1231a83)
- Label to display only the contents of a master folder

##### 🐛 Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<div align="center">

[Screenshots](https://github.com/ollm/OpenComic/blob/master/SCREENSHOTS.MD) | [Features](#features) | [Changelog](https://github.com/ollm/OpenComic/blob/master/CHANGELOG.md) | [Download](#download-beta-v100-beta5)
[Screenshots](https://github.com/ollm/OpenComic/blob/master/SCREENSHOTS.MD) | [Features](#features) | [Changelog](https://github.com/ollm/OpenComic/blob/master/CHANGELOG.md) | [Download](#download-v100)

</div>

Expand Down
58 changes: 49 additions & 9 deletions scripts/dom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const domPoster = require(p.join(appDir, 'scripts/dom/poster.js')),
domManager = require(p.join(appDir, 'scripts/dom/dom.js')),
labels = require(p.join(appDir, 'scripts/dom/labels.js')),
search = require(p.join(appDir, 'scripts/dom/search.js'));

/*Page - Index*/
Expand Down Expand Up @@ -338,6 +339,13 @@ async function reloadIndex()
if(indexPathA) indexPathControlA.pop();
}

var indexLabel = {};

function setIndexLabel(config)
{
indexLabel = config;
}

var currentPath = false, currentPathScrollTop = [], fromDeepLoadNow = 0;

async function loadIndexPage(animation = true, path = false, content = false, keepScroll = false, mainPath = false, fromGoBack = false, notAutomaticBrowsing = false, fromDeepLoad = false)
Expand All @@ -359,6 +367,9 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
if(currentPathScrollTop[path === false ? 0 : path])
keepScroll = currentPathScrollTop[path === false ? 0 : path];

let _indexLabel = indexLabel;
indexLabel = {};

currentPath = path;

if(!path)
Expand Down Expand Up @@ -410,7 +421,7 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
{
for(let key in masterFolders)
{
if(fs.existsSync(masterFolders[key]))
if(fs.existsSync(masterFolders[key]) && (!_indexLabel.masterFolder || _indexLabel.masterFolder == masterFolders[key]))
{
let file = fileManager.file(masterFolders[key]);
let files = await file.readDir();
Expand Down Expand Up @@ -441,7 +452,7 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
// Get comics in library
let comicsStorage = storage.get('comics');

if(!isEmpty(comicsStorage))
if(!isEmpty(comicsStorage) && !_indexLabel.masterFolder)
{
for(let key in comicsStorage)
{
Expand Down Expand Up @@ -494,7 +505,7 @@ async function loadIndexPage(animation = true, path = false, content = false, ke

if(!content)
{
if(template.contentLeft('.menu-list').length === 0) template.loadContentLeft('index.content.left.html', animation);
if(template.contentLeft('.menu-list').length === 0) dom.loadIndexContentLeft(animation);
template.loadGlobalElement('index.elements.menus.html', 'menus');
floatingActionButton(true, 'dom.addComicButtons();');
}
Expand Down Expand Up @@ -532,7 +543,7 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
{
if(readingActive)
{
template.loadContentLeft('index.content.left.html', animation);
dom.loadIndexContentLeft(animation);
}

template.loadGlobalElement('index.elements.menus.html', 'menus');
Expand Down Expand Up @@ -627,15 +638,40 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
if(readingActive)
readingActive = false;

if(!isFromRecentlyOpened)
selectMenuItem('library');
else
selectMenuItem('recently-opened');
if(isEmpty(_indexLabel))
{
if(!isFromRecentlyOpened)
selectMenuItem('library');
else
selectMenuItem('recently-opened');
}

shortcuts.register('browse');
gamepad.updateBrowsableItems(path ? sha1(path) : 'library');
}

function loadIndexContentLeft(animation, isFromSettings = false)
{
let masterFolders = storage.get('masterFolders');

let _masterFolders = [];

for(let i = 0, len = masterFolders.length; i < len; i++)
{
_masterFolders.push({
name: p.basename(masterFolders[i]),
path: masterFolders[i],
});
}

handlebarsContext.masterFolders = _masterFolders;
handlebarsContext.isFromSettings = isFromSettings;

template.loadContentLeft('index.content.left.html', animation);

handlebarsContext.isFromSettings = false;
}

function compressedError(error)
{
//console.log(error);
Expand Down Expand Up @@ -1064,7 +1100,7 @@ function changeLanguage(lan)
template.contentRight('.language-list.active').removeClass('active');
template.contentRight('.language-list-'+lan).addClass('active');

template.loadContentLeft('index.content.left.html', false);
dom.loadIndexContentLeft(false);
template.loadHeader('languages.header.html', false);
storage.updateVar('config', 'language', lan);

Expand Down Expand Up @@ -1661,12 +1697,15 @@ gamepad.setButtonEvent('reading', 1, function(key, button) {

module.exports = {
loadIndexPage: loadIndexPage,
loadIndexContentLeft: loadIndexContentLeft,
setIndexLabel: setIndexLabel,
reloadIndex: reloadIndex,
loadRecentlyOpened: loadRecentlyOpened,
loadLanguagesPage: loadLanguagesPage,
loadSettingsPage: loadSettingsPage,
loadThemePage: loadThemePage,
changeLanguage: changeLanguage,
selectMenuItem: selectMenuItem,
floatingActionButton: floatingActionButton,
setCurrentPageVars: setCurrentPageVars,
changeView: changeView,
Expand Down Expand Up @@ -1699,6 +1738,7 @@ module.exports = {
metadataPathName: metadataPathName,
fromLibrary: fromLibrary,
search: search,
labels: labels,
this: domManager.this,
query: domManager.query,
queryAll: domManager.queryAll,
Expand Down
11 changes: 11 additions & 0 deletions scripts/dom/labels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

function masterFolder(folder, index)
{
dom.selectMenuItem('master-folder-'+index);
dom.setIndexLabel({masterFolder: folder});
dom.loadIndexPage(true);
}

module.exports = {
masterFolder: masterFolder,
};
16 changes: 15 additions & 1 deletion scripts/opencomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ async function startApp()

template.loadContentRight('index.content.right.empty.html', false);
template.loadHeader('index.header.html', false);
template.loadContentLeft('index.content.left.html', false);
template.loadGlobalElement('index.elements.menus.html', 'menus');
dom.loadIndexContentLeft(false);

if(!toOpenFile)
{
Expand Down Expand Up @@ -940,6 +940,20 @@ hb.registerHelper('compare', function(lvalue, operator, rvalue, options) {

});

hb.registerHelper('ifOr', function() {

let options = arguments[arguments.length - 1];

for(let i = 0, len = arguments.length - 1; i < len; i++)
{
if(!playmax.empty(arguments[i]))
return options.fn(this);
}

return options.inverse(this);

});

hb.registerHelper('for', function(from, to, incr, options) {

var accum = '';
Expand Down
2 changes: 1 addition & 1 deletion scripts/recently-opened.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async function load(animation = true, content = false)

if(!content)
{
if(template.contentLeft('.menu-list').length === 0) template.loadContentLeft('index.content.left.html', animation);
if(template.contentLeft('.menu-list').length === 0) dom.loadIndexContentLeft(animation);
template.loadGlobalElement('index.elements.menus.html', 'menus');
dom.floatingActionButton(false);
}
Expand Down
2 changes: 2 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function removeMasterFolder(key)
storage.set('masterFolders', masterFolders);

updateMasterFolders();
dom.loadIndexContentLeft(true, true);
}
}

Expand All @@ -224,6 +225,7 @@ function addMasterFolder()
storage.set('masterFolders', masterFolders);

updateMasterFolders();
dom.loadIndexContentLeft(true, true);
}
}

Expand Down
17 changes: 15 additions & 2 deletions templates/index.content.left.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<div class="menu-list">
<div class="menu-item menu-item-library body-medium gamepad-item{{#unless isFromRecentlyOpened}} active{{/unless}}" onclick="dom.loadIndexPage(true);">
<div class="menu-item menu-item-library body-medium gamepad-item{{#unless isFromRecentlyOpened}}{{#unless isFromSettings}} active{{/unless}}{{/unless}}" onclick="dom.loadIndexPage(true);">
<div class="icon-24 material-icon">book</div>
{{language.global.library}}
</div>
Expand All @@ -10,6 +10,19 @@
{{language.global.recents}}
</div>

{{#if masterFolders}}

<div class="separator-2" style="width: calc(100% + 12px);"></div>

{{#each masterFolders}}
<div class="menu-item menu-item-master-folder-{{@key}} body-medium gamepad-item" onclick="dom.labels.masterFolder('{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', {{@key}});">
<div class="icon-24 material-icon">folder</div>
{{name}}
</div>
{{/each}}

{{/if}}

<div class="separator-2" style="width: calc(100% + 12px);"></div>

<div class="menu-item menu-item-language body-medium gamepad-item" onclick="dom.loadLanguagesPage();">
Expand All @@ -22,7 +35,7 @@
{{language.global.theme}}
</div>

<div class="menu-item menu-item-settings body-medium gamepad-item" onclick="dom.loadSettingsPage();">
<div class="menu-item menu-item-settings body-medium gamepad-item{{#if isFromSettings}} active{{/if}}" onclick="dom.loadSettingsPage();">
<div class="icon-24 material-icon">settings</div>
{{language.global.settings}}
</div>
Expand Down

0 comments on commit ff35144

Please sign in to comment.