From ef5e2f6cfb7f33ac8b6ab0b3d557749828e0b965 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 14 May 2022 17:42:27 +0200 Subject: [PATCH] Add feature to assign user to course, add date editing support It seems like the button click event doesn't work in an ngFor. That took a while to debug --- .../src/graphql-resolvers/course.resolver.ts | 9 +++++++ .../app/auth/register/register.component.ts | 13 +++++----- frontend/src/app/graphql/course.graphql | 4 +++ .../edit/edit.component.html | 4 ++- .../shared-components/edit/edit.component.ts | 2 +- .../shared-components.module.ts | 4 ++- .../table/table.component.html | 9 ++++--- .../table/table.component.ts | 3 +++ .../course-edit/course-edit.component.html | 7 ++--- .../course-edit/course-edit.component.ts | 9 +++++-- frontend/src/app/subjects/subjects.module.ts | 4 ++- .../assign-to-course.component.css | 0 .../assign-to-course.component.html | 6 +++++ .../assign-to-course.component.spec.ts | 25 ++++++++++++++++++ .../assign-to-course.component.ts | 26 +++++++++++++++++++ frontend/src/app/users/users.module.ts | 4 ++- 16 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 frontend/src/app/users/assign-to-course/assign-to-course.component.css create mode 100644 frontend/src/app/users/assign-to-course/assign-to-course.component.html create mode 100644 frontend/src/app/users/assign-to-course/assign-to-course.component.spec.ts create mode 100644 frontend/src/app/users/assign-to-course/assign-to-course.component.ts diff --git a/backend/src/graphql-resolvers/course.resolver.ts b/backend/src/graphql-resolvers/course.resolver.ts index 44e10ea..2c130e1 100644 --- a/backend/src/graphql-resolvers/course.resolver.ts +++ b/backend/src/graphql-resolvers/course.resolver.ts @@ -40,4 +40,13 @@ export class CourseResolver { await this.courseRepo.create(input); return true; } + + @mutation(returns => Boolean) + async courseAssignUser(@arg('course', returns => ID) course: number, @arg('user', returns => ID) user: number, @arg('role') role: string): Promise { + if (role !== 'teacher' && role !== 'student') { + throw new Error('Érvénytelen szerepkör'); + } + await this.courseRepo.users(course).link(user, {throughData: {role: role}}); + return true; + } } diff --git a/frontend/src/app/auth/register/register.component.ts b/frontend/src/app/auth/register/register.component.ts index 49dfcea..d9e0163 100644 --- a/frontend/src/app/auth/register/register.component.ts +++ b/frontend/src/app/auth/register/register.component.ts @@ -1,8 +1,8 @@ -import {Component, OnInit} from '@angular/core'; -import {AbstractControl, FormControl, ValidationErrors, Validators} from '@angular/forms'; -import {LoginService} from '../login.service'; -import {Router} from '@angular/router'; -import {FormErrorStateMatcher} from '../../utility/form-error-state-matcher'; +import { Component, OnInit } from '@angular/core'; +import { AbstractControl, FormControl, ValidationErrors, Validators } from '@angular/forms'; +import { LoginService } from '../login.service'; +import { Router } from '@angular/router'; +import { FormErrorStateMatcher } from '../../utility/form-error-state-matcher'; @Component({ selector: 'app-register', @@ -74,8 +74,7 @@ export class RegisterComponent implements OnInit { try { await this.loginService.createUser(this.emailFormControl.value, this.passFormControl.value, this.nameFormControl.value); await this.router.navigate(['/']); - } catch (e) { - alert(e); + } catch (e) { // A GraphQL már kiirja } } diff --git a/frontend/src/app/graphql/course.graphql b/frontend/src/app/graphql/course.graphql index e2a0cc0..5e4c599 100644 --- a/frontend/src/app/graphql/course.graphql +++ b/frontend/src/app/graphql/course.graphql @@ -35,3 +35,7 @@ mutation EditCourse($input: CourseUpdateInput!) { mutation CreateCourse($input: CourseCreateInput!) { courseCreate(course: $input) } + +mutation CourseAssignUser($user: ID!, $course: ID!, $role: String!) { + courseAssignUser(user: $user, course: $course, role: $role) +} diff --git a/frontend/src/app/shared-components/edit/edit.component.html b/frontend/src/app/shared-components/edit/edit.component.html index c25105c..39bff6a 100644 --- a/frontend/src/app/shared-components/edit/edit.component.html +++ b/frontend/src/app/shared-components/edit/edit.component.html @@ -13,7 +13,9 @@ - + + + diff --git a/frontend/src/app/shared-components/edit/edit.component.ts b/frontend/src/app/shared-components/edit/edit.component.ts index 524c2eb..73bc333 100644 --- a/frontend/src/app/shared-components/edit/edit.component.ts +++ b/frontend/src/app/shared-components/edit/edit.component.ts @@ -15,7 +15,7 @@ export class EditComponent, UT extend implements OnInit { item?: T; - @Input() creating = false; + creating = false; isLoading = true; @Input() gql: Query; diff --git a/frontend/src/app/shared-components/shared-components.module.ts b/frontend/src/app/shared-components/shared-components.module.ts index 055796e..97c3e76 100644 --- a/frontend/src/app/shared-components/shared-components.module.ts +++ b/frontend/src/app/shared-components/shared-components.module.ts @@ -14,6 +14,7 @@ import { MatInputModule } from '@angular/material/input'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatTooltipModule } from '@angular/material/tooltip'; import { MatDatepickerModule } from '@angular/material/datepicker'; +import { MatNativeDateModule } from '@angular/material/core'; @NgModule({ @@ -35,7 +36,8 @@ import { MatDatepickerModule } from '@angular/material/datepicker'; MatInputModule, MatCheckboxModule, MatTooltipModule, - MatDatepickerModule + MatDatepickerModule, + MatNativeDateModule ] }) export class SharedComponentsModule { diff --git a/frontend/src/app/shared-components/table/table.component.html b/frontend/src/app/shared-components/table/table.component.html index b55bf40..f07cbc3 100644 --- a/frontend/src/app/shared-components/table/table.component.html +++ b/frontend/src/app/shared-components/table/table.component.html @@ -24,9 +24,12 @@ - + + + + diff --git a/frontend/src/app/shared-components/table/table.component.ts b/frontend/src/app/shared-components/table/table.component.ts index c72bacf..e40ffca 100644 --- a/frontend/src/app/shared-components/table/table.component.ts +++ b/frontend/src/app/shared-components/table/table.component.ts @@ -24,6 +24,9 @@ export class TableComponent implements OnInit { } ngOnInit(): void { + if (typeof this.allowEditing === 'string') { + throw new Error('use [allowEditing]'); + } } getPropNames(): string[] { diff --git a/frontend/src/app/subjects/subject-edit/courses/course-edit/course-edit.component.html b/frontend/src/app/subjects/subject-edit/courses/course-edit/course-edit.component.html index 8221e9b..d5a6514 100644 --- a/frontend/src/app/subjects/subject-edit/courses/course-edit/course-edit.component.html +++ b/frontend/src/app/subjects/subject-edit/courses/course-edit/course-edit.component.html @@ -3,6 +3,7 @@ {title: 'Félév', name: 'semester'}, {title: 'Név', name: 'alias'} ]"> +

Teljesitési módok

@@ -10,7 +11,7 @@
@@ -40,7 +41,7 @@ {prop: 'minPoints', title: 'Minimum elérendő pontszám'}, {prop: 'maxPoints', title: 'Maximálisan elérhető pontszám'}, {prop: 'deadline', title: 'Határidő', type: 'date'} -]" allowEditing="true" allowNew="true" [editFunction]="editRequirement.bind(this)" +]" allowNew="true" [editFunction]="editRequirement.bind(this)" [createFunction]="createRequirement.bind(this)"> @@ -49,7 +50,7 @@ {{ editedRequirement?.name || 'Új követelmény' }} - diff --git a/frontend/src/app/users/assign-to-course/assign-to-course.component.spec.ts b/frontend/src/app/users/assign-to-course/assign-to-course.component.spec.ts new file mode 100644 index 0000000..b8de6ed --- /dev/null +++ b/frontend/src/app/users/assign-to-course/assign-to-course.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AssignToCourseComponent } from './assign-to-course.component'; + +describe('AssignToCourseComponent', () => { + let component: AssignToCourseComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [AssignToCourseComponent] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(AssignToCourseComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/users/assign-to-course/assign-to-course.component.ts b/frontend/src/app/users/assign-to-course/assign-to-course.component.ts new file mode 100644 index 0000000..4a73536 --- /dev/null +++ b/frontend/src/app/users/assign-to-course/assign-to-course.component.ts @@ -0,0 +1,26 @@ +import { Component, OnInit } from '@angular/core'; +import { CourseAssignUserGQL, User, UserListGQL } from '../../services/graphql'; +import { ActivatedRoute } from '@angular/router'; + +@Component({ + selector: 'app-assign-to-course', + templateUrl: './assign-to-course.component.html', + styleUrls: ['./assign-to-course.component.css'] +}) +export class AssignToCourseComponent implements OnInit { + itemType: User; + + constructor(public listGQL: UserListGQL, public assignGQL: CourseAssignUserGQL, private route: ActivatedRoute) { + } + + ngOnInit(): void { + } + + async assignAsTeacher(item: User): Promise { // TODO: Remove assigned users from list + await this.assignGQL.mutate({course: this.route.snapshot.queryParams.course, user: item.id + '', role: 'teacher'}).toPromise(); + } + + async assignAsStudent(item: User): Promise { + await this.assignGQL.mutate({course: this.route.snapshot.queryParams.course, user: item.id + '', role: 'student'}).toPromise(); + } +} diff --git a/frontend/src/app/users/users.module.ts b/frontend/src/app/users/users.module.ts index 9f8aa9f..3ebcbb3 100644 --- a/frontend/src/app/users/users.module.ts +++ b/frontend/src/app/users/users.module.ts @@ -5,14 +5,16 @@ import { RouterModule, Routes } from '@angular/router'; import { RouteData } from '../app-routing.module'; import { SharedComponentsModule } from '../shared-components/shared-components.module'; import { UserEditComponent } from './user-edit/user-edit.component'; +import { AssignToCourseComponent } from './assign-to-course/assign-to-course.component'; const routes: Routes = [ {path: '', component: UserListComponent, data: {title: ''} as RouteData}, + {path: 'assign', component: AssignToCourseComponent, data: {title: 'Hozzárendelés kurzushoz'}}, {path: ':id', component: UserEditComponent, data: {title: 'Szerkesztés'}} ]; @NgModule({ - declarations: [UserListComponent, UserEditComponent], + declarations: [UserListComponent, UserEditComponent, AssignToCourseComponent], imports: [ CommonModule, RouterModule.forChild(routes),