-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
78 additions
and
39 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
frontend/src/app/assignment/modules/edit-assignment/diff-modal/diff-modal.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<ngbx-modal [back]="['..']" size="lg" #modal> | ||
<ng-container modal-title> | ||
Differences | ||
</ng-container> | ||
<ng-container modal-body> | ||
<h5>Metadata</h5> | ||
<pre [innerHTML]="diffMetadata | safeHtml"></pre> | ||
<h5>Tasks</h5> | ||
<pre [innerHTML]="diffTasks | safeHtml"></pre> | ||
</ng-container> | ||
<ng-container modal-footer> | ||
<button type="button" class="btn btn-secondary" (click)="modal.close()"> | ||
Close | ||
</button> | ||
</ng-container> | ||
</ngbx-modal> |
Empty file.
51 changes: 51 additions & 0 deletions
51
frontend/src/app/assignment/modules/edit-assignment/diff-modal/diff-modal.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {Component, OnInit} from '@angular/core'; | ||
import {AssignmentService} from "../../../services/assignment.service"; | ||
import * as jsdiff from "diff"; | ||
import {ActivatedRoute} from "@angular/router"; | ||
import {AssignmentContext} from "../../../services/assignment.context"; | ||
import {switchMap} from "rxjs/operators"; | ||
import {TaskMarkdownService} from "../task-markdown.service"; | ||
|
||
@Component({ | ||
selector: 'app-diff-modal', | ||
templateUrl: './diff-modal.component.html', | ||
styleUrl: './diff-modal.component.scss' | ||
}) | ||
export class DiffModalComponent implements OnInit { | ||
diffMetadata = ''; | ||
diffTasks = ''; | ||
|
||
constructor( | ||
private route: ActivatedRoute, | ||
private context: AssignmentContext, | ||
private assignmentService: AssignmentService, | ||
private taskMarkdownService: TaskMarkdownService, | ||
) { | ||
} | ||
|
||
ngOnInit() { | ||
this.route.params.pipe( | ||
switchMap(({aid}) => this.assignmentService.get(aid)), | ||
).subscribe(oldAssignment => { | ||
const {tasks: oldTasks, ...old} = oldAssignment; | ||
const {tasks: newTasks, ...current} = this.context.assignment; | ||
this.diffMetadata = renderDiff(jsdiff.diffJson(old, current)); | ||
const oldTasksMd = this.taskMarkdownService.renderTasks(oldTasks); | ||
const newTasksMd = this.taskMarkdownService.renderTasks(newTasks); | ||
this.diffTasks = renderDiff(jsdiff.diffWords(oldTasksMd, newTasksMd)); | ||
}); | ||
} | ||
} | ||
|
||
function escapeHtml(text: string) { | ||
return text.replace(/[&<>"'`=\/]/g, function (s) { | ||
return `&#${s.charCodeAt(0)};`; | ||
}); | ||
} | ||
|
||
function renderDiff(diff: jsdiff.Change[]) { | ||
return diff.map(part => { | ||
const color = part.added ? 'text-success' : part.removed ? 'text-danger' : ''; | ||
return `<span class="${color}">${escapeHtml(part.value)}</span>`; | ||
}).join(''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters