From 0c91f836aa4c5f2cf31f65d64f0c3e8b2196dec2 Mon Sep 17 00:00:00 2001 From: Laury Bueno Date: Fri, 7 Aug 2020 14:59:01 -0300 Subject: [PATCH 1/4] Create a base for new components --- .../forum-summary/forum-summary.component.js | 28 ++ .../forum-summary/forum-summary.module.js | 8 + .../topic-create/topic-create.component.js | 26 ++ .../topic-create/topic-create.module.js | 8 + .../topic-detail/topic-detail.component.js | 34 ++ .../topic-detail/topic-detail.module.js | 8 + .../components/forum-summary.template.html | 201 +++++++++++ .../components/topic-create.template.html | 94 +++++ .../components/topic-detail.template.html | 325 ++++++++++++++++++ discussion/urls.py | 5 + 10 files changed, 737 insertions(+) create mode 100644 discussion/static/js/discussion/forum-summary/forum-summary.component.js create mode 100644 discussion/static/js/discussion/forum-summary/forum-summary.module.js create mode 100644 discussion/static/js/discussion/topic-create/topic-create.component.js create mode 100644 discussion/static/js/discussion/topic-create/topic-create.module.js create mode 100644 discussion/static/js/discussion/topic-detail/topic-detail.component.js create mode 100644 discussion/static/js/discussion/topic-detail/topic-detail.module.js create mode 100644 discussion/templates/components/forum-summary.template.html create mode 100644 discussion/templates/components/topic-create.template.html create mode 100644 discussion/templates/components/topic-detail.template.html diff --git a/discussion/static/js/discussion/forum-summary/forum-summary.component.js b/discussion/static/js/discussion/forum-summary/forum-summary.component.js new file mode 100644 index 0000000..f8f8232 --- /dev/null +++ b/discussion/static/js/discussion/forum-summary/forum-summary.component.js @@ -0,0 +1,28 @@ +(function() { + 'use strict'; + angular. + module('forumSummary'). + component('forumSummary', { + templateUrl: '/discussion/forum-summary.template.html', + controller: 'ForumCtrl', + bindings: {}, + }); + + ForumCtrl.$inject = [ + '$scope', + '$routeParams', + '$http', + '$location', + 'Category', + 'Forum', + 'ForumPage', + 'Tag', + 'Topic', + 'TopicPage', + 'CurrentUser' + ]; + + function ForumCtrl ($scope, $routeParams, $http, $location, Category, Forum, ForumPage, Tag, Topic, TopicPage, CurrentUser) { + + } +})(); \ No newline at end of file diff --git a/discussion/static/js/discussion/forum-summary/forum-summary.module.js b/discussion/static/js/discussion/forum-summary/forum-summary.module.js new file mode 100644 index 0000000..f68fb86 --- /dev/null +++ b/discussion/static/js/discussion/forum-summary/forum-summary.module.js @@ -0,0 +1,8 @@ +(function() { + 'use strict'; + + angular.module('forumSummary', [ + 'discussion.services', + ]); + +})(); \ No newline at end of file diff --git a/discussion/static/js/discussion/topic-create/topic-create.component.js b/discussion/static/js/discussion/topic-create/topic-create.component.js new file mode 100644 index 0000000..c688628 --- /dev/null +++ b/discussion/static/js/discussion/topic-create/topic-create.component.js @@ -0,0 +1,26 @@ +(function() { + 'use strict'; + angular. + module('topicCreate'). + component('topicCreate', { + templateUrl: '/discussion/topic-create.template.html', + controller: 'NewTopicCtrl', + bindings: {}, + }); + + NewTopicCtrl.$inject = [ + '$scope', + '$window', + '$location', + 'Forum', + 'Topic', + 'TopicFile', + 'Category', + 'Tag', + 'ContentFile', + ]; + + function NewTopicCtrl ($scope, $window, $location, Forum, Topic, TopicFile, Category, Tag, ContentFile) { + + } +})(); \ No newline at end of file diff --git a/discussion/static/js/discussion/topic-create/topic-create.module.js b/discussion/static/js/discussion/topic-create/topic-create.module.js new file mode 100644 index 0000000..f878c17 --- /dev/null +++ b/discussion/static/js/discussion/topic-create/topic-create.module.js @@ -0,0 +1,8 @@ +(function() { + 'use strict'; + + angular.module('topicCreate', [ + 'discussion.services', + ]); + +})(); \ No newline at end of file diff --git a/discussion/static/js/discussion/topic-detail/topic-detail.component.js b/discussion/static/js/discussion/topic-detail/topic-detail.component.js new file mode 100644 index 0000000..19c6380 --- /dev/null +++ b/discussion/static/js/discussion/topic-detail/topic-detail.component.js @@ -0,0 +1,34 @@ +(function() { + 'use strict'; + angular. + module('topicDetail'). + component('topicDetail', { + templateUrl: '/discussion/topic-detail.template.html', + controller: 'TopicCtrl', + bindings: {}, + }); + + TopicCtrl.$inject = [ + '$scope', + '$routeParams', + '$sce', + '$location', + '$anchorScroll', + 'Forum', + 'Category', + 'Tag', + 'Topic', + 'TopicFile', + 'TopicRead', + 'Comment', + 'TopicLike', + 'CommentLike', + 'CommentFile', + 'CurrentUser', + 'ContentFile', + ]; + + function TopicCtrl ($scope, $routeParams, $sce, $location, $anchorScroll, Forum, Category, Tag, Topic, TopicFile, TopicRead, Comment, TopicLike, CommentLike, CommentFile, CurrentUser, ContentFile) { + + } +})(); \ No newline at end of file diff --git a/discussion/static/js/discussion/topic-detail/topic-detail.module.js b/discussion/static/js/discussion/topic-detail/topic-detail.module.js new file mode 100644 index 0000000..ab91ce4 --- /dev/null +++ b/discussion/static/js/discussion/topic-detail/topic-detail.module.js @@ -0,0 +1,8 @@ +(function() { + 'use strict'; + + angular.module('topicDetail', [ + 'discussion.services', + ]); + +})(); \ No newline at end of file diff --git a/discussion/templates/components/forum-summary.template.html b/discussion/templates/components/forum-summary.template.html new file mode 100644 index 0000000..48b198d --- /dev/null +++ b/discussion/templates/components/forum-summary.template.html @@ -0,0 +1,201 @@ +{% verbatim %} +
+ +
+
+ + categorias + + + tags + + + opções + +
+
+ + +
+ +
+
+
+ + + +
+
+

Fóruns

+ criar novo tópico + +
+ +
+ +
+
+ +
+
+

Últimas Postagens

+
+
+ +
+
+
+ {{topic.author.first_name || topic.author.username  }} +
+ +
+ Última atividade {{ topic.last_activity_at | dateFilter }} + 1 gostou + 1 comentário +
+
+
+ +
+
+
+
+

+ {{ forum.title }} + +

+
+
+ +
+

Este fórum ainda não possui nenhum tópico.

+
+
+

Nenhum resultado encontrado.

+
+ + +
+ + + + + + + + + + + + + + + + + +
tópicoreaçõescategoriastags
+ {{ topic.title }} + Por {{topic.author.first_name + " " + topic.author.last_name}} | Última atividade {{ topic.last_activity_at | dateFilter }} + + {{ topic.count_replies }} + {{ topic.count_likes }} + + {{ category.name }} + + +
+ +
+ + +
    + + +
      + + +
        +
        + + +
        + +
        +
        +
        + +
          + +
            + +
              +
              +
              +{% endverbatim %} diff --git a/discussion/templates/components/topic-create.template.html b/discussion/templates/components/topic-create.template.html new file mode 100644 index 0000000..a24871f --- /dev/null +++ b/discussion/templates/components/topic-create.template.html @@ -0,0 +1,94 @@ +{% verbatim %} +
              + + +
              +
              +
              +
              +
              Fórum é campo obrigatório
              + +
              Título do tópico é campo obrigatório
              +
              Tópico não pode ser vazio
              +
              +
              +
              +
              + + +
              + +
              +
              +
              +
              +
              + + +
              +
              +
              +
              + + +
              +
              + + +
              +
              + +
              + + +
              +
              +
              + + + + #{{$item.name}} + +
              +
              +
              +
              +
              +
              +
              +
              + +
              +
              + +
              +
              +
              +
              +{% endverbatim %} diff --git a/discussion/templates/components/topic-detail.template.html b/discussion/templates/components/topic-detail.template.html new file mode 100644 index 0000000..1f08b82 --- /dev/null +++ b/discussion/templates/components/topic-detail.template.html @@ -0,0 +1,325 @@ +{% verbatim %} +
              + + +
              +
              +

              {{ error_message }}

              +
              +
              + +
              +
              +
              +
              +
              +
              +
              +

              Editar Tópico

              +
              +
              +
              +
              +
              +
              + + +
              + +
              +
              +
              + + +
              +
              + +
              +
              +

              Carregando formulário...

              +
              + +
              + +
              + +
              + + +
              +
              +
              + + + + #{{$item.name}} + +
              +
              +
              +
              +
              +
              +
              +
              + +
              +
              + + +
              + + +
              +
              + {{ topic.author.name }} +
              + + + + +
              +
              + + +
              +
              +
              +
              + gostei + + comentar + editar tópico + última edição {{ topic.updated_at | date : "d 'de' MMMM 'de' yyyy 'às' HH'h'mm" }} +
              +
              + 1 gostou + 1 comentário + +
              +
              + + +
              +
              +
              +
              +

              Carregando formulário...

              +
              + + + + + + +
              +
              + +
              +

              Comentários

              + +
              +
              + {{ comment.author.name }} +
              +
              + + {{ comment.author.name || comment.author.username}} + +
              +
              + + +
              + +
              +
              +
              +

              Carregando formulário...

              +
              + + + + + + +
              + +
              +
              +
              + gostei + responder + editar + {{ comment.updated_at | date : "d 'de' MMMM 'de' yyyy 'às' HH'h'mm" }} +
              +
              + 1 gostou + +
              +
              + + + +
              +
              + {{ reply.author.name }} +
              +
              +
              + + {{ reply.author.name }} + +
              +
              + + +
              +
              + +
              +
              +
              +

              Carregando formulário...

              +
              + + + + teste + + + + +
              + +
              +
              +
              + gostei + responder + editar + {{ reply.updated_at | date : "d 'de' MMMM 'de' yyyy 'às' HH'h'mm" }} +
              +
              + 1 gostou +
              +
              +
              + + + +
              +
              +
              +
              +

              Carregando formulário...

              +
              + + + + + + +
              +
              + +
              + + +
              +
              +
              +
              +
              +{% endverbatim %} diff --git a/discussion/urls.py b/discussion/urls.py index b9c3af5..4b2548e 100644 --- a/discussion/urls.py +++ b/discussion/urls.py @@ -47,4 +47,9 @@ url(r'^topic/new/', TemplateView.as_view(template_name="forum-new-topic.html")), url(r'^forum/embed/$', TemplateView.as_view(template_name="forum-embed.html")), url(r'^home/$', RedirectView.as_view(url='/discussion/', permanent=False), name='forum-home'), + + # Templates for Angular components + url(r'^forum-summary.template.html', TemplateView.as_view(template_name="components/forum-summary.template.html")), + url(r'^topic-create.template.html', TemplateView.as_view(template_name="components/topic-create.template.html")), + url(r'^topic-detail.template.html', TemplateView.as_view(template_name="components/topic-detail.template.html")), ] From 0695f3f6fe819434f1bc7915a0b199ce0115258f Mon Sep 17 00:00:00 2001 From: Laury Bueno Date: Mon, 10 Aug 2020 15:58:08 -0300 Subject: [PATCH 2/4] [Controller] Remove whitespace --- .../static/js/discussion-controllers.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/discussion/static/js/discussion-controllers.js b/discussion/static/js/discussion-controllers.js index 9f2ee8b..efe3099 100644 --- a/discussion/static/js/discussion-controllers.js +++ b/discussion/static/js/discussion-controllers.js @@ -4,10 +4,10 @@ app.controller('ForumCtrl', ['$scope', '$routeParams', '$http', '$location', 'Category', 'Forum', 'ForumPage', 'Tag', 'Topic', 'TopicPage', 'CurrentUser', function ($scope, $routeParams, $http, $location, Category, Forum, ForumPage, Tag, Topic, TopicPage, CurrentUser) { - + const forum_id = $routeParams.forumId; $scope.user = CurrentUser; - + $scope.forum = {} $scope.topics = {} $scope.search = {txt:""} @@ -90,7 +90,7 @@ $scope.filters.tags = []; $scope.forum_search = false; } - + $scope.forums = ForumPage.get({ search: $scope.current_search, // if there is a search in progress, keep it page: $scope.forum.current_page, @@ -120,7 +120,7 @@ page_size: $scope.forum_topics_page, forum: forum_id, ordering: '-last_activity_at'}, - function(page){ + function(page){ $scope.forum.topics = page.results; $scope.topics_loaded = true; }, @@ -150,7 +150,7 @@ page_size: $scope.forum_topics_page, ordering: '-last_activity_at', ignoreLoadingBar: true}, - function(page){ + function(page){ $scope.forums = []; $scope.forum.title = "Resultados de busca"; $scope.topics.current_page = 1; @@ -219,7 +219,7 @@ if(type === 'cat') { if(operation === 'add') { - $scope.filters.categories.some(obj => obj.name === filter_obj.name) ? + $scope.filters.categories.some(obj => obj.name === filter_obj.name) ? console.log('already filtering by this category') : $scope.filters.categories.push(filter_obj); } @@ -229,8 +229,8 @@ } else { if(operation === 'add') { - $scope.filters.tags.some(obj => obj.name === filter_obj.name) ? - console.log('already filtering by this tag') : + $scope.filters.tags.some(obj => obj.name === filter_obj.name) ? + console.log('already filtering by this tag') : $scope.filters.tags.push(filter_obj); } else { @@ -243,7 +243,7 @@ } set_route(); - + $scope.forums = Forum.query({ // TODO: when single forum, filter only within it categories : $scope.filters.categories.map(function(el) { return el.id; @@ -315,9 +315,9 @@ return false; } - $scope.filter_categories = function(){ + $scope.filter_categories = function(){ $scope.forums.filter(function(t) { - if (t.id == $scope.new_topic.forum) + if (t.id == $scope.new_topic.forum) $scope.forum_category = t.category } ); @@ -358,8 +358,8 @@ $scope.topic = Topic.get({id: $routeParams.topicId}, function(topic){ // Mark topic as read if (topic.categories.length > 0) - $scope.category_id = $scope.topic.categories[0].id; - + $scope.category_id = $scope.topic.categories[0].id; + var topic_read = new TopicRead(); topic_read.topic = topic.id; topic_read.is_read = true; From e4977a7d2bc316a6b0f7055b0bcc32992f4aaf90 Mon Sep 17 00:00:00 2001 From: Laury Bueno Date: Mon, 10 Aug 2020 15:58:40 -0300 Subject: [PATCH 3/4] [Components] Add experimental support for forum summary --- .../forum-summary/forum-summary.component.js | 258 +++++++++++++++++- 1 file changed, 256 insertions(+), 2 deletions(-) diff --git a/discussion/static/js/discussion/forum-summary/forum-summary.component.js b/discussion/static/js/discussion/forum-summary/forum-summary.component.js index f8f8232..2aa7312 100644 --- a/discussion/static/js/discussion/forum-summary/forum-summary.component.js +++ b/discussion/static/js/discussion/forum-summary/forum-summary.component.js @@ -4,8 +4,10 @@ module('forumSummary'). component('forumSummary', { templateUrl: '/discussion/forum-summary.template.html', - controller: 'ForumCtrl', - bindings: {}, + controller: ForumCtrl, + bindings: { + forum: '<', + }, }); ForumCtrl.$inject = [ @@ -24,5 +26,257 @@ function ForumCtrl ($scope, $routeParams, $http, $location, Category, Forum, ForumPage, Tag, Topic, TopicPage, CurrentUser) { + var ctrl = this; + + // const forum_id = $routeParams.forumId; + // $scope.user = CurrentUser; + + // $scope.forum = {} + // $scope.topics = {} + // $scope.search = {txt:""} + // // Pagination Params + // $scope.forum_pages_max_number = 20; + // $scope.forum_topics_page = 20; + // $scope.forum.page_size = 20; + // $scope.forum.current_page = 1 + + // if(forum_id) { + // singleInit(); + // } else { + // normalInit(); + // } + + // function singleInit() { + // Forum.get({id: forum_id}, (forum) => { + // $scope.filters = undefined; + // $scope.forum_search = false; + // $scope.forum_single = true; + // $scope.forums = []; + // $scope.forum = forum; + // $scope.topics.current_page = 1; + // $scope.forum.page = TopicPage.get({ + // page: 1, + // page_size: $scope.forum_topics_page, + // forum: forum_id, + // ordering: '-last_activity_at'}, + // function(page){ + // $scope.forum.topics = page.results; + // $scope.forum_topics_total = page.count; + // $scope.topics_loaded = true; + // }, + // function(err){ + // console.log("Erro ao carregar os tópicos"); + // } + // ); + // $scope.forums.push(forum); // to reuse template's ng-repeat + // },function(err){ + // normalInit(); + // }); + // } + + // function normalInit() { + // $scope.filters = {}; + // $scope.forum_single = false; + // const categoriesParams = $routeParams['categories']; + // const tagParams = $routeParams['tags'] + + // if(categoriesParams || tagParams) { + // if(categoriesParams) { + // if(typeof categoriesParams === 'string' || typeof categoriesParams === 'number') + // $scope.filters.categories = [categoriesParams]; + // else + // $scope.filters.categories = categoriesParams; + + // $scope.filters.categories = $scope.filters.categories.map(function(cat) { + // return angular.fromJson(cat); + // }); + // } + // else { + // $scope.filters.categories = []; + // } + // if(tagParams) { + // if(typeof tagParams === 'string' || typeof tagParams === 'number') + // $scope.filters.tags = [tagParams]; + // else + // $scope.filters.tags = tagParams; + // $scope.filters.tags = $scope.filters.tags.map(function(tag) { + // return angular.fromJson(tag); + // }); + // } + // else { + // $scope.filters.tags = []; + // } + // $scope.forum_search = true; + // } + // else { + // $scope.filters.categories = []; + // $scope.filters.tags = []; + // $scope.forum_search = false; + // } + + // $scope.forums = ForumPage.get({ + // search: $scope.current_search, // if there is a search in progress, keep it + // page: $scope.forum.current_page, + // page_size: $scope.forum.page_size, + // }, (response) => { + // $scope.forums = response.results + // $scope.forum.total_forum_items = response.count + // $scope.forum.max_size = response.length + // $scope.forum_page_loaded = response.$resolved; + // $scope.forum.has_next_page = (response.next !== null || response.previous !== null) + // }); + // $scope.latest_topics = Topic.query({ + // limit: 6, + // ordering: '-last_activity_at', + // }, function(){ + // $scope.topics_loaded = true; + // } + // ); + // } + + + // // Pagination controls + // $scope.topicPageChanged = function(){ + // $scope.forum.page = TopicPage.get({ + // search: $scope.current_search, // if there is a search in progress, keep it + // page: $scope.topics.current_page, + // page_size: $scope.forum_topics_page, + // forum: forum_id, + // ordering: '-last_activity_at'}, + // function(page){ + // $scope.forum.topics = page.results; + // $scope.topics_loaded = true; + // }, + // function(err){ + // console.log("Erro ao carregar os tópicos"); + // } + // ); + // }; + // $scope.forumPageChanged = () => { + // $scope.forums = ForumPage.get({ + // search: $scope.current_search, // if there is a search in progress, keep it + // page: $scope.forum.current_page, + // page_size: $scope.forum.page_size + // }, (response) => { + // $scope.forums = response.results + // $scope.forum.total_forum_items = response.count + // $scope.forum.max_size = response.length + // $scope.forum_page_loaded = response.$resolved; + // }); + // }; + + // $scope.getResults = function(txt) { + // $scope.current_search = txt; + // TopicPage.get({ + // search: txt, + // page: 1, + // page_size: $scope.forum_topics_page, + // ordering: '-last_activity_at', + // ignoreLoadingBar: true}, + // function(page){ + // $scope.forums = []; + // $scope.forum.title = "Resultados de busca"; + // $scope.topics.current_page = 1; + // $scope.forum.topics = page.results; + // $scope.forum_topics_total = page.count; + // $scope.topics_loaded = true; + + // $scope.filters = undefined; + // $scope.forum_search = true; + // $scope.forum_single = false; + // $scope.forums.push($scope.forum); // to reuse template's ng-repeat + + // }, function(err){ + // normalInit(); + // }); + // } + + // function clear_filters() { + // $scope.filters = {}; + // $scope.filters.categories = []; + // $scope.filters.tags = []; + // } + + // $scope.clear_search = () => { + // $scope.forum_search = false; + // $scope.current_search = ""; + // $scope.forums = {} + // $scope.topics_loaded = false; + // $scope.search = {txt:""} + // normalInit() + // } + + // function set_route() { + // var new_url = '#!/'; + // if (forum_id) + // new_url += forum_id; + // var plain_url = true; + // for(var i = 0; i < $scope.filters.categories.length; i++) { + // if (plain_url) + // new_url += '?categories=' + angular.toJson($scope.filters.categories[i]); + // else + // new_url += '&categories=' + angular.toJson($scope.filters.categories[i]); + // plain_url = false; + // } + // for(var i = 0; i < $scope.filters.tags.length; i++) { + // if (plain_url) + // new_url += '?tags=' + angular.toJson($scope.filters.tags[i]); + // else + // new_url += '&tags=' + angular.toJson($scope.filters.tags[i]); + // plain_url = false; + // } + // window.location.hash = new_url; + // } + + // $scope.forumFilter = function(operation, type, filter_obj) { + + // if(!$scope.filters) { + // $scope.filters = {}; + // $scope.filters.categories = [] + // $scope.filters.tags = [] + // } + + // if(operation == 'clear') { + // clear_filters(); + // } + + // if(type === 'cat') { + // if(operation === 'add') { + // $scope.filters.categories.some(obj => obj.name === filter_obj.name) ? + // console.log('already filtering by this category') : + // $scope.filters.categories.push(filter_obj); + // } + // else { + // $scope.filters.categories.splice( $scope.filters.categories.indexOf(filter_obj), 1 ); + // } + // } + // else { + // if(operation === 'add') { + // $scope.filters.tags.some(obj => obj.name === filter_obj.name) ? + // console.log('already filtering by this tag') : + // $scope.filters.tags.push(filter_obj); + // } + // else { + // $scope.filters.tags.splice( $scope.filters.tags.indexOf(filter_obj), 1 ); + // } + // } + + // if($scope.filters.categories.length + $scope.filters.tags.length === 0) { + // clear_filters(); + // } + + // set_route(); + + // $scope.forums = Forum.query({ // TODO: when single forum, filter only within it + // categories : $scope.filters.categories.map(function(el) { + // return el.id; + // }), //array with cat id's + // tags : $scope.filters.tags.map(function(el) { + // return el.id; + // }) //array with tag id's + // }, function(r) { + // $scope.forum_search = true; + // }); + // } } })(); \ No newline at end of file From 913c5d028a69219e6538a156f29cf09885443040 Mon Sep 17 00:00:00 2001 From: Laury Bueno Date: Tue, 11 Aug 2020 13:55:06 -0300 Subject: [PATCH 4/4] [Components] Minor fixes com topic detail --- .../topic-detail/topic-detail.component.js | 220 +++++++++++++++++- .../components/topic-detail.template.html | 26 +-- 2 files changed, 230 insertions(+), 16 deletions(-) diff --git a/discussion/static/js/discussion/topic-detail/topic-detail.component.js b/discussion/static/js/discussion/topic-detail/topic-detail.component.js index 19c6380..fa66102 100644 --- a/discussion/static/js/discussion/topic-detail/topic-detail.component.js +++ b/discussion/static/js/discussion/topic-detail/topic-detail.component.js @@ -4,13 +4,13 @@ module('topicDetail'). component('topicDetail', { templateUrl: '/discussion/topic-detail.template.html', - controller: 'TopicCtrl', + controller: TopicCtrl, bindings: {}, }); TopicCtrl.$inject = [ '$scope', - '$routeParams', + '$stateParams', '$sce', '$location', '$anchorScroll', @@ -28,7 +28,221 @@ 'ContentFile', ]; - function TopicCtrl ($scope, $routeParams, $sce, $location, $anchorScroll, Forum, Category, Tag, Topic, TopicFile, TopicRead, Comment, TopicLike, CommentLike, CommentFile, CurrentUser, ContentFile) { + function TopicCtrl ($scope, $stateParams, $sce, $location, $anchorScroll, Forum, Category, Tag, Topic, TopicFile, TopicRead, Comment, TopicLike, CommentLike, CommentFile, CurrentUser, ContentFile) { + $scope.topic = Topic.get({id: $stateParams.topicId}, function(topic){ + // Mark topic as read + if (topic.categories.length > 0) + $scope.category_id = $scope.topic.categories[0].id; + + var topic_read = new TopicRead(); + topic_read.topic = topic.id; + topic_read.is_read = true; + topic_read.$save(); + + //Filter the topics from Forum + Forum.get({id:$scope.topic.forum}, function(t) { + $scope.forum_categories = t.category; + } + ); + + }, function(error) { + $scope.fatal_error = true; + $scope.error_message = error.data.message; + }); + $scope.user = CurrentUser; + +// uiTinymceConfig.automatic_uploads = true; + +// uiTinymceConfig.images_upload_handler = ContentFile.upload; + + // Prepare for topic editing +// $scope.forums = Forum.query(); + $scope.categories = Category.query(); + $scope.tags = Tag.query(); + // angular.copy($scope.topic, $scope.current_topic); + $scope.update_topic = function() { + $scope.topic.categories = $scope.categories.filter(function(cat) { + return cat.id == $scope.category_id; + }); + var topic_files = $scope.topic.files; + $scope.topic.$update(function(topic){ + angular.forEach(topic_files, function(topic_file) { + if(topic_file instanceof TopicFile){ // Prepare only new files for store in the topic + topic_file.topic = topic.id; + delete topic_file.file; + topic_file.$patch().then(function(comment_file_complete) { + topic.files.push(comment_file_complete); + }); + } + }); + $scope.updating = false; + // Mark topic as read + var topic_read = new TopicRead(); + topic_read.topic = topic.id; + topic_read.is_read = true; + topic_read.$save(); + }); + }; + + $scope.uploadTopicFiles = function (file, topic) { + + if (file) { + TopicFile.upload(file).then(function (response) { + var comment_file = new TopicFile(response.data); + + if (topic.files === undefined) + topic.files = []; + topic.files.push(comment_file); + return {location: comment_file.file}; + }, function (response) { + if (response.status > 0) { + $scope.errorMsg = response.status + ': ' + response.data; + } + }, function (evt) { + topic.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); + }); + } + }; + + // Turn new tags into serializable objects + $scope.tagTransform = function (newTag) { + var item = { + name: newTag.toLowerCase() + }; + return item; + }; + + $scope.tagExists = function (newTag) { + for (var tag of $scope.tags) + if (tag.name.toLowerCase() == newTag) + return true; + return false; + } + + // Bootstrap functions for new comments and replies + $scope.new_comment = function(){ + var comment = new Comment(); + comment.topic = $scope.topic; + return comment; + }; + + $scope.save_comment = function(comment, parent_comment) { + if (parent_comment) { + comment.parent = parent_comment.id; + parent_comment.comment_replies.push(comment); + } else { + comment.topic.comments.push(comment); + } + // Store files to be saved after the comment + var files = []; + angular.copy(comment.files, files); + delete comment.files; + + // Turn the topic object into an id for JSON parsing + comment.topic = comment.topic.id; + + // Send the comment data to be saved by the API + comment.$save().then(function(comment) { + angular.forEach(files, function(comment_file) { + comment_file.comment = comment.id; + delete comment_file.file; + comment_file.$patch().then(function(comment_file_complete) { + comment.files.push(comment_file_complete); + }); + }); + //clear variable to prepare for new comment + comment = $scope.new_comment(); + }, (err) => console.error(err)); + }; + + $scope.update_comment = function(changed_comment) { + var comment_files = changed_comment.files; + + // Get the correct comment instance from the server + Comment.get({id: changed_comment.id}, function(comment){ + comment.text = changed_comment.text; + angular.copy(comment, changed_comment); + comment.$update().then(function(comment) { + angular.forEach(comment_files, function(comment_file) { + if(comment_file instanceof CommentFile){ // Prepare only new files for store in the topic + comment_file.comment = comment.id; + delete comment_file.file; + comment_file.$patch().then(function(comment_file_complete) { + changed_comment.files.push(comment_file_complete); + }); + } + }); + }); + }); + }; + + $scope.topic_like = function(topic) { + if (topic.user_like) { + TopicLike.delete({id:topic.user_like}); + topic.user_like = 0; + topic.count_likes -=1; + } else { + // Change this before promisse so the user sees the action take effect. + topic.user_like = -1; + + TopicLike.save({topic:topic.id}, function(topic_like){ + topic.user_like = topic_like.id; + }); + topic.count_likes +=1 + } + }; + + $scope.comment_like = function(comment) { + if (comment.user_like) { + CommentLike.delete({id:comment.user_like}); + comment.user_like = 0; + comment.count_likes -=1; + } else { + // Change this before promisse so the user sees the action take effect. + comment.user_like = -1; + + CommentLike.save({comment:comment.id}, function(comment_like){ + comment.user_like = comment_like.id; + }); + comment.count_likes +=1 + } + }; + + // uiTinymceConfig.file_browser_callback = function(field_name, url, type, win) { + // if(type=='image') { + // $('#select-file').click(); + // console.log('file_browser_callback called!'); + // } + // }; + // + // uiTinymceConfig.images_upload_handler = function (blobInfo, success, failure) { + // console.log('images_upload_handler called!'); + // }; + + // ng-file-upload + $scope.uploadCommentFiles = function (file, comment) { + + if (file) { + CommentFile.upload(file).then(function (response) { + var comment_file = new CommentFile(response.data); + + if (comment.files === undefined) + comment.files = []; + comment.files.push(comment_file); + return {location: comment_file.file}; + }, function (response) { + if (response.status > 0) { + $scope.errorMsg = response.status + ': ' + response.data; + } + }, function (evt) { + comment.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); + }); + } + } + + $scope.get_as_safe_html = function(html_content) { + return $sce.trustAsHtml(html_content); + } } })(); \ No newline at end of file diff --git a/discussion/templates/components/topic-detail.template.html b/discussion/templates/components/topic-detail.template.html index 1f08b82..ae331e4 100644 --- a/discussion/templates/components/topic-detail.template.html +++ b/discussion/templates/components/topic-detail.template.html @@ -29,7 +29,7 @@

              F
              -
              +
              @@ -107,7 +107,7 @@

              Editar Tópico

              -
              +
              {{ topic.author.name }}
              @@ -132,7 +132,7 @@

              {{ topic.title }} po gostei comentar - editar tópico + editar tópico última edição {{ topic.updated_at | date : "d 'de' MMMM 'de' yyyy 'às' HH'h'mm" }}

              @@ -184,13 +184,13 @@

              Comentários

              {{ comment.author.name || comment.author.username}} -
              +
              -
              +

              Carregando formulário...

              @@ -204,8 +204,8 @@

              Comentários

              ngf-multiple="false">anexar arquivo - + ng-click="update_comment(changed_comment); comment.$ctrl.updating=false">comentar + @@ -217,7 +217,7 @@

              Comentários

              ng-class="{ 'active': comment.user_like }" class="action liked">gostei responder - editar + editar {{ comment.updated_at | date : "d 'de' MMMM 'de' yyyy 'às' HH'h'mm" }}
              @@ -237,7 +237,7 @@

              Comentários

              {{ reply.author.name }}
              -
              +
              {{ reply.author.name }} @@ -248,7 +248,7 @@

              Comentários

              -
              +

              Carregando formulário...

              @@ -264,8 +264,8 @@

              Comentários

              teste - + ng-click="update_comment(changed_reply); reply.$ctrl.updating = false">comentar + @@ -277,7 +277,7 @@

              Comentários

              ng-class="{ 'active': reply.user_like }" class="action liked">gostei responder - editar + editar {{ reply.updated_at | date : "d 'de' MMMM 'de' yyyy 'às' HH'h'mm" }}