Skip to content

Commit

Permalink
Create demo environment for snippet resource
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrekalo committed Oct 18, 2018
1 parent 9cd5219 commit 4b22f69
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
74 changes: 74 additions & 0 deletions demo/controllers/snippet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
export default {

resourceName: 'snippet',
resourceCaption: 'title',

setupList: function({list}) {

this.addCreateControl('Create new snippet');

// --------------------------------------------------------------
// Filters
// --------------------------------------------------------------
list.addFilter('TextFormElement', {
name: 'title',
label: 'Title'
});

// --------------------------------------------------------------
// List items
// --------------------------------------------------------------
list.addItem('TextListItem', {
caption: 'ID',
mapTo: 'id',
addIf: this.screenIsLarge
});

list.addItem('LinkListItem', {
caption: 'Title',
mapTo: 'title',
action: 'editItem'
});

list.addItem('TextListItem', {
caption: 'Code',
mapTo: 'code'
});

list.addItem('TextListItem', {
caption: 'Content',
mapTo: 'content',
limitCharacters: 130,
stripTags: true
});

list.addItem('ContextMenuListItem', {
caption: 'Actions',
items: [{caption: 'Edit', action: 'editItem'}]
});

},

setupEdit: function({edit}) {

this.addToIndexControl().addSaveControl();

edit.addField('TextareaFormElement', {
label: 'Title',
name: 'title',
attributes: {input: {class: 'inputType2 size2 fontBold'}}
});

edit.addField('TextFormElement', {
label: 'Code',
name: 'code'
});

edit.addField('CodeFormElement', {
label: 'Content',
name: 'content'
});

}

};
6 changes: 6 additions & 0 deletions demo/mainNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export default {
url: router.url('resource.category.index')
},

{
caption: 'Html snippets',
key: 'snippet',
url: router.url('resource.snippet.index')
},

{
caption: 'Tags',
key: 'tag',
Expand Down
1 change: 1 addition & 0 deletions demo/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default router => {
router.resource('user');
router.resource('tag');
router.resource('category');
router.resource('snippet');
router.resource({name: 'media', hasCreateRoute: ['image', 'videoEmbed', 'file']});

router.controller('my-settings', 'mySettings', 'MySettings');
Expand Down
1 change: 1 addition & 0 deletions demo/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default {
UserController: () => import('./controllers/user'),
CategoryController: () => import('./controllers/category'),
MediaController: () => import('./controllers/media'),
SnippetController: () => import('./controllers/snippet'),
MySettingsController: () => import('./controllers/mySettings')
};
36 changes: 36 additions & 0 deletions server/fakeServerConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,42 @@ module.exports = {

}
},
snippet: {
filters: {
title: function(title, query) {
return title.toLowerCase().indexOf(query.toLowerCase()) >= 0;
}
},
validationRules: {
title: {
rule: function(title) {
return title.length > 0;
},
message: 'Please enter title.'
},
code: {
rule: function(code) {
return code.length > 0;
},
message: 'Please enter code.'
}
},
data: function(random) {

return range(1, 50).map(function(index) {
return {
type: 'snippet',
id: String(index),
attributes: {
title: 'Snippet ' + index,
code: 'snippet.code.' + index,
content: '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>'
}
};
});

}
},
category: {
filters: {
title: function(title, query) {
Expand Down

0 comments on commit 4b22f69

Please sign in to comment.