Skip to content

Commit

Permalink
Allow to create multiple tasks at once
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejkupczyk committed Oct 18, 2020
1 parent 2f458fa commit 17a0f33
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
5 changes: 5 additions & 0 deletions files/todolists.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
.ToDoLists-form .finished {
text-decoration: line-through;
}
.ToDoLists-add-new {
resize: none;
overflow: hidden;
overflow-wrap: break-word;
}

[v-cloak] {
display: none;
Expand Down
6 changes: 2 additions & 4 deletions files/todolists.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}

this.$http.post(this.action, { task: this.newTask }, (response) => {
this.tasks.push(response);
this.tasks.push(...response);
this.newTask.description = '';
});
},
Expand Down Expand Up @@ -70,9 +70,7 @@
});
},
validateDescription(description) {
const length = description ? description.length : 0;

return length > 0 && length <= 120;
return (description ? description.length : 0) > 0;
},
},
});
Expand Down
8 changes: 3 additions & 5 deletions pages/partials/todolist.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ class="<?= plugin_get_current() ?>-form form-inline"
@submit.prevent
>
<input v-model="newTask.bug_id" type="hidden" value="<?= $bugId ?>">
<input
<textarea
@keydown.enter.prevent="insertTask"
v-model="newTask.description"
v-if="!readOnly"
type="text"
rows="1"
class="<?= plugin_get_current() ?>-add-new input-sm"
placeholder="<?= plugin_lang_get('add_new_task') ?>"
size="40"
maxlength="120"
/>
></textarea>
<button class="btn btn-primary btn-sm btn-white btn-round" @click="insertTask">
<?= plugin_lang_get('add') ?>
</button>
Expand Down
17 changes: 11 additions & 6 deletions src/AjaxRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __get($name)
} elseif (isset($this->data[$name])) {
return $this->data[$name];
} else {
throw new Exception();
throw new Exception("Property {$name} is undefined");
}
}

Expand Down Expand Up @@ -72,12 +72,17 @@ protected function deleteRequest()

protected function postRequest()
{
$task = $this->repository->insert([
'bug_id' => $this->bug_id,
'description' => $this->description,
]);
$tasksToAdd = array_filter(explode(PHP_EOL, $this->description));
$tasksAdded = [];

foreach ($tasksToAdd as $description) {
$tasksAdded[] = $this->repository->insert([
'bug_id' => $this->bug_id,
'description' => $description,
]);
}

$this->sendJSON($task);
$this->sendJSON($tasksAdded);
}

protected function putRequest()
Expand Down
1 change: 1 addition & 0 deletions src/TasksRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function insert($data)
return [
'id' => db_insert_id($this->table),
'bug_id' => $bug_id,
'finished' => false,
'description' => $description,
];
}
Expand Down

0 comments on commit 17a0f33

Please sign in to comment.