diff --git a/categories/categories.client.module.js b/categories/categories.client.module.js new file mode 100644 index 0000000..2a972a0 --- /dev/null +++ b/categories/categories.client.module.js @@ -0,0 +1,4 @@ +'use strict'; + +// Use application configuration module to register a new module +ApplicationConfiguration.registerModule('core'); diff --git a/categories/category-server-model.server.model.js b/categories/category-server-model.server.model.js new file mode 100644 index 0000000..54fb2b0 --- /dev/null +++ b/categories/category-server-model.server.model.js @@ -0,0 +1,40 @@ +'use strict'; + +/** + * Module dependencies. + */ +var mongoose = require('mongoose'), + Schema = mongoose.Schema; + +function validateLength (v) { + // a custom validation function for checking string length to be used by the model + return v.length <= 15; +} +/** + * CategoryServerModel Schema + */ +var CategoryServerModelSchema = new Schema({ + created:{ + type:Date, + default:Date.now + }, + description:{ + type:String, + default:'', + trin:true + }, + name: { + type: String, + default: '', + trim: true, + unique : true, + // make this a required field + required: 'name cannot be blank', + // wires in a custom validator function (http://mongoosejs.com/docs/api.html#schematype_SchemaType-validate). + validate: [validateLength, 'name must be 15 chars in length or less'] + } + // CategoryServerModel model fields + // ... +}); + +mongoose.model('CategoryServerModel', CategoryServerModelSchema); diff --git a/categories/config.js b/categories/config.js new file mode 100644 index 0000000..f2db078 --- /dev/null +++ b/categories/config.js @@ -0,0 +1,186 @@ +'use strict'; + +/** + * Module dependencies. + */ +var _ = require('lodash'), + chalk = require('chalk'), + glob = require('glob'), + fs = require('fs'), + path = require('path'); + +/** + * Get files by glob patterns + */ +var getGlobbedPaths = function (globPatterns, excludes) { + // URL paths regex + var urlRegex = new RegExp('^(?:[a-z]+:)?\/\/', 'i'); + + // The output array + var output = []; + + // If glob pattern is array so we use each pattern in a recursive way, otherwise we use glob + if (_.isArray(globPatterns)) { + globPatterns.forEach(function (globPattern) { + output = _.union(output, getGlobbedPaths(globPattern, excludes)); + }); + } else if (_.isString(globPatterns)) { + if (urlRegex.test(globPatterns)) { + output.push(globPatterns); + } else { + var files = glob.sync(globPatterns); + if (excludes) { + files = files.map(function (file) { + if (_.isArray(excludes)) { + for (var i in excludes) { + file = file.replace(excludes[i], ''); + } + } else { + file = file.replace(excludes, ''); + } + return file; + }); + } + output = _.union(output, files); + } + } + + return output; +}; + +/** + * Validate NODE_ENV existance + */ +var validateEnvironmentVariable = function () { + var environmentFiles = glob.sync('./config/env/' + process.env.NODE_ENV + '.js'); + console.log(); + if (!environmentFiles.length) { + if (process.env.NODE_ENV) { + console.error(chalk.red('+ Error: No configuration file found for "' + process.env.NODE_ENV + '" environment using development instead')); + } else { + console.error(chalk.red('+ Error: NODE_ENV is not defined! Using default development environment')); + } + process.env.NODE_ENV = 'development'; + } + // Reset console color + console.log(chalk.white('')); +}; + +/** + * Validate Secure=true parameter can actually be turned on + * because it requires certs and key files to be available + */ +var validateSecureMode = function (config) { + + if (config.secure !== true) { + return true; + } + + var privateKey = fs.existsSync('./config/sslcerts/key.pem'); + var certificate = fs.existsSync('./config/sslcerts/cert.pem'); + + if (!privateKey || !certificate) { + console.log(chalk.red('+ Error: Certificate file or key file is missing, falling back to non-SSL mode')); + console.log(chalk.red(' To create them, simply run the following from your shell: sh ./scripts/generate-ssl-certs.sh')); + console.log(); + config.secure = false; + } +}; + +/** + * Initialize global configuration files + */ +var initGlobalConfigFolders = function (config, assets) { + // Appending files + config.folders = { + server: {}, + client: {} + }; + + // Setting globbed client paths + config.folders.client = getGlobbedPaths(path.join(process.cwd(), 'modules/*/client/'), process.cwd().replace(new RegExp(/\\/g), '/')); +}; + +/** + * Initialize global configuration files + */ +var initGlobalConfigFiles = function (config, assets) { + // Appending files + config.files = { + server: {}, + client: {} + }; + + // Setting Globbed model files + config.files.server.models = getGlobbedPaths(assets.server.models); + + // Setting Globbed route files + config.files.server.routes = getGlobbedPaths(assets.server.routes); + + // Setting Globbed config files + config.files.server.configs = getGlobbedPaths(assets.server.config); + + // Setting Globbed socket files + config.files.server.sockets = getGlobbedPaths(assets.server.sockets); + + // Setting Globbed policies files + config.files.server.policies = getGlobbedPaths(assets.server.policies); + + // Setting Globbed js files + config.files.client.js = getGlobbedPaths(assets.client.lib.js, 'public/').concat(getGlobbedPaths(assets.client.js, ['client/', 'public/'])); + + // Setting Globbed css files + config.files.client.css = getGlobbedPaths(assets.client.lib.css, 'public/').concat(getGlobbedPaths(assets.client.css, ['client/', 'public/'])); + + // Setting Globbed test files + config.files.client.tests = getGlobbedPaths(assets.client.tests); +}; + +/** + * Initialize global configuration + */ +var initGlobalConfig = function () { + // Validate NDOE_ENV existance + validateEnvironmentVariable(); + + // Get the default assets + var defaultAssets = require(path.join(process.cwd(), 'config/assets/default')); + + // Get the current assets + var environmentAssets = require(path.join(process.cwd(), 'config/assets/', process.env.NODE_ENV)) || {}; + + // Merge assets + var assets = _.merge(defaultAssets, environmentAssets); + + // Get the default config + var defaultConfig = require(path.join(process.cwd(), 'config/env/default')); + + // Get the current config + var environmentConfig = require(path.join(process.cwd(), 'config/env/', process.env.NODE_ENV)) || {}; + + // Merge config files + var envConf = _.merge(defaultConfig, environmentConfig); + + var config = _.merge(envConf, (fs.existsSync(path.join(process.cwd(), 'config/env/local.js')) && require(path.join(process.cwd(), 'config/env/local.js'))) || {}); + + // Initialize global globbed files + initGlobalConfigFiles(config, assets); + + // Initialize global globbed folders + initGlobalConfigFolders(config, assets); + + // Validate Secure SSL mode can be used + validateSecureMode(config); + + // Expose configuration utilities + config.utils = { + getGlobbedPaths: getGlobbedPaths + }; + + return config; +}; + +/** + * Set configuration object + */ +module.exports = initGlobalConfig(); diff --git a/categories/core.server.controller.js b/categories/core.server.controller.js new file mode 100644 index 0000000..df18cba --- /dev/null +++ b/categories/core.server.controller.js @@ -0,0 +1,113 @@ +'use strict'; +exports.renderIndex = function (req, res) { + res.render('modules/core/server/views/index', { + user: req.user || null + }); +}; + +/** + * Render the server error page + */ +exports.renderServerError = function (req, res) { + res.status(500).render('modules/core/server/views/500', { + error: 'Oops! Something went wrong...' + }); +}; + +/** + * Render the server not found responses + * Performs content-negotiation on the Accept HTTP header + */ +exports.renderNotFound = function (req, res) { + + res.status(404).format({ + 'text/html': function () { + res.render('modules/core/server/views/404', { + url: req.originalUrl + }); + }, + 'application/json': function () { + res.json({ + error: 'Path not found' + }); + }, + 'default': function () { + res.send('Path not found'); + } + }); +}; + +/** + * Module dependencies. + */ +var path = require('path'), + mongoose = require('mongoose'), + Category = mongoose.model('CategoryServerModel'), + errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')), + _ = require('lodash'); + +/** + * Create a Core + */ +exports.create = function (req, res) { + var category=new Category(req.body); + category.save(function(err) { + if (err) { + return res.status(400).send({ + message: errorHandler.getErrorMessage(err) + }); + } else { + res.status(201).json(category); + } + }); +}; + +/** + * Show the current Core + */ +exports.read = function (req, res) { + Category.findById(req.params.categoryId).exec(function(err, category) { + if (err) { + return res.status(400).send({ + message: errorHandler.getErrorMessage(err) + }); + } else { + if (!category) { + return res.status(404).send({ + message: 'Category not found' + }); + } + res.json(category); + } + }); +}; + +/** + * Update a Core + */ +exports.update = function (req, res) { + +}; + +/** + * Delete an Core + */ +exports.delete = function (req, res) { + +}; + +/** + * List of Cores + */ +exports.list = function (req, res) { + Category.find().exec(function(err,categories){ + if(err){ + return res.status(400).send({ + message:errorHandler.getErrorMessage(err) + }); + }else{ + res.json(categories); + } + }); + +}; diff --git a/categories/routes.server.routes.js b/categories/routes.server.routes.js new file mode 100644 index 0000000..a3695a8 --- /dev/null +++ b/categories/routes.server.routes.js @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = function(app) { + var categories=require('../../server/controllers/core.server.controller'); + app.route('/categories') + .get(categories.list) + .post(categories.create); + + + app.route('/categories/:categoryId') + .get(categories.read); + // Routing logic + // ... +}; diff --git a/categories/server.js b/categories/server.js new file mode 100644 index 0000000..8fa7b2e --- /dev/null +++ b/categories/server.js @@ -0,0 +1,7 @@ +'use strict'; + +/** + * Module dependencies. + */ +var app = require('./config/lib/app'); +var server = app.start(); diff --git a/my-todolist/js/MainController.js b/my-todolist/js/MainController.js index b1d5d88..83fe6d6 100644 --- a/my-todolist/js/MainController.js +++ b/my-todolist/js/MainController.js @@ -3,16 +3,64 @@ */ function MainController($scope){ + this.likelist=[]; + this.myAmount=209.82; + this.myDate=1288323623006; + this.text="the text is here"; + this.myarray=[ + "angular","app" + ]; + this.addMovie=function(){ + this.favourites.unshift({ + title:this.newtitle, + year:this.release + } + ) + }; + this.unlike= function(index){ + this.likelist.splice(index,1); + }; + this.myObject={ + one:"key1", + two:"key2" + }; + this.addToLikes=function(movie) + { +// in function + this.likelist.push(movie); + }; this.favourites=[{ title:'the shawshank', year:'1994', popular:true },{ - title:'the shawshank', - year:'1994', + title:'excorcist', + year:'1995', popular:false }] } +function UserController($http){ +var API='/api/todo'; +this.userId=''; +this.chosenUser={}; +this.getUser=function(){ + if(!this.userId){ + return; + } + $http.get(API+this.userId); + $http.then(function(response){ + this.chosenUser=response.data; + console.log(this.chosenUser) + },function(reason){ +console.log(reason) + }); + $http.post() +} +} + + angular.module('app1') - .controller('MainController',MainController) \ No newline at end of file + .controller('MainController',MainController) +angular.module('app2') + .controller('UserController',UserController) \ No newline at end of file diff --git a/my-todolist/js/app.js b/my-todolist/js/app.js index b3c724f..a38e782 100644 --- a/my-todolist/js/app.js +++ b/my-todolist/js/app.js @@ -1,4 +1,5 @@ /** * Created by lcom64 on 30/1/17. */ -angular.module('app1',[]); \ No newline at end of file +angular.module('app1',[]); +angular.module('app2',[]); \ No newline at end of file diff --git a/my-todolist/js/app2.js b/my-todolist/js/app2.js new file mode 100644 index 0000000..e69de29 diff --git a/my-todolist/js/index1.html b/my-todolist/js/index1.html index 2e21e93..6a0c9f8 100644 --- a/my-todolist/js/index1.html +++ b/my-todolist/js/index1.html @@ -6,11 +6,60 @@ + + +
-
  • + +
    {{main.myObject|json}}
    + Year + Title +
    + {{like.title}} + Unlike +
    +
    {{ movies.title }} + Add like

    the movie is popular

    -
  • +
    +
    +
    + + + +
    +
    + + {{main.myDate| date:'EEEE'}}
    + {{main.myDate| date:'medium'}}
    + {{main.myDate| date:'short'}}
    + {{main.myDate| date:'longDate'}}
    + {{main.myDate| date:'MMMM'}}
    + {{main.myDate| date:'MM'}}
    + {{main.myDate| date:'yyyy'}}
    + {{main.myDate| date:'HH'}}
    + {{main.myDate| date:'EEEE'}}
    + {{main.myAmount|currency}} + {{main.myAmount|currency:'USD':1}} + + + {{ main.myarray.length>0? + "Something here": + "Nothing here" + }} + + + + {{main.myObject[Mykey]}} + diff --git a/my-todolist/js/index2.html b/my-todolist/js/index2.html new file mode 100644 index 0000000..bb96bc3 --- /dev/null +++ b/my-todolist/js/index2.html @@ -0,0 +1,19 @@ + + + + + Title + + +
    +
    + + + Search user +
    +
    {{user.chosenUser}}
    +
    + + + + \ No newline at end of file diff --git a/my-todolist/package.json b/my-todolist/package.json index 597b494..8bf1ca4 100644 --- a/my-todolist/package.json +++ b/my-todolist/package.json @@ -6,7 +6,7 @@ "cookie-session": "~1.1.0", "ejs": "~2.1.4", "express": "~4.11.0", - "mongoose": "4.7,7", + "mongoose": "4.7.7", "multer": "^1.2.1", "validator": "6.2.1", "path":"0.12.7", diff --git a/my-todolist/uploads/33cbf6c3f892f7725ea81c0598c9df5c b/my-todolist/uploads/33cbf6c3f892f7725ea81c0598c9df5c deleted file mode 100644 index 9cbad1f..0000000 Binary files a/my-todolist/uploads/33cbf6c3f892f7725ea81c0598c9df5c and /dev/null differ