Skip to content

Commit a128bc8

Browse files
Merge pull request #139 from Zren/uifix
UI Fixes
2 parents 0c64038 + d241385 commit a128bc8

18 files changed

+172
-54
lines changed

app.js

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ app.get('/:type(scripts|libs)/:username/:namespace/:scriptname/issues/:topic/:ac
188188

189189
// Admin routes
190190
app.get('/admin', admin.adminPage);
191+
app.get('/admin/json', admin.adminJsonView);
191192
app.get('/admin/user/:id', admin.adminUserView);
192193
app.get('/admin/api', admin.adminApiKeysPage);
193194
app.post('/admin/api/update', admin.apiAdminUpdate);

controllers/admin.js

+39
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,45 @@ exports.adminUserView = function (req, res, next) {
8282
});
8383
};
8484

85+
86+
var jsonModelMap = {
87+
'User': User,
88+
'Script': Script,
89+
};
90+
// View everything about a particular user
91+
// This is mostly for debugging in production
92+
exports.adminJsonView = function (req, res, next) {
93+
var authedUser = req.session.user;
94+
95+
var modelname = req.query.model;
96+
var id = req.query.id;
97+
98+
//
99+
var options = {};
100+
101+
// Session
102+
authedUser = options.authedUser = modelParser.parseUser(authedUser);
103+
options.isMod = authedUser && authedUser.isMod;
104+
options.isAdmin = authedUser && authedUser.isAdmin;
105+
106+
if (!options.isAdmin)
107+
return res.send(403, {status: 403, message: 'Not an admin.'});
108+
109+
110+
var model = jsonModelMap[modelname];
111+
if (!model)
112+
return res.send(400, {status: 400, message: 'Invalid model.'});
113+
114+
model.findOne({
115+
_id: id
116+
}, function(err, obj){
117+
if (err || !obj)
118+
return res.send(404, {status: 404, message: 'Id doesn\'t exist.'});
119+
120+
res.json(obj);
121+
});
122+
};
123+
85124
// Make changes to users listed
86125
exports.adminUserUpdate = function (req, res, next) {
87126
var authedUser = req.session.user;

controllers/group.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ exports.list = function (req, res) {
152152
// groupListQuery: Pagination
153153
var pagination = options.pagination; // is set in modelQuery.apply___ListQueryDefaults
154154

155+
// popularGroupListQuery
156+
var popularGroupListQuery = Group.find();
157+
popularGroupListQuery
158+
.sort('-rating')
159+
.limit(25);
160+
155161
//--- Tasks
156162

157163
// Pagination
@@ -160,6 +166,9 @@ exports.list = function (req, res) {
160166
// groupListQuery
161167
tasks.push(execQueryTask(groupListQuery, options, 'groupList'));
162168

169+
// popularGroupListQuery
170+
tasks.push(execQueryTask(popularGroupListQuery, options, 'popularGroupList'));
171+
163172
//---
164173
function preRender(){
165174
// groupList
@@ -168,6 +177,9 @@ exports.list = function (req, res) {
168177
// Pagination
169178
options.paginationRendered = pagination.renderDefault(req);
170179

180+
// popularGroupList
181+
options.popularGroupList = _.map(options.popularGroupList, modelParser.parseGroup);
182+
171183
// Page <head> meta keywords
172184
var pageMetaKeywords = ['userscript', 'greasemonkey'];
173185
if (options.groupList)
@@ -224,9 +236,10 @@ exports.view = function (req, res, next) {
224236
// scriptListQuery: Pagination
225237
var pagination = options.pagination; // is set in modelQuery.apply___ListQueryDefaults
226238

227-
// groupListQuery
228-
var groupListQuery = Group.find();
229-
groupListQuery
239+
// popularGroupListQuery
240+
var popularGroupListQuery = Group.find();
241+
popularGroupListQuery
242+
.sort('-rating')
230243
.limit(25);
231244

232245
//--- Tasks
@@ -237,16 +250,16 @@ exports.view = function (req, res, next) {
237250
// scriptListQuery
238251
tasks.push(execQueryTask(scriptListQuery, options, 'scriptList'));
239252

240-
// groupListQuery
241-
tasks.push(execQueryTask(groupListQuery, options, 'groupList'));
253+
// popularGroupListQuery
254+
tasks.push(execQueryTask(popularGroupListQuery, options, 'popularGroupList'));
242255

243256
//---
244257
function preRender(){
245258
// scriptList
246259
options.scriptList = _.map(options.scriptList, modelParser.parseScript);
247260

248-
// groupList
249-
options.groupList = _.map(options.groupList, modelParser.parseGroup);
261+
// popularGroupList
262+
options.popularGroupList = _.map(options.popularGroupList, modelParser.parseGroup);
250263

251264
// Pagination
252265
options.paginationRendered = pagination.renderDefault(req);

controllers/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ exports.home = function (req, res) {
5252
// scriptListQuery: Pagination
5353
var pagination = options.pagination; // is set in modelQuery.apply___ListQueryDefaults
5454

55-
// groupListQuery
56-
var groupListQuery = Group.find();
57-
groupListQuery
55+
// popularGroupListQuery
56+
var popularGroupListQuery = Group.find();
57+
popularGroupListQuery
5858
.sort('-rating')
5959
.limit(25);
6060

@@ -66,16 +66,16 @@ exports.home = function (req, res) {
6666
// scriptListQuery
6767
tasks.push(execQueryTask(scriptListQuery, options, 'scriptList'));
6868

69-
// groupListQuery
70-
tasks.push(execQueryTask(groupListQuery, options, 'groupList'));
69+
// popularGroupListQuery
70+
tasks.push(execQueryTask(popularGroupListQuery, options, 'popularGroupList'));
7171

7272
//---
7373
function preRender(){
7474
// scriptList
7575
options.scriptList = _.map(options.scriptList, modelParser.parseScript);
7676

77-
// groupList
78-
options.groupList = _.map(options.groupList, modelParser.parseGroup);
77+
// popularGroupList
78+
options.popularGroupList = _.map(options.popularGroupList, modelParser.parseGroup);
7979

8080
// Pagination
8181
options.paginationRendered = pagination.renderDefault(req);

controllers/script.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,19 @@ var getScriptPageTasks = function(options) {
7575

7676
// Show the groups the script belongs to
7777
tasks.push(function (callback) {
78-
if (script.isLib) { return callback(); }
78+
script.hasGroups = false;
79+
script.groups = [];
80+
81+
Group.find({
82+
_scriptIds: script._id
83+
}, function (err, scriptGroupList) {
84+
if (err) return callback(err);
85+
86+
scriptGroupList = _.map(scriptGroupList, modelParser.parseGroup);
87+
88+
script.hasGroups = scriptGroupList.length > 0;
89+
script.groups = scriptGroupList;
7990

80-
Group.find({ _scriptIds: script._id }, 'name', function (err, groups) {
81-
options.hasGroups = !err && groups.length > 0;
82-
options.groups = (groups || []).map(function (group) {
83-
return { name: group.name, url: group.name.replace(/\s+/g, '_') };
84-
});
8591
callback();
8692
});
8793
});
@@ -355,7 +361,7 @@ exports.edit = function (req, res, next) {
355361
options.canCreateGroup = (!script._groupId).toString();
356362

357363
function preRender(){
358-
var groupNameList = (options.groups || []).map(function (group) {
364+
var groupNameList = (options.script.groups || []).map(function (group) {
359365
return group.name;
360366
});
361367
options.groupNameListJSON = JSON.stringify(groupNameList);

libs/flag.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var Flag = require('../models/flag').Flag;
22
var User = require('../models/user').User;
33
var getKarma = require('./collectiveRating').getKarma;
4-
var thresholds = { 'Script': 5, 'User': 10, 'Discussion': 3, 'Comment': 2 };
4+
var thresholds = { 'Script': 1, 'User': 1, 'Discussion': 1, 'Comment': 1 };
55
var maxKarma = 10;
66

77
// Determine whether content can be flagged by a user.
@@ -66,7 +66,7 @@ function getThreshold (model, content, author, callback) {
6666

6767
// Hardcode the threshold at 1.
6868
// modelQuery.applyModelListQueryFlaggedFilter supports this hardcoded number.
69-
return callback(1);
69+
// return callback(1);
7070

7171
// Moderators have a doubled threshold
7272
var threshold = thresholds[model.modelName] * (author.role < 4 ? 2 : 1);

libs/modelQuery.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ var applyModelListQueryFlaggedFilter = function(modelListQuery, options, flagged
132132
if (flaggedQuery == 'true') {
133133
modelListQuery.and({flags: {$gt: 0 }});
134134
} else if (flaggedQuery == false) {
135-
modelListQuery.and({$or: [
136-
{flags: {$exists: false}},
137-
{flags: 0 },
138-
]});
135+
// modelListQuery.and({$or: [
136+
// {flags: {$exists: false}},
137+
// {flags: {$lte: 0} },
138+
// ]});
139139
}
140140
}
141141
} else {
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="panel panel-default">
2+
<div class="panel-heading">
3+
<div class="panel-title">Popular Groups</div>
4+
</div>
5+
<div class="panel-body">
6+
<ul class="tagcloud">
7+
{{#popularGroupList}}
8+
<li><a href="{{{groupPageUrl}}}">{{name}}</a> <span class="badge">{{size}}</span></li>
9+
{{/popularGroupList}}
10+
</ul>
11+
</div>
12+
</div>
+11
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
{{#adminTools}}
2+
<div class="panel panel-default">
3+
<div class="panel-heading">
4+
<div class="panel-title">
5+
<i class="fa fa-fw fa-coffee"></i>
6+
Admin Tools
7+
</div>
8+
</div>
9+
<div class="panel-body">
10+
<a href="/admin/json?model=Script&id={{{script._id}}}" class="btn btn-link col-xs-12"><i class="fa fa-database"></i> Raw JSON Data</a>
11+
</div>
12+
</div>
213
{{/adminTools}}

views/includes/scriptUserToolsPanel.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</div>
88
<p><i class="fa fa-fw fa-signal"></i> <b>Rating:</b> {{script.rating}}</p>
99
<div class="progress">
10-
<div style="width: {{script.votesPercent}}%" class="progress-bar progress-bar-good">{{#script.votes}}{{script.votes}}<i class="fa fa-fw fa-caret-up"></i>{{/script.votes}}</div>
11-
<div style="width: {{script.flagsPercent}}%" class="progress-bar progress-bar-danger">{{#script.flags}}{{script.flags}}<i class="fa fa-fw fa-caret-down"></i>{{/script.flags}}</div>
10+
<div style="width: {{script.votesPercent}}%" class="progress-bar progress-bar-good">{{#script.votes}}{{script.votes}} Votes{{/script.votes}}</div>
11+
<div style="width: {{script.flagsPercent}}%" class="progress-bar progress-bar-danger">{{#script.flags}}{{script.flags}} <i class="fa fa-fw fa-flag"></i>{{/script.flags}}</div>
1212
</div>
1313
</div>
1414
<ul class="nav nav-pills nav-justified">

views/includes/scripts/commentReplyScript.html

+39
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script type="text/javascript">
2+
23
$('.btn-comment-reply').click(function(e){
34
$('#reply-control').collapse('show');
45

@@ -16,4 +17,42 @@
1617
text += ' \n';
1718
$replyTextarea.text(text);
1819
});
20+
21+
function isElementInViewport (el) {
22+
//special bonus for those using jQuery
23+
if (el instanceof jQuery) {
24+
el = el[0];
25+
}
26+
27+
var rect = el.getBoundingClientRect();
28+
29+
return (
30+
rect.top >= 0 &&
31+
rect.left >= 0 &&
32+
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
33+
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
34+
);
35+
}
36+
37+
var hasShownReplyForm = false;
38+
function callback (el) {
39+
if (!hasShownReplyForm) {
40+
$('#reply-control').collapse('show');
41+
hasShownReplyForm = true;
42+
}
43+
}
44+
45+
function fireIfElementVisible (el, callback) {
46+
return function () {
47+
if ( isElementInViewport(el) ) {
48+
callback(el);
49+
}
50+
}
51+
}
52+
53+
var handler = fireIfElementVisible ($('#show-reply-form-when-visible'), callback);
54+
55+
//jQuery
56+
$(window).on('DOMContentLoaded load resize scroll', handler);
57+
1958
</script>

views/includes/userAdminToolsPanel.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<input type="submit" class="col-sm-2 btn btn-default" value="Save">
2121
</div>
2222
</form>
23-
<a href="/admin/user/{{{user._id}}}" class="btn btn-link col-xs-12"><i class="fa fa-database"></i> Raw Data</a>
23+
<a href="/admin/json?model=User&id={{{user._id}}}" class="btn btn-link col-xs-12"><i class="fa fa-database"></i> Raw JSON Data</a>
2424
</div>
2525
</div>
2626
{{/adminTools}}

views/pages/discussionPage.html

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<title>{{title}}</title>
55
{{> includes/head.html }}
66
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-markdown/2.2.1/css/bootstrap-markdown.min.css">
7+
<style>
8+
#show-reply-form-when-visible { height: 100px; }
9+
</style>
710
</head>
811
<body>
912
{{> includes/header.html }}
@@ -40,6 +43,7 @@
4043
</div>
4144
</div>
4245

46+
<div id="show-reply-form-when-visible"></div>
4347
{{> includes/commentForm.html }}
4448

4549
{{> includes/footer.html }}

views/pages/groupListPage.html

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ <h2 class="page-heading">
2222
</div>
2323
<div class="col-sm-4">
2424
{{> includes/searchBarPanel.html }}
25+
{{> includes/popularGroupsPanel.html }}
2526
</div>
2627
</div>
2728
</div>

views/pages/groupScriptListPage.html

+1-12
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,7 @@ <h2 class="page-heading">
2222
</div>
2323
<div class="col-sm-4">
2424
{{> includes/searchBarPanel.html }}
25-
<div class="panel panel-default">
26-
<div class="panel-heading">
27-
<div class="panel-title">Popular Groups</div>
28-
</div>
29-
<div class="panel-body">
30-
<ul class="tagcloud">
31-
{{#groupList}}
32-
<li><a href="{{{groupPageUrl}}}">{{name}}</a> <span class="badge">{{size}}</span></li>
33-
{{/groupList}}
34-
</ul>
35-
</div>
36-
</div>
25+
{{> includes/popularGroupsPanel.html }}
3726
</div>
3827
</div>
3928
</div>

views/pages/scriptIssuePage.html

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
{{> includes/head.html }}
66
<link rel="stylesheet" href="https://toopay.github.io/bootstrap-markdown/css/bootstrap-markdown.min.css">
77
<link rel="stylesheet" href="/css/scriptPage.css">
8+
<style>
9+
#show-reply-form-when-visible { height: 100px; }
10+
</style>
811
</head>
912
<body>
1013
{{> includes/header.html }}
@@ -49,6 +52,7 @@
4952
</div>
5053
</div>
5154

55+
<div id="show-reply-form-when-visible"></div>
5256
{{> includes/commentForm.html }}
5357

5458
{{> includes/footer.html }}

0 commit comments

Comments
 (0)