2015-12-06 21:32:41 +01:00
|
|
|
'use strict';
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
},
|
|
|
|
|
|
|
|
load: function () {
|
2017-01-31 07:50:28 +01:00
|
|
|
const data = SettingsStore.load('file-info');
|
2015-12-06 21:32:41 +01:00
|
|
|
if (data) {
|
|
|
|
this.reset(data, {silent: true});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
save: function () {
|
|
|
|
SettingsStore.save('file-info', this.toJSON());
|
|
|
|
},
|
|
|
|
|
|
|
|
getLast: function () {
|
2015-12-07 22:20:18 +01:00
|
|
|
return this.first();
|
2015-12-07 20:07:56 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
getMatch: function (storage, name, path) {
|
2016-07-17 13:30:38 +02:00
|
|
|
return this.find(fi => {
|
2015-12-07 20:07:56 +01:00
|
|
|
return (fi.get('storage') || '') === (storage || '') &&
|
|
|
|
(fi.get('name') || '') === (name || '') &&
|
|
|
|
(fi.get('path') || '') === (path || '');
|
|
|
|
});
|
2015-12-10 22:31:47 +01:00
|
|
|
},
|
|
|
|
|
2015-12-13 15:59:41 +01:00
|
|
|
getByName: function(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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
FileInfoCollection.load = function() {
|
2017-01-31 07:50:28 +01:00
|
|
|
const coll = new FileInfoCollection();
|
2015-12-06 21:32:41 +01:00
|
|
|
coll.load();
|
|
|
|
return coll;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = FileInfoCollection;
|