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

Erase all button on menu #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions client-data/board.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<script src="../js/minitpl.js"></script>
<script src="../js/board.js"></script>
<script src="../tools/pencil/wbo_pencil_point.js"></script>
<script src="../tools/new/new.js"></script>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably not be called new, but something like clear

<script src="../tools/pencil/pencil.js"></script>
<script src="../tools/cursor/cursor.js"></script>
<script src="../tools/line/line.js"></script>
Expand Down
60 changes: 60 additions & 0 deletions client-data/tools/new/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* WHITEBOPHIR
*********************************************************
* @licstart The following is the entire license notice for the
* JavaScript code in this page.
*
* Copyright (C) 2013 Ophir LOJKINE
*
*
* The JavaScript code in this page is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License (GNU GPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
*
* @licend
*/

(function grid() {
// when new button clicks then calls this function
function btnClickHandler() {
Tools.socket.emit('broadcast', {
board: Tools.boardName,
data : {
tool : "New",
type : "deleteall"
}
});
Tools.drawingArea.innerHTML = '';
Comment on lines +30 to +37
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tools.socket shouldn't be used directly. You can use drawAndSend. See other tools for an example.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there should probably be a confirmation prompt. This erases all data forever, which could represent days of work by multiple people.

}

// this is callback handler from socket
function eraseAll(data) {
switch (data.type) {
case "deleteall":
Tools.drawingArea.innerHTML = '';
break;
Comment on lines +43 to +45
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a formatting problem

}
}

Tools.add({
"name": "New",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shouldn't be called new

"shortcut": "n",
"listeners": {},
"icon": "tools/new/new.svg",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not new

"oneTouch": true,
"onstart": btnClickHandler,
"draw": eraseAll,
"mouseCursor": "crosshair",
});

})();
9 changes: 9 additions & 0 deletions client-data/tools/new/new.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions server/boardData.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ BoardData.prototype.delete = function (id) {
this.delaySave();
};

/** Removes all data from the board
*/
BoardData.prototype.deleteall = function () {
//KISS
this.board = [];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This.board is an object, not an array

this.delaySave();
};

/** Reads data from the board
* @param {string} id - Identifier of the element to get.
* @returns {object} The element with the given id, or undefined if no element has this id
Expand Down
3 changes: 3 additions & 0 deletions server/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ async function saveHistory(boardName, message) {
case "delete":
if (id) board.delete(id);
break;
case "deleteall":
board.deleteall();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check that the tool is activated, and this tool should probably not be activated by default.

break;
case "update":
if (id) board.update(id, message);
break;
Expand Down