renamed outstanding attribute references to labels

This commit is contained in:
azivner
2018-04-01 09:59:44 -04:00
parent ab2f28ceef
commit c9d73c6115
12 changed files with 71 additions and 73 deletions

View File

@@ -33,7 +33,7 @@ async function exportNoteInner(branchId, directory, pack) {
const metadata = await getMetadata(note);
if (metadata.labels.find(attr => attr.name === 'exclude_from_export')) {
if (metadata.labels.find(label => label.name === 'exclude_from_export')) {
return;
}
@@ -63,10 +63,10 @@ async function getMetadata(note) {
title: note.title,
type: note.type,
mime: note.mime,
labels: (await note.getLabels()).map(attr => {
labels: (await note.getLabels()).map(label => {
return {
name: attr.name,
value: attr.value
name: label.name,
value: label.value
};
})
};

View File

@@ -115,8 +115,8 @@ async function importNotes(files, parentNoteId) {
mime: file.meta.mime
});
for (const attr of file.meta.labels) {
await labels.createLabel(noteId, attr.name, attr.value);
for (const label of file.meta.labels) {
await labels.createLabel(noteId, label.name, label.value);
}
if (file.children.length > 0) {

View File

@@ -16,32 +16,32 @@ async function updateNoteLabels(req, res, next) {
const labels = req.body;
const now = utils.nowDate();
for (const attr of labels) {
if (attr.labelId) {
for (const label of labels) {
if (label.labelId) {
await sql.execute("UPDATE labels SET name = ?, value = ?, dateModified = ?, isDeleted = ?, position = ? WHERE labelId = ?",
[attr.name, attr.value, now, attr.isDeleted, attr.position, attr.labelId]);
[label.name, label.value, now, label.isDeleted, label.position, label.labelId]);
}
else {
// if it was "created" and then immediatelly deleted, we just don't create it at all
if (attr.isDeleted) {
if (label.isDeleted) {
continue;
}
attr.labelId = utils.newLabelId();
label.labelId = utils.newLabelId();
await sql.insert("labels", {
labelId: attr.labelId,
labelId: label.labelId,
noteId: noteId,
name: attr.name,
value: attr.value,
position: attr.position,
name: label.name,
value: label.value,
position: label.position,
dateCreated: now,
dateModified: now,
isDeleted: false
});
}
await sync_table.addLabelSync(attr.labelId);
await sync_table.addLabelSync(label.labelId);
}
return await sql.getRows("SELECT * FROM labels WHERE isDeleted = 0 AND noteId = ? ORDER BY position, dateCreated", [noteId]);
@@ -50,9 +50,9 @@ async function updateNoteLabels(req, res, next) {
async function getAllLabelNames(req) {
const names = await sql.getColumn("SELECT DISTINCT name FROM labels WHERE isDeleted = 0");
for (const attr of labels.BUILTIN_LABELS) {
if (!names.includes(attr)) {
names.push(attr);
for (const label of labels.BUILTIN_LABELS) {
if (!names.includes(label)) {
names.push(label);
}
}

View File

@@ -6,9 +6,9 @@ const parseFilters = require('../../services/parse_filters');
const buildSearchQuery = require('../../services/build_search_query');
async function searchNotes(req) {
const {attrFilters, searchText} = parseFilters(req.params.searchString);
const {labelFilters, searchText} = parseFilters(req.params.searchString);
const {query, params} = buildSearchQuery(attrFilters, searchText);
const {query, params} = buildSearchQuery(labelFilters, searchText);
const noteIds = await sql.getColumn(query, params);