Alan Colon 7 лет назад
Родитель
Сommit
71fcbe7a93

+ 0 - 30
app/api-service.js

@@ -1,30 +0,0 @@
-const app = require('./app')
-const appApiService = require('./app-api-service')
-
-app.service('api', function($http) {
-  let opts = {
-    headers: {},
-    withCredentials: true
-  }
-  const api = (req) => req.then(res => {
-    // Enter post-processing here
-    return res.data
-  })
-  this.login = data => api($http.post('/api/auth/login', data, opts))
-  this.setToken = token => {
-    this.token = token
-    opts.headers.authentication = `Bearer ${token}`
-  }
-
-  this.crud = (apiPrefix) => ({
-    list: () => api($http.get(`${apiPrefix}`, opts)),
-    create: data => api($http.post(`${apiPrefix}`, data, opts)),
-    read: id => api($http.get(`${apiPrefix}/${id}`, opts)),
-    update: (id, data) => api($http.patch(`${apiPrefix}/${id}`, data, opts)),
-    delete: (id) => api($http.delete(`${apiPrefix}/${id}`, opts)),
-    trash: () => api($http.get(`${apiPrefix}/trash`, opts)),
-    undelete: (id) => api($http.delete(`${apiPrefix}/trash/${id}`, opts))
-  })
-
-  appApiService.apply(this, [api, $http])
-})

+ 0 - 3
app/app-api-service.js

@@ -1,3 +0,0 @@
-module.exports = function(api, $http) {
-  this.statistics = () => api($http.get('/api/statistics'))
-}

+ 0 - 19
app/app-index.js

@@ -1,19 +0,0 @@
-const app = require('./app')
-require('./statistics')
-// TODO: Register app specific services
-app.config(($routeProvider, $mdThemingProvider) => {
-  // TODO: App Title
-  window.title = 'Special Dispatch'
-
-  // TODO: Select a theme
-  const palettes = ['red', 'pink', 'purple', 'deep-purple', 'indigo', 'blue', 'light-blue', 'cyan', 'teal', 'green', 'light-green', 'lime', 'yellow', 'amber', 'orange', 'deep-orange', 'brown', 'grey', 'blue-grey']
-  const randomPalette = () => palettes[Math.floor(Math.random() * palettes.length)]
-  $mdThemingProvider.theme('default')
-    .primaryPalette('blue-grey')
-    .accentPalette('indigo')
-    .warnPalette('red')
-
-  // TODO: App Routes
-  //  $routeProvider.when('/test', {template: '<app-test-page />'})
-
-})

+ 20 - 0
app/app.js

@@ -1,5 +1,25 @@
 const angular = require('angular')
 require('material-framework/app')
+const routes = require('./routes')
 
 const app = angular.module('app', ['material-framework'])
+// TODO: Register app specific services
+app.config(($routeProvider, $mdThemingProvider) => {
+  // TODO: App Title
+  window.title = 'Special Dispatch'
 
+  // TODO: Select a theme
+  const palettes = ['red', 'pink', 'purple', 'deep-purple', 'indigo', 'blue', 'light-blue', 'cyan', 'teal', 'green', 'light-green', 'lime', 'yellow', 'amber', 'orange', 'deep-orange', 'brown', 'grey', 'blue-grey']
+  const randomPalette = () => palettes[Math.floor(Math.random() * palettes.length)]
+  $mdThemingProvider.theme('default')
+    .primaryPalette('blue-grey')
+    .accentPalette('indigo')
+    .warnPalette('red')
+
+  // TODO: App Routes
+  routes($routeProvider)
+  //  $routeProvider.when('/test', {template: '<app-test-page />'})
+
+})
+
+module.exports = app

+ 0 - 4
app/assets/app-index.js

@@ -1,4 +0,0 @@
-// TODO: App specific assets
-module.exports = {
-  logo: require('./logo-simple.png')
-}

+ 4 - 0
app/assets/index.js

@@ -0,0 +1,4 @@
+const assets = require('material-framework/app/assets')
+module.exports = Object.assign(assets, {
+  logo: require('./logo-simple.png')
+})

+ 0 - 2
app/components/app-index.js

@@ -1,2 +0,0 @@
-// TODO: App specific components
-require('./app-user-area-nav')

+ 3 - 0
app/components/index.js

@@ -0,0 +1,3 @@
+// TODO: App specific components
+require('./user-area-nav')
+require('./dashboard-page')

+ 0 - 0
app/components/app-user-area-nav.js → app/components/user-area-nav.js


+ 8 - 1
app/index.js

@@ -1 +1,8 @@
-require('./app')
+const assets = require('./assets')
+const app = require('./app')
+require('./services')
+require('./components')
+module.exports = {
+  app,
+  assets
+}

+ 3 - 0
app/routes.js

@@ -0,0 +1,3 @@
+module.exports = function($routeProvider) {
+  $routeProvider.when('/dashboard', {template: '<app-dashboard-page />'})
+}

+ 5 - 0
app/services/api.js

@@ -0,0 +1,5 @@
+const app = require('../app')
+
+app.run(function(api) {
+  api.statistics = () => api.get('/api/statistics')
+})

+ 2 - 0
app/services/index.js

@@ -0,0 +1,2 @@
+require('./statistics')
+require('./api')

+ 1 - 1
app/statistics.js → app/services/statistics.js

@@ -1,5 +1,5 @@
 const _ = require('lodash')
-const app = require('./app')
+const app = require('../app')
 
 app.service('statistics', function(api) {
   const chart = ({

+ 3 - 1
bin/project.js

@@ -1,4 +1,6 @@
 const config = require('../config')
 const frameworkConfig = require('material-framework/config')
 frameworkConfig.inject(config)
-require('material-framework/bin/project')
+require('../lib/server')
+require('../lib/database')
+require('material-framework/bin/project')

+ 0 - 5
lib/app-routes.js

@@ -1,5 +0,0 @@
-const asyncHandler = require('express-async-handler')
-const C = require('./controllers')
-module.exports = (app) => {
-  app.get('/api/statistics', C.statistics.get)
-}

+ 0 - 3
lib/controllers/app-index.js

@@ -1,3 +0,0 @@
-module.exports = {
-  statistics: require('./statistics')
-}

+ 6 - 5
lib/controllers/index.js

@@ -1,5 +1,6 @@
-const appIndex = require('./app-index')
-module.exports = Object.assign({
-  auth: require('./auth'),
-  user: require('./user')
-}, appIndex)
+const statistics = require('./statistics')
+const { controllers: C } = require('material-framework/server')
+
+module.exports = Object.assign(C, {
+  statistics
+})

+ 3 - 2
lib/database/app-index.js → lib/database/index.js

@@ -1,4 +1,5 @@
 // TODO: App Specific Models
+const {database} = require('material-framework/server')
 const Location = require('./location')
 const Workday = require('./workday')
 const Service = require('./service')
@@ -14,7 +15,7 @@ const RetailerService = Retailer.hasMany(Service)
 const ServiceRetailer = Service.belongsTo(Retailer)
 
 
-module.exports = {
+module.exports = Object.assign(database, {
   Location,
   Workday,
   Service,
@@ -25,4 +26,4 @@ module.exports = {
   ServiceWorkday,
   RetailerService,
   ServiceRetailer,
-}
+})

+ 1 - 0
lib/database/sequelize.js

@@ -0,0 +1 @@
+module.exports = require('material-framework/server').database.sequelize

+ 1 - 7
lib/routes.js

@@ -1,10 +1,4 @@
-const crudRoute = require('./crud-route')
-const asyncHandler = require('express-async-handler')
 const C = require('./controllers')
-const appRoutes = require('./app-routes')
-
 module.exports = app => {
-  appRoutes(app)
-  app.post('/api/auth/login', asyncHandler(C.auth.login.post))
-  crudRoute({ app, controller: C.user, typeName: 'User' })
+  app.get('/api/statistics', C.statistics.get)
 }

+ 3 - 2
lib/server.js

@@ -1,2 +1,3 @@
-const app = require('material-framework/server')
-app.start()
+const { app } = require('material-framework/server')
+const routes = require('./routes')
+routes(app)