|
| 1 | +var express = require('express'); |
| 2 | +var admin = express(); |
| 3 | +//var itemsapi = require('./config/itemsapi'); |
| 4 | + |
| 5 | + |
| 6 | +//var ItemsAPI = require('itemsapi-node'); |
| 7 | +//var ITEMSAPI_URL = 'http://localhost:4000/api/v1'; |
| 8 | + |
| 9 | +//var config = require('./index').get(); |
| 10 | +//var Promise = require('bluebird') |
| 11 | +//var _ = require('lodash') |
| 12 | + |
| 13 | +//var client = new ItemsAPI(ITEMSAPI_URL, 'movies'); |
| 14 | + |
| 15 | +/*client({ |
| 16 | + name: 'movies', |
| 17 | + backend: 'http://localhost:4000/api/v1' |
| 18 | +}).search({ |
| 19 | + query: 'test' |
| 20 | +})*/ |
| 21 | + |
| 22 | +//var client = new ItemsAPI(); |
| 23 | + |
| 24 | +/*module.exports = function(options) { |
| 25 | + var itemsapi = new ItemsAPI() |
| 26 | + options = options || {} |
| 27 | +
|
| 28 | + itemsapi.setParams({ |
| 29 | + name: options.collection || options.name, |
| 30 | + backendUrl: options.backend || options.backendUrl || ITEMSAPI_URL |
| 31 | + }) |
| 32 | +
|
| 33 | + return itemsapi |
| 34 | +}*/ |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +var Promise = require('bluebird'); |
| 39 | +var bodyParser = require('body-parser'); |
| 40 | + |
| 41 | +var cookieParser = require('cookie-parser'); |
| 42 | +var moment = require('moment') |
| 43 | + |
| 44 | +admin.use('/lte/plugins', express.static('bower_components/AdminLTE/plugins')); |
| 45 | +admin.use('/lte/bootstrap', express.static('bower_components/AdminLTE/bootstrap')); |
| 46 | +admin.use('/lte/dist', express.static('bower_components/AdminLTE/dist')); |
| 47 | +admin.use('/codemirror', express.static('bower_components/codemirror')); |
| 48 | + |
| 49 | +//var mongoose = require('mongoose'); |
| 50 | +//var mongoose = require('./config/mongoose'); |
| 51 | +//var passport = require('passport'); |
| 52 | +//var LocalStrategy = require('passport-local').Strategy; |
| 53 | +//var config = require('./config/index').get(); |
| 54 | +//var session = require('express-session'); |
| 55 | +//var fixtures = require('node-mongoose-fixtures'); |
| 56 | +//var urlHelper = require('./src/helpers/url'); |
| 57 | +//var uiHelper = require('./src/helpers/ui'); |
| 58 | + |
| 59 | +var nunjucks = require('nunjucks'); |
| 60 | + |
| 61 | +var nunenv = new nunjucks.Environment( |
| 62 | + new nunjucks.FileSystemLoader('admin/views', { |
| 63 | + autoescape: true, |
| 64 | + watch: true, |
| 65 | + noCache: true, |
| 66 | + }) |
| 67 | +) |
| 68 | + |
| 69 | +nunenv.express(admin) |
| 70 | + |
| 71 | +admin.set('view engine', 'html.twig'); |
| 72 | +admin.set('view cache', false); |
| 73 | +admin.engine('html.twig', nunenv.render); |
| 74 | + |
| 75 | +admin.use(bodyParser.json({ |
| 76 | + limit: '50mb' |
| 77 | +})); |
| 78 | + |
| 79 | +admin.use(bodyParser.urlencoded({ extended: false, limit: '50mb' })); |
| 80 | +admin.use(cookieParser()); |
| 81 | + |
| 82 | +/** |
| 83 | + * dashboard |
| 84 | + */ |
| 85 | +admin.get(['/', '/dashboard'], function (req, res) { |
| 86 | + return res.render('dashboard') |
| 87 | +}) |
| 88 | + |
| 89 | +/** |
| 90 | + * collections get edit |
| 91 | + */ |
| 92 | +admin.get(['/collections/edit', '/collections/edit/:id'], function (req, res) { |
| 93 | + if (req.params.id) { |
| 94 | + req.client.setName(req.params.id) |
| 95 | + } |
| 96 | + |
| 97 | + console.log(req.client); |
| 98 | + |
| 99 | + Promise.all([req.client.getCollection(), req.client.getMapping()]) |
| 100 | + .spread(function(collection, mapping) { |
| 101 | + res.render('collections/edit', { |
| 102 | + collection: JSON.stringify(collection, null, 4), |
| 103 | + mapping: JSON.stringify(mapping, null, 4) |
| 104 | + }); |
| 105 | + }) |
| 106 | +}) |
| 107 | + |
| 108 | +/** |
| 109 | + * collections post edit |
| 110 | + */ |
| 111 | +admin.post(['/collections/edit', '/collections/edit/:id'], function (req, res) { |
| 112 | + |
| 113 | + if (req.params.id) { |
| 114 | + req.client.setName(req.params.id) |
| 115 | + } |
| 116 | + |
| 117 | + var json = JSON.parse(req.body.row) |
| 118 | + console.log(json); |
| 119 | + req.client.updateCollection(json) |
| 120 | + .then(function(result) { |
| 121 | + console.log(result); |
| 122 | + var url = req.params.id ? |
| 123 | + '/admin/collections/edit/' + req.params.id : |
| 124 | + '/admin/collections/edit' |
| 125 | + res.redirect(url); |
| 126 | + }) |
| 127 | +}) |
| 128 | + |
| 129 | +module.exports = admin; |
0 commit comments