forked from marmelab/ng-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
184 lines (168 loc) · 5.73 KB
/
config.js
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
(function() {
"use strict";
var app = angular.module('myApp', ['ng-admin']);
app.directive('customPostLink', ['$location', function($location) {
return {
restrict: 'E',
template: '<a ng-click="displayPost(entity)">View post</a>',
controller: function($scope, $location) {
},
link: function($scope, element, attributes) {
$scope.displayPost = function(entity) {
var postId = entity.getField('post_id').value;
$location.path('/edit/posts/' + postId);
}
}
}
}]);
app.config(function(NgAdminConfigurationProvider, Application, Entity, Field, Reference, ReferencedList, ReferenceMany) {
function truncate(value) {
if (!value) {
return '';
}
return value.length > 50 ? value.substr(0, 50) + '...' : value;
}
function pagination(page, maxPerPage) {
return {
_start: (page - 1) * maxPerPage,
_end: page * maxPerPage
}
}
var post = new Entity('posts'),
commentBody = new Field('body'),
commentId = new Field('id');
var tag = new Entity('tags')
.label('Tags')
.order(3)
.dashboard(10)
.pagination(pagination)
.infinitePagination(false)
.addField(new Field('id')
.order(1)
.label('ID')
.type('number')
.identifier(true)
.edition('read-only')
)
.addField(new Field('name')
.order(2)
.label('Name')
.edition('editable')
.validation({
"required": true,
"max-length" : 150
})
).addField(new Field('actions')
.type('callback')
.list(true)
.label('Big Name')
.isEditLink(false)
.callback(function() {
return '{{ entity.getField("name").value.toUpperCase() }}';
})
);
//
var comment = new Entity('comments')
.order(2)
.label('Comments')
.description('Lists all the blog comments with an infinite pagination')
.dashboard(10)
.pagination(pagination)
.infinitePagination(true)
.addField(commentId
.order(1)
.label('ID')
.type('number')
.identifier(true)
.edition('read-only')
)
.addField(new Reference('post_id')
.dashboard(false)
.targetEntity(post)
.targetLabel('title')
)
.addField(commentBody
.order(2)
.type('text')
.label('Comment')
.edition('editable')
.truncateList(truncate)
.validation({
"required": true,
"max-length" : 150
})
)
.addField(new Field('created_at')
.order(3)
.label('Creation Date')
.type('date')
.edition('editable')
.dashboard(false)
.validation({
"required": true
})
).addQuickFilter('Today', function() {
var now = new Date(),
year = now.getFullYear(),
month = now.getMonth() + 1,
day = now.getDate();
month = month < 10 ? '0' + month : month;
day = day < 10 ? '0' + day : day;
return {
created_at: [year, month, day].join('-')
}
})
.addField(new Field('actions')
.type('callback')
.list(true)
.label('Actions')
.isEditLink(false)
.callback(function() {
return '<custom-post-link></custom-post-link>';
})
);
post
.label('Posts')
.order(1)
.dashboard(null)
.perPage(10)
.pagination(pagination)
.titleCreate('Create a post')
.titleEdit('Edit a post')
.description('Lists all the blog posts with a simple pagination')
.addField(new Field('id')
.label('ID')
.type('number')
.identifier(true)
.edition('read-only')
)
.addField(new Field('title')
.label('Title')
.edition('editable')
.truncateList(truncate)
)
.addField(new Field('body')
.label('Body')
.type('wysiwyg')
.edition('editable')
.truncateList(truncate)
)
.addField(new ReferencedList('comments')
.label('Comments')
.targetEntity(comment)
.targetField('post_id')
.targetFields([commentId, commentBody])
)
.addField(new ReferenceMany('tags')
.label('Tags')
.targetEntity(tag)
.targetLabel('name')
);
var app = new Application('ng-admin backend demo')
.baseApiUrl('http://localhost:8080/')
.addEntity(post)
.addEntity(comment)
.addEntity(tag);
NgAdminConfigurationProvider.configure(app);
})
})();