Fix some warnings.

master
Sander Vocke 6 years ago
parent 0715bc1b10
commit 0f4b465db5
  1. 8
      src/browser.js
  2. 5
      src/database.js
  3. 60
      src/queries.js
  4. 1
      src/searchbar.js
  5. 21
      src/userquerywidget.js

@ -34,13 +34,13 @@ export function insert_into_album_tree(treebaseitem, treeitem) {
for (var i = 0; i < parts.length; i++) { for (var i = 0; i < parts.length; i++) {
var part = parts[i]; var part = parts[i];
var subitem = false; var subitem = false;
var required_relative_path = (current_item.data == "/") ? var required_relative_path = (current_item.data === "/") ?
current_item.data + part : current_item.data + part :
current_item.data + "/" + part; current_item.data + "/" + part;
for (var j = 0; j < current_item.children.length; j++) { for (var j = 0; j < current_item.children.length; j++) {
var child = current_item.children[j]; var child = current_item.children[j];
if (child.data == required_relative_path) { if (child.data === required_relative_path) {
subitem = child; subitem = child;
break; break;
} }
@ -62,7 +62,7 @@ export function build_albums_tree(all_db_albums) {
var tree = new NavTreeItem("", "/", []); var tree = new NavTreeItem("", "/", []);
for (var i = 0; i < all_db_albums.length; i++) { for (var i = 0; i < all_db_albums.length; i++) {
var album = all_db_albums[i]; var album = all_db_albums[i];
if (album.state.relative_path != "/") { // we already made the base, skip that one if (album.state.relative_path !== "/") { // we already made the base, skip that one
var item = new NavTreeItem( var item = new NavTreeItem(
album.state.name, album.state.name,
album.state.relative_path, album.state.relative_path,
@ -118,7 +118,7 @@ export function NavListItem(props) {
} }
} }
if (navitem.children.length == 0) { if (navitem.children.length === 0) {
return ( return (
<ListItem button onClick={handleClick}> <ListItem button onClick={handleClick}>
<ListItemText primary={navitem.display_name} /> <ListItemText primary={navitem.display_name} />

@ -52,15 +52,16 @@ export class DB {
// Perform a series of queries sequentially, then return the last result. // Perform a series of queries sequentially, then return the last result.
// Note that synchronous operation is not supported for all database types. // Note that synchronous operation is not supported for all database types.
queries_sync(s) { queries_sync(s) {
var i;
if (this.state.db_type === DBTypeEnum.ALASQL_SQLITE || if (this.state.db_type === DBTypeEnum.ALASQL_SQLITE ||
this.state.db_type === DBTypeEnum.ALASQL_NATIVE) { this.state.db_type === DBTypeEnum.ALASQL_NATIVE) {
for (var i = 0; i < (s.length - 1); i++) { for (i = 0; i < (s.length - 1); i++) {
this.state.db_object(s[i]); this.state.db_object(s[i]);
} }
return this.state.db_object(s[s.length - 1]); return this.state.db_object(s[s.length - 1]);
} }
if (this.state.db_type === DBTypeEnum.SQLJS_SQLITE) { if (this.state.db_type === DBTypeEnum.SQLJS_SQLITE) {
for (var i = 0; i < (s.length - 1); i++) { for (i = 0; i < (s.length - 1); i++) {
this.state.db_object.exec(s[i]); this.state.db_object.exec(s[i]);
} }
return this.state.db_object.exec(s[s.length - 1]); return this.state.db_object.exec(s[s.length - 1]);

@ -35,7 +35,7 @@ export function do_album_query(query, database) {
var albums = []; var albums = [];
if (res && Array.isArray(res)) { if (res && Array.isArray(res)) {
res.forEach(row => { res.forEach(row => {
var album_name = new String(row["relativePath"]).substring(row["relativePath"].lastIndexOf('/') + 1); var album_name = row["relativePath"].substring(row["relativePath"].lastIndexOf('/') + 1);
albums.push(create_album(row["id"], album_name, row["relativePath"])); albums.push(create_album(row["id"], album_name, row["relativePath"]));
}); });
} }
@ -144,32 +144,33 @@ export class MatchingFilter extends ResultFilter {
match_type = MatchTypeEnum.MATCH_EQUALS; match_type = MatchTypeEnum.MATCH_EQUALS;
to_sql_where() { to_sql_where() {
if(this.match_against == MatchAgainstEnum.MATCH_IMAGE_NAME) { var expr;
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) { if(this.match_against === MatchAgainstEnum.MATCH_IMAGE_NAME) {
if(this.match_type === MatchTypeEnum.MATCH_EQUALS) {
return '(Images.name="' + this.match_from + '")'; return '(Images.name="' + this.match_from + '")';
} else if(this.match_type == MatchTypeEnum.MATCH_NATURAL) { } else if(this.match_type === MatchTypeEnum.MATCH_NATURAL) {
var expr = '"' + '.*' + escape_regex(this.match_from) + '.*' + '"'; expr = '".*' + escape_regex(this.match_from) + '.*"';
return "(LOWER(Images.name) REGEXP LOWER(" + expr +"))"; return "(LOWER(Images.name) REGEXP LOWER(" + expr +"))";
} }
} else if(this.match_against == MatchAgainstEnum.MATCH_TAG_NAME) { } else if(this.match_against === MatchAgainstEnum.MATCH_TAG_NAME) {
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) { if(this.match_type === MatchTypeEnum.MATCH_EQUALS) {
return '(Tags.name="' + this.match_from + '")'; return '(Tags.name="' + this.match_from + '")';
} else if(this.match_type == MatchTypeEnum.MATCH_NATURAL) { } else if(this.match_type === MatchTypeEnum.MATCH_NATURAL) {
var expr = '"' + '.*' + escape_regex(this.match_from) + '.*' + '"'; expr = '".*' + escape_regex(this.match_from) + '.*"';
return '(LOWER(Tags.name) REGEXP LOWER("' + expr + '"))'; return '(LOWER(Tags.name) REGEXP LOWER("' + expr + '"))';
} }
} else if(this.match_against == MatchAgainstEnum.MATCH_ALBUM_NAME) { } else if(this.match_against === MatchAgainstEnum.MATCH_ALBUM_NAME) {
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) { if(this.match_type === MatchTypeEnum.MATCH_EQUALS) {
var expr = '\/(.*\/)*' + escape_regex(this.match_from); expr = '\/(.*\/)*' + escape_regex(this.match_from);
return '(Albums.relativePath REGEXP "' + expr + '")'; return '(Albums.relativePath REGEXP "' + expr + '")';
} else if(this.match_type == MatchTypeEnum.MATCH_NATURAL) { } else if(this.match_type === MatchTypeEnum.MATCH_NATURAL) {
throw new Error("Natural matching on album names is not yet supported."); throw new Error("Natural matching on album names is not yet supported.");
} }
} else if(this.match_against == MatchAgainstEnum.MATCH_ALBUM_NAME_IN_TREE) { } else if(this.match_against === MatchAgainstEnum.MATCH_ALBUM_NAME_IN_TREE) {
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) { if(this.match_type === MatchTypeEnum.MATCH_EQUALS) {
var expr = escape_regex(this.match_from) + '(\/[^\/]+)*'; expr = escape_regex(this.match_from) + '(\/[^\/]+)*';
return '(Albums.relativePath REGEXP "' + expr + '")'; return '(Albums.relativePath REGEXP "' + expr + '")';
} else if(this.match_type == MatchTypeEnum.MATCH_NATURAL) { } else if(this.match_type === MatchTypeEnum.MATCH_NATURAL) {
throw new Error("Natural matching on album tree names is not yet supported."); throw new Error("Natural matching on album tree names is not yet supported.");
} }
} }
@ -195,9 +196,9 @@ export class LogicalOperatorFilter extends ResultFilter {
var where1 = this.sub_filter_a.to_sql_where(); var where1 = this.sub_filter_a.to_sql_where();
var where2 = this.sub_filter_b.to_sql_where(); var where2 = this.sub_filter_b.to_sql_where();
var operator_str = ""; var operator_str = "";
if (this.operator == LogicalOperatorEnum.AND) { if (this.operator === LogicalOperatorEnum.AND) {
operator_str = " AND "; operator_str = " AND ";
} else if (this.operator == LogicalOperatorEnum.OR) { } else if (this.operator === LogicalOperatorEnum.OR) {
operator_str = " OR "; operator_str = " OR ";
} else { } else {
throw new Error('Unsupported logical operator: ' + this.operator); throw new Error('Unsupported logical operator: ' + this.operator);
@ -209,7 +210,7 @@ export class LogicalOperatorFilter extends ResultFilter {
var a = this.sub_filter_a.simplify(); var a = this.sub_filter_a.simplify();
var b = this.sub_filter_b.simplify(); var b = this.sub_filter_b.simplify();
if(this.operator == LogicalOperatorEnum.OR) { if(this.operator === LogicalOperatorEnum.OR) {
if(a.is_true() || b.is_true()) { if(a.is_true() || b.is_true()) {
return new ConstFilter(this.return_type, true); return new ConstFilter(this.return_type, true);
} }
@ -217,7 +218,7 @@ export class LogicalOperatorFilter extends ResultFilter {
if(b.is_false()) { return a; } if(b.is_false()) { return a; }
} }
if(this.operator == LogicalOperatorEnum.AND) { if(this.operator === LogicalOperatorEnum.AND) {
if(a.is_false() || b.is_false()) { if(a.is_false() || b.is_false()) {
return new ConstFilter(this.return_type, false); return new ConstFilter(this.return_type, false);
} }
@ -277,7 +278,7 @@ export function maybe_tag_query(user_query) {
} }
export function filter_is_const_false(filter) { export function filter_is_const_false(filter) {
if(filter instanceof ConstFilter && filter.constval == false) { if(filter instanceof ConstFilter && filter.constval === false) {
return true; return true;
} }
// TODO resolve recursively // TODO resolve recursively
@ -286,10 +287,11 @@ export function filter_is_const_false(filter) {
function filter_from_text_segment(result_type, segment) { function filter_from_text_segment(result_type, segment) {
var filter = false; var filter = false;
var name_filter;
if (result_type == ResultTypeEnum.IMAGE) { if (result_type === ResultTypeEnum.IMAGE) {
// Option 1: match on image name // Option 1: match on image name
var name_filter = new MatchingFilter( name_filter = new MatchingFilter(
result_type, result_type,
MatchAgainstEnum.MATCH_IMAGE_NAME, MatchAgainstEnum.MATCH_IMAGE_NAME,
segment['text'], segment['text'],
@ -308,9 +310,9 @@ function filter_from_text_segment(result_type, segment) {
if(segment['negated']) { if(segment['negated']) {
filter = new NegationFilter(result_type, filter); filter = new NegationFilter(result_type, filter);
} }
} else if (result_type == ResultTypeEnum.ALBUM) { } else if (result_type === ResultTypeEnum.ALBUM) {
// TODO: We need a natural matcher for album names // TODO: We need a natural matcher for album names
var name_filter = new MatchingFilter( name_filter = new MatchingFilter(
result_type, result_type,
MatchAgainstEnum.MATCH_ALBUM_NAME, MatchAgainstEnum.MATCH_ALBUM_NAME,
segment['text'], segment['text'],
@ -320,9 +322,9 @@ function filter_from_text_segment(result_type, segment) {
if(segment['negated']) { if(segment['negated']) {
filter = new NegationFilter(result_type, filter); filter = new NegationFilter(result_type, filter);
} }
} else if (result_type == ResultTypeEnum.TAG) { } else if (result_type === ResultTypeEnum.TAG) {
// Match against the tag name. // Match against the tag name.
var name_filter = new MatchingFilter( name_filter = new MatchingFilter(
result_type, result_type,
MatchAgainstEnum.MATCH_TAG_NAME, MatchAgainstEnum.MATCH_TAG_NAME,
segment['text'], segment['text'],
@ -341,7 +343,7 @@ export function user_query_from_search_string(search_string) {
const parser = require('search-string'); const parser = require('search-string');
var parsed = parser.parse(search_string); var parsed = parser.parse(search_string);
var conditions = parsed.getParsedQuery(); //var conditions = parsed.getParsedQuery();
var texts = parsed.getTextSegments(); var texts = parsed.getTextSegments();
var r = new UserQuery(); var r = new UserQuery();

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField'; import TextField from '@material-ui/core/TextField';
export class SearchBar extends React.Component { export class SearchBar extends React.Component {

@ -53,16 +53,16 @@ export function MatchingFilterExpressionControl(props) {
const classes = useStyles(); const classes = useStyles();
const { expr } = props; const { expr } = props;
if(expr.match_type == MatchTypeEnum.MATCH_EQUALS && if(expr.match_type === MatchTypeEnum.MATCH_EQUALS &&
expr.match_against == "Tags.name") { expr.match_against === "Tags.name") {
// This is an exact tag match. // This is an exact tag match.
return <TagEqualsExpressionControl name={expr.match_from} /> return <TagEqualsExpressionControl name={expr.match_from} />
} }
var opstr = ""; var opstr = "";
if (expr.match_type == MatchTypeEnum.MATCH_EQUALS) { if (expr.match_type === MatchTypeEnum.MATCH_EQUALS) {
opstr = " = "; opstr = " = ";
} else if (expr.match_type == MatchTypeEnum.MATCH_REGEXP_CASEINSENSITIVE) { } else if (expr.match_type === MatchTypeEnum.MATCH_REGEXP_CASEINSENSITIVE) {
opstr = " ≈ "; opstr = " ≈ ";
} }
@ -80,9 +80,9 @@ export function LogicalOperatorFilterExpressionControl(props) {
const { expr } = props; const { expr } = props;
var opstring = ""; var opstring = "";
if (expr.operator == LogicalOperatorEnum.AND) { if (expr.operator === LogicalOperatorEnum.AND) {
opstring = " AND "; opstring = " AND ";
} else if (expr.operator == LogicalOperatorEnum.OR) { } else if (expr.operator === LogicalOperatorEnum.OR) {
opstring = " OR "; opstring = " OR ";
} }
@ -123,7 +123,6 @@ export function ConstFilterExpressionControl(props) {
} }
export function FilterExpressionControl(props) { export function FilterExpressionControl(props) {
const classes = useStyles();
const { expr } = props; const { expr } = props;
if (expr instanceof ConstFilter) { if (expr instanceof ConstFilter) {
@ -138,17 +137,14 @@ export function FilterExpressionControl(props) {
} }
export function FilterControl(props) { export function FilterControl(props) {
const classes = useStyles();
const { filter, onChange, resultType, resultTypeString } = props; const { filter, onChange, resultType, resultTypeString } = props;
function handleResultToggled() { function handleResultToggled() {
if (enabled) { if (enabled) {
var new_filter = new ConstFilter(resultType, false); onChange(new ConstFilter(resultType, false));
onChange(new_filter);
} }
else { else {
var new_filter = new ConstFilter(resultType, true); onChange(new ConstFilter(resultType, true));
onChange(new_filter);
} }
} }
@ -177,7 +173,6 @@ export function FilterControl(props) {
} }
export function UserQueryWidget(props) { export function UserQueryWidget(props) {
const classes = useStyles();
const { userQuery, onChange } = props; const { userQuery, onChange } = props;
var _ = require('lodash'); var _ = require('lodash');

Loading…
Cancel
Save