Skip to content

Issues-479:Watch functionality changes #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions Topcoder/controllers/class.watchingcontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php
/**
* Watching controller
*
*/

/**
* Handles displaying watched discussions and watched categories
*
*/
class WatchingController extends VanillaController {

/** @var arrayModels to include. */
public $Uses = ['Database', 'DiscussionModel', 'Form'];

/**
* Highlight route and include JS, CSS, and modules used by all methods.
*
* Always called by dispatcher before controller's requested method.
*
* @since 2.0.0
* @access public
*/
public function initialize() {
parent::initialize();
$this->Menu->highlightRoute('/watching');

/**
* The default Cache-Control header does not include no-store, which can cause issues (e.g. inaccurate unread
* status or new comment counts) when users visit the discussion list via the browser's back button. The same
* check is performed here as in Gdn_Controller before the Cache-Control header is added, but this value
* includes the no-store specifier.
*/
if (Gdn::session()->isValid()) {
$this->setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate');
}

$this->CountCommentsPerPage = c('Vanilla.Comments.PerPage', 30);
$this->fireEvent('AfterInitialize');
}

/**
* Display categorioes and discussions the user has watched
*
* @param string $cp Category page
* @param string $dp Discussion page
* @throws Exception
*/
public function index($cp = '', $dp = '') {
$this->addJsFile('jquery.gardenmorepager.js');
$this->addJsFile('topcoder.js');
$this->permission('Garden.SignIn.Allow');
Gdn_Theme::section('CategoryList');

// Sort filter is used for categories and discussions
$sort = Gdn::request()->get('sort', null);
$saveSorting = $sort !== null && Gdn::request()->get('save') && Gdn::session()->validateTransientKey(Gdn::request()->get('TransientKey', ''));
if($saveSorting) {
Gdn::session()->setPreference('CategorySort', $sort);
}
$sort = Gdn::session()->getPreference('CategorySort', false);
$this->setData('CategorySort', $sort);

$userMetaModel = new UserMetaModel();
list($cp, $categoryLimit) = offsetLimit($cp, 30);

// Validate Category Page
if (!is_numeric($cp) || $cp < 0) {
$cp = 0;
}
$categorySort = $sort == 'old'? 'asc': 'desc';
$watchedCategoryIDs = $userMetaModel->getWatchedCategories(Gdn::session()->UserID, $categorySort, $categoryLimit, $cp);
$countOfWatchedCategories = $userMetaModel->userWatchedCategoriesCount(Gdn::session()->UserID);

$categories = [];
$categoryModel = new CategoryModel();
foreach ($watchedCategoryIDs as $item) {
$category = CategoryModel::categories(val('CategoryID', $item));
// $category['Archived']
// if (!$category['PermsDiscussionsView']) {
// continue;
// }
$categories[] = $category;
}
$categoryModel->joinRecent($categories);
$this->setData('WatchedCategories', $categories);
$this->setData('CountWatchedCategories', $countOfWatchedCategories);

$pagerFactory = new Gdn_PagerFactory();
$this->WatchedCategoriesPager = $pagerFactory->getPager('MorePager', $this);
$this->WatchedCategoriesPager->ClientID='WatchingCategories';
$this->WatchedCategoriesPager->MoreCode = 'More Categories';
$this->WatchedCategoriesPager->configure($cp,
$categoryLimit,
$countOfWatchedCategories,
'watching?cp={Page}'
);

Gdn_Theme::section('DiscussionList');

list($dp, $discussionlimit) = offsetLimit($dp, 30);
if (!is_numeric($dp) || $dp < 0) {
$dp = 0;
}

$discussionModel = new DiscussionModel();
$discussionModel->setSort($sort);
$discussionModel->setFilters(Gdn::request()->get());
$wheres = [
'w.Bookmarked' => '1',
'w.UserID' => Gdn::session()->UserID
];

$this->DiscussionData = $discussionModel->get($dp, $discussionlimit, $wheres);
$this->setData('Discussions', $this->DiscussionData);
$countDiscussions = $discussionModel->getCount($wheres);
$this->setData('CountDiscussions', $countDiscussions);

$pagerFactory = new Gdn_PagerFactory();
$this->DiscussionPager = $pagerFactory->getPager('MorePager', $this);
$this->DiscussionPager->ClientID='WatchingDiscussions';
$this->DiscussionPager->MoreCode = 'More Discussions';
$this->DiscussionPager->configure($dp,
$discussionlimit,
$countDiscussions,
'watching?dp={Page}');

$this->allowJSONP(true);

// Deliver JSON data if necessary
if ($this->deliveryType() != DELIVERY_TYPE_ALL) {
if ($dp > 0) {
//$this->setJson('LessRow', $this->DiscussionPager->toString('less'));
$this->setJson('MoreRow', $this->DiscussionPager->toString('more'));
$this->setJson('Loading', $dp.' to '.$discussionlimit);
$this->View = 'discussions';
} else if($cp > 0) {
//$this->setJson('LessRow', $this->WatchedCategoriesPager->toString('less'));
$this->setJson('MoreRow', $this->WatchedCategoriesPager->toString('more'));
$this->setJson('Loading', $cp.' to '.$categoryLimit);
$this->View = 'categories';
}

}

$this->canonicalUrl(url('/watching', true));

// Add modules
$this->addModule('DiscussionFilterModule');

// Render default view
$this->setData('Title', t('Watching'));
$this->setData('Breadcrumbs', [['Name' => t('Watching'), 'Url' => '/watching']]);

$this->render();
}
}
19 changes: 19 additions & 0 deletions Topcoder/design/topcoder.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,22 @@ a:hover span.challengeRoles {
padding: 0px 0px;
text-transform: none;
}

.Topcoder h2.HomepageTitle {
font-family: Barlow_Condensed, Helvetica, Arial, sans-serif;
font-weight: 500;
color: #2a2a2a !important;
font-size: 24px !important;
font-weight: 500 !important;
line-height: 28px !important;
text-transform: uppercase !important;
}
.Topcoder h1.HomepageTitle {
font-family: Barlow_Condensed, Helvetica, Arial, sans-serif;
font-weight: 500;
color: #2a2a2a !important;
font-size: 34px !important;
font-weight: 500 !important;
line-height: 38px !important;
text-transform: uppercase !important;
}
21 changes: 21 additions & 0 deletions Topcoder/js/topcoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
jQuery(document).ready(function($) {

// Set up paging
if ($.morepager) {

$('#WatchingDiscussionsMore').morepager({
pageContainerSelector: 'ul.Discussions:last',
afterPageLoaded: function() {
$(document).trigger('DiscussionPagingComplete');
}
});

// profile/discussions paging
$('#WatchingCategoriesMore').morepager({
pageContainerSelector: 'ul.WatchedCategoryList:last',
afterPageLoaded: function() {
$(document).trigger('DiscussionPagingComplete');
}
});
}
});
14 changes: 14 additions & 0 deletions Topcoder/views/watching/categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php if (!defined('APPLICATION')) exit();
$Session = Gdn::session();
include_once $this->fetchViewLocation('helper_functions', 'categories', 'vanilla');

if($this->data('WatchedCategories')) {
$categories = $this->data('WatchedCategories');
?>
<?php
foreach ($categories as $category) {
writeListItem($category, 1);
}
?>
<?php
}
11 changes: 11 additions & 0 deletions Topcoder/views/watching/discussions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php if (!defined('APPLICATION')) exit();
$Session = Gdn::session();
include_once $this->fetchViewLocation('helper_functions', 'discussions', 'vanilla');

if ($this->data('Discussions')->numRows() > 0) {
?>

<?php include($this->fetchViewLocation('discussions', 'Discussions', 'Vanilla')); ?>

<?php
}
43 changes: 43 additions & 0 deletions Topcoder/views/watching/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php if (!defined('APPLICATION')) exit();
$Session = Gdn::session();
include_once $this->fetchViewLocation('helper_functions', 'discussions', 'vanilla');
include_once $this->fetchViewLocation('helper_functions', 'categories', 'vanilla');

echo '<h1 class="H HomepageTitle">'.
adminCheck(NULL, ['', ' ']).
$this->data('Title').
'</h1>';

$this->fireEvent('AfterPageTitle');
echo '<div class="PageControls Top">';
echo categorySorts();
echo '</div>';

if($this->data('WatchedCategories')) {
echo '<h2 class="H HomepageTitle">Categories</h2>';
$categories = $this->data('WatchedCategories');
?>
<ul class="DataList CategoryList WatchedCategoryList">
<?php
foreach ($categories as $category) {
writeListItem($category, 1);
}
?>
</ul>
<?php
echo $this->WatchedCategoriesPager->toString('more');
}

if ($this->data('Discussions')->numRows() > 0) {
echo '<h2 class="H HomepageTitle">Discussions</h2>';
?>
<ul class="DataList Discussions">
<?php include($this->fetchViewLocation('discussions', 'Discussions', 'Vanilla'));
?>
</ul>
<?php
echo $this->DiscussionPager->toString('more');
}