2017-12-14 20:12:14 +02:00
|
|
|
const Folder = require('lib/models/Folder.js');
|
2019-03-02 19:35:57 +02:00
|
|
|
const Setting = require('lib/models/Setting.js');
|
2017-07-15 17:54:19 +02:00
|
|
|
|
|
|
|
class FoldersScreenUtils {
|
2019-04-20 20:29:23 +02:00
|
|
|
static async allForDisplay(options = {}) {
|
2019-03-02 19:35:57 +02:00
|
|
|
const orderDir = Setting.value('folders.sortOrder.reverse') ? 'DESC' : 'ASC';
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
const folderOptions = Object.assign(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
caseInsensitive: true,
|
|
|
|
order: [
|
|
|
|
{
|
|
|
|
by: 'title',
|
|
|
|
dir: orderDir,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
options
|
|
|
|
);
|
2019-04-20 20:29:23 +02:00
|
|
|
|
|
|
|
let folders = await Folder.all(folderOptions);
|
2017-10-08 00:17:10 +02:00
|
|
|
|
2019-03-02 19:35:57 +02:00
|
|
|
if (Setting.value('folders.sortOrder.field') === 'last_note_user_updated_time') {
|
|
|
|
folders = await Folder.orderByLastModified(folders, orderDir);
|
|
|
|
}
|
|
|
|
|
2019-04-20 20:29:23 +02:00
|
|
|
return folders;
|
|
|
|
}
|
|
|
|
|
|
|
|
static async refreshFolders() {
|
|
|
|
const folders = await this.allForDisplay({ includeConflictFolder: true });
|
|
|
|
|
2017-07-15 17:54:19 +02:00
|
|
|
this.dispatch({
|
2017-11-08 23:22:24 +02:00
|
|
|
type: 'FOLDER_UPDATE_ALL',
|
2019-03-02 19:35:57 +02:00
|
|
|
items: folders,
|
2017-07-15 17:54:19 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:35:57 +02:00
|
|
|
static scheduleRefreshFolders() {
|
|
|
|
if (this.scheduleRefreshFoldersIID_) clearTimeout(this.scheduleRefreshFoldersIID_);
|
|
|
|
|
|
|
|
this.scheduleRefreshFoldersIID_ = setTimeout(() => {
|
|
|
|
this.scheduleRefreshFoldersIID_ = null;
|
|
|
|
this.refreshFolders();
|
|
|
|
}, 1000);
|
|
|
|
}
|
2017-07-15 17:54:19 +02:00
|
|
|
}
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = { FoldersScreenUtils };
|