Skip to content

Commit

Permalink
Fixed eslint and grunt running. Added filter functions to image lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
5orenso committed Mar 28, 2019
1 parent 8969361 commit bf3d8ad
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 61 deletions.
18 changes: 17 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"node": true,
"jest": true
},
"extends": "airbnb-base",
"extends": [
"airbnb-base",
"standard-preact"
],
"plugins": [
"import"
],
Expand All @@ -14,8 +17,12 @@
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1 }],
"global-require": "warn",
"import/no-dynamic-require": "warn",
"import/extensions": ["error", "never", { "packages": "always" }],
"strict": 0,
"no-console": 0,
"react/jsx-indent": ["error", 4],
"react/jsx-indent-props": ["error", 2],
"quotes": ["error", "single",{ "allowTemplateLiterals": true }],
"prefer-destructuring": [
"error", {
"array": false,
Expand All @@ -32,5 +39,14 @@
"ExportDeclaration": { "multiline": true, "consistent": false, "minProperties": 6 }
}
]
},
"globals": {
"fetch": false,
"poly": false,
"document": false,
"window": false,
"localStorage": false,
"history": false,
"Favico": false
}
}
12 changes: 9 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ module.exports = function (grunt) {
config: '.eslintrc.json',
reset: true
},
target: ['app/**/*.js', 'lib/**/*.js', 'template/global/js/push-notification.js']
target: [
'app/**/*.js',
'lib/**/*.js',
'template/global/js/push-notification.js',
// 'preact/repair*/lib/**/*.js',
// 'preact/repair*/src/**/*.js',
]
},
jsdoc: {
dist: {
Expand Down Expand Up @@ -65,7 +71,7 @@ module.exports = function (grunt) {
options: {
script: 'app/server.js',
ext: 'js,json,html',
ignore: ['node_modules/*', 'template/*', 'sessions/*', 'preact/*'],
ignore: ['template/*', 'sessions/*', 'preact/*'],
args: ['-c', '../config/config.js'],
env: {
nodeEnv: 'development'
Expand All @@ -77,7 +83,7 @@ module.exports = function (grunt) {
options: {
script: 'app/server.js',
ext: 'js,json,html',
ignore: ['node_modules/*', 'template/*', 'sessions/*', 'preact/*'],
ignore: ['template/*', 'sessions/*', 'preact/*'],
args: ['-c', '../config/config-local.js'],
env: {
nodeEnv: 'development'
Expand Down
44 changes: 44 additions & 0 deletions app/routes/api/get-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,54 @@ module.exports = async (req, res) => {
query.category = req.params.category;
}

// Fields to consider:
const queryFieldsString = [
'exif.model',
'exif.lensModel',
'exif.exposureTime',
'exif.photographicSensitivity',
];
const queryFieldsNumber = [
'exif.fNumber',
'exif.focalLength',
];
const queryFieldsArrayObject = [
['predictions.className', { probability: { $gte: 0.2 } }],
['predictionsCocoSsd.class', { score: { $gte: 0 } }],
];
for (let i = 0, l = queryFieldsString.length; i < l; i += 1) {
const field = queryFieldsString[i];
if (req.query.hasOwnProperty(field)) {
// TODO: Should santitize this field.
query[field] = { $regex: req.query[field], $options: 'i' };
}
}
for (let i = 0, l = queryFieldsNumber.length; i < l; i += 1) {
const field = queryFieldsNumber[i];
if (req.query.hasOwnProperty(field)) {
// TODO: Should santitize this field.
query[field] = parseFloat(req.query[field]);
}
}
for (let i = 0, l = queryFieldsArrayObject.length; i < l; i += 1) {
const arrayField = queryFieldsArrayObject[i];
const field = arrayField[0];
const fieldQuery = arrayField[1];
if (req.query.hasOwnProperty(field)) {
// TODO: Should santitize this field.
const parts = field.split('.');
const arrayName = parts[0];
const objKey = parts[1];
query[arrayName] = { $elemMatch: { [objKey]: req.query[field], ...fieldQuery } };
}
}

query = webUtil.cleanObject(query);
const limit = parseInt(req.query.limit || 10, 10);
const skip = parseInt(req.query.offset || 0, 10);

console.log('query', query);

let apiContent;
let total;
let data = {};
Expand Down
42 changes: 20 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,22 @@
"coverage": "jest --coverage --coverageReporters=text-lcov | coveralls"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"@tensorflow-models/mobilenet": "^1.0.0",
"@tensorflow-models/coco-ssd": "^1.0.0",
"@tensorflow/tfjs": "^1.0.2",
"@tensorflow/tfjs-core": "^1.0.2",
"@tensorflow/tfjs-core": "^1.0.3",
"@tensorflow/tfjs-node": "^1.0.2",
"buster": "^0.7.18",
"buster-istanbul": "^0.1.15",
"coveralls": "^3.0.2",
"eslint": "^5.12.0",
"eslint": "^5.15.3",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-standard-preact": "^1.1.6",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"grunt": "^1.0.3",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"grunt": "^1.0.4",
"grunt-buster": "^0.4.2",
"grunt-contrib-nodeunit": "^2.0.0",
"grunt-contrib-watch": "^1.1.0",
Expand All @@ -58,40 +56,40 @@
"grunt-webpack": "^3.1.3",
"html-md": "~3.0.2",
"ink-docstrap": "^1.3.2",
"jest": "^24.0.0",
"jest": "^24.5.0",
"jpeg-js": "^0.3.4",
"jsdoc": "^3.5.5",
"mockingoose": "^2.12.0",
"node-gyp": "^3.8.0",
"request": "~2.88.0",
"sinon": "^7.2.3",
"sinon": "^7.3.1",
"time-grunt": "^2.0.0",
"uglifyjs-webpack-plugin": "^2.1.1",
"webpack": "^4.29.0",
"uglifyjs-webpack-plugin": "^2.1.2",
"webpack": "^4.29.6",
"xml2js": "~0.4.19"
},
"keywords": [],
"dependencies": {
"body-parser": "^1.18.3",
"client-sessions": "^0.8.0",
"commander": "^2.19.0",
"compression": "^1.7.3",
"compression": "^1.7.4",
"cors": "^2.8.5",
"elasticsearch": "^15.3.1",
"elasticsearch": "^15.4.1",
"exif": "^0.6.0",
"express": "^4.16.4",
"express-fileupload": "^1.1.1-alpha.1",
"express-jwt": "^5.3.1",
"highlight.js": "^9.14.2",
"highlight.js": "^9.15.6",
"imagemagick": "^0.1.3",
"jest-runner-eslint": "^0.7.3",
"js-yaml": "^3.12.1",
"jsonwebtoken": "^8.4.0",
"js-yaml": "^3.13.0",
"jsonwebtoken": "^8.5.1",
"lynx": "^0.2.0",
"marked": "^0.6.0",
"marked": "^0.6.1",
"mkdirp": "^0.5.1",
"moment": "^2.24.0",
"mongoose": "^5.4.8",
"mongoose": "^5.4.20",
"morgan": "^1.9.1",
"node-dogstatsd": "0.0.7",
"rest": "^2.0.0",
Expand All @@ -102,7 +100,7 @@
"uuid": "^3.3.2",
"walk": "^2.3.14",
"web-push": "^3.3.3",
"websequencediagrams": "0.1.1"
"websequencediagrams": "1.0.0"
},
"jest": {
"collectCoverageFrom": [
Expand Down
2 changes: 1 addition & 1 deletion preact/simple-blog-cms/build/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion preact/simple-blog-cms/build/bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion preact/simple-blog-cms/build/sw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 22 additions & 8 deletions preact/simple-blog-cms/lib/components/articleEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export default class ArticleEdit extends Component {
const handleImageInput = props.handleImageInput;
const handleImageSubmit = props.handleImageSubmit;
const handleImglistClick = props.handleImglistClick;
const handleImageTagClick = props.handleImageTagClick;

const imglist = props.imglist;
const filterQuery = props.filterQuery;

const images = article.img || [];
const imagesTotal = images.length;
Expand Down Expand Up @@ -233,24 +235,36 @@ export default class ArticleEdit extends Component {
<h3>Bildearkivet:</h3>
<div class='col-12'>
<div class='d-flex justify-content-center'>
<div class="col-8 mb-2">
<div class="col-10 mb-2">
<input type="text" class="form-control" placeholder="Søk etter bilder" name="q"
onKeypress={e => handleImageInput(e, 54)}
/>
</div>
<div class="col-2">
<button class="btn btn-success" onclick={e => handleImageSubmit(e, 54)}>Søk</button>
</div>

</div>
</div>
<div class='row'>
{imglist.map((img, idx) => {
return (
<div class='col-2 p-1'>
<img src={`${this.imageServer}/pho/${img.src}?w=${imageWidth}`} class='img-fluid' data-idx={idx} onclick={handleImglistClick} />
</div>
);
})}
<div class='col-12'>
{Object.keys(filterQuery).map(key =>
<span class={`mr-1 badge badge-danger`}
data-name={key}
data-value={filterQuery[key]}
onClick={handleImageTagClick}
>
{key}: {filterQuery[key]}
</span>
)}
</div>
{imglist.map((img, idx) => {
return (
<div class='col-2 p-1'>
<img src={`${this.imageServer}/pho/${img.src}?w=${imageWidth}`} class='img-fluid' data-idx={idx} onclick={handleImglistClick} />
</div>
);
})}
</div>
</div>
)}
Expand Down
Loading

0 comments on commit bf3d8ad

Please sign in to comment.