Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit e34aa05

Browse files
Merge pull request #724 from h-da/feature/574-snackbar-migration
Migrate MatSnackBar to SnackBarService
2 parents dd7dbd9 + 4a3f628 commit e34aa05

File tree

13 files changed

+107
-108
lines changed

13 files changed

+107
-108
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111
-->
1212

1313
## [NEXT]
14+
### Changed
15+
- Migrate MatSnackBar to SnackBarService. [#724](https://github.com/h-da/geli/pull/724)
16+
- Reload user list after deleting an account. [#724](https://github.com/h-da/geli/pull/724)
17+
- Validate form before submit when creating a new course. [#724](https://github.com/h-da/geli/pull/724)
18+
- Validate :id for CourseController details route. [#724](https://github.com/h-da/geli/pull/724)
1419

1520
## [[0.7.0](https://github.com/h-da/geli/releases/tag/v0.7.0)] - 2018-05-05 - SS 18 intermediate Release
1621
### Added

api/src/controllers/CourseController.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class CourseController {
162162
* @apiError NotFoundError Includes implicit authorization check. (In getCourse helper method.)
163163
* @apiError ForbiddenError (Redundant) Authorization check.
164164
*/
165-
@Get('/:id')
165+
@Get('/:id([a-fA-F0-9]{24})')
166166
async getCourseView(@Param('id') id: string, @CurrentUser() currentUser: IUser): Promise<ICourseView> {
167167
const course = await this.getCourse(id, currentUser);
168168

app/webFrontend/src/app/admin/user-admin/user-admin.component.ts

+27-28
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Component, OnInit} from '@angular/core';
22
import {UserDataService} from '../../shared/services/data.service';
33
import {Router} from '@angular/router';
44
import {ShowProgressService} from '../../shared/services/show-progress.service';
5-
import {MatSnackBar} from '@angular/material';
5+
import {SnackBarService} from '../../shared/services/snack-bar.service';
66
import {IUser} from '../../../../../../shared/models/IUser';
77
import {DialogService} from '../../shared/services/dialog.service';
88
import {UserService} from '../../shared/services/user.service';
@@ -20,7 +20,7 @@ export class UserAdminComponent implements OnInit {
2020
constructor(private userDataService: UserDataService,
2121
private router: Router,
2222
private showProgress: ShowProgressService,
23-
public snackBar: MatSnackBar,
23+
public snackBar: SnackBarService,
2424
public dialogService: DialogService,
2525
private userService: UserService) {
2626
}
@@ -46,18 +46,15 @@ export class UserAdminComponent implements OnInit {
4646
});
4747
}
4848

49-
updateRole(userIndex: number) {
49+
async updateRole(userIndex: number) {
5050
this.showProgress.toggleLoadingGlobal(true);
51-
this.userDataService.updateItem(this.allUsers[userIndex]).then(
52-
(val) => {
53-
this.showProgress.toggleLoadingGlobal(false);
54-
this.snackBar.open('Role of user ' + val.email + ' successfully updated to ' + val.role, '', {duration: 3000});
55-
},
56-
(error) => {
57-
this.snackBar.open(error.error.message, '', {duration: 3000});
58-
this.showProgress.toggleLoadingGlobal(false);
59-
}
60-
);
51+
try {
52+
const user = await this.userDataService.updateItem(this.allUsers[userIndex]);
53+
this.snackBar.open('Role of user ' + user.email + ' successfully updated to ' + user.role);
54+
} catch (err) {
55+
this.snackBar.open(err.error.message);
56+
}
57+
this.showProgress.toggleLoadingGlobal(false);
6158
}
6259

6360
editUser(userIndex: number) {
@@ -66,22 +63,24 @@ export class UserAdminComponent implements OnInit {
6663
}
6764

6865
deleteUser(userIndex: number) {
69-
this.dialogService
70-
.confirmDelete('user', this.allUsers[userIndex].email)
71-
.subscribe(res => {
72-
if (res) {
66+
this.dialogService.confirmDelete('user', this.allUsers[userIndex].email)
67+
.subscribe(async res => {
68+
if (!res) {
69+
return;
70+
}
71+
7372
this.showProgress.toggleLoadingGlobal(true);
74-
this.userDataService.deleteItem(this.allUsers[userIndex]).then(
75-
(val) => {
76-
this.showProgress.toggleLoadingGlobal(false);
77-
this.snackBar.open('User ' + val + ' was successfully deleted.', '', {duration: 3000});
78-
},
79-
(error) => {
80-
this.showProgress.toggleLoadingGlobal(false);
81-
this.snackBar.open(error, '', {duration: 3000});
82-
}
83-
);
84-
}
73+
const user = this.allUsers[userIndex];
74+
75+
try {
76+
await this.userDataService.deleteItem(user);
77+
this.snackBar.open('User ' + user.email + ' was successfully deleted.');
78+
} catch (err) {
79+
this.snackBar.open(err.error.message);
80+
}
81+
82+
this.getUsers();
83+
this.showProgress.toggleLoadingGlobal(false);
8584
});
8685
}
8786
}

app/webFrontend/src/app/auth/activation-resend/activation-resend.component.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Validators, FormGroup, FormBuilder, FormControl} from '@angular/forms';
33
import {AuthenticationService} from '../../shared/services/authentication.service';
44
import {Router} from '@angular/router';
55
import {ShowProgressService} from '../../shared/services/show-progress.service';
6-
import {MatSnackBar} from '@angular/material';
6+
import {SnackBarService} from '../../shared/services/snack-bar.service';
77
import {errorCodes} from '../../../../../../api/src/config/errorCodes';
88
import {TitleService} from '../../shared/services/title.service';
99
import {emailValidator} from '../../shared/validators/validators';
@@ -32,7 +32,7 @@ export class ActivationResendComponent implements OnInit {
3232
constructor(private router: Router,
3333
private authenticationService: AuthenticationService,
3434
private showProgress: ShowProgressService,
35-
private snackBar: MatSnackBar,
35+
private snackBar: SnackBarService,
3636
private formBuilder: FormBuilder,
3737
private titleService: TitleService, ) {
3838
}
@@ -95,7 +95,7 @@ export class ActivationResendComponent implements OnInit {
9595
break;
9696
}
9797
default: {
98-
this.snackBar.open('Activation Resend failed', 'Dismiss');
98+
this.snackBar.open('Activation Resend failed');
9999
}
100100
}
101101
}

app/webFrontend/src/app/course/course-container/course-container.component.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Component, EventEmitter, Input, Output, OnInit, ViewEncapsulation} from '@angular/core';
2-
import {MatDialog, MatSnackBar} from '@angular/material';
2+
import {MatDialog} from '@angular/material';
3+
import {SnackBarService} from '../../shared/services/snack-bar.service';
34
import {UserService} from '../../shared/services/user.service';
45
import {CourseService, UserDataService} from '../../shared/services/data.service';
56
import {Router} from '@angular/router';
@@ -30,7 +31,7 @@ export class CourseContainerComponent implements OnInit {
3031
private courseService: CourseService,
3132
private router: Router,
3233
private dialog: MatDialog,
33-
private snackBar: MatSnackBar,
34+
private snackBar: SnackBarService,
3435
private userDataService: UserDataService) {
3536

3637
}
@@ -48,22 +49,21 @@ export class CourseContainerComponent implements OnInit {
4849
accessKey
4950
}).then((res) => {
5051
LastVisitedCourseContainerUpdater.addCourseToLastVisitedCourses(courseId, this.userService, this.userDataService);
51-
this.snackBar.open('Successfully enrolled', '', {duration: 5000});
52+
this.snackBar.open('Successfully enrolled');
5253
// reload courses to update enrollment status
5354
this.onEnroll.emit();
54-
}).catch((error) => {
55-
const errormessage = error.error.message;
56-
switch (errormessage) {
55+
}).catch((err) => {
56+
switch (err.error.message) {
5757
case errorCodes.course.accessKey.code: {
58-
this.snackBar.open(`${errorCodes.course.accessKey.text}`, 'Dismiss');
58+
this.snackBar.open(`${errorCodes.course.accessKey.text}`);
5959
break;
6060
}
6161
case errorCodes.course.notOnWhitelist.code: {
62-
this.snackBar.open(`${errorCodes.course.notOnWhitelist.text}`, 'Dismiss');
62+
this.snackBar.open(`${errorCodes.course.notOnWhitelist.text}`);
6363
break;
6464
}
6565
default: {
66-
this.snackBar.open('Enroll failed', '', {duration: 5000});
66+
this.snackBar.open('Enroll failed');
6767
}
6868
}
6969
});

app/webFrontend/src/app/course/course-detail/course-detail.component.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {UserService} from '../../shared/services/user.service';
77
import {IUser} from '../../../../../../shared/models/IUser';
88
import {User} from '../../models/User';
99
import {MatSnackBar, MatDialog} from '@angular/material';
10+
import {SnackBarService} from '../../shared/services/snack-bar.service';
1011
import {DownloadCourseDialogComponent} from './download-course-dialog/download-course-dialog.component';
1112
import {TitleService} from '../../shared/services/title.service';
1213
import {LastVisitedCourseContainerUpdater} from '../../shared/utils/LastVisitedCourseContainerUpdater';
@@ -27,7 +28,7 @@ export class CourseDetailComponent implements OnInit {
2728
private route: ActivatedRoute,
2829
private courseService: CourseService,
2930
public userService: UserService,
30-
private snackBar: MatSnackBar,
31+
private snackBar: SnackBarService,
3132
private dialog: MatDialog,
3233
private titleService: TitleService,
3334
private userDataService: UserDataService,
@@ -47,14 +48,12 @@ export class CourseDetailComponent implements OnInit {
4748
this.course = await this.courseService.readCourseToView(courseId);
4849
this.titleService.setTitleCut(['Course: ', this.course.name]);
4950
LastVisitedCourseContainerUpdater.addCourseToLastVisitedCourses(courseId, this.userService, this.userDataService);
50-
} catch (errorResponse) {
51-
if (errorResponse.status === 401) {
52-
this.snackBar.open('You are not authorized to view this course.', '', {duration: 3000});
53-
} else if (errorResponse.status === 404) {
54-
this.snackBar.open('Your selected course is not available.', '', {duration: 3000});
51+
} catch (err) {
52+
if (err.status === 404) {
53+
this.snackBar.open('Your selected course is not available.');
5554
this.router.navigate(['/not-found']);
5655
} else {
57-
this.snackBar.open('Something went wrong: ' + errorResponse.message, '', {duration: 3000});
56+
this.snackBar.open('Something went wrong: ' + err.error.message);
5857
}
5958
}
6059
}

app/webFrontend/src/app/course/course-detail/download-course-dialog/download-course-dialog.component.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Component, Inject, OnInit, QueryList, ViewChildren, ViewEncapsulation} from '@angular/core';
2-
import {MAT_DIALOG_DATA, MatDialog, MatDialogRef, MatSnackBar} from '@angular/material';
2+
import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from '@angular/material';
3+
import {SnackBarService} from '../../../shared/services/snack-bar.service';
34
import {ICourse} from '../../../../../../../shared/models/ICourse';
45
import {LectureCheckboxComponent} from './downloadCheckBoxes/lecture-checkbox.component';
56
import {DownloadFileService} from 'app/shared/services/data.service';
@@ -28,7 +29,7 @@ export class DownloadCourseDialogComponent implements OnInit {
2829
constructor(public dialogRef: MatDialogRef<DownloadCourseDialogComponent>,
2930
@Inject(MAT_DIALOG_DATA) public data: any,
3031
private downloadReq: DownloadFileService,
31-
public snackBar: MatSnackBar,
32+
public snackBar: SnackBarService,
3233
private saveFileService: SaveFileService) {
3334
}
3435

@@ -57,7 +58,7 @@ export class DownloadCourseDialogComponent implements OnInit {
5758
}
5859

5960
onChildEvent() {
60-
const childChecked: boolean[] = new Array();
61+
const childChecked: boolean[] = [];
6162

6263
this.childLectures.forEach(lec => {
6364
if (lec.chkbox === true && !lec.childUnits.find(unit => unit.chkbox === false)) {
@@ -109,7 +110,7 @@ export class DownloadCourseDialogComponent implements OnInit {
109110
this.disableDownloadButton = true;
110111
const obj = await this.buildObject();
111112
if (obj.lectures.length === 0) {
112-
this.snackBar.open('No units selected!', 'Dismiss', {duration: 3000});
113+
this.snackBar.open('No units selected!');
113114
this.disableDownloadButton = false;
114115
return;
115116
}
@@ -125,15 +126,13 @@ export class DownloadCourseDialogComponent implements OnInit {
125126
if (!this.keepDialogOpen) {
126127
this.dialogRef.close();
127128
}
128-
} catch (error) {
129+
} catch (err) {
129130
this.showSpinner = false;
130131
this.disableDownloadButton = false;
131-
this.snackBar.open('Woops! Something went wrong. Please try again in a few Minutes.',
132-
'Dismiss', {duration: 10000});
132+
this.snackBar.openLong('Woops! Something went wrong. Please try again in a few Minutes.');
133133
}
134134
} else {
135-
this.snackBar.open('Requested Download Package is too large! Please Download fewer Units in one Package.',
136-
'Dismiss', {duration: 10000});
135+
this.snackBar.openLong('Requested Download Package is too large! Please Download fewer Units in one Package.');
137136
this.showSpinner = false;
138137
this.disableDownloadButton = false;
139138
}
@@ -163,8 +162,7 @@ export class DownloadCourseDialogComponent implements OnInit {
163162
}
164163
});
165164

166-
const downloadObj = {courseName: this.course._id, lectures: lectures};
167-
return downloadObj;
165+
return {courseName: this.course._id, lectures: lectures};
168166
}
169167

170168
}

app/webFrontend/src/app/course/course-detail/download-course-dialog/downloadCheckBoxes/unit-checkbox.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
import {IUnit} from '../../../../../../../../shared/models/units/IUnit';
66
import {IFileUnit} from '../../../../../../../../shared/models/units/IFileUnit';
77
import {UploadUnitCheckboxComponent} from './upload-unit-checkbox.component';
8-
import {MatSnackBar} from '@angular/material';
98
import {ConfigService} from '../../../../shared/services/data.service';
109

1110

@@ -32,7 +31,7 @@ export class UnitCheckboxComponent implements OnInit {
3231
childUnitDesc: string;
3332
showCheckBox = true; // false if the unit has only large files
3433

35-
constructor(public snackBar: MatSnackBar, private configService: ConfigService) {
34+
constructor(private configService: ConfigService) {
3635
}
3736

3837
ngOnInit() {

app/webFrontend/src/app/course/course-edit/course-user-list/course-user-list-overview/course-user-list-overview.component.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
22
import {IUser} from '../../../../../../../../shared/models/IUser';
33
import {DialogService} from '../../../../shared/services/dialog.service';
4-
import {MatSnackBar} from '@angular/material';
4+
import {SnackBarService} from '../../../../shared/services/snack-bar.service';
55
import {CourseService, NotificationService} from '../../../../shared/services/data.service';
66
import {ICourse} from '../../../../../../../../shared/models/ICourse';
77
import {User} from '../../../../models/User';
@@ -27,7 +27,8 @@ export class CourseUserListOverviewComponent implements OnInit {
2727
return users.map((user: IUser) => `${user.profile.firstName} ${user.profile.lastName}<${user.email}>`).join(', ');
2828
}
2929

30-
constructor(private dialogService: DialogService, private snackBar: MatSnackBar,
30+
constructor(private dialogService: DialogService,
31+
private snackBar: SnackBarService,
3132
private courseService: CourseService,
3233
private notificationService: NotificationService) {
3334
}
@@ -84,9 +85,9 @@ export class CourseUserListOverviewComponent implements OnInit {
8485
this.resetSelectedUsers();
8586
try {
8687
await this.courseService.sendMailToSelectedUsers(mailData);
87-
this.snackBar.open('Sending mail succeeded.', 'Dismiss', {duration: 2000});
88+
this.snackBar.open('Sending mail succeeded.');
8889
} catch (err) {
89-
this.snackBar.open('Sending mail failed.', 'Dismiss', {duration: 3000});
90+
this.snackBar.open('Sending mail failed.');
9091
}
9192
}
9293

0 commit comments

Comments
 (0)