Skip to content

Commit

Permalink
API Students Inscriptions (#115)
Browse files Browse the repository at this point in the history
Integrate Courses Students Index

Integrated Students Passed Index

Integrated Courses Final Inscriptions Show

Clean Code

Add courseName to FinalInscriptionIndexDTO

Integrated Students Final Inscriptions Index

Unify Enroll & Unenroll Modal
  • Loading branch information
MatiasMercado committed Feb 5, 2017
1 parent 9bb30a5 commit a58c5ac
Show file tree
Hide file tree
Showing 23 changed files with 478 additions and 309 deletions.
70 changes: 18 additions & 52 deletions app/scripts/controllers/courses/CoursesFinalInscriptionShowCtrl.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,28 @@
'use strict';

define(['paw'], function(paw) {
paw.controller('CoursesFinalInscriptionShowCtrl', ['$routeParams', function($routeParams) {
define(['paw','services/Courses','services/Paths'], function(paw) {
paw.controller('CoursesFinalInscriptionShowCtrl', ['$routeParams', 'Courses', '$log', 'Paths', function($routeParams, Courses, $log, Paths) {

var _this = this;
var courseId = $routeParams.courseId;
var inscriptionId = $routeParams.inscriptionId;

this.formatDate = function(finalExamDate) {
var date = finalExamDate.split('T')[0];
var time = finalExamDate.split('T')[1];
return date.split('-')[2] + '/' + date.split('-')[1] + '/' + date.split('-')[0] + ' ' + time;
};

this.course = {
courseId: '72.03',
credits: 3,
name: 'Introducción a Informática',
semester: 1,
inscription: {
id: '1',
courseId: '93.42',
vacancy: '12',
maxVacancy: '50',
finalExamDate: '2017-01-20T18:45',
state: 'OPEN',
students: [
{
firstName: 'Matías',
lastName: 'Mercado',
docket: '55019'
},
{
firstName: 'Facundo',
lastName: 'Mercado',
docket: '51202'
},
{
firstName: 'Gibar',
lastName: 'Sin',
docket: '54655'
},
{
firstName: 'Obi Wan',
lastName: 'Kenobi',
docket: '12000'
},
{
firstName: 'Darth',
lastName: 'Vader',
docket: '66666'
},
{
firstName: 'Luke',
lastName: 'Skywalker',
docket: '53222'
}
]
Courses.get(courseId).then(function(course) {
_this.course = course;
_this.course.all('finalInscriptions').get(inscriptionId).then(function(finalInscription) {
_this.course.inscription = finalInscription;
_this.course.inscription.students = finalInscription.history;
});
}, function(response) {
$log.info('Response status: ' + response.status);
if (response.status === 404) {
Paths.get().notFound().go();
}
});

this.getStudentPath = function(docket) {
return Paths.get().students({docket: docket}).path;
};

}]);
});
17 changes: 7 additions & 10 deletions app/scripts/controllers/courses/CoursesShowCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ define(['paw','services/Courses','services/Paths', 'controllers/modals/DeleteCor
return date.split('-')[2] + '/' + date.split('-')[1] + '/' + date.split('-')[0] + ' ' + time;
};

this.getCorrelativePath = function(correlativeId) {
return Paths.get().courses({courseId: correlativeId}).path;
};
this.getFinalInscriptionPath = function(finalInscriptionId) {
return Paths.get().courses({courseId: courseId}).finals({inscriptionId: finalInscriptionId}).path;
};

Courses.get(courseId).then(function(course) {
_this.course = course;
Courses.setOnSubSidebar(course);
Expand All @@ -34,8 +27,12 @@ define(['paw','services/Courses','services/Paths', 'controllers/modals/DeleteCor
}
});

// this.getFinalInscriptionPath = function(finalInscriptionId) {
// return Paths.get().courses({courseId: courseId}).path;
// };
this.getCorrelativePath = function(correlativeId) {
return Paths.get().courses({courseId: correlativeId}).path;
};
this.getFinalInscriptionPath = function(finalInscriptionId) {
return Paths.get().courses({courseId: courseId}).finals({inscriptionId: finalInscriptionId}).path;
};

}]);
});
78 changes: 28 additions & 50 deletions app/scripts/controllers/courses/CoursesStudentsIndexCtrl.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,34 @@
'use strict';

define(['paw'], function(paw) {
paw.controller('CoursesStudentsIndexCtrl', ['$routeParams', function($routeParams) {
define(['paw','services/Courses','services/Paths', 'controllers/modals/UnenrollController'], function(paw) {
paw.controller('CoursesStudentsIndexCtrl', ['$routeParams', 'Courses', '$log', 'Paths', function($routeParams, Courses, $log, Paths) {
var _this = this;
var courseId = $routeParams.courseId; // For future Service calls
var courseId = $routeParams.courseId;

this.course = {
courseId: '72.03',
name: 'Introducción a Informática',
credits: 3,
semester: 1,
students: [
{
firstName: 'Matías',
lastName: 'Mercado',
docket: '55019'
},
{
firstName: 'Facundo',
lastName: 'Mercado',
docket: '51202'
},
{
firstName: 'Gibar',
lastName: 'Sin',
docket: '54655'
},
{
firstName: 'Obi Wan',
lastName: 'Kenobi',
docket: '12000'
},
{
firstName: 'Darth',
lastName: 'Vader',
docket: '66666'
},
{
firstName: 'Luke',
lastName: 'Skywalker',
docket: '53222'
}]
};
this.filter = {
docket: $routeParams.docket,
firstName: $routeParams.firstName,
lastName: $routeParams.lastName
};

this.filter = {
docket: $routeParams.docket,
firstName: $routeParams.firstName,
lastName: $routeParams.lastName
};
this.resetSearch = function() {
this.filter = {};
};

this.resetSearch = function() {
this.filter = {};
};
}]);
});
Courses.get(courseId).then(function(course) {
_this.course = course;
_this.course.getList('students').then(function(students) {
_this.course.students = students;
});
}, function(response) {
$log.info('Response status: ' + response.status);
if (response.status === 404) {
Paths.get().notFound().go();
}
});

this.getStudentPath = function(docket) {
return Paths.get().students({docket: docket}).path;
};
}]);
});
84 changes: 28 additions & 56 deletions app/scripts/controllers/courses/CoursesStudentsPassedCtrl.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,34 @@
'use strict';

define(['paw'], function(paw) {
paw.controller('CoursesStudentsPassedCtrl', ['$routeParams', function($routeParams) {
define(['paw','services/Courses','services/Paths'], function(paw) {
paw.controller('CoursesStudentsPassedCtrl', ['$routeParams', 'Courses', '$log', 'Paths', function($routeParams, Courses, $log, Paths) {
var _this = this;
var courseId = $routeParams.courseId; // For future Service calls
var courseId = $routeParams.courseId;

this.course = {
courseId: '72.03',
name: 'Introducción a Informática',
credits: 3,
semester: 1,
passedStudents: [
{
grade: '4',
firstName: 'Matías',
lastName: 'Mercado',
docket: '55019'
},
{
grade: '10',
firstName: 'Facundo',
lastName: 'Mercado',
docket: '51202'
},
{
grade: '9.50',
firstName: 'Gibar',
lastName: 'Sin',
docket: '54655'
},
{
grade: '8.50',
firstName: 'Obi Wan',
lastName: 'Kenobi',
docket: '12000'
},
{
grade: '10',
firstName: 'Darth',
lastName: 'Vader',
docket: '66666'
},
{
grade: '8',
firstName: 'Luke',
lastName: 'Skywalker',
docket: '53222'
}]
};
this.filter = {
docket: $routeParams.docket,
firstName: $routeParams.firstName,
lastName: $routeParams.lastName
};

this.filter = {
docket: $routeParams.docket,
firstName: $routeParams.firstName,
lastName: $routeParams.lastName
};
this.resetSearch = function() {
this.filter = {};
};

this.resetSearch = function() {
this.filter = {};
};
}]);
});
Courses.get(courseId).then(function(course) {
_this.course = course;
_this.course.all('students').customGET('passed').then(function(students) {
_this.course.passedStudents = students;
});
}, function(response) {
$log.info('Response status: ' + response.status);
if (response.status === 404) {
Paths.get().notFound().go();
}
});

this.getStudentPath = function(docket) {
return Paths.get().students({docket: docket}).path;
};
}]);
});
75 changes: 75 additions & 0 deletions app/scripts/controllers/modals/EnrollController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';

define(['paw', 'services/modalFactory', 'services/Students', 'services/flashMessages'], function(paw) {
paw.controller('EnrollController',
['modalFactory', '$log', 'Students', '$route', 'flashMessages',
function (modalFactory, $log, Students, $route, flashMessages) {
var modalTemplateUrl = 'views/modals/enroll.html';
var onSuccess = function(result) {
Students.enroll(result.docket, result.courseId)
.then(function(response) {
flashMessages.setSuccess('i18nEnrollSuccess');
$route.reload();
}, function(response) {
flashMessages.setError('i18nFormErrors');
$log.warn('[ERROR] - Response: ' + JSON.stringify(response));
$route.reload();
});
};

var onFailure = function(msg) {
$log.info(msg);
};

this.open = function (size, title, docket, fullName, courseName, courseId) {
var resolve = getResolve(title, docket, fullName, courseId, courseName);
modalFactory.create(size, 'EnrollModalInstanceController', modalTemplateUrl, resolve, onSuccess, onFailure);
};
}]);

paw.controller('EnrollModalInstanceController',
function($uibModalInstance, title, docket, fullName, courseId, courseName) {
this.title = title;
this.fullName = fullName;
this.docket = docket;
this.courseId = courseId;
this.courseName = courseName;

var _this = this;

this.ok = function () {
$uibModalInstance.close({
title: title,
docket: docket,
fullName: fullName,
courseId: courseId,
courseName: courseName
});
};

this.cancel = function () {
$uibModalInstance.dismiss('Enroll modal dismissed at: ' + new Date());
};
});

function getResolve(title, docket, fullName, courseId, courseName) {
return {
title: function() {
return title;
},
docket: function () {
return docket;
},
fullName: function() {
return fullName;
},
courseId: function () {
return courseId;
},
courseName: function () {
return courseName;
}
};
};
}
);
Loading

0 comments on commit a58c5ac

Please sign in to comment.