Update Compass QoL Enhancer to 1.30.0

- Add ability to toggle sorting on Wiki/Resources
This commit is contained in:
blankie 2024-04-23 11:49:10 +10:00
parent 5120b11375
commit b4037cea1d
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 37 additions and 13 deletions

View File

@ -2,7 +2,7 @@
// @name Compass QoL Enhancer // @name Compass QoL Enhancer
// @namespace blankie-scripts // @namespace blankie-scripts
// @match http*://*.compass.education/* // @match http*://*.compass.education/*
// @version 1.29.0 // @version 1.30.0
// @author blankie // @author blankie
// @description A userscript that adds small but useful features for Compass, such as the ability to close windows by clicking on the background // @description A userscript that adds small but useful features for Compass, such as the ability to close windows by clicking on the background
// @inject-into page // @inject-into page
@ -230,7 +230,7 @@ if (LearningTasksDetailsWidgetNew) {
let isStudentView = widget.isStudentView; let isStudentView = widget.isStudentView;
let isStudentOrParent = widget.isStudentOrParent; let isStudentOrParent = widget.isStudentOrParent;
widget.isStudentView = widget.isStudentOrParent = false; widget.isStudentView = widget.isStudentOrParent = false;
let ret = originalRenderer.apply(this, arguments); let ret = originalRenderer.apply(widget, arguments);
widget.isStudentView = isStudentView; widget.isStudentView = isStudentView;
widget.isStudentOrParent = isStudentOrParent; widget.isStudentOrParent = isStudentOrParent;
return ret; return ret;
@ -363,11 +363,10 @@ if (InstanceDetailsWidget) {
} }
// Sort by name in wiki/resources // Sort by name in wiki/resources
function isFolder(node) {
return node.data.type === unsafeWindow.Compass.enums.WikiNodeType.Folder;
}
function wikiNodeSort(lhs, rhs) { function wikiNodeSort(lhs, rhs) {
function isFolder(node) {
return node.data.type === unsafeWindow.Compass.enums.WikiNodeType.Folder;
}
if (isFolder(lhs) && !isFolder(rhs)) { if (isFolder(lhs) && !isFolder(rhs)) {
return -1; return -1;
} else if (!isFolder(lhs) && isFolder(rhs)) { } else if (!isFolder(lhs) && isFolder(rhs)) {
@ -384,13 +383,38 @@ function wikiNodeSort(lhs, rhs) {
return 1; return 1;
} }
} }
function wikiHandleSorting() {
// check if root node exists, otherwise pages like /Communicate/SchoolDocumentation.aspx will die
if (this.sort && this.treePanel.getRootNode()) {
this.treePanel.store.sort({sorterFn: wikiNodeSort});
} else if (!this.sort) {
this.treePanel.store.sorters.clear();
}
}
// Add "Enable/Disable sorting" button
function wikiAddSortButton() {
let refreshButton = this.treePanel.down("#refreshButton");
toolbar = refreshButton.up();
toolbar.remove("toggleSortButton");
toolbar.insert(toolbar.items.items.indexOf(refreshButton), {
xtype: "button",
itemId: "toggleSortButton",
text: `${this.sort ? "Disable" : "Enable"} Sorting`,
handler: () => {
this.sort = !this.sort;
wikiHandleSorting.call(this);
this.rebindTreePanel(true);
}
});
}
let WikiBrowserPanel = getExtClass("Compass.widgets.WikiBrowserPanel"); let WikiBrowserPanel = getExtClass("Compass.widgets.WikiBrowserPanel");
if (WikiBrowserPanel) { if (WikiBrowserPanel) {
let originalInitComponent = WikiBrowserPanel.prototype.initComponent; let originalInitComponent = WikiBrowserPanel.prototype.initComponent;
WikiBrowserPanel.prototype.initComponent = function() { WikiBrowserPanel.prototype.initComponent = function() {
this.on("treeDataLoaded", function() { this.sort = true;
this.treePanel.store.sort({sorterFn: wikiNodeSort}); this.on("treeDataLoaded", wikiHandleSorting);
});
originalInitComponent.apply(this, arguments); originalInitComponent.apply(this, arguments);
} }
@ -406,10 +430,8 @@ if (WikiBrowserPanel) {
this.treePanel.down("#toolButton").hidden = true; this.treePanel.down("#toolButton").hidden = true;
this.treePanel.events.itemcontextmenu = true; this.treePanel.events.itemcontextmenu = true;
// check if root node exists, otherwise pages like /Communicate/SchoolDocumentation.aspx will die wikiHandleSorting.call(this);
if (this.treePanel.getRootNode()) { wikiAddSortButton.call(this);
this.treePanel.store.sort({sorterFn: wikiNodeSort});
}
}; };
let originalSelectedNodeChanged = WikiBrowserPanel.prototype.selectedNodeChanged; let originalSelectedNodeChanged = WikiBrowserPanel.prototype.selectedNodeChanged;
@ -427,6 +449,8 @@ if (WikiBrowserPanel) {
toolbar.remove(item); toolbar.remove(item);
} }
} }
wikiAddSortButton.call(this);
}; };
let originalUpdateNodePermissions = WikiBrowserPanel.prototype.updateNodePermissions; let originalUpdateNodePermissions = WikiBrowserPanel.prototype.updateNodePermissions;