Skip to content

Commit

Permalink
Merge pull request #280 from romfabbro/transect
Browse files Browse the repository at this point in the history
Transect
  • Loading branch information
FredericBerton authored Jun 10, 2016
2 parents 34146c0 + b2e9424 commit ec4f7e1
Show file tree
Hide file tree
Showing 9 changed files with 615 additions and 250 deletions.
89 changes: 89 additions & 0 deletions Back/database/Pipe/DB_Mother/064_Create_TransectForm.txt
Original file line number Diff line number Diff line change
@@ -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
123 changes: 123 additions & 0 deletions Back/database/Pipe/DB_Mother/065_Migration_SubTransect.txt
Original file line number Diff line number Diff line change
@@ -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
66 changes: 61 additions & 5 deletions Back/ecoreleve_server/GenericObjets/FrontModules.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def GetDTOFromConf(self,Editable):
'options': None,
'defaultValue' : None,
'editorAttrs' : {'disabled': isDisabled},
'fullPath':self.fullPath
'fullPath':self.fullPath,
'size':curSize
}

try :
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -226,6 +281,7 @@ def InputAutocomplete(self):
'GridFormEditor' : InputLNM,
'AutocompTreeEditor' : InputThesaurus,
'AutocompleteEditor': InputAutocomplete,
'GridRanged': GridRanged,
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions Back/ecoreleve_server/GenericObjets/ObjectWithDynProp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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}
Expand Down
Loading

0 comments on commit ec4f7e1

Please sign in to comment.