2017-01-31 07:50:28 +01:00
|
|
|
const Backbone = require('backbone');
|
|
|
|
const FileInfoModel = require('../models/file-info-model');
|
|
|
|
const SettingsStore = require('../comp/settings-store');
|
2015-12-06 21:32:41 +01:00
|
|
|
|
2017-01-31 07:50:28 +01:00
|
|
|
const FileInfoCollection = Backbone.Collection.extend({
|
2015-12-06 21:32:41 +01:00
|
|
|
model: FileInfoModel,
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
initialize() {},
|
2015-12-06 21:32:41 +01:00
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
load() {
|
2017-02-20 23:39:13 +01:00
|
|
|
return SettingsStore.load('file-info').then(data => {
|
|
|
|
if (data) {
|
2019-08-16 23:05:39 +02:00
|
|
|
this.reset(data, { silent: true });
|
2017-02-20 23:39:13 +01:00
|
|
|
}
|
2017-02-05 21:28:43 +01:00
|
|
|
});
|
2017-02-04 19:31:26 +01:00
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
save() {
|
2015-12-06 21:32:41 +01:00
|
|
|
SettingsStore.save('file-info', this.toJSON());
|
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
getLast() {
|
2015-12-07 22:20:18 +01:00
|
|
|
return this.first();
|
2015-12-07 20:07:56 +01:00
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
getMatch(storage, name, path) {
|
2016-07-17 13:30:38 +02:00
|
|
|
return this.find(fi => {
|
2019-08-16 23:05:39 +02:00
|
|
|
return (
|
|
|
|
(fi.get('storage') || '') === (storage || '') &&
|
2015-12-07 20:07:56 +01:00
|
|
|
(fi.get('name') || '') === (name || '') &&
|
2019-08-16 23:05:39 +02:00
|
|
|
(fi.get('path') || '') === (path || '')
|
|
|
|
);
|
2015-12-07 20:07:56 +01:00
|
|
|
});
|
2015-12-10 22:31:47 +01:00
|
|
|
},
|
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
getByName(name) {
|
2016-07-17 13:30:38 +02:00
|
|
|
return this.find(file => file.get('name').toLowerCase() === name.toLowerCase());
|
2015-12-06 21:32:41 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-02-05 20:28:17 +01:00
|
|
|
FileInfoCollection.instance = new FileInfoCollection();
|
2015-12-06 21:32:41 +01:00
|
|
|
|
|
|
|
module.exports = FileInfoCollection;
|