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

edit task data click event #7

Merged
merged 4 commits into from
Feb 14, 2022
Merged
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
58 changes: 54 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const getIndex = async (arr:any,val:string) => {
export function activate(context: vscode.ExtensionContext) {

// Load KanbanBoard file
const KanbanBoard = require(context.extensionPath+"\\src\\kanbanBoard.js");

const KanbanBoard = require(context.extensionPath+"/src/kanbanBoard.js");
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
// console.log('Congratulations, your extension "kanban-vscode" is now active!');
Expand Down Expand Up @@ -62,6 +61,8 @@ export function activate(context: vscode.ExtensionContext) {
});
}

let items = ["todo","inprogress","testing","completed"];

//Load Kanban page
const panel = vscode.window.createWebviewPanel(
'kanbanBoard',
Expand Down Expand Up @@ -114,8 +115,6 @@ export function activate(context: vscode.ExtensionContext) {
});
return;
case 'addTask':
let items = ["todo","inprogress","testing","completed"];

window.showInputBox({
placeHolder: "Task Name",
title: "Create Task"
Expand All @@ -138,6 +137,12 @@ export function activate(context: vscode.ExtensionContext) {
}
let val:string = value || '';
data = JSON.parse(data);
for(let i=0;i<items.length;i++) {
if(data[items[i]].findIndex(d => d.name === input) > -1) {
vscode.window.showErrorMessage("Task Already exist. Please create a task with different name");
return;
}
}
data[val].push({"name":input, "description": desc});

fs.writeFile(jsonPath,JSON.stringify(data,undefined,4),(err: any) => {
Expand All @@ -152,6 +157,7 @@ export function activate(context: vscode.ExtensionContext) {
}
);
case 'delete':
console.log('Delete api event Click!');
fs.readFile(jsonPath,"utf8",async (err:any,data:any) => {
if(err) {
vscode.window.showErrorMessage("Can't delete. Please try again");
Expand All @@ -170,6 +176,50 @@ export function activate(context: vscode.ExtensionContext) {
});
});
return;

case 'edit':
console.log('Edit api event Click!');
window.showInputBox({
placeHolder: "Task Name",
title: "Edit Task",
value: message.text.name
}).then((input) => {
window.showInputBox({
placeHolder: "Task Description",
title: "Edit Task",
value: message.text.description
}).then((desc) => {
window.showQuickPick(items,{
canPickMany: false,
placeHolder: "Please select",
title: "Task Status"
}).then((value) => {
// window.showInformationMessage(`Task Name: ${input}. Task status: ${value}`);
fs.readFile(jsonPath,"utf8",(err:any,data:any) => {
if(err) {
vscode.window.showErrorMessage("Error in Loading Kanban Board.");
return;
}
let val:string = value || '';
data = JSON.parse(data);
let key = message.text.status.replace(" ", '').toLowerCase();
let ind = data[key].findIndex(d => d.name === message.text.name);
if(ind > -1) {
data[key].splice(ind, 1);
}
data[val].push({"name":input, "description": desc});

fs.writeFile(jsonPath,JSON.stringify(data,undefined,4),(err: any) => {
if(err) {
vscode.window.showErrorMessage("Something went Wrong!");
}
panel.webview.html = KanbanBoard.loadKanbanBoard(bootstrap,JSON.stringify(data,undefined,4),sortablejs);
});
});
});
});
}
);

}
});
Expand Down
17 changes: 15 additions & 2 deletions src/kanbanBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ const loadKanbanBoard = (bootstrap,data,sortablejs) => {
})
}

function dataClicked(data, status) {
console.log('Edit Data: ', data, status);
vscode.postMessage({
command: 'edit',
text: {
name: data.name,
description: data.description,
status: status
}
})
}

Sortable.create(todo,{
group: {
name: "kanban",
Expand Down Expand Up @@ -255,8 +267,9 @@ const displayData = (data,key,name) => {
for(let i=0;i<data.length;i++) {
res+=`
<li class="list-group-item d-flex justify-content-between align-items-center" style="cursor: pointer;">
${data[i].name}

<div>
<div onclick='dataClicked(${JSON.stringify(data[i])}, "${name}");'>${data[i].name}</div>
<div>
<button type="button" class="btn btn-outline-danger" onclick="deleteTask('${data[i].name}','${key}');" style="float: right;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash-fill" viewBox="0 0 16 16">
<path d="M2.5 1a1 1 0 0 0-1 1v1a1 1 0 0 0 1 1H3v9a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V4h.5a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H10a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1H2.5zm3 4a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5zM8 5a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7A.5.5 0 0 1 8 5zm3 .5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 1 0z"/>
Expand Down