Skip to content

Commit

Permalink
Grails3 add Chauffage creation possibility
Browse files Browse the repository at this point in the history
- within a profile it is possible to select a Chauffage type
  but there is not visible way to create one, added.
  • Loading branch information
artlog committed Mar 25, 2022
1 parent 53fdbf3 commit c532da0
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 4 deletions.
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 grails-app/services/smarthome/automation/ChauffageService.groovy
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
}
}

}
40 changes: 40 additions & 0 deletions grails-app/views/chauffage/search.gsp
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>
5 changes: 1 addition & 4 deletions src/main/groovy/smarthome/automation/ModeCommand.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
*/
package smarthome.automation

import smarthome.automation.House;
import smarthome.automation.Mode;
import smarthome.security.SmartHomeSecurityUtils;
import grails.validation.Validateable

import smarthome.automation.Mode

/**
* Enregistement profil
Expand Down
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 src/test/groovy/smarthome/automation/ChauffageServiceSpec.groovy
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
}
}

0 comments on commit c532da0

Please sign in to comment.