client/posts: add option to disable safety ratings

This commit is contained in:
rr- 2017-03-30 20:50:12 +02:00
parent c2be365b6e
commit 77bf3bdc3c
13 changed files with 71 additions and 57 deletions

View File

@ -4,7 +4,7 @@
<div class='messages'></div>
<% if (ctx.canEditPostSafety) { %>
<% if (ctx.enableSafety && ctx.canEditPostSafety) { %>
<section class='safety'>
<label>Safety</label>
<div class='radio-wrapper'>

View File

@ -20,10 +20,12 @@
<%= ctx.makeRelativeTime(ctx.post.creationTime) %>
</section>
<section class='safety'>
<i class='fa fa-circle safety-<%- ctx.post.safety %>'></i><!--
--><%- ctx.post.safety[0].toUpperCase() + ctx.post.safety.slice(1) %>
</section>
<% if (ctx.enableSafety) { %>
<section class='safety'>
<i class='fa fa-circle safety-<%- ctx.post.safety %>'></i><!--
--><%- ctx.post.safety[0].toUpperCase() + ctx.post.safety.slice(1) %>
</section>
<% } %>
<section class='zoom'>
<a href class='fit-original'>Original zoom</a> &middot;

View File

@ -41,16 +41,18 @@
</header>
<div class='body'>
<div class='safety'>
<% for (let safety of ['safe', 'sketchy', 'unsafe']) { %>
<%= ctx.makeRadio({
name: 'safety-' + ctx.uploadable.key,
value: safety,
text: safety[0].toUpperCase() + safety.substr(1),
selectedValue: ctx.uploadable.safety,
}) %>
<% } %>
</div>
<% if (ctx.enableSafety) { %>
<div class='safety'>
<% for (let safety of ['safe', 'sketchy', 'unsafe']) { %>
<%= ctx.makeRadio({
name: 'safety-' + ctx.uploadable.key,
value: safety,
text: safety[0].toUpperCase() + safety.substr(1),
selectedValue: ctx.uploadable.safety,
}) %>
<% } %>
</div>
<% } %>
<div class='options'>
<% if (ctx.canUploadAnonymously) { %>

View File

@ -4,9 +4,11 @@
%><wbr/><%
%><input class='mousetrap' type='submit' value='Search'/><%
%><wbr/><%
%><input data-safety=safe type='button' class='mousetrap safety safety-safe <%- ctx.settings.listPosts.safe ? '' : 'disabled' %>'/><%
%><input data-safety=sketchy type='button' class='mousetrap safety safety-sketchy <%- ctx.settings.listPosts.sketchy ? '' : 'disabled' %>'/><%
%><input data-safety=unsafe type='button' class='mousetrap safety safety-unsafe <%- ctx.settings.listPosts.unsafe ? '' : 'disabled' %>'/><%
%><% if (ctx.enableSafety) { %><%
%><input data-safety=safe type='button' class='mousetrap safety safety-safe <%- ctx.settings.listPosts.safe ? '' : 'disabled' %>'/><%
%><input data-safety=sketchy type='button' class='mousetrap safety safety-sketchy <%- ctx.settings.listPosts.sketchy ? '' : 'disabled' %>'/><%
%><input data-safety=unsafe type='button' class='mousetrap safety safety-unsafe <%- ctx.settings.listPosts.unsafe ? '' : 'disabled' %>'/><%
%><% } %><%
%><wbr/><%
%><a class='mousetrap button append' href='<%- ctx.formatClientLink('help', 'search', 'posts') %>'>Syntax help</a><%
%></form><%
@ -20,7 +22,7 @@
%><a href class='mousetrap button append close'>Stop tagging</a><%
%></form><%
%><% } %><%
%><% if (ctx.canBulkEditSafety) { %><%
%><% if (ctx.enableSafety && ctx.canBulkEditSafety) { %><%
%><form class='horizontal bulk-edit bulk-edit-safety'><%
%><a href class='mousetrap button append open'>Mass edit safety</a><%
%><a href class='mousetrap button append close'>Stop editing safety</a><%

View File

@ -1,5 +1,6 @@
'use strict';
const config = require('../config.js');
const api = require('../api.js');
const settings = require('../models/settings.js');
const uri = require('../util/uri.js');
@ -31,6 +32,7 @@ class PostListController {
this._headerView = new PostsHeaderView({
hostNode: this._pageController.view.pageHeaderHolderNode,
parameters: ctx.parameters,
enableSafety: config.enableSafety,
canBulkEditTags: api.hasPrivilege('posts:bulkEdit:tags'),
canBulkEditSafety: api.hasPrivilege('posts:bulkEdit:safety'),
bulkEdit: {
@ -79,20 +81,6 @@ class PostListController {
e.detail.post.save().catch(error => window.alert(error.message));
}
_decorateSearchQuery(text) {
const browsingSettings = settings.get();
let disabledSafety = [];
for (let key of Object.keys(browsingSettings.listPosts)) {
if (browsingSettings.listPosts[key] === false) {
disabledSafety.push(key);
}
}
if (disabledSafety.length) {
text = `-rating:${disabledSafety.join(',')} ${text}`;
}
return text.trim();
}
_syncPageController() {
this._pageController.run({
parameters: this._ctx.parameters,
@ -104,9 +92,7 @@ class PostListController {
},
requestPage: (offset, limit) => {
return PostList.search(
this._decorateSearchQuery(
this._ctx.parameters.query || ''),
offset, limit, fields);
this._ctx.parameters.query, offset, limit, fields);
},
pageRenderer: pageCtx => {
Object.assign(pageCtx, {

View File

@ -20,8 +20,8 @@ class PostMainController extends BasePostController {
Promise.all([
Post.get(ctx.parameters.id),
PostList.getAround(
ctx.parameters.id, this._decorateSearchQuery(
parameters ? parameters.query || '' : '')),
ctx.parameters.id,
parameters ? parameters.query : null),
]).then(responses => {
const [post, aroundResponse] = responses;
@ -91,20 +91,6 @@ class PostMainController extends BasePostController {
});
}
_decorateSearchQuery(text) {
const browsingSettings = settings.get();
let disabledSafety = [];
for (let key of Object.keys(browsingSettings.listPosts)) {
if (browsingSettings.listPosts[key] === false) {
disabledSafety.push(key);
}
}
if (disabledSafety.length) {
text = `-rating:${disabledSafety.join(',')} ${text}`;
}
return text.trim();
}
_evtFitModeChange(e) {
const browsingSettings = settings.get();
browsingSettings.fitMode = e.detail.mode;

View File

@ -1,6 +1,7 @@
'use strict';
const api = require('../api.js');
const config = require('../config.js');
const router = require('../router.js');
const uri = require('../util/uri.js');
const misc = require('../util/misc.js');
@ -29,6 +30,7 @@ class PostUploadController {
this._view = new PostUploadView({
canUploadAnonymously: api.hasPrivilege('posts:create:anonymous'),
canViewPosts: api.hasPrivilege('posts:view'),
enableSafety: config.enableSafety,
});
this._view.addEventListener('change', e => this._evtChange(e));
this._view.addEventListener('submit', e => this._evtSubmit(e));

View File

@ -57,7 +57,7 @@ class UserListController {
},
requestPage: (offset, limit) => {
return UserList.search(
this._ctx.parameters.query || '', offset, limit);
this._ctx.parameters.query, offset, limit);
},
pageRenderer: pageCtx => {
Object.assign(pageCtx, {

View File

@ -1,6 +1,7 @@
'use strict';
const api = require('../api.js');
const config = require('../config.js');
const events = require('../events.js');
const misc = require('../util/misc.js');
const views = require('../util/views.js');
@ -23,6 +24,7 @@ class PostEditSidebarControl extends events.EventTarget {
views.replaceContent(this._hostNode, template({
post: this._post,
enableSafety: config.enableSafety,
canEditPostSafety: api.hasPrivilege('posts:edit:safety'),
canEditPostSource: api.hasPrivilege('posts:edit:source'),
canEditPostTags: api.hasPrivilege('posts:edit:tags'),

View File

@ -1,6 +1,7 @@
'use strict';
const api = require('../api.js');
const config = require('../config.js');
const events = require('../events.js');
const tags = require('../tags.js');
const views = require('../util/views.js');
@ -23,6 +24,7 @@ class PostReadonlySidebarControl extends events.EventTarget {
post: this._post,
getTagCategory: this._getTagCategory,
getTagUsages: this._getTagUsages,
enableSafety: config.enableSafety,
canListPosts: api.hasPrivilege('posts:list'),
canEditPosts: api.hasPrivilege('posts:edit'),
canViewTags: api.hasPrivilege('tags:view'),

View File

@ -1,5 +1,7 @@
'use strict';
const settings = require('../models/settings.js');
const config = require('../config.js');
const api = require('../api.js');
const uri = require('../util/uri.js');
const AbstractList = require('./abstract_list.js');
@ -9,14 +11,17 @@ class PostList extends AbstractList {
static getAround(id, searchQuery) {
return api.get(
uri.formatApiLink(
'post', id, 'around', {query: searchQuery, fields: 'id'}));
'post', id, 'around', {
query: PostList._decorateSearchQuery(searchQuery || ''),
fields: 'id',
}));
}
static search(text, offset, limit, fields) {
return api.get(
uri.formatApiLink(
'posts', {
query: text,
query: PostList._decorateSearchQuery(text || ''),
offset: offset,
limit: limit,
fields: fields.join(','),
@ -28,6 +33,23 @@ class PostList extends AbstractList {
{results: PostList.fromResponse(response.results)}));
});
}
static _decorateSearchQuery(text) {
const browsingSettings = settings.get();
const disabledSafety = [];
if (config.enableSafety) {
for (let key of Object.keys(browsingSettings.listPosts)) {
if (browsingSettings.listPosts[key] === false) {
disabledSafety.push(key);
}
}
if (disabledSafety.length) {
text = `-rating:${disabledSafety.join(',')} ${text}`;
}
}
return text.trim();
}
}
PostList._itemClass = Post;

View File

@ -277,14 +277,20 @@ class PostUploadView extends events.EventTarget {
_updateUploadableFromDom(uploadable) {
const rowNode = uploadable.rowNode;
uploadable.safety =
rowNode.querySelector('.safety input:checked').value;
const safetyNode = rowNode.querySelector('.safety input:checked');
if (safetyNode) {
uploadable.safety = safetyNode.value;
}
uploadable.anonymous =
rowNode.querySelector('.anonymous input').checked;
uploadable.flags = [];
if (rowNode.querySelector('.loop-video input:checked')) {
uploadable.flags.push('loop');
}
uploadable.tags = [];
uploadable.relations = [];
for (let [i, lookalike] of uploadable.lookalikes.entries()) {

View File

@ -46,6 +46,8 @@ elasticsearch:
index: szurubooru
enable_safety: yes
tag_name_regex: ^\S+$
tag_category_name_regex: ^[^\s%+#/]+$