Skip to content

Commit

Permalink
Integrated Courses Final Inscription New (#118)
Browse files Browse the repository at this point in the history
* Integrated Courses Final Inscription New

Add Delete Final Modal to Courses Show
  • Loading branch information
MatiasMercado committed Feb 5, 2017
1 parent d6af4e5 commit 3d4af22
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 23 deletions.
43 changes: 30 additions & 13 deletions app/scripts/controllers/courses/CoursesFinalInscriptionNewCtrl.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
'use strict';

define(['paw'], function(paw) {
paw.controller('CoursesFinalInscriptionNewCtrl', ['$routeParams', '$window', '$filter', function($routeParams, $window, $filter) {
define(['paw', 'services/Courses', 'services/flashMessages'], function(paw) {
paw.controller('CoursesFinalInscriptionNewCtrl',
['$routeParams', 'Courses', '$window', '$filter', 'flashMessages', '$log', '$route', 'Paths',
function($routeParams, Courses, $window, $filter, flashMessages, $log, $route, Paths) {

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

this.currentDate = new Date();

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

this.new = function(finalInscription) {
// Make Api request
var parsedDate = $filter('date')(finalInscription.finalExamDate, 'yyyy-MM-ddTHH:mm:ss');
_this.errors = [];
var newFinalInscription = angular.copy(finalInscription);
newFinalInscription.finalExamDate = $filter('date')(finalInscription.finalExamDate, 'yyyy-MM-ddTHH:mm:ss');
Courses.newFinalInscription(this.courseId, newFinalInscription).then(function(response) {
flashMessages.setSuccess('i18nFinalSuccessfullyCreated');
Paths.get().courses(_this.course).go();
}, function(response) {

$log.warn(JSON.stringify(response));
flashMessages.setError('i18nFormErrors');
$route.reload();
});
};

this.cancel = function() {
$window.history.back();
};

this.currentDate = new Date();

this.course = {
courseId: '72.03',
credits: 3,
name: 'Introducción a Informática',
semester: 1
};
}]);
});
8 changes: 1 addition & 7 deletions app/scripts/controllers/courses/CoursesShowCtrl.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
'use strict';

define(['paw','services/Courses','services/Paths', 'controllers/modals/DeleteCorrelativeController'], function(paw) {
define(['paw','services/Courses','services/Paths', 'controllers/modals/DeleteCorrelativeController', 'controllers/modals/DeleteFinalController'], function(paw) {
paw.controller('CoursesShowCtrl', ['$routeParams', 'Courses', '$log', 'Paths', function($routeParams, Courses, $log, Paths) {
var _this = this;
var courseId = $routeParams.courseId;

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;
};

Courses.get(courseId).then(function(course) {
_this.course = course;
Courses.setOnSubSidebar(course);
Expand Down
73 changes: 73 additions & 0 deletions app/scripts/controllers/modals/DeleteFinalController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';

define(['paw', 'services/modalFactory', 'services/Courses', 'services/flashMessages'], function(paw) {
paw.controller('DeleteFinalController',
['modalFactory', '$log', 'Courses', '$route', 'flashMessages',
function (modalFactory, $log, Courses, $route, flashMessages) {
var modalTemplateUrl = 'views/modals/delete_final.html';
var onSuccess = function(result) {
Courses.deleteFinalInscription(result.courseId, result.id)
.then(function(response) {
flashMessages.setSuccess('i18nDeleteFinalSuccess');
$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, courseId, courseName, finalExamDate, id) {
var resolve = getResolve(title, courseId, courseName, finalExamDate, id);
modalFactory.create(size, 'DeleteFinalModalInstanceController', modalTemplateUrl, resolve, onSuccess, onFailure);
};
}]);

paw.controller('DeleteFinalModalInstanceController',
function($uibModalInstance, title, courseId, courseName, finalExamDate, id) {
this.title = title;
this.courseId = courseId;
this.courseName = courseName;
this.finalExamDate = finalExamDate;
this.id = id;

var _this = this;

this.ok = function () {
$uibModalInstance.close({
courseId: courseId,
courseName: courseName,
finalExamDate: finalExamDate,
id: id
});
};

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

function getResolve(title, courseId, courseName, finalExamDate, id) {
return {
title: function() {
return title;
},
courseId: function () {
return courseId;
},
courseName: function () {
return courseName;
},
finalExamDate: function () {
return finalExamDate;
},
id: function() {
return id;
}
};
};
}
);
7 changes: 6 additions & 1 deletion app/scripts/i18n/translations.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ define([], function() {
i18nCourseApproved: 'Historial de aprobados',
i18nCourseAddCorrelative: 'Agregar correlativa',
i18nCourseDelete: 'Eliminar',
i18nFinalDelete: 'Eliminar',

// Tables common headers
i18nActions: 'Acciones',
Expand Down Expand Up @@ -152,6 +153,7 @@ define([], function() {
i18nCourseSuccessfullyCreated: 'El curso se ha creado exitosamente',
i18nCourseSuccessfullyUpdated: 'El curso se ha editado exitosamente',
i18nInvalidBirthday: 'La fecha debe ser anterior a la fecha actual',
i18nInvalidFinalExamDate: 'La fecha del examen debe ser posterior a la fecha actual',

// Final Exams
i18nFinalExams: 'Exámenes Finales',
Expand Down Expand Up @@ -189,10 +191,12 @@ define([], function() {
i18nModalCourseId: 'Código del curso',
i18nModalCorrelativeName: 'Nombre de la correlativa',
i18nModalCorrelativeId: 'Código de la correlativa',
i18nModalStudentFullName: 'Nombre del estudiante',
i18nModalStudentFullName: 'Nombre del alumno',
i18nModalDeleteFinal: 'Eliminar examen final',

// Flash messages
i18nEditSuccess: 'La edición ha sido exitosa',
i18nDeleteFinalSuccess: 'Se ha eliminado el examen final',
i18nDeleteCorrelativeSuccess: 'Se ha eliminado la correlatividad',
i18nAddCorrelativeSuccess: 'Se ha agregado la correlatividad',
i18nEnrollSuccess: 'Se ha agregado la inscripción',
Expand All @@ -202,6 +206,7 @@ define([], function() {
i18nFormErrors: 'Hay errores en los datos ingresados',
i18nSuccess: '¡Éxito! - ',
i18nError: '¡Error! - ',
i18nFinalSuccessfullyCreated: 'Se ha creado la inscripción',
i18nPasswordResetSuccess: 'La contraseña ha sido reseteada exitosamente',
i18nInvalidUsernameOrPassword: 'Usuario y/o contraseña incorrecta',
i18nStudentSuccessfullyCreated: 'El alumno se ha creado exitosamente',
Expand Down
12 changes: 12 additions & 0 deletions app/scripts/services/Courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ define(['paw', 'services/AuthenticatedRestangular', 'services/navDataService'],
return originalCourse.customPOST(editedCourse);
};

rest.newFinalInscription = function(courseId, finalInscription) {
var body = {
finalExamDate: finalInscription.finalExamDate,
maxVacancy: finalInscription.vacancy
};
return rest.one('courses', courseId).all('finalInscriptions').customPOST(body);
};

rest.deleteFinalInscription = function(courseId, id) {
return rest.one('courses', courseId).one('finalInscriptions', id).customDELETE();
};

return rest;
}]);
});
5 changes: 4 additions & 1 deletion app/views/courses/final_inscriptions_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ <h2 class='inline'>
(<span class='text-danger' translate='i18nRequiredIcon'/>)
</label>
<input type='datetime-local' name='finalExamDate' id='finalExamDate' class='form-input-field' ng-model='controller.finalInscription.finalExamDate' required min='{{controller.currentDate}}' placeholder="{{ 'i18nfinalExamDatePlaceholder' | translate}}"/>
<div ng-messages='form.finalExamDate.$error' ng-show='form.finalExamDate.$touched || form.$submitted' class='form-errors' role='alert' ng-messages-multiple>
<div ng-messages='form.finalExamDate.$error' ng-show='form.finalExamDate.$touched || form.$submitted' class='form-errors' role='alert'>
<div ng-message='required'>
<p translate='i18nRequiredField'></p>
</div>
<div ng-message='min'>
<p translate='i18nInvalidDate'></p>
</div>
<div ng-message='date'>
<p translate='i18nInvalidFormatDate'></p>
</div>
</div>
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion app/views/courses/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h3 translate='i18nFinalExams' class='page-sub-header'></h3>
<td colspan='4' class='text-danger text-center' translate='i18nNoFinalExamsFound'></td>
</tr>
<tr ng-repeat='inscription in controller.course.finalInscriptions'>
<td>{{controller.formatDate(inscription.finalExamDate)}}</td>
<td>{{inscription.finalExamDate | date: 'dd/MM/yyyy HH:mm'}}</td>
<td>{{ inscription.vacancy }}/{{ inscription.maxVacancy }}</td>
<td ng-show="inscription.state == 'OPEN'" translate='i18nInscriptionOpen'></td>
<td ng-show="inscription.state == 'CLOSED'" translate='i18nInscriptionClosed'></td>
Expand All @@ -99,6 +99,11 @@ <h3 translate='i18nFinalExams' class='page-sub-header'></h3>
<span class='fa fa-info-circle' aria-hidden='true'></span>
<span translate='i18nInformation'></span>
</a>
<a class='btn btn-danger' role='button' ng-controller='DeleteFinalController as modalController'
ng-click="modalController.open('md', 'i18nFinalDelete', controller.course.courseId, controller.course.name, inscription.finalExamDate, inscription.id)">
<span class='fa fa-trash' aria-hidden='true'></span>
<span translate='i18nFinalDelete'></span>
</a>
</td>
</tr>
</tbody>
Expand Down
18 changes: 18 additions & 0 deletions app/views/modals/delete_final.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class='modal-header'>
<h4 class='modal-title' id='modal-title' translate='i18nModalDeleteFinal'></h4>
</div>
<div class='modal-body'>
<p class='break-words'>
<span class='bold' translate='i18nModalCourseId'></span>: {{ controller.courseId }}
</p>
<p class='break-words'>
<span class='bold' translate='i18nModalCourseName'></span>: {{ controller.courseName }}
</p>
<p class='break-words'>
<span class='bold' translate='i18nFinalExamDate'></span>: {{ controller.finalExamDate | date: 'dd/MM/yyyy HH:mm'}}
</p>
</div>
<div class='modal-footer'>
<button class='btn btn-default' type='button' ng-click="controller.cancel()" translate='i18nCancel'></button>
<button class='btn btn-danger' type='button' ng-click='controller.ok()' translate='i18nConfirm'></button>
</div>
4 changes: 4 additions & 0 deletions app/views/students/final_inscriptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h3 translate='i18nFinalExams' class='page-sub-header'></h3>
<table class='table table-hover'>
<thead>
<tr>
<th translate='i18nCourse'></th>
<th translate='i18nFinalExamDate'></th>
<th translate='i18nVacancy'></th>
<th translate='i18nState'></th>
Expand All @@ -30,6 +31,7 @@ <h3 translate='i18nFinalExams' class='page-sub-header'></h3>
<td colspan='4' class='text-danger text-center' translate='i18nNoFinalExamsFound'></td>
</tr>
<tr ng-repeat='inscription in controller.student.finalInscriptionsAvailable'>
<td>{{inscription.name}}</td>
<td>{{inscription.finalExamDate | date: 'dd/MM/yyyy HH:mm'}}</td>
<td>{{ inscription.vacancy }}/{{ inscription.maxVacancy }}</td>
<td ng-show="inscription.state == 'OPEN'" translate='i18nInscriptionOpen'></td>
Expand Down Expand Up @@ -57,6 +59,7 @@ <h3 translate='i18nFinalExamsTaken' class='page-sub-header'></h3>
<table class='table table-hover'>
<thead>
<tr>
<th translate='i18nCourse'></th>
<th translate='i18nFinalExamDate'></th>
<th translate='i18nVacancy'></th>
<th translate='i18nState'></th>
Expand All @@ -68,6 +71,7 @@ <h3 translate='i18nFinalExamsTaken' class='page-sub-header'></h3>
<td colspan='4' class='text-danger text-center' translate='i18nNoFinalExamsFound'></td>
</tr>
<tr ng-repeat='inscription in controller.student.finalInscriptionsTaken'>
<td>{{inscription.name}}</td>
<td>{{inscription.finalExamDate | date: 'dd/MM/yyyy HH:mm'}}</td>
<td>{{ inscription.vacancy }}/{{ inscription.maxVacancy }}</td>
<td ng-show="inscription.state == 'OPEN'" translate='i18nInscriptionOpen'></td>
Expand Down

0 comments on commit 3d4af22

Please sign in to comment.