server reorganize files and folder by features

- move and rename files
- use associative arrays which store handlers for 'dynamically'
  load module from de db route
- store models_path in test/server/common,
  a global model variable has the same name that the filename of the model
This commit is contained in:
Sébastien Moratinos 2014-01-22 23:57:41 +01:00
parent 771099d43e
commit 729cd300b7
49 changed files with 105 additions and 87 deletions

View file

@ -13,8 +13,8 @@ auth = require './server/routes/auth'
db = require './server/routes/db'
file = require './server/routes/file'
folder = require './server/routes/folder'
user = require './server/handlers/user'
logging = require './server/logging'
user = require './server/users/user_handler'
logging = require './server/commons/logging'
sprites = require './server/routes/sprites'
contact = require './server/routes/contact'
languages = require './server/routes/languages'

View file

@ -1,5 +1,5 @@
mongoose = require('mongoose')
plugins = require('./plugins')
plugins = require('../plugins/plugins')
ArticleSchema = new mongoose.Schema(
body: String,

View file

@ -1,7 +1,7 @@
winston = require('winston')
request = require('request')
Article = require('../models/Article')
Handler = require('./Handler')
Article = require('./Article')
Handler = require('../commons/Handler')
ArticleHandler = class ArticleHandler extends Handler
modelClass: Article

View file

@ -1,4 +1,4 @@
c = require './common'
c = require '../commons/schemas'
ArticleSchema = c.object()
c.extendNamedProperties ArticleSchema # name first

View file

@ -1,5 +1,5 @@
mongoose = require('mongoose')
plugins = require('./plugins')
plugins = require('../plugins/plugins')
NestedLevelSchema = new mongoose.Schema(
name: String

View file

@ -1,7 +1,7 @@
winston = require('winston')
request = require('request')
Campaign = require('../models/Campaign')
Handler = require('./Handler')
Campaign = require('./Campaign')
Handler = require('../commons/Handler')
CampaignHandler = class CampaignHandler extends Handler
modelClass: Campaign

View file

@ -1,7 +1,7 @@
winston = require('winston')
request = require('request')
CampaignStatus = require('../models/CampaignStatus')
Handler = require('./Handler')
CampaignStatus = require('./CampaignStatus')
Handler = require('../commons/Handler')
CampaignStatusHandler = class CampaignStatusHandler extends Handler
modelClass: CampaignStatus

View file

@ -1,7 +1,7 @@
async = require 'async'
mongoose = require('mongoose')
Grid = require 'gridfs-stream'
errors = require '../errors'
errors = require './errors'
module.exports = class Handler
# subclasses should override these properties

View file

@ -1,5 +1,5 @@
#this file will hold the experimental JSON schema for i18n
c = require './common'
c = require './schemas'
languageCodeArrayRegex = c.generateLanguageCodeArrayRegex()

View file

@ -1,5 +1,5 @@
mongoose = require('mongoose')
plugins = require('./plugins')
plugins = require('../plugins/plugins')
FileSchema = new mongoose.Schema()

View file

@ -1,5 +1,5 @@
File = require('../models/File')
Handler = require('./Handler')
File = require('./File')
Handler = require('../commons/Handler')
FileHandler = class FileHandler extends Handler
modelClass: File

View file

@ -1,4 +1,4 @@
c = require './common'
c = require '../commons/schemas'
FileSchema = c.baseSchema()

View file

@ -1,6 +1,6 @@
mongoose = require('mongoose')
plugins = require('./plugins')
jsonschema = require('../schemas/level')
plugins = require('../plugins/plugins')
jsonschema = require('./level_schema')
LevelSchema = new mongoose.Schema({
description: String

View file

@ -1,6 +1,6 @@
mongoose = require('mongoose')
plugins = require('./plugins')
jsonschema = require('../schemas/level_component')
plugins = require('../../plugins/plugins')
jsonschema = require('./level_component_schema')
LevelComponentSchema = new mongoose.Schema {
description: String

View file

@ -1,7 +1,7 @@
winston = require('winston')
request = require('request')
LevelComponent = require('../models/LevelComponent')
Handler = require('./Handler')
LevelComponent = require('./LevelComponent')
Handler = require('../../commons/Handler')
LevelComponentHandler = class LevelComponentHandler extends Handler
modelClass: LevelComponent

View file

@ -1,5 +1,5 @@
c = require './common'
metaschema = require './metaschema'
c = require '../../commons/schemas'
metaschema = require '../../commons/metaschema'
attackSelfCode = """
class AttacksSelf extends Component

View file

@ -1,5 +1,5 @@
mongoose = require('mongoose')
Level = require('./Level')
Level = require('../Level')
LevelDraftSchema = new mongoose.Schema(
user: {type: mongoose.Schema.ObjectId, ref: 'User'}

View file

@ -1,7 +1,7 @@
winston = require('winston')
request = require('request')
LevelDraft = require('../models/LevelDraft')
Handler = require('./Handler')
LevelDraft = require('./LevelDraft')
Handler = require('../../commons/Handler')
LevelDraftHandler = class LevelDraftHandler extends Handler
modelClass: LevelDraft

View file

@ -1,8 +1,8 @@
# TODO: not updated since rename from level_instance, or since we redid how all models are done; probably busted
mongoose = require('mongoose')
plugins = require('./plugins')
jsonschema = require('../schemas/level_feedback')
plugins = require('../../plugins/plugins')
jsonschema = require('./level_feedback_schema')
LevelFeedbackSchema = new mongoose.Schema({
created:

View file

@ -1,5 +1,5 @@
LevelFeedback = require('../models/LevelFeedback')
Handler = require('./Handler')
LevelFeedback = require('./LevelFeedback')
Handler = require('../../commons/Handler')
class LevelFeedbackHandler extends Handler
modelClass: LevelFeedback

View file

@ -1,4 +1,4 @@
c = require './common'
c = require '../../commons/schemas'
LevelFeedbackLevelSchema = c.object {required: ['original', 'majorVersion']}, {
original: c.objectId({})

View file

@ -1,10 +1,10 @@
winston = require('winston')
request = require('request')
Level = require('../models/Level')
Session = require('../models/LevelSession')
SessionHandler = require('./level_session')
Feedback = require('../models/LevelFeedback')
Handler = require('./Handler')
Level = require('./Level')
Session = require('./sessions/LevelSession')
SessionHandler = require('./sessions/level_session_handler')
Feedback = require('./feedbacks/LevelFeedback')
Handler = require('../commons/Handler')
mongoose = require('mongoose')
LevelHandler = class LevelHandler extends Handler

View file

@ -1,5 +1,5 @@
c = require './common'
ThangComponentSchema = require './thang_component'
c = require '../commons/schemas'
ThangComponentSchema = require './thangs/thang_component_schema'
SpecificArticleSchema = c.object()
c.extendNamedProperties SpecificArticleSchema # name first

View file

@ -1,8 +1,8 @@
# TODO: not updated since rename from level_instance, or since we redid how all models are done; probably busted
mongoose = require('mongoose')
plugins = require('./plugins')
jsonschema = require('../schemas/level_session')
plugins = require('../../plugins/plugins')
jsonschema = require('./level_session_schema')
LevelSessionSchema = new mongoose.Schema({
created:

View file

@ -1,5 +1,5 @@
LevelSession = require('../models/LevelSession')
Handler = require('./Handler')
LevelSession = require('./LevelSession')
Handler = require('../../commons/Handler')
TIMEOUT = 1000 * 30 # no activity for 30 seconds means it's not active

View file

@ -1,4 +1,4 @@
c = require './common'
c = require '../../commons/schemas'
LevelSessionPlayerSchema = c.object {
id: c.objectId(links: [{rel: 'extra', href: "/db/user/{($)}"}])

View file

@ -1,6 +1,6 @@
mongoose = require('mongoose')
plugins = require('./plugins')
jsonschema = require('../schemas/level_system')
plugins = require('../../plugins/plugins')
jsonschema = require('./level_system_schema')
LevelSystemSchema = new mongoose.Schema {
description: String

View file

@ -1,7 +1,7 @@
winston = require('winston')
request = require('request')
LevelSystem = require('../models/LevelSystem')
Handler = require('./Handler')
LevelSystem = require('./LevelSystem')
Handler = require('../../commons/Handler')
LevelSystemHandler = class LevelSystemHandler extends Handler
modelClass: LevelSystem

View file

@ -1,5 +1,5 @@
c = require './common'
metaschema = require './metaschema'
c = require '../../commons/schemas'
metaschema = require '../../commons/metaschema'
jitterSystemCode = """
class Jitter extends System

View file

@ -1,5 +1,5 @@
mongoose = require('mongoose')
plugins = require('./plugins')
plugins = require('../../plugins/plugins')
LevelComponentSchema = new mongoose.Schema(
original: {type: mongoose.Schema.ObjectId, ref: 'level.session'}

View file

@ -1,5 +1,5 @@
mongoose = require('mongoose')
plugins = require('./plugins')
plugins = require('../../plugins/plugins')
ThangTypeSchema = new mongoose.Schema({
body: String,

View file

@ -1,4 +1,4 @@
c = require './common'
c = require '../../commons/schemas'
module.exports = ThangComponentSchema = c.object {
title: "Component"

View file

@ -1,7 +1,7 @@
winston = require('winston')
request = require('request')
ThangType = require('../models/ThangType')
Handler = require('./Handler')
ThangType = require('./ThangType')
Handler = require('../../commons/Handler')
ThangTypeHandler = class ThangTypeHandler extends Handler
modelClass: ThangType

View file

@ -1,5 +1,5 @@
c = require './common'
ThangComponentSchema = require './thang_component'
c = require '../../commons/schemas'
ThangComponentSchema = require './thang_component_schema'
ThangTypeSchema = c.object()
c.extendNamedProperties ThangTypeSchema # name first

View file

@ -1,5 +1,5 @@
mongoose = require('mongoose')
User = require('./User')
User = require('../users/User')
textSearch = require('mongoose-text-search')
module.exports.NamedPlugin = (schema) ->

View file

@ -1,11 +1,11 @@
passport = require('passport')
winston = require('winston')
LocalStrategy = require('passport-local').Strategy
User = require('./../models/User')
UserHandler = require('./../handlers/user')
User = require('../users/User')
UserHandler = require('../users/user_handler')
config = require '../../server_config'
nodemailer = require 'nodemailer'
errors = require './../errors'
errors = require '../commons/errors'
module.exports.setupRoutes = (app) ->
passport.serializeUser((user, done) -> done(null, user._id))

View file

@ -3,10 +3,26 @@ winston = require 'winston'
mongoose = require 'mongoose'
Grid = require 'gridfs-stream'
async = require 'async'
errors = require './../errors'
errors = require '../commons/errors'
testing = '--unittest' in process.argv
handlers =
'article': '../../server/articles/article_handler'
'campaign': '../../server/campaigns/campaign_handler'
'campaign_status': '../../server/campaigns/campaign_status_handler'
'file': '../../server/files/file_handler'
'level': '../../server/levels/level_handler'
'level_component': '../../server/levels/components/level_component_handler'
'level_draft': '../../server/levels/drafts/level_draft_handler'
'level_feedback': '../../server/levels/feedbacks/level_feedback_handler'
'level_session': '../../server/levels/sessions/level_session_handler'
'level_system': '../../server/levels/systems/level_system_handler'
'level_thang_type': '../../server/levels/thangs/level_thangType_handler'
'user': '../../server/users/user_handler'
module.exports.connectDatabase = () ->
dbName = config.mongo.db
dbName += '_unittest' if testing
@ -30,7 +46,8 @@ module.exports.setupRoutes = (app) ->
return getSchema(req, res, module) if parts[1] is 'schema'
try
name = "../handlers/#{module.replace '.', '_'}"
moduleName = module.replace '.', '_'
name = handlers[moduleName]
module = require(name)
return module.getLatestVersion(req, res, parts[1], parts[3]) if parts[2] is 'version'
return module.versions(req, res, parts[1]) if parts[2] is 'versions'

View file

@ -3,7 +3,7 @@ Grid = require 'gridfs-stream'
fs = require 'fs'
request = require 'request'
mongoose = require('mongoose')
errors = require './../errors'
errors = require '../commons/errors'
module.exports.setupRoutes = (app) ->
app.all '/file*', (req, res) ->

View file

@ -1,7 +1,7 @@
fs = require 'fs'
request = require 'request'
mongoose = require('mongoose')
errors = require './../errors'
errors = require '../commons/errors'
module.exports.setupRoutes = (app) ->
app.all '/folder*', (req, res) ->

View file

@ -1,4 +1,4 @@
errors = require './../errors'
errors = require '../commons/errors'
winston = require 'winston'
locale = require '../../app/locale/locale' # requiring from app; will break if we stop serving from where app lives

View file

@ -1,5 +1,5 @@
mongoose = require('mongoose')
jsonschema = require('../schemas/user')
jsonschema = require('./user_schema')
crypto = require('crypto')
{salt, isProduction} = require('../../server_config')

View file

@ -1,9 +1,9 @@
winston = require('winston')
schema = require('../schemas/user')
schema = require('./user_schema')
crypto = require('crypto')
request = require('request')
User = require('../models/User')
Handler = require('./Handler')
User = require('./User')
Handler = require('../commons/Handler')
languages = require '../routes/languages'
mongoose = require 'mongoose'
config = require '../../server_config'

View file

@ -1,4 +1,4 @@
c = require './common'
c = require '../commons/schemas'
emailSubscriptions = ['announcement', 'tester', 'level_creator', 'developer', 'article_editor', 'translator', 'support', 'notification']
UserSchema = c.object {},

View file

@ -6,24 +6,25 @@ _.str = require('underscore.string')
_.mixin(_.str.exports())
GLOBAL.mongoose = require 'mongoose'
mongoose.connect('mongodb://localhost/coco_unittest')
path = require('path')
models_path = '../../server/models/'
include_models = [
'Article'
'Campaign'
'CampaignStatus'
'Level'
'LevelComponent'
'LevelSystem'
'LevelDraft'
'LevelSession'
'LevelThangType'
'User'
models_path = [
'../../server/articles/Article'
'../../server/campaigns/Campaign'
'../../server/campaigns/CampaignStatus'
'../../server/levels/Level'
'../../server/levels/components/LevelComponent'
'../../server/levels/systems/LevelSystem'
'../../server/levels/drafts/LevelDraft'
'../../server/levels/sessions/LevelSession'
'../../server/levels/thangs/LevelThangType'
'../../server/users/User'
]
for m in include_models
GLOBAL[m] = require models_path+m
for m in models_path
model = path.basename(m)
#console.log('model=' + model)
GLOBAL[model] = require m
async = require 'async'