First pass formatting with Prettier
* Added .prettierrc.json * Added .prettierignore * Formatted
This commit is contained in:
@@ -2,36 +2,36 @@
|
||||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
const MenuModule = require('./menu_module.js').MenuModule;
|
||||
const ViewController = require('./view_controller.js').ViewController;
|
||||
const Errors = require('./enig_error.js').Errors;
|
||||
const FileEntry = require('./file_entry.js');
|
||||
const FileBaseFilters = require('./file_base_filter.js');
|
||||
const { getAvailableFileAreaTags } = require('./file_base_area.js');
|
||||
const MenuModule = require('./menu_module.js').MenuModule;
|
||||
const ViewController = require('./view_controller.js').ViewController;
|
||||
const Errors = require('./enig_error.js').Errors;
|
||||
const FileEntry = require('./file_entry.js');
|
||||
const FileBaseFilters = require('./file_base_filter.js');
|
||||
const { getAvailableFileAreaTags } = require('./file_base_area.js');
|
||||
const {
|
||||
getSortedAvailMessageConferences,
|
||||
getSortedAvailMessageAreasByConfTag,
|
||||
updateMessageAreaLastReadId,
|
||||
getMessageIdNewerThanTimestampByArea
|
||||
} = require('./message_area.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
getMessageIdNewerThanTimestampByArea,
|
||||
} = require('./message_area.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
|
||||
// deps
|
||||
const async = require('async');
|
||||
const moment = require('moment');
|
||||
const _ = require('lodash');
|
||||
const async = require('async');
|
||||
const moment = require('moment');
|
||||
const _ = require('lodash');
|
||||
|
||||
exports.moduleInfo = {
|
||||
name : 'Set New Scan Date',
|
||||
desc : 'Sets new scan date for applicable scans',
|
||||
author : 'NuSkooler',
|
||||
name: 'Set New Scan Date',
|
||||
desc: 'Sets new scan date for applicable scans',
|
||||
author: 'NuSkooler',
|
||||
};
|
||||
|
||||
const MciViewIds = {
|
||||
main : {
|
||||
scanDate : 1,
|
||||
targetSelection : 2,
|
||||
}
|
||||
main: {
|
||||
scanDate: 1,
|
||||
targetSelection: 2,
|
||||
},
|
||||
};
|
||||
|
||||
// :TODO: for messages, we could insert "conf - all areas" into targets, and allow such
|
||||
@@ -42,69 +42,87 @@ exports.getModule = class SetNewScanDate extends MenuModule {
|
||||
|
||||
const config = this.menuConfig.config;
|
||||
|
||||
this.target = config.target || 'message';
|
||||
this.target = config.target || 'message';
|
||||
this.scanDateFormat = config.scanDateFormat || 'YYYYMMDD';
|
||||
|
||||
this.menuMethods = {
|
||||
scanDateSubmit : (formData, extraArgs, cb) => {
|
||||
scanDateSubmit: (formData, extraArgs, cb) => {
|
||||
let scanDate = _.get(formData, 'value.scanDate');
|
||||
if(!scanDate) {
|
||||
if (!scanDate) {
|
||||
return cb(Errors.MissingParam('"scanDate" missing from form data'));
|
||||
}
|
||||
|
||||
scanDate = moment(scanDate, this.scanDateFormat);
|
||||
if(!scanDate.isValid()) {
|
||||
return cb(Errors.Invalid(`"${_.get(formData, 'value.scanDate')}" is not a valid date`));
|
||||
if (!scanDate.isValid()) {
|
||||
return cb(
|
||||
Errors.Invalid(
|
||||
`"${_.get(formData, 'value.scanDate')}" is not a valid date`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const targetSelection = _.get(formData, 'value.targetSelection'); // may be undefined if N/A
|
||||
const targetSelection = _.get(formData, 'value.targetSelection'); // may be undefined if N/A
|
||||
|
||||
this[`setNewScanDateFor${_.capitalize(this.target)}Base`](targetSelection, scanDate, () => {
|
||||
return this.prevMenu(cb);
|
||||
});
|
||||
this[`setNewScanDateFor${_.capitalize(this.target)}Base`](
|
||||
targetSelection,
|
||||
scanDate,
|
||||
() => {
|
||||
return this.prevMenu(cb);
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
setNewScanDateForMessageBase(targetSelection, scanDate, cb) {
|
||||
const target = this.targetSelections[targetSelection];
|
||||
if(!target) {
|
||||
return cb(Errors.UnexpectedState('Unable to get target in which to set new scan'));
|
||||
if (!target) {
|
||||
return cb(
|
||||
Errors.UnexpectedState('Unable to get target in which to set new scan')
|
||||
);
|
||||
}
|
||||
|
||||
// selected area, or all of 'em
|
||||
let updateAreaTags;
|
||||
if('' === target.area.areaTag) {
|
||||
if ('' === target.area.areaTag) {
|
||||
updateAreaTags = this.targetSelections
|
||||
.map( targetSelection => targetSelection.area.areaTag )
|
||||
.filter( areaTag => areaTag ); // remove the blank 'all' entry
|
||||
.map(targetSelection => targetSelection.area.areaTag)
|
||||
.filter(areaTag => areaTag); // remove the blank 'all' entry
|
||||
} else {
|
||||
updateAreaTags = [ target.area.areaTag ];
|
||||
updateAreaTags = [target.area.areaTag];
|
||||
}
|
||||
|
||||
async.each(updateAreaTags, (areaTag, nextAreaTag) => {
|
||||
getMessageIdNewerThanTimestampByArea(areaTag, scanDate, (err, messageId) => {
|
||||
if(err) {
|
||||
return nextAreaTag(err);
|
||||
}
|
||||
|
||||
if(!messageId) {
|
||||
return nextAreaTag(null); // nothing to do
|
||||
}
|
||||
|
||||
messageId = Math.max(messageId - 1, 0);
|
||||
|
||||
return updateMessageAreaLastReadId(
|
||||
this.client.user.userId,
|
||||
async.each(
|
||||
updateAreaTags,
|
||||
(areaTag, nextAreaTag) => {
|
||||
getMessageIdNewerThanTimestampByArea(
|
||||
areaTag,
|
||||
messageId,
|
||||
true, // allowOlder
|
||||
nextAreaTag
|
||||
scanDate,
|
||||
(err, messageId) => {
|
||||
if (err) {
|
||||
return nextAreaTag(err);
|
||||
}
|
||||
|
||||
if (!messageId) {
|
||||
return nextAreaTag(null); // nothing to do
|
||||
}
|
||||
|
||||
messageId = Math.max(messageId - 1, 0);
|
||||
|
||||
return updateMessageAreaLastReadId(
|
||||
this.client.user.userId,
|
||||
areaTag,
|
||||
messageId,
|
||||
true, // allowOlder
|
||||
nextAreaTag
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
}, err => {
|
||||
return cb(err);
|
||||
});
|
||||
},
|
||||
err => {
|
||||
return cb(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
setNewScanDateForFileBase(targetSelection, scanDate, cb) {
|
||||
@@ -114,19 +132,19 @@ exports.getModule = class SetNewScanDate extends MenuModule {
|
||||
// to the user.
|
||||
//
|
||||
const filterCriteria = {
|
||||
areaTag : getAvailableFileAreaTags(this.client),
|
||||
newerThanTimestamp : scanDate,
|
||||
limit : 1,
|
||||
orderBy : 'upload_timestamp',
|
||||
order : 'ascending',
|
||||
areaTag: getAvailableFileAreaTags(this.client),
|
||||
newerThanTimestamp: scanDate,
|
||||
limit: 1,
|
||||
orderBy: 'upload_timestamp',
|
||||
order: 'ascending',
|
||||
};
|
||||
|
||||
FileEntry.findFiles(filterCriteria, (err, fileIds) => {
|
||||
if(err) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
if(!fileIds || 0 === fileIds.length) {
|
||||
if (!fileIds || 0 === fileIds.length) {
|
||||
// nothing to do
|
||||
return cb(null);
|
||||
}
|
||||
@@ -136,7 +154,7 @@ exports.getModule = class SetNewScanDate extends MenuModule {
|
||||
return FileBaseFilters.setFileBaseLastViewedFileIdForUser(
|
||||
this.client.user,
|
||||
pointerFileId,
|
||||
true, // allowOlder
|
||||
true, // allowOlder
|
||||
cb
|
||||
);
|
||||
});
|
||||
@@ -149,48 +167,53 @@ exports.getModule = class SetNewScanDate extends MenuModule {
|
||||
//
|
||||
const selections = [];
|
||||
getSortedAvailMessageConferences(this.client).forEach(conf => {
|
||||
getSortedAvailMessageAreasByConfTag(conf.confTag, { client : this.client } ).forEach(area => {
|
||||
getSortedAvailMessageAreasByConfTag(conf.confTag, {
|
||||
client: this.client,
|
||||
}).forEach(area => {
|
||||
selections.push({
|
||||
conf : {
|
||||
confTag : conf.confTag,
|
||||
text : conf.conf.name, // standard
|
||||
name : conf.conf.name,
|
||||
desc : conf.conf.desc,
|
||||
conf: {
|
||||
confTag: conf.confTag,
|
||||
text: conf.conf.name, // standard
|
||||
name: conf.conf.name,
|
||||
desc: conf.conf.desc,
|
||||
},
|
||||
area: {
|
||||
areaTag: area.areaTag,
|
||||
text: area.area.name, // standard
|
||||
name: area.area.name,
|
||||
desc: area.area.desc,
|
||||
},
|
||||
area : {
|
||||
areaTag : area.areaTag,
|
||||
text : area.area.name, // standard
|
||||
name : area.area.name,
|
||||
desc : area.area.desc,
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
selections.unshift({
|
||||
conf : {
|
||||
confTag : '',
|
||||
text : 'All conferences',
|
||||
name : 'All conferences',
|
||||
desc : 'All conferences',
|
||||
conf: {
|
||||
confTag: '',
|
||||
text: 'All conferences',
|
||||
name: 'All conferences',
|
||||
desc: 'All conferences',
|
||||
},
|
||||
area: {
|
||||
areaTag: '',
|
||||
text: 'All areas',
|
||||
name: 'All areas',
|
||||
desc: 'All areas',
|
||||
},
|
||||
area : {
|
||||
areaTag : '',
|
||||
text : 'All areas',
|
||||
name : 'All areas',
|
||||
desc : 'All areas',
|
||||
}
|
||||
});
|
||||
|
||||
// Find current conf/area & move it directly under "All"
|
||||
const currConfTag = this.client.user.properties[UserProps.MessageConfTag];
|
||||
const currAreaTag = this.client.user.properties[UserProps.MessageAreaTag];
|
||||
if(currConfTag && currAreaTag) {
|
||||
const confAreaIndex = selections.findIndex( confArea => {
|
||||
return confArea.conf.confTag === currConfTag && confArea.area.areaTag === currAreaTag;
|
||||
const currConfTag = this.client.user.properties[UserProps.MessageConfTag];
|
||||
const currAreaTag = this.client.user.properties[UserProps.MessageAreaTag];
|
||||
if (currConfTag && currAreaTag) {
|
||||
const confAreaIndex = selections.findIndex(confArea => {
|
||||
return (
|
||||
confArea.conf.confTag === currConfTag &&
|
||||
confArea.area.areaTag === currAreaTag
|
||||
);
|
||||
});
|
||||
|
||||
if(confAreaIndex > -1) {
|
||||
if (confAreaIndex > -1) {
|
||||
selections.splice(1, 0, selections.splice(confAreaIndex, 1)[0]);
|
||||
}
|
||||
}
|
||||
@@ -202,31 +225,41 @@ exports.getModule = class SetNewScanDate extends MenuModule {
|
||||
|
||||
mciReady(mciData, cb) {
|
||||
super.mciReady(mciData, err => {
|
||||
if(err) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
const self = this;
|
||||
const vc = self.addViewController( 'main', new ViewController( { client : this.client } ) );
|
||||
const self = this;
|
||||
const vc = self.addViewController(
|
||||
'main',
|
||||
new ViewController({ client: this.client })
|
||||
);
|
||||
|
||||
async.series(
|
||||
[
|
||||
function validateConfig(callback) {
|
||||
if(![ 'message', 'file' ].includes(self.target)) {
|
||||
return callback(Errors.Invalid(`Invalid "target" in config: ${self.target}`));
|
||||
if (!['message', 'file'].includes(self.target)) {
|
||||
return callback(
|
||||
Errors.Invalid(
|
||||
`Invalid "target" in config: ${self.target}`
|
||||
)
|
||||
);
|
||||
}
|
||||
// :TOD0: validate scanDateFormat
|
||||
return callback(null);
|
||||
},
|
||||
function loadFromConfig(callback) {
|
||||
return vc.loadFromMenuConfig( { callingMenu : self, mciMap : mciData.menu }, callback);
|
||||
return vc.loadFromMenuConfig(
|
||||
{ callingMenu: self, mciMap: mciData.menu },
|
||||
callback
|
||||
);
|
||||
},
|
||||
function loadAvailSelections(callback) {
|
||||
switch(self.target) {
|
||||
case 'message' :
|
||||
switch (self.target) {
|
||||
case 'message':
|
||||
return self.loadAvailMessageBaseSelections(callback);
|
||||
|
||||
default :
|
||||
default:
|
||||
return callback(null);
|
||||
}
|
||||
},
|
||||
@@ -236,11 +269,16 @@ exports.getModule = class SetNewScanDate extends MenuModule {
|
||||
const scanDateView = vc.getView(MciViewIds.main.scanDate);
|
||||
|
||||
// :TODO: MaskTextEditView needs some love: If setText() with input that matches the mask, we should ignore the non-mask chars! Hack in place for now
|
||||
const scanDateFormat = self.scanDateFormat.replace(/[/\-. ]/g, '');
|
||||
const scanDateFormat = self.scanDateFormat.replace(
|
||||
/[/\-. ]/g,
|
||||
''
|
||||
);
|
||||
scanDateView.setText(today.format(scanDateFormat));
|
||||
|
||||
if('message' === self.target) {
|
||||
const targetSelectionView = vc.getView(MciViewIds.main.targetSelection);
|
||||
if ('message' === self.target) {
|
||||
const targetSelectionView = vc.getView(
|
||||
MciViewIds.main.targetSelection
|
||||
);
|
||||
|
||||
targetSelectionView.setItems(self.targetSelections);
|
||||
targetSelectionView.setFocusItemIndex(0);
|
||||
@@ -249,7 +287,7 @@ exports.getModule = class SetNewScanDate extends MenuModule {
|
||||
self.viewControllers.main.resetInitialFocus();
|
||||
//vc.switchFocus(MciViewIds.main.scanDate);
|
||||
return callback(null);
|
||||
}
|
||||
},
|
||||
],
|
||||
err => {
|
||||
return cb(err);
|
||||
|
||||
Reference in New Issue
Block a user