keeweb/app/scripts/models/update-model.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-09-17 21:56:58 +02:00
import { Model } from 'framework/model';
2019-09-15 14:16:32 +02:00
import { SettingsStore } from 'comp/settings/settings-store';
2015-10-29 22:20:01 +01:00
2019-09-17 21:56:58 +02:00
class UpdateModel extends Model {
2019-08-18 10:17:09 +02:00
load() {
return SettingsStore.load('update-info').then(data => {
if (data) {
try {
_.each(data, (val, key) => {
if (/Date$/.test(key)) {
data[key] = val ? new Date(val) : null;
}
});
2019-08-16 23:05:39 +02:00
this.set(data, { silent: true });
} catch (e) {
/* failed to load model */
}
}
});
2019-09-17 21:56:58 +02:00
}
2019-08-18 10:17:09 +02:00
save() {
2019-09-17 21:56:58 +02:00
const attr = _.clone(this);
2016-07-17 13:30:38 +02:00
Object.keys(attr).forEach(key => {
2015-11-14 16:28:36 +01:00
if (key.lastIndexOf('update', 0) === 0) {
delete attr[key];
}
});
2015-12-05 14:57:43 +01:00
SettingsStore.save('update-info', attr);
2015-10-29 22:20:01 +01:00
}
2019-09-17 21:56:58 +02:00
}
UpdateModel.defineModelProperties({
lastSuccessCheckDate: null,
lastCheckDate: null,
lastVersion: null,
lastVersionReleaseDate: null,
lastCheckError: null,
lastCheckUpdMin: null,
status: null,
updateStatus: null,
updateError: null,
updateManual: false
2015-10-29 22:20:01 +01:00
});
2019-09-17 21:56:58 +02:00
const instance = new UpdateModel();
2015-10-29 22:20:01 +01:00
2019-09-17 21:56:58 +02:00
export { instance as UpdateModel };