2017-02-08 03:20:10 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
2022-06-05 20:04:25 +00:00
|
|
|
const MenuModule = require('./menu_module.js').MenuModule;
|
|
|
|
const ViewController = require('./view_controller.js').ViewController;
|
|
|
|
const getSortedAvailableFileAreas =
|
|
|
|
require('./file_base_area.js').getSortedAvailableFileAreas;
|
|
|
|
const FileBaseFilters = require('./file_base_filter.js');
|
2017-02-08 03:20:10 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const async = require('async');
|
2017-02-08 03:20:10 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2022-06-05 20:04:25 +00:00
|
|
|
name: 'File Base Search',
|
|
|
|
desc: 'Module for quickly searching the file base',
|
|
|
|
author: 'NuSkooler',
|
2017-02-08 03:20:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const MciViewIds = {
|
2022-06-05 20:04:25 +00:00
|
|
|
search: {
|
|
|
|
searchTerms: 1,
|
|
|
|
search: 2,
|
|
|
|
tags: 3,
|
|
|
|
area: 4,
|
|
|
|
orderBy: 5,
|
|
|
|
sort: 6,
|
|
|
|
advSearch: 7,
|
|
|
|
},
|
2017-02-08 03:20:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.getModule = class FileBaseSearch extends MenuModule {
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
this.menuMethods = {
|
2022-06-05 20:04:25 +00:00
|
|
|
search: (formData, extraArgs, cb) => {
|
2018-06-22 05:15:04 +00:00
|
|
|
const isAdvanced = formData.submitId === MciViewIds.search.advSearch;
|
|
|
|
return this.searchNow(formData, isAdvanced, cb);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const self = this;
|
|
|
|
const vc = self.addViewController(
|
|
|
|
'search',
|
|
|
|
new ViewController({ client: this.client })
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function loadFromConfig(callback) {
|
2022-06-05 20:04:25 +00:00
|
|
|
return vc.loadFromMenuConfig(
|
|
|
|
{ callingMenu: self, mciMap: mciData.menu },
|
|
|
|
callback
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
function populateAreas(callback) {
|
2022-06-05 20:04:25 +00:00
|
|
|
self.availAreas = [{ name: '-ALL-' }].concat(
|
|
|
|
getSortedAvailableFileAreas(self.client) || []
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
const areasView = vc.getView(MciViewIds.search.area);
|
2022-06-05 20:04:25 +00:00
|
|
|
areasView.setItems(self.availAreas.map(a => a.name));
|
2018-06-22 05:15:04 +00:00
|
|
|
areasView.redraw();
|
|
|
|
vc.switchFocus(MciViewIds.search.searchTerms);
|
|
|
|
|
|
|
|
return callback(null);
|
2022-06-05 20:04:25 +00:00
|
|
|
},
|
2018-06-22 05:15:04 +00:00
|
|
|
],
|
|
|
|
err => {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getSelectedAreaTag(index) {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (0 === index) {
|
|
|
|
return ''; // -ALL-
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
const area = this.availAreas[index];
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!area) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return area.areaTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
getOrderBy(index) {
|
|
|
|
return FileBaseFilters.OrderByValues[index] || FileBaseFilters.OrderByValues[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
getSortBy(index) {
|
|
|
|
return FileBaseFilters.SortByValues[index] || FileBaseFilters.SortByValues[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
getFilterValuesFromFormData(formData, isAdvanced) {
|
2022-06-05 20:04:25 +00:00
|
|
|
const areaIndex = isAdvanced ? formData.value.areaIndex : 0;
|
|
|
|
const orderByIndex = isAdvanced ? formData.value.orderByIndex : 0;
|
|
|
|
const sortByIndex = isAdvanced ? formData.value.sortByIndex : 0;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
return {
|
2022-06-05 20:04:25 +00:00
|
|
|
areaTag: this.getSelectedAreaTag(areaIndex),
|
|
|
|
terms: formData.value.searchTerms,
|
|
|
|
tags: isAdvanced ? formData.value.tags : '',
|
|
|
|
order: this.getOrderBy(orderByIndex),
|
|
|
|
sort: this.getSortBy(sortByIndex),
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
searchNow(formData, isAdvanced, cb) {
|
|
|
|
const filterCriteria = this.getFilterValuesFromFormData(formData, isAdvanced);
|
|
|
|
|
|
|
|
const menuOpts = {
|
2022-06-05 20:04:25 +00:00
|
|
|
extraArgs: {
|
|
|
|
filterCriteria: filterCriteria,
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2023-08-24 02:11:26 +00:00
|
|
|
menuFlags: ['popParent'],
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
return this.gotoMenu(
|
|
|
|
this.menuConfig.config.fileBaseListEntriesMenu || 'fileBaseListEntries',
|
|
|
|
menuOpts,
|
|
|
|
cb
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2017-02-08 03:20:10 +00:00
|
|
|
};
|