Skip to content

Commit de5e928

Browse files
committed
add comment afte to code snippets
1 parent df08200 commit de5e928

File tree

7 files changed

+47
-11
lines changed

7 files changed

+47
-11
lines changed

backend/src/model/snippet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const CodeSnippetSchema = new Schema({
99
code: String,
1010
language: String,
1111
comment: String,
12+
commentAfter: String,
1213
});
1314

1415
const snippetSchema = new Schema({

frontend/src/app/core/model/snippet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export interface Snippet {
1616
export interface CodeSnippet {
1717
code: string;
1818
comment: string;
19+
commentAfter: string;
1920
}

frontend/src/app/my-snippets/create-snippet-form/create-snippet-form.component.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<div class="navigation-space-buffer rounded bg-white shadow-sm">
22
<form [formGroup]="snippetFormGroup" novalidate (ngSubmit)="createSnippet(snippetFormGroup.value, false, popup)">
33
<div class="form-group pb-1">
4-
<label for="title" class="space-btw-wrapper"><span>Title*</span> <span><i class="fa fa-code fa-lg"></i></span></label>
4+
<label for="title" class="space-btw-wrapper"><span>Title*</span> <span><i
5+
class="fa fa-code fa-lg"></i></span></label>
56
<input type="text" class="form-control" id="title"
67
required
78
formControlName="title"
@@ -57,7 +58,7 @@
5758
<div [formGroupName]="i" class="border rounded pt-1 pl-3 pr-3 mb-3">
5859
<div class="form-group mb-0">
5960
<div class="form-group">
60-
<label for="comment-{{i}}">Comment (optional)- <i class="fab fa-markdown"></i> <a
61+
<label for="comment-{{i}}">Comment before (optional) - <i class="fab fa-markdown"></i> <a
6162
class="markdown-link" href="https://daringfireball.net/projects/markdown/" target="_blank">Markdown is
6263
supported</a></label>
6364
<textarea class="form-control"
@@ -80,6 +81,18 @@
8081
class="description-chars-counter">{{codeSnippet.get('code').value ? codeSnippet.get('code').value.length : 0}}
8182
/ 5000
8283
</div>
84+
<div class="form-group">
85+
<label for="commentAfter-{{i}}">Comment after (optional) - <i class="fab fa-markdown"></i> <a
86+
class="markdown-link" href="https://daringfireball.net/projects/markdown/" target="_blank">Markdown is
87+
supported</a></label>
88+
<textarea class="form-control"
89+
style="height: 5rem"
90+
id="commentAfter-{{i}}"
91+
formControlName="commentAfter"
92+
placeholder='Appears after code snippet in details'>
93+
</textarea>
94+
</div>
95+
8396
<div class="clear"></div>
8497
<div *ngIf="codeSnippet.invalid && (codeSnippet.dirty || codeSnippet.touched)" class="alert alert-danger">
8598
<div *ngIf="codeSnippet.get('code').errors.tooManyLines">
@@ -98,7 +111,7 @@
98111
class="btn btn-sm btn-primary mb-2"
99112
title="Add another code section"
100113
(click)="addEmptyCodeSnippet(i)">
101-
<i class="fa fa-plus"></i> Add
114+
<i class="fa fa-plus"></i> Add code section
102115
</button>
103116
<button type="button"
104117
class="btn btn-sm btn-danger mb-2 ml-2"
@@ -108,6 +121,7 @@
108121
<i class="far fa-trash-alt"></i> Remove
109122
</button>
110123
</div>
124+
111125
</div>
112126

113127
<div class="form-group pt-2 pb-3">

frontend/src/app/my-snippets/create-snippet-form/create-snippet-form.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ export class CreateSnippetFormComponent extends SnippetFormBaseComponent impleme
125125

126126
return this.formBuilder.group({
127127
code: [this.code ? this.ext === 'vscode' ? this.decodeTextVsCode(this.code) : this.code : '', textSizeValidator(5000, 500)],
128-
comment: [this.comment ? this.comment : '', textSizeValidator(1000, 30)]
128+
comment: [this.comment ? this.comment : '', textSizeValidator(1000, 30)],
129+
commentAfter: [ '', textSizeValidator(1000, 30)]
129130
});
130131
}
131132

frontend/src/app/my-snippets/snippet-form-base/snippet-form.base.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,24 @@ export class SnippetFormBaseComponent implements OnInit {
127127
createCodeSnippet(codeSnippet: CodeSnippet): FormGroup {
128128
return this.formBuilder.group({
129129
code: [codeSnippet.code, textSizeValidator(5000, 500)],
130-
comment: codeSnippet.comment
130+
comment: codeSnippet.comment,
131+
commentAfter: codeSnippet.commentAfter
131132
});
132133
}
133134

134135
createInitialCodeSnippet(): FormGroup {
135136
return this.formBuilder.group({
136137
code: ['', textSizeValidator(5000, 500)],
137-
comment: ['', textSizeValidator(1000, 30)]
138+
comment: ['', textSizeValidator(1000, 30)],
139+
commentAfter: ['', textSizeValidator(1000, 30)]
138140
});
139141
}
140142

141143
createEmptyCodeSnippet(): FormGroup {
142144
return this.formBuilder.group({
143145
code: ['', textSizeValidator(5000, 500)],
144-
comment: ['', textSizeValidator(1000, 30)]
146+
comment: ['', textSizeValidator(1000, 30)],
147+
commentAfter: ['', textSizeValidator(1000, 30)]
145148
});
146149
}
147150

@@ -170,8 +173,8 @@ export class SnippetFormBaseComponent implements OnInit {
170173
const lastSlashIndex = headers.get('location').lastIndexOf('/');
171174
const newSnippetId = headers.get('location').substring(lastSlashIndex + 1);
172175
snippet._id = newSnippetId;
173-
const queryParmas = popup ? {popup: popup} : {};
174-
this.navigateToSnippetDetails(snippet, queryParmas)
176+
const queryParams = popup ? {popup: popup} : {};
177+
this.navigateToSnippetDetails(snippet, queryParams)
175178
},
176179
(error: HttpResponse<any>) => {
177180
this.errorService.handleError(error.body.json());

frontend/src/app/my-snippets/update-snippet-form/update-snippet-form.component.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<div [formGroupName]="i" class="border rounded pt-1 pl-3 pr-3 mb-3">
5858
<div class="form-group mb-0">
5959
<div class="form-group">
60-
<label for="comment-{{i}}">Comment (optional)- <i class="fab fa-markdown"></i> <a
60+
<label for="comment-{{i}}">Comment before (optional)- <i class="fab fa-markdown"></i> <a
6161
class="markdown-link" href="https://daringfireball.net/projects/markdown/" target="_blank">Markdown is
6262
supported</a></label>
6363
<textarea class="form-control"
@@ -80,6 +80,17 @@
8080
class="description-chars-counter">{{codeSnippet.get('code').value ? codeSnippet.get('code').value.length : 0}}
8181
/ 5000
8282
</div>
83+
<div class="form-group">
84+
<label for="commentAfter-{{i}}">Comment after (optional) - <i class="fab fa-markdown"></i> <a
85+
class="markdown-link" href="https://daringfireball.net/projects/markdown/" target="_blank">Markdown is
86+
supported</a></label>
87+
<textarea class="form-control"
88+
style="height: 5rem"
89+
id="commentAfter-{{i}}"
90+
formControlName="commentAfter"
91+
placeholder='Appears after code snippet in details'>
92+
</textarea>
93+
</div>
8394
<div class="clear"></div>
8495
<div *ngIf="codeSnippet.invalid && (codeSnippet.dirty || codeSnippet.touched)" class="alert alert-danger">
8596
<div *ngIf="codeSnippet.get('code').errors.tooManyLines">
@@ -98,7 +109,7 @@
98109
class="btn btn-sm btn-primary mb-2"
99110
title="Add another code section"
100111
(click)="addEmptyCodeSnippet(i)">
101-
<i class="fa fa-plus"></i> Add
112+
<i class="fa fa-plus"></i> Add code section
102113
</button>
103114
<button type="button"
104115
class="btn btn-sm btn-danger mb-2 ml-2"
@@ -108,6 +119,7 @@
108119
<i class="far fa-trash-alt"></i> Remove
109120
</button>
110121
</div>
122+
111123
</div>
112124

113125
<div class="form-group pt-2 pb-3">

frontend/src/app/shared/snippet-details/snippet-card-body/snippet-card-body.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<div class="clear"></div>
1616
<pre class="mb-0"><code [highlight]="codeSnippet.code" #codePart></code></pre>
1717
</div>
18+
<p *ngIf="codeSnippet.commentAfter" class="mb-0 mt-2"
19+
[innerHtml]="codeSnippet.commentAfter | md2html"></p>
1820
<hr *ngIf="!isLast">
1921
</div>
2022
</div>
@@ -37,6 +39,8 @@
3739
<div class="clear"></div>
3840
<pre class="mb-0"><code [highlight]="codeSnippet.code" #codePart></code></pre>
3941
</div>
42+
<p *ngIf="codeSnippet.commentAfter" class="mb-1 mt-2"
43+
[innerHtml]="codeSnippet.commentAfter | md2html"></p>
4044
<hr *ngIf="!isLast">
4145
</div>
4246
</ng-template>

0 commit comments

Comments
 (0)