forked from colmena/colmena
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.js
More file actions
114 lines (112 loc) · 3.95 KB
/
routes.js
File metadata and controls
114 lines (112 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'use strict'
import angular from 'angular'
import templateUrlMain from './views/main.html'
import templateUrlModels from './views/models.html'
import templateUrlModelsInfo from './views/models.info.html'
import templateUrlModelsItems from './views/models.items.html'
import templateUrlModelsItemsAdd from './views/models.items.add.html'
import templateUrlModelsItemsEdit from './views/models.items.edit.html'
import templateUrlModelsItemsView from './views/models.items.view.html'
const app = angular.module('com.module.browser.routes', [])
app.config(($stateProvider) => $stateProvider
.state('app.browser', {
abstract: true,
url: '/browser',
templateUrl: templateUrlMain,
})
.state('app.browser.models', {
url: '',
templateUrl: templateUrlModels,
controllerAs: 'ctrl',
controller: function modelsCtrl (models) {
this.models = models
},
resolve: {
models: (MetaService) => MetaService.find(),
},
})
.state('app.browser.models.info', {
url: '/:modelName/info',
templateUrl: templateUrlModelsInfo,
controllerAs: 'info',
controller: function infoCtrl (model) {
this.model = model
},
resolve: {
model: ($stateParams, MetaService) => MetaService.findById($stateParams.modelName),
},
})
.state('app.browser.models.items', {
url: '/:modelName',
templateUrl: templateUrlModelsItems,
controllerAs: 'items',
controller: function itemsCtrl (model, items) {
this.model = model
this.items = items
this.itemKeys = []
if (this.items[ 0 ] !== undefined) {
this.itemKeys = Object.keys(this.items[ 0 ])
}
},
resolve: {
model: ($stateParams, MetaService) => MetaService.findById($stateParams.modelName),
items: ($stateParams, MetaService) => MetaService.getModelItems($stateParams.modelName),
},
})
.state('app.browser.models.items.view', {
url: '/:modelId/view',
templateUrl: templateUrlModelsItemsView,
controllerAs: 'view',
controller: function itemsViewCtrl (item) {
this.item = item
this.itemKeys = Object.keys(this.item)
},
resolve: {
item: ($stateParams, MetaService) => MetaService.getModelItem($stateParams.modelName, $stateParams.modelId),
},
})
.state('app.browser.models.items.edit', {
url: '/:modelId/edit',
templateUrl: templateUrlModelsItemsEdit,
controllerAs: 'edit',
controller: function itemsEditCtrl ($state, MetaService, model, item, itemFields) {
this.item = item
this.itemFields = itemFields
this.submit = () => MetaService.upsert(model.name, this.item)
.then(() => {
$state.go('app.browser.models.items', { modelName: model.name }, { reload: true })
})
},
resolve: {
item: ($stateParams, MetaService) => MetaService.getModelItem($stateParams.modelName, $stateParams.modelId),
itemFields: ($stateParams, MetaService, model) => MetaService.getModelFields(model),
},
})
.state('app.browser.models.items.add', {
url: '/add',
templateUrl: templateUrlModelsItemsAdd,
controllerAs: 'add',
controller: function addCtrl ($state, MetaService, model, itemFields) {
this.item = {}
this.itemFields = itemFields
this.submit = () => MetaService.upsert(model.name, this.item)
.then(() => {
$state.go('app.browser.models.items', { modelName: model.name }, { reload: true })
})
},
resolve: {
itemFields: ($stateParams, MetaService, model) => MetaService.getModelFields(model),
},
})
.state('app.browser.models.items.delete', {
url: '/:modelId/delete',
template: '',
controller: function deleteCtrl ($state, $stateParams, MetaService, model) {
MetaService.delete(model.name, $stateParams.modelId, () => {
$state.go('app.browser.models.items', { modelName: model.name }, { reload: true })
}, () => {
$state.go('app.browser.models.items', { modelName: model.name }, { reload: true })
})
},
})
)