Commit 0456e67c7ac0b837bdac7021373b594f565b0af5
Exists in
master
and in
15 other branches
Merge branch 'master' of softwarepublico.gov.br:noosfero-themes/angular-theme
Showing
8 changed files
with
91 additions
and
25 deletions
Show diff stats
src/app/article/comment/comments.component.spec.ts
@@ -19,7 +19,6 @@ describe("Components", () => { | @@ -19,7 +19,6 @@ describe("Components", () => { | ||
19 | 19 | ||
20 | let properties = { article: { id: 1 }, parent: <any>null }; | 20 | let properties = { article: { id: 1 }, parent: <any>null }; |
21 | function createComponent() { | 21 | function createComponent() { |
22 | - // postCommentEventService = jasmine.createSpyObj("postCommentEventService", ["subscribe"]); | ||
23 | let providers = [ | 22 | let providers = [ |
24 | helpers.createProviderToValue('CommentService', commentService), | 23 | helpers.createProviderToValue('CommentService', commentService), |
25 | helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService), | 24 | helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService), |
src/app/article/comment/comments.component.ts
@@ -9,7 +9,7 @@ import { CommentComponent } from "./comment.component"; | @@ -9,7 +9,7 @@ import { CommentComponent } from "./comment.component"; | ||
9 | directives: [PostCommentComponent, CommentComponent], | 9 | directives: [PostCommentComponent, CommentComponent], |
10 | outputs: ['commentAdded'] | 10 | outputs: ['commentAdded'] |
11 | }) | 11 | }) |
12 | -@Inject(CommentService, "$element") | 12 | +@Inject(CommentService, "$scope") |
13 | export class CommentsComponent { | 13 | export class CommentsComponent { |
14 | 14 | ||
15 | comments: noosfero.CommentViewModel[] = []; | 15 | comments: noosfero.CommentViewModel[] = []; |
@@ -32,9 +32,22 @@ export class CommentsComponent { | @@ -32,9 +32,22 @@ export class CommentsComponent { | ||
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
35 | - commentAdded(comment: noosfero.Comment): void { | 35 | + commentAdded(comment: noosfero.CommentViewModel): void { |
36 | + comment.__show_reply = false; | ||
37 | + if (comment.reply_of) { | ||
38 | + this.comments.forEach((commentOnList) => { | ||
39 | + if (commentOnList.id == comment.reply_of.id) { | ||
40 | + if (commentOnList.replies) { | ||
41 | + commentOnList.replies.push(comment); | ||
42 | + } else { | ||
43 | + commentOnList.replies = [comment]; | ||
44 | + } | ||
45 | + } | ||
46 | + }); | ||
47 | + } | ||
36 | this.comments.push(comment); | 48 | this.comments.push(comment); |
37 | this.resetShowReply(); | 49 | this.resetShowReply(); |
50 | + this.$scope.$apply(); | ||
38 | } | 51 | } |
39 | 52 | ||
40 | commentRemoved(comment: noosfero.Comment): void { | 53 | commentRemoved(comment: noosfero.Comment): void { |
@@ -51,6 +64,7 @@ export class CommentsComponent { | @@ -51,6 +64,7 @@ export class CommentsComponent { | ||
51 | if (this.parent) { | 64 | if (this.parent) { |
52 | this.parent.__show_reply = false; | 65 | this.parent.__show_reply = false; |
53 | } | 66 | } |
67 | + | ||
54 | } | 68 | } |
55 | 69 | ||
56 | loadComments() { | 70 | loadComments() { |
src/lib/ng-noosfero-api/http/restangular_service.ts
@@ -223,7 +223,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | @@ -223,7 +223,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | ||
223 | restRequest = restangularObj.remove(queryParams, headers); | 223 | restRequest = restangularObj.remove(queryParams, headers); |
224 | 224 | ||
225 | restRequest | 225 | restRequest |
226 | - .then(this.getHandleSuccessFunction(deferred, this.modelRemovedEventEmitter)) | 226 | + .then(this.getHandleSuccessFunction(deferred, this.modelRemovedEventEmitter, obj)) |
227 | .catch(this.getHandleErrorFunction(deferred)); | 227 | .catch(this.getHandleErrorFunction(deferred)); |
228 | 228 | ||
229 | return deferred.promise; | 229 | return deferred.promise; |
@@ -311,7 +311,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | @@ -311,7 +311,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | ||
311 | } | 311 | } |
312 | 312 | ||
313 | /** HANDLERS */ | 313 | /** HANDLERS */ |
314 | - protected getHandleSuccessFunction<C>(deferred: ng.IDeferred<noosfero.RestResult<C | T | any>>, successEmitter: EventEmitter<T> = null): (response: restangular.IResponse) => void { | 314 | + protected getHandleSuccessFunction<C>(deferred: ng.IDeferred<noosfero.RestResult<C | T | any>>, successEmitter: EventEmitter<T> = null, currentModel: T = null): (response: restangular.IResponse) => void { |
315 | let self = this; | 315 | let self = this; |
316 | 316 | ||
317 | /** | 317 | /** |
@@ -328,7 +328,11 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | @@ -328,7 +328,11 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | ||
328 | deferred.resolve(resultModel); | 328 | deferred.resolve(resultModel); |
329 | // emits the event if a successEmiter was provided in the successEmitter parameter | 329 | // emits the event if a successEmiter was provided in the successEmitter parameter |
330 | if (successEmitter !== null) { | 330 | if (successEmitter !== null) { |
331 | - successEmitter.next(resultModel); | 331 | + if (successEmitter !== this.modelRemovedEventEmitter) { |
332 | + successEmitter.next(resultModel.data); | ||
333 | + } else { | ||
334 | + successEmitter.next(currentModel !== null ? currentModel : resultModel.data); | ||
335 | + } | ||
332 | } | 336 | } |
333 | }; | 337 | }; |
334 | return successFunction; | 338 | return successFunction; |
src/lib/ng-noosfero-api/interfaces/comment.ts
src/plugins/comment_paragraph/allow-comment/allow-comment.component.spec.ts
@@ -3,7 +3,6 @@ import {ComponentTestHelper, createClass} from '../../../spec/component-test-hel | @@ -3,7 +3,6 @@ import {ComponentTestHelper, createClass} from '../../../spec/component-test-hel | ||
3 | import * as helpers from "../../../spec/helpers"; | 3 | import * as helpers from "../../../spec/helpers"; |
4 | import {Provider} from 'ng-forward'; | 4 | import {Provider} from 'ng-forward'; |
5 | import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; | 5 | import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; |
6 | - | ||
7 | let htmlTemplate = '<comment-paragraph-plugin-allow-comment [content]="ctrl.content" [paragraph-uuid]="ctrl.paragraphUuid" [article]="ctrl.article"></comment-paragraph-plugin-allow-comment>'; | 6 | let htmlTemplate = '<comment-paragraph-plugin-allow-comment [content]="ctrl.content" [paragraph-uuid]="ctrl.paragraphUuid" [article]="ctrl.article"></comment-paragraph-plugin-allow-comment>'; |
8 | 7 | ||
9 | describe("Components", () => { | 8 | describe("Components", () => { |
@@ -23,6 +22,7 @@ describe("Components", () => { | @@ -23,6 +22,7 @@ describe("Components", () => { | ||
23 | }; | 22 | }; |
24 | 23 | ||
25 | let providers = [ | 24 | let providers = [ |
25 | + new Provider('CommentService', { useValue: helpers.mocks.commentService } ), | ||
26 | new Provider('CommentParagraphService', { useValue: serviceMock }), | 26 | new Provider('CommentParagraphService', { useValue: serviceMock }), |
27 | new Provider('CommentParagraphEventService', { useValue: eventServiceMock }) | 27 | new Provider('CommentParagraphEventService', { useValue: eventServiceMock }) |
28 | ]; | 28 | ]; |
src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts
@@ -2,24 +2,27 @@ import {Component, Input, Inject} from "ng-forward"; | @@ -2,24 +2,27 @@ import {Component, Input, Inject} from "ng-forward"; | ||
2 | import {SideCommentsComponent} from "../side-comments/side-comments.component"; | 2 | import {SideCommentsComponent} from "../side-comments/side-comments.component"; |
3 | import {CommentParagraphEventService} from "../events/comment-paragraph-event.service"; | 3 | import {CommentParagraphEventService} from "../events/comment-paragraph-event.service"; |
4 | import {CommentParagraphService} from "../http/comment-paragraph.service"; | 4 | import {CommentParagraphService} from "../http/comment-paragraph.service"; |
5 | +import {CommentService} from "./../../../lib/ng-noosfero-api/http/comment.service"; | ||
5 | 6 | ||
6 | @Component({ | 7 | @Component({ |
7 | selector: "comment-paragraph-plugin-allow-comment", | 8 | selector: "comment-paragraph-plugin-allow-comment", |
8 | templateUrl: "plugins/comment_paragraph/allow-comment/allow-comment.html", | 9 | templateUrl: "plugins/comment_paragraph/allow-comment/allow-comment.html", |
9 | directives: [SideCommentsComponent] | 10 | directives: [SideCommentsComponent] |
10 | }) | 11 | }) |
11 | -@Inject("$scope", CommentParagraphEventService, CommentParagraphService) | 12 | +@Inject("$scope", CommentParagraphEventService, CommentParagraphService, CommentService) |
12 | export class AllowCommentComponent { | 13 | export class AllowCommentComponent { |
13 | 14 | ||
14 | @Input() content: string; | 15 | @Input() content: string; |
15 | @Input() paragraphUuid: string; | 16 | @Input() paragraphUuid: string; |
16 | @Input() article: noosfero.Article; | 17 | @Input() article: noosfero.Article; |
17 | - commentsCount: number; | 18 | + commentsCount: number = 0; |
18 | display = false; | 19 | display = false; |
19 | 20 | ||
20 | constructor(private $scope: ng.IScope, | 21 | constructor(private $scope: ng.IScope, |
21 | private commentParagraphEventService: CommentParagraphEventService, | 22 | private commentParagraphEventService: CommentParagraphEventService, |
22 | - private commentParagraphService: CommentParagraphService) { } | 23 | + private commentParagraphService: CommentParagraphService, |
24 | + private commentService: CommentService | ||
25 | + ) { } | ||
23 | 26 | ||
24 | ngOnInit() { | 27 | ngOnInit() { |
25 | this.commentParagraphEventService.subscribeToggleCommentParagraph((article: noosfero.Article) => { | 28 | this.commentParagraphEventService.subscribeToggleCommentParagraph((article: noosfero.Article) => { |
@@ -27,7 +30,19 @@ export class AllowCommentComponent { | @@ -27,7 +30,19 @@ export class AllowCommentComponent { | ||
27 | this.$scope.$apply(); | 30 | this.$scope.$apply(); |
28 | }); | 31 | }); |
29 | this.commentParagraphService.commentParagraphCount(this.article, this.paragraphUuid).then((count: number) => { | 32 | this.commentParagraphService.commentParagraphCount(this.article, this.paragraphUuid).then((count: number) => { |
30 | - this.commentsCount = count; | 33 | + this.commentsCount = count ? count : 0; |
34 | + }); | ||
35 | + | ||
36 | + this.commentService.subscribeToModelAdded((comment: noosfero.CommentParagraph) => { | ||
37 | + if (comment.paragraph_uuid === this.paragraphUuid) { | ||
38 | + this.commentsCount += 1; | ||
39 | + }; | ||
40 | + }); | ||
41 | + | ||
42 | + this.commentService.subscribeToModelRemoved((comment: noosfero.CommentParagraph) => { | ||
43 | + if (comment.paragraph_uuid === this.paragraphUuid) { | ||
44 | + this.commentsCount -= (comment.replies) ? 1 + comment.replies.length : 1; | ||
45 | + }; | ||
31 | }); | 46 | }); |
32 | } | 47 | } |
33 | 48 |
src/plugins/comment_paragraph/models/comment_paragraph.ts
0 → 100644
src/spec/mocks.ts
@@ -85,24 +85,24 @@ export var mocks: any = { | @@ -85,24 +85,24 @@ export var mocks: any = { | ||
85 | mocks.articleService.articleAddedFn = fn; | 85 | mocks.articleService.articleAddedFn = fn; |
86 | }, | 86 | }, |
87 | modelRemovedEventEmitter: | 87 | modelRemovedEventEmitter: |
88 | - { | ||
89 | - subscribe: (fn: Function) => { | ||
90 | - mocks.articleService.articleRemovedFn = fn; | ||
91 | - }, | ||
92 | - next: (param: any) => { | ||
93 | - mocks.articleService.articleRemovedFn(param); | ||
94 | - } | 88 | + { |
89 | + subscribe: (fn: Function) => { | ||
90 | + mocks.articleService.articleRemovedFn = fn; | ||
91 | + }, | ||
92 | + next: (param: any) => { | ||
93 | + mocks.articleService.articleRemovedFn(param); | ||
95 | } | 94 | } |
95 | + } | ||
96 | , | 96 | , |
97 | modelAddedEventEmitter: | 97 | modelAddedEventEmitter: |
98 | - { | ||
99 | - subscribe: (fn: Function) => { | ||
100 | - mocks.articleService.articleAddedFn = fn; | ||
101 | - }, | ||
102 | - next: (param: any) => { | ||
103 | - mocks.articleService.articleAddedFn(param); | ||
104 | - } | 98 | + { |
99 | + subscribe: (fn: Function) => { | ||
100 | + mocks.articleService.articleAddedFn = fn; | ||
101 | + }, | ||
102 | + next: (param: any) => { | ||
103 | + mocks.articleService.articleAddedFn(param); | ||
105 | } | 104 | } |
105 | + } | ||
106 | , | 106 | , |
107 | remove: (article: noosfero.Article) => { | 107 | remove: (article: noosfero.Article) => { |
108 | return { | 108 | return { |
@@ -156,6 +156,34 @@ export var mocks: any = { | @@ -156,6 +156,34 @@ export var mocks: any = { | ||
156 | instant: () => { } | 156 | instant: () => { } |
157 | }, | 157 | }, |
158 | commentService: { | 158 | commentService: { |
159 | + commentRemovedFn: null, | ||
160 | + commentAddedFn: null, | ||
161 | + subscribeToModelRemoved: (fn: Function) => { | ||
162 | + mocks.commentService.commentRemovedFn = fn; | ||
163 | + }, | ||
164 | + subscribeToModelAdded: (fn: Function) => { | ||
165 | + mocks.commentService.commentAddedFn = fn; | ||
166 | + }, | ||
167 | + modelRemovedEventEmitter: | ||
168 | + { | ||
169 | + subscribe: (fn: Function) => { | ||
170 | + mocks.commentService.commentRemovedFn = fn; | ||
171 | + }, | ||
172 | + next: (param: any) => { | ||
173 | + mocks.commentService.commentRemovedFn(param); | ||
174 | + } | ||
175 | + } | ||
176 | + , | ||
177 | + modelAddedEventEmitter: | ||
178 | + { | ||
179 | + subscribe: (fn: Function) => { | ||
180 | + mocks.articleService.commentAddedFn = fn; | ||
181 | + }, | ||
182 | + next: (param: any) => { | ||
183 | + mocks.articleService.commentAddedFn(param); | ||
184 | + } | ||
185 | + } | ||
186 | + , | ||
159 | getByArticle: (article: noosfero.Article) => { | 187 | getByArticle: (article: noosfero.Article) => { |
160 | return Promise.resolve({ data: {} }); | 188 | return Promise.resolve({ data: {} }); |
161 | } | 189 | } |