Skip to content

Commit

Permalink
feat(filters): content type filters #49
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Jul 18, 2018
1 parent 84d41ab commit 785dc7c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
56 changes: 53 additions & 3 deletions src/app/filters-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,51 @@ import Slider from 'material-ui/Slider'
import SelectField from 'material-ui/SelectField';
import MenuItem from 'material-ui/MenuItem';
import InputSize from './input-size';

import fs from 'fs'
import Checkbox from 'material-ui/Checkbox';

export default class ConfigPage extends Page {
constructor(props) {
super(props)
this.setTitle('Rats filters');
this.options = {}
this.basicTypes = ['video',
'audio',
'pictures',
'books',
'application',
'archive',
'disc']
this.contentType = this.basicTypes.slice(0)
this.descriptions = {
main: __('All'),
video: __('Video'),
audio: __('Audio/Music'),
books: __('Books'),
pictures: __('Pictures/Images'),
application: __('Apps/Games'),
archive: __('Archives'),
disc: __('Discs/ISO')
}
}
componentDidMount() {
this.loadSettings()
}
loadSettings() {
window.torrentSocket.emit('config', window.customLoader((options) => {
this.options = options;
console.log(this.options)

if(this.options.filters && this.options.filters.contentType && this.options.filters.contentType.length > 0)
this.contentType = this.options.filters.contentType

this.forceUpdate();
}));
}
saveSettings() {
if(this.options.filters && this.basicTypes.length === this.contentType.length)
this.options.filters.contentType = null // обнуляем в случае если заданы все фильтры
else
this.options.filters.contentType = this.contentType

window.torrentSocket.emit('setConfig', this.options)
this.settingsSavedMessage = true
this.forceUpdate()
Expand Down Expand Up @@ -164,6 +189,31 @@ export default class ConfigPage extends Page {
</div>
}

<div className='column w100p'>
<div style={{flex: 1, padding: '8px 0px'}}>{__('disable some categories')}:</div>
{
this.basicTypes.map(type => (<Checkbox
label={this.descriptions[type]}
checked={this.contentType && this.contentType.indexOf(type) >= 0}
onCheck={e => {
if(e.target.checked)
{
this.contentType.push(type)
}
else
{
const index = this.contentType.indexOf(type)
this.contentType.splice(index, 1)
}
if(this.contentType.length == 0)
this.contentType = this.basicTypes.slice(0)

this.forceUpdate()
}}
/>))
}
</div>

{
this.toRemoveProbably && this.toRemoveProbably > 0
?
Expand Down
6 changes: 6 additions & 0 deletions src/background/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ app.get('*', function(req, res)
return false
}

if(config.filters.contentType && Array.isArray(config.filters.contentType) && !config.filters.contentType.includes(torrent.contentType))
{
console.log('ignore torrent', torrent.name, 'because type', torrent.contentType, 'not in:', config.filters.contentType)
return false
}

return true
}

Expand Down
4 changes: 3 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@
"Pause torrent downloading": "Pause torrent downloading",
"P2P torrents replication server": "P2P torrents replication server",
"Enable torrents replication server for other rats clients (required for replication)": "Enable torrents replication server for other rats clients (required for replication)",
"* - enabled means ignoring all adult content": "* - enabled means ignoring all adult content"
"* - enabled means ignoring all adult content": "* - enabled means ignoring all adult content",
"disable some categories": "disable some categories",
"Discs/ISO": "Discs/ISO"
}
}
4 changes: 3 additions & 1 deletion translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@
"Pause torrent downloading": "Пауза скачки торрента",
"P2P torrents replication server": "Сервер репликация торрентов через p2p",
"Enable torrents replication server for other rats clients (required for replication)": "Включить сервер репликации для остальных крысиных клиентов (необходим для репликации)",
"* - enabled means ignoring all adult content": "* - означает игнорирование всего контента для взрослых"
"* - enabled means ignoring all adult content": "* - означает игнорирование всего контента для взрослых",
"disable some categories": "отключить некоторые категории",
"Discs/ISO": "Диски/Образы"
}
}
4 changes: 3 additions & 1 deletion translations/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@
"Pause torrent downloading": "Pause torrent downloading",
"P2P torrents replication server": "P2P torrents replication server",
"Enable torrents replication server for other rats clients (required for replication)": "Enable torrents replication server for other rats clients (required for replication)",
"* - enabled means ignoring all adult content": "* - enabled means ignoring all adult content"
"* - enabled means ignoring all adult content": "* - enabled means ignoring all adult content",
"disable some categories": "disable some categories",
"Discs/ISO": "Discs/ISO"
}
}

0 comments on commit 785dc7c

Please sign in to comment.