diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index a8f8d25..94d91ce 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts @@ -20,8 +20,10 @@ import { ExpandableListModule } from 'angular2-expandable-list'; import { AttendanceListComponent } from './pages/attendance-list/attendance-list.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MaterialModule } from './material.module'; -import { NgxSpinnerModule } from 'ngx-spinner'; +import { NgxSpinnerModule } from 'ngx-spinner'; +import { MatDialogModule } from '@angular/material/dialog'; +import { Dialog } from './components/dialog/dialog'; @NgModule({ declarations: [ @@ -37,7 +39,8 @@ import { NgxSpinnerModule } from 'ngx-spinner'; TeacherAttendancePageComponent, ManageClassesComponent, AttendanceListComponent, - AddStudentSingleClassComponent + AddStudentSingleClassComponent, + Dialog, ], imports: [ BrowserModule, @@ -47,8 +50,14 @@ import { NgxSpinnerModule } from 'ngx-spinner'; BrowserAnimationsModule, MaterialModule, NgxSpinnerModule, + MatDialogModule, + ], + entryComponents: [ + Dialog + ], + providers: [ + // {provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {hasBackdrop: false}} ], - providers: [], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/client/src/app/components/dialog/dialog.html b/client/src/app/components/dialog/dialog.html new file mode 100644 index 0000000..101ebea --- /dev/null +++ b/client/src/app/components/dialog/dialog.html @@ -0,0 +1,11 @@ +

Escolha os alunos para adicionar

+
+ + + {{student.Name}} + + +
+ + +
\ No newline at end of file diff --git a/client/src/app/components/dialog/dialog.ts b/client/src/app/components/dialog/dialog.ts new file mode 100644 index 0000000..59d9ee2 --- /dev/null +++ b/client/src/app/components/dialog/dialog.ts @@ -0,0 +1,40 @@ +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; +import { Component, Inject } from '@angular/core'; +import { AuthService} from '../../services/auth.service'; + +@Component({ + selector: 'dialog-overview-example-dialog', + templateUrl: './dialog.html', +}) +export class Dialog { + + toAddList = {}; + + constructor( + public dialogRef: MatDialogRef, + private service: AuthService, + @Inject(MAT_DIALOG_DATA) public data: any) { } + + cancelClicked(): void { + this.dialogRef.close(); + } + + addClicked() { + this.dialogRef.close(); + const keys = Object.keys(this.toAddList); + keys.forEach(key => { + if (this.toAddList[key].selected) { + const request = { + turma: this.data.turmaId, + pessoa: key, + }; + this.service.postNewAlunoInTurma(request).subscribe(() => console.log(`${key} sent`)); + } + }); + } + + onSelection(selected) { + this.toAddList[selected.option.value.id] = { selected: selected.option.selected, id: selected.option.value.id }; + console.log('list: ', this.toAddList); + } +} diff --git a/client/src/app/pages/manage-classes-page/manage-classes-page.component.css b/client/src/app/pages/manage-classes-page/manage-classes-page.component.css index 1eec99e..f37b08e 100644 --- a/client/src/app/pages/manage-classes-page/manage-classes-page.component.css +++ b/client/src/app/pages/manage-classes-page/manage-classes-page.component.css @@ -52,69 +52,16 @@ font-size: 20px; } +.delete-button { + color: gray; + background-color: transparent; + border: none; + margin-left: 40px; +} -/* header {} - h2 { - text-align: center; - margin: 0; - padding: 0; - display: block; - color: #ffffff; - background-color: rgb(57, 86, 148); - - } - - h4 { - text-align: center; - margin: 0; - padding: 0; - display: block; - color: black; - background: rgb(225, 226, 227); - - } - - button { - margin: 4px auto; - font-family: Arial; - background-color: #e1e2e3; - border: none; - padding: auto; - border-radius: 0; - cursor: pointer; - cursor: hand; - float: left; - font-size: medium; - } - - button:hover { - background-color: #cfd8dc; - } - - - body {} - - ul { - margin: 0 auto; - padding: 0; - padding: 5px 5px 0 5px; - border-left: none; - border-right: none; - border: 1px solid rgba(0, 0, 0, 0.1); - } - button.card { - border: 1px solid #CCC; - box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.5); - margin-bottom: 5px; - width: 100%; - box-sizing: border-box; - cursor: pointer; - border-radius: 3px; - - } - - span.data { - position: relative; - } - - */ \ No newline at end of file +.add-button { + color: gray; + background-color: transparent; + border: none; + margin-right: 40px; +} \ No newline at end of file diff --git a/client/src/app/pages/manage-classes-page/manage-classes-page.component.html b/client/src/app/pages/manage-classes-page/manage-classes-page.component.html index 44904ac..5559c97 100644 --- a/client/src/app/pages/manage-classes-page/manage-classes-page.component.html +++ b/client/src/app/pages/manage-classes-page/manage-classes-page.component.html @@ -1,9 +1,3 @@ - -
-
- {{c.Name}} -
-
- - - -
+
+
+ + + + + Turma {{turma.Turma.Name}} + + + + + +
+ + {{student.Name}} + +
+ +
+
+
+
\ No newline at end of file diff --git a/client/src/app/pages/manage-classes-page/manage-classes-page.component.ts b/client/src/app/pages/manage-classes-page/manage-classes-page.component.ts index f318178..09bb4ef 100644 --- a/client/src/app/pages/manage-classes-page/manage-classes-page.component.ts +++ b/client/src/app/pages/manage-classes-page/manage-classes-page.component.ts @@ -1,5 +1,8 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, Inject } from '@angular/core'; import { AuthService} from '../../services/auth.service'; +import { NgxSpinnerService } from 'ngx-spinner'; +import { MatDialog } from '@angular/material/dialog'; +import { Dialog } from '../../components/dialog/dialog'; @Component({ selector: 'app-manage-classes', @@ -8,20 +11,74 @@ import { AuthService} from '../../services/auth.service'; }) export class ManageClassesComponent implements OnInit { - listaCurso: Array = []; + courseList: Array = []; + studentList: Array = []; TEACHER_ID = 6; // should get user ID from service singleton - constructor(private service: AuthService) { } + expansionAux = -1; + constructor(private service: AuthService, private spinner: NgxSpinnerService, public dialog: MatDialog) { } ngOnInit() { - // load spinner + this.spinner.show(undefined, + { + type: 'line-scale-party', + size: 'medium', + bdColor: 'transparent', + color: 'yellow', + fullScreen: false + } + ); this.getCursos(); } // Calls service to get "cursos" getCursos(): void { - this.service.getTurmasDoColaborador(this.TEACHER_ID).subscribe((cursos) => { - this.listaCurso = cursos; - console.log('Cursos: ', cursos); + this.service.getTurmasDoColaborador(this.TEACHER_ID).subscribe((courses) => { + this.courseList = courses; + console.log('Cursos: ', this.courseList) + this.spinner.hide(); + }); + } + + expandCollapse(courseId: number) { + return courseId === this.expansionAux; + } + + populateStudents(turma) { + this.expansionAux = turma.id; + Object.assign(this.studentList, turma.Alunos, {}); + } + + removeStudent(student, turma) { + this.service.removeAlunoFromTurma(turma.id, student.id).subscribe((res) => { + const {status } = res; + if (status === 200 ) { + this.studentList = this.studentList.filter((value) => value.id !== student.id); + } + }); + } + + showAddStudent(classId: number) { + this.spinner.show(); + this.service.getAllAlunos().subscribe((alunos) => { + const allStudents = alunos; + console.log('All Students: ', allStudents); + this.studentList.map((student, index) => allStudents.splice(index, 1)); + this.spinner.hide(); + + const dialogRef = this.dialog.open(Dialog, { + maxWidth: '290px', + height: '500px', + data: { + students: allStudents, + turmaId: classId, + }, + }); + dialogRef.afterClosed().subscribe(result => { + console.log('The dialog was closed'); + console.log('This All Students: ', allStudents); + this.getCursos(); + this.expansionAux = -1; + }); }); } } diff --git a/client/src/app/pages/manage-classes-page/teste.json b/client/src/app/pages/manage-classes-page/teste.json new file mode 100644 index 0000000..948a962 --- /dev/null +++ b/client/src/app/pages/manage-classes-page/teste.json @@ -0,0 +1,42 @@ +{ + "turma": { + "id": 1, + "Name": "Turma Teste 1", + "Place": "Campinas", + "Description": "Primeira turma pra teste", + "WeekDay": 4, + "StartTime": "20:56:43", + "EndTime": "00:00:00", + "Cursos": 1, + "Alunos": [ + 2, + 3, + 4 + ], + "Aulas": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 11, + 12, + 13 + ] + }, + "aluno": { + "Ativo": true, + "Email": "rotiv@gmail.com", + "EndDate": "2019-06-13", + "Name": "Rotiv", + "Password": "abc123", + "Phone": "1932622407", + "StartDate": "2019-06-10", + "UserType": 0, + "id": 9 + } +} \ No newline at end of file diff --git a/client/src/app/services/auth.service.ts b/client/src/app/services/auth.service.ts index eb02b5d..44ceeaa 100644 --- a/client/src/app/services/auth.service.ts +++ b/client/src/app/services/auth.service.ts @@ -60,13 +60,12 @@ export class AuthService { getAllTurmasDoColaborador() { return this.http.get(`${this.url}/colaboradorTurma`); - } - getAllTurmas(): Observable{ + getAllTurmas(): Observable { return this.http.get(`${this.url}/turma`); } - + getAllAulas(): Observable{ return this.http.get(`${this.url}/aulas`); } @@ -98,4 +97,13 @@ export class AuthService { postNewAlunoInAula(bodyObj){ return this.http.post(`${this.url}/pessoaAula/`, bodyObj, this.httpOptions); } -} \ No newline at end of file + + removeAlunoFromTurma(turmaId, alunoId) { + return this.http.delete(`${this.url}/pessoaTurma/${alunoId}/${turmaId}`, {...this.httpOptions, observe: 'response' }); + } + + postNewAlunoInTurma(bodyObj) { + return this.http.post(`${this.url}/pessoaTurma2/`, bodyObj, this.httpOptions); + } + +} diff --git a/server/djangular/db.sqlite3 b/server/djangular/db.sqlite3 index 94db86e..49f1b02 100644 Binary files a/server/djangular/db.sqlite3 and b/server/djangular/db.sqlite3 differ diff --git a/server/djangular/djangular/__pycache__/__init__.cpython-37.pyc b/server/djangular/djangular/__pycache__/__init__.cpython-37.pyc index a778b02..423c050 100644 Binary files a/server/djangular/djangular/__pycache__/__init__.cpython-37.pyc and b/server/djangular/djangular/__pycache__/__init__.cpython-37.pyc differ diff --git a/server/djangular/djangular/__pycache__/settings.cpython-37.pyc b/server/djangular/djangular/__pycache__/settings.cpython-37.pyc index 4bd90dd..30cfada 100644 Binary files a/server/djangular/djangular/__pycache__/settings.cpython-37.pyc and b/server/djangular/djangular/__pycache__/settings.cpython-37.pyc differ diff --git a/server/djangular/djangular/__pycache__/urls.cpython-37.pyc b/server/djangular/djangular/__pycache__/urls.cpython-37.pyc index adecbea..54a9ecc 100644 Binary files a/server/djangular/djangular/__pycache__/urls.cpython-37.pyc and b/server/djangular/djangular/__pycache__/urls.cpython-37.pyc differ diff --git a/server/djangular/djangular/__pycache__/wsgi.cpython-37.pyc b/server/djangular/djangular/__pycache__/wsgi.cpython-37.pyc index cc49e95..b0446de 100644 Binary files a/server/djangular/djangular/__pycache__/wsgi.cpython-37.pyc and b/server/djangular/djangular/__pycache__/wsgi.cpython-37.pyc differ diff --git a/server/djangular/serve/__pycache__/__init__.cpython-37.pyc b/server/djangular/serve/__pycache__/__init__.cpython-37.pyc index 961d8f9..85bc4bc 100644 Binary files a/server/djangular/serve/__pycache__/__init__.cpython-37.pyc and b/server/djangular/serve/__pycache__/__init__.cpython-37.pyc differ diff --git a/server/djangular/serve/__pycache__/admin.cpython-37.pyc b/server/djangular/serve/__pycache__/admin.cpython-37.pyc index 81ded6a..e3c3c42 100644 Binary files a/server/djangular/serve/__pycache__/admin.cpython-37.pyc and b/server/djangular/serve/__pycache__/admin.cpython-37.pyc differ diff --git a/server/djangular/serve/__pycache__/api.cpython-37.pyc b/server/djangular/serve/__pycache__/api.cpython-37.pyc index 8a3a815..f7964d1 100644 Binary files a/server/djangular/serve/__pycache__/api.cpython-37.pyc and b/server/djangular/serve/__pycache__/api.cpython-37.pyc differ diff --git a/server/djangular/serve/__pycache__/models.cpython-37.pyc b/server/djangular/serve/__pycache__/models.cpython-37.pyc index b4ca0a5..e579c09 100644 Binary files a/server/djangular/serve/__pycache__/models.cpython-37.pyc and b/server/djangular/serve/__pycache__/models.cpython-37.pyc differ diff --git a/server/djangular/serve/__pycache__/serializers.cpython-37.pyc b/server/djangular/serve/__pycache__/serializers.cpython-37.pyc index d23d7fc..f3a1c72 100644 Binary files a/server/djangular/serve/__pycache__/serializers.cpython-37.pyc and b/server/djangular/serve/__pycache__/serializers.cpython-37.pyc differ diff --git a/server/djangular/serve/__pycache__/urls.cpython-37.pyc b/server/djangular/serve/__pycache__/urls.cpython-37.pyc index cef1ec8..4caf689 100644 Binary files a/server/djangular/serve/__pycache__/urls.cpython-37.pyc and b/server/djangular/serve/__pycache__/urls.cpython-37.pyc differ diff --git a/server/djangular/serve/api.py b/server/djangular/serve/api.py index 1bc0de3..a3efdfd 100644 --- a/server/djangular/serve/api.py +++ b/server/djangular/serve/api.py @@ -148,4 +148,42 @@ class TurmaProfessorAPI(generics.ListAPIView): queryset = Turma.objects.all() filter_backends = (DjangoFilterBackend,) filterset_fields = ('Aluno.id',) - serializer_class = GetTurmaSerializer \ No newline at end of file + serializer_class = GetTurmaSerializer + +class UpdatePessoaTurmaAPI(generics.RetrieveDestroyAPIView): + serializer_class = TurmaSerializer + def delete(self, request, alunoId, turmaId): + table = Turma.Alunos.through.objects.filter(turma_id=turmaId, pessoa_id=alunoId) + if not table: + return Response(data={ + "message": "Verique as informações passadas" + }, status=status.HTTP_400_BAD_REQUEST) + table.delete() + return Response('Aluno deletado com sucesso!') + def post (self, request, alunoId, turmaId): + turma = Turma.objects.filter(id = turmaId) + aluno = Pessoa.objects.filter(id = alunoId) + if not aluno: + return Response(data={ + "message": "Aluno não encontrado" + }, status=status.HTTP_400_BAD_REQUEST) + if not turma: + return Response(data={ + "message": "Aluno não encontrado" + }, status=status.HTTP_400_BAD_REQUEST) + # table = Turma.Alunos.through.objects.filter(turma_id=turmaId, pessoa_id=alunoId) + turma.Alunos.add(aluno) + return Response(data={ + "message": "Relação pessoa/turma criada com sucesso!" + }, status=status.HTTP_201_CREATED) + +class newPessoaTurma(viewsets.ModelViewSet): + queryset = PessoaAula.objects.all() + serializer_class = TurmaAulaSerializer + + def get_serializer_class(self): + method = self.request.method + if method == 'PUT' or method == 'POST': + return TurmaAulaSerializer + else: + return TurmaAulaSerializer diff --git a/server/djangular/serve/migrations/__pycache__/0001_initial.cpython-37.pyc b/server/djangular/serve/migrations/__pycache__/0001_initial.cpython-37.pyc index a003c2a..08efabc 100644 Binary files a/server/djangular/serve/migrations/__pycache__/0001_initial.cpython-37.pyc and b/server/djangular/serve/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/server/djangular/serve/migrations/__pycache__/0002_auto_20190503_2245.cpython-37.pyc b/server/djangular/serve/migrations/__pycache__/0002_auto_20190503_2245.cpython-37.pyc index 97ea399..1c92daa 100644 Binary files a/server/djangular/serve/migrations/__pycache__/0002_auto_20190503_2245.cpython-37.pyc and b/server/djangular/serve/migrations/__pycache__/0002_auto_20190503_2245.cpython-37.pyc differ diff --git a/server/djangular/serve/migrations/__pycache__/0003_aula_curso.cpython-37.pyc b/server/djangular/serve/migrations/__pycache__/0003_aula_curso.cpython-37.pyc index ea618c8..59e3063 100644 Binary files a/server/djangular/serve/migrations/__pycache__/0003_aula_curso.cpython-37.pyc and b/server/djangular/serve/migrations/__pycache__/0003_aula_curso.cpython-37.pyc differ diff --git a/server/djangular/serve/migrations/__pycache__/0004_auto_20190608_1909.cpython-37.pyc b/server/djangular/serve/migrations/__pycache__/0004_auto_20190608_1909.cpython-37.pyc index df4ddd9..3298245 100644 Binary files a/server/djangular/serve/migrations/__pycache__/0004_auto_20190608_1909.cpython-37.pyc and b/server/djangular/serve/migrations/__pycache__/0004_auto_20190608_1909.cpython-37.pyc differ diff --git a/server/djangular/serve/migrations/__pycache__/0005_auto_20190608_1913.cpython-37.pyc b/server/djangular/serve/migrations/__pycache__/0005_auto_20190608_1913.cpython-37.pyc index 97872c4..07f133e 100644 Binary files a/server/djangular/serve/migrations/__pycache__/0005_auto_20190608_1913.cpython-37.pyc and b/server/djangular/serve/migrations/__pycache__/0005_auto_20190608_1913.cpython-37.pyc differ diff --git a/server/djangular/serve/migrations/__pycache__/0006_auto_20190608_1914.cpython-37.pyc b/server/djangular/serve/migrations/__pycache__/0006_auto_20190608_1914.cpython-37.pyc index 8759b79..d3d8741 100644 Binary files a/server/djangular/serve/migrations/__pycache__/0006_auto_20190608_1914.cpython-37.pyc and b/server/djangular/serve/migrations/__pycache__/0006_auto_20190608_1914.cpython-37.pyc differ diff --git a/server/djangular/serve/migrations/__pycache__/__init__.cpython-37.pyc b/server/djangular/serve/migrations/__pycache__/__init__.cpython-37.pyc index 7907ec3..b7ed161 100644 Binary files a/server/djangular/serve/migrations/__pycache__/__init__.cpython-37.pyc and b/server/djangular/serve/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/server/djangular/serve/serializers.py b/server/djangular/serve/serializers.py index 5498f84..6f4c8da 100644 --- a/server/djangular/serve/serializers.py +++ b/server/djangular/serve/serializers.py @@ -31,6 +31,11 @@ class Meta: model = Turma fields = '__all__' +class TurmaAulaSerializer(serializers.ModelSerializer): + class Meta: + model = Turma.Alunos.through + fields = '__all__' + class GetTurmaSerializer(serializers.ModelSerializer): class Meta: model = Turma diff --git a/server/djangular/serve/urls.py b/server/djangular/serve/urls.py index 4e26391..9b1c899 100644 --- a/server/djangular/serve/urls.py +++ b/server/djangular/serve/urls.py @@ -19,5 +19,7 @@ url(r'^alunosDaAula/(?P.+)$', GetAlunosDaAulaAPI.as_view()), # url(r'^updatePessoaAula/(?P.+)/(?P.+)/(?P.+)$', UpdatePessoaAulaAPI.as_view()), path('colaboradorTurma/', ColaboradorTurmaAPIALL.as_view()), - url(r'^colaboradorTurma/(?P.+)$', ColaboradorTurmaAPI.as_view()), + url(r'^colaboradorTurma/(?P.+)$', ColaboradorTurmaAPI.as_view()), + url(r'^pessoaTurma/(?P.+)/(?P.+)$', UpdatePessoaTurmaAPI.as_view()), + url(r'^pessoaTurma2/$', newPessoaTurma.as_view({'post':'create', 'get':'list'})), ]