added "type" to attribute dialog, name autocomplete servers according to the choice

This commit is contained in:
azivner
2018-08-03 11:11:57 +02:00
parent 097114c0f2
commit 509093b755
8 changed files with 623 additions and 233 deletions

View File

@@ -1,18 +1,25 @@
"use strict";
const repository = require('./repository');
const sql = require('./sql');
const utils = require('./utils');
const Attribute = require('../entities/attribute');
const BUILTIN_ATTRIBUTES = [
'disableVersioning',
'calendarRoot',
'archived',
'excludeFromExport',
'run',
'manualTransactionHandling',
'disableInclusion',
'appCss',
'hideChildrenOverview'
// label names
{ type: 'label', name: 'disableVersioning' },
{ type: 'label', name: 'calendarRoot' },
{ type: 'label', name: 'archived' },
{ type: 'label', name: 'excludeFromExport' },
{ type: 'label', name: 'run' },
{ type: 'label', name: 'manualTransactionHandling' },
{ type: 'label', name: 'disableInclusion' },
{ type: 'label', name: 'appCss' },
{ type: 'label', name: 'hideChildrenOverview' },
// relation names
{ type: 'relation', name: 'runOnNoteView' },
{ type: 'relation', name: 'runOnNoteTitleChange' }
];
async function getNotesWithAttribute(name, value) {
@@ -44,9 +51,29 @@ async function createAttribute(noteId, name, value = "") {
}).save();
}
async function getAttributeNames(type, nameLike) {
const names = await sql.getColumn(
`SELECT DISTINCT name
FROM attributes
WHERE isDeleted = 0
AND type = ?
AND name LIKE '%${utils.sanitizeSql(nameLike)}%'`, [ type ]);
for (const attribute of BUILTIN_ATTRIBUTES) {
if (attribute.type === type && !names.includes(attribute.name)) {
names.push(attribute.name);
}
}
names.sort();
return names;
}
module.exports = {
getNotesWithAttribute,
getNoteWithAttribute,
createAttribute,
getAttributeNames,
BUILTIN_ATTRIBUTES
};