mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-08 07:21:02 -04:00
[#181] fix selected / checkmark classes on operation list, based on the current recipe list. Update TODO
This commit is contained in:
parent
ccc5095763
commit
5e9aa5cd09
5 changed files with 82 additions and 13 deletions
|
@ -63,6 +63,7 @@ class App {
|
||||||
this.setCompileMessage();
|
this.setCompileMessage();
|
||||||
this.loadLocalStorage();
|
this.loadLocalStorage();
|
||||||
this.populateOperationsList();
|
this.populateOperationsList();
|
||||||
|
this.manager.recipe.updateSelectedOperations();
|
||||||
this.manager.setup();
|
this.manager.setup();
|
||||||
this.manager.output.saveBombe();
|
this.manager.output.saveBombe();
|
||||||
this.uriParams = this.getURIParams();
|
this.uriParams = this.getURIParams();
|
||||||
|
@ -329,6 +330,8 @@ class App {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.adjustComponentSizes();
|
this.adjustComponentSizes();
|
||||||
|
|
||||||
|
// @TODO: handle sortable, draggable, popovers functionality etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -801,7 +804,7 @@ class App {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for CyerChef statechange events.
|
* Handler for CyberChef statechange events.
|
||||||
* Fires whenever the input or recipe changes in any way.
|
* Fires whenever the input or recipe changes in any way.
|
||||||
*
|
*
|
||||||
* @listens Manager#statechange
|
* @listens Manager#statechange
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
#### Mobile UI ( on real device ):
|
#### Mobile UI ( on real device ):
|
||||||
- OperationsWaiter operationDblClick: class 'selected' needs to be removed once it is deleted from recipe list, through any type of event
|
|
||||||
- How to add operations to favourites since drag and drop is now disabled on mobile ( maybe a star icon...? )
|
- How to add operations to favourites since drag and drop is now disabled on mobile ( maybe a star icon...? )
|
||||||
- 'name' in recipe waiter > addOperation is <b>what</b>ever instead of a plain title..
|
- 'name' in recipe waiter > addOperation is <b>what</b>ever instead of a plain data-name, updateSelectedOperations not working for search results because of that
|
||||||
- Recipe list on mobile panel is too small to comfortably scroll and change order of recipes
|
- Recipe list on mobile panel is too small to comfortably scroll and change order of recipes
|
||||||
|
|
||||||
- test *thoroughly* with keyboard popping up because that messes with view-heights on mobile probably and might make it a very frustrating experience
|
- test *thoroughly* with keyboard popping up because that messes with view-heights on mobile probably and might make it a very frustrating experience
|
||||||
|
|
|
@ -236,7 +236,6 @@ class OperationsWaiter {
|
||||||
*/
|
*/
|
||||||
operationDblclick(e) {
|
operationDblclick(e) {
|
||||||
const li = e.target;
|
const li = e.target;
|
||||||
e.target.classList.add("selected");
|
|
||||||
this.manager.recipe.addOperation(li.getAttribute("data-name"));
|
this.manager.recipe.addOperation(li.getAttribute("data-name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,6 +339,7 @@ class OperationsWaiter {
|
||||||
this.app.saveFavourites(favouritesList);
|
this.app.saveFavourites(favouritesList);
|
||||||
this.app.loadFavourites();
|
this.app.loadFavourites();
|
||||||
this.app.populateOperationsList();
|
this.app.populateOperationsList();
|
||||||
|
this.manager.recipe.updateSelectedOperations();
|
||||||
this.manager.recipe.initialiseOperationDragNDrop();
|
this.manager.recipe.initialiseOperationDragNDrop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -388,7 +388,8 @@ class RecipeWaiter {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the specified operation to the recipe.
|
* Adds the specified operation to the recipe and
|
||||||
|
* adds a checkmark to the operation in Operations op-list
|
||||||
*
|
*
|
||||||
* @fires Manager#operationadd
|
* @fires Manager#operationadd
|
||||||
* @param {string} name - The name of the operation to add
|
* @param {string} name - The name of the operation to add
|
||||||
|
@ -396,6 +397,7 @@ class RecipeWaiter {
|
||||||
*/
|
*/
|
||||||
addOperation(name) {
|
addOperation(name) {
|
||||||
const item = document.createElement("li");
|
const item = document.createElement("li");
|
||||||
|
item.setAttribute("data-name", name);
|
||||||
|
|
||||||
item.classList.add("operation");
|
item.classList.add("operation");
|
||||||
item.innerText = name;
|
item.innerText = name;
|
||||||
|
@ -404,6 +406,8 @@ class RecipeWaiter {
|
||||||
|
|
||||||
$(item).find("[data-toggle='tooltip']").tooltip();
|
$(item).find("[data-toggle='tooltip']").tooltip();
|
||||||
|
|
||||||
|
this.updateSelectedOperations();
|
||||||
|
|
||||||
item.dispatchEvent(this.manager.operationadd);
|
item.dispatchEvent(this.manager.operationadd);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
@ -419,6 +423,7 @@ class RecipeWaiter {
|
||||||
while (recList.firstChild) {
|
while (recList.firstChild) {
|
||||||
recList.removeChild(recList.firstChild);
|
recList.removeChild(recList.firstChild);
|
||||||
}
|
}
|
||||||
|
this.clearAllSelectedClasses();
|
||||||
recList.dispatchEvent(this.manager.operationremove);
|
recList.dispatchEvent(this.manager.operationremove);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,8 +471,8 @@ class RecipeWaiter {
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
opAdd(e) {
|
opAdd(e) {
|
||||||
log.debug(`'${e.target.querySelector(".op-title").textContent}' added to recipe`);
|
log.debug(`'${e.target.getAttribute("data-name")}' added to recipe`);
|
||||||
|
this.updateSelectedOperations();
|
||||||
this.triggerArgEvents(e.target);
|
this.triggerArgEvents(e.target);
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
}
|
}
|
||||||
|
@ -482,6 +487,7 @@ class RecipeWaiter {
|
||||||
*/
|
*/
|
||||||
opRemove(e) {
|
opRemove(e) {
|
||||||
log.debug("Operation removed from recipe");
|
log.debug("Operation removed from recipe");
|
||||||
|
this.updateSelectedOperations();
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,6 +611,70 @@ class RecipeWaiter {
|
||||||
controlsContent.style.transform = `scale(${scale})`;
|
controlsContent.style.transform = `scale(${scale})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all "selected" classes for op-list list items at once
|
||||||
|
*
|
||||||
|
* This hides all the checkmark icons of previously added ( selected )
|
||||||
|
* operations to the recipe list
|
||||||
|
*/
|
||||||
|
clearAllSelectedClasses(){
|
||||||
|
const list = document.querySelectorAll(".operation.selected");
|
||||||
|
|
||||||
|
// check if any operations are selected at all to prevent errors
|
||||||
|
if (list.length){
|
||||||
|
list.forEach((item) => {
|
||||||
|
item.classList.remove("selected");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add "selected" to the operation that is added to the recipe
|
||||||
|
*
|
||||||
|
* This displays a checkmark icon to the operation in the op-list
|
||||||
|
*
|
||||||
|
* @param {string} opDataName the data-name of the target operation
|
||||||
|
*/
|
||||||
|
addSelectedClass(opDataName){
|
||||||
|
const list = document.querySelectorAll(".operation");
|
||||||
|
const item = Array.from(list).find((item) => item.getAttribute("data-name") === opDataName );
|
||||||
|
|
||||||
|
item.classList.add("selected");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update which items are selected in op-list.
|
||||||
|
*
|
||||||
|
* First, all selected classes are removed from op-list, then we get the current
|
||||||
|
* recipe-list ingredient names and add 'selected' back to the matching operations.
|
||||||
|
*
|
||||||
|
* Note: It seems a little overkill, but with the current tightly coupled code this is
|
||||||
|
* a reliable way to make sure the 'selected' operations are always in sync with
|
||||||
|
* the recipe list ( I think this is preferable to complicating a lot of existing
|
||||||
|
* code ), I'd recommend to refactor this at one point, but that will mean a huge code
|
||||||
|
* overhaul for another time / issue.
|
||||||
|
*/
|
||||||
|
updateSelectedOperations(){
|
||||||
|
let recipeList, operations;
|
||||||
|
|
||||||
|
recipeList = document.querySelectorAll("#rec-list > li");
|
||||||
|
operations = document.querySelectorAll(".operation");
|
||||||
|
|
||||||
|
this.clearAllSelectedClasses();
|
||||||
|
|
||||||
|
if ( recipeList.length ){
|
||||||
|
recipeList.forEach((ingredient) => {
|
||||||
|
const ingredientName = ingredient.getAttribute("data-name");
|
||||||
|
|
||||||
|
operations.forEach((operation) => {
|
||||||
|
if ( ingredientName === operation.getAttribute("data-name")){
|
||||||
|
this.addSelectedClass(ingredientName);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default RecipeWaiter;
|
export default RecipeWaiter;
|
||||||
|
|
|
@ -27,16 +27,13 @@ class WindowWaiter {
|
||||||
* continuous resetting).
|
* continuous resetting).
|
||||||
*/
|
*/
|
||||||
windowResize() {
|
windowResize() {
|
||||||
debounce(this.app.adjustComponentSizes, 200, "windowResize", this.app, [])();
|
|
||||||
|
|
||||||
if ( window.innerWidth >= this.app.breakpoint ) {
|
if ( window.innerWidth >= this.app.breakpoint ) {
|
||||||
this.app.setDesktopLayout(false);
|
this.app.setDesktopLayout(false); //@TODO: use setDesktopUI() func
|
||||||
} else {
|
} else {
|
||||||
this.app.setMobileLayout();
|
this.app.setMobileLayout(); //@TODO: use mobileUI() if needed
|
||||||
}
|
}
|
||||||
|
|
||||||
// we must repopulate the op lists to handle sortable, draggable, popovers etc.
|
debounce(this.app.adjustComponentSizes, 200, "windowResize", this.app, [])();
|
||||||
debounce(this.app.populateOperationsList, 200, "windowResize", this.app, [])();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue