Skip to content

Commit

Permalink
beginning work on menu management
Browse files Browse the repository at this point in the history
  • Loading branch information
davydotcom committed Jan 9, 2014
1 parent 1808a8a commit c92c242
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 4 deletions.
3 changes: 2 additions & 1 deletion SpudCms/grails-app/conf/SpudPageUrlMappings.groovy
Expand Up @@ -7,8 +7,9 @@ class SpudPageUrlMappings {
"/spud/admin/pages"(resources: "pages", namespace: "spud_admin")
"/spud/admin/pages/page_parts/$id"(controller: "pages", namespace: "spud_admin", action: 'pageParts')
"/spud/admin/snippets"(resources: "snippets", namespace: "spud_admin")
"/spud/admin/menus"(resources: "menus", namespace: "spud_admin")
"/spud/admin/menus"(resources: "menus", namespace: "spud_admin") {
"menu_items"(resources: "menu_items", namespace: "spud_admin")
"/menu_items"(resources: "menuItems", namespace: "spud_admin")
}

"/$id**" (
Expand Down
@@ -0,0 +1,91 @@
package spud.admin
import spud.cms.*
import spud.core.*

@SpudApp(name="Menus", thumbnail="spud/admin/menus_thumb.png")
@SpudSecure(['MENUS'])
class MenuItemsController {
static namespace = "spud_admin"

def index() {
def menu = loadMenu()
if(!menu) {
return
}
def menuItems = SpudMenuItem.findAllByMenu(menu)
render view: '/spud/admin/menu_items/index', model:[menuItems: menuItems]
}

def create() {
def menu = new SpudMenu()
render view: '/spud/admin/menus/create', model:[menu: menu]
}

def save() {
if(!params.menu) {
flash.error = "Menu submission not specified"
redirect resource: 'menus', action: 'index', namespace: 'spud_admin'
return
}

def menu = new SpudMenu(params.menu)



if(menu.save(flush:true)) {
redirect resource: 'menus', action: 'index', namespace: 'spud_admin'
} else {
flash.error = "Error Saving Menu"
render view: '/spud/admin/menus/create', model:[menu:menu]
}
}

def edit = {
def menu = loadMenu()
if(!menu) {
return
}
render view: '/spud/admin/menus/edit', model: [menu: menu]

}

def update() {
def menu = loadMenu()
if(!menu) {
return
}
menu.properties += params.menu

if(menu.save(flush:true)) {
redirect resource: 'menus', action: 'index', namespace: 'spud_admin'
} else {
render view: '/spud/admin/menus/edit', model: [menu: menu]
}
}

def delete() {
def menu = loadMenu()
if(!menu) {
return
}
menu.delete()
flash.notice = "Menu Removed Successfully!"
redirect resource: 'menus', action: 'index', namespace: 'spud_admin'
}

private loadMenu() {
if(!params.menusId) {
flash.error = "Menu Id Not Specified For Listing Menu Items"
redirect controller: 'menus', action: 'index', namespace: 'spud_admin'
return null
}

def menu = SpudMenu.get(params.menusId)
if(!menu) {
flash.error = "Menu not found for listing Menu Items!"
redirect controller: 'menus', action: 'index', namespace: 'spud_admin'
return null
}
return menu
}
}
87 changes: 87 additions & 0 deletions SpudCms/grails-app/controllers/spud/admin/MenusController.groovy
@@ -0,0 +1,87 @@
package spud.admin
import spud.cms.*
import spud.core.*

@SpudApp(name="Menus", thumbnail="spud/admin/menus_thumb.png")
@SpudSecure(['MENUS'])
class MenusController {
static namespace = "spud_admin"

def index() {
def menus = SpudMenu.list([sort: 'name', max: 25] + params)
render view: '/spud/admin/menus/index', model:[menus: menus, menuCount: SpudMenu.count()]
}

def create() {
def menu = new SpudMenu()
render view: '/spud/admin/menus/create', model:[menu: menu]
}

def save() {
if(!params.menu) {
flash.error = "Menu submission not specified"
redirect resource: 'menus', action: 'index', namespace: 'spud_admin'
return
}

def menu = new SpudMenu(params.menu)



if(menu.save(flush:true)) {
redirect resource: 'menus', action: 'index', namespace: 'spud_admin'
} else {
flash.error = "Error Saving Menu"
render view: '/spud/admin/menus/create', model:[menu:menu]
}
}

def edit = {
def menu = loadMenu()
if(!menu) {
return
}
render view: '/spud/admin/menus/edit', model: [menu: menu]

}

def update() {
def menu = loadMenu()
if(!menu) {
return
}
menu.properties += params.menu

if(menu.save(flush:true)) {
redirect resource: 'menus', action: 'index', namespace: 'spud_admin'
} else {
render view: '/spud/admin/menus/edit', model: [menu: menu]
}
}

def delete() {
def menu = loadMenu()
if(!menu) {
return
}
menu.delete()
flash.notice = "Menu Removed Successfully!"
redirect resource: 'menus', action: 'index', namespace: 'spud_admin'
}

private loadMenu() {
if(!params.id) {
flash.error = "Menu Id Not Specified"
redirect controller: 'menus', action: 'index', namespace: 'spud_admin'
return null
}

def menu = SpudMenu.get(params.id)
if(!menu) {
flash.error = "Menu not found!"
redirect controller: 'menus', action: 'index', namespace: 'spud_admin'
return null
}
return menu
}
}
Expand Up @@ -8,7 +8,7 @@ class SnippetsController {
static namespace = "spud_admin"

def index = {
def snippets = SpudSnippet.list([sort: 'name'] + params)
def snippets = SpudSnippet.list([sort: 'name', max:25] + params)
render view: '/spud/admin/snippets/index', model:[snippets: snippets, snippetCount: SpudSnippet.count()]
}

Expand Down
24 changes: 24 additions & 0 deletions SpudCms/grails-app/domain/spud/cms/SpudMenu.groovy
@@ -0,0 +1,24 @@
package spud.cms

class SpudMenu {
Integer siteId = 0
String name
String description


Date dateCreated
Date lastUpdated

static mapping = {
table 'spud_menus'
autoTimestamp true
description type:'text'

dateCreated column: 'created_at'
lastUpdated column: 'updated_at'
}
static constraints = {
name blank:false, unique: 'siteId'
description nullable:true
}
}
42 changes: 42 additions & 0 deletions SpudCms/grails-app/domain/spud/cms/SpudMenuItem.groovy
@@ -0,0 +1,42 @@
package spud.cms

class SpudMenuItem {
String name
String parentType
Long parentId

Integer menuOrder = 0
String url
SpudPage page

SpudMenu menu


Date dateCreated
Date lastUpdated

static mapping = {
table 'spud_menu_items'
autoTimestamp true

menu column: 'spud_menu_id'
page column: 'spud_page_id'

dateCreated column: 'created_at'
lastUpdated column: 'updated_at'

// parentType index: 'idx_menu_item_parent'
// parentId index: 'idx_menu_item_parent'
// TODO Add Multi column index for parent in right order
}
static constraints = {
name blank:false
menu nullable: false
parentType blank: false
parentId blank: false
url nullable: true
page nullable: true
menuOrder nullable: true

}
}
10 changes: 10 additions & 0 deletions SpudCms/grails-app/views/spud/admin/menus/_form.gsp
@@ -0,0 +1,10 @@
<fieldset>
<div class="control-group">
<label for="menu.name" class="control-label">Name</label>
<div class="controls">
<g:textField name="menu.name" value="${menu?.name}"/>
</div>

</div>
</fieldset>

11 changes: 11 additions & 0 deletions SpudCms/grails-app/views/spud/admin/menus/create.gsp
@@ -0,0 +1,11 @@
<g:applyLayout name="spud/admin/detail" >

<content tag="detail">
<g:form name="new_menu" url="[action: 'save', method:'POST', resource: 'menus',namespace: 'spud_admin']" method="POST" class="form-horizontal">
<g:render template="/spud/admin/menus/form" model="[menu: menu]" />
<div class="form-actions">
<g:submitButton name="_submit" value="Create Menu" class="btn btn-primary"/> or <spAdmin:link action="index" resource="menus" class="btn">cancel</spAdmin:link>
</div>
</g:form>
</content>
</g:applyLayout>
11 changes: 11 additions & 0 deletions SpudCms/grails-app/views/spud/admin/menus/edit.gsp
@@ -0,0 +1,11 @@
<g:applyLayout name="spud/admin/detail" >

<content tag="detail">
<g:form name="edit_menu" url="[action: 'update', method:'PUT', resource: 'menus', id: menu.id ,namespace: 'spud_admin']" method="PUT" class="form-horizontal">
<g:render template="/spud/admin/menus/form" model="[menu: menu]" />
<div class="form-actions">
<g:submitButton name="_submit" value="Save Menu" class="btn btn-primary"/> or <spAdmin:link action="index" resource="menus" class="btn">cancel</spAdmin:link>
</div>
</g:form>
</content>
</g:applyLayout>
28 changes: 28 additions & 0 deletions SpudCms/grails-app/views/spud/admin/menus/index.gsp
@@ -0,0 +1,28 @@
<g:applyLayout name="spud/admin/detail" >
<content tag="data_controls">
<spAdmin:link resource="menus" action="create" class="btn btn-primary" title="New Menu">New Menu</spAdmin:link>
</content>


<content tag="detail">
<div class="page_list">
<g:each var="menu" in="${menus}">
<div class="page_row">

<span class="row_meta"><spAdmin:link controller="menuItems" action="index" params="[menusId: menu.id]">${menu.name}</spAdmin:link>

<span class="edit_controls">
<spAdmin:link action="edit" id="${menu.id}" title="Edit ${menu.name}" class="btn">Edit</spAdmin:link>

<spAdmin:link resource="menus" action="delete" data-method="DELETE" id="${menu.id}" data-confirm="Are you sure you want to remove this menu and all items associated with it?" class="btn btn-danger">Remove</spAdmin:link>
</span>
<br style="clear:both;"/>
</div>
</g:each>
<g:paginate resource="menus" action="index" namespace="spud_admin" total="${menuCount}" max="25" />
</div>



</content>
</g:applyLayout>
2 changes: 1 addition & 1 deletion SpudCms/grails-app/views/spud/admin/snippets/index.gsp
Expand Up @@ -3,7 +3,7 @@
<spAdmin:link resource="snippets" action="create" class="btn btn-primary" title="New Snippet">New Snippet</spAdmin:link>
</content>
<content tag="detail">

<p class="lead">Snippets are reusable chunks of content that can be injected into your pages and layouts.</p>
<div class="page_list">
<g:each var="snippet" in="${snippets}">
<div class="page_row">
Expand Down
Expand Up @@ -15,6 +15,8 @@ class SpudPermalink {
static constraints = {
attachmentType nullable: true
attachmentId nullable: true
siteId index: true
// TODO: Create Index Compound on attachmentType, attachmentId
}

static mapping = {
Expand Down
Expand Up @@ -3,7 +3,9 @@
<content tag="data_controls">
<spAdmin:link action="create" title="New Permalink" class="btn btn-primary">New Permalink</spAdmin:link>
</content>

<content tag="detail">
<p class="lead">Permalinks allow you to define a url that can be redirected to another location. Useful for moving pages and content without sacrificing SEO.</p>
<table class="admin-table data-table" id="usertable">
<thead>
<tr>
Expand All @@ -23,7 +25,9 @@
<td>${permalink.attachmentType ?: 'N/A'}</td>
<td>${permalink.dateCreated}</td>
<td align="right">
<spAdmin:link action="edit" id="${permalink.id}" title="Edit ${permalink.urlName}" class="btn">Edit</spAdmin:link>
<g:if test="${!permalink.attachmentType}">
<spAdmin:link action="edit" id="${permalink.id}" title="Edit ${permalink.urlName}" class="btn">Edit</spAdmin:link>
</g:if>
<spAdmin:link resource="permalinks" action="delete" data-method="DELETE" id="${permalink.id}" data-confirm="Are you sure you want to remove this permalink?" class="btn btn-danger">Remove</spAdmin:link>
</td>
</tr>
Expand Down

0 comments on commit c92c242

Please sign in to comment.