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

Commit

Permalink
Merge pull request #660 from h-da/feature/#582-unit-visibility-toggle-2
Browse files Browse the repository at this point in the history
Feature/#582 unit visibility toggle 2
  • Loading branch information
PatrickSkowronek authored May 4, 2018
2 parents d37136c + 91c9a1b commit 64e409e
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed wording of progress display on profile page. [#715](https://github.com/h-da/geli/issues/715)
- Fixed form validator in create task [#579](https://github.com/h-da/geli/issues/579)

### Added
- Unit visibility toggle [#582](https://github.com/h-da/geli/issues/582)

### Security
- Fixed numerous severe user related security issues. [#691](https://github.com/h-da/geli/issues/691) [#709](https://github.com/h-da/geli/pull/709)
- Fixed multiple severe course related security issues. [#594](https://github.com/h-da/geli/issues/594) [#653](https://github.com/h-da/geli/issues/653) [#691](https://github.com/h-da/geli/issues/691)
Expand Down
1 change: 0 additions & 1 deletion api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/src/controllers/CourseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,9 @@ export class CourseController {
@Authorized(['teacher', 'admin'])
@Post('/:id/whitelist')
async whitelistStudents(
@Param('id') id: string,
@UploadedFile('file', {options: uploadOptions}) file: any,
@CurrentUser() currentUser: IUser) {
@Param('id') id: string,
@UploadedFile('file', {options: uploadOptions}) file: any,
@CurrentUser() currentUser: IUser) {
const name: string = file.originalname;
if (!name.endsWith('.csv')) {
throw new TypeError(errorCodes.upload.type.notCSV.code);
Expand Down
10 changes: 6 additions & 4 deletions api/src/models/Course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ const courseSchema = new mongoose.Schema({
ref: 'User'
},
media:
{
type: mongoose.Schema.Types.ObjectId,
ref: 'Directory'
},
{
type: mongoose.Schema.Types.ObjectId,
ref: 'Directory'
},
teachers: [
{
type: mongoose.Schema.Types.ObjectId,
Expand Down Expand Up @@ -253,11 +253,13 @@ courseSchema.methods.forView = function (): ICourseView {
};

courseSchema.methods.populateLecturesFor = function (user: IUser) {
const isTeacherOrAdmin = (user.role === 'teacher' || user.role === 'admin');
return this.populate({
path: 'lectures',
populate: {
path: 'units',
virtuals: true,
match: {$or: [{visible: undefined}, {visible: true}, {visible: !isTeacherOrAdmin}]},
populate: {
path: 'progressData',
match: {user: {$eq: user._id}}
Expand Down
3 changes: 3 additions & 0 deletions api/src/models/units/Unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const unitSchema = new mongoose.Schema({
type: {
type: String
},
visible: {
type: Boolean
},
unitCreator: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
Expand Down
1 change: 0 additions & 1 deletion app/webFrontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions app/webFrontend/src/app/course/course.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@
<mat-icon color="warn">visibility_off</mat-icon>
</button>
</span>
<span class="course-admin-actions" *ngIf="course.userCanEditCourse">
<button mat-icon-button (click)="editCourse(course._id)">
<mat-icon>mode_edit</mat-icon>
</button>

<button mat-icon-button (click)="showReport(course._id)">
<mat-icon>show_chart</mat-icon>
</button>

<button mat-icon-button *ngIf="!course.active" disabled>
<mat-icon color="warn">visibility_off</mat-icon>
</button>
</span>
<span class="course-student-actions" *ngIf="this.userService.isStudent()">
<div style="float:left">
<i class="material-icons" style="margin-top: 8px;"
Expand Down
2 changes: 2 additions & 0 deletions app/webFrontend/src/app/models/units/CodeKataUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class CodeKataUnit implements ICodeKataUnit {
weight: number;
updatedAt: string;
createdAt: string;
visible: boolean;

definition: string;
code: string;
Expand All @@ -25,4 +26,5 @@ export class CodeKataUnit implements ICodeKataUnit {
this.weight = 0;
this.__t = 'code-kata';
}

}
2 changes: 2 additions & 0 deletions app/webFrontend/src/app/models/units/FileUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class FileUnit implements IFileUnit {
weight: number;
updatedAt: string;
createdAt: string;
visible: boolean;
unitCreator: any;

files: IFile[] = [];
Expand All @@ -25,4 +26,5 @@ export class FileUnit implements IFileUnit {
this.progressable = false;
this.weight = 0;
}

}
1 change: 1 addition & 0 deletions app/webFrontend/src/app/models/units/FreeTextUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class FreeTextUnit implements IFreeTextUnit {
__t: string;
progressable: boolean;
weight: number;
visible: boolean;
unitCreator: any;

markdown: string;
Expand Down
1 change: 1 addition & 0 deletions app/webFrontend/src/app/models/units/TaskUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class TaskUnit implements ITaskUnit {
__t: string;
progressable: boolean;
weight: number;
visible: boolean;
unitCreator: any;

tasks: ITask[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class CodeKataUnitFormComponent implements OnInit {
name: this.generalInfo.form.value.name,
description: this.generalInfo.form.value.description,
deadline: this.generalInfo.form.value.deadline,
visible: this.generalInfo.form.value.visible
};

if (this.model._id === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export class FileUnitFormComponent implements OnInit {
this.model = {
...this.model,
name: this.generalInfo.form.value.name,
description: this.generalInfo.form.value.description
description: this.generalInfo.form.value.description,
visible: this.generalInfo.form.value.visible

};

const reqObj = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class FreeTextUnitFormComponent implements OnInit {
...this.model,
name: this.generalInfo.form.value.name,
description: this.generalInfo.form.value.description,
visible: this.generalInfo.form.value.visible,

markdown: this.freeTextEditor.markdown
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class TaskUnitEditComponent implements OnInit {
name: this.generalInfo.form.value.name,
description: this.generalInfo.form.value.description,
deadline: this.generalInfo.form.value.deadline,
visible: this.generalInfo.form.value.visible
};

if (this.isTaskUnitValid()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@
<mat-datepicker-toggle matSuffix [for]="deadlineDatepicker"></mat-datepicker-toggle>
<mat-datepicker #deadlineDatepicker (selectedChanged)="updateDateTime($event)"></mat-datepicker>
</mat-form-field>

<div>
<mat-slide-toggle formControlName="visible">
<span *ngIf="form.value.visible">Unit can be seen by students</span>
<span *ngIf="!form.value.visible">Unit cannot be seen by students</span>
</mat-slide-toggle>
</div>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ export class UnitGeneralInfoFormComponent implements OnInit {
}

ngOnInit() {
if (this.model !== null && this.model !== undefined && this.model.visible === undefined) {
this.model.visible = true;
}
this.form = this.formBuilder.group({
name: [this.model ? this.model.name : '', Validators.required],
description: [this.model ? this.model.description : ''],
deadline: [this.model ? this.model.deadline : '']
deadline: [this.model ? this.model.deadline : ''],
visible: [this.model ? this.model.visible : false]
});
}

Expand Down
11 changes: 8 additions & 3 deletions app/webFrontend/src/app/unit/unit.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<div *ngFor="let unit of units;">
<mat-card class="unit-card">
<button mat-icon-button *ngIf="unit.visible === false" disabled>
<mat-icon color="warn">visibility_off</mat-icon>
</button>
<mat-card-title class="unit-card-title">
{{unit.name}}
</mat-card-title>
Expand All @@ -19,9 +22,11 @@
<app-code-kata *ngSwitchCase="'code-kata'" [codeKataUnit]="unit"></app-code-kata>
<app-free-text-unit *ngSwitchCase="'free-text'" [freeTextUnit]="unit"></app-free-text-unit>
<div class="unit-detail">
<div class="user-detail" *ngIf="unit.unitCreator">{{unit.unitCreator.profile.firstName + ' ' + unit.unitCreator.profile.lastName}}</div>
<span *ngIf="unit.createdAt === unit.updatedAt">Published on: {{getFormattedDate(unit.createdAt)}}</span>
<span *ngIf="unit.createdAt !== unit.updatedAt">Changed on: {{getFormattedDate(unit.updatedAt)}}</span>
<div class="user-detail" *ngIf="unit.unitCreator">{{unit.unitCreator.profile.firstName + ' ' +
unit.unitCreator.profile.lastName}}
</div>
<span *ngIf="unit.createdAt === unit.updatedAt">Published on: {{getFormattedDate(unit.createdAt)}}</span>
<span *ngIf="unit.createdAt !== unit.updatedAt">Changed on: {{getFormattedDate(unit.updatedAt)}}</span>
</div>
</mat-card-content>
</mat-card>
Expand Down
1 change: 1 addition & 0 deletions shared/models/units/IUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export interface IUnit {
updatedAt: string;
createdAt: string;
unitCreator: IUser;
visible: boolean;
__t: string;
}

0 comments on commit 64e409e

Please sign in to comment.