Razique Mahroua
2019-12-06 ac3b23a9e629e421955ff0927f710a084078505b
Reimport proper files for the todo application
4 files deleted
9 files added
1 files modified
17 files renamed
376 ■■■■ changed files
todo-single/Dockerfile 38 ●●●● patch | view | raw | blame | history
todo-single/build.sh 10 ●●●●● patch | view | raw | blame | history
todo-single/enable-rh-nodejs8.sh 3 ●●●●● patch | view | raw | blame | history
todo-single/nginx.conf 64 ●●●●● patch | view | raw | blame | history
todo-single/nodejs-source/README.md 17 ●●●●● patch | view | raw | blame | history
todo-single/nodejs-source/app.js 56 ●●●●● patch | view | raw | blame | history
todo-single/nodejs-source/compile.sh 3 ●●●●● patch | view | raw | blame | history
todo-single/nodejs-source/controllers/items.js 51 ●●●●● patch | view | raw | blame | history
todo-single/nodejs-source/models/db.js 11 ●●●●● patch | view | raw | blame | history
todo-single/nodejs-source/models/items.js 41 ●●●● patch | view | raw | blame | history
todo-single/nodejs-source/package.json 10 ●●●●● patch | view | raw | blame | history
todo-single/nodejs-source/run.sh 4 ●●●● patch | view | raw | blame | history
todo-single/nodejs-source/todo/css/style.css patch | view | raw | blame | history
todo-single/nodejs-source/todo/hello.html patch | view | raw | blame | history
todo-single/nodejs-source/todo/index.html patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/angular-resource.min.js patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/angular.min.js patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/css/bootstrap.min.css patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/css/ng-grid.min.css patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/fonts/glyphicons-halflings-regular.eot patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/fonts/glyphicons-halflings-regular.svg patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/fonts/glyphicons-halflings-regular.ttf patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/fonts/glyphicons-halflings-regular.woff patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/jquery.min.js patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/ng-grid-2.0.11.min.js patch | view | raw | blame | history
todo-single/nodejs-source/todo/lib/dependencies/ui-bootstrap-tpls.min.js patch | view | raw | blame | history
todo-single/nodejs-source/todo/script/item.js patch | view | raw | blame | history
todo-single/run.sh 4 ●●●● patch | view | raw | blame | history
todo-single/src/app.js 38 ●●●●● patch | view | raw | blame | history
todo-single/src/models/db.js 10 ●●●●● patch | view | raw | blame | history
todo-single/src/package.json 16 ●●●●● patch | view | raw | blame | history
todo-single/Dockerfile
@@ -1,26 +1,26 @@
FROM registry.access.redhat.com/ubi8:8.0
FROM    ubi7/ubi:7.7
LABEL version="1.0" \
  description="To Do List application front-end" \
  creationDate="2017-12-25" \
  updatedDate="2019-11-28"
MAINTAINER username <username@example.com>
ENV BACKEND_HOST=localhost:8081
ENV     NODEJS_VERSION=8.0 \
        HOME=/opt/app-root/src
RUN yum install -y --disableplugin=subscription-manager --nodocs \
  nginx nginx-mod-http-perl \
  && yum clean all
RUN     yum install -y --setopt=tsflags=nodocs rh-nodejs8 make && \
        yum clean all -y && \
        mkdir -p /opt/app-root && \
        groupadd -r appuser -f -g 1001 && \
        useradd -u 1001 -r -g appuser -m -d ${HOME} -s /sbin/nologin \
          -c "Application User" appuser && \
        chown -R appuser:appuser /opt/app-root && \
        chmod -R 755 /opt/app-root
COPY nginx.conf /etc/nginx/
ADD     ./enable-rh-nodejs8.sh /etc/profile.d/
RUN touch /run/nginx.pid \
  && chgrp -R nginx /var/log/nginx /run/nginx.pid \
  && chmod -R g+rwx /var/log/nginx /run/nginx.pid
COPY    run.sh build ${HOME}/
WORKDIR ${HOME}
RUN     scl enable rh-nodejs8 'npm install'
COPY src/ /usr/share/nginx/html
EXPOSE  8080
USER    1001
EXPOSE 8080
USER nginx
CMD nginx -g "daemon off;"
CMD ["scl","enable","rh-nodejs8","./run.sh"]
todo-single/build.sh
New file
@@ -0,0 +1,10 @@
#!/bin/bash
echo "Preparing build folder"
rm -fr build
mkdir -p build
cp -ap nodejs-source/* build
rm build/*.sh
chmod -R a+rwX build
podman build --layers=false -t do280/todo-single .
todo-single/enable-rh-nodejs8.sh
New file
@@ -0,0 +1,3 @@
#!/bin/bash
source /opt/rh/rh-nodejs8/enable
export X_SCLS="`scl enable rh-nodejs8 'echo $X_SCLS'`"
todo-single/nginx.conf
File was deleted
todo-single/nodejs-source/README.md
New file
@@ -0,0 +1,17 @@
# DO276 JavaScript/Node.js To Do List App
Based on Restify 4.0 and Sequelize 3.14. Tested on Node.js 0.10 from SCL with
Mariadb 5.5.
Do `npm install` do download dependencies.
Run as `node app.js`
* Don't do pagination yet.
* Database connection parameters hardcoded (as a novice developer would usually do).
* There is a lot of boiler plate code in the controller and the model. There should
  be a way to have more centralized error handling.
* Access app as http://localhost:30080/todo
todo-single/nodejs-source/app.js
New file
@@ -0,0 +1,56 @@
var restify = require('restify');
var controller = require('./controllers/items');
var db = require('./models/db');
var model = require('./models/items');
model.connect(db.params, function(err) {
    if (err) throw err;
});
var server = restify.createServer()
    .use(restify.plugins.fullResponse())
    .use(restify.plugins.queryParser())
    .use(restify.plugins.bodyParser());
controller.context(server, '/todo/api', model);
server.get({
    path: '/todo/api/items/:id'
}, controller.read);
server.get({
    path: '/todo/api/items'
}, controller.list);
server.post({
    path: '/todo/api/items'
}, controller.save);
server.del({
    path: '/todo/api/items/:id'
}, controller.destroy);
server.get({
    path: '/todo/*',
    name: 'todoapi'
    }, restify.plugins.serveStatic({
    'directory': __dirname,
    'default': 'index.html'
}));
var port = process.env.APP_PORT || 8080;
server.listen(port, function (err) {
    if (err)
        console.error(err);
    else
        console.log('App is ready at : ' + port);
});
if (process.env.environment == 'production')
    process.on('uncaughtException', function (err) {
        console.error(JSON.parse(JSON.stringify(err, ['stack', 'message', 'inner'], 2)))
    });
todo-single/nodejs-source/compile.sh
New file
@@ -0,0 +1,3 @@
#!/bin/bash
npm install
todo-single/nodejs-source/controllers/items.js
File was renamed from todo-single/src/controllers/items.js
@@ -9,11 +9,10 @@
    if (path)
        context = path + context;
        
    server.get(context + '/', this.list);
    server.get(context + '/:id', this.read);
    server.get(context + '-count', this.count);
    server.post(context + '/', this.save);
    server.del(context + '/:id', this.destroy);
    // server.get(context + '/', this.list);
    // server.get(context + '/:id', this.read);
    // server.post(context + '/', this.save);
    // server.del(context + '/:id', this.destroy);
    
    model = itemsModel;
};
@@ -25,13 +24,13 @@
    model.listAll(page_no, sortField, sortDirection, function(err, items) {
        if (err) {
            res.send(err);
            next(err);
        }
        else {
            if (items) {
                model.countAll(function(err, n) {
                    if (err) {
                        res.send(err);
                        next(err);
                    }
                    else {
                        if (n) {
@@ -46,11 +45,14 @@
                            res.json(page);
                            next();
                        }
                        else {
                            next(new Error("Can't count items"));
                        }
                    }
                });
            }
            else {
                res.send(err);
                next(new Error("Can't retrieve items"));
            }
        }
    })
@@ -60,7 +62,7 @@
    var key = req.params.id;
    model.read(key, function(err, item) {
        if (err) {
            res.send(err);
            next(err);
        }
        else {
            if (item) {
@@ -68,34 +70,18 @@
                next();
            }
            else {
                res.send(err);
                next(new Error("Can't retrieve items"));
            }
        }
    })
};
exports.count = function(req, res, next) {
    model.countAll(function(err, n) {
        if (err) {
            res.send(err);
        }
        else {
            var page = {
              count: n
            };
            res.json(page)
            next();
        }
    })
};
exports.save = function(req, res, next) {
    if (req.params.id) {
        model.update(req.params.id, req.params.description, req.params.done, function(err, item) {
    if (req.body.id) {
        model.update(req.body.id, req.body.description, req.body.done, function(err, item) {
            if (err) {
                res.send(err);
                next(err);
            }
            else {
                res.json(item);
@@ -104,9 +90,9 @@
        });
    }
    else {
        model.create(req.params.description, req.params.done, function(err, item) {
        model.create(req.body.description, req.body.done, function(err, item) {
            if (err) {
                res.send(err);
                next(err);
            }
            else {
                res.json(item);
@@ -121,9 +107,10 @@
    if (req.params.id) {
        model.destroy(req.params.id, function(err, item) {
            if (err) {
                res.send(err);
                next(err);
            }
            else {
                //XXX jee_api does NOT return item on delete
                res.json(item);
            }
        });
todo-single/nodejs-source/models/db.js
New file
@@ -0,0 +1,11 @@
module.exports.params = {
  dbname: process.env.MYSQL_ENV_MYSQL_DATABASE,
  username: process.env.MYSQL_ENV_MYSQL_USER,
  password: process.env.MYSQL_ENV_MYSQL_PASSWORD,
  params: {
      host: process.env.MYSQL_SERVICE_HOST,
      port: process.env.MYSQL_SERVICE_PORT,
      dialect: 'mysql'
  }
};
todo-single/nodejs-source/models/items.js
File was renamed from todo-single/src/models/items.js
@@ -18,14 +18,14 @@
        timestamps: false,
        freezeTableName: true
    });
    if (process.env.DATABASE_INIT == 'true') {
        Item.sync({ force: true }).then(function() {
            callback();
        }).catch(function(err) {
            callback(err);
        });
    }
    // drop and create tables, better done globally
    /*
    Item.sync({ force: true }).then(function() {
        callback();
    }).error(function(err) {
        callback(err);
    });
    */
}
exports.disconnect = function(callback) {
@@ -40,18 +40,18 @@
        done: (done) ? true : false
    }).then(function(item) {
        callback(null, item);
    }).catch(function(err) {
    }).error(function(err) {
        callback(err);
    });
}
exports.update = function(key, description, done, callback) {
    Item.find({ where:{ id: key } }).then(function(item) {
    Item.findOne({ where:{ id: key } }).then(function(item) {
        if (!item) {
            callback(new Error("Nothing found for key " + key));
        }
        else {
            item.updateAttributes({
            item.update({
                description: description,
                done: (done) ? true : false
            }).then(function() {
@@ -60,14 +60,14 @@
                callback(err);
            });
        }
    }).catch(function(err) {
    }).error(function(err) {
        callback(err);
    });
}
exports.read = function(key, callback) {
    Item.find({ where:{ id: key } }).then(function(item) {
    Item.findOne({ where:{ id: key } }).then(function(item) {
        if (!item) {
            callback(new Error("Nothing found for key " + key));
        }
@@ -79,13 +79,13 @@
                done: item.done
            });
        }
    }).catch(function(err) {
    }).error(function(err) {
        callback(err);
    });
}
exports.destroy = function(key, callback) {
    Item.find({ where:{ id: key } }).then(function(item) {
    Item.findOne({ where:{ id: key } }).then(function(item) {
        if (!item) {
            callback(new Error("Nothing found for " + key));
        }
@@ -96,19 +96,18 @@
                callback(err);
            });
        }
    }).catch(function(err) {
    }).error(function(err) {
        callback(err);
    });
}
exports.countAll = function(callback) {
    Item.findAll({
        attributes: [[Sequelize.fn('COUNT', Sequelize.col('id')), 'no_items']]
    }).then(function(n) {
    Item.findAll({ attributes: [[Sequelize.fn('COUNT', Sequelize.col('id')), 'no_items']] } ).then(function(n) {
        callback(null, n[0].get('no_items'));
    }).catch(function(err) {
    }).error(function(err) {
        callback(err);
    });
   //callback(null, 100);
}
exports.listAll = function(page, sortField, sortDirection, callback) {
@@ -120,7 +119,7 @@
                id: item.id, description: item.description, done: item.done });
        });
        callback(null, theitems);
    }).catch(function(err) {
    }).error(function(err) {
        callback(err);
    });
}
todo-single/nodejs-source/package.json
New file
@@ -0,0 +1,10 @@
{
  "name": "todo",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "restify": "8.4.0",
    "sequelize": "5.21.1",
    "mysql2": "2.0.0"
  }
}
todo-single/nodejs-source/run.sh
New file
@@ -0,0 +1,4 @@
#!/bin/bash
node app.js
todo-single/nodejs-source/todo/css/style.css
todo-single/nodejs-source/todo/hello.html
todo-single/nodejs-source/todo/index.html
todo-single/nodejs-source/todo/lib/dependencies/angular-resource.min.js
todo-single/nodejs-source/todo/lib/dependencies/angular.min.js
todo-single/nodejs-source/todo/lib/dependencies/css/bootstrap.min.css
todo-single/nodejs-source/todo/lib/dependencies/css/ng-grid.min.css
todo-single/nodejs-source/todo/lib/dependencies/fonts/glyphicons-halflings-regular.eot
Binary files differ
todo-single/nodejs-source/todo/lib/dependencies/fonts/glyphicons-halflings-regular.svg
todo-single/nodejs-source/todo/lib/dependencies/fonts/glyphicons-halflings-regular.ttf
Binary files differ
todo-single/nodejs-source/todo/lib/dependencies/fonts/glyphicons-halflings-regular.woff
Binary files differ
todo-single/nodejs-source/todo/lib/dependencies/jquery.min.js
todo-single/nodejs-source/todo/lib/dependencies/ng-grid-2.0.11.min.js
todo-single/nodejs-source/todo/lib/dependencies/ui-bootstrap-tpls.min.js
todo-single/nodejs-source/todo/script/item.js
todo-single/run.sh
New file
@@ -0,0 +1,4 @@
#!/bin/sh
node app.js
todo-single/src/app.js
File was deleted
todo-single/src/models/db.js
File was deleted
todo-single/src/package.json
File was deleted