changed services and views
This commit is contained in:
parent
6d6f4c6c37
commit
95aa7e2883
@ -1,3 +1,4 @@
|
|||||||
|
import { GroupModule } from './group/group.module';
|
||||||
import { AuthGuard } from './auth/auth.guard';
|
import { AuthGuard } from './auth/auth.guard';
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { Routes, RouterModule } from '@angular/router';
|
import { Routes, RouterModule } from '@angular/router';
|
||||||
@ -5,6 +6,7 @@ import { Routes, RouterModule } from '@angular/router';
|
|||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: '', redirectTo: 'user', pathMatch: 'full' },
|
{ path: '', redirectTo: 'user', pathMatch: 'full' },
|
||||||
|
{ path: 'group', loadChildren: () => import('./group/group.module').then(m => m.GroupModule), canActivate: [AuthGuard] },
|
||||||
{ path: 'subject', loadChildren: () => import('./subject/subject.module').then(m => m.SubjectModule), canActivate: [AuthGuard] },
|
{ path: 'subject', loadChildren: () => import('./subject/subject.module').then(m => m.SubjectModule), canActivate: [AuthGuard] },
|
||||||
{ path: 'user', loadChildren: () => import('./user/user.module').then(m => m.UserModule) }
|
{ path: 'user', loadChildren: () => import('./user/user.module').then(m => m.UserModule) }
|
||||||
];
|
];
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<div *ngIf="group$ | async as group">
|
<div *ngIf="group$ | async as group">
|
||||||
<div>
|
<div>
|
||||||
<button *ngIf="group.admin.id === userId" (click)="onDelete(group.id)" class="btn btn-primary">Delete group</button>
|
<button *ngIf="group.admin.id === userId" (click)="onDelete()" class="btn btn-primary">Delete group</button>
|
||||||
<button *ngIf="group.admin.id !== userId" (click)="onLeaveGroup(group.id)" class="btn btn-primary">Leave group</button>
|
<button *ngIf="group.admin.id !== userId" (click)="onLeaveGroup()" class="btn btn-primary">Leave group</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="group-main-data">
|
<div class="group-main-data">
|
||||||
<div>
|
<div>
|
||||||
@ -14,6 +14,7 @@
|
|||||||
Admin: {{ group.admin.fullName }} ({{group.admin.userName}})
|
Admin: {{ group.admin.fullName }} ({{group.admin.userName}})
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<app-subject-list></app-subject-list>
|
||||||
<app-group-users [groupUsers]="group.users"></app-group-users>
|
<app-group-users [groupUsers]="group.users"></app-group-users>
|
||||||
<app-group-candidates [candidates]="group.userCandidates"></app-group-candidates>
|
<app-group-candidates [candidates]="group.userCandidates"></app-group-candidates>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,13 +27,13 @@ export class GroupEditComponent implements OnInit {
|
|||||||
|
|
||||||
onDelete(): void {
|
onDelete(): void {
|
||||||
this.groupService.delete(this.groupId).subscribe(() => {
|
this.groupService.delete(this.groupId).subscribe(() => {
|
||||||
this.router.navigateByUrl('/groups');
|
this.router.navigateByUrl('/group');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onLeaveGroup(): void {
|
onLeaveGroup(): void {
|
||||||
this.groupService.leaveGroup(this.groupId).subscribe(() => {
|
this.groupService.leaveGroup(this.groupId).subscribe(() => {
|
||||||
this.router.navigateByUrl('/groups');
|
this.router.navigateByUrl('/group');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,5 +16,3 @@
|
|||||||
</app-group-list>
|
</app-group-list>
|
||||||
</mat-tab>
|
</mat-tab>
|
||||||
</mat-tab-group>
|
</mat-tab-group>
|
||||||
<app-group-users></app-group-users>
|
|
||||||
<app-group-candidates></app-group-candidates>
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { SubjectModule } from './../subject/subject.module';
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { GroupMainComponent } from './components/group-main/group-main.component';
|
import { GroupMainComponent } from './components/group-main/group-main.component';
|
||||||
@ -29,6 +30,7 @@ import { MatButtonModule } from '@angular/material/button';
|
|||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
MatCheckboxModule,
|
MatCheckboxModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
|
SubjectModule
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class GroupModule { }
|
export class GroupModule { }
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { SubjectDeleteRequestService } from './../../services/subject-delete-request.service';
|
import { SubjectDeleteRequestService } from './../../services/subject-delete-request.service';
|
||||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { Subject } from '../../interfaces/subject.interface';
|
import { Subject } from '../../interfaces/subject.interface';
|
||||||
import { SubjectService } from '../../services/subject.service';
|
import { SubjectService } from '../../services/subject.service';
|
||||||
@ -13,6 +13,7 @@ import { Router } from '@angular/router';
|
|||||||
})
|
})
|
||||||
export class SubjectMainComponent implements OnInit {
|
export class SubjectMainComponent implements OnInit {
|
||||||
|
|
||||||
|
@Input() groupId: number;
|
||||||
subjects$: Observable<Subject[]>;
|
subjects$: Observable<Subject[]>;
|
||||||
subjectDeleteRequests$: Observable<SubjectDeleteRequest[]>;
|
subjectDeleteRequests$: Observable<SubjectDeleteRequest[]>;
|
||||||
|
|
||||||
@ -21,8 +22,8 @@ export class SubjectMainComponent implements OnInit {
|
|||||||
private subjectDeleteRequestService: SubjectDeleteRequestService) { }
|
private subjectDeleteRequestService: SubjectDeleteRequestService) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.subjects$ = this.subjectService.getList();
|
this.subjects$ = this.subjectService.getListByGroupId(Number(localStorage.getItem('userId')));
|
||||||
this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getList();
|
this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getListByGroupId(this.groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddNewSubject(): void {
|
onAddNewSubject(): void {
|
||||||
@ -31,29 +32,29 @@ export class SubjectMainComponent implements OnInit {
|
|||||||
|
|
||||||
onApproveDeletion(deletionRequestId: number): void {
|
onApproveDeletion(deletionRequestId: number): void {
|
||||||
this.subjectDeleteRequestService.approveDeletion(deletionRequestId).subscribe(() => {
|
this.subjectDeleteRequestService.approveDeletion(deletionRequestId).subscribe(() => {
|
||||||
this.subjects$ = this.subjectService.getList();
|
this.subjects$ = this.subjectService.getListByGroupId(this.groupId);
|
||||||
this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getList();
|
this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getListByGroupId(this.groupId);
|
||||||
alert('Deletion approved');
|
alert('Deletion approved');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddDeleteRequest(id: number): void {
|
onAddDeleteRequest(id: number): void {
|
||||||
this.subjectDeleteRequestService.add(id).subscribe(() => {
|
this.subjectDeleteRequestService.add(id).subscribe(() => {
|
||||||
this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getList();
|
this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getListByGroupId(this.groupId);
|
||||||
alert('Delete request sent');
|
alert('Delete request sent');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onCancelDeletion(deletionRequestId: number): void {
|
onCancelDeletion(deletionRequestId: number): void {
|
||||||
this.subjectDeleteRequestService.cancelDeletion(deletionRequestId).subscribe(() => {
|
this.subjectDeleteRequestService.cancelDeletion(deletionRequestId).subscribe(() => {
|
||||||
this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getList();
|
this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getListByGroupId(this.groupId);
|
||||||
alert('Deletion canceled');
|
alert('Deletion canceled');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onDeleteSubject(id: number): void {
|
onDeleteSubject(id: number): void {
|
||||||
this.subjectService.delete(id).subscribe(() => {
|
this.subjectService.delete(id).subscribe(() => {
|
||||||
this.subjects$ = this.subjectService.getList();
|
this.subjects$ = this.subjectService.getListByGroupId(this.groupId);
|
||||||
alert('success');
|
alert('success');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,18 +12,18 @@ export class SubjectDeleteRequestService {
|
|||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
add(subjectId: number): Observable<void> {
|
add(subjectId: number): Observable<void> {
|
||||||
return this.http.post<void>(`${environment.host + environment.apiEndpoints.deleteRequests.addDeletionRequest}`, {subjectId});
|
return this.http.post<void>(`${environment.host + environment.apiEndpoints.deleteRequests.add}`, {subjectId});
|
||||||
}
|
}
|
||||||
|
|
||||||
approveDeletion(id: number): Observable<void> {
|
approveDeletion(id: number): Observable<void> {
|
||||||
return this.http.post<void>(`${environment.host + environment.apiEndpoints.deleteRequests.approveDeletion}`, {id});
|
return this.http.post<void>(`${environment.host + environment.apiEndpoints.deleteRequests.approve}`, {id});
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelDeletion(id: number): Observable<void> {
|
cancelDeletion(id: number): Observable<void> {
|
||||||
return this.http.delete<void>(`${environment.host + environment.apiEndpoints.deleteRequests.cancelDeletion}/${id}`);
|
return this.http.delete<void>(`${environment.host + environment.apiEndpoints.deleteRequests.cancel}/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getList(): Observable<SubjectDeleteRequest[]> {
|
getListByGroupId(groupId: number): Observable<SubjectDeleteRequest[]> {
|
||||||
return this.http.get<SubjectDeleteRequest[]>(environment.host + environment.apiEndpoints.deleteRequests.getList);
|
return this.http.get<SubjectDeleteRequest[]>(`${environment.host + environment.apiEndpoints.deleteRequests.getListByGroupId}/${groupId}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,22 +12,22 @@ export class SubjectService {
|
|||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
add(subject: Subject): Observable<void> {
|
add(subject: Subject): Observable<void> {
|
||||||
return this.http.post<void>(environment.host + environment.apiEndpoints.subjects, subject);
|
return this.http.post<void>(environment.host + environment.apiEndpoints.subjects.add, subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(id: number): Observable<void> {
|
delete(id: number): Observable<void> {
|
||||||
return this.http.delete<void>(`${environment.host + environment.apiEndpoints.subjects}/${id}`);
|
return this.http.delete<void>(`${environment.host + environment.apiEndpoints.subjects.delete}/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getById(id: number): Observable<Subject> {
|
getById(id: number): Observable<Subject> {
|
||||||
return this.http.get<Subject>(`${environment.host + environment.apiEndpoints.subjects}/${id}`);
|
return this.http.get<Subject>(`${environment.host + environment.apiEndpoints.subjects.getById}/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getList(): Observable<Subject[]> {
|
getListByGroupId(groupId: number): Observable<Subject[]> {
|
||||||
return this.http.get<Subject[]>(environment.host + environment.apiEndpoints.subjects);
|
return this.http.get<Subject[]>(`${environment.host + environment.apiEndpoints.subjects.getListByGroupId}/${groupId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(subject: Subject): Observable<void> {
|
update(subject: Subject): Observable<void> {
|
||||||
return this.http.put<void>(`${environment.host + environment.apiEndpoints.subjects}/${subject.id}`, subject);
|
return this.http.put<void>(`${environment.host + environment.apiEndpoints.subjects.update}/${subject.id}`, subject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,9 @@ import { SubjectDeleteRequestListComponent } from './components/subject-delete-r
|
|||||||
MatCheckboxModule,
|
MatCheckboxModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
MatDatepickerModule
|
MatDatepickerModule
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
SubjectMainComponent, SubjectListComponent, SubjectEditComponent, SubjectDeleteRequestListComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class SubjectModule { }
|
export class SubjectModule { }
|
||||||
|
@ -36,7 +36,7 @@ export class LoginComponent implements OnInit {
|
|||||||
localStorage.setItem('userId', auth.user.id);
|
localStorage.setItem('userId', auth.user.id);
|
||||||
localStorage.setItem('userName', auth.user.userName);
|
localStorage.setItem('userName', auth.user.userName);
|
||||||
localStorage.setItem('fullName', auth.user.fullName);
|
localStorage.setItem('fullName', auth.user.fullName);
|
||||||
this.router.navigateByUrl('/subjects');
|
this.router.navigateByUrl('/group');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,12 +2,18 @@ export const environment = {
|
|||||||
production: false,
|
production: false,
|
||||||
host: 'http://localhost:56764/',
|
host: 'http://localhost:56764/',
|
||||||
apiEndpoints: {
|
apiEndpoints: {
|
||||||
subjects: 'api/subjects',
|
subjects: {
|
||||||
|
getListByGroupId: 'api/subjects/list-by-group-id',
|
||||||
|
getById: 'api/subjects/get-by-id',
|
||||||
|
delete: 'api/subjects/delete',
|
||||||
|
add: 'api/subjects/add',
|
||||||
|
update: 'api/subjects/update'
|
||||||
|
},
|
||||||
deleteRequests: {
|
deleteRequests: {
|
||||||
getList: 'api/subjectDeleteRequests/list',
|
getListByGroupId: 'api/subjectDeleteRequests/list-by-group-id',
|
||||||
addDeletionRequest: 'api/subjectDeleteRequests/addDeletionRequest',
|
add: 'api/subjectDeleteRequests/add',
|
||||||
approveDeletion: 'api/subjectDeleteRequests/approveDeletion',
|
approve: 'api/subjectDeleteRequests/approve',
|
||||||
cancelDeletion: 'api/subjectDeleteRequests/cancelDeletion',
|
cancel: 'api/subjectDeleteRequests/cancel',
|
||||||
},
|
},
|
||||||
users: {
|
users: {
|
||||||
register: 'api/users/register',
|
register: 'api/users/register',
|
||||||
@ -18,7 +24,8 @@ export const environment = {
|
|||||||
getById: 'api/groups/get-by-id',
|
getById: 'api/groups/get-by-id',
|
||||||
getCurrentUserGroups: 'api/groups/current-user-groups',
|
getCurrentUserGroups: 'api/groups/current-user-groups',
|
||||||
create: 'api/groups/create',
|
create: 'api/groups/create',
|
||||||
delete: 'api/groups/delete'
|
delete: 'api/groups/delete',
|
||||||
|
leave: 'api/groups/leave'
|
||||||
},
|
},
|
||||||
groupCandidates: {
|
groupCandidates: {
|
||||||
getList: 'api/group-candidates/list',
|
getList: 'api/group-candidates/list',
|
||||||
|
Loading…
Reference in New Issue
Block a user