Skip to content
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

Issue 168 #173

Merged
merged 3 commits into from
Mar 20, 2018
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<p>
course-detail works!
</p>

<div id="courseDetail" *ngIf="course">
<h2 id="detailHeading">
{{course.department_code}} {{course.number}}: {{course.name}} Details
Expand Down Expand Up @@ -48,8 +44,8 @@ <h2 id="detailHeading">
<div id="buttonHolder">
<!-- These are intentionally left without a (click) function
for now, TODO implement functionality -->
<button class="btn btn-search" id="save">Save Changes</button>
<button class="btn btn-search" id="cancel">Cancel</button>
<button class="btn btn-search" id="save" (click)="saveCourse()">Save Changes</button>
<button class="btn btn-search" id="cancel" (click)="goBack()">Cancel</button>
</div>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,40 @@ describe('CourseDetailComponent', () => {
expect(descElem.getAttribute('ng-reflect-model')).toMatch(component.course.description.substr(0, 30));
});

describe('when save button pressed', ()=>{
beforeEach(async()=>{
let saveBtn=document.getElementById('save');
saveBtn.click();
spyOn(component, 'saveCourse');
});

it('should call saveCourse()', async()=>{
fixture.whenStable().then(()=>{
expect(component.saveCourse).toHaveBeenCalled();``
});
});

});


describe('when cancel button pressed', ()=>{
beforeEach(async()=>{
let cancelBtn=document.getElementById('cancel');
cancelBtn.click();
});

beforeEach(async()=>{
spyOn(component, 'goBack');
});

it('should call goBack()', async()=>{
fixture.whenStable().then(()=>{
expect(component.goBack).toHaveBeenCalled();
});
});

});

});

});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Course} from '../course';
import {Department} from '../../department/department';
import {YacsService} from '../../services/yacs.service';
import {ActivatedRoute, Router} from '@angular/router';
import {Location} from '@angular/common';
@Component({
selector: 'app-course-detail',
templateUrl: './course-detail.component.html',
Expand All @@ -11,7 +12,7 @@ import {ActivatedRoute, Router} from '@angular/router';
export class CourseDetailComponent implements OnInit {
@Input() course: Course;
depts: Department[];
constructor(private yacsService: YacsService, private route: ActivatedRoute) { }
constructor(private yacsService: YacsService, private route: ActivatedRoute, private router: Router, private location: Location) { }

ngOnInit() {
let id: number;
Expand All @@ -33,4 +34,15 @@ export class CourseDetailComponent implements OnInit {

//}

saveCourse(){
this.yacsService.updateCourse(this.course)
.subscribe(()=> this.goBack());
this.getCourse();
}
goBack(){
this.location.back();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,39 @@ <h2 *ngIf="selectedDept">Courses in the {{selectedDept.name}} Department</h2>
<tr>
<th class="id">ID</th>
<th>Name</th>
<th class="code" *ngIf="!selectedDept">Dept.</th>
<th class="code">Number</th>
<th class="id" *ngIf="!selectedDept">Dept.</th>
<th class="id">Number</th>
<!--<%if show_school_id%><th>School ID</th><%end%>-->
<th class="code">Credits</th>
<!--<th></th>-->
<th class="id">Credits</th>

<th class="id">Actions</th>
<th class="id"></th>

<th class="id"></th>

</tr>
</thead>

<tbody>
<tr *ngFor="let course of courses" [class.selected]="course === selectedCourse" (click)="onSelect(course)">
<td class="id">{{course.id}}</td>
<td>{{course.name}}</td>
<td class="code" *ngIf="!selectedDept">{{getCourseDeptCode(course)}}</td>
<td class="code">{{course.number}}</td>
<td class="code">{{creditRange(course)}}</td>
<td >{{course.name}}</td>
<td class="id" *ngIf="!selectedDept">{{getCourseDeptCode(course)}}</td>
<td class="id">{{course.number}}</td>
<td class="id">{{creditRange(course)}}</td>
<td class="id" style="text-align: center !important;"><a routerLink="{{course.id}}">Details</a></td>
<td class="id" style="text-align: center !important;"><a routerLink="/sections" [queryParams]="{course_id: course.id }">Show Sections</a></td>
<td class="id" style="text-align: center !important;"><a class="delete" >Delete</a></td>
</tr>

</tbody>
</table>
<ng-template #nocourses><div id="no-courses" *ngIf="!courses">
<p>There are currently no courses under this department.</p>
</ng-template>
</div>

</ng-template> <!-- This actually should be here,
I incorrectly thought it should be further down-->

<div *ngIf="selectedDept">
<p><a href="/departments">Back to departments</a></p>
Expand Down
7 changes: 6 additions & 1 deletion yacs-admin-angular/src/app/services/fake-yacs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ export class FakeYacsService implements YacsService{
//return of(COURSES.filter(course => course.department_id === dept_id));

}

updateCourse(course: Course): Observable<any>{
return this.http.put(this.coursesUrl, course, cudOptions).pipe(
tap(_=>console.log(course),
catchError(this.handleError<any>('updateCourse')))
);
}

getDeptsBySchoolID(school_id: number): Observable<Department[]>{
return this.http.get<Department[]>(this.deptsUrl)
Expand Down
7 changes: 6 additions & 1 deletion yacs-admin-angular/src/app/services/yacs-prod.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ export class YacsProdService implements YacsService{
});

}

updateCourse(course: Course): Observable<any>{
return this.http.put(this.baseUrl+'/courses', course, cudOptions).pipe(
tap(_=> console.log(course)),
catchError(this.handleError<any>('updateCourse'))
);
}
getCoursesByDeptID(dept_id: number): Observable<Course[]>{
return this.http.get<Course[]>(this.baseUrl+'/courses', {
params: new HttpParams().set('department_id', String(dept_id))
Expand Down
4 changes: 3 additions & 1 deletion yacs-admin-angular/src/app/services/yacs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export abstract class YacsService {

abstract getCourses(): Observable<Course[]>;
abstract getCoursesByDeptID(dept_id: number): Observable<Course[]>;

//PUT method for courses
abstract updateCourse(course: Course): Observable<any>;

abstract getSections(): Observable<Section[]>;
abstract getSectionByID(id: number): Observable<Section>;
abstract getSectionsByCourseID(course_id: number): Observable<Section[]>;
Expand Down