Skip to content
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
1 change: 1 addition & 0 deletions app/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default Model.extend({

donationGoals: hasMany('donation-goal', { async: true }),
organization: belongsTo('organization', { async: true }),
taskLists: hasMany('task-list', { async: true }),
tasks: hasMany('tasks', { async: true }),
projectCategories: hasMany('project-category', { async: true }),
projectSkills: hasMany('project-skill', { async: true }),
Expand Down
55 changes: 55 additions & 0 deletions app/models/task-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';

/**
Task-list is a collection of categorized tasks that belong to a project.

@class task-list
@module Model
@extends Ember.Model
*/
export default Model.extend({

/**
Task-lists name

@attribute name
@type string
*/
name: attr(),

/**
Order is a read-only attribute computed from the `position` attribute

@attribute order
@readonly
@type number
*/
order: attr(),

/**
Position is a virtual (write-only) attribute used to compute the `order` of the task-list

@attribute position
@virtual
@type number
*/
position: attr(),

/**
The project that the task-list belongs to.

@attribute project
@type Ember.computed
*/
project: belongsTo('project', { async: true }),

/**
The tasks that belong to the task-list.

@attribute tasks
@type Ember.computed
*/
tasks: hasMany('task', { async: true })
});
116 changes: 116 additions & 0 deletions app/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,134 @@ import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
import ContainsCodeMixin from '../mixins/contains-code';

/**
Task is a (issue/idea/task) created by a user for a project.

@class task
@module Model
@extends Ember.Model
*/
export default Model.extend(ContainsCodeMixin, {

/**
The tasks body content.

@attribute body
@type string
*/
body: attr(),

/**
The date that the task was inserted.

@attribute insertedAt
@type date
*/
insertedAt: attr('date'),

/**
The tasks markdown content.

@attribute markdown
@type string
*/
markdown: attr(),

/**
The tasks client facing number.

@attribute number
@type number
*/
number: attr('number'),

/**
Order is a read-only attribute computed from the `position` attribute

@attribute order
@readonly
@type number
*/
order: attr(),

/**
The task's type (issue/task/idea/etc.)

@attribute taskType
@type string
*/
taskType: attr(),

/**
The task's status (open/closed)

@attribute status
@type string
*/
status: attr(),

/**
The task's title

@attribute title
@type string
*/
title: attr(),

/**
Position is a virtual (write-only) attribute used to compute the `order` of the task

@attribute position
@virtual
@type number
*/
position: attr(),

/**
The comments that belong to the task

@attribute comments
@type Ember.computed
*/
comments: hasMany('comment', { async: true }),

/**
The comment user mentions that belong to the task

@attribute commentUserMentions
@type Ember.computed
*/
commentUserMentions: hasMany('comment-user-mention', { asnyc: true }),

/**
The task-list that the task belongs to

@attribute task-list
@type Ember.computed
*/
taskList: belongsTo('task-list', { async: true }),

/**
The task user mentions that belong to the task.

@attribute taskUserMentions
@type Ember.computed
*/
taskUserMentions: hasMany('task-user-mention', { asnyc: true }),

/**
The project that the task belongs to

@attribute project
@type Ember.computed
*/
project: belongsTo('project', { async: true }),

/**
The user that the task belongs to

@attribute user
@type Ember.computed
*/
user: belongsTo('user', { async: true })
});
13 changes: 12 additions & 1 deletion mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function generatePreviewMentions(schema, preview) {

// The set of routes we have defined; needs updated when adding new routes
const routes = [
'categories', 'comment-user-mentions', 'comments', 'donation-goals', 'organizations',
'categories', 'comment-user-mentions', 'comments', 'donation-goals', 'organizations', 'task-lists',
'task-user-mentions', 'tasks', 'previews', 'projects', 'project-categories', 'slugged-routes',
'stripe-connect-accounts', 'stripe-connect-subscriptions', 'stripe-connect-plans',
'stripe-platform-cards', 'stripe-platform-customers',
Expand Down Expand Up @@ -427,6 +427,16 @@ export default function() {
this.post('/stripe-connect-subscriptions');
this.get('/stripe-connect-subscriptions/:id');

/**
* Task lists
*/

// GET /task-lists
this.get('/task-lists', { coalesce: true });

// GET /task-lists/:id
this.get('/task-lists/:id');

/**
* Task user mentions
*/
Expand Down Expand Up @@ -476,6 +486,7 @@ export default function() {
task.attrs = attrs;

task.taskUserMentions.models.forEach((mention) => mention.destroy());
task.order = (task.position || 0) * 100;
task.save();

return task;
Expand Down
10 changes: 10 additions & 0 deletions mirage/factories/task-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Factory } from 'ember-cli-mirage';

export default Factory.extend({
order() {
return (this.position || 0) * 100;
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make this multiplier significantly larger, like 100.

position(i) {
return i + 1;
}
});
6 changes: 6 additions & 0 deletions mirage/factories/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export default Factory.extend({
number(i) {
return i + 1;
},
order() {
return (this.position || 0) * 100;
},
position(i) {
return i + 1;
},
status: 'open',
taskType: faker.list.cycle('task', 'idea', 'issue'),
title() {
Expand Down
1 change: 1 addition & 0 deletions mirage/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
export default Model.extend({
donationGoals: hasMany(),
organization: belongsTo(),
taskLists: hasMany(),
tasks: hasMany(),
projectCategories: hasMany(),
projectSkills: hasMany(),
Expand Down
6 changes: 6 additions & 0 deletions mirage/models/task-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Model, belongsTo, hasMany } from 'ember-cli-mirage';

export default Model.extend({
project: belongsTo(),
tasks: hasMany()
});
1 change: 1 addition & 0 deletions mirage/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
export default Model.extend({
comments: hasMany(),
commentUserMentions: hasMany(),
taskList: belongsTo(),
taskUserMentions: hasMany(),
project: belongsTo(),
user: belongsTo()
Expand Down
42 changes: 39 additions & 3 deletions mirage/scenarios/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,45 @@ export default function(server) {
username: 'random'
});

server.createList('task', 10, { project, taskType: 'idea', user: owner });
server.createList('task', 10, { project, taskType: 'issue', user: owner });
server.createList('task', 10, { project, taskType: 'task', user: owner });
let inboxTaskList = server.create('taskList', {
name: 'Inbox',
position: 0,
project
});

let backlogTaskList = server.create('taskList', {
name: 'Backlog',
position: 1,
project
});

let inProgressTaskList = server.create('taskList', {
name: 'In Progress',
position: 2,
project
});

let doneTaskList = server.create('taskList', {
name: 'Done',
position: 3,
project
});

server.createList('task', 2, { project, taskList: inboxTaskList, taskType: 'idea', user: owner });
server.createList('task', 1, { project, taskList: inboxTaskList, taskType: 'issue', user: owner });
server.createList('task', 1, { project, taskList: inboxTaskList, taskType: 'task', user: owner });

server.createList('task', 1, { project, taskList: backlogTaskList, taskType: 'idea', user: owner });
server.createList('task', 1, { project, taskList: backlogTaskList, taskType: 'issue', user: owner });
server.createList('task', 2, { project, taskList: backlogTaskList, taskType: 'task', user: owner });

server.createList('task', 1, { project, taskList: inProgressTaskList, taskType: 'idea', user: owner });
server.createList('task', 3, { project, taskList: inProgressTaskList, taskType: 'issue', user: owner });
server.createList('task', 2, { project, taskList: inProgressTaskList, taskType: 'task', user: owner });

server.createList('task', 1, { project, taskList: doneTaskList, taskType: 'idea', user: owner });
server.createList('task', 1, { project, taskList: doneTaskList, taskType: 'issue', user: owner });
server.createList('task', 1, { project, taskList: doneTaskList, taskType: 'task', user: owner });

let skillTitles = ['CSS', 'Ember.js', 'HTML'];

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/models/project-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ moduleForModel('project', 'Unit | Model | project', {
'model:stripe-connect-account',
'model:stripe-connect-plan',
'model:task',
'model:task-list',
'model:user'
]
});
Expand All @@ -40,6 +41,7 @@ testForBelongsTo('project', 'stripeConnectPlan');
testForHasMany('project', 'donationGoals');
testForHasMany('project', 'projectCategories');
testForHasMany('project', 'projectSkills');
testForHasMany('project', 'taskLists');
testForHasMany('project', 'tasks');

test('it should have open tasks', function(assert) {
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/models/task-list-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { moduleForModel, test } from 'ember-qunit';
import { testForAttributes } from 'code-corps-ember/tests/helpers/attributes';
import { testForBelongsTo, testForHasMany } from '../../helpers/relationship';

moduleForModel('task-list', 'Unit | Model | task list', {
// Specify the other units that are required for this test.
needs: [
'model:project',
'model:task'
]
});

test('it exists', function(assert) {
let model = this.subject();
assert.ok(!!model);
});

testForAttributes('task-list', ['name', 'order', 'position']);
testForBelongsTo('task-list', 'project');
testForHasMany('task-list', 'tasks');
4 changes: 3 additions & 1 deletion tests/unit/models/task-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ moduleForModel('task', 'Unit | Model | task', {
'model:comment',
'model:comment-user-mention',
'model:project',
'model:task-list',
'model:task-user-mention',
'model:user'
]
Expand All @@ -18,8 +19,9 @@ test('it exists', function(assert) {
assert.ok(!!model);
});

testForAttributes('task', ['body', 'insertedAt', 'markdown', 'number', 'status', 'taskType', 'title']);
testForAttributes('task', ['body', 'insertedAt', 'markdown', 'number', 'order', 'position', 'status', 'taskType', 'title']);
testForBelongsTo('task', 'project');
testForBelongsTo('task', 'taskList');
testForBelongsTo('task', 'user');
testForHasMany('task', 'comments');
testForHasMany('task', 'commentUserMentions');
Expand Down
1 change: 1 addition & 0 deletions tests/unit/serializers/task-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ moduleForModel('task', 'Unit | Serializer | task', {
'model:user',
'model:comment',
'model:comment-user-mention',
'model:task-list',
'model:task-user-mention'
]
});
Expand Down