Skip to content

Commit 4a88c38

Browse files
authored
Merge pull request #78 from topcoder-platform/issues-508
Issues-479:Watch functionality changes
2 parents dd92114 + dab1e16 commit 4a88c38

File tree

6 files changed

+265
-0
lines changed

6 files changed

+265
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?php
2+
/**
3+
* Watching controller
4+
*
5+
*/
6+
7+
/**
8+
* Handles displaying watched discussions and watched categories
9+
*
10+
*/
11+
class WatchingController extends VanillaController {
12+
13+
/** @var arrayModels to include. */
14+
public $Uses = ['Database', 'DiscussionModel', 'Form'];
15+
16+
/**
17+
* Highlight route and include JS, CSS, and modules used by all methods.
18+
*
19+
* Always called by dispatcher before controller's requested method.
20+
*
21+
* @since 2.0.0
22+
* @access public
23+
*/
24+
public function initialize() {
25+
parent::initialize();
26+
$this->Menu->highlightRoute('/watching');
27+
28+
/**
29+
* The default Cache-Control header does not include no-store, which can cause issues (e.g. inaccurate unread
30+
* status or new comment counts) when users visit the discussion list via the browser's back button. The same
31+
* check is performed here as in Gdn_Controller before the Cache-Control header is added, but this value
32+
* includes the no-store specifier.
33+
*/
34+
if (Gdn::session()->isValid()) {
35+
$this->setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate');
36+
}
37+
38+
$this->CountCommentsPerPage = c('Vanilla.Comments.PerPage', 30);
39+
$this->fireEvent('AfterInitialize');
40+
}
41+
42+
/**
43+
* Display categorioes and discussions the user has watched
44+
*
45+
* @param string $cp Category page
46+
* @param string $dp Discussion page
47+
* @throws Exception
48+
*/
49+
public function index($cp = '', $dp = '') {
50+
$this->addJsFile('jquery.gardenmorepager.js');
51+
$this->addJsFile('topcoder.js');
52+
$this->permission('Garden.SignIn.Allow');
53+
Gdn_Theme::section('CategoryList');
54+
55+
// Sort filter is used for categories and discussions
56+
$sort = Gdn::request()->get('sort', null);
57+
$saveSorting = $sort !== null && Gdn::request()->get('save') && Gdn::session()->validateTransientKey(Gdn::request()->get('TransientKey', ''));
58+
if($saveSorting) {
59+
Gdn::session()->setPreference('CategorySort', $sort);
60+
}
61+
$sort = Gdn::session()->getPreference('CategorySort', false);
62+
$this->setData('CategorySort', $sort);
63+
64+
$userMetaModel = new UserMetaModel();
65+
list($cp, $categoryLimit) = offsetLimit($cp, 30);
66+
67+
// Validate Category Page
68+
if (!is_numeric($cp) || $cp < 0) {
69+
$cp = 0;
70+
}
71+
$categorySort = $sort == 'old'? 'asc': 'desc';
72+
$watchedCategoryIDs = $userMetaModel->getWatchedCategories(Gdn::session()->UserID, $categorySort, $categoryLimit, $cp);
73+
$countOfWatchedCategories = $userMetaModel->userWatchedCategoriesCount(Gdn::session()->UserID);
74+
75+
$categories = [];
76+
$categoryModel = new CategoryModel();
77+
foreach ($watchedCategoryIDs as $item) {
78+
$category = CategoryModel::categories(val('CategoryID', $item));
79+
// $category['Archived']
80+
// if (!$category['PermsDiscussionsView']) {
81+
// continue;
82+
// }
83+
$categories[] = $category;
84+
}
85+
$categoryModel->joinRecent($categories);
86+
$this->setData('WatchedCategories', $categories);
87+
$this->setData('CountWatchedCategories', $countOfWatchedCategories);
88+
89+
$pagerFactory = new Gdn_PagerFactory();
90+
$this->WatchedCategoriesPager = $pagerFactory->getPager('MorePager', $this);
91+
$this->WatchedCategoriesPager->ClientID='WatchingCategories';
92+
$this->WatchedCategoriesPager->MoreCode = 'More Categories';
93+
$this->WatchedCategoriesPager->configure($cp,
94+
$categoryLimit,
95+
$countOfWatchedCategories,
96+
'watching?cp={Page}'
97+
);
98+
99+
Gdn_Theme::section('DiscussionList');
100+
101+
list($dp, $discussionlimit) = offsetLimit($dp, 30);
102+
if (!is_numeric($dp) || $dp < 0) {
103+
$dp = 0;
104+
}
105+
106+
$discussionModel = new DiscussionModel();
107+
$discussionModel->setSort($sort);
108+
$discussionModel->setFilters(Gdn::request()->get());
109+
$wheres = [
110+
'w.Bookmarked' => '1',
111+
'w.UserID' => Gdn::session()->UserID
112+
];
113+
114+
$this->DiscussionData = $discussionModel->get($dp, $discussionlimit, $wheres);
115+
$this->setData('Discussions', $this->DiscussionData);
116+
$countDiscussions = $discussionModel->getCount($wheres);
117+
$this->setData('CountDiscussions', $countDiscussions);
118+
119+
$pagerFactory = new Gdn_PagerFactory();
120+
$this->DiscussionPager = $pagerFactory->getPager('MorePager', $this);
121+
$this->DiscussionPager->ClientID='WatchingDiscussions';
122+
$this->DiscussionPager->MoreCode = 'More Discussions';
123+
$this->DiscussionPager->configure($dp,
124+
$discussionlimit,
125+
$countDiscussions,
126+
'watching?dp={Page}');
127+
128+
$this->allowJSONP(true);
129+
130+
// Deliver JSON data if necessary
131+
if ($this->deliveryType() != DELIVERY_TYPE_ALL) {
132+
if ($dp > 0) {
133+
//$this->setJson('LessRow', $this->DiscussionPager->toString('less'));
134+
$this->setJson('MoreRow', $this->DiscussionPager->toString('more'));
135+
$this->setJson('Loading', $dp.' to '.$discussionlimit);
136+
$this->View = 'discussions';
137+
} else if($cp > 0) {
138+
//$this->setJson('LessRow', $this->WatchedCategoriesPager->toString('less'));
139+
$this->setJson('MoreRow', $this->WatchedCategoriesPager->toString('more'));
140+
$this->setJson('Loading', $cp.' to '.$categoryLimit);
141+
$this->View = 'categories';
142+
}
143+
144+
}
145+
146+
$this->canonicalUrl(url('/watching', true));
147+
148+
// Add modules
149+
$this->addModule('DiscussionFilterModule');
150+
151+
// Render default view
152+
$this->setData('Title', t('Watching'));
153+
$this->setData('Breadcrumbs', [['Name' => t('Watching'), 'Url' => '/watching']]);
154+
155+
$this->render();
156+
}
157+
}

Topcoder/design/topcoder.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,22 @@ a:hover span.challengeRoles {
126126
padding: 0px 0px;
127127
text-transform: none;
128128
}
129+
130+
.Topcoder h2.HomepageTitle {
131+
font-family: Barlow_Condensed, Helvetica, Arial, sans-serif;
132+
font-weight: 500;
133+
color: #2a2a2a !important;
134+
font-size: 24px !important;
135+
font-weight: 500 !important;
136+
line-height: 28px !important;
137+
text-transform: uppercase !important;
138+
}
139+
.Topcoder h1.HomepageTitle {
140+
font-family: Barlow_Condensed, Helvetica, Arial, sans-serif;
141+
font-weight: 500;
142+
color: #2a2a2a !important;
143+
font-size: 34px !important;
144+
font-weight: 500 !important;
145+
line-height: 38px !important;
146+
text-transform: uppercase !important;
147+
}

Topcoder/js/topcoder.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
jQuery(document).ready(function($) {
2+
3+
// Set up paging
4+
if ($.morepager) {
5+
6+
$('#WatchingDiscussionsMore').morepager({
7+
pageContainerSelector: 'ul.Discussions:last',
8+
afterPageLoaded: function() {
9+
$(document).trigger('DiscussionPagingComplete');
10+
}
11+
});
12+
13+
// profile/discussions paging
14+
$('#WatchingCategoriesMore').morepager({
15+
pageContainerSelector: 'ul.WatchedCategoryList:last',
16+
afterPageLoaded: function() {
17+
$(document).trigger('DiscussionPagingComplete');
18+
}
19+
});
20+
}
21+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php if (!defined('APPLICATION')) exit();
2+
$Session = Gdn::session();
3+
include_once $this->fetchViewLocation('helper_functions', 'categories', 'vanilla');
4+
5+
if($this->data('WatchedCategories')) {
6+
$categories = $this->data('WatchedCategories');
7+
?>
8+
<?php
9+
foreach ($categories as $category) {
10+
writeListItem($category, 1);
11+
}
12+
?>
13+
<?php
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php if (!defined('APPLICATION')) exit();
2+
$Session = Gdn::session();
3+
include_once $this->fetchViewLocation('helper_functions', 'discussions', 'vanilla');
4+
5+
if ($this->data('Discussions')->numRows() > 0) {
6+
?>
7+
8+
<?php include($this->fetchViewLocation('discussions', 'Discussions', 'Vanilla')); ?>
9+
10+
<?php
11+
}

Topcoder/views/watching/index.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php if (!defined('APPLICATION')) exit();
2+
$Session = Gdn::session();
3+
include_once $this->fetchViewLocation('helper_functions', 'discussions', 'vanilla');
4+
include_once $this->fetchViewLocation('helper_functions', 'categories', 'vanilla');
5+
6+
echo '<h1 class="H HomepageTitle">'.
7+
adminCheck(NULL, ['', ' ']).
8+
$this->data('Title').
9+
'</h1>';
10+
11+
$this->fireEvent('AfterPageTitle');
12+
echo '<div class="PageControls Top">';
13+
echo categorySorts();
14+
echo '</div>';
15+
16+
if($this->data('WatchedCategories')) {
17+
echo '<h2 class="H HomepageTitle">Categories</h2>';
18+
$categories = $this->data('WatchedCategories');
19+
?>
20+
<ul class="DataList CategoryList WatchedCategoryList">
21+
<?php
22+
foreach ($categories as $category) {
23+
writeListItem($category, 1);
24+
}
25+
?>
26+
</ul>
27+
<?php
28+
echo $this->WatchedCategoriesPager->toString('more');
29+
}
30+
31+
if ($this->data('Discussions')->numRows() > 0) {
32+
echo '<h2 class="H HomepageTitle">Discussions</h2>';
33+
?>
34+
<ul class="DataList Discussions">
35+
<?php include($this->fetchViewLocation('discussions', 'Discussions', 'Vanilla'));
36+
?>
37+
</ul>
38+
<?php
39+
echo $this->DiscussionPager->toString('more');
40+
}
41+
42+
43+

0 commit comments

Comments
 (0)