Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tagger feature for copy/paste order #367 #369

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 44 additions & 11 deletions tools/tagger/tagger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let selectedOrder = [];

function renderItems(items, catId) {
let html = '';
items.forEach((tag) => {
Expand Down Expand Up @@ -66,8 +68,16 @@

function toggleTag(target) {
target.classList.toggle('selected');
// eslint-disable-next-line no-use-before-define
const title = target.querySelector('.tag').dataset.title;

Check failure on line 71 in tools/tagger/tagger.js

View workflow job for this annotation

GitHub Actions / build

Use object destructuring
const category = target.closest('.category').querySelector('h2').textContent; // Assuming category title is in h2
const tagIdentifier = { title, category };

if (target.classList.contains('selected')) {
selectedOrder.push(tagIdentifier); // Add to the selection order
} else {
selectedOrder = selectedOrder.filter(item => item.title !== title || item.category !== category); // Remove from the selection order

Check failure on line 78 in tools/tagger/tagger.js

View workflow job for this annotation

GitHub Actions / build

This line has a length of 136. Maximum allowed is 100

Check failure on line 78 in tools/tagger/tagger.js

View workflow job for this annotation

GitHub Actions / build

Expected parentheses around arrow function argument
}
displaySelected();

Check failure on line 80 in tools/tagger/tagger.js

View workflow job for this annotation

GitHub Actions / build

'displaySelected' was used before it was defined
}

function displaySelected() {
Expand All @@ -76,20 +86,33 @@
const toCopyBuffer = [];

selTagsEl.innerHTML = '';
const selectedTags = document.querySelectorAll('#results .path.selected');
if (selectedTags.length > 0) {
selectedTags.forEach((path) => {
selectedOrder.forEach(({ title, category }) => {
// Find the category element
const categories = document.querySelectorAll('#results .category');
let path;
categories.forEach(cat => {

Check failure on line 93 in tools/tagger/tagger.js

View workflow job for this annotation

GitHub Actions / build

Expected parentheses around arrow function argument
if (cat.querySelector('h2').textContent === category) {
const tag = Array.from(cat.querySelectorAll('.tag')).find(t => t.dataset.title === title);

Check failure on line 95 in tools/tagger/tagger.js

View workflow job for this annotation

GitHub Actions / build

Expected parentheses around arrow function argument
if (tag) {
path = tag.closest('.path');
}
}
});

if (path) {
const clone = path.cloneNode(true);
clone.classList.remove('filtered', 'selected');
const tag = clone.querySelector('.tag');
tag.innerHTML = tag.dataset.title;
clone.addEventListener('click', () => {
toggleTag(path);
});
toCopyBuffer.push(tag.dataset.title);
toCopyBuffer.push(`${category}: ${tag.dataset.title}`);
selTagsEl.append(clone);
});
}
});

if (selectedOrder.length > 0) {
selEl.classList.remove('hidden');
} else {
selEl.classList.add('hidden');
Expand All @@ -99,6 +122,7 @@
copybuffer.value = toCopyBuffer.join(', ');
}


Check failure on line 125 in tools/tagger/tagger.js

View workflow job for this annotation

GitHub Actions / build

More than 1 blank line not allowed
async function init() {
const tax = await getTaxonomy();

Expand All @@ -113,11 +137,20 @@
copyButton.disabled = true;
});

selEl.querySelector('button.clear').addEventListener('click', () => {
const selectedTags = document.querySelectorAll('#results .path.selected');
selectedTags.forEach((tag) => {
toggleTag(tag);
const clearButton = selEl.querySelector('button.clear');
clearButton.addEventListener('click', () => {
// Remove the 'filtered' class from all tags
document.querySelectorAll('#results .tag').forEach((tag) => {
tag.closest('.path').classList.remove('filtered');
});

Check failure on line 146 in tools/tagger/tagger.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
// Remove the 'selected' class from all selected tags
document.querySelectorAll('.selected').forEach((selectedTag) => {
selectedTag.classList.remove('selected');
});

Check failure on line 151 in tools/tagger/tagger.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
selectedOrder = [];
displaySelected();
copyButton.disabled = false;
});

Expand All @@ -131,4 +164,4 @@
});
}

init();
init();

Check failure on line 167 in tools/tagger/tagger.js

View workflow job for this annotation

GitHub Actions / build

Newline required at end of file but not found