From 6b394e0b70f581b010d8cc3cc402fd62a55aa9fa Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 10 May 2016 11:10:52 -0300 Subject: [PATCH] Add component to edit comment paragraph discussions --- src/app/article/article-default-view.component.ts | 3 ++- src/app/article/cms/article-editor/article-editor.component.ts | 3 +-- src/lib/ng-noosfero-api/http/article.service.ts | 8 +++++++- src/plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.component.ts | 39 +++++++++++++++++++++++++++++++++++++++ src/plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.html | 35 +++++++++++++++++++++++++++++++++++ src/plugins/comment_paragraph/article/cms/discussion-editor/discussion.scss | 14 ++++++++++++++ src/plugins/comment_paragraph/index.ts | 3 ++- src/plugins/comment_paragraph/languages/en.json | 4 +++- src/plugins/comment_paragraph/languages/pt.json | 4 +++- 9 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 src/plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.component.ts create mode 100644 src/plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.html create mode 100644 src/plugins/comment_paragraph/article/cms/discussion-editor/discussion.scss diff --git a/src/app/article/article-default-view.component.ts b/src/app/article/article-default-view.component.ts index d5a832e..fb55a27 100644 --- a/src/app/article/article-default-view.component.ts +++ b/src/app/article/article-default-view.component.ts @@ -43,7 +43,8 @@ export class ArticleViewComponent { directiveName: string; ngOnInit() { - let specificDirective = 'noosfero' + this.article.type; + let articleType = this.article.type.replace(/::/, ''); + let specificDirective = 'noosfero' + articleType; this.directiveName = "noosfero-default-article"; if (this.$injector.has(specificDirective + 'Directive')) { this.directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); diff --git a/src/app/article/cms/article-editor/article-editor.component.ts b/src/app/article/cms/article-editor/article-editor.component.ts index 8b24331..4cb4592 100644 --- a/src/app/article/cms/article-editor/article-editor.component.ts +++ b/src/app/article/cms/article-editor/article-editor.component.ts @@ -16,8 +16,7 @@ export class ArticleEditorComponent { private $compile: ng.ICompileService) { } ngOnInit() { - let articleType = this.article.type; - articleType = articleType.replace(/::/, ''); + let articleType = this.article.type.replace(/::/, ''); let specificDirective = `${articleType.charAt(0).toLowerCase()}${articleType.substring(1)}Editor`; let directiveName = "article-basic-editor"; if (this.$injector.has(specificDirective + 'Directive')) { diff --git a/src/lib/ng-noosfero-api/http/article.service.ts b/src/lib/ng-noosfero-api/http/article.service.ts index 645494c..1cc7bd5 100644 --- a/src/lib/ng-noosfero-api/http/article.service.ts +++ b/src/lib/ng-noosfero-api/http/article.service.ts @@ -27,7 +27,13 @@ export class ArticleService extends RestangularService { 'Content-Type': 'application/json' }; let deferred = this.$q.defer>(); - let attributesToUpdate: any = { article: { name: article.name, body: article.body, published: article.published } }; + // TODO dynamically copy the selected attributes to update + let attributesToUpdate: any = { + article: { + name: article.name, body: article.body, published: article.published, + start_date: article['start_date'], end_date: article['end_date'] + } + }; let restRequest: ng.IPromise> = this.getElement(article.id).customPOST(attributesToUpdate, null, null, headers); restRequest.then(this.getHandleSuccessFunction(deferred)) .catch(this.getHandleErrorFunction(deferred)); diff --git a/src/plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.component.ts b/src/plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.component.ts new file mode 100644 index 0000000..ed7d9b5 --- /dev/null +++ b/src/plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.component.ts @@ -0,0 +1,39 @@ +import {Component, Input, Inject} from 'ng-forward'; + +@Component({ + selector: 'comment-paragraph-plugin-discussion-editor', + templateUrl: "plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.html" +}) +@Inject("$scope") +export class DiscussionEditorComponent { + + @Input() article: noosfero.Article; + start_date: Date; + end_date: Date; + + constructor(private $scope: ng.IScope) { + this.convertDate('start_date'); + this.convertDate('end_date'); + } + + convertDate(attributeName: string) { + this.$scope.$watch(() => { + return this[attributeName]; + }, () => { + if (this[attributeName]) { + this.article[attributeName] = this[attributeName].toISOString(); + } + }); + } + + ngOnInit() { + if (this.article['start_date']) { + this.start_date = new Date(this.article['start_date']); + } else { + this.start_date = moment().toDate(); + } + if (this.article['end_date']) { + this.end_date = new Date(this.article['end_date']); + } + } +} diff --git a/src/plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.html b/src/plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.html new file mode 100644 index 0000000..33dcdba --- /dev/null +++ b/src/plugins/comment_paragraph/article/cms/discussion-editor/discussion-editor.html @@ -0,0 +1,35 @@ +
+
+ + +
+
+ +
+ + + + + + + + + + + + + + +
+
+
+ + +
+
diff --git a/src/plugins/comment_paragraph/article/cms/discussion-editor/discussion.scss b/src/plugins/comment_paragraph/article/cms/discussion-editor/discussion.scss new file mode 100644 index 0000000..05632a2 --- /dev/null +++ b/src/plugins/comment_paragraph/article/cms/discussion-editor/discussion.scss @@ -0,0 +1,14 @@ +comment-paragraph-plugin-discussion-editor { + .discussion-date { + [uib-datepicker-popup-wrap] { + display: inline-block; + } + .date-popup-button { + @extend .input-group-btn; + display: inline-block; + } + } + .end-date { + margin-left: 60px; + } +} diff --git a/src/plugins/comment_paragraph/index.ts b/src/plugins/comment_paragraph/index.ts index 38d3a84..798c51b 100644 --- a/src/plugins/comment_paragraph/index.ts +++ b/src/plugins/comment_paragraph/index.ts @@ -1,6 +1,7 @@ import {AllowCommentComponent} from "./allow-comment/allow-comment.component"; import {CommentParagraphArticleButtonHotspotComponent} from "./hotspot/comment-paragraph-article-button.component"; import {CommentParagraphFormHotspotComponent} from "./hotspot/comment-paragraph-form.component"; +import {DiscussionEditorComponent} from "./article/cms/discussion-editor/discussion-editor.component"; -export let mainComponents: any = [AllowCommentComponent]; +export let mainComponents: any = [AllowCommentComponent, DiscussionEditorComponent]; export let hotspots: any = [CommentParagraphArticleButtonHotspotComponent, CommentParagraphFormHotspotComponent]; diff --git a/src/plugins/comment_paragraph/languages/en.json b/src/plugins/comment_paragraph/languages/en.json index 4e7f83f..d89f0bf 100644 --- a/src/plugins/comment_paragraph/languages/en.json +++ b/src/plugins/comment_paragraph/languages/en.json @@ -1,3 +1,5 @@ { - "comment-paragraph-plugin.title": "Paragraph Comments" + "comment-paragraph-plugin.title": "Paragraph Comments", + "comment-paragraph-plugin.discussion.editor.start_date.label": "From", + "comment-paragraph-plugin.discussion.editor.end_date.label": "To" } diff --git a/src/plugins/comment_paragraph/languages/pt.json b/src/plugins/comment_paragraph/languages/pt.json index f1ecd5c..43750a3 100644 --- a/src/plugins/comment_paragraph/languages/pt.json +++ b/src/plugins/comment_paragraph/languages/pt.json @@ -1,3 +1,5 @@ { - "comment-paragraph-plugin.title": "Comentários por Parágrafo" + "comment-paragraph-plugin.title": "Comentários por Parágrafo", + "comment-paragraph-plugin.discussion.editor.start_date.label": "De", + "comment-paragraph-plugin.discussion.editor.end_date.label": "Até" } -- libgit2 0.21.2