Skip to content

Commit

Permalink
Merge pull request #27 from hacklabr/develop
Browse files Browse the repository at this point in the history
Develop into master
  • Loading branch information
frclba authored Aug 11, 2020
2 parents 5295141 + 913c5d0 commit 1c5fd0f
Show file tree
Hide file tree
Showing 11 changed files with 1,218 additions and 13 deletions.
26 changes: 13 additions & 13 deletions discussion/static/js/discussion-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:""}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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
}
);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
(function() {
'use strict';
angular.
module('forumSummary').
component('forumSummary', {
templateUrl: '/discussion/forum-summary.template.html',
controller: ForumCtrl,
bindings: {
forum: '<',
},
});

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) {

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;
// });
// }
}
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(function() {
'use strict';

angular.module('forumSummary', [
'discussion.services',
]);

})();
Loading

0 comments on commit 1c5fd0f

Please sign in to comment.