mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-13 23:50:28 +01:00
feat(forums): load forums list data
This commit is contained in:
@@ -653,7 +653,10 @@
|
||||
MODERATORS: 'Moderators',
|
||||
DESC: 'Description',
|
||||
CATEGORY: 'Category',
|
||||
READONLY: 'Only oper/admin can post new topic'
|
||||
READONLY: 'Only oper/admin can post new topic',
|
||||
TOPICS: 'Topics',
|
||||
REPLIES: 'Replies',
|
||||
LAST_REPLY: 'Last Reply'
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -653,7 +653,10 @@
|
||||
MODERATORS: '版主',
|
||||
DESC: '描述',
|
||||
CATEGORY: '分类',
|
||||
READONLY: '只有管理员可以发起新话题'
|
||||
READONLY: '只有管理员可以发起新话题',
|
||||
TOPICS: '主题数',
|
||||
REPLIES: '回贴数',
|
||||
LAST_REPLY: '最近回复'
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('forums')
|
||||
.controller('ForumsAdminController', ForumsAdminController);
|
||||
|
||||
ForumsAdminController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'MeanTorrentConfig', 'ForumsAdminService', 'SideOverlay', '$filter', 'NotifycationService',
|
||||
'marked', 'ModalConfirmService'];
|
||||
|
||||
function ForumsAdminController($scope, $state, $translate, Authentication, MeanTorrentConfig, ForumsAdminService, SideOverlay, $filter, NotifycationService,
|
||||
marked, ModalConfirmService) {
|
||||
var vm = this;
|
||||
vm.forumsConfig = MeanTorrentConfig.meanTorrentConfig.forumsConfig;
|
||||
vm.user = Authentication.user;
|
||||
|
||||
vm.addModeratorPopover = {
|
||||
title: 'FORUMS.MODERATOR_TITLE',
|
||||
templateUrl: 'add-moderator.html',
|
||||
items: []
|
||||
};
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
vm.init = function () {
|
||||
ForumsAdminService.query({}, function (items) {
|
||||
vm.forums = items;
|
||||
console.log(items);
|
||||
|
||||
angular.forEach(vm.forums, function (f) {
|
||||
vm.addModeratorPopover.items.push(f._id, false);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* popupCreateForum
|
||||
* @param evt
|
||||
*/
|
||||
vm.popupCreateForum = function (evt) {
|
||||
vm.forum = {
|
||||
name: '',
|
||||
desc: '',
|
||||
category: 'discuss',
|
||||
order: 0,
|
||||
readOnly: false
|
||||
};
|
||||
|
||||
vm.actionTitle = 'FORUMS.BTN_ADD_FORUM';
|
||||
vm.isEdit = false;
|
||||
vm.categoryChanged();
|
||||
SideOverlay.open(evt, 'popupSlide');
|
||||
};
|
||||
/**
|
||||
* popupEditForum
|
||||
* @param evt
|
||||
* @param f: forum
|
||||
*/
|
||||
vm.popupEditForum = function (evt, f) {
|
||||
if (f) {
|
||||
vm.forum = new ForumsAdminService(f);
|
||||
vm.actionTitle = 'FORUMS.BTN_EDIT_FORUM';
|
||||
vm.isEdit = true;
|
||||
SideOverlay.open(evt, 'popupSlide');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
vm.categoryChanged = function () {
|
||||
vm.selectedForums = $filter('filter')(vm.forums, {
|
||||
category: vm.forum.category
|
||||
});
|
||||
|
||||
vm.forum.order = vm.selectedForums.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* createNewForum
|
||||
*/
|
||||
vm.createNewForum = function () {
|
||||
var f = new ForumsAdminService(vm.forum);
|
||||
f.$save(function (res) {
|
||||
NotifycationService.showSuccessNotify('FORUMS.ADD_SUCCESSFULLY');
|
||||
vm.forum = undefined;
|
||||
SideOverlay.close(null, 'popupSlide');
|
||||
vm.init();
|
||||
}, function (res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.ADD_FAILED');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* editForum
|
||||
*/
|
||||
vm.editForum = function () {
|
||||
vm.forum.$update(function (res) {
|
||||
NotifycationService.showSuccessNotify('FORUMS.EDIT_SUCCESSFULLY');
|
||||
vm.forum = undefined;
|
||||
SideOverlay.close(null, 'popupSlide');
|
||||
vm.init();
|
||||
}, function (res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.EDIT_FAILED');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* deleteForum
|
||||
*/
|
||||
vm.deleteForum = function () {
|
||||
var modalOptions = {
|
||||
closeButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_CANCEL'),
|
||||
actionButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_OK'),
|
||||
headerText: $translate.instant('FORUMS.DELETE_CONFIRM_HEADER_TEXT'),
|
||||
bodyText: $translate.instant('FORUMS.DELETE_CONFIRM_BODY_TEXT')
|
||||
};
|
||||
|
||||
ModalConfirmService.showModal({}, modalOptions)
|
||||
.then(function (result) {
|
||||
vm.forum.$remove(function (res) {
|
||||
NotifycationService.showSuccessNotify('FORUMS.DELETE_SUCCESSFULLY');
|
||||
vm.forum = undefined;
|
||||
SideOverlay.close(null, 'popupSlide');
|
||||
vm.init();
|
||||
}, function (res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.DELETE_FAILED');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* getForumDesc
|
||||
* @param f: forum
|
||||
* @returns {*}
|
||||
*/
|
||||
vm.getForumDesc = function (f) {
|
||||
if (f) {
|
||||
return marked(f.desc, {sanitize: true});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* addModerator
|
||||
*/
|
||||
vm.addModerator = function () {
|
||||
ForumsAdminService.addModerator({
|
||||
_id: vm.forum._id,
|
||||
_username: vm.addModeratorPopover.username
|
||||
}, function (res) {
|
||||
NotifycationService.showSuccessNotify('FORUMS.ADD_MODERATOR_SUCCESSFULLY');
|
||||
vm.addModeratorPopover.items[vm.forum._id] = false;
|
||||
vm.init();
|
||||
}, function (res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.ADD_MODERATOR_FAILED');
|
||||
vm.addModeratorPopover.items[vm.forum._id] = false;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* addModeratorClicked
|
||||
* @param f: forum
|
||||
*/
|
||||
vm.addModeratorClicked = function (f) {
|
||||
vm.addModeratorPopover.username = undefined;
|
||||
vm.addModeratorPopover.items[f._id] = true;
|
||||
|
||||
vm.forum = f;
|
||||
};
|
||||
|
||||
/**
|
||||
* removeModeratorClicked
|
||||
* @param f forum
|
||||
* @param m moderator
|
||||
*/
|
||||
vm.removeModeratorClicked = function (f, m) {
|
||||
var modalOptions = {
|
||||
closeButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_CANCEL'),
|
||||
actionButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_OK'),
|
||||
headerText: $translate.instant('FORUMS.DELETE_CONFIRM_HEADER_TEXT'),
|
||||
bodyText: $translate.instant('FORUMS.REMOVE_CONFIRM_BODY_TEXT')
|
||||
};
|
||||
|
||||
ModalConfirmService.showModal({}, modalOptions)
|
||||
.then(function (result) {
|
||||
ForumsAdminService.removeModerator({
|
||||
_id: f._id,
|
||||
_username: m.username
|
||||
}, function (res) {
|
||||
NotifycationService.showSuccessNotify('FORUMS.REMOVE_MODERATOR_SUCCESSFULLY');
|
||||
vm.init();
|
||||
}, function (res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.REMOVE_MODERATOR_FAILED');
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
}());
|
||||
@@ -5,131 +5,24 @@
|
||||
.module('forums')
|
||||
.controller('ForumsController', ForumsController);
|
||||
|
||||
ForumsController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'MeanTorrentConfig', 'ForumsAdminService', 'SideOverlay', '$filter', 'NotifycationService',
|
||||
ForumsController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'MeanTorrentConfig', 'ForumsService', 'SideOverlay', '$filter', 'NotifycationService',
|
||||
'marked', 'ModalConfirmService'];
|
||||
|
||||
function ForumsController($scope, $state, $translate, Authentication, MeanTorrentConfig, ForumsAdminService, SideOverlay, $filter, NotifycationService,
|
||||
function ForumsController($scope, $state, $translate, Authentication, MeanTorrentConfig, ForumsService, SideOverlay, $filter, NotifycationService,
|
||||
marked, ModalConfirmService) {
|
||||
var vm = this;
|
||||
vm.forumsConfig = MeanTorrentConfig.meanTorrentConfig.forumsConfig;
|
||||
vm.user = Authentication.user;
|
||||
|
||||
vm.addModeratorPopover = {
|
||||
title: 'FORUMS.MODERATOR_TITLE',
|
||||
templateUrl: 'add-moderator.html',
|
||||
items: []
|
||||
};
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
vm.init = function () {
|
||||
ForumsAdminService.query({}, function (items) {
|
||||
ForumsService.query({}, function (items) {
|
||||
vm.forums = items;
|
||||
console.log(items);
|
||||
|
||||
angular.forEach(vm.forums, function (f) {
|
||||
vm.addModeratorPopover.items.push(f._id, false);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* popupCreateForum
|
||||
* @param evt
|
||||
*/
|
||||
vm.popupCreateForum = function (evt) {
|
||||
vm.forum = {
|
||||
name: '',
|
||||
desc: '',
|
||||
category: 'discuss',
|
||||
order: 0,
|
||||
readOnly: false
|
||||
};
|
||||
|
||||
vm.actionTitle = 'FORUMS.BTN_ADD_FORUM';
|
||||
vm.isEdit = false;
|
||||
vm.categoryChanged();
|
||||
SideOverlay.open(evt, 'popupSlide');
|
||||
};
|
||||
/**
|
||||
* popupEditForum
|
||||
* @param evt
|
||||
* @param f: forum
|
||||
*/
|
||||
vm.popupEditForum = function (evt, f) {
|
||||
if (f) {
|
||||
vm.forum = new ForumsAdminService(f);
|
||||
vm.actionTitle = 'FORUMS.BTN_EDIT_FORUM';
|
||||
vm.isEdit = true;
|
||||
SideOverlay.open(evt, 'popupSlide');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
vm.categoryChanged = function () {
|
||||
vm.selectedForums = $filter('filter')(vm.forums, {
|
||||
category: vm.forum.category
|
||||
});
|
||||
|
||||
vm.forum.order = vm.selectedForums.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* createNewForum
|
||||
*/
|
||||
vm.createNewForum = function () {
|
||||
var f = new ForumsAdminService(vm.forum);
|
||||
f.$save(function (res) {
|
||||
NotifycationService.showSuccessNotify('FORUMS.ADD_SUCCESSFULLY');
|
||||
vm.forum = undefined;
|
||||
SideOverlay.close(null, 'popupSlide');
|
||||
vm.init();
|
||||
}, function (res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.ADD_FAILED');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* editForum
|
||||
*/
|
||||
vm.editForum = function () {
|
||||
vm.forum.$update(function (res) {
|
||||
NotifycationService.showSuccessNotify('FORUMS.EDIT_SUCCESSFULLY');
|
||||
vm.forum = undefined;
|
||||
SideOverlay.close(null, 'popupSlide');
|
||||
vm.init();
|
||||
}, function (res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.EDIT_FAILED');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* deleteForum
|
||||
*/
|
||||
vm.deleteForum = function () {
|
||||
var modalOptions = {
|
||||
closeButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_CANCEL'),
|
||||
actionButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_OK'),
|
||||
headerText: $translate.instant('FORUMS.DELETE_CONFIRM_HEADER_TEXT'),
|
||||
bodyText: $translate.instant('FORUMS.DELETE_CONFIRM_BODY_TEXT')
|
||||
};
|
||||
|
||||
ModalConfirmService.showModal({}, modalOptions)
|
||||
.then(function (result) {
|
||||
vm.forum.$remove(function (res) {
|
||||
NotifycationService.showSuccessNotify('FORUMS.DELETE_SUCCESSFULLY');
|
||||
vm.forum = undefined;
|
||||
SideOverlay.close(null, 'popupSlide');
|
||||
vm.init();
|
||||
}, function (res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.DELETE_FAILED');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* getForumDesc
|
||||
* @param f: forum
|
||||
@@ -141,59 +34,5 @@
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* addModerator
|
||||
*/
|
||||
vm.addModerator = function () {
|
||||
ForumsAdminService.addModerator({
|
||||
_id: vm.forum._id,
|
||||
_username: vm.addModeratorPopover.username
|
||||
}, function (res) {
|
||||
NotifycationService.showSuccessNotify('FORUMS.ADD_MODERATOR_SUCCESSFULLY');
|
||||
vm.addModeratorPopover.items[vm.forum._id] = false;
|
||||
vm.init();
|
||||
}, function (res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.ADD_MODERATOR_FAILED');
|
||||
vm.addModeratorPopover.items[vm.forum._id] = false;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* addModeratorClicked
|
||||
* @param f: forum
|
||||
*/
|
||||
vm.addModeratorClicked = function (f) {
|
||||
vm.addModeratorPopover.username = undefined;
|
||||
vm.addModeratorPopover.items[f._id] = true;
|
||||
|
||||
vm.forum = f;
|
||||
};
|
||||
|
||||
/**
|
||||
* removeModeratorClicked
|
||||
* @param f forum
|
||||
* @param m moderator
|
||||
*/
|
||||
vm.removeModeratorClicked = function (f, m) {
|
||||
var modalOptions = {
|
||||
closeButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_CANCEL'),
|
||||
actionButtonText: $translate.instant('FORUMS.DELETE_CONFIRM_OK'),
|
||||
headerText: $translate.instant('FORUMS.DELETE_CONFIRM_HEADER_TEXT'),
|
||||
bodyText: $translate.instant('FORUMS.REMOVE_CONFIRM_BODY_TEXT')
|
||||
};
|
||||
|
||||
ModalConfirmService.showModal({}, modalOptions)
|
||||
.then(function (result) {
|
||||
ForumsAdminService.removeModerator({
|
||||
_id: f._id,
|
||||
_username: m.username
|
||||
}, function (res) {
|
||||
NotifycationService.showSuccessNotify('FORUMS.REMOVE_MODERATOR_SUCCESSFULLY');
|
||||
vm.init();
|
||||
}, function (res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.REMOVE_MODERATOR_FAILED');
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
||||
<section class="container padding-top-10" ng-controller="ForumsController as vm" ng-init="vm.init();">
|
||||
<section class="container padding-top-10" ng-controller="ForumsAdminController as vm" ng-init="vm.init();">
|
||||
<div class="row margin-top-20 forum-list">
|
||||
<div class="col-md-10 col-md-offset-1">
|
||||
<button class="btn btn-success" ng-click="vm.popupCreateForum($event)"> {{ 'FORUMS.BTN_ADD_FORUM' | translate }} </button>
|
||||
@@ -7,7 +7,7 @@
|
||||
<div class="col-sm-10 col-sm-offset-1">
|
||||
<div class="panel panel-default margin-top-30" ng-repeat="cat in vm.forumsConfig.category">
|
||||
<div class="panel-heading text-center mt-title">
|
||||
<strong>{{ 'FORUMS.CATEGORY.'+cat.name | translate }}</strong>
|
||||
<h3 class="panel-title">{{ 'FORUMS.CATEGORY.'+cat.name | translate }}</h3>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
@@ -21,7 +21,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="f in vm.forums | filter: { category: cat.value }">
|
||||
<td scope="row">
|
||||
<td>
|
||||
<h4>{{f.name}} <span class="badge badge_mt" ng-show="f.readOnly">R</span>
|
||||
<small>[<a href="#" ng-click="vm.popupEditForum($event, f);">{{'FORUMS.LINK_EDIT' | translate}}</a>]</small>
|
||||
<small>[<a href="#"
|
||||
|
||||
@@ -1,2 +1,72 @@
|
||||
<section class="container padding-top-10" ng-controller="ForumsController as vm" ng-init="vm.init();">
|
||||
<section ng-controller="ForumsController as vm" ng-init="vm.init();">
|
||||
<div class="pagetop">
|
||||
<div class="container">
|
||||
<div class="col-sm-8">
|
||||
<div class="page-header">
|
||||
<h1>meanTorrent Forums</h1>
|
||||
|
||||
<p class="text-muted">Welcome to meanTorrent forums!</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div class="page-header padding-top-10">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" aria-label="search" placeholder="Search">
|
||||
|
||||
<div class="input-group-btn">
|
||||
<button type="button" class="btn btn-default" aria-label="Search"><span class="glyphicon glyphicon-search"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!--<p class="text-muted margin-top-10">Welcome to meanTorrent forums!</p>-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container forum-list">
|
||||
<div class="path margin-top-20">
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="#"><span class="small glyphicon glyphicon-home"></span> Forums</a></li>
|
||||
<!--<li><a href="#">Library</a></li>-->
|
||||
<!--<li class="active">Data</li>-->
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive table-category" ng-repeat="cat in vm.forumsConfig.category">
|
||||
<table class="table table-hover table-valign-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="col-md-7">{{'FORUMS.CATEGORY.'+cat.name | translate}}</th>
|
||||
<th class="text-center">{{'FORUMS.FIELDS.TOPICS' | translate}}</th>
|
||||
<th class="text-center">{{'FORUMS.FIELDS.REPLIES' | translate}}</th>
|
||||
<th class="text-center">{{'FORUMS.FIELDS.LAST_REPLY' | translate}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="f in vm.forums | filter: { category: cat.value }">
|
||||
<td>
|
||||
<span class="forum-icon glyphicon glyphicon-folder-open"></span>
|
||||
|
||||
<div class="forum-info">
|
||||
<h4><a href="#">{{f.name}}</a>
|
||||
<small class="badge badge_mt" ng-show="f.readOnly">R</small>
|
||||
</h4>
|
||||
|
||||
<p class="forum-desc" ng-bind-html="vm.getForumDesc(f);"></p>
|
||||
|
||||
<p>{{'FORUMS.FIELDS.MODERATORS' | translate}}: <span ng-repeat="m in f.moderators">{{m.username}} </span></p>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-center">{{f.topicCount}}</td>
|
||||
<td class="text-center">{{f.replyCount}}</td>
|
||||
<td class="text-center">
|
||||
<div class="last-reply">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -20,7 +20,8 @@ var path = require('path'),
|
||||
exports.list = function (req, res) {
|
||||
Forum.find()
|
||||
.sort('order -createdat')
|
||||
.populate('lastTopic')
|
||||
.populate('lastNewTopic')
|
||||
.populate('lastReplyTopic')
|
||||
.populate('moderators', 'username displayName profileImageURL uploaded downloaded')
|
||||
.exec(function (err, forums) {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user