keeweb/app/scripts/collections/file-info-collection.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-09-17 21:39:06 +02:00
import { Collection } from 'framework/collection';
2019-09-15 14:16:32 +02:00
import { SettingsStore } from 'comp/settings/settings-store';
import { FileInfoModel } from 'models/file-info-model';
2015-12-06 21:32:41 +01:00
2019-09-17 21:39:06 +02:00
class FileInfoCollection extends Collection {
static model = FileInfoModel;
2015-12-06 21:32:41 +01:00
2019-08-18 10:17:09 +02:00
load() {
2020-06-01 16:53:51 +02:00
return SettingsStore.load('file-info').then((data) => {
if (data) {
2019-09-17 21:39:06 +02:00
for (const item of data) {
this.push(new FileInfoModel(item));
}
}
});
2019-09-17 21:39:06 +02:00
}
2019-08-18 10:17:09 +02:00
save() {
2019-09-17 21:39:06 +02:00
SettingsStore.save('file-info', this);
}
2015-12-07 20:07:56 +01:00
2019-08-18 10:17:09 +02:00
getMatch(storage, name, path) {
2020-06-01 16:53:51 +02:00
return this.find((fi) => {
2019-08-16 23:05:39 +02:00
return (
2019-09-17 21:39:06 +02:00
(fi.storage || '') === (storage || '') &&
(fi.name || '') === (name || '') &&
(fi.path || '') === (path || '')
2019-08-16 23:05:39 +02:00
);
2015-12-07 20:07:56 +01:00
});
2019-09-17 21:39:06 +02:00
}
2015-12-10 22:31:47 +01:00
2019-08-18 10:17:09 +02:00
getByName(name) {
2020-06-01 16:53:51 +02:00
return this.find((file) => file.name.toLowerCase() === name.toLowerCase());
2015-12-06 21:32:41 +01:00
}
2019-09-17 21:39:06 +02:00
}
2015-12-06 21:32:41 +01:00
2019-09-17 21:39:06 +02:00
const instance = new FileInfoCollection();
2015-12-06 21:32:41 +01:00
2019-09-17 21:39:06 +02:00
export { instance as FileInfoCollection };