diff --git a/.gitignore b/.gitignore index 0079e95..3727eb2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ MobileDatabase.iml .idea node_modules .DS_Store +/bower_components diff --git a/app.js b/app.js index 7536ba7..442b774 100644 --- a/app.js +++ b/app.js @@ -26,11 +26,8 @@ if(rebuildDatabase){ }); } - - const app = express(); -const index = require('./routes/index'); const apiV1 = require('./routes/apiV1'); // view engine setup @@ -43,10 +40,9 @@ app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); -app.use(express.static(path.join(__dirname, 'public'))); -app.use('/', index); app.use('/api/v1', apiV1); +app.use('/', express.static(path.join(__dirname, 'app'))); // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/app/app.css b/app/app.css new file mode 100755 index 0000000..48e881d --- /dev/null +++ b/app/app.css @@ -0,0 +1,25 @@ +/* app css stylesheet */ + +.menu { + list-style: none; + border-bottom: 0.1em solid black; + margin-bottom: 2em; + padding: 0 0 0.5em; +} + +.menu:before { + content: "["; +} + +.menu:after { + content: "]"; +} + +.menu > li { + display: inline; +} + +.menu > li + li:before { + content: "|"; + padding-right: 0.3em; +} diff --git a/app/app.js b/app/app.js new file mode 100755 index 0000000..6ea2401 --- /dev/null +++ b/app/app.js @@ -0,0 +1,14 @@ +'use strict'; + +// Declare app level module which depends on views, and components +angular.module('myApp', [ + 'ngRoute', + 'myApp.view1', + 'myApp.view2', + 'myApp.version' +]). +config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) { + $locationProvider.hashPrefix('!'); + + $routeProvider.otherwise({redirectTo: '/view1'}); +}]); diff --git a/app/components/version/interpolate-filter.js b/app/components/version/interpolate-filter.js new file mode 100755 index 0000000..03bb198 --- /dev/null +++ b/app/components/version/interpolate-filter.js @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('myApp.version.interpolate-filter', []) + +.filter('interpolate', ['version', function(version) { + return function(text) { + return String(text).replace(/\%VERSION\%/mg, version); + }; +}]); diff --git a/app/components/version/interpolate-filter_test.js b/app/components/version/interpolate-filter_test.js new file mode 100755 index 0000000..ff56c52 --- /dev/null +++ b/app/components/version/interpolate-filter_test.js @@ -0,0 +1,15 @@ +'use strict'; + +describe('myApp.version module', function() { + beforeEach(module('myApp.version')); + + describe('interpolate filter', function() { + beforeEach(module(function($provide) { + $provide.value('version', 'TEST_VER'); + })); + + it('should replace VERSION', inject(function(interpolateFilter) { + expect(interpolateFilter('before %VERSION% after')).toEqual('before TEST_VER after'); + })); + }); +}); diff --git a/app/components/version/version-directive.js b/app/components/version/version-directive.js new file mode 100755 index 0000000..74088f8 --- /dev/null +++ b/app/components/version/version-directive.js @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('myApp.version.version-directive', []) + +.directive('appVersion', ['version', function(version) { + return function(scope, elm, attrs) { + elm.text(version); + }; +}]); diff --git a/app/components/version/version-directive_test.js b/app/components/version/version-directive_test.js new file mode 100755 index 0000000..4a59e11 --- /dev/null +++ b/app/components/version/version-directive_test.js @@ -0,0 +1,17 @@ +'use strict'; + +describe('myApp.version module', function() { + beforeEach(module('myApp.version')); + + describe('app-version directive', function() { + it('should print current version', function() { + module(function($provide) { + $provide.value('version', 'TEST_VER'); + }); + inject(function($compile, $rootScope) { + var element = $compile('')($rootScope); + expect(element.text()).toEqual('TEST_VER'); + }); + }); + }); +}); diff --git a/app/components/version/version.js b/app/components/version/version.js new file mode 100755 index 0000000..cb7a10f --- /dev/null +++ b/app/components/version/version.js @@ -0,0 +1,8 @@ +'use strict'; + +angular.module('myApp.version', [ + 'myApp.version.interpolate-filter', + 'myApp.version.version-directive' +]) + +.value('version', '0.1'); diff --git a/app/components/version/version_test.js b/app/components/version/version_test.js new file mode 100755 index 0000000..4ca6880 --- /dev/null +++ b/app/components/version/version_test.js @@ -0,0 +1,11 @@ +'use strict'; + +describe('myApp.version module', function() { + beforeEach(module('myApp.version')); + + describe('version service', function() { + it('should return current version', inject(function(version) { + expect(version).toEqual('0.1'); + })); + }); +}); diff --git a/app/index-async.html b/app/index-async.html new file mode 100755 index 0000000..281254e --- /dev/null +++ b/app/index-async.html @@ -0,0 +1,58 @@ + + +
+ + + + + + +This is the partial for view 1.
diff --git a/app/view1/view1.js b/app/view1/view1.js new file mode 100755 index 0000000..4ce0b4f --- /dev/null +++ b/app/view1/view1.js @@ -0,0 +1,14 @@ +'use strict'; + +angular.module('myApp.view1', ['ngRoute']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/view1', { + templateUrl: 'view1/view1.html', + controller: 'View1Ctrl' + }); +}]) + +.controller('View1Ctrl', [function() { + +}]); \ No newline at end of file diff --git a/app/view1/view1_test.js b/app/view1/view1_test.js new file mode 100755 index 0000000..14ba79b --- /dev/null +++ b/app/view1/view1_test.js @@ -0,0 +1,16 @@ +'use strict'; + +describe('myApp.view1 module', function() { + + beforeEach(module('myApp.view1')); + + describe('view1 controller', function(){ + + it('should ....', inject(function($controller) { + //spec body + var view1Ctrl = $controller('View1Ctrl'); + expect(view1Ctrl).toBeDefined(); + })); + + }); +}); \ No newline at end of file diff --git a/app/view2/view2.html b/app/view2/view2.html new file mode 100755 index 0000000..b6503ee --- /dev/null +++ b/app/view2/view2.html @@ -0,0 +1,5 @@ +This is the partial for view 2.
++ Showing of 'interpolate' filter: + {{ 'Current version is v%VERSION%.' | interpolate }} +
diff --git a/app/view2/view2.js b/app/view2/view2.js new file mode 100755 index 0000000..a0ff97d --- /dev/null +++ b/app/view2/view2.js @@ -0,0 +1,14 @@ +'use strict'; + +angular.module('myApp.view2', ['ngRoute']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/view2', { + templateUrl: 'view2/view2.html', + controller: 'View2Ctrl' + }); +}]) + +.controller('View2Ctrl', [function() { + +}]); \ No newline at end of file diff --git a/app/view2/view2_test.js b/app/view2/view2_test.js new file mode 100755 index 0000000..07b34d6 --- /dev/null +++ b/app/view2/view2_test.js @@ -0,0 +1,16 @@ +'use strict'; + +describe('myApp.view2 module', function() { + + beforeEach(module('myApp.view2')); + + describe('view2 controller', function(){ + + it('should ....', inject(function($controller) { + //spec body + var view2Ctrl = $controller('View2Ctrl'); + expect(view2Ctrl).toBeDefined(); + })); + + }); +}); \ No newline at end of file diff --git a/bower.json b/bower.json new file mode 100755 index 0000000..66d9d74 --- /dev/null +++ b/bower.json @@ -0,0 +1,15 @@ +{ + "name": "angular-seed", + "description": "A starter project for AngularJS", + "version": "0.0.0", + "homepage": "https://github.com/angular/angular-seed", + "license": "MIT", + "private": true, + "dependencies": { + "angular": "~1.5.0", + "angular-route": "~1.5.0", + "angular-loader": "~1.5.0", + "angular-mocks": "~1.5.0", + "html5-boilerplate": "^5.3.0" + } +} diff --git a/package.json b/package.json index 1b55db4..cf5e4b7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,10 @@ "private": true, "scripts": { "start": "nodemon ./bin/www", - "start:dev": "nodemon ./bin/www" + "start:dev": "nodemon ./bin/www", + "postinstall": "bower install", + "update-deps": "npm update", + "postupdate-deps": "bower update" }, "dependencies": { "bluebird": "^3.5.0", @@ -25,6 +28,7 @@ "string-format": "^0.5.0" }, "devDependencies": { - "nodemon": "^1.11.0" + "nodemon": "^1.11.0", + "bower": "^1.7.7" } } diff --git a/routes/apiV1.js b/routes/apiV1.js index cf0a888..0c55024 100644 --- a/routes/apiV1.js +++ b/routes/apiV1.js @@ -2,34 +2,9 @@ const express = require('express'); const router = express.Router(); -router.use('/crud', require('./v1/crud')); - -router.use('/dictionary/blocks', require('./v1/dictionary/blocks')); -router.use('/dictionary/builds', require('./v1/dictionary/builds')); -router.use('/dictionary/buildData', require('./v1/dictionary/buildData')); -router.use('/dictionary/templates', require('./v1/dictionary/templates')); - -router.use('/lemmas', require('./v1/lemmas')); - -router.use('/entry/layouts', require('./v1/entry/layouts')); -router.use('/entry/layoutTemplates', require('./v1/entry/layoutTemplates')); -router.use('/entry/templates', require('./v1/entry/templates')); -router.use('/entry/typeEntries', require('./v1/entry/typeTemplates')); -router.use('/entry/types', require('./v1/entry/types')); -router.use('/entry/typeTemplates', require('./v1/entry/typeTemplates')); router.use('/definitions', require('./v1/definitions')); -router.use('/languages', require('./v1/languages')); - -router.use('/localized/entry/layouts', require('./v1/localized/entryLayouts')); -router.use('/localized/metadata', require('./v1/localized/metadata')); - -router.use('/metadata', require('./v1/metadata')); - -router.use('/partsOfSpeech', require('./v1/lemmaClassTypes')); - -router.use('/sources', require('./v1/sources')); - +router.use('/models', require('./v1/models')); router.use('/export', require('./v1/export')); module.exports = router; diff --git a/routes/index.js b/routes/index.js deleted file mode 100644 index 6e84977..0000000 --- a/routes/index.js +++ /dev/null @@ -1,9 +0,0 @@ -const express = require('express'); -const router = express.Router(); - -/* GET home page. */ -router.get('/', function(req, res, next) { - res.render('index', { title: 'Express' }); -}); - -module.exports = router; diff --git a/routes/users.js b/routes/users.js deleted file mode 100644 index f15a20d..0000000 --- a/routes/users.js +++ /dev/null @@ -1,9 +0,0 @@ -const express = require('express'); -const router = express.Router(); - -/* GET users listing. */ -router.get('/', function(req, res, next) { - res.send('respond with a resource'); -}); - -module.exports = router; diff --git a/routes/v1/dictionary/blocks.js b/routes/v1/dictionary/blocks.js deleted file mode 100644 index 7f384d5..0000000 --- a/routes/v1/dictionary/blocks.js +++ /dev/null @@ -1,14 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.DictionaryBlock.findAll().then(function (blocks) { - "use strict"; - res.send(blocks); - }); - -}); - -module.exports = router; diff --git a/routes/v1/dictionary/buildData.js b/routes/v1/dictionary/buildData.js deleted file mode 100644 index 3858bae..0000000 --- a/routes/v1/dictionary/buildData.js +++ /dev/null @@ -1,15 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); -const Promise = require('bluebird'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.DictionaryBuildData.findAll().then(function (buildData) { - "use strict"; - res.send(buildData); - }); - -}); - -module.exports = router; diff --git a/routes/v1/dictionary/builds.js b/routes/v1/dictionary/builds.js deleted file mode 100644 index 2eb6f29..0000000 --- a/routes/v1/dictionary/builds.js +++ /dev/null @@ -1,15 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); -const Promise = require('bluebird'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.DictionaryBuild.findAll().then(function (builds) { - "use strict"; - res.send(builds); - }); - -}); - -module.exports = router; diff --git a/routes/v1/dictionary/templates.js b/routes/v1/dictionary/templates.js deleted file mode 100644 index 01c7daf..0000000 --- a/routes/v1/dictionary/templates.js +++ /dev/null @@ -1,15 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); -const Promise = require('bluebird'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.DictionaryTemplate.findAll().then(function (templates) { - "use strict"; - res.send(templates); - }); - -}); - -module.exports = router; diff --git a/routes/v1/entry/layoutTemplates.js b/routes/v1/entry/layoutTemplates.js deleted file mode 100644 index 493dba1..0000000 --- a/routes/v1/entry/layoutTemplates.js +++ /dev/null @@ -1,14 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.EntryLayoutTemplates.findAll().then(function (layoutTemplates) { - "use strict"; - res.send(layoutTemplates); - }); - -}); - -module.exports = router; diff --git a/routes/v1/entry/layouts.js b/routes/v1/entry/layouts.js deleted file mode 100644 index 1f93142..0000000 --- a/routes/v1/entry/layouts.js +++ /dev/null @@ -1,15 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); -const Promise = require('bluebird'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.EntryLayout.findAll().then(function (layouts) { - "use strict"; - res.send(layouts); - }); - -}); - -module.exports = router; diff --git a/routes/v1/entry/templates.js b/routes/v1/entry/templates.js deleted file mode 100644 index d7fd33e..0000000 --- a/routes/v1/entry/templates.js +++ /dev/null @@ -1,14 +0,0 @@ -var express = require('express'); -var router = express.Router(); -var models = require('../../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.EntryTemplate.findAll().then(function (templates) { - "use strict"; - res.send(templates); - }); - -}); - -module.exports = router; diff --git a/routes/v1/entry/typeEntries.js b/routes/v1/entry/typeEntries.js deleted file mode 100644 index 916a200..0000000 --- a/routes/v1/entry/typeEntries.js +++ /dev/null @@ -1,15 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); -const Promise = require('bluebird'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.EntryTypeTemplates.findAll().then(function (typeTemplates) { - "use strict"; - res.send(typeTemplates); - }); - -}); - -module.exports = router; diff --git a/routes/v1/entry/typeTemplates.js b/routes/v1/entry/typeTemplates.js deleted file mode 100644 index 6d03a65..0000000 --- a/routes/v1/entry/typeTemplates.js +++ /dev/null @@ -1,14 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.EntryTypeTemplates.findAll().then(function (templates) { - "use strict"; - res.send(templates); - }); - -}); - -module.exports = router; diff --git a/routes/v1/entry/types.js b/routes/v1/entry/types.js deleted file mode 100644 index fac0502..0000000 --- a/routes/v1/entry/types.js +++ /dev/null @@ -1,15 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); -const Promise = require('bluebird'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.EntryType.findAll().then(function (types) { - "use strict"; - res.send(types); - }); - -}); - -module.exports = router; diff --git a/routes/v1/export.js b/routes/v1/export.js index cbfa918..59bce9a 100644 --- a/routes/v1/export.js +++ b/routes/v1/export.js @@ -3,9 +3,9 @@ const router = express.Router(); const models = require('../../models'); const sqlite_models = require('../../sqlite_models'); -function exportData(model){ +function exportData(lc, model){ "use strict"; - return models[model].findAll().then(function(sequlizeData){ + return models[model].findAll({where: {LanguageIsoCode: lc}}).then(function(sequlizeData){ const data = sequlizeData.map(function(row){ return row.get({plain: true}); }); return sqlite_models[model].bulkCreate(data); }); @@ -34,9 +34,9 @@ const tables = [ /* GET languages listing. */ -router.get('/database.sqlite', function(req, res, next) { +router.get('/:lc/sqlite', function(req, res, next) { for(let i = 0; i < tables.length; i++){ - exportPromise = exportPromise.then(function(){ return exportData(tables[i]); }); + exportPromise = exportPromise.then(function(){ return exportData(req.params.lc, tables[i]); }); } exportPromise.then(function(){ "use strict"; diff --git a/routes/v1/languages.js b/routes/v1/languages.js deleted file mode 100644 index 72e4ec2..0000000 --- a/routes/v1/languages.js +++ /dev/null @@ -1,14 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.Language.findAll().then(function (languages) { - "use strict"; - res.send(languages); - }); - -}); - -module.exports = router; diff --git a/routes/v1/lemmaClassTypes.js b/routes/v1/lemmaClassTypes.js deleted file mode 100644 index e21a473..0000000 --- a/routes/v1/lemmaClassTypes.js +++ /dev/null @@ -1,14 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.LemmaClassType.findAll().then(function (classTypes) { - "use strict"; - res.send(classTypes); - }); - -}); - -module.exports = router; diff --git a/routes/v1/lemmas.js b/routes/v1/lemmas.js deleted file mode 100644 index e025b65..0000000 --- a/routes/v1/lemmas.js +++ /dev/null @@ -1,14 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.Entry.findAll().then(function (entries) { - "use strict"; - res.send(entries); - }); - -}); - -module.exports = router; diff --git a/routes/v1/localized/entryLayouts.js b/routes/v1/localized/entryLayouts.js deleted file mode 100644 index bd8c519..0000000 --- a/routes/v1/localized/entryLayouts.js +++ /dev/null @@ -1,14 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.LocalizedEntryLayout.findAll().then(function (layouts) { - "use strict"; - res.send(layouts); - }); - -}); - -module.exports = router; diff --git a/routes/v1/localized/metadata.js b/routes/v1/localized/metadata.js deleted file mode 100644 index 8001faf..0000000 --- a/routes/v1/localized/metadata.js +++ /dev/null @@ -1,14 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.LocalizedMetadata.findAll().then(function (metadata) { - "use strict"; - res.send(metadata); - }); - -}); - -module.exports = router; diff --git a/routes/v1/metadata.js b/routes/v1/metadata.js deleted file mode 100644 index 79d350d..0000000 --- a/routes/v1/metadata.js +++ /dev/null @@ -1,14 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.Metadata.findAll().then(function (metadata) { - "use strict"; - res.send(metadata); - }); - -}); - -module.exports = router; diff --git a/routes/v1/crud.js b/routes/v1/models.js similarity index 74% rename from routes/v1/crud.js rename to routes/v1/models.js index 85b9a7e..8a60466 100644 --- a/routes/v1/crud.js +++ b/routes/v1/models.js @@ -24,9 +24,13 @@ router.get('/:model/:id', function(req, res, next) { return; } - model.findAll().then(function (data) { + model.findById(req.params.id).then(function (data) { "use strict"; - res.send(data); + if(data === null){ + res.status(404).send(`Entity for ID [${req.params.id}] does not exist for Model [${req.params.model}]`); + } else { + res.send(data); + } }); }); diff --git a/routes/v1/sources.js b/routes/v1/sources.js deleted file mode 100644 index 132f145..0000000 --- a/routes/v1/sources.js +++ /dev/null @@ -1,14 +0,0 @@ -const express = require('express'); -const router = express.Router(); -const models = require('../../models/index'); - -/* GET languages listing. */ -router.get('/', function(req, res, next) { - models.Source.findAll().then(function (sources) { - "use strict"; - res.send(sources); - }); - -}); - -module.exports = router;