Skip to content

Commit 7378b84

Browse files
committed
video 5
1 parent d183cf7 commit 7378b84

File tree

13 files changed

+102
-2
lines changed

13 files changed

+102
-2
lines changed

TodoListAPI/Repositories/TodoItemRepository.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Linq;
2+
using System.Threading.Tasks;
23
using JsonApiDotNetCore.Data;
34
using JsonApiDotNetCore.Services;
45
using Microsoft.Extensions.Logging;
@@ -29,5 +30,11 @@ public override IQueryable<TodoItem> Get()
2930
{
3031
return base.Get().Where(e => e.OwnerId == _authenticationService.GetUserId());
3132
}
33+
34+
public override async Task<TodoItem> CreateAsync(TodoItem todoItem)
35+
{
36+
todoItem.OwnerId = _authenticationService.GetUserId();
37+
return await base.CreateAsync(todoItem);
38+
}
3239
}
3340
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Ember from 'ember';
2+
3+
export default Ember.Component.extend({
4+
actions: {
5+
save() {
6+
this.get('saveAction')();
7+
}
8+
}
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<form {{action "save" on="submit"}}>
2+
{{input placeholder="description" value=todoItem.description}}
3+
<br />
4+
{{#if todoItem.validations.isValid}}
5+
<button type="submit">Add</button>
6+
{{else}}
7+
<button type="submit" disabled>Add</button>
8+
{{/if}}
9+
</form>

TodoListClient/app/models/todo-item.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import DS from 'ember-data';
2+
import { validator, buildValidations } from 'ember-cp-validations';
23

34
const { attr, belongsTo } = DS;
5+
const Validations = buildValidations({
6+
description: [
7+
validator('presence', true),
8+
validator('length', {
9+
min: 4
10+
})
11+
]
12+
});
413

5-
export default DS.Model.extend({
14+
export default DS.Model.extend(Validations, {
615

716
description: attr('string'),
817
owner: belongsTo('person')

TodoListClient/app/router.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const Router = Ember.Router.extend({
99
Router.map(function() {
1010
this.route('login');
1111
this.route('s', function() {
12-
this.route('todo-items');
12+
this.route('todo-items', function() {
13+
this.route('add');
14+
});
1315
});
1416
});
1517

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Ember from 'ember';
2+
import DataRoute from 'ember-data-route';
3+
4+
export default Ember.Route.extend(DataRoute, {
5+
model() {
6+
return this.store.createRecord('todo-item');
7+
},
8+
9+
actions: {
10+
save() {
11+
this.get('controller.model')
12+
.save()
13+
.then(() => {
14+
this.transitionTo('s.todo-items');
15+
});
16+
}
17+
},
18+
19+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{{login-buttons}}
2+
<br />
23
{{outlet}}
34
{{ember-notify}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{forms/todo-item-form
2+
todoItem=model
3+
saveAction=(route-action "save")}}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{#link-to "s.todo-items.add"}}Add{{/link-to}}
2+
<br />
13
{{#each model as |todoItem|}}
24
{{todoItem.description}} <br />
35
{{/each}}

TodoListClient/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@
3131
"ember-cli-sri": "^2.1.0",
3232
"ember-cli-test-loader": "^1.1.0",
3333
"ember-cli-uglify": "^1.2.0",
34+
"ember-cp-validations": "3.2.4",
3435
"ember-data": "^2.11.0",
36+
"ember-data-route": "0.2.0",
3537
"ember-export-application-global": "^1.0.5",
3638
"ember-load-initializers": "^0.6.0",
3739
"ember-notify": "5.2.1",
3840
"ember-resolver": "^2.0.3",
41+
"ember-route-action-helper": "2.0.2",
3942
"ember-simple-auth": "1.2.0",
4043
"ember-source": "^2.11.0",
4144
"ember-welcome-page": "^2.0.2",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { moduleForComponent, test } from 'ember-qunit';
2+
import hbs from 'htmlbars-inline-precompile';
3+
4+
moduleForComponent('forms/todo-item-form', 'Integration | Component | forms/todo item form', {
5+
integration: true
6+
});
7+
8+
test('it renders', function(assert) {
9+
10+
// Set any properties with this.set('myProperty', 'value');
11+
// Handle any actions with this.on('myAction', function(val) { ... });
12+
13+
this.render(hbs`{{forms/todo-item-form}}`);
14+
15+
assert.equal(this.$().text().trim(), '');
16+
17+
// Template block usage:
18+
this.render(hbs`
19+
{{#forms/todo-item-form}}
20+
template block text
21+
{{/forms/todo-item-form}}
22+
`);
23+
24+
assert.equal(this.$().text().trim(), 'template block text');
25+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { moduleFor, test } from 'ember-qunit';
2+
3+
moduleFor('route:s/todo-items/add', 'Unit | Route | s/todo items/add', {
4+
// Specify the other units that are required for this test.
5+
// needs: ['controller:foo']
6+
});
7+
8+
test('it exists', function(assert) {
9+
let route = this.subject();
10+
assert.ok(route);
11+
});

0 commit comments

Comments
 (0)