Skip to content

Commit

Permalink
merging to be able to get updated code from sprint2-main
Browse files Browse the repository at this point in the history
  • Loading branch information
karengc27 committed Oct 10, 2024
2 parents ed4c6ad + 7e3e82e commit 6dedcec
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "nodebb-theme-quickstart"]
path = nodebb-theme-quickstart
url = https://github.com/sschauk/nodebb-theme-quickstart
Binary file added dump.rdb
Binary file not shown.
1 change: 1 addition & 0 deletions nodebb-theme-quickstart
1 change: 1 addition & 0 deletions pidfile 2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
28408
1 change: 1 addition & 0 deletions pidfile 3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
43549
2 changes: 1 addition & 1 deletion public/scss/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ html[data-dir="rtl"] {
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; }
}
}
}
29 changes: 16 additions & 13 deletions public/src/admin/extend/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,23 @@ define('admin/extend/widgets', [
});
}

function setupCloneButton() {
const clone = $('[component="clone"]');
function clone(location, template) {
console.log('Dhanya Shah');
const widgets = $('#active-widgets .tab-pane[data-template="' + template + '"] [data-location="' + location + '"] [data-widget]');
widgets.each(function () {
const widget = $(this).clone(true);
appendClonedWidget(widget, location);
});
}
function appendClonedWidget(widget, location) {
$('#active-widgets .active.tab-pane[data-template]:not([data-template="global"]) [data-location="' + location + '"] .widget-area').append(widget);
}

function setupCloneButton() { // all correct
const cloneContainer = $('[component="clone"]');
const cloneBtn = $('[component="clone/button"]');

clone.find('.dropdown-menu li').on('click', function () {
cloneContainer.find('.dropdown-menu li').on('click', function () {
const template = $(this).find('a').text();
cloneBtn.translateHtml('[[admin/extend/widgets:clone-from]] <strong>' + template + '</strong>');
cloneBtn.attr('data-template', template);
Expand All @@ -281,18 +293,9 @@ define('admin/extend/widgets', [
return currentAreas.indexOf(location) !== -1 ? location : undefined;
}).get().filter(function (i) { return i; });

function clone(location) {
$('#active-widgets .tab-pane[data-template="' + template + '"] [data-location="' + location + '"]').each(function () {
$(this).find('[data-widget]').each(function () {
const widget = $(this).clone(true);
$('#active-widgets .active.tab-pane[data-template]:not([data-template="global"]) [data-location="' + location + '"] .widget-area').append(widget);
});
});
}

for (let i = 0, ii = areasToClone.length; i < ii; i++) {
const location = areasToClone[i];
clone(location);
clone(location, template);
}

alerts.success('[[admin/extend/widgets:alert.clone-success]]');
Expand Down
78 changes: 43 additions & 35 deletions public/src/admin/manage/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,50 +199,57 @@ define('admin/manage/categories', [
function itemDidAdd(e) {
newCategoryId = e.to.dataset.cid;
}

// asked chatgpt to help find out what function does and give
// suggestions on what a coder can do to reduce cognitive complexity
// this functions updates information once the user finishes drag/drop
function itemDragDidEnd(e) {
console.log('Console Logging Saanika Chauk');
const isCategoryUpdate = parseInt(newCategoryId, 10) !== -1;

// Update needed?
if ((e.newIndex != null && parseInt(e.oldIndex, 10) !== parseInt(e.newIndex, 10)) || isCategoryUpdate) {
if (shouldUpdate(e, isCategoryUpdate)) {
const cid = e.item.dataset.cid;
const modified = {};
// on page 1 baseIndex is 0, on page n baseIndex is (n - 1) * ajaxify.data.categoriesPerPage
// this makes sure order is correct when drag & drop is used on pages > 1
const baseIndex = (ajaxify.data.pagination.currentPage - 1) * ajaxify.data.categoriesPerPage;
modified[cid] = {
order: baseIndex + e.newIndex + 1,
};

const modified = createModObject(e, cid, isCategoryUpdate);
if (isCategoryUpdate) {
modified[cid].parentCid = newCategoryId;

// Show/hide expand buttons after drag completion
const oldParentCid = parseInt(e.from.getAttribute('data-cid'), 10);
const newParentCid = parseInt(e.to.getAttribute('data-cid'), 10);
if (oldParentCid !== newParentCid) {
const toggle = document.querySelector(`.categories li[data-cid="${newParentCid}"] .toggle`);
if (toggle) {
toggle.classList.toggle('invisible', false);
}

const children = document.querySelectorAll(`.categories li[data-cid="${oldParentCid}"] ul[data-cid] li[data-cid]`);
if (!children.length) {
const toggle = document.querySelector(`.categories li[data-cid="${oldParentCid}"] .toggle`);
if (toggle) {
toggle.classList.toggle('invisible', true);
}
}

e.item.dataset.parentCid = newParentCid;
}
handleCatUpdate(e);
}

newCategoryId = -1;
api.put('/categories/' + cid, modified[cid]).catch(alerts.error);
}
}

function shouldUpdate(e, isCategoryUpdate) {
return (e.newIndex != null && parseInt(e.oldIndex, 10) !== parseInt(e.newIndex, 10)) || isCategoryUpdate;
}
function createModObject(e, cid, isCategoryUpdate) {
const baseIndex = (ajaxify.data.pagination.currentPage - 1) * ajaxify.data.categoriesPerPage;
const modified = {};
modified[cid] = {
order: baseIndex + e.newIndex + 1,
};
if (isCategoryUpdate) {
modified[cid].parentCid = newCategoryId;
}
return modified;
}
function handleCatUpdate(e) {
const oldParentCid = parseInt(e.from.getAttribute('data-cid'), 10);
const newParentCid = parseInt(e.to.getAttribute('data-cid'), 10);
if (oldParentCid !== newParentCid) {
toggleExpand(newParentCid, oldParentCid);
e.item.dataset.parentCid = newParentCid;
}
}
function toggleExpand(newParentCid, oldParentCid) {
const newToggle = document.querySelector(`.categories li[data-cid="${newParentCid}"] .toggle`);
if (newToggle) {
newToggle.classList.toggle('invisible', false);
}
const children = document.querySelectorAll(`.categories li[data-cid="${oldParentCid}"] ul[data-cid] li[data-cid]`);
if (!children.length) {
const oldToggle = document.querySelector(`.categories li[data-cid="${oldParentCid}"] .toggle`);
if (oldToggle) {
oldToggle.classList.toggle('invisible', true);
}
}
}
/**
* Render categories - recursively
*
Expand All @@ -253,6 +260,7 @@ define('admin/manage/categories', [
*/
function renderList(categories, container, parentCategory) {
// Translate category names if needed
console.log('rendering categories in list');
let count = 0;
const parentId = parentCategory.cid;
categories.forEach(function (category, idx, parent) {
Expand Down
43 changes: 24 additions & 19 deletions public/src/client/account/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define('forum/account/blocks', [
const Blocks = {};

Blocks.init = function () {
console.log('ALANNA CAO');
header.init();
const blockListEl = $('[component="blocks/search/list"]');
const startTypingEl = blockListEl.find('[component="blocks/start-typing"]');
Expand All @@ -29,25 +30,7 @@ define('forum/account/blocks', [
searchBy: 'username',
paginate: false,
}, function (err, data) {
if (err) {
return alerts.error(err);
}
if (!data.users.length) {
noUsersEl.removeClass('hidden');
return;
}
noUsersEl.addClass('hidden');
// Only show first 10 matches
if (data.matchCount > 10) {
data.users.length = 10;
}

app.parseAndTranslate('account/blocks', 'edit', {
edit: data.users,
}, function (html) {
blockListEl.find('[component="blocks/search/match"]').remove();
html.insertAfter(noUsersEl);
});
handleUserSearchResponse(err, data, blockListEl, noUsersEl);
});
}, 200));

Expand All @@ -66,6 +49,28 @@ define('forum/account/blocks', [
});
};

function handleUserSearchResponse(err, data, blockListEl, noUsersEl) {
if (err) {
return alerts.error(err);
}
if (!data.users.length) {
noUsersEl.removeClass('hidden');
return;
}
noUsersEl.addClass('hidden');
// Only show first 10 matches
if (data.matchCount > 10) {
data.users.length = 10;
}

app.parseAndTranslate('account/blocks', 'edit', {
edit: data.users,
}, function (html) {
blockListEl.find('[component="blocks/search/match"]').remove();
html.insertAfter(noUsersEl);
});
}

async function performBlock(uid, action) {
return socket.emit('user.toggleBlock', {
blockeeUid: uid,
Expand Down
26 changes: 15 additions & 11 deletions public/src/client/account/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@ define('forum/account/info', ['forum/account/header', 'alerts', 'forum/account/s
sessions.prepareSessionRevocation();
};

function prependModerationNote(html) {
$('[component="account/moderation-note/list"]').prepend(html);
html.find('.timeago').timeago();
}

function handleSetModerationNote(noteEl, err, notes) {
console.log('Refactor by Sofian Syed');
if (err) {
return alerts.error(err);
}
noteEl.val('');
app.parseAndTranslate('account/info', 'moderationNotes', { moderationNotes: notes }, prependModerationNote);
}

function handleModerationNote() {
$('[component="account/save-moderation-note"]').on('click', function () {
const noteEl = $('[component="account/moderation-note"]');
const note = noteEl.val();
socket.emit('user.setModerationNote', {
uid: ajaxify.data.uid,
note: note,
}, function (err, notes) {
if (err) {
return alerts.error(err);
}
noteEl.val('');

app.parseAndTranslate('account/info', 'moderationNotes', { moderationNotes: notes }, function (html) {
$('[component="account/moderation-note/list"]').prepend(html);
html.find('.timeago').timeago();
});
});
}, handleSetModerationNote.bind(null, noteEl));
});


Expand Down
63 changes: 63 additions & 0 deletions public/src/client/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,73 @@ define('forum/category', [
},
});

initalizeCategorySearch();

hooks.fire('action:topics.loaded', { topics: ajaxify.data.topics });
hooks.fire('action:category.loaded', { cid: ajaxify.data.cid });
};

function initalizeCategorySearch() {
const searchBox = $('#topicSearchInput');
if (!searchBox.length) {
return;
}

const searchButton = $('.search-button');

// Perform search on input change
searchBox.on('input', function () {
const searchTerm = $(this).val().toLowerCase();
performTopicSearch(searchTerm);
});

// Perform search on enter key press
searchBox.on('keypress', function (e) {
if (e.key === 'Enter') {
const searchTerm = $(this).val().toLowerCase();
performTopicSearch(searchTerm);
}
});

// Perform search when button is clicked
searchButton.on('click', function () {
const searchTerm = searchBox.val().toLowerCase();
performTopicSearch(searchTerm);
});
}

function performTopicSearch(searchTerm) {
const term = searchTerm.toLowerCase();

const $topics = $('[component="category/topic"]');

// Filter the topics based on the search term
const $matchedTopics = $topics.filter(function () {
const topicText = $(this).find('h3[component="topic/header"]').text().toLowerCase(); // Get the topic text
const metaContent = $(this).find('meta[itemprop="name"]').attr('content') ?
$(this).find('meta[itemprop="name"]').attr('content').toLowerCase() : ''; // Get meta content if it exists

// True if either topic text or meta content includes search term
return topicText.includes(term) || metaContent.includes(term);
});

// Show matched topics and hide others
$topics.addClass('hidden');
$matchedTopics.removeClass('hidden');

// Handle case where no topics match the search term
if ($matchedTopics.length === 0) {
if ($('[component="category/topic/no-matches"]').length === 0) {
$(`<div component="category/topic/no-matches" class="alert alert-info">No topics match the search term "${searchTerm}".</div>`)
.insertAfter('[component="category/topic"]:last');
} else {
$('[component="category/topic/no-matches"]').removeClass('hidden');
}
} else {
$('[component="category/topic/no-matches"]').addClass('hidden');
}
}

function handleScrollToTopicIndex() {
let topicIndex = ajaxify.data.topicIndex;
if (topicIndex && utils.isNumber(topicIndex)) {
Expand Down
7 changes: 7 additions & 0 deletions public/src/client/topic/threadTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ define('forum/topic/threadTools', [
changeWatching('ignore');
});

// CHATGPT SUGGESTED CODE TESTING AQUI
// require(['pinButton'], function (PinButton) {
// PinButton.init(function () {
// console.log('Button state changed');
// });
// });

function changeWatching(type, state = 1) {
const method = state ? 'put' : 'del';
api[method](`/topics/${tid}/${type}`, {}, () => {
Expand Down
Loading

0 comments on commit 6dedcec

Please sign in to comment.