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