1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Electron: Resolves #755: Added note properties dialog box to view and edit created time, updated time, source URL and geolocation

This commit is contained in:
Laurent Cozic
2018-09-16 19:37:31 +01:00
parent 1b784fe3b0
commit 4e8372174b
11 changed files with 465 additions and 23 deletions

View File

@@ -287,7 +287,7 @@ class BaseModel {
}
// Remove fields that are not in the `fields` list, if provided.
// Note that things like update_time, user_update_time will still
// Note that things like update_time, user_updated_time will still
// be part of the final list of fields if autoTimestamp is on.
// id also will stay.
if (!options.isNew && options.fields) {
@@ -314,6 +314,10 @@ class BaseModel {
// The purpose of user_updated_time is to allow the user to manually set the time of a note (in which case
// options.autoTimestamp will be `false`). However note that if the item is later changed, this timestamp
// will be set again to the current time.
//
// The technique to modify user_updated_time while keeping updated_time current (so that sync can happen) is to
// manually set updated_time when saving and to set autoTimestamp to false, for example:
// Note.save({ id: "...", updated_time: Date.now(), user_updated_time: 1436342618000 }, { autoTimestamp: false })
if (options.autoTimestamp && this.hasField('user_updated_time')) {
o.user_updated_time = timeNow;
}

View File

@@ -100,7 +100,12 @@ class Note extends BaseItem {
static geolocationUrl(note) {
if (!('latitude' in note) || !('longitude' in note)) throw new Error('Latitude or longitude is missing');
if (!Number(note.latitude) && !Number(note.longitude)) throw new Error(_('This note does not have geolocation information.'));
return sprintf('https://www.openstreetmap.org/?lat=%s&lon=%s&zoom=20', note.latitude, note.longitude)
return this.geoLocationUrlFromLatLong(note.latitude, note.longitude);
//return sprintf('https://www.openstreetmap.org/?lat=%s&lon=%s&zoom=20', note.latitude, note.longitude);
}
static geoLocationUrlFromLatLong(lat, long) {
return sprintf('https://www.openstreetmap.org/?lat=%s&lon=%s&zoom=20', lat, long)
}
static modelType() {
@@ -465,17 +470,6 @@ class Note extends BaseItem {
return note;
}
// Not used?
// static async delete(id, options = null) {
// let r = await super.delete(id, options);
// this.dispatch({
// type: 'NOTE_DELETE',
// id: id,
// });
// }
static async batchDelete(ids, options = null) {
const result = await super.batchDelete(ids, options);
for (let i = 0; i < ids.length; i++) {

View File

@@ -60,6 +60,23 @@ class Time {
return moment(ms).format(format);
}
formatLocalToMs(localDateTime, format = null) {
if (format === null) format = this.dateTimeFormat();
const m = moment(localDateTime, format);
if (m.isValid()) return m.toDate().getTime();
throw new Error('Invalid input for formatLocalToMs: ' + localDateTime);
}
// Mostly used as a utility function for the DateTime Electron component
anythingToDateTime(o, defaultValue = null) {
if (o && o.toDate) return o.toDate();
if (!o) return defaultValue;
let m = moment(o, time.dateTimeFormat());
if (m.isValid()) return m.toDate();
m = moment(o, time.dateFormat());
return m.isValid() ? m.toDate() : defaultValue;
}
msleep(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => {