Skip to content
This repository was archived by the owner on Jun 18, 2019. It is now read-only.

Commit cf5eec6

Browse files
committed
feature(validation): Validate modal
Adiciona validacao no modal de cursoi #14
1 parent 3c8c85e commit cf5eec6

File tree

4 files changed

+52
-41
lines changed

4 files changed

+52
-41
lines changed

Angular_Seed_Project/models/cursos.js

+32-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
var mongoose = require('mongoose');
22

33
var cursoSchema = new mongoose.Schema({
4-
nome: String,
5-
descricao: String,
6-
local: String,
7-
data_inicio: Date,
8-
data_fim: Date,
9-
data_limite_inscricao: Date,
10-
min_inscritos: Number,
11-
max_inscritos: Number,
4+
nome: {
5+
type: String,
6+
required: true
7+
},
8+
descricao: {
9+
type: String,
10+
required: true
11+
},
12+
local: {
13+
type: String,
14+
required: true
15+
},
16+
data_inicio: {
17+
type: Date,
18+
required: true
19+
},
20+
data_fim: {
21+
type: Date,
22+
required: false
23+
},
24+
data_limite_inscricao: {
25+
type: Date,
26+
required: true
27+
},
28+
min_inscritos: {
29+
type: Number,
30+
required: true
31+
},
32+
max_inscritos: {
33+
type: Number,
34+
required: false
35+
},
1236
created_by: String,
1337
instrutor: Object,
1438
carga_horaria: Number,

Angular_Seed_Project/page/modais/modalUniversidade.html

+13-12
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ <h4 class="modal-title">Crie e Edite o curso desejado</h4>
55
<small class="font-bold">Universidade Certsys fortalece as bases acadêmicas e técnicas.</small>
66
</div>
77
<div class="modal-body">
8-
<form method="get" class="form-horizontal">
8+
<form name="cursoForm" ng-submit="cursoForm.$validate && salvar()" class="form-horizontal">
99
<div class="col-sm-12 text-center"><h3>Dados Gerais do Curso</h3></div>
1010
<div class="form-group"><label class="col-sm-2 control-label">Título:</label>
1111
<div class="col-sm-10"><input type="text" ng-model="titulo" placeholder="Ferramenta e nível da aula..."
12-
class="form-control">
12+
class="form-control" required>
1313
</div>
1414
</div>
1515

1616
<div class="form-group"><label class="col-sm-2 control-label">Descrição:</label>
17-
<div class="col-sm-10"><input type="text" ng-model="descricao" placeholder="Diretrizes gerais..." class="form-control">
17+
<div class="col-sm-10"><input type="text" ng-model="descricao" placeholder="Diretrizes gerais..." class="form-control" required>
1818
</div>
1919
</div>
2020

2121
<div class="form-group"><label class="col-sm-2 control-label">Local:</label>
22-
<div class="col-sm-10"><input type="text" ng-model="local" placeholder="Defina o local do curso..." class="form-control">
22+
<div class="col-sm-10"><input type="text" ng-model="local" placeholder="Defina o local do curso..." class="form-control" required>
2323
</div>
2424
</div>
2525

@@ -34,20 +34,20 @@ <h4 class="modal-title">Crie e Edite o curso desejado</h4>
3434
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
3535
<input id="data-inicio" watch-direct-changes="true" type="text" date-time="diaInicio" data-ng-model="diaInicio"
3636
format="DD/MM/YYYY" view="date" min-view="date" auto-close="true"
37-
class="ng-pristine ng-valid ng-scope ng-touched form-control">
37+
class="ng-pristine ng-valid ng-scope ng-touched form-control" required>
3838
<!--<input type="text" class="form-control" data-ng-model="programado.checkOut" name="programado" date-time required min="{{ today | date: 'yyyy-MM-dd' }}" view="date" auto-close="true" min-view="date" format="DD/MM/YYYY">-->
3939
</div>
4040

4141
<div class="col-sm-2 input-group-2 date">
42-
<input ng-model="horarioInicio" type="text" clock-picker class="form-control">
42+
<input ng-model="horarioInicio" type="text" clock-picker class="form-control" required>
4343
<!--<input type="text" class="form-control" data-ng-model="programado.checkOut" name="programado" date-time required min="{{ today | date: 'yyyy-MM-dd' }}" view="date" auto-close="true" min-view="date" format="DD/MM/YYYY">-->
4444
</div>
4545

4646
<label class="col-sm-2 control-label"> às </label>
4747

4848
<div class="col-sm-2 input-group-2 date">
4949
<input ng-model="horarioFim" type="text" clock-picker
50-
class="form-control">
50+
class="form-control" required>
5151
<!--<input type="text" class="form-control" data-ng-model="programado.checkOut" name="programado" date-time required min="{{ today | date: 'yyyy-MM-dd' }}" view="date" auto-close="true" min-view="date" format="DD/MM/YYYY">-->
5252
</div>
5353

@@ -57,7 +57,7 @@ <h4 class="modal-title">Crie e Edite o curso desejado</h4>
5757
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
5858
<input id="data-limite-inscricao" type="text" date-time="" data-ng-model="dataLimiteInscricao"
5959
format="DD/MM/YYYY HH:mm" view="date" min-view="hours" auto-close="true"
60-
class="ng-pristine ng-valid ng-scope ng-touched form-control">
60+
class="ng-pristine ng-valid ng-scope ng-touched form-control" required>
6161
<!--<input type="text" class="form-control" data-ng-model="programado.checkOut" name="programado" date-time required min="{{ today | date: 'yyyy-MM-dd' }}" view="date" auto-close="true" min-view="date" format="DD/MM/YYYY">-->
6262
</div>
6363
</div>
@@ -66,14 +66,14 @@ <h4 class="modal-title">Crie e Edite o curso desejado</h4>
6666
<div class="col-sm-12 text-center"><h3>Mínimo e Máximo de Alunos</h3></div>
6767
<div class="form-group"><label class="col-sm-2 control-label">Mín:</label>
6868
<div class="col-sm-10">
69-
<h-number value="minInscritos" min="2" step="1"
69+
<h-number value="minInscritos" min="1" step="1"
7070
change="onChangeMinimo()"></h-number>
7171
</div>
7272

7373
</div>
7474
<div class="form-group"><label class="col-sm-2 control-label">Max:</label>
7575
<div class="col-sm-10">
76-
<h-number value="maxInscritos" min="2" step="1"
76+
<h-number value="maxInscritos" min="1" step="1"
7777
change="onChangeMaximo()"></h-number>
7878
</div>
7979
</div>
@@ -82,7 +82,7 @@ <h4 class="modal-title">Crie e Edite o curso desejado</h4>
8282
<div class="form-group"><label class="col-sm-2 control-label">Instrutor:</label>
8383
<div class="col-sm-10">
8484
<input type="text" placeholder="Quem irá ministrar..." class="form-control" ng-model="selected"
85-
typeahead="contato as (contato.nome) for contato in contatos | filter:{nome: $viewValue}"/>
85+
typeahead="contato as (contato.nome) for contato in contatos | filter:{nome: $viewValue}" required/>
8686
</div>
8787
</div>
8888

@@ -95,7 +95,8 @@ <h4 class="modal-title">Crie e Edite o curso desejado</h4>
9595
<button type="button" class="btn btn-white" ng-click="cancel()"><i class="fa fa-times"></i> Fechar </button>
9696
<button type="button" class="btn btn-danger" ng-show="isCreated()" ng-click="remove()"><i class="fa fa-trash"></i> Remover Curso </button>
9797
<button type="button" class="btn btn-primary" ng-show="isCreated()" ng-click="gerenciar()"><i class="fa fa-pencil"></i> Gerenciar Curso </button>
98-
<button type="button" class="btn btn-success" ng-click="salvar()"><i class="fa fa-floppy-o"></i> Salvar Curso </button>
98+
<!--<button type="submit" class="btn btn-success" ng-click="salvar()"><i class="fa fa-floppy-o"></i> Salvar Curso </button>-->
99+
<button type="submit" class="btn btn-success" ng-click="salvar()"><i class="fa fa-floppy-o"></i> Salvar Curso </button>
99100
</div>
100101
</div>
101102

Angular_Seed_Project/page/modais/modaluniversidade.controller.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ function ModalInstanceCtrl($scope, $modalInstance, $http, userService, getCurso,
2121
method: "GET",
2222
params: {token: userService.getToken(), mail: getCurso.instrutor.sAMAccountName}
2323
}).then(function (response) {
24-
//your code in case the post succeeds
25-
// console.log(response.data.lenght > 0);
24+
2625
$scope.titulo = getCurso.nome;
2726
$scope.descricao = getCurso.descricao;
2827
$scope.local = getCurso.local;
@@ -35,6 +34,7 @@ function ModalInstanceCtrl($scope, $modalInstance, $http, userService, getCurso,
3534
$scope.horarioFim = data_fim.getHours() + ":" + data_fim.getMinutes();
3635
$scope.dataLimiteInscricao = new Date(getCurso.data_limite_inscricao);
3736
$scope.selected = response.data[0];
37+
3838
}).catch(function (err) {
3939
// console.log(err);
4040
});
@@ -120,6 +120,7 @@ function ModalInstanceCtrl($scope, $modalInstance, $http, userService, getCurso,
120120
carga_horaria: $scope.cargaHoraria
121121
};
122122

123+
console.log($scope.data_inicio, $scope.dataLimiteInscricao)
123124

124125
if ($scope.editar) {
125126
$http({
@@ -128,8 +129,6 @@ function ModalInstanceCtrl($scope, $modalInstance, $http, userService, getCurso,
128129
, data: data
129130
, params: {token: userService.getToken()}
130131
}).then(function (response) {
131-
//your code in case the post succeeds
132-
// console.log(response);
133132
swal({
134133
title: "Sucesso!",
135134
text: "Seu curso foi editado com sucesso!",
@@ -139,16 +138,14 @@ function ModalInstanceCtrl($scope, $modalInstance, $http, userService, getCurso,
139138
universidadeService.sendSalvou(true);
140139
$modalInstance.close();
141140
setTimeout(function () {
142-
// after 1500ms, reloads the page to refresh the courses table
143141
location.reload()
144142
}, 1000);
145-
146143
}
147144
)
148145
.catch(function (err) {
149-
//your code in case your post fails
150-
// console.log(err);
146+
console.log(err);
151147
});
148+
152149
} else {
153150
$http({
154151
method: 'POST'
@@ -170,12 +167,10 @@ function ModalInstanceCtrl($scope, $modalInstance, $http, userService, getCurso,
170167
// after 1500ms, reloads the page to refresh the courses table
171168
location.reload()
172169
}, 1000);
173-
174170
}
175171
)
176172
.catch(function (err) {
177-
//your code in case your post fails
178-
// console.log(err);
173+
console.log(err);
179174
});
180175
}
181176
};

Angular_Seed_Project/page/universidade/universidade.controller.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function universidade($scope, $http, userService, $state, universidadeService, $
213213
};
214214

215215
$scope.allowSubscription = function (curso) {
216-
if (curso.inscritos.length >= curso.max_inscritos) return false;
216+
if (curso.inscritos.length > curso.max_inscritos) return false;
217217
else if ($scope.status(curso) !== INSCRICOES_ABERTAS) return false;
218218
return true;
219219
};
@@ -227,14 +227,6 @@ function universidade($scope, $http, userService, $state, universidadeService, $
227227
tecnico: userService.Authenticate().tecnico,
228228
instructors: userService.Authenticate().instructors
229229
};
230-
231-
// $scope.myFilter = function (selectedStatus, cursos) {
232-
// if (!cursos) return;
233-
// console.log(selectedStatus);
234-
// console.log(cursos);
235-
// return cursos
236-
// }
237-
238230
}
239231

240232
function cursoStatusFilter () {
@@ -250,7 +242,6 @@ function cursoStatusFilter () {
250242
}
251243
});
252244
});
253-
//console.log(tempClients)
254245
return filtredCursos;
255246

256247
} else {

0 commit comments

Comments
 (0)