Permalink
Browse files

added the schedule item stuff, now with autocomplete, datepicker and …

…dataTable component
  • Loading branch information...
1 parent 71f51ad commit c67357a69ebaf69a7d9d87c6e0b934cb28fec605 @jettro committed Dec 20, 2009
@@ -0,0 +1,55 @@
+package nl.gridshore.scheduling
+
+import grails.converters.JSON
+
+class SchedulingController {
+ def scheduleItemService;
+
+ def index = {
+
+ }
+
+ def create = {
+ def persons = Person.list()
+ def projects = Project.list()
+
+ [projects: projects, persons: persons]
+ }
+
+ def newScheduleItem = {
+ def personName = params.person
+ def projectName = params.project
+ def nrHours = params.nrhours.toInteger()
+ def weekNr = params.weeknr.toInteger()
+
+ flash.message = "New item is created for person ${personName} and project ${projectName}"
+ scheduleItemService.createScheduleItem(personName, projectName, weekNr, nrHours)
+ redirect(action: "create")
+ }
+
+ def scheduleItemDataAsJSON = {
+ def list = []
+ def allItems = ScheduleItem.list(params)
+ response.setHeader("Cache-Control", "no-store")
+ allItems.each {
+ list << [
+ id:it.id,
+ person:it.person.toString(),
+ project:it.project.toString(),
+ weekNr:it.weekNr,
+ nrHours:it.nrHours
+ ]
+ }
+ def data = [
+ totalRecords: ScheduleItem.count(),
+ results: list
+ ]
+ render data as JSON
+ }
+
+ static navigation = [group: 'tabs', order: 40, action: 'index',
+ subItems: [
+ [group: 'tabs', action: 'create']
+ ]
+ ]
+}
@@ -0,0 +1,34 @@
+package nl.gridshore.scheduling
+
+class ScheduleItemService {
+
+ boolean transactional = true
+
+ def createScheduleItems(long personId, long projectId,int numberHours,int weekNr,
+ Date startDate, Date endDate) {
+ // determine the start and end date
+
+ doCreateScheduleItem(person, project, weekNr, numberHours)
+ }
+
+ def createScheduleItem(String personName, String projectName, int weekNr, int numberHours) {
+ def project = Project.findByName(projectName)
+ def person = Person.findByName(personName)
+ doCreateScheduleItem(person,project,weekNr,numberHours)
+ }
+
+ def createScheduleItem(long personId, long projectId, int weekNr, int numberHours) {
+ def project = Project.get(projectId)
+ def person = Person.get(personId)
+ doCreateScheduleItem(person,project,weekNr,numberHours)
+ }
+
+ private def doCreateScheduleItem(Person person, Project project, int weekNr, int numberHours) {
+ def scheduleItem = new ScheduleItem(
+ person: person,
+ project: project,
+ weekNr: weekNr,
+ nrHours: numberHours)
+ scheduleItem.save()
+ }
+}
@@ -3,8 +3,104 @@
<head>
<title>Home page</title>
<meta name="layout" content="main"/>
+ <style type="text/css" media="screen">
+
+ #nav {
+ margin-top:20px;
+ margin-left:30px;
+ width:228px;
+ float:left;
+
+ }
+ .homePagePanel * {
+ margin:0px;
+ }
+ .homePagePanel .panelBody ul {
+ list-style-type:none;
+ margin-bottom:10px;
+ }
+ .homePagePanel .panelBody h1 {
+ text-transform:uppercase;
+ font-size:1.1em;
+ margin-bottom:10px;
+ }
+ .homePagePanel .panelBody {
+ background: url(images/leftnav_midstretch.png) repeat-y top;
+ margin:0px;
+ padding:15px;
+ }
+ .homePagePanel .panelBtm {
+ background: url(images/leftnav_btm.png) no-repeat top;
+ height:20px;
+ margin:0px;
+ }
+
+ .homePagePanel .panelTop {
+ background: url(images/leftnav_top.png) no-repeat top;
+ height:11px;
+ margin:0px;
+ }
+ h2 {
+ margin-top:15px;
+ margin-bottom:15px;
+ font-size:1.2em;
+ }
+ #pageBody {
+ margin-left:280px;
+ margin-right:20px;
+ }
+ </style>
+
</head>
<body>
- Place your content here
+ <div id="nav">
+ <div class="homePagePanel">
+ <div class="panelTop">
+
+ </div>
+ <div class="panelBody">
+ <h1>Application Status</h1>
+ <ul>
+ <li>App version: <g:meta name="app.version"></g:meta></li>
+ <li>Grails version: <g:meta name="app.grails.version"></g:meta></li>
+ <li>JVM version: ${System.getProperty('java.version')}</li>
+ <li>Controllers: ${grailsApplication.controllerClasses.size()}</li>
+ <li>Domains: ${grailsApplication.domainClasses.size()}</li>
+ <li>Services: ${grailsApplication.serviceClasses.size()}</li>
+ <li>Tag Libraries: ${grailsApplication.tagLibClasses.size()}</li>
+ </ul>
+ <h1>Installed Plugins</h1>
+ <ul>
+ <g:set var="pluginManager"
+ value="${applicationContext.getBean('pluginManager')}"></g:set>
+
+ <g:each var="plugin" in="${pluginManager.allPlugins}">
+ <li>${plugin.name} - ${plugin.version}</li>
+ </g:each>
+
+ </ul>
+ </div>
+ <div class="panelBtm">
+ </div>
+ </div>
+
+
+ </div>
+ <div id="pageBody">
+ <h1>Welcome to Grails</h1>
+ <p>Congratulations, you have successfully started your first Grails application! At the moment
+ this is the default page, feel free to modify it to either redirect to a controller or display whatever
+ content you may choose. Below is a list of controllers that are currently deployed in this application,
+ click on each to execute its default action:</p>
+
+ <div id="controllerList" class="dialog">
+ <h2>Available Controllers:</h2>
+ <ul>
+ <g:each var="c" in="${grailsApplication.controllerClasses}">
+ <li class="controller"><g:link controller="${c.logicalPropertyName}">${c.fullName}</g:link></li>
+ </g:each>
+ </ul>
+ </div>
+ </div>
</body>
</html>
@@ -16,6 +16,14 @@
<nav:render group="tabs"/>
<nav:renderSubItems group="tabs"/>
</div>
+<div id="messages">
+ <g:if test="${flash.error}">
+ <div class="flasherror">${flash.error}</div>
+ </g:if>
+ <g:if test="${flash.message}">
+ <div class="flash">${flash.message}</div>
+ </g:if>
+</div>
<g:layoutBody/>
</body>
</html>
@@ -0,0 +1,26 @@
+<%@ page contentType="text/html;charset=UTF-8" %>
+<html>
+<head>
+ <title>Create schedule item</title>
+ <meta name="layout" content="main"/>
+ <gui:resources components="autoComplete,datePicker"/>
+</head>
+<body>
+<g:form action="newScheduleItem" method="POST">
+ <div style="width:300px">
+ Person : <span class="yui-skin-sam"><gui:autoComplete id="person" options="${persons*.name}"/></span>
+ Project : <span class="yui-skin-sam"><gui:autoComplete id="project" options="${projects*.name}"/></span>
+ </div>
+
+ <div style="width:300px">
+ Number of hours : <br/><g:textField id="nrhours" name="nrhours"/><br/>
+ Week number : <br/><g:textField id="weeknr" name="weeknr"/><br/>
+ </div>
+
+ <div class="yui-skin-sam">
+ <gui:datePicker id="startDate"/>
+ <gui:datePicker id="endDate"/>
+ </div>
+</g:form>
+</body>
+</html>
@@ -0,0 +1,31 @@
+<%@ page contentType="text/html;charset=UTF-8" %>
+<html>
+<head>
+ <title>Show all schedule items</title>
+ <meta name="layout" content="main"/>
+ <gui:resources components="dataTable"/>
+</head>
+<body>
+<div class="yui-skin-sam">
+ <gui:dataTable
+ id="scheduleItemDatatable"
+ draggableColumns="true"
+ columnDefs="[
+ [key:'id', sortable:true, resizeable: true, label:'ID'],
+ [key:'person', sortable:true, resizeable: true, label:'Person'],
+ [key:'project', sortable:true, resizeable: true, label: 'Project'],
+ [key:'weekNr', type:'number', sortable:true, resizeable: true, label: 'Week Nr'],
+ [key:'nrHours', type:'number', sortable:true, resizeable: true, label: 'Nr Hours']
+ ]"
+ paginatorConfig="[
+ template:'{PreviousPageLink} {PageLinks} {NextPageLink} {CurrentPageReport}',
+ pageReportTemplate:'{totalRecords} total records'
+ ]"
+ controller="scheduling"
+ action="scheduleItemDataAsJSON"
+ resultsList="results"
+ rowExpansion="false"
+ rowsPerPage="15"/>
+</div>
+</body>
+</html>
@@ -0,0 +1,17 @@
+package nl.gridshore.scheduling
+
+import grails.test.*
+
+class ScheduleItemServiceTests extends GrailsUnitTestCase {
+ protected void setUp() {
+ super.setUp()
+ }
+
+ protected void tearDown() {
+ super.tearDown()
+ }
+
+ void testSomething() {
+
+ }
+}
@@ -0,0 +1,17 @@
+package nl.gridshore.scheduling
+
+import grails.test.*
+
+class SchedulingControllerTests extends ControllerUnitTestCase {
+ protected void setUp() {
+ super.setUp()
+ }
+
+ protected void tearDown() {
+ super.tearDown()
+ }
+
+ void testSomething() {
+
+ }
+}

0 comments on commit c67357a

Please sign in to comment.