diff --git a/Back/database/Pipe/DB_Mother/064_Create_TransectForm.txt b/Back/database/Pipe/DB_Mother/064_Create_TransectForm.txt new file mode 100644 index 000000000..baf52d273 --- /dev/null +++ b/Back/database/Pipe/DB_Mother/064_Create_TransectForm.txt @@ -0,0 +1,89 @@ + + +INSERT INTO ProtocoleType +Values ('SubTransect',6,NULL) + +INSERT INTO ObservationDynProp +VALUES ('nb_contact','Integer') + +DECLARE @type int SET @type = (SELECT ID FROM ProtocoleType WHERE Name = 'SubTransect') +DECLARE @contact int SET @contact = (SELECT ID FROM ObservationDynProp WHERE Name = 'nb_contact') + +INSERT INTO ProtocoleType_ObservationDynProp (Required,FK_ProtocoleType,FK_ObservationDynProp) +VALUES +(1,@type,@contact), +(1,@type,(SELECT ID FROM ObservationDynProp WHERE Name = 'taxon')), +(1,@type,(SELECT ID FROM ObservationDynProp WHERE Name = 'validator')), +(1,@type,(SELECT ID FROM ObservationDynProp WHERE Name = 'sampled')), +(1,@type,(SELECT ID FROM ObservationDynProp WHERE Name = 'picture')), +(1,@type,(SELECT ID FROM ObservationDynProp WHERE Name = 'cultivated')) + + + +INSERT INTO ModuleForms ( +[module_id] + ,[TypeObj] + ,[Name] + ,[Label] + ,[Required] + ,[FieldSizeEdit] + ,[FieldSizeDisplay] + ,[InputType] + ,[editorClass] + ,[FormRender] + ,[FormOrder] + ,[Legend] + ,[Options] + ,[Validators] + ,[displayClass] + ,[EditClass] + ,[Status] + ,[Locked] + ,[DefaultValue] ) +VALUES +(1,@type,'taxon','Taxon',1,6,6,'AutocompTreeEditor','form-control',2,10,NULL,'204089',NULL,'fixedCol','fixedCol',1,NULL,NULL), +(1,@type,'autoRanged','',0,3,3,'GridRanged','form-control',2,200,NULL,'{"range":200,"prefixLabel":"P","inputType":"Number"}',NULL,NULL,NULL,1,NULL,NULL), +(1,@type,'FK_ProtocoleType','FK_ProtocoleType',0,3,3,'Number','form-control',0,3000,NULL,NULL,NULL,'hide','hide',1,NULL,231), + + +(1,@type,'validator','Validator',0,6,6,'Select','form-control',2,1020,NULL,'SELECT ID as val, Login as label From [User] Union all select -1 as val, '' '' as label' ,NULL,NULL,NULL,1,1,NULL), +(1,@type,'sampled','Sampled',0,4,4,'Checkbox','form-control',2,1025,NULL,NULL,NULL,'','',1,1,NULL), +(1,@type,'picture','Picture',0,3,3,'Checkbox','form-control',2,1031,NULL,'',NULL,'','',1,NULL,NULL), + +(1,@type,'cultivated','Cultivated',0,4,4,'Checkbox','form-control',2,1035,NULL,'',NULL,'','',1,1,NULL), +(1,@type,'nb_contact','nb contact',0,4,4,'Number','form-control',2,1040,NULL,'',NULL,'','',1,1,NULL), + +(1,@type,'Comments','Comments',0,6,6,'TextArea','form-control',2,2000,NULL,NULL,NULL,'','',1,1,NULL) + + +GO + +INSERT INTO ModuleForms ( +[module_id] + ,[TypeObj] + ,[Name] + ,[Label] + ,[Required] + ,[FieldSizeEdit] + ,[FieldSizeDisplay] + ,[InputType] + ,[editorClass] + ,[FormRender] + ,[FormOrder] + ,[Legend] + ,[Options] + ,[Validators] + ,[displayClass] + ,[EditClass] + ,[Status] + ,[Locked] + ,[DefaultValue] ) +VALUES +(1,220,'SubTransect','',0,3,3,'GridFormEditor','form-control',2,200,NULL,231,NULL,NULL,NULL,1,NULL,NULL) + +GO + +INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('64_Create_TransectForm',GETDATE(),(SELECT db_name())) + + +GO diff --git a/Back/database/Pipe/DB_Mother/065_Migration_SubTransect.txt b/Back/database/Pipe/DB_Mother/065_Migration_SubTransect.txt new file mode 100644 index 000000000..7db341edd --- /dev/null +++ b/Back/database/Pipe/DB_Mother/065_Migration_SubTransect.txt @@ -0,0 +1,123 @@ + + +declare @proto int SET @proto = (SELECT ID FROM ProtocoleType WHERE Name = 'SubTransect') + + +INSERT INTO Observation +(creationDate,FK_ProtocoleType,Comments,original_id,Parent_Observation) +SELECT o.creationDate,@proto,sub.Comments,sub.PK,o.ID +FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub +JOIN Observation o ON o.FK_ProtocoleType = 220 and o.original_id = sub.Fk_Trans + + +declare @proto int SET @proto = (SELECT ID FROM ProtocoleType WHERE Name = 'SubTransect') +INSERT INTO ObservationDynPropValue +(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) +SELECT o.creationDate,Cultivated,NULL,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'cultivated') +FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub +JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto + + +INSERT INTO ObservationDynPropValue +(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) +SELECT o.creationDate,identity_sure,NULL,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'identity_sure') +FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub +JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto + +INSERT INTO ObservationDynPropValue +(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) +SELECT o.creationDate,picture,NULL,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'picture') +FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub +JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto + + +INSERT INTO ObservationDynPropValue +(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) +SELECT o.creationDate,sampled,NULL,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'sampled') +FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub +JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto + + +INSERT INTO ObservationDynPropValue +(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) +SELECT o.creationDate,nb_contact,NULL,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'nb_contact') +FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub +JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto + +INSERT INTO ObservationDynPropValue +(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) +SELECT o.creationDate,NULL,Name_Taxon,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'taxon') +FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub +JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto + + +INSERT INTO ObservationDynPropValue +(StartDate,ValueInt,ValueString,FK_Observation,FK_ObservationDynProp) +SELECT o.creationDate,NULL,validator,o.ID,(SELECT ID FROM ObservationDynProp WHERE Name = 'validator') +FROM [ECWP-eReleveData].dbo.TSubProtocol_Transect sub +JOIN Observation o ON o.original_id = sub.PK AND o.FK_ProtocoleType = @proto + + +---------------------------- INSERT transect occurence value ------------------------ +USE [ECWP-eReleveData] + +BEGIN + IF OBJECT_ID('tempdb..#tempSubTransValue') IS NOT NULL + DROP TABLE #tempSubTransValue + + + CREATE Table #tempSubTransValue (col varchar(10),value decimal, original_ID int ) + + DECLARE @ListCol VARCHAR(MAX) = STUFF((SELECT DISTINCT ',' + name --replace(replace(QUOTENAME(name),'[',''),']','') + FROM sys.columns + WHERE objecT_id = OBJECT_ID('TSubProtocol_Transect') + AND name like 'P%' and name not in ('Picture','PK') + FOR XML PATH(''), TYPE).value('.', 'VARCHAR(MAX)') + ,1,1,'') + ,@sql VARCHAR(MAX) + + + print(@ListCol) + + SET @sql = 'INSERT INTO #tempSubTransValue + SELECT col,value,pk + FROM (SELECT * FROM TSubProtocol_Transect) p + UNPIVOT (value FOR col IN ('+@ListCol+')) as unpvt + where value != 0 + ' + print(@sql) + EXEC (@sql) + + + UPDATE #tempSubTransValue SET col = 'C'+CAST( CONVERT(INT,replace(col,'P',''))-1 AS VARCHAR(10)) + +USE EcoReleve_ECWP + INSERT INTO ObservationDynPropSubValue (FieldName,ValueNumeric,FK_Observation) + select col,value,o.ID + FROM #tempSubTransValue v + JOIN Observation o ON o.original_id = v.original_ID + +Update v set ValueString = CASE WHEN th.TTop_FullPath IS NOT NULL THEN th.TTop_FullPath ELSE ValueString END +FROM ObserVationDynPropValue v +LEFT JOIN THESAURUS.dbo.TTopic th on v.ValueString = th.TTop_Name +WHERE EXISTS ( + SELECT * FROM Observation o + WHERE v.FK_Observation = o.ID and o.FK_ProtocoleType = (SELECT ID FROM ProtocoleType WHERE NAme = 'SubTransect') +) +AND +FK_ObservationDynProp = (SELECT ID FROM ObservationDynProp WHERE NAme = 'taxon') + + + +END +GO + +UPDATE ModuleForms SET Options = 204083 +WHERE TypeObj = 231 and name = 'taxon' + +GO + +INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('65_Migration_SubTransect',GETDATE(),(SELECT db_name())) + + +GO diff --git a/Back/ecoreleve_server/GenericObjets/FrontModules.py b/Back/ecoreleve_server/GenericObjets/FrontModules.py index 8165ba86a..6f7ef2446 100644 --- a/Back/ecoreleve_server/GenericObjets/FrontModules.py +++ b/Back/ecoreleve_server/GenericObjets/FrontModules.py @@ -107,7 +107,8 @@ def GetDTOFromConf(self,Editable): 'options': None, 'defaultValue' : None, 'editorAttrs' : {'disabled': isDisabled}, - 'fullPath':self.fullPath + 'fullPath':self.fullPath, + 'size':curSize } try : @@ -161,17 +162,23 @@ def InputSelect (self) : def InputLNM(self) : ''' build ListOfNestedModel input type : used for complex protocols and Fieldworkers in station form ''' if self.Options != None : + gridRanged = False result = self.session.query(ModuleForms).filter(and_(ModuleForms.TypeObj == self.Options , ModuleForms.Module_ID == self.Module_ID)).all() subNameObj = result[0].Name subschema = {} for conf in result : - subschema[conf.Name] = conf.GetDTOFromConf(self.Editable) + if conf.InputType == 'GridRanged': + gridRanged = conf.GetDTOFromConf(self.Editable) + confGridRanged = conf + subschema.update(gridRanged) + else : + subschema[conf.Name] = conf.GetDTOFromConf(self.Editable) fields = [] resultat = [] - Legends = sorted ([(obj.Legend,obj.FormOrder,obj.Name)for obj in result if obj.FormOrder is not None], key = lambda x : x[1]) + Legends = sorted ([(obj.Legend,obj.FormOrder,obj.Name) for obj in result if obj.FormOrder is not None and obj.InputType != 'GridRanged'], key = lambda x : x[1]) # Legend2s = sorted ([(obj.Legend)for obj in result if obj.FormOrder is not None ], key = lambda x : x[1]) - withOutLegends = sorted ([(obj.Legend,obj.FormOrder,obj.Name)for obj in result if obj.FormOrder is not None and obj.Legend is None ], key = lambda x : x[1]) + withOutLegends = sorted ([(obj.Legend,obj.FormOrder,obj.Name)for obj in result if obj.FormOrder is not None and obj.Legend is None and obj.InputType != 'GridRanged'], key = lambda x : x[1]) Unique_Legends = list() # Get distinct Fieldset in correct order @@ -187,6 +194,19 @@ def InputLNM(self) : curIndex = Unique_Legends.index(curProp[0]) resultat[curIndex]['fields'].append(curProp[2]) + if gridRanged : + curIndex = Unique_Legends.index(conf.Legend) + # resultat[curIndex]['fields'].pop(resultat[curIndex]['fields'].index(conf.Name)) + tupleList = [ (gridRanged[obj]['order'],gridRanged[obj]['name']) for obj in gridRanged] + l = sorted(tupleList,key = lambda x : x[0]) + + for order,name in l: + resultat[curIndex]['fields'].append(name) + + if 'fixedCol' in subschema[resultat[curIndex]['fields'][0]]['fieldClass'] : + rr = resultat[curIndex]['fields'].pop(0) + resultat[curIndex]['fields'].append(rr) + self.dto['fieldsets'] = resultat self.dto['subschema'] = subschema self.dto['nbByDefault'] = self.DefaultValue @@ -217,7 +237,42 @@ def InputAutocomplete(self): for row in result: self.dto['options']['source'].append(row[0]) self.dto['options']['iconFont'] = 'reneco reneco-autocomplete' - + + def GridRanged (self): + options = json.loads(self.Options) + self.dto = {} + if self.Editable: + isDisabled = False + curSize = self.FieldSizeEdit + else : + isDisabled = True + curSize = self.FieldSizeDisplay + + + CssClass = 'col-md-'+str(curSize) + addClass = '' + for i in range(options['range']): + if i == 0 : + addClass += 'firstCol' + else : + addClass = '' + curDTO = { + 'name': 'C'+str(i), + 'type': options['inputType'], + 'title' : options['prefixLabel']+str(i+1), + 'editable' : self.Editable, + 'editorClass' : str(self.editorClass) , + 'validators': [], + 'options': None, + 'defaultValue' : None, + 'editorAttrs' : {'disabled': isDisabled}, + 'defaultValue' : None, + 'fieldClass' : str(self.EditClass) + ' ' + CssClass+ ' '+ addClass, + 'order':i, + 'size':curSize + } + self.dto['C'+str(i)] = curDTO + func_type_context = { @@ -226,6 +281,7 @@ def InputAutocomplete(self): 'GridFormEditor' : InputLNM, 'AutocompTreeEditor' : InputThesaurus, 'AutocompleteEditor': InputAutocomplete, + 'GridRanged': GridRanged, } diff --git a/Back/ecoreleve_server/GenericObjets/ObjectTypeWithDynProp.py b/Back/ecoreleve_server/GenericObjets/ObjectTypeWithDynProp.py index 78aefd244..1e67c8197 100644 --- a/Back/ecoreleve_server/GenericObjets/ObjectTypeWithDynProp.py +++ b/Back/ecoreleve_server/GenericObjets/ObjectTypeWithDynProp.py @@ -46,7 +46,7 @@ def AddDynamicPropInSchemaDTO(self,SchemaDTO,FrontModules,DisplayMode): Fields = self.ObjContext.query(ModuleForms ).filter(ModuleForms.Module_ID == FrontModules.ID ).filter(or_(ModuleForms.TypeObj == self.ID, ModuleForms.TypeObj == None) - ).filter(ModuleForms.FormRender > 0).all() + ).filter(ModuleForms.FormRender > 0).filter(ModuleForms.InputType != 'GridRanged').all() for CurModuleForms in Fields : SchemaDTO[CurModuleForms.Name] = CurModuleForms.GetDTOFromConf(Editable) diff --git a/Back/ecoreleve_server/GenericObjets/ObjectWithDynProp.py b/Back/ecoreleve_server/GenericObjets/ObjectWithDynProp.py index b04fa6c71..ef4695f98 100644 --- a/Back/ecoreleve_server/GenericObjets/ObjectWithDynProp.py +++ b/Back/ecoreleve_server/GenericObjets/ObjectWithDynProp.py @@ -394,7 +394,6 @@ def linkedFieldDate(self): def updateLinkedField(self,useDate = None): if useDate is None: useDate = self.linkedFieldDate() - print('in dyn prop ') for linkProp in self.getLinkedField() : curPropName = linkProp['Name'] @@ -443,7 +442,7 @@ def getDefaultValue(self,resultat): defaultValues = {} recursive_level = resultat['recursive_level'] for key, value in resultat['schema'].items(): - if value['defaultValue'] is not None: + if 'defaultValue' in value and value['defaultValue'] is not None: defaultValues[key] = value['defaultValue'] if 'subschema' in value: temp = {'schema':value['subschema'],'defaultValues':{}, 'recursive_level':recursive_level+1} diff --git a/Back/ecoreleve_server/Models/Protocoles.py b/Back/ecoreleve_server/Models/Protocoles.py index b7d0ee6d9..c12e08a17 100644 --- a/Back/ecoreleve_server/Models/Protocoles.py +++ b/Back/ecoreleve_server/Models/Protocoles.py @@ -24,6 +24,7 @@ from datetime import datetime from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import relationship, backref +from ..utils.parseValue import isNumeric #-------------------------------------------------------------------------- class Observation(Base,ObjectWithDynProp): @@ -38,12 +39,13 @@ class Observation(Base,ObjectWithDynProp): FK_Individual = Column(Integer,ForeignKey('Individual.ID')) Observation_children = relationship("Observation", cascade="all, delete-orphan") + SubObservation_children = relationship("ObservationDynPropSubValue", cascade="all, delete-orphan") Equipment = relationship("Equipment", backref = 'Observation',cascade = "all, delete-orphan", uselist=False) Station = relationship("Station", back_populates = 'Observations') Individual = relationship('Individual') def __init__(self,**kwargs): - super().__init__(**kwargs) + Base.__init__(self,**kwargs) ObjectWithDynProp.__init__(self) @orm.reconstructor @@ -73,29 +75,10 @@ def linkedFieldDate(self): except : return datetime.now() - def UpdateFromJson(self,DTOObject,startDate = None): - super().UpdateFromJson(DTOObject,startDate) - self.updateLinkedField() @hybrid_property def Observation_childrens(self): if self.Observation_children is not None or self.Observation_children != []: - # subObsList = [] - # print(self.Observation_children) - # print(type(self.Observation_children)) - - # typeName = 'children' - # sub_ProtocoleType = None - # # print ('CHILDREN !!!!!!!!!!') ### Append flatdata to list of data for existing subProto - # typeName = self.Observation_children[0].GetType().Name - # for subObs in self.Observation_children: - # subObs.LoadNowValues() - # sub_ProtocoleType = subObs.GetType().ID - # subObsList.append(subObs.GetFlatObject()) - # # self.__setattr__(typeName, subObsList) - # # print('self.GetProperty(typeName)') - # # print(self.GetProperty(typeName)) - # return subObsList return True else: return [] @@ -104,20 +87,67 @@ def Observation_childrens(self): def Observation_childrens(self,listOfSubProtocols): listObs = [] if len(listOfSubProtocols) !=0 : + for curData in listOfSubProtocols : + if self.GetType().Status == 8 : + # if self.GetType().Name == 'Transects' : + subDictList = [] + for k,v in curData.items(): + subDict = {} + col = k + if isNumeric(v) and 'C' in k and isNumeric(col.split('C')[1]): + newRow = {k:v} + subDict['FieldName'] = k + subDict['valeur'] = v + # del curData[k] + subDictList.append(subDict) + curData['listOfSubObs'] = subDictList + if 'ID' in curData : subObs = list(filter(lambda x : x.ID==curData['ID'],self.Observation_children))[0] subObs.LoadNowValues() else : - subObs = Observation(FK_ProtocoleType = curData['FK_ProtocoleType'] - ,Parent_Observation=self.ID,FK_Station=self.FK_Station) + subObs = Observation(FK_ProtocoleType = curData['FK_ProtocoleType'] ,Parent_Observation=self.ID,FK_Station=self.FK_Station) subObs.init_on_load() + if subObs is not None: subObs.UpdateFromJson(curData) listObs.append(subObs) # self.deleteSubObs(listObs) self.Observation_children = listObs + @hybrid_property + def SubObservation_childrens(self): + dictToUpdate = {} + if self.SubObservation_children is not None or self.SubObservation_children != []: + for row in self.SubObservation_children: + dictToUpdate[row.FieldName] = row.ValueNumeric + return dictToUpdate + + @SubObservation_childrens.setter + def SubObservation_childrens(self,listOfSubObs): + listSubValues = [] + if len(listOfSubObs)>0 : + for curData in listOfSubObs : + if 'FK_Observation' in curData : + subObsValue = list(filter(lambda x : x.FK_Observation==curData['FK_Observation'] and x.FieldName == curData['FieldName'] + ,self.SubObservation_children))[0] + else : + subObsValue = ObservationDynPropSubValue(FK_Observation = self.ID) + + if subObsValue is not None: + subObsValue.ValueNumeric = curData['valeur'] + subObsValue.FieldName = curData['FieldName'] + listSubValues.append(subObsValue) + # self.deleteSubObs(listSubValues) + self.SubObservation_children = listSubValues + + def UpdateFromJson(self,DTOObject,startDate = None): + ObjectWithDynProp.UpdateFromJson(self,DTOObject,startDate) + if 'listOfSubObs' in DTOObject : + self.SubObservation_childrens = DTOObject['listOfSubObs'] + self.updateLinkedField() + def GetFlatObject(self,schema=None): result = super().GetFlatObject() subObsList = [] @@ -129,7 +159,10 @@ def GetFlatObject(self,schema=None): for subObs in self.Observation_children: subObs.LoadNowValues() sub_ProtocoleType = subObs.GetType().ID - subObsList.append(subObs.GetFlatObject()) + flatObs = subObs.GetFlatObject() + if len(subObs.SubObservation_children) > 0 : + flatObs.update(subObs.SubObservation_childrens) + subObsList.append(flatObs) result[typeName] = subObsList return result @@ -179,6 +212,16 @@ def init_on_load(self): ProtocoleType_ObservationDynProps = relationship('ProtocoleType_ObservationDynProp',backref='ProtocoleType') Observations = relationship('Observation',backref='ProtocoleType') + # def AddDynamicPropInSchemaDTO(self,SchemaDTO,FrontModules,DisplayMode) : + # ObjectTypeWithDynProp.AddDynamicPropInSchemaDTO(self,SchemaDTO,FrontModules,DisplayMode) + # print(self.Status) + # if self.Status == 8: + # print('inaddDYnpropSHEMA') + # Editable = (DisplayMode.lower() == 'edit') + # Field = self.ObjContext.query(ModuleForms).filter(ModuleForms.InputType == 'GridRanged').first() + + # SchemaDTO.update(Field.GetDTOFromConf(Editable)) + #-------------------------------------------------------------------------- class ProtocoleType_ObservationDynProp(Base): @@ -190,3 +233,13 @@ class ProtocoleType_ObservationDynProp(Base): FK_ProtocoleType = Column(Integer, ForeignKey('ProtocoleType.ID')) FK_ObservationDynProp = Column(Integer, ForeignKey('ObservationDynProp.ID')) + +class ObservationDynPropSubValue (Base): + + __tablename__ = 'ObservationDynPropSubValue' + + ID = Column(Integer,Sequence('ObservationDynPropSubValue__id_seq'), primary_key=True) + FieldName = Column(String(250)) + ValueNumeric = Column(Numeric(30,10)) + FK_Observation = Column(Integer, ForeignKey('Observation.ID')) + diff --git a/Back/ecoreleve_server/Views/protocols.py b/Back/ecoreleve_server/Views/protocols.py index c2429cb83..dd4596057 100644 --- a/Back/ecoreleve_server/Views/protocols.py +++ b/Back/ecoreleve_server/Views/protocols.py @@ -315,10 +315,10 @@ def getListofProtocolTypes (request): fieldActivityID = request.params['FieldActivityID'] join_table = join(ProtocoleType,FieldActivity_ProtocoleType,ProtocoleType.ID == FieldActivity_ProtocoleType.FK_ProtocoleType ) query = select([ProtocoleType.ID, ProtocoleType.Name] - ).where(and_(ProtocoleType.Status == 4 ,FieldActivity_ProtocoleType.FK_fieldActivity == fieldActivityID) + ).where(and_(or_(ProtocoleType.Status == 4,ProtocoleType.Status == 8),FieldActivity_ProtocoleType.FK_fieldActivity == fieldActivityID) ).select_from(join_table) else : - query = select([ProtocoleType.ID, ProtocoleType.Name]).where(ProtocoleType.Status == 4) + query = select([ProtocoleType.ID, ProtocoleType.Name]).where(or_(ProtocoleType.Status == 4,ProtocoleType.Status == 8)) result = session.execute(query).fetchall() res = [] diff --git a/Front/app/ns_modules/ns_bbfe/bbfe-gridForm.js b/Front/app/ns_modules/ns_bbfe/bbfe-gridForm.js index 26a03ff80..5f4b6f455 100644 --- a/Front/app/ns_modules/ns_bbfe/bbfe-gridForm.js +++ b/Front/app/ns_modules/ns_bbfe/bbfe-gridForm.js @@ -1,216 +1,228 @@ -define([ - 'jquery', - 'underscore', - 'backbone', - 'marionette', - 'backbone-forms', - - ], function ($, _, Backbone, Marionette, Form, List, tpl) { - - 'use strict'; - return Form.editors.GridFormEditor = Form.editors.Base.extend({ - events: { - 'click #addFormBtn' : 'addEmptyForm', - }, - initialize: function(options) { - - if (options.schema.validators.length) { - this.defaultRequired = true; - } else { - options.schema.validators.push('required'); - this.defaultRequired = false; - } - - Form.editors.Base.prototype.initialize.call(this, options); - - this.template = options.template || this.constructor.template; - this.options = options; - this.options.schema.fieldClass = 'col-xs-12'; - this.forms = []; - this.disabled = options.schema.editorAttrs.disabled; - - this.hidden = ''; - if(this.disabled) { - this.hidden = 'hidden'; - } - this.hasNestedForm = true; - - this.key = this.options.key; - this.nbByDefault = this.options.model.schema[this.key]['nbByDefault']; - - }, - //removeForm - deleteForm: function() { - - }, - - addEmptyForm: function() { - var mymodel = Backbone.Model.extend({ - defaults : this.options.schema.subschema.defaultValues - }); - - var model = new mymodel(); - //model.default = this.options.model.attributes[this.key]; - model.schema = this.options.schema.subschema; - model.fieldsets = this.options.schema.fieldsets; - this.addForm(model); - }, - - addForm: function(model){ - var _this = this; - var form = new Backbone.Form({ - model: model, - fieldsets: model.fieldsets, - schema: model.schema - }).render(); - - this.forms.push(form); - - if(!this.defaultRequired){ - form.$el.find('fieldset').append('\ -
\ - \ -
\ - '); - form.$el.find('button#remove').on('click', function() { - _this.$el.find('#formContainer').find(form.el).remove(); - var i = _this.forms.indexOf(form); - if (i > -1) { - _this.forms.splice(i, 1); - } - return; - }); - } - - - this.$el.find('#formContainer').append(form.el); - }, - - render: function() { - //Backbone.View.prototype.initialize.call(this, options); - var _this = this; - - var $el = $($.trim(this.template({ - hidden: this.hidden - }))); - this.setElement($el); - - - var data = this.options.model.attributes[this.key]; - - var model = new Backbone.Model(); - model.schema = this.options.schema.subschema; - - var size=0; - - var odrFields = this.options.schema.fieldsets[0].fields; - for (var i = odrFields.length - 1; i >= 0; i--) { - var col = model.schema[odrFields[i]]; - //sucks - var test = true; - if(col.fieldClass){ - test = !(col.fieldClass.split(' ')[0] == 'hide'); //FK_protocolType - col.fieldClass += ' grid-field'; - } - - if(col.title && test) { - this.$el.find('#th').prepend('
| ' + col.title + '
'); - size++; - } - } - - size = size*150; - size += 35; - - //this.$el.find('#th').prepend('
'); - // size += 35; - - - this.$el.find('#th').width(size); - this.$el.find('#formContainer').width(size); - - if (data) { - //data - if (data.length) { - for (var i = 0; i < data.length; i++) { - if(i >= this.nbByDefault) { - this.defaultRequired = false; - } - var model = new Backbone.Model(); - model.schema = this.options.schema.subschema; - model.fieldsets = this.options.schema.fieldsets; - model.attributes = data[i]; - this.addForm(model); - - }; - - if (data.length < this.nbByDefault) { - for (var i = 0; i < data.length; i++) { - this.addForm(model); - } - } - this.defaultRequired = false; - } - } else { - //no data - if (this.nbByDefault >= 1) { - for (var i = 0; i < this.nbByDefault; i++) { - this.addEmptyForm(); - } - this.defaultRequired = false; - } - } - - return this; - }, - - feedRequiredEmptyForms: function() { - - }, - - getValue: function() { - var errors = false; - for (var i = 0; i < this.forms.length; i++) { - if (this.forms[i].commit()) { - errors = true; - } - }; - if (errors) { - return false; - } else { - var values = []; - for (var i = 0; i < this.forms.length; i++) { - var tmp = this.forms[i].getValue(); - var empty = true; - for (var key in tmp) { - if(tmp[key]){ - empty = false; - } - } - if(!empty){ - /* if (this.defaultValue) { - tmp['FK_ProtocoleType'] = this.defaultValue; - }*/ - values[i] = tmp; - } - }; - return values; - } - - - }, - }, { - //STATICS - template: _.template('\ -
\ - \ -
\ -
\ -
\ -
\ -
\ - \ -
\ - ', null, Form.templateSettings), - }); +define([ + 'jquery', + 'underscore', + 'backbone', + 'marionette', + 'backbone-forms', + + ], function ($, _, Backbone, Marionette, Form, List, tpl) { + + 'use strict'; + return Form.editors.GridFormEditor = Form.editors.Base.extend({ + events: { + 'click #addFormBtn' : 'addEmptyForm', + }, + initialize: function(options) { + + if (options.schema.validators.length) { + this.defaultRequired = true; + } else { + options.schema.validators.push('required'); + this.defaultRequired = false; + } + + Form.editors.Base.prototype.initialize.call(this, options); + + this.template = options.template || this.constructor.template; + this.options = options; + this.options.schema.fieldClass = 'col-xs-12'; + this.forms = []; + this.disabled = options.schema.editorAttrs.disabled; + + this.hidden = ''; + if(this.disabled) { + this.hidden = 'hidden'; + } + this.hasNestedForm = true; + + this.key = this.options.key; + this.nbByDefault = this.options.model.schema[this.key]['nbByDefault']; + + }, + //removeForm + deleteForm: function() { + + }, + + addEmptyForm: function() { + var mymodel = Backbone.Model.extend({ + defaults : this.options.schema.subschema.defaultValues + }); + + var model = new mymodel(); + //model.default = this.options.model.attributes[this.key]; + model.schema = this.options.schema.subschema; + model.fieldsets = this.options.schema.fieldsets; + this.addForm(model); + }, + + addForm: function(model){ + var _this = this; + var form = new Backbone.Form({ + model: model, + fieldsets: model.fieldsets, + schema: model.schema + }).render(); + + this.forms.push(form); + + if(!this.defaultRequired){ + form.$el.find('fieldset').append('\ +
\ + \ +
\ + '); +/* form.$el.find('fieldset').prepend('\ +
\ + \ +
\ + ');*/ + form.$el.find('button#remove').on('click', function() { + _this.$el.find('#formContainer').find(form.el).remove(); + var i = _this.forms.indexOf(form); + if (i > -1) { + _this.forms.splice(i, 1); + } + return; + }); + } + + + this.$el.find('#formContainer').append(form.el); + }, + + render: function() { + //Backbone.View.prototype.initialize.call(this, options); + var _this = this; + + var $el = $($.trim(this.template({ + hidden: this.hidden + }))); + this.setElement($el); + + + var data = this.options.model.attributes[this.key]; + + var model = new Backbone.Model(); + model.schema = this.options.schema.subschema; + + var size=0; + + var odrFields = this.options.schema.fieldsets[0].fields; + for (var i = odrFields.length - 1; i >= 0; i--) { + var col = model.schema[odrFields[i]]; + //sucks + var test = true; + if(col.fieldClass){ + test = !(col.fieldClass.split(' ')[0] == 'hide'); //FK_protocolType + col.fieldClass += ' grid-field'; + } + + if(col.title && test) { + this.$el.find('#th').prepend('
| ' + col.title + '
'); + } + + + if ( col.size == null) { + size += 150; + } + else { + size += col.size*25; + } + + } + + size += 285; + + //this.$el.find('#th').prepend('
'); + // size += 35; + + + this.$el.find('#th').width(size); + this.$el.find('#formContainer').width(size); + + if (data) { + //data + if (data.length) { + for (var i = 0; i < data.length; i++) { + if(i >= this.nbByDefault) { + this.defaultRequired = false; + } + var model = new Backbone.Model(); + model.schema = this.options.schema.subschema; + model.fieldsets = this.options.schema.fieldsets; + model.attributes = data[i]; + this.addForm(model); + + }; + + if (data.length < this.nbByDefault) { + for (var i = 0; i < data.length; i++) { + this.addForm(model); + } + } + this.defaultRequired = false; + } + } else { + //no data + if (this.nbByDefault >= 1) { + for (var i = 0; i < this.nbByDefault; i++) { + this.addEmptyForm(); + } + this.defaultRequired = false; + } + } + + return this; + }, + + feedRequiredEmptyForms: function() { + + }, + + getValue: function() { + var errors = false; + for (var i = 0; i < this.forms.length; i++) { + if (this.forms[i].commit()) { + errors = true; + } + }; + if (errors) { + return false; + } else { + var values = []; + for (var i = 0; i < this.forms.length; i++) { + var tmp = this.forms[i].getValue(); + var empty = true; + for (var key in tmp) { + if(tmp[key]){ + empty = false; + } + } + if(!empty){ + /* if (this.defaultValue) { + tmp['FK_ProtocoleType'] = this.defaultValue; + }*/ + values[i] = tmp; + } + }; + return values; + } + + + }, + }, { + //STATICS + template: _.template('\ +
\ + \ +
\ +
\ +
\ +
\ +
\ + \ +
\ + ', null, Form.templateSettings), + }); }); \ No newline at end of file diff --git a/Front/app/styles/ui/_form.less b/Front/app/styles/ui/_form.less index 2c5279f01..fc56e42ca 100644 --- a/Front/app/styles/ui/_form.less +++ b/Front/app/styles/ui/_form.less @@ -183,7 +183,7 @@ select:disabled { } .expand-grid{ - padding-bottom: 200px; + padding-bottom: 50px; background: #ddd; & .fancytreeview{ max-height: 200px; @@ -296,6 +296,10 @@ Dans detail station, bloc "Detailled Infos", en mode edit : background: rgba(221, 221, 221, 0.3); } + &>.fixedCol{ + background: #eee; + } + /* input{ border-radius: 0px; @@ -381,6 +385,35 @@ Dans detail station, bloc "Detailled Infos", en mode edit : .solo-input10{ margin-right: 16.66666667%; } + + +.fixedCol { + position:absolute; + //z-index:1000; + +} + +#th&>.fixedCol {background: #ccc;} + + +.firstCol-6{ + margin-left : 150px !important; + +} + + +.firstCol-8{ + margin-left : 200px !important; + +} + +.col-md-3.grid-field{ + width: 75px; + } +.col-md-2.grid-field{ + width: 50px; +} + #stationForm textarea { height: 50px; max-height: 50px; @@ -388,4 +421,4 @@ Dans detail station, bloc "Detailled Infos", en mode edit : textarea { resize: none; } - +