-
Notifications
You must be signed in to change notification settings - Fork 86
Updates to task / task list design - #553 #554 #555 #557
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
783df8b
Added schema for tasks lists - #554
green-arrow 2bd2617
Merge branch 'develop' into task-redesign
green-arrow 77480ab
Fix seed data and task model tests.
green-arrow 7d45f05
Added API and views for task lists
green-arrow 741d0e4
Merge branch 'develop' into task-redesign
green-arrow 106f78a
Address code review comments
green-arrow 8ccbfaf
Change naming of 'rank' to 'order'
green-arrow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| defmodule CodeCorps.Repo.Migrations.CreateTaskList do | ||
| use Ecto.Migration | ||
| import Ecto.Changeset | ||
| import Ecto.Query | ||
|
|
||
| alias CodeCorps.Project | ||
| alias CodeCorps.Repo | ||
| alias CodeCorps.Task | ||
| alias CodeCorps.TaskList | ||
|
|
||
| def change do | ||
| create table(:task_lists) do | ||
| add :name, :string | ||
| add :order, :integer | ||
| add :project_id, references(:projects, on_delete: :nothing) | ||
|
|
||
| timestamps() | ||
| end | ||
|
|
||
| create index(:task_lists, [:project_id]) | ||
|
|
||
| alter table(:tasks) do | ||
| add :task_list_id, references(:task_lists, on_delete: :nothing) | ||
| add :order, :integer | ||
| end | ||
|
|
||
| flush | ||
|
|
||
| Application.ensure_all_started :timex | ||
| migrate_existing() | ||
| end | ||
|
|
||
| def migrate_existing() do | ||
| Project | ||
| |> preload(:task_lists) | ||
| |> Repo.all() | ||
| |> Enum.each(&handle_project_migration/1) | ||
| end | ||
|
|
||
| defp handle_project_migration(project) do | ||
| cond do | ||
| project.task_lists != [] -> | ||
| IO.puts "Task lists already exist for #{project.title}, skipping migration." | ||
| true -> | ||
| IO.puts "Generating default task lists for #{project.title}." | ||
|
|
||
| {:ok, project} = Project.changeset(project, %{}) | ||
| |> put_assoc(:task_lists, TaskList.default_task_lists()) | ||
| |> Repo.update | ||
|
|
||
| add_existing_tasks_to_inbox(project, hd(project.task_lists)) | ||
| end | ||
| end | ||
|
|
||
| defp add_existing_tasks_to_inbox(project, task_list) do | ||
| Task | ||
| |> CodeCorps.Helpers.Query.project_filter(%{ project_id: project.id }) | ||
| |> Repo.all() | ||
| |> Enum.each(&assign_task_to_inbox(&1, task_list)) | ||
| end | ||
|
|
||
| defp assign_task_to_inbox(task, task_list) do | ||
| Task.changeset(task, %{ task_list_id: task_list.id }) | ||
| |> Repo.update() | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| defmodule CodeCorps.TaskListControllerTest do | ||
| use CodeCorps.ApiCase, resource_name: :task_list | ||
|
|
||
| @valid_attrs %{ | ||
| name: "Test task" | ||
| } | ||
|
|
||
| @invalid_attrs %{ | ||
| name: nil | ||
| } | ||
|
|
||
| describe "index" do | ||
| test "lists all entries", %{conn: conn} do | ||
| [task_list_1, task_list_2] = insert_pair(:task_list) | ||
|
|
||
| conn | ||
| |> request_index | ||
| |> json_response(200) | ||
| |> assert_ids_from_response([task_list_1.id, task_list_2.id]) | ||
| end | ||
|
|
||
| test "lists all entries by order", %{conn: conn} do | ||
| # Has to be done manually. Inserting as a list is too quick. | ||
| # Field lacks the resolution to differentiate. | ||
| project = insert(:project) | ||
| task_list_1 = insert(:task_list, project: project, order: 2000) | ||
| task_list_2 = insert(:task_list, project: project, order: 1000) | ||
| task_list_3 = insert(:task_list, project: project, order: 3000) | ||
|
|
||
| path = conn |> task_list_path(:index) | ||
|
|
||
| conn | ||
| |> get(path) | ||
| |> json_response(200) | ||
| |> assert_ids_from_response([task_list_2.id, task_list_1.id, task_list_3.id]) | ||
| end | ||
|
|
||
| test "lists all task lists for a project", %{conn: conn} do | ||
| project_1 = insert(:project) | ||
| project_2 = insert(:project) | ||
| insert(:task_list, project: project_1) | ||
| insert(:task_list, project: project_1) | ||
| insert(:task_list, project: project_2) | ||
|
|
||
| json = | ||
| conn | ||
| |> get("projects/#{project_1.id}/task-lists") | ||
| |> json_response(200) | ||
|
|
||
| assert json["data"] |> Enum.count == 2 | ||
| end | ||
| end | ||
|
|
||
| describe "show" do | ||
| test "shows chosen resource", %{conn: conn} do | ||
| task_list = insert(:task_list) | ||
|
|
||
| conn | ||
| |> request_show(task_list) | ||
| |> json_response(200) | ||
| |> Map.get("data") | ||
| |> assert_result_id(task_list.id) | ||
| end | ||
|
|
||
| test "shows task list by id for project", %{conn: conn} do | ||
| task_list = insert(:task_list) | ||
|
|
||
| path = conn |> project_task_list_path(:show, task_list.project_id, task_list.id) | ||
| data = conn |> get(path) |> json_response(200) |> Map.get("data") | ||
|
|
||
| assert data["id"] == "#{task_list.id}" | ||
| assert data["type"] == "task-list" | ||
| end | ||
|
|
||
| test "renders 404 when id is nonexistent", %{conn: conn} do | ||
| assert conn |> request_show(:not_found) |> json_response(404) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| defmodule CodeCorps.TaskListTest do | ||
| use CodeCorps.ModelCase | ||
|
|
||
| alias CodeCorps.TaskList | ||
|
|
||
| @valid_attrs %{name: "some content", position: 42} | ||
| @invalid_attrs %{} | ||
|
|
||
| test "changeset with valid attributes" do | ||
| changeset = TaskList.changeset(%TaskList{}, @valid_attrs) | ||
| assert changeset.valid? | ||
| end | ||
|
|
||
| test "changeset with invalid attributes" do | ||
| changeset = TaskList.changeset(%TaskList{}, @invalid_attrs) | ||
| refute changeset.valid? | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
hd()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hd/1refers to the first item in the list, the head. (Also,tl/1refers to the last item, the tail)