Skip to content

Commit 07dfa92

Browse files
committed
Fix issues during code review and merge conflicts with master
2 parents 0e3bba0 + 0b06476 commit 07dfa92

24 files changed

Lines changed: 1024 additions & 51 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.idea
22
node_modules
33
server/datasources.local.json
4-
server/model-config.local.json
4+
server/model-config.local.json

client/css/style.css

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,69 @@ header.carousel .fill {
119119
.txt-mbr-desc {
120120
font-size: 14px;
121121
}
122+
123+
/*---Learning Resource---*/
124+
/*Single ID*/
125+
.edit, .b-cancel, .b-update, .b-delete, .div-space-edit {
126+
display: none; /* Hides input box*/
127+
}
128+
.editing .b-edit, .editing .div-space-read {
129+
display: none; /* Hides styled text when .editing*/
130+
}
131+
.editing .b-update, .editing .b-delete, .editing .div-space-edit {
132+
display: block; /* Shows input text box when .editing*/
133+
}
134+
.editing .b-cancel, .editing .b-update {
135+
display: inline;
136+
}
137+
/*.vertical-center {
138+
min-height: 100%;
139+
min-height: 100vh;
140+
display: flex;
141+
align-items: center;
142+
}*/
143+
.sty-resource {
144+
text-transform: capitalize;
145+
}
146+
.sty-title {
147+
font-size: 1.5em;
148+
background: #4F4D4D;
149+
color: #FAFAFA;
150+
padding: 10px 20px;
151+
}
152+
.sty-desc {
153+
background: #F6F6F6;
154+
padding: 30px 20px;
155+
}
156+
.sty-authors {
157+
}
158+
.sty-resource-auth {
159+
font-size: .6em;
160+
color: #B7B7B7;
161+
}
162+
div[class^="div-space-edit"], .ctrl {
163+
margin: 20px 0;
164+
}
165+
div[class^="div-space-read"], .ctrl {
166+
margin: 0px 0;
167+
}
168+
div .txt-help {
169+
margin: 12px 0px;
170+
}
171+
.ctrl {
172+
margin: 30px 0px 20px 0px;
173+
}
174+
#msg {
175+
position: fixed;
176+
top: 10px;
177+
right: 10px;
178+
padding: 8px 12px;
179+
}
180+
.b-edit {
181+
float: right;
182+
margin-left: 10px;
183+
}
184+
.sty-form {
185+
background: #EFEFEF;
186+
padding: 30px;
187+
}

client/spa-index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<head lang="en">
44
<meta charset="UTF-8">
55
<title>SPA</title>
6+
<link rel="stylesheet" href="../css/bootstrap.min.css">
7+
<link rel="stylesheet" href="../css/style.css">
68
</head>
79
<body>
810
Hi, I'm the spa index from the spa folder.

client/spa/js/instructor/instructor.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var View = require('./instructor.view');
77

88
module.exports = Backbone.Controller.extend({
99
routes: {
10-
'instructor/:id': 'showInstructor'
10+
'instructors/:id': 'showInstructor'
1111
},
1212
initialize: function(){
1313
this.options.container = this.options.container || 'body';

client/spa/js/instructor/instructor.model.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ module.exports = Backbone.Model.extend({
1414
});
1515
},
1616
validate: function(attrs){
17+
var errors = [];
1718
if (!attrs.firstName){
18-
return 'firstName cannot be empty';
19+
errors.push('firstName cannot be empty');
1920
}
2021
if (!attrs.lastName){
21-
return 'lastName cannot be empty';
22+
errors.push('lastName cannot be empty');
2223
}
2324
if (!attrs.skills){
24-
return 'skills cannot be empty';
25+
errors.push('skills cannot be empty');
2526
}
27+
return errors;
2628
}
2729
});

client/spa/js/instructor/spec/instructor.controller.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Instructor controller', function(){
2525

2626
it('has the expected routes', function(){
2727
expect(controller.routes).toEqual(jasmine.objectContaining({
28-
'instructor/:id': 'showInstructor'
28+
'instructors/:id': 'showInstructor'
2929
}));
3030
});
3131

@@ -89,7 +89,7 @@ describe('Instructor controller', function(){
8989
expect($('body')).toHaveText(
9090
'There was a problem rendering this instructor');
9191
};
92-
controller.showInstructor(1, cb);
92+
controller.showInstructor('whatid', cb);
9393
});
9494
});
9595
});

client/spa/js/instructor/spec/instructor.model.spec.js

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,61 +17,116 @@ describe('Instructor model ', function(){
1717
model = new Model();
1818
});
1919

20-
xit('initializes with custom logic', function(){
20+
it('has the expected routes', function(){
21+
expect(model.urlRoot).toEqual('/api/instructors');
2122
});
2223
});
2324

24-
describe('when updating the model for instructor ', function(){
25+
describe('when updating the model for instructor with errorSpy ', function(){
2526
var errorSpy;
2627

2728
beforeEach(function(){
2829
errorSpy = jasmine.createSpy('Invalid');
2930
model = new Model({
30-
id: 1
31+
id: 1,
32+
firstName: 'Jeff',
33+
lastName: 'Thomas',
34+
skills: 'C++, Java'
3135
});
3236
model.on('invalid', errorSpy);
33-
model.save();
3437
});
3538

3639
it('does not save when firstName is empty ', function(){
40+
model.set('firstName', null);
41+
model.save();
3742
expect(errorSpy).toHaveBeenCalled();
38-
expect(errorSpy).toHaveBeenCalledWith(
39-
model,
40-
'firstName cannot be empty',
41-
{ validate: true, validationError: 'firstName cannot be empty'}
42-
);
43+
expect(errorSpy.calls.mostRecent().args[0]).toBe(model);
44+
expect(errorSpy.calls.mostRecent().args[1][0]).toEqual(
45+
'firstName cannot be empty');
4346
});
4447

45-
// Use if you have transformation logic on set
46-
xit('sets the values correctly ', function(){
47-
48+
it('does not save when lastName is empty ', function(){
49+
model.set('lastName', null);
50+
model.save();
51+
expect(errorSpy).toHaveBeenCalled();
52+
expect(errorSpy.calls.mostRecent().args[0]).toBe(model);
53+
expect(errorSpy.calls.mostRecent().args[1][0]).toEqual(
54+
'lastName cannot be empty');
4855
});
4956

50-
// Use if you have transformation logic on get
51-
xit('retrieves the correct values ', function(){
52-
57+
it('does not save when skills is empty ', function(){
58+
model.set('skills', null);
59+
model.save();
60+
expect(errorSpy).toHaveBeenCalled();
61+
expect(errorSpy.calls.mostRecent().args[0]).toBe(model);
62+
expect(errorSpy.calls.mostRecent().args[1][0]).toEqual(
63+
'skills cannot be empty');
5364
});
5465
});
5566

56-
describe('when changing the state of the model ', function(){
57-
var eventSpy;
67+
describe('when changing the state of the model without errorSpy', function(){
5868

5969
beforeEach(function(){
60-
eventSpy = jasmine.createSpy('Change Event');
70+
6171
model = new Model({
6272
id: 1,
6373
firstName: 'Mike',
64-
lastName: 'Foster'
74+
lastName: 'Foster',
75+
skills: 'reading'
6576
});
66-
model.on('foo', eventSpy);
67-
model.set({firstName: 'changed', lastName: 'changed'});
77+
78+
});
79+
80+
it('does not save when firstName is empty ', function(){
81+
model.set('firstName', null);
82+
model.save();
83+
expect(model.validationError).toEqual(['firstName cannot be empty']);
6884
});
6985

70-
it('triggers the custom event foo', function(){
71-
expect(eventSpy).toHaveBeenCalled();
72-
expect(eventSpy).toHaveBeenCalledWith(
73-
'bar'
74-
);
86+
it('does not save when firstName and lastName are empty ', function(){
87+
model.set('firstName', null);
88+
model.set('lastName', null);
89+
model.save();
90+
expect(model.validationError).toEqual(['firstName cannot be empty',
91+
'lastName cannot be empty']);
92+
});
93+
94+
it('does not save when firstName and skills are empty ', function(){
95+
model.set('firstName', null);
96+
model.set('skills', null);
97+
model.save();
98+
expect(model.validationError).toEqual(['firstName cannot be empty',
99+
'skills cannot be empty']);
100+
});
101+
102+
it('does not save when lastName is empty ', function(){
103+
model.set('lastName', null);
104+
model.save();
105+
expect(model.validationError).toEqual(['lastName cannot be empty']);
106+
});
107+
108+
it('does not save when lastName and skills are empty ', function(){
109+
model.set('lastName', null);
110+
model.set('skills', null);
111+
model.save();
112+
expect(model.validationError).toEqual(['lastName cannot be empty',
113+
'skills cannot be empty']);
114+
});
115+
116+
it('does not save when skills is empty ', function(){
117+
model.set('skills', null);
118+
model.save();
119+
expect(model.validationError).toEqual(['skills cannot be empty']);
120+
});
121+
122+
it('does not save when all fields are empty ', function(){
123+
model.set('firstName', null);
124+
model.set('lastName', null);
125+
model.set('skills', null);
126+
model.save();
127+
expect(model.validationError).toEqual(['firstName cannot be empty',
128+
'lastName cannot be empty',
129+
'skills cannot be empty']);
75130
});
76131
});
77132
});

client/spa/js/instructor/spec/instructor.view.spec.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,6 @@ describe('Instructor view ', function(){
103103

104104
});
105105

106-
xdescribe('when the user clicks on the Save button ', function(){
107-
xit('updates the model', function(){
108-
109-
});
110-
});
111-
112-
xdescribe('when the user clicks on ... ', function(){
113-
xit('triggers the ... event', function(){
114-
});
115-
});
116-
117106
}); // end edit/update test
118107

119108
describe('when the user clicks on the Delete button ', function(){
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
var Backbone = require('../vendor/index').Backbone;
4+
var $ = require('../vendor/index').$;
5+
var Model = require('./learning-resource.model');
6+
var View = require('./learning-resource.view');
7+
8+
module.exports = Backbone.Controller.extend({
9+
10+
routes: {
11+
'learning-resource/:id': 'showLearningResource'
12+
},
13+
14+
initialize: function(){
15+
this.options.container = this.options.container || 'body';
16+
},
17+
18+
initializeModel: function(attributes){
19+
this.model = new Model(attributes);
20+
this.view = new View({model: this.model});
21+
},
22+
23+
showLearningResource: function(learningResourceId){
24+
var self = this;
25+
var view = this.view;
26+
27+
//Ensures that what the view put in the DOM is removed and
28+
//any events the view had listenTo'd are removed.
29+
if (view) view.destroy();
30+
31+
this.initializeModel({id: learningResourceId});
32+
33+
this.model.fetch({
34+
success: function(){
35+
view = self.renderView();
36+
},
37+
error: function() {
38+
view = self.renderError();
39+
}
40+
});
41+
},
42+
43+
renderToContainer: function(view){
44+
return $(this.options.container).html(view);
45+
},
46+
47+
renderView: function(){
48+
this.renderToContainer(this.view.render().$el);
49+
return this.view;
50+
},
51+
52+
renderError: function(){
53+
return this.renderToContainer(
54+
'<p>There was a problem rendering this learning resource.</p>');
55+
}
56+
57+
});

0 commit comments

Comments
 (0)