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++) {
var part = parts[i];
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;
for (var j = 0; j < current_item.children.length; j++) {
var child = current_item.children[j];
if (child.data == required_relative_path) {
if (child.data === required_relative_path) {
subitem = child;
break;
}
@ -62,7 +62,7 @@ export function build_albums_tree(all_db_albums) {
var tree = new NavTreeItem("", "/", []);
for (var i = 0; i < all_db_albums.length; 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(
album.state.name,
album.state.relative_path,
@ -118,7 +118,7 @@ export function NavListItem(props) {
}
}
if (navitem.children.length == 0) {
if (navitem.children.length === 0) {
return (
<ListItem button onClick={handleClick}>
<ListItemText primary={navitem.display_name} />

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

@ -35,7 +35,7 @@ export function do_album_query(query, database) {
var albums = [];
if (res && Array.isArray(res)) {
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"]));
});
}
@ -144,32 +144,33 @@ export class MatchingFilter extends ResultFilter {
match_type = MatchTypeEnum.MATCH_EQUALS;
to_sql_where() {
if(this.match_against == MatchAgainstEnum.MATCH_IMAGE_NAME) {
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) {
var expr;
if(this.match_against === MatchAgainstEnum.MATCH_IMAGE_NAME) {
if(this.match_type === MatchTypeEnum.MATCH_EQUALS) {
return '(Images.name="' + this.match_from + '")';
} else if(this.match_type == MatchTypeEnum.MATCH_NATURAL) {
var expr = '"' + '.*' + escape_regex(this.match_from) + '.*' + '"';
} else if(this.match_type === MatchTypeEnum.MATCH_NATURAL) {
expr = '".*' + escape_regex(this.match_from) + '.*"';
return "(LOWER(Images.name) REGEXP LOWER(" + expr +"))";
}
} else if(this.match_against == MatchAgainstEnum.MATCH_TAG_NAME) {
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) {
} else if(this.match_against === MatchAgainstEnum.MATCH_TAG_NAME) {
if(this.match_type === MatchTypeEnum.MATCH_EQUALS) {
return '(Tags.name="' + this.match_from + '")';
} else if(this.match_type == MatchTypeEnum.MATCH_NATURAL) {
var expr = '"' + '.*' + escape_regex(this.match_from) + '.*' + '"';
} else if(this.match_type === MatchTypeEnum.MATCH_NATURAL) {
expr = '".*' + escape_regex(this.match_from) + '.*"';
return '(LOWER(Tags.name) REGEXP LOWER("' + expr + '"))';
}
} else if(this.match_against == MatchAgainstEnum.MATCH_ALBUM_NAME) {
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) {
var expr = '\/(.*\/)*' + escape_regex(this.match_from);
} else if(this.match_against === MatchAgainstEnum.MATCH_ALBUM_NAME) {
if(this.match_type === MatchTypeEnum.MATCH_EQUALS) {
expr = '\/(.*\/)*' + escape_regex(this.match_from);
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.");
}
} else if(this.match_against == MatchAgainstEnum.MATCH_ALBUM_NAME_IN_TREE) {
if(this.match_type == MatchTypeEnum.MATCH_EQUALS) {
var expr = escape_regex(this.match_from) + '(\/[^\/]+)*';
} else if(this.match_against === MatchAgainstEnum.MATCH_ALBUM_NAME_IN_TREE) {
if(this.match_type === MatchTypeEnum.MATCH_EQUALS) {
expr = escape_regex(this.match_from) + '(\/[^\/]+)*';
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.");
}
}
@ -195,9 +196,9 @@ export class LogicalOperatorFilter extends ResultFilter {
var where1 = this.sub_filter_a.to_sql_where();
var where2 = this.sub_filter_b.to_sql_where();
var operator_str = "";
if (this.operator == LogicalOperatorEnum.AND) {
if (this.operator === LogicalOperatorEnum.AND) {
operator_str = " AND ";
} else if (this.operator == LogicalOperatorEnum.OR) {
} else if (this.operator === LogicalOperatorEnum.OR) {
operator_str = " OR ";
} else {
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 b = this.sub_filter_b.simplify();
if(this.operator == LogicalOperatorEnum.OR) {
if(this.operator === LogicalOperatorEnum.OR) {
if(a.is_true() || b.is_true()) {
return new ConstFilter(this.return_type, true);
}
@ -217,7 +218,7 @@ export class LogicalOperatorFilter extends ResultFilter {
if(b.is_false()) { return a; }
}
if(this.operator == LogicalOperatorEnum.AND) {
if(this.operator === LogicalOperatorEnum.AND) {
if(a.is_false() || b.is_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) {
if(filter instanceof ConstFilter && filter.constval == false) {
if(filter instanceof ConstFilter && filter.constval === false) {
return true;
}
// TODO resolve recursively
@ -286,10 +287,11 @@ export function filter_is_const_false(filter) {
function filter_from_text_segment(result_type, segment) {
var filter = false;
var name_filter;
if (result_type == ResultTypeEnum.IMAGE) {
if (result_type === ResultTypeEnum.IMAGE) {
// Option 1: match on image name
var name_filter = new MatchingFilter(
name_filter = new MatchingFilter(
result_type,
MatchAgainstEnum.MATCH_IMAGE_NAME,
segment['text'],
@ -308,9 +310,9 @@ function filter_from_text_segment(result_type, segment) {
if(segment['negated']) {
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
var name_filter = new MatchingFilter(
name_filter = new MatchingFilter(
result_type,
MatchAgainstEnum.MATCH_ALBUM_NAME,
segment['text'],
@ -320,9 +322,9 @@ function filter_from_text_segment(result_type, segment) {
if(segment['negated']) {
filter = new NegationFilter(result_type, filter);
}
} else if (result_type == ResultTypeEnum.TAG) {
} else if (result_type === ResultTypeEnum.TAG) {
// Match against the tag name.
var name_filter = new MatchingFilter(
name_filter = new MatchingFilter(
result_type,
MatchAgainstEnum.MATCH_TAG_NAME,
segment['text'],
@ -341,7 +343,7 @@ export function user_query_from_search_string(search_string) {
const parser = require('search-string');
var parsed = parser.parse(search_string);
var conditions = parsed.getParsedQuery();
//var conditions = parsed.getParsedQuery();
var texts = parsed.getTextSegments();
var r = new UserQuery();

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

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

Loading…
Cancel
Save