From 865c9aa77907be8a0a8bfd270771364cdd90843c Mon Sep 17 00:00:00 2001 From: iamsuvhro Date: Thu, 24 Feb 2022 15:20:46 +0530 Subject: [PATCH 1/6] Support many_to_many in connection types, multiple dbs support standard sqls -- updated --- .../migrations/0006_auto_20220224_0933.py | 23 +++++++++++++++++++ api/cueSearch/models.py | 5 ++-- 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 api/cueSearch/migrations/0006_auto_20220224_0933.py diff --git a/api/cueSearch/migrations/0006_auto_20220224_0933.py b/api/cueSearch/migrations/0006_auto_20220224_0933.py new file mode 100644 index 00000000..16f38d3b --- /dev/null +++ b/api/cueSearch/migrations/0006_auto_20220224_0933.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.5 on 2022-02-24 09:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dataset', '0001_initial'), + ('cueSearch', '0005_searchcardtemplate_connectiontype'), + ] + + operations = [ + migrations.RemoveField( + model_name='searchcardtemplate', + name='connectionType', + ), + migrations.AddField( + model_name='searchcardtemplate', + name='connectionType', + field=models.ManyToManyField(blank=True, null=True, to='dataset.ConnectionType'), + ), + ] diff --git a/api/cueSearch/models.py b/api/cueSearch/models.py index 075ddc3d..768bf5a1 100644 --- a/api/cueSearch/models.py +++ b/api/cueSearch/models.py @@ -26,9 +26,8 @@ def __str__(self): class SearchCardTemplate(models.Model): RENDER_TYPE_TABLE = "table" RENDER_TYPE_LINE = "line" - connectionType = models.ForeignKey( - ConnectionType, on_delete=models.SET_NULL, null=True, blank=True - ) + + connectionType = models.ManyToManyField(ConnectionType, null=True, blank=True) templateName = models.TextField(null=True, blank=True) title = models.TextField(null=True, blank=True) bodyText = models.TextField(null=True, blank=True) From 4baae266ecd9347578eb39b52af41bf43ec4d0d4 Mon Sep 17 00:00:00 2001 From: iamsuvhro Date: Fri, 25 Feb 2022 17:55:29 +0530 Subject: [PATCH 2/6] Many_to_many input type field updated in cardTemplate create & update api --- ...alter_searchcardtemplate_connectiontype.py | 19 ++++++++++++++++++ api/cueSearch/models.py | 2 +- api/cueSearch/services/cardTemplate.py | 20 +++++++++++++------ 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 api/cueSearch/migrations/0007_alter_searchcardtemplate_connectiontype.py diff --git a/api/cueSearch/migrations/0007_alter_searchcardtemplate_connectiontype.py b/api/cueSearch/migrations/0007_alter_searchcardtemplate_connectiontype.py new file mode 100644 index 00000000..c8f15f1f --- /dev/null +++ b/api/cueSearch/migrations/0007_alter_searchcardtemplate_connectiontype.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.5 on 2022-02-24 10:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dataset', '0001_initial'), + ('cueSearch', '0006_auto_20220224_0933'), + ] + + operations = [ + migrations.AlterField( + model_name='searchcardtemplate', + name='connectionType', + field=models.ManyToManyField(blank=True, to='dataset.ConnectionType'), + ), + ] diff --git a/api/cueSearch/models.py b/api/cueSearch/models.py index 768bf5a1..67e94ec7 100644 --- a/api/cueSearch/models.py +++ b/api/cueSearch/models.py @@ -27,7 +27,7 @@ class SearchCardTemplate(models.Model): RENDER_TYPE_TABLE = "table" RENDER_TYPE_LINE = "line" - connectionType = models.ManyToManyField(ConnectionType, null=True, blank=True) + connectionType = models.ManyToManyField(ConnectionType, blank=True) templateName = models.TextField(null=True, blank=True) title = models.TextField(null=True, blank=True) bodyText = models.TextField(null=True, blank=True) diff --git a/api/cueSearch/services/cardTemplate.py b/api/cueSearch/services/cardTemplate.py index ee85f0af..bda3bbbc 100644 --- a/api/cueSearch/services/cardTemplate.py +++ b/api/cueSearch/services/cardTemplate.py @@ -22,8 +22,6 @@ def createCardTemplate(payload: dict): """ try: res = ApiResponse("Error occur while creating search card template") - connectionTypeId = int(payload.get("connectionTypeId", 1)) - connectionType = ConnectionType.objects.get(id=connectionTypeId) renderType = payload.get("renderType", "table") templateName = payload.get("templateName", "") title = payload.get("title", "") @@ -36,8 +34,14 @@ def createCardTemplate(payload: dict): bodyText=bodyText, sql=sql, renderType=renderType, - connectionType=connectionType, ) + + connectionTypeId = list(payload.get("connectionTypeId")) + for id in connectionTypeId: + value = ConnectionType.objects.get(id=id) + cardTemplateObj.connectionType.add(value) + + res.update(True, "Search card template created successfully") except Exception as ex: logging.error("Error %s", str(ex)) @@ -64,8 +68,7 @@ def updateCardTemplate(templateId: int, payload: dict): """Method to update card template""" try: res = ApiResponse("Error while updating card template") - connectionTypeId = int(payload.get("connectionTypeId")) - connectionType = ConnectionType.objects.get(id=connectionTypeId) + renderType = payload.get("renderType", "table") templateName = payload.get("templateName", "") title = payload.get("title", "") @@ -79,8 +82,13 @@ def updateCardTemplate(templateId: int, payload: dict): templateObj.title = title templateObj.templateName = templateName templateObj.renderType = renderType - templateObj.connectionType = connectionType templateObj.save() + + connectionTypeId = list(payload.get("connectionTypeId")) + for id in connectionTypeId: + value = ConnectionType.objects.get(id=id) + templateObj.connectionType.add(value) + res.update(True, "Successfully updated template") except Exception as ex: logging.error("Error %s", str(ex)) From a1e3e6f1d60129e28b3a2b6a72e0083106737d8f Mon Sep 17 00:00:00 2001 From: iamsuvhro Date: Mon, 28 Feb 2022 09:58:42 +0530 Subject: [PATCH 3/6] Many to many field backend implemented --- api/cueSearch/models.py | 2 +- api/cueSearch/services/cardTemplate.py | 6 ++++-- api/seeddata/searchCardTemplate.json | 12 ++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/api/cueSearch/models.py b/api/cueSearch/models.py index 67e94ec7..f9cdbd6d 100644 --- a/api/cueSearch/models.py +++ b/api/cueSearch/models.py @@ -27,7 +27,7 @@ class SearchCardTemplate(models.Model): RENDER_TYPE_TABLE = "table" RENDER_TYPE_LINE = "line" - connectionType = models.ManyToManyField(ConnectionType, blank=True) + connectionType = models.ManyToManyField(ConnectionType, blank=True) #on_delete=models.SET_NULL templateName = models.TextField(null=True, blank=True) title = models.TextField(null=True, blank=True) bodyText = models.TextField(null=True, blank=True) diff --git a/api/cueSearch/services/cardTemplate.py b/api/cueSearch/services/cardTemplate.py index bda3bbbc..2e7970a3 100644 --- a/api/cueSearch/services/cardTemplate.py +++ b/api/cueSearch/services/cardTemplate.py @@ -40,7 +40,7 @@ def createCardTemplate(payload: dict): for id in connectionTypeId: value = ConnectionType.objects.get(id=id) cardTemplateObj.connectionType.add(value) - + res.update(True, "Search card template created successfully") except Exception as ex: @@ -83,12 +83,14 @@ def updateCardTemplate(templateId: int, payload: dict): templateObj.templateName = templateName templateObj.renderType = renderType templateObj.save() + + templateObj.objects.filter(id=templateId).update(connectionType=None) connectionTypeId = list(payload.get("connectionTypeId")) for id in connectionTypeId: value = ConnectionType.objects.get(id=id) templateObj.connectionType.add(value) - + res.update(True, "Successfully updated template") except Exception as ex: logging.error("Error %s", str(ex)) diff --git a/api/seeddata/searchCardTemplate.json b/api/seeddata/searchCardTemplate.json index bbb8758c..4bc5ab4e 100644 --- a/api/seeddata/searchCardTemplate.json +++ b/api/seeddata/searchCardTemplate.json @@ -9,7 +9,7 @@ "bodyText": "This table displays raw data for dataset {{dataset}} with filter {{filter}} ", "sql": "SELECT * FROM ({{ datasetSql|safe }}) WHERE {{filter|safe}} limit 500", "renderType": "table", - "connectionType": 6 + "connectionType": [6] } }, { @@ -22,7 +22,7 @@ "bodyText": "{% load event_tags %} {% for filterDim in filterDimensions %} {% conditionalCount searchResults 'dimension' filterDim as dimCount %} {% if dimCount > 1 %} {% for metricName in metrics %} This chart displays filtered values on dimension {{filterDim}} along with other filters applied i.e. {{filter|safe}} for metric {{metricName}} on dataset {{dataset}} +-; {% endfor %} {% endif %} {% endfor %}", "sql": "{% load event_tags %} {% for filterDim in filterDimensions %} {% conditionalCount searchResults 'dimension' filterDim as dimCount %} {% if dimCount > 1 %} {% for metricName in metrics %} SELECT ({{ timestampColumn }}), {{ filterDim }}, SUM({{ metricName }}) as {{metricName}} FROM ({{ datasetSql|safe }}) WHERE {{filter|safe}} GROUP BY 1, 2 limit 500 +-; {% endfor %} {% endif %} {% endfor %}", "renderType": "line", - "connectionType": 6 + "connectionType": [6] } }, { @@ -35,7 +35,7 @@ "bodyText": " {% for metric in metrics %} For {{filter}} +-; {% endfor %}", "sql": " {% for metric in metrics %} SELECT ({{ timestampColumn }}), SUM({{ metric }}) as {{ metric }} FROM ({{ datasetSql|safe }}) WHERE {{filter|safe}} GROUP BY 1 limit 500 +-; {% endfor %}", "renderType": "line", - "connectionType": 6 + "connectionType": [6] } }, { @@ -48,7 +48,7 @@ "bodyText": "This table displays raw data for dataset {{dataset}} with filter {{filter}} ", "sql": "SELECT * FROM ({{ datasetSql|safe }}) AS templatetable WHERE {% for orResults in groupedResultsForFilter %} {% for orResult in orResults %} \"templatetable\".\"{{ orResult.dimension }}\" = '{{ orResult.value }}' OR {% endfor %} True AND {% endfor %} True limit 500", "renderType": "table", - "connectionType": 1 + "connectionType": [1] } }, { @@ -61,7 +61,7 @@ "bodyText": "{% load event_tags %} {% for filterDim in filterDimensions %} {% conditionalCount searchResults 'dimension' filterDim as dimCount %} {% if dimCount > 1 %} {% for metricName in metrics %} This chart displays filtered values on dimension {{filterDim}} along with other filters applied i.e. {{filter|safe}} for metric {{metricName}} on dataset {{dataset}} +-; {% endfor %} {% endif %} {% endfor %}", "sql": "{% load event_tags %} {% for filterDim in filterDimensions %} {% conditionalCount searchResults 'dimension' filterDim as dimCount %} {% if dimCount > 1 %} {% for metricName in metrics %} SELECT \"templatetable\".\"{{ timestampColumn }}\", \"templatetable\".\"{{ filterDim }}\", SUM(\"templatetable\".\"{{ metricName }}\") as {{metricName}} FROM ({{ datasetSql|safe }}) AS templatetable WHERE {% for orResults in groupedResultsForFilter %} {% for orResult in orResults %} \"templatetable\".\"{{ orResult.dimension }}\" = '{{ orResult.value }}' OR {% endfor %} True AND {% endfor %} True GROUP BY 1, 2 limit 500 +-; {% endfor %} {% endif %} {% endfor %}", "renderType": "line", - "connectionType": 1 + "connectionType": [1] } }, { @@ -74,7 +74,7 @@ "bodyText": " {% for metric in metrics %} For {{filter}} +-; {% endfor %}", "sql": " {% for metric in metrics %} SELECT \"templatetable\".\"{{ timestampColumn }}\", SUM(\"templatetable\".\"{{ metric }}\") as {{ metric }} FROM ({{ datasetSql|safe }}) AS templatetable WHERE {% for orResults in groupedResultsForFilter %} {% for orResult in orResults %} \"templatetable\".\"{{ orResult.dimension }}\" = '{{ orResult.value }}' OR {% endfor %} True AND {% endfor %} True GROUP BY 1 limit 500 +-; {% endfor %}", "renderType": "line", - "connectionType": 1 + "connectionType": [1] } } ] \ No newline at end of file From f4c1229c166a7e5078cb6588d743480f15d45cd2 Mon Sep 17 00:00:00 2001 From: iamsuvhro Date: Mon, 28 Feb 2022 16:20:35 +0530 Subject: [PATCH 4/6] delete implemented in update cardTemplate api --- api/cueSearch/services/cardTemplate.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/cueSearch/services/cardTemplate.py b/api/cueSearch/services/cardTemplate.py index 2e7970a3..81bde41c 100644 --- a/api/cueSearch/services/cardTemplate.py +++ b/api/cueSearch/services/cardTemplate.py @@ -83,14 +83,19 @@ def updateCardTemplate(templateId: int, payload: dict): templateObj.templateName = templateName templateObj.renderType = renderType templateObj.save() - - templateObj.objects.filter(id=templateId).update(connectionType=None) + + oldConnTypeId = templateObj.connectionType.values() + + for item in oldConnTypeId: + connId = item['id'] + templateObj.connectionType.remove(connId,None) connectionTypeId = list(payload.get("connectionTypeId")) for id in connectionTypeId: value = ConnectionType.objects.get(id=id) templateObj.connectionType.add(value) + res.update(True, "Successfully updated template") except Exception as ex: logging.error("Error %s", str(ex)) From 5ca42efd9d8849b5bd5e45df53b66dc55238ece4 Mon Sep 17 00:00:00 2001 From: iamsuvhro Date: Mon, 28 Feb 2022 18:46:33 +0530 Subject: [PATCH 5/6] Serializer issue fixed --- api/cueSearch/serializers.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/api/cueSearch/serializers.py b/api/cueSearch/serializers.py index af0c799c..54e1345f 100644 --- a/api/cueSearch/serializers.py +++ b/api/cueSearch/serializers.py @@ -2,7 +2,7 @@ from rest_framework import serializers from dataset.models import ConnectionType, Dataset from cueSearch.models import GlobalDimension, SearchCardTemplate - +from dataset.serializers import ConnectionTypeSerializer class AllDimensionsSerializer(serializers.ModelSerializer): """ @@ -81,18 +81,9 @@ class Meta: class SearchCardTemplateSerializer(serializers.ModelSerializer): """Serializers for get Search card template""" - connectionTypeName = serializers.SerializerMethodField() - connectionTypeId = serializers.SerializerMethodField() - - def get_connectionTypeName(self, obj): - name = "" - if obj.connectionType: - name = obj.connectionType.name - return name + connectionTypeName = ConnectionTypeSerializer(many=True, read_only=True) + connectionTypeId = ConnectionTypeSerializer(many=True, read_only=True) - def get_connectionTypeId(self, obj): - if obj.connectionType: - return obj.connectionType.id class Meta: model = SearchCardTemplate From fc972a50ee8de3cefbe2eeeadf4449e94469cc0c Mon Sep 17 00:00:00 2001 From: iamsuvhro Date: Wed, 2 Mar 2022 11:25:42 +0530 Subject: [PATCH 6/6] Multiple connection type added in UI --- ui/src/components/Search/CardTemplates/AddCardTemplates.js | 5 ++++- ui/src/components/Search/CardTemplates/EditCardTemplates.js | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/src/components/Search/CardTemplates/AddCardTemplates.js b/ui/src/components/Search/CardTemplates/AddCardTemplates.js index 7c9f7ad3..cebf9801 100644 --- a/ui/src/components/Search/CardTemplates/AddCardTemplates.js +++ b/ui/src/components/Search/CardTemplates/AddCardTemplates.js @@ -14,7 +14,7 @@ const { Option } = Select; export default function AddCardTemplates(props) { const [form] = Form.useForm(); const [renderType, setRenderType] = useState("table"); - const [connectionType, setConnectionType] = useState(); + const [connectionType, setConnectionType] = useState([]); useEffect(() => { getConnectionType(); }, []); @@ -32,6 +32,7 @@ export default function AddCardTemplates(props) { const addCardTemplateFormSubmit = async (values) => { let payload = {}; let connType = values["connectionType"].split("."); + console.log(connType); payload["connectionTypeId"] = connType[0]; payload["connectionTypeName"] = connType[1]; payload["templateName"] = values["templateName"]; @@ -164,6 +165,8 @@ export default function AddCardTemplates(props) { ]} >