Skip to content

Commit a5b1356

Browse files
author
Ian Redpath
committed
comments look not half bad now
1 parent a6e91eb commit a5b1356

File tree

7 files changed

+113
-20
lines changed

7 files changed

+113
-20
lines changed

public/project/components/libraries/library.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export class Library {
192192
const comm: any = _.find(this.library.comments, c => { return (<any>c)._id === this.editCommentId })
193193
comm.comment = resp.json().comment.comment
194194
comm.date = resp.json().comment.date
195+
comm.edited = resp.json().comment.edited
195196
this.cancelEditComment()
196197
}
197198
})
@@ -213,7 +214,36 @@ export class Library {
213214
const day = date.getUTCDay()
214215
const hour = date.getUTCHours()
215216
const minutes = date.getUTCMinutes()
216-
return new Date(datenum)
217+
const seconds = date.getUTCSeconds()
218+
219+
const dateNow = new Date()
220+
const yearNow = dateNow.getUTCFullYear()
221+
const monthNow = dateNow.getUTCMonth()
222+
const dayNow = dateNow.getUTCDay()
223+
const hourNow = dateNow.getUTCHours()
224+
const minutesNow = dateNow.getUTCMinutes()
225+
const secondsNow = dateNow.getUTCSeconds()
226+
227+
if (year !== yearNow) {
228+
const diff = yearNow - year
229+
return `${diff} year${diff === 1 ? "" : 's'} ago`
230+
} else if (month !== monthNow) {
231+
const diff = monthNow - month
232+
return `${diff} month${diff === 1 ? "" : 's'} ago`
233+
} else if (day !== dayNow) {
234+
const diff = dayNow - day
235+
return `${diff} day${diff === 1 ? "" : 's'} ago`
236+
} else if (hour !== hourNow) {
237+
const diff = hourNow - hour
238+
return `${diff} hour${diff === 1 ? "" : 's'} ago`
239+
} else if (minutes !== minutesNow) {
240+
const diff = minutesNow - minutes
241+
return `${diff} minute${diff === 1 ? "" : 's'} ago`
242+
} else {
243+
const diff = secondsNow - seconds
244+
return `${diff} second${diff === 1 ? "" : 's'} ago`
245+
}
246+
//return new Date(datenum)
217247
}
218248

219249
}

public/project/components/libraries/library.view.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,19 @@ <h1 *ngIf="!hasEditRights()">{{library.name}}</h1>
5252
</div>
5353
</div>
5454
</div>
55-
56-
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 comments">
55+
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 comments">
5756
<h3 class="h4-margins">Comments</h3>
58-
<div class="results-row">
57+
<div class="results-row table-responsive">
5958
<span class="no-results" *ngIf="library.comments.length ===0">No comments</span>
60-
<table>
61-
<tr *ngFor="#comment of library.comments">
62-
<td><a [routerLink]='["/User", { user: comment.userId }]'>{{comment.username}}</a></td>
59+
<table class="comments-table table-striped">
60+
<tr *ngFor="#comment of library.comments" class="comments-row">
6361
<td>
62+
<img class="comment-img" src="./assets/default_user.png" [routerLink]="['/User', { user: comment.userId }]">
63+
</td>
64+
<td class="content-cell">
65+
<h5 class="profile-header"><a [routerLink]='["/User", { user: comment.userId }]'>{{comment.username}}</a></h5>
66+
<h6 class="timestamp">{{getCommentDate(comment.date)}} {{comment.edited ? '(edited)' : ''}}</h6>
67+
6468
<div *ngIf="isEditingComment(comment._id)">
6569
<input type="text" [(ngModel)]="editCommentText">
6670
<span class="glyphicon glyphicon-check" (click)="saveEditComment()"></span>
@@ -70,9 +74,6 @@ <h3 class="h4-margins">Comments</h3>
7074
{{comment.comment}}
7175
</div>
7276
</td>
73-
<td>
74-
{{ getCommentDate(comment.date) }}
75-
</td>
7677
</tr>
7778
</table>
7879
</div>

public/project/components/movies/movie.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export class Movie {
247247
let comm: any = _.find(this.movie.comments, c => { return (<any>c)._id === this.editCommentId })
248248
comm.comment = resp.json().comment.comment
249249
comm.date = resp.json().comment.date
250+
comm.edited = resp.json().comment.edited
250251
this.cancelEditComment()
251252
}
252253
})
@@ -258,6 +259,41 @@ export class Movie {
258259
}
259260

260261
getCommentDate(datenum: number) {
261-
return new Date(datenum)
262+
const date = new Date(datenum)
263+
const year = date.getUTCFullYear()
264+
const month = date.getUTCMonth()
265+
const day = date.getUTCDay()
266+
const hour = date.getUTCHours()
267+
const minutes = date.getUTCMinutes()
268+
const seconds = date.getUTCSeconds()
269+
270+
const dateNow = new Date()
271+
const yearNow = dateNow.getUTCFullYear()
272+
const monthNow = dateNow.getUTCMonth()
273+
const dayNow = dateNow.getUTCDay()
274+
const hourNow = dateNow.getUTCHours()
275+
const minutesNow = dateNow.getUTCMinutes()
276+
const secondsNow = dateNow.getUTCSeconds()
277+
278+
if (year !== yearNow) {
279+
const diff = yearNow - year
280+
return `${diff} year${diff === 1 ? "" : 's'} ago`
281+
} else if (month !== monthNow) {
282+
const diff = monthNow - month
283+
return `${diff} month${diff === 1 ? "" : 's'} ago`
284+
} else if (day !== dayNow) {
285+
const diff = dayNow - day
286+
return `${diff} day${diff === 1 ? "" : 's'} ago`
287+
} else if (hour !== hourNow) {
288+
const diff = hourNow - hour
289+
return `${diff} hour${diff === 1 ? "" : 's'} ago`
290+
} else if (minutes !== minutesNow) {
291+
const diff = minutesNow - minutes
292+
return `${diff} minute${diff === 1 ? "" : 's'} ago`
293+
} else {
294+
const diff = secondsNow - seconds
295+
return `${diff} second${diff === 1 ? "" : 's'} ago`
296+
}
297+
//return new Date(datenum)
262298
}
263299
}

public/project/components/movies/movie.view.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ <h1 class="movie-title">{{omdbMovie.title}}</h1>
6969
</div>
7070
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 comments">
7171
<h3 class="h4-margins">Comments</h3>
72-
<div class="results-row">
72+
<div class="results-row table-responsive">
7373
<span class="no-results" *ngIf="movie.comments.length ===0">No comments</span>
74-
<table>
75-
<tr *ngFor="#comment of movie.comments">
76-
<td><a [routerLink]='["/User", { user: comment.userId }]'>{{comment.username}}</a></td>
74+
<table class="comments-table table-striped">
75+
<tr *ngFor="#comment of movie.comments" class="comments-row">
7776
<td>
77+
<img class="comment-img" src="./assets/default_user.png" [routerLink]="['/User', { user: comment.userId }]">
78+
</td>
79+
<td class="content-cell">
80+
<h5 class="profile-header"><a [routerLink]='["/User", { user: comment.userId }]'>{{comment.username}}</a></h5>
81+
<h6 class="timestamp">{{getCommentDate(comment.date)}} {{comment.edited ? '(edited)' : ''}}</h6>
7882
<div *ngIf="isEditingComment(comment._id)">
7983
<input type="text" [(ngModel)]="editCommentText">
8084
<span class="glyphicon glyphicon-check" (click)="saveEditComment()"></span>
@@ -84,9 +88,6 @@ <h3 class="h4-margins">Comments</h3>
8488
{{comment.comment}}
8589
</div>
8690
</td>
87-
<td>
88-
{{ getCommentDate(comment.date) }}
89-
</td>
9091
</tr>
9192
</table>
9293
</div>

public/project/css/style.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,29 @@
177177

178178
.new-comment {
179179
margin-top: 20px;
180+
}
181+
182+
.comment-img {
183+
width: 100%;
184+
}
185+
186+
.timestamp {
187+
display:inline-block;
188+
}
189+
190+
.comments-table {
191+
text-align:initial;
192+
}
193+
194+
.content-cell {
195+
width: 92%;
196+
padding-left: 20px;
197+
}
198+
.icon-cell {
199+
width: 8%;
200+
201+
}
202+
.comments-row > td {
203+
padding-bottom: .5em;
204+
padding-top: .5em;
180205
}

server/project/models/library.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export default class LibraryModel {
183183
editCommentForLibrary(libId: string, commentId: string, commentText: string) {
184184
let deferred = Q.defer()
185185
const date = new Date().getTime()
186-
this.commentModel.findByIdAndUpdate(commentId, { comment: commentText, date }, { new: true }, (err, resp) => {
186+
this.commentModel.findByIdAndUpdate(commentId, { comment: commentText, date, edited: true }, { new: true }, (err, resp) => {
187187
if (err) {
188188
deferred.reject(err)
189189
} else {

server/project/models/movie.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export default class LibraryModel {
219219
editCommentForMovie(movieId: string, commentId: string, commentText: string) {
220220
let deferred = Q.defer()
221221
const date = new Date().getTime()
222-
this.commentModel.findByIdAndUpdate(commentId, { comment: commentText, date }, { new: true }, (err, resp) => {
222+
this.commentModel.findByIdAndUpdate(commentId, { comment: commentText, date, edited: true }, { new: true }, (err, resp) => {
223223
if (err) {
224224
deferred.reject(err)
225225
} else {

0 commit comments

Comments
 (0)