mirror of
https://gitlab.silvrtree.co.uk/martind2000/recipes.git
synced 2025-01-10 21:05:08 +00:00
updates to stop it breaking with an empty table
This commit is contained in:
parent
4bce53d91b
commit
79f1f5704a
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@
|
||||
|
||||
*.iml
|
||||
|
||||
/dist
|
||||
## Directory-based project format:
|
||||
.idea/
|
||||
# if you remove the above rule, at least ignore the following:
|
||||
|
30
.jshintrc
Normal file
30
.jshintrc
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"node": true,
|
||||
"esnext": true,
|
||||
"bitwise": true,
|
||||
"camelcase": true,
|
||||
"curly": true,
|
||||
"eqeqeq": true,
|
||||
"immed": true,
|
||||
"indent": 2,
|
||||
"latedef": true,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"quotmark": "single",
|
||||
"regexp": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"strict": true,
|
||||
"trailing": true,
|
||||
"smarttabs": true,
|
||||
"white": true,
|
||||
"validthis": true,
|
||||
"browser" : true,
|
||||
"jquery":true,
|
||||
|
||||
"globals": {
|
||||
|
||||
"angular": false
|
||||
|
||||
}
|
||||
}
|
@ -7,8 +7,10 @@
|
||||
<link href="//fonts.googleapis.com/css?family=Roboto+Slab:400,300,700" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" href="//cdn.linearicons.com/free/1.0.0/icon-font.min.css">
|
||||
<link href="//cdn.muicss.com/mui-0.4.6/css/mui.min.css" rel="stylesheet" type="text/css" />
|
||||
<!-- inject:css -->
|
||||
<link href="css/app.css" rel="stylesheet" type="text/css" />
|
||||
<link href="css/md.css" rel="stylesheet" type="text/css" />
|
||||
<!-- endinject -->
|
||||
<script src="//cdn.muicss.com/mui-0.4.6/js/mui.min.js"></script>
|
||||
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
|
||||
<script src="libs/ejs.js"></script>
|
||||
@ -58,6 +60,8 @@
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
<!-- inject:js -->
|
||||
<script src="js/shell.js"></script>
|
||||
<script src="js/app.js"></script>
|
||||
<!-- endinject -->
|
||||
</html>
|
@ -1,3 +1,4 @@
|
||||
'use strict';
|
||||
/**
|
||||
* Created by Martin on 24/02/2016.
|
||||
*/
|
||||
@ -7,15 +8,14 @@ $.fn.pressEnter = function (fn) {
|
||||
return this.each(function () {
|
||||
$(this).bind('enterPress', fn);
|
||||
$(this).keyup(function (e) {
|
||||
if (e.keyCode == 13) {
|
||||
$(this).trigger("enterPress");
|
||||
if (e.keyCode === 13) {
|
||||
$(this).trigger('enterPress');
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
console.log('GO!');
|
||||
var $list = $('#listContainer');
|
||||
var displayList = function (obj) {
|
||||
@ -23,7 +23,7 @@ $.fn.pressEnter = function (fn) {
|
||||
console.log(html);
|
||||
$list.empty();
|
||||
$list.append(html);
|
||||
$("#listContainer .entry").not('.emptyMessage').click(function () {
|
||||
$('#listContainer').find('.entry').not('.emptyMessage').click(function () {
|
||||
console.log('Clicked list. ' + this.id);
|
||||
getRecipe(this.id);
|
||||
});
|
||||
@ -58,7 +58,7 @@ $.fn.pressEnter = function (fn) {
|
||||
displayPage(data);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log('ajax error');
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
@ -89,7 +89,7 @@ $.fn.pressEnter = function (fn) {
|
||||
displayList(data);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log('ajax error');
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
@ -113,12 +113,12 @@ $.fn.pressEnter = function (fn) {
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
|
||||
},
|
||||
success: function (data) {
|
||||
success: function () {
|
||||
// console.log(data);
|
||||
// displayList(data);
|
||||
},
|
||||
error: function (xhr, type) {
|
||||
console.log("ajax error");
|
||||
console.log('ajax error');
|
||||
console.log(xhr);
|
||||
console.log(type);
|
||||
}
|
||||
@ -131,14 +131,14 @@ $.fn.pressEnter = function (fn) {
|
||||
|
||||
$('#newurl').pressEnter(function () {
|
||||
var url = $(this).val();
|
||||
if (url != null) {
|
||||
if (url !== null) {
|
||||
console.log('Adding: ' + url);
|
||||
addNew(url);
|
||||
$('#addstatus').fadeIn(400).delay(1500).fadeOut(400);
|
||||
$(this).val('');
|
||||
setTimeout((function () {
|
||||
setTimeout(function () {
|
||||
getList();
|
||||
}), 5000);
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
|
||||
|
13
gulp/build.js
Normal file
13
gulp/build.js
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var gulp = require('gulp');
|
||||
|
||||
|
||||
function handleError(err) {
|
||||
console.error(err.toString());
|
||||
this.emit('end');
|
||||
}
|
||||
|
||||
gulp.task('clean', function () {
|
||||
return gulp.src(['.tmp', 'dist'], { read: false }).pipe($.rimraf());
|
||||
});
|
73
gulpfile.js
Normal file
73
gulpfile.js
Normal file
@ -0,0 +1,73 @@
|
||||
"use strict";
|
||||
var gulp = require('gulp'),
|
||||
|
||||
autoprefixer = require('gulp-autoprefixer'),
|
||||
cssnano = require('gulp-cssnano'),
|
||||
jshint = require('gulp-jshint'),
|
||||
uglify = require('gulp-uglify'),
|
||||
|
||||
rename = require('gulp-rename'),
|
||||
concat = require('gulp-concat'),
|
||||
notify = require('gulp-notify'),
|
||||
cache = require('gulp-cache'),
|
||||
livereload = require('gulp-livereload'),
|
||||
htmlmin = require('gulp-htmlmin'),
|
||||
inject = require('gulp-inject'),
|
||||
del = require('del');
|
||||
|
||||
|
||||
|
||||
gulp.task('scripts', function() {
|
||||
return gulp.src('app/js/**/*.js')
|
||||
.pipe(jshint('.jshintrc'))
|
||||
.pipe(jshint.reporter('default'))
|
||||
.pipe(concat('main.js'))
|
||||
.pipe(gulp.dest('dist/js'))
|
||||
.pipe(rename({suffix: '.min'}))
|
||||
.pipe(uglify())
|
||||
.pipe(gulp.dest('dist/js'))
|
||||
.pipe(notify({ message: 'Scripts task complete' }));
|
||||
});
|
||||
|
||||
gulp.task('styles', function() {
|
||||
return gulp.src('app/css/**/*.css')
|
||||
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
|
||||
.pipe(gulp.dest('dist/css'))
|
||||
.pipe(rename({suffix: '.min'}))
|
||||
.pipe(cssnano())
|
||||
.pipe(gulp.dest('dist/css'))
|
||||
.pipe(notify({ message: 'Styles task complete' }));
|
||||
});
|
||||
|
||||
gulp.task('partials', function() {
|
||||
|
||||
gulp.src(['app/partials/**/*']).pipe(gulp.dest('dist/partials'));
|
||||
gulp.src(['app/libs/ejs_production.js']).pipe(gulp.dest('dist/libs'));
|
||||
});
|
||||
|
||||
gulp.task('minify-html', function () {
|
||||
var sources = gulp.src(['dist/**/*.min.js', 'dist/**/*.min.css'], {read: false});
|
||||
var appstream = gulp.src(['dist/**/*.min.js'], {read:false});
|
||||
return gulp.src(['app/*.html']).pipe(inject(gulp.src(['./dist/js/**/*.min.js', './dist/css/**/*.min.css'], {read: false}), {
|
||||
starttag: '"main": [',
|
||||
endtag: ']',
|
||||
transform: function (filepath, file, i, length) {
|
||||
return ' "' + filepath + '"' + (i + 1 < length ? ',' : '');
|
||||
}
|
||||
}))
|
||||
.pipe(gulp.dest('dist'));
|
||||
/*.pipe(gulp.dest('./'));
|
||||
.pipe(inject(sources),{relative:true})
|
||||
/!*.pipe(htmlmin({removeComments: true, collapseWhitespace: true, keepClosingSlash: true}))*!/
|
||||
.pipe(gulp.dest('dist'));*/
|
||||
});
|
||||
|
||||
|
||||
gulp.task('clean', function() {
|
||||
return del(['dist']);
|
||||
});
|
||||
|
||||
|
||||
gulp.task('default', ['clean'], function() {
|
||||
gulp.start('styles', 'scripts','partials','minify-html');
|
||||
});
|
15
package.json
15
package.json
@ -14,11 +14,26 @@
|
||||
"cookie-parser": "^1.4.1",
|
||||
"express": "^4.13.4",
|
||||
"morgan": "^1.7.0",
|
||||
"require-dir": "^0.3.0",
|
||||
"serve-favicon": "^2.3.0",
|
||||
"sqlite3": "^3.1.1",
|
||||
"string": "^3.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"del": "^2.2.0",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-autoprefixer": "^3.1.0",
|
||||
"gulp-cache": "^0.4.2",
|
||||
"gulp-concat": "^2.6.0",
|
||||
"gulp-cssnano": "^2.1.1",
|
||||
"gulp-htmlmin": "^1.3.0",
|
||||
"gulp-inject": "^3.0.0",
|
||||
"gulp-jshint": "^2.0.0",
|
||||
"gulp-livereload": "^3.8.1",
|
||||
"gulp-notify": "^2.2.0",
|
||||
"gulp-rename": "^1.2.2",
|
||||
"gulp-uglify": "^1.5.3",
|
||||
"jshint": "^2.9.1",
|
||||
"jsonfile": "^2.2.3",
|
||||
"log4js": "^0.6.31",
|
||||
"simplecrawler": "^0.6.2"
|
||||
|
@ -25,7 +25,7 @@ app.use(logger('dev'));
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.use(cookieParser());
|
||||
app.use(express.static(path.join(__dirname, 'app')));
|
||||
app.use(express.static(path.join(__dirname, 'dist')));
|
||||
|
||||
app.use('/recipes', recipes);
|
||||
//app.use('/users', users);
|
||||
|
@ -137,13 +137,15 @@ router.get('/list', function(req, res) {
|
||||
db.all('select id, title from `recipes` where title is not null;', function (err, rows) {
|
||||
|
||||
var out = [];
|
||||
|
||||
if (rows !== null && rows.length > 0)
|
||||
// logger.debug(err);
|
||||
// logger.debug(rows);
|
||||
rows.forEach(function (row) {
|
||||
|
||||
out.push({"id": row.id, "title": row.title});
|
||||
});
|
||||
rows.forEach(function (row) {
|
||||
|
||||
out.push({"id": row.id, "title": row.title});
|
||||
});
|
||||
}
|
||||
res.writeHead(200, {"ContentType": "application/json"});
|
||||
//res.send(JSON.stringify(t));
|
||||
res.end(JSON.stringify({list:out}));
|
||||
@ -163,20 +165,20 @@ router.get('/entry/:id', function(req, res) {
|
||||
var out = [];
|
||||
// logger.debug(err);
|
||||
// logger.debug(rows);
|
||||
rows.forEach(function (row) {
|
||||
if (rows !== null && rows.length > 0)
|
||||
rows.forEach(function (row) {
|
||||
|
||||
var d = {"id": row.id, "title": row.title};
|
||||
|
||||
if (row.reduced.length !== 0) {
|
||||
d.body = row.reduced;
|
||||
}
|
||||
else
|
||||
{
|
||||
d.body = row.html;
|
||||
}
|
||||
out.push(d);
|
||||
});
|
||||
var d = {"id": row.id, "title": row.title};
|
||||
|
||||
if (row.reduced.length !== 0) {
|
||||
d.body = row.reduced;
|
||||
}
|
||||
else {
|
||||
d.body = row.html;
|
||||
}
|
||||
out.push(d);
|
||||
});
|
||||
}
|
||||
res.writeHead(200, {"ContentType": "application/json"});
|
||||
//res.send(JSON.stringify(t));
|
||||
res.end(JSON.stringify({list:out}));
|
||||
|
Loading…
Reference in New Issue
Block a user