2020-04-15 16:50:01 +02:00
|
|
|
import { Model } from 'framework/model';
|
|
|
|
import { ExternalEntryCollection } from 'collections/external-entry-collection';
|
|
|
|
|
|
|
|
class ExternalDeviceModel extends Model {
|
|
|
|
entries = new ExternalEntryCollection();
|
|
|
|
groups = [];
|
2020-05-11 17:24:06 +02:00
|
|
|
entryMap = {};
|
2020-04-15 16:50:01 +02:00
|
|
|
|
|
|
|
close() {}
|
|
|
|
|
|
|
|
forEachEntry(filter, callback) {
|
2020-05-05 18:11:58 +02:00
|
|
|
if (filter.trash || filter.group) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-05 15:08:19 +02:00
|
|
|
for (const entry of this.entries) {
|
|
|
|
if (entry.matches(filter)) {
|
|
|
|
callback(entry);
|
|
|
|
}
|
2020-04-15 16:50:01 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-11 17:24:06 +02:00
|
|
|
|
|
|
|
entryId(title, user) {
|
|
|
|
return `${title}:${user}`.toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
getMatchingEntry(entry) {
|
|
|
|
return this.entryMap[this.entryId(entry.title, entry.user)];
|
|
|
|
}
|
|
|
|
|
|
|
|
_buildEntryMap() {
|
|
|
|
for (const entry of this.entries) {
|
|
|
|
this.entryMap[entry.id.toLowerCase()] = entry;
|
|
|
|
}
|
|
|
|
}
|
2020-04-15 16:50:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ExternalDeviceModel.defineModelProperties({
|
|
|
|
id: '',
|
2020-05-05 20:47:15 +02:00
|
|
|
external: true,
|
2020-05-09 23:55:57 +02:00
|
|
|
readOnly: true,
|
2020-04-15 16:50:01 +02:00
|
|
|
active: false,
|
|
|
|
entries: undefined,
|
|
|
|
groups: undefined,
|
|
|
|
name: undefined,
|
2020-05-05 20:50:11 +02:00
|
|
|
shortName: undefined,
|
2020-05-11 17:24:06 +02:00
|
|
|
deviceClassName: undefined,
|
|
|
|
entryMap: undefined
|
2020-04-15 16:50:01 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
export { ExternalDeviceModel };
|