Commit 93b0c18b authored by harshavardhan.c's avatar harshavardhan.c

Added new services for support lens dashboard

parent 1c975cab
......@@ -16,9 +16,12 @@ class Endpoints:
save_support_case = base_url + "/support_case/create"
fetch_support_case = base_url + "/support_case/fetch"
delete_support_case = base_url + "/support_case/delete"
delete_case_details = base_url + "/support_case/delete"
resolve_case_details = base_url + "/support_case/resolve"
close_case_details = base_url + "/support_case/close"
edit_support_case = base_url + "/support_case/edit"
get_support_case_table_details = base_url + "/support_case/fetch_table"
get_dashboard_details = base_url + "/support_case/get_dashboard_details"
class DBMapping:
......@@ -39,7 +42,12 @@ class DBMapping:
class CaseStatus:
OPEN = "open"
DELETE = "delete"
DELETED = "deleted"
CLOSED = "closed"
REPLIED = "replied"
RESOLVED = "resolved"
RE_ASSIGNED = "re_assigned"
ASSIGNED = "assigned"
class StatusMessages:
......@@ -58,6 +66,8 @@ class StatusMessages:
SUPPORTCASE_SAVE = "Failed to save support case details"
SUPPORTCASE_FETCH = "Failed to fetch support case details"
SUPPORTCASE_DASHBOARD = "Failed to fetch dashboard details"
SUPPORTCASE = "Failed to update case details"
class StaticJsons:
......@@ -95,8 +105,8 @@ class StaticJsons:
]
SUPPORTLENS_FETCHTABLE_HEADERCONTENT = [
{
"value": "case_number",
"label": "case Number",
"value": "case_id",
"label": "Case Number",
"enable_column_search": True,
"header_type": "text"
},
......@@ -107,18 +117,19 @@ class StaticJsons:
"header_type": "text"
},
{
"value": "customer_project_id",
"value": "ProjectName",
"label": "Customer Project ID",
"enable_column_search": True,
"header_type": "text"
},
{
"value": "status",
"label": "Status",
"enable_column_search": True,
"header_type": "select",
"options": []
},
# {
# "value": "status",
# "label": "Status",
# "enable_column_search": True,
# "header_type": "select",
# "options": [],
# "hidden": True
# },
{
"value": "created_by",
"label": "Created By",
......@@ -127,7 +138,7 @@ class StaticJsons:
"options": []
},
{
"value": "last_updated",
"value": "last_updated_on",
"label": "Last Updated",
"enable_column_search": True,
"header_type": "date_range"
......@@ -159,6 +170,110 @@ class StaticJsons:
]
}
SUPPORTLENS_HEADER_CONTENT = {"support_lens_table_header_content": [
{
"key": "open",
"label": "Open",
"svgName": 'open.svg',
"count": 0,
"className": "w-20",
},
{
"key": "replied",
"label": "Replied",
"count": 0,
"svgName": 'replied-yet-to-assign.svg',
"className": "w-20",
},
{
"key": "assigned",
"label": "Assigned",
"count": 0,
"svgName": 'assigned.svg',
"className": "w-20",
},
{
"key": "re_assigned",
"label": "Re-Assigned",
"count": 0,
"svgName": 're-assigned.svg',
"className": "w-20",
},
{
"key": "resolved",
"label": "Resolved",
"count": 0,
"svgName": 'resolved.svg',
"className": "w-20",
},
{
"key": "deleted",
"label": "Deleted",
"count": 0,
"svgName": 'deleted.svg',
"className": "w-20 mr-1",
},
{
"key": "closed",
"label": "Closed",
"count": 0,
"svgName": 'closed.svg',
"className": "w-20 mr-1",
}
],
"support_lens_dashboard_header_content":
[
{
"key": "open",
"label": "OPEN CASES",
"count": 0,
"valueColor": "#484848",
"iconStyle": {"color": '#F44336'},
"svgName": 'open.svg'
},
{
"key": "replied",
"label": "REPLIED/ YET TO ASSIGN",
"count": 0,
"valueColor": "#484848",
"iconStyle": {'color': '#FFC107'},
"svgName": 'replied-yet-to-assign.svg'
},
{
"key": "assigned",
"label": "ASSIGNED CASES",
"count": 0,
"valueColor": "#484848",
"iconStyle": {'color': '#03A9F4'},
"svgName": 'assigned.svg'
},
{
"key": "re_assigned",
"label": "RE-ASSIGNED CASES",
"count": 0,
"valueColor": "#484848",
"iconStyle": {'color': '#3F51B5'},
"svgName": 're-assigned.svg'
},
{
"key": "resolved",
"label": "RESOLVED CASES",
"count": 0,
"valueColor": "#484848",
"iconStyle": {'color': '#4CAF50'},
"svgName": 'resolved.svg'
}
],
"support_lens_chart_header_content":
[
{"count": 0, "name": 'OPEN CASES', "itemStyle": {"color": '#EF5350'}, "key": "open"},
{"count": 0, "name": 'REPLIED/ YET TO ASSIGN', "itemStyle": {"color": '#FFCA28'}, "key": "replied"},
{"count": 0, "name": 'ASSIGNED CASES', "itemStyle": {"color": '#29B6F6'}, "key": "assigned"},
{"count": 0, "name": 'RE-ASSIGNED CASES', "itemStyle": {"color": '#5C6BC0'}, "key": "re_assigned"},
{"count": 0, "name": 'RESOLVED CASES', "itemStyle": {"color": '#66BB6A'}, "key": "resolved"},
]
}
class MongoEncryptionConstants:
......
......@@ -118,7 +118,7 @@ class ResolverSetupHandler:
collection_name=DBMapping.resolver_configuration,
set_json=record, query=query_json)
final_json = dict(status=StatusMessages.SUCCESS, message="Category saved Successfully")
final_json = dict(status=StatusMessages.SUCCESS, message="Resolver data saved Successfully")
except Exception as e:
logger.debug("Exception occurred while saving category data" + str(e))
return final_json
......@@ -165,7 +165,7 @@ class ResolverSetupHandler:
self.mongo_obj.delete_one_record(db_name=DBMapping.support_lens_configuration,
collection_name=DBMapping.resolver_configuration,
query_json=query_json)
final_json = dict(status=StatusMessages.SUCCESS, message="Resolved deleted Successfully")
final_json = dict(status=StatusMessages.SUCCESS, message="Resolver data deleted Successfully")
except Exception as e:
logger.debug("Exception occurred while deleting Resolver data" + str(e))
return final_json
......
......@@ -108,7 +108,7 @@ class TicketSetupHandler:
user_data = self.mongo_obj.find_one(db_name=DBMapping.ilens_configuration,
collection_name=DBMapping.user,
query={"user_id": user["user_id"]})
user = dict(userName=user_data["username"], user_id=user)
user = dict(userName=user_data["username"], user_id=user.get("user_id"))
if input_json["type"] == "create":
case_id = "case_" + self.new_id.get_next_id("case")
else:
......@@ -167,10 +167,17 @@ class TicketSetupHandler:
last_updated_by=user,
user_details=input_json["contacts"]
)
if "model" in input_json:
if input_json["model"].lower() == "view":
case_data.update(comments=input_json.get("comments"),
assigned_to=input_json.get("assign"),
case_status=input_json.get("status"),
emailIds=input_json.get("email"),
phoneNumbers=input_json["phoneNumber"])
self.mongo_obj.update_one(db_name=DBMapping.support_lens_configuration,
collection_name=DBMapping.ticket_configuration,
set_json=case_data, query=query_json)
final_json = dict(status=StatusMessages.SUCCESS, message="Casedata saved successfully")
final_json = dict(status=StatusMessages.SUCCESS, message="Case data saved successfully")
except Exception as e:
logger.exception("Exception while saving ticket data" + str(e))
return final_json
......@@ -222,6 +229,25 @@ class TicketSetupHandler:
def fetch_ticket_details(self, input_json):
final_json = dict(status=StatusMessages.FAILED, message=StatusMessages.FAILED, data=list())
try:
query_json = {
'_id': 0,
'category': "$category_id",
'subCategory': '$sub_category_id',
'site': '$site_id',
'subject': "$subject",
'fileNameBlock': '$file_details',
'description': '$Description',
'contacts': '$user_details',
}
if "model" in input_json:
if input_json["model"].lower() == "view":
query_json.update({
"status": "$case_status",
"assign": "$assigned_to",
"comments": "$comments",
"phoneNumber": "$phoneNumbers",
"email": "$emailIds"
})
response_data = list(self.mongo_obj.aggregate(
db_name=DBMapping.support_lens_configuration,
collection_name=DBMapping.ticket_configuration,
......@@ -231,18 +257,10 @@ class TicketSetupHandler:
'case_id': input_json["case_id"]
}
}, {
'$project': {
'_id': 0,
'category': "$category_id",
'subCategory': '$sub_category_id',
'site': '$site_id',
'subject': "$subject",
'fileNameBlock': '$file_details',
'description': '$Description',
'contacts': '$user_details',
}
'$project': query_json
}
]))
if len(response_data):
response_data = response_data[0]
final_json = dict(status=StatusMessages.SUCCESS, message=StatusMessages.SUCCESS,
......@@ -252,55 +270,188 @@ class TicketSetupHandler:
logger.exception("Exception while fetching case details" + str(e))
return final_json
def delete_case_details(self, input_json):
def delete_support_case_details(self, input_json):
try:
if "case_id" in input_json and input_json["case_id"] != "":
query = {"case_id": input_json["case_id"]}
new_values = {"$set": {"case_status": CaseStatus.DELETE}}
ConnectionObj.mongo_connection_obj.update_one(db_name=DBMapping.support_lens_configuration,
collection_name=DBMapping.ticket_configuration,
query=query, set_json=new_values)
response = self.update_case_status(case_id=input_json["case_id"], status_value=CaseStatus.DELETED)
return {"status": "success", "message": "Case deleted successfully"}
except Exception as e:
logger.exception(str(e))
return {"status": "failed", "message": str(e)}
def get_support_case_table_details(self, input_json):
def resolve_support_case_details(self, input_json):
try:
response = self.update_case_status(case_id=input_json["case_id"], status_value=CaseStatus.RESOLVED)
return {"status": "success", "message": "Case resolved successfully"}
except Exception as e:
logger.exception(str(e))
return {"status": "failed", "message": str(e)}
def close_case_details(self, input_json):
try:
final_json = dict(status=StatusMessages.FAILED, message=StatusMessages.FAILED,
data=dict(tableData=dict(headerContent=StaticJsons.SUPPORTLENS_FETCHTABLE_HEADERCONTENT),
tableActions=StaticJsons.SUPPORTLENS_FETCHTABLE_TABLEACTIONS,
enableRowExpand=True, table_type="infinite_scroll", hideSearch=True, server_search=True))
response = self.update_case_status(case_id=input_json["case_id"], status_value=CaseStatus.CLOSED)
return {"status": "success", "message": "Case closed successfully"}
except Exception as e:
logger.exception(str(e))
return {"status": "failed", "message": str(e)}
@staticmethod
def update_case_status(case_id, status_value):
try:
query = {"case_id": case_id}
new_values = {"$set": {"case_status": status_value}}
ConnectionObj.mongo_connection_obj.update_one(db_name=DBMapping.support_lens_configuration,
collection_name=DBMapping.ticket_configuration,
query=query, set_json=new_values)
return True
except Exception as e:
logger.error(f"Exception occurred while updating case status {str(e)}", exc_info=True)
return False
def get_support_case_table_details(self, input_json):
final_json = dict(status=StatusMessages.FAILED, message=StatusMessages.FAILED,
data=dict(tableData=dict(headerContent=StaticJsons.SUPPORTLENS_FETCHTABLE_HEADERCONTENT),
tableActions=StaticJsons.SUPPORTLENS_FETCHTABLE_TABLEACTIONS,
enableRowExpand=True, table_type="infinite_scroll", hideSearch=True,
server_search=True))
try:
json_data = [
{
'$match': {
'project_id': input_json["project_id"],
'case_status': input_json["tab_name"]
}
}, {
'$project': {
'_id': 0,
'case_id': '$case_id',
'status': '$case_status',
"subject": '$subject',
"ProjectName": "$ProjectName",
'last_updated_on': '$last_updated_on',
'created_by': '$created_by'
}
},
{
'$limit': input_json["records"]
},
{
'$skip': int(input_json["records"]) * (int(input_json["page"]) - 1)
}
]
if input_json["filters"]:
for key, value in input_json["filters"].items():
if value not in ["", None, str()]:
if key == "created_by":
json_data[0]["$match"].update(
{f"{key}.userName": {"$regex": f"{value}", '$options': "i"}})
elif key == "last_updated_on":
json_data[0]["$match"].update(
{key: {"$gte": value[0] / 1000, '$lte': value[-1] / 1000}})
else:
json_data[0]["$match"].update(
{key: {"$regex": f"{value}", '$options': "i"}})
records = list(self.mongo_obj.aggregate(
db_name=DBMapping.support_lens_configuration,
collection_name=DBMapping.ticket_configuration,
list_for_aggregation=[
{
'$match': {
'project_id': input_json["project_id"]
}
}, {
'$project': {
'_id': 0,
'case_number': '$case_id',
'status': '$case_status',
"subject": '$subject',
"customer_project_id": "$ProjectName",
'last_updated': '$last_updated_on',
'created_by': '$created_by'
}
}
]))
list_for_aggregation=json_data))
json_data.pop(3)
json_data.pop(2)
total_records = list(self.mongo_obj.aggregate(
db_name=DBMapping.support_lens_configuration,
collection_name=DBMapping.ticket_configuration,
list_for_aggregation=json_data))
users_list = list()
for record in records:
record["created_by"] = record["created_by"]["userName"]
record["last_updated"] = datetime.fromtimestamp(record["last_updated"]).strftime("%d %b %Y,%H:%M")
record["created_by"] = record["created_by"]["userName"].replace("_", " ").replace("-", " ").title()
record["last_updated_on"] = datetime.fromtimestamp(record["last_updated_on"]).strftime("%d %b %Y,%H:%M")
record["expandData"] = [{"label": str(key).replace("_", " ").replace("-", " ").title(), "value": value}
for key, value in record.items()]
if record["created_by"] not in users_list:
users_list.append(record["created_by"])
users_data = deepcopy(final_json["data"]["tableData"]["headerContent"][-2])
users_data["options"] = [{"label": str(user).replace("_", " ").replace("-", " ").title(), "value": user}
for user in users_list]
final_json["data"]["tableData"]["headerContent"][-2] = deepcopy(users_data)
final_json.update(status=StatusMessages.SUCCESS, message=StatusMessages.SUCCESS)
final_json["data"]["tableData"].update(bodyContent=deepcopy(records))
final_json["data"]["total_no"] = len(records)
final_json["data"]["total_no"] = len(total_records)
if len(total_records) >= (int(input_json["records"]) * int(input_json["page"])):
final_json["end_of_records"] = True
else:
final_json["end_of_records"] = False
if input_json["enable_tab"]:
final_json["tab_count"] = self.get_case_count_details(input_json=input_json,
filter_value="support_lens_table_header_content")
except Exception as e:
logger.exception(str(e))
return final_json
def get_dashboard_details(self, input_json):
final_json = dict(status=StatusMessages.FAILED, message=StatusMessages.FAILED, data=dict())
try:
final_json["data"]["caseStatus"] = self.get_case_count_details(input_json=input_json,
filter_value="support_lens_dashboard_header_content")
final_json["data"]["chartData"] = self.get_chart_details(input_json)
final_json.update(status="success", message="success")
except Exception as e:
logger.exception(str(e))
return final_json
def get_chart_details(self, input_json):
try:
chart_json = self.get_case_count_details(input_json=input_json,
filter_value="support_lens_chart_header_content")
total_count = 0
for chart in chart_json:
chart["value"] = chart.pop("count")
total_count += chart["value"]
for data in chart_json:
data["percentage"] = f"{round(float((data['value'] / total_count) * 100), 2)}%"
return chart_json
except Exception as e:
logger.exception(str(e))
return dict()
def get_case_count_details(self, input_json, filter_value):
final_json = dict(status=StatusMessages.SUCCESS, message=StatusMessages.SUCCESS, data=dict())
count_json_header_content = deepcopy(StaticJsons.SUPPORTLENS_HEADER_CONTENT[filter_value])
try:
json_data = [
{
'$match': {
'project_id': input_json["project_id"]
}
},
{
"$group":
{
"_id": "$" + "case_status",
"totalCount": {"$sum": 1}
}
}
]
count_json = {CaseStatus.DELETED: 0,
CaseStatus.OPEN: 0,
CaseStatus.CLOSED: 0,
CaseStatus.RESOLVED: 0,
CaseStatus.REPLIED: 0,
CaseStatus.ASSIGNED: 0,
CaseStatus.RE_ASSIGNED: 0
}
case_data = self.mongo_obj.aggregate_query(json_data=json_data,
database_name=DBMapping.support_lens_configuration,
collection_name=DBMapping.ticket_configuration)
for each_case in case_data:
count_json.update({each_case["_id"]: each_case["totalCount"]})
for header in count_json_header_content:
if header["key"] in count_json:
header["count"] = count_json[header["key"]]
final_json["data"] = deepcopy(count_json_header_content)
except Exception as e:
logger.exception(str(e))
return final_json["data"]
......@@ -35,28 +35,64 @@ def fetch_support_case_details():
return final_json
@supportcase_setup_configuration.route(Endpoints.delete_support_case, methods=['POST'])
@supportcase_setup_configuration.route(Endpoints.delete_case_details, methods=['POST'])
@apply_encryption
def delete_support_case_details():
final_json = {"status": StatusMessages.FAILED, "message": StatusMessages.SUPPORTCASE_SAVE}
def delete_case_details():
final_json = {"status": StatusMessages.FAILED, "message": StatusMessages.SUPPORTCASE}
try:
input_data = request.data
# input_data = request.get_json()
final_json = handler_obj.delete_case_details(input_data)
final_json = handler_obj.delete_support_case_details(input_data)
except Exception as e:
logger.exception("Exception -> %s" % str(e))
return final_json
@supportcase_setup_configuration.route(Endpoints.resolve_case_details, methods=['POST'])
@apply_encryption
def resolve_case_details():
final_json = {"status": StatusMessages.FAILED, "message": StatusMessages.SUPPORTCASE}
try:
input_data = request.data
# input_data = request.get_json()
final_json = handler_obj.resolve_support_case_details(input_data)
except Exception as e:
logger.exception("Exception -> %s" % str(e))
return final_json
@supportcase_setup_configuration.route(Endpoints.close_case_details, methods=['POST'])
@apply_encryption
def close_case_details():
final_json = {"status": StatusMessages.FAILED, "message": StatusMessages.SUPPORTCASE}
try:
input_data = request.data
# input_data = request.get_json()
final_json = handler_obj.close_case_details(input_data)
except Exception as e:
logger.exception("Exception -> %s" % str(e))
return final_json
@supportcase_setup_configuration.route(Endpoints.get_support_case_table_details, methods=['POST'])
@apply_encryption
def get_support_case_table_details():
final_json = {"status": StatusMessages.FAILED, "message": StatusMessages.SUPPORTCASE_SAVE}
final_json = {"status": StatusMessages.FAILED, "message": StatusMessages.SUPPORTCASE_FETCH}
try:
input_data = request.data
# input_data = request.get_json()
final_json = handler_obj.get_support_case_table_details(input_data)
except Exception as e:
logger.exception("Exception -> %s" % str(e))
return final_json
\ No newline at end of file
return final_json
@supportcase_setup_configuration.route(Endpoints.get_dashboard_details, methods=['POST'])
@apply_encryption
def get_dashboard_details():
final_json = {"status": StatusMessages.FAILED, "message": StatusMessages.SUPPORTCASE_DASHBOARD}
try:
input_data = request.data
# input_data = request.get_json()
final_json = handler_obj.get_dashboard_details(input_data)
except Exception as e:
logger.exception("Exception -> %s" % str(e))
return final_json
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment