mirror of https://github.com/TriliumNext/Notes
Link entity migrated to Attribute, WIP
parent
fd9b79e115
commit
3cb421143f
@ -0,0 +1,10 @@
|
||||
UPDATE links SET type = 'internal-link' WHERE type = 'hyper';
|
||||
UPDATE links SET type = 'image-link' WHERE type = 'image';
|
||||
UPDATE links SET type = 'relation-map-link' WHERE type = 'relation-map';
|
||||
|
||||
INSERT INTO attributes (attributeId, noteId, type, name, value, position, utcDateCreated, utcDateModified, isDeleted, hash, isInheritable)
|
||||
SELECT linkId, noteId, 'relation', type, targetNoteId, 0, utcDateCreated, utcDateModified, isDeleted, hash, 0 FROM links;
|
||||
|
||||
UPDATE sync SET entityName = 'attributes' WHERE entityName = 'links';
|
||||
|
||||
DROP TABLE links;
|
||||
@ -1,51 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const Entity = require('./entity');
|
||||
const repository = require('../services/repository');
|
||||
const dateUtils = require('../services/date_utils');
|
||||
|
||||
/**
|
||||
* This class represents link from one note to another in the form of hyperlink or image reference. Note that
|
||||
* this is different concept than attribute/relation.
|
||||
*
|
||||
* @param {string} linkId
|
||||
* @param {string} noteId
|
||||
* @param {string} targetNoteId
|
||||
* @param {string} type
|
||||
* @param {boolean} isDeleted
|
||||
* @param {string} utcDateModified
|
||||
* @param {string} utcDateCreated
|
||||
*
|
||||
* @extends Entity
|
||||
*/
|
||||
class Link extends Entity {
|
||||
static get entityName() { return "links"; }
|
||||
static get primaryKeyName() { return "linkId"; }
|
||||
static get hashedProperties() { return ["linkId", "noteId", "targetNoteId", "type", "isDeleted", "utcDateCreated", "utcDateModified"]; }
|
||||
|
||||
async getNote() {
|
||||
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
||||
async getTargetNote() {
|
||||
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.targetNoteId]);
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
if (!this.isDeleted) {
|
||||
this.isDeleted = false;
|
||||
}
|
||||
|
||||
if (!this.utcDateCreated) {
|
||||
this.utcDateCreated = dateUtils.utcNowDateTime();
|
||||
}
|
||||
|
||||
super.beforeSaving();
|
||||
|
||||
if (this.isChanged) {
|
||||
this.utcDateModified = dateUtils.utcNowDateTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Link;
|
||||
@ -0,0 +1,33 @@
|
||||
class Link {
|
||||
constructor(treeCache, row) {
|
||||
this.treeCache = treeCache;
|
||||
/** @param {string} linkId */
|
||||
this.linkId = row.linkId;
|
||||
/** @param {string} noteId */
|
||||
this.noteId = row.noteId;
|
||||
/** @param {string} type */
|
||||
this.type = row.type;
|
||||
/** @param {string} targetNoteId */
|
||||
this.targetNoteId = row.targetNoteId;
|
||||
/** @param {string} utcDateCreated */
|
||||
this.utcDateCreated = row.utcDateCreated;
|
||||
/** @param {string} utcDateModified */
|
||||
this.utcDateModified = row.utcDateModified;
|
||||
}
|
||||
|
||||
/** @returns {NoteShort} */
|
||||
async getNote() {
|
||||
return await this.treeCache.getNote(this.noteId);
|
||||
}
|
||||
|
||||
/** @returns {NoteShort} */
|
||||
async getTargetNote() {
|
||||
return await this.treeCache.getNote(this.targetNoteId);
|
||||
}
|
||||
|
||||
get toString() {
|
||||
return `Link(linkId=${this.linkId}, type=${this.type}, note=${this.noteId}, targetNoteId=${this.targetNoteId})`;
|
||||
}
|
||||
}
|
||||
|
||||
export default Link;
|
||||
@ -0,0 +1,31 @@
|
||||
import StandardWidget from "./standard_widget.js";
|
||||
|
||||
class WhatLinksHereWidget extends StandardWidget {
|
||||
getWidgetTitle() { return "What links here"; }
|
||||
|
||||
async doRenderBody() {
|
||||
|
||||
|
||||
const $noteId = this.$body.find(".note-info-note-id");
|
||||
const $dateCreated = this.$body.find(".note-info-date-created");
|
||||
const $dateModified = this.$body.find(".note-info-date-modified");
|
||||
const $type = this.$body.find(".note-info-type");
|
||||
const $mime = this.$body.find(".note-info-mime");
|
||||
|
||||
const note = this.ctx.note;
|
||||
|
||||
$noteId.text(note.noteId);
|
||||
$dateCreated.text(note.dateCreated);
|
||||
$dateModified.text(note.dateModified);
|
||||
$type.text(note.type);
|
||||
$mime.text(note.mime);
|
||||
}
|
||||
|
||||
syncDataReceived(syncData) {
|
||||
if (syncData.find(sd => sd.entityName === 'notes' && sd.entityId === this.ctx.note.noteId)) {
|
||||
this.doRenderBody();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default WhatLinksHereWidget;
|
||||
@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
const repository = require('../../services/repository');
|
||||
|
||||
async function getLinks(req) {
|
||||
const note = await repository.getNote(req.params.noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${req.params.noteId} not found`];
|
||||
}
|
||||
|
||||
return await note.getLinks();
|
||||
}
|
||||
|
||||
async function getIncomingLinks(req) {
|
||||
const note = await repository.getNote(req.params.noteId);
|
||||
|
||||
if (!note) {
|
||||
return [404, `Note ${req.params.noteId} not found`];
|
||||
}
|
||||
|
||||
note.getTargetRelations()
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getLinks,
|
||||
getIncomingLinks
|
||||
};
|
||||
Loading…
Reference in New Issue