forked from consometers/consoherozh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Grails3 add Chauffage creation possibility
- within a profile it is possible to select a Chauffage type but there is not visible way to create one, added.
- Loading branch information
Showing
6 changed files
with
140 additions
and
4 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
grails-app/controllers/smarthome/automation/ChauffageController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package smarthome.automation | ||
|
||
import org.springframework.security.access.annotation.Secured | ||
import smarthome.core.AbstractController | ||
import smarthome.plugin.NavigableAction | ||
import smarthome.plugin.NavigationEnum | ||
import smarthome.security.User | ||
|
||
class ChauffageController extends AbstractController { | ||
|
||
ChauffageService chauffageService | ||
|
||
@NavigableAction(label = "Chauffages", navigation = NavigationEnum.configuration, header = "Administrateur") | ||
def search(String chauffageSearch) { | ||
List<Chauffage> chauffages = chauffageService.list(chauffageSearch, this.getPagination([:])) | ||
render view: 'search', model: [recordsTotal:chauffages.size(),chauffages:chauffages] | ||
} | ||
|
||
@Secured("hasRole('ROLE_ADMIN')") | ||
def add() { | ||
String libelle = params.libelle | ||
if (libelle) { | ||
chauffageService.create(params.libelle) | ||
} | ||
redirect action: 'search' | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
grails-app/services/smarthome/automation/ChauffageService.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package smarthome.automation | ||
|
||
import grails.gorm.transactions.Transactional | ||
import smarthome.core.AbstractService | ||
import smarthome.core.QueryUtils | ||
|
||
@Transactional | ||
class ChauffageService extends AbstractService { | ||
|
||
Chauffage create(String libelle) { | ||
List<Chauffage> chauffages = listChauffageByLibelle(libelle); | ||
if (chauffages.isEmpty()) | ||
{ | ||
Chauffage chauffage = new Chauffage(libelle:libelle) | ||
save(chauffage) | ||
} | ||
else { | ||
return chauffages.first(); | ||
} | ||
} | ||
|
||
List<Chauffage> list(String chauffageSearch, Map pagination) { | ||
return Chauffage.createCriteria().list(pagination) { | ||
if (chauffageSearch) { | ||
ilike 'agentModel', QueryUtils.decorateMatchAll(chauffageSearch) | ||
} | ||
} | ||
} | ||
|
||
List<Chauffage> listChauffageByLibelle( String libelle) { | ||
return Chauffage.createCriteria().list { | ||
eq 'libelle', libelle | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<html> | ||
<head> | ||
<meta name='layout' content='authenticated' /> | ||
</head> | ||
|
||
<body> | ||
|
||
<g:applyLayout name="applicationConfigure"> | ||
|
||
<g:form > | ||
<fieldset> | ||
<div class="field-group"> | ||
<label for="libelle">Libelle<span | ||
class="aui-icon icon-required"> required</span></label> | ||
<g:textField class="text long-field" name="libelle" value=""/> | ||
</div> | ||
</fieldset> | ||
<g:actionSubmit class="aui-button" value="Ajouter ce chauffage" action="add"/> | ||
</g:form> | ||
|
||
<div style="overflow-x:auto;"> | ||
<app:datatable datatableId="datatable" recordsTotal="${ recordsTotal }"> | ||
<thead> | ||
<tr> | ||
<th>Libelle</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<g:each var="chauffage" in="${ chauffages }"> | ||
<tr> | ||
<td>${chauffage.libelle}</td> | ||
</tr> | ||
</g:each> | ||
</tbody> | ||
</app:datatable> | ||
</div> | ||
|
||
</g:applyLayout> | ||
|
||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/groovy/smarthome/automation/ChauffageControllerSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package smarthome.automation | ||
|
||
import grails.testing.web.controllers.ControllerUnitTest | ||
import spock.lang.Specification | ||
|
||
class ChauffageControllerSpec extends Specification implements ControllerUnitTest<ChauffageController> { | ||
|
||
def setup() { | ||
} | ||
|
||
def cleanup() { | ||
} | ||
|
||
void "test something"() { | ||
expect:"fix me" | ||
true == false | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/groovy/smarthome/automation/ChauffageServiceSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package smarthome.automation | ||
|
||
import grails.testing.services.ServiceUnitTest | ||
import spock.lang.Specification | ||
|
||
class ChauffageServiceSpec extends Specification implements ServiceUnitTest<ChauffageService>{ | ||
|
||
def setup() { | ||
} | ||
|
||
def cleanup() { | ||
} | ||
|
||
void "test something"() { | ||
expect:"fix me lame !" | ||
true | ||
} | ||
} |