Skip to content

Commit

Permalink
Grails 3 some fixes ( including issue consometers#6 )
Browse files Browse the repository at this point in the history
- Fix create of a user from an administrator
  - consometers#6
  - create applicationKey on server side on the fly in UserService
- When slecting device and deviceType some icons are missing
  - linky & manual counter icon ( to improve )

- Creating a House within USer profile
  - display profile without error if house is missing
  - Workaround a stackoverflow infinite recursion when saving a profile with a house.

- cleanup some unused imports
  • Loading branch information
artlog committed Mar 25, 2022
1 parent c532da0 commit 306d0f4
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 25 deletions.
Binary file added grails-app/assets/images/deviceType/linky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 8 additions & 23 deletions grails-app/services/smarthome/automation/ChartService.groovy
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
package smarthome.automation

import java.util.Date;
import java.util.List;

import grails.converters.JSON;
import grails.plugin.cache.CachePut;
import grails.plugin.cache.Cacheable;

import org.apache.commons.lang.StringUtils;
import grails.web.mapping.LinkGenerator;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Propagation;
import grails.gorm.transactions.Transactional;

import smarthome.core.AbstractService;
import smarthome.core.AsynchronousMessage;
import smarthome.core.ClassUtils;
import smarthome.core.QueryUtils;
import smarthome.automation.Chart;
import smarthome.core.ExchangeType;
import smarthome.core.SmartHomeException;
import smarthome.core.chart.ChartTransformer;
import smarthome.security.User;

import grails.gorm.transactions.Transactional
import org.apache.commons.lang.StringUtils
import org.springframework.security.access.prepost.PreAuthorize
import smarthome.automation.Chart
import smarthome.core.AbstractService
import smarthome.core.ClassUtils
import smarthome.core.SmartHomeException
import smarthome.core.chart.ChartTransformer

class ChartService extends AbstractService {

Expand Down
6 changes: 4 additions & 2 deletions grails-app/services/smarthome/automation/HouseService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ group by chauffage.libelle
house.defaut = true
house.name = "Maison principale"
}

return super.save(house)

house.save();
// grails 3, StackOverflow infinite recursion loop with super AbstractService
// return super.save(house)
}


Expand Down
4 changes: 4 additions & 0 deletions grails-app/services/smarthome/security/UserService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class UserService extends AbstractService {
user.lastActivation = new Date()
user.passwordExpired = true
user.password = UUID.randomUUID() // création d'un password fictif en attente du déblocage par l'utilisateur
// never save a User without an applicationKey and generate it only on server side.
if ( user.applicationKey == null ) {
user.applicationKey = UUID.randomUUID()
}
}


Expand Down
49 changes: 49 additions & 0 deletions grails-app/views/deviceType/linky/_linkyForm.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<g:set var="fournisseur" value="${ device?.metadata('fournisseur') }"/>

<g:if test="${ fournisseur?.id }">
<g:hiddenField name="metadatas[0].id" value="${ fournisseur.id }"/>
</g:if>

<g:hiddenField name="metadatas[0].name" value="fournisseur"/>

<div class="field-group">
<label title="API : device.metadata('fournisseur')?.value">
Fournisseur
</label>
<g:select name="metadatas[0].value" value="${ fournisseur?.value }" class="select" optionKey="libelle" optionValue="libelle"
from="${smarthome.automation.DeviceTypeProvider.findAllByDeviceType(device?.deviceType)}"
noSelection="['': '']"/>
</div>


<g:set var="unite" value="${ device?.metadata('unite') }"/>

<g:if test="${ unite?.id }">
<g:hiddenField name="metadatas[1].id" value="${ unite.id }"/>
</g:if>

<g:hiddenField name="metadatas[1].name" value="unite"/>

<div class="field-group">
<label title="API : device.metadata('unite')?.value">
Unité
</label>
<g:field type="text" name="metadatas[1].value" value="${unite?.value}" class="text medium-field"/>
</div>


<g:set var="coefConversion" value="${ device?.metadata('coefConversion') }"/>

<g:if test="${ coefConversion?.id }">
<g:hiddenField name="metadatas[2].id" value="${ coefConversion.id }"/>
</g:if>

<g:hiddenField name="metadatas[2].name" value="coefConversion"/>

<div class="field-group">
<label title="API : device.metadata('coefConversion')?.value">
Coefficient de conversion
</label>
<g:field type="number decimal" name="metadatas[2].value" value="${coefConversion?.value}" class="text medium-field"/>
<div class="description">Ce coefficient sera appliqué sur la consommation intermédiaire et non pas sur l'index total qui lui ne change pas</div>
</div>
35 changes: 35 additions & 0 deletions grails-app/views/deviceType/manualCounter/_manualCounterForm.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<g:set var="timeout" value="${ device?.metadata('timeout') }"/>

<g:if test="${ timeout?.id }">
<g:hiddenField name="metadatas[0].id" value="${ timeout.id }"/>
</g:if>

<g:hiddenField name="metadatas[0].name" value="timeout"/>

<div class="field-group">
<label title="API : device.metadata('timeout')?.value">
Timeout bouton poussoir (en millisecondes)
</label>
<g:field type="number" name="metadatas[0].value" value="${timeout?.value}" class="text medium-field"/>
</div>


<g:set var="defaulttimer" value="${ device?.metadata('defaulttimer') }"/>

<g:if test="${ defaulttimer?.id }">
<g:hiddenField name="metadatas[1].id" value="${ defaulttimer.id }"/>
</g:if>

<g:hiddenField name="metadatas[1].name" value="defaulttimer"/>

<div class="field-group">
<label title="API : device.metadata('defaulttimer')?.value">
Minuterie par défaut (en minutes)
</label>
<g:field type="text" name="metadatas[1].value" value="${defaulttimer?.value}" class="text medium-field"/>
</div>


<h4>Configuration périphérique</h4>
<g:render template="/deviceType/generic/metadatasForm"
model="[device: device, exclude: ['timeout', 'defaulttimer'], startStatus: 2, commitButton: true]"/>
3 changes: 3 additions & 0 deletions grails-app/views/house/_form.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
<label>Ville</label>
<g:textField name="house.location" value="${house?.location}" class="text long-field" />
<div class="description">Utilisé pour les prévisions météo sous la forme "ville et/ou code postal, pays". Ex : Lorient, France. Calculé tous les jours à minuit.
<g:if test="${ house?.id }">
<sec:ifAllGranted roles="ROLE_ADMIN">
<g:remoteLink action="calculWeather" controller="houseWeather" id="${ house.id }" onSuccess="alert('Calcul terminé')" onFailure="alert('Erreur calcul')">Calcul manuel</g:remoteLink>
</sec:ifAllGranted>
</g:if>
</div>

</div>
<div class="field-group">
<label>Surface (en m²)</label>
Expand Down

0 comments on commit 306d0f4

Please sign in to comment.