mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-08-07 10:15:07 +02:00
* Some WIP on file area releated stuff - various partially implemented pieces coming together
* Some changes to database.js: Triggers for FTS were not being created properly * Misc fixes & improvements
This commit is contained in:
parent
7da0abdc39
commit
5a0b291a02
14 changed files with 675 additions and 21 deletions
222
mods/file_area_list.js
Normal file
222
mods/file_area_list.js
Normal file
|
@ -0,0 +1,222 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
const MenuModule = require('../core/menu_module.js').MenuModule;
|
||||
const ViewController = require('../core/view_controller.js').ViewController;
|
||||
const ansi = require('../core/ansi_term.js');
|
||||
const theme = require('../core/theme.js');
|
||||
const FileEntry = require('../core/file_entry.js');
|
||||
const stringFormat = require('../core/string_format.js');
|
||||
const FileArea = require('../core/file_area.js');
|
||||
|
||||
// deps
|
||||
const async = require('async');
|
||||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
|
||||
/*
|
||||
Misc TODO
|
||||
* Allow rating to be user defined colors & characters/etc.
|
||||
*
|
||||
|
||||
|
||||
Well known file entry meta values:
|
||||
* upload_by_username
|
||||
* upload_by_user_id
|
||||
* file_md5
|
||||
* file_sha256
|
||||
* file_crc32
|
||||
* est_release_year
|
||||
* dl_count
|
||||
* byte_size
|
||||
* user_rating
|
||||
*
|
||||
*/
|
||||
|
||||
exports.moduleInfo = {
|
||||
name : 'File Area List',
|
||||
desc : 'Lists contents of file an file area',
|
||||
author : 'NuSkooler',
|
||||
};
|
||||
|
||||
const FormIds = {
|
||||
browse : 0,
|
||||
details : 1,
|
||||
};
|
||||
|
||||
const MciViewIds = {
|
||||
browse : {
|
||||
desc : 1,
|
||||
navMenu : 2,
|
||||
// 10+: customs
|
||||
},
|
||||
};
|
||||
|
||||
exports.getModule = class FileAreaList extends MenuModule {
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
||||
const config = this.menuConfig.config;
|
||||
|
||||
if(options.extraArgs) {
|
||||
this.filterCriteria = options.extraArgs.filterCriteria;
|
||||
}
|
||||
|
||||
this.filterCriteria = this.filterCriteria || {
|
||||
// :TODO: set area tag - all in current area by default
|
||||
};
|
||||
}
|
||||
|
||||
enter() {
|
||||
super.enter();
|
||||
}
|
||||
|
||||
leave() {
|
||||
super.leave();
|
||||
}
|
||||
|
||||
initSequence() {
|
||||
const self = this;
|
||||
|
||||
async.series(
|
||||
[
|
||||
function beforeArt(callback) {
|
||||
return self.beforeArt(callback);
|
||||
},
|
||||
function display(callback) {
|
||||
return self.displayBrowsePage(false, callback);
|
||||
}
|
||||
],
|
||||
() => {
|
||||
self.finishedLoading();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
displayBrowsePage(clearScreen, cb) {
|
||||
const self = this;
|
||||
const config = this.menuConfig.config;
|
||||
|
||||
async.waterfall(
|
||||
[
|
||||
function clearAndDisplayArt(callback) {
|
||||
if (clearScreen) {
|
||||
self.client.term.rawWrite(ansi.resetScreen());
|
||||
}
|
||||
|
||||
theme.displayThemedAsset(
|
||||
//config.art.browse,
|
||||
'FBRWSE',
|
||||
self.client,
|
||||
{ font : self.menuConfig.font, trailingLF : false },
|
||||
(err, artData) => {
|
||||
return callback(err, artData);
|
||||
}
|
||||
);
|
||||
},
|
||||
function prepeareViewController(artData, callback) {
|
||||
if(_.isUndefined(self.viewControllers.browse)) {
|
||||
const vc = self.addViewController(
|
||||
'browse',
|
||||
new ViewController( { client : self.client, formId : FormIds.browse } )
|
||||
);
|
||||
|
||||
const loadOpts = {
|
||||
callingMenu : self,
|
||||
mciMap : artData.mciMap,
|
||||
formId : FormIds.browse,
|
||||
};
|
||||
|
||||
return vc.loadFromMenuConfig(loadOpts, callback);
|
||||
}
|
||||
|
||||
self.viewControllers.view.setFocus(true);
|
||||
self.viewControllers.view.getView(MciViewIds.view.BBSList).redraw();
|
||||
|
||||
return callback(null);
|
||||
},
|
||||
function fetchEntryData(callback) {
|
||||
return self.loadFileIds(callback);
|
||||
},
|
||||
function loadCurrentFileInfo(callback) {
|
||||
self.currentFileEntry = new FileEntry();
|
||||
|
||||
self.currentFileEntry.load( self.fileList[ self.fileListPosition ], err => {
|
||||
return callback(err);
|
||||
});
|
||||
},
|
||||
function populateViews(callback) {
|
||||
if(_.isString(self.currentFileEntry.desc)) {
|
||||
const descView = self.viewControllers.browse.getView(MciViewIds.browse.desc);
|
||||
if(descView) {
|
||||
descView.setText(self.currentFileEntry.desc);
|
||||
//descView.redraw();
|
||||
}
|
||||
}
|
||||
|
||||
const currEntry = self.currentFileEntry;
|
||||
const uploadTimestampFormat = config.browseUploadTimestampFormat || config.uploadTimestampFormat || 'YYYY-MMM-DD';
|
||||
const area = FileArea.getFileAreaByTag(currEntry.areaTag);
|
||||
const hashTagsSep = config.hashTagsSep || ', ';
|
||||
const entryInfo = {
|
||||
fileId : currEntry.fileId,
|
||||
areaTag : currEntry.areaTag,
|
||||
areaName : area.name || 'N/A',
|
||||
areaDesc : area.desc || 'N/A',
|
||||
fileSha1 : currEntry.fileSha1,
|
||||
fileName : currEntry.fileName,
|
||||
desc : currEntry.desc,
|
||||
descLong : currEntry.descLong,
|
||||
uploadByUsername : currEntry.uploadByUsername,
|
||||
uploadTimestamp : moment(currEntry.uploadTimestamp).format(uploadTimestampFormat),
|
||||
hashTags : Array.from(currEntry.hashTags).join(hashTagsSep),
|
||||
};
|
||||
|
||||
const META_NUMBERS = [ 'byte_size', 'dl_count' ];
|
||||
_.forEach(self.currentFileEntry.meta, (value, name) => {
|
||||
if(META_NUMBERS.indexOf(name) > -1) {
|
||||
value = parseInt(value);
|
||||
}
|
||||
entryInfo[_.camelCase(name)] = value;
|
||||
});
|
||||
|
||||
|
||||
|
||||
// entryInfo.fileSize = 1241234; // :TODO: REMOVE ME!
|
||||
|
||||
// 10+ are custom textviews
|
||||
let textView;
|
||||
let customMciId = 10;
|
||||
|
||||
while( (textView = self.viewControllers.browse.getView(customMciId)) ) {
|
||||
const key = `browseInfoFormat${customMciId}`;
|
||||
const format = config[key];
|
||||
|
||||
if(format) {
|
||||
textView.setText(stringFormat(format, entryInfo));
|
||||
}
|
||||
|
||||
++customMciId;
|
||||
}
|
||||
}
|
||||
],
|
||||
err => {
|
||||
if(cb) {
|
||||
return cb(err);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
loadFileIds(cb) {
|
||||
this.fileListPosition = 0;
|
||||
|
||||
FileEntry.findFiles(this.filterCriteria, (err, fileIds) => {
|
||||
this.fileList = fileIds;
|
||||
return cb(err);
|
||||
});
|
||||
}
|
||||
|
||||
};
|
|
@ -127,7 +127,7 @@ MessageListModule.prototype.enter = function() {
|
|||
if(this.messageAreaTag) {
|
||||
this.tempMessageConfAndAreaSwitch(this.messageAreaTag);
|
||||
} else {
|
||||
this.messageAreaTag = this.messageAreaTag = this.client.user.properties.message_area_tag;
|
||||
this.messageAreaTag = this.client.user.properties.message_area_tag;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue