1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

API: Added documentation generator and built documentation

This commit is contained in:
Laurent Cozic
2018-09-28 21:03:28 +01:00
parent 9841488ce4
commit e98575643c
21 changed files with 1227 additions and 46 deletions

View File

@ -2,6 +2,7 @@ const { uuid } = require('lib/uuid.js');
const { promiseChain } = require('lib/promise-utils.js');
const { time } = require('lib/time-utils.js');
const { Database } = require('lib/database.js');
const { _ } = require('lib/locale.js');
const structureSql = `
CREATE TABLE folders (
@ -143,10 +144,53 @@ class JoplinDatabase extends Database {
return output;
}
tableFields(tableName) {
tableFields(tableName, options = null) {
if (options === null) options = {};
if (!this.tableFields_) throw new Error('Fields have not been loaded yet');
if (!this.tableFields_[tableName]) throw new Error('Unknown table: ' + tableName);
return this.tableFields_[tableName];
const output = this.tableFields_[tableName].slice();
if (options.includeDescription) {
for (let i = 0; i < output.length; i++) {
output[i].description = this.fieldDescription(tableName, output[i].name);
}
}
return output;
}
fieldDescription(tableName, fieldName) {
if (!this.tableDescriptions_) {
this.tableDescriptions_ = {
notes: {
parent_id: _('ID of the notebook that contains this note. Change this ID to move the note to a different notebook.'),
body: _('The note body, in Markdown. May also contain HTML.'),
is_conflict: _('Tells whether the note is a conflict or not.'),
is_todo: _('Tells whether this note is a todo or not.'),
todo_due: _('When the todo is due. An alarm will be triggered on that date.'),
todo_completed: _('Tells whether todo is completed or not. This is a timestamp in milliseconds.'),
},
folders: {},
resources: {},
tags: {},
};
const baseItems = ['notes', 'folders', 'tags', 'resources'];
for (let i = 0; i < baseItems.length; i++) {
const n = baseItems[i];
const singular = n.substr(0, n.length - 1);
this.tableDescriptions_[n].title = _('The %s title.', singular);
this.tableDescriptions_[n].created_time = _('When the %s was created.', singular);
this.tableDescriptions_[n].updated_time = _('When the %s was last updated.', singular);
this.tableDescriptions_[n].user_created_time = _('When the %s was created. It may differ from created_time as it can be manually set by the user.', singular);
this.tableDescriptions_[n].user_updated_time = _('When the %s was last updated. It may differ from updated_time as it can be manually set by the user.', singular);
}
}
const d = this.tableDescriptions_[tableName];
return d && d[fieldName] ? d[fieldName] : '';
}
refreshTableFields() {