Skip to content

Commit

Permalink
Merge pull request #50 from stat-kwon/master
Browse files Browse the repository at this point in the history
Add display_info variable in dashboard object
  • Loading branch information
stat-kwon authored Mar 5, 2024
2 parents 1a82bc7 + a1fe6c6 commit dc4a808
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/spaceone/dashboard/info/private_dashboard_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def PrivateDashboardInfo(dashboard_vo: PrivateDashboard, minimal=False):
"private_dashboard_id": dashboard_vo.private_dashboard_id,
"name": dashboard_vo.name,
"version": dashboard_vo.version,
"display_info": change_struct_type(dashboard_vo.display_info),
"labels": change_list_value_type(dashboard_vo.labels),
"user_id": dashboard_vo.user_id,
"workspace_id": dashboard_vo.workspace_id,
Expand Down
1 change: 1 addition & 0 deletions src/spaceone/dashboard/info/public_dashboard_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def PublicDashboardInfo(dashboard_vo: PublicDashboard, minimal=False):
"public_dashboard_id": dashboard_vo.public_dashboard_id,
"name": dashboard_vo.name,
"version": dashboard_vo.version,
"display_info": change_struct_type(dashboard_vo.display_info),
"labels": change_list_value_type(dashboard_vo.labels),
"resource_group": dashboard_vo.resource_group,
"project_id": dashboard_vo.project_id,
Expand Down
6 changes: 0 additions & 6 deletions src/spaceone/dashboard/manager/private_dashboard_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ def _rollback(vo: PrivateDashboard) -> None:

return dashboard_vo

def update_private_dashboard(self, params: dict) -> PrivateDashboard:
dashboard_vo: PrivateDashboard = self.get_private_dashboard(
params["private_dashboard_id"], params["workspace_id"], params["domain_id"]
)
return self.update_private_dashboard_by_vo(params, dashboard_vo)

def update_private_dashboard_by_vo(
self, params: dict, dashboard_vo: PrivateDashboard
) -> PrivateDashboard:
Expand Down
6 changes: 0 additions & 6 deletions src/spaceone/dashboard/manager/public_dashboard_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ def _rollback(vo: PublicDashboard) -> None:

return dashboard_vo

def update_public_dashboard(self, params: dict) -> PublicDashboard:
dashboard_vo: PublicDashboard = self.get_public_dashboard(
params["public_dashboard_id"], params["domain_id"]
)
return self.update_public_dashboard_by_vo(params, dashboard_vo)

def update_public_dashboard_by_vo(
self, params: dict, dashboard_vo: PublicDashboard
) -> PublicDashboard:
Expand Down
3 changes: 3 additions & 0 deletions src/spaceone/dashboard/model/private_dashboard_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PrivateDashboard(MongoModel):
variables = DictField(default={})
settings = DictField(default={})
variables_schema = DictField(default={})
display_info = DictField(default={})
labels = ListField(StringField())
tags = DictField(default={})
user_id = StringField(max_length=40)
Expand All @@ -29,13 +30,15 @@ class PrivateDashboard(MongoModel):
"variables",
"settings",
"variables_schema",
"display_info",
"labels",
"tags",
],
"minimal_fields": [
"private_dashboard_id",
"name",
"version",
"display_info",
"user_id",
"workspace_id",
"domain_id",
Expand Down
3 changes: 3 additions & 0 deletions src/spaceone/dashboard/model/public_dashboard_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PublicDashboard(MongoModel):
variables = DictField(default={})
settings = DictField(default={})
variables_schema = DictField(default={})
display_info = DictField(default={})
labels = ListField(StringField())
tags = DictField(default={})
resource_group = StringField(
Expand All @@ -32,13 +33,15 @@ class PublicDashboard(MongoModel):
"variables",
"settings",
"variables_schema",
"display_info",
"labels",
"tags",
],
"minimal_fields": [
"public_dashboard_id",
"name",
"version",
"display_info",
"resource_group",
"project_id",
"workspace_id",
Expand Down
17 changes: 11 additions & 6 deletions src/spaceone/dashboard/service/private_dashboard_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ def update(self, params):
params["name"] = dashboard_vo.name

if "settings" in params:
params["settings"] = self._merge_settings(
params["settings"] = self._merge_dict(
dashboard_vo.settings, params["settings"]
)

if "display_info" in params:
params["display_info"] = self._merge_dict(
dashboard_vo.display_info, params["display_info"]
)

version_change_keys = ["layouts", "variables", "variables_schema"]
if self._has_version_key_in_params(dashboard_vo, params, version_change_keys):
self.dashboard_mgr.increase_version(dashboard_vo)
Expand Down Expand Up @@ -402,11 +407,11 @@ def _has_version_key_in_params(
return False

@staticmethod
def _merge_settings(old_settings: dict, new_settings: dict) -> dict:
settings = copy.deepcopy(old_settings)
def _merge_dict(old_dict: dict, new_dict: dict) -> dict:
settings = copy.deepcopy(old_dict)

if old_settings:
settings.update(new_settings)
if old_dict:
settings.update(new_dict)
return settings
else:
return new_settings
return new_dict
17 changes: 11 additions & 6 deletions src/spaceone/dashboard/service/public_dashboard_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,15 @@ def update(self, params):
params["name"] = dashboard_vo.name

if "settings" in params:
params["settings"] = self._merge_settings(
params["settings"] = self._merge_dict(
dashboard_vo.settings, params["settings"]
)

if "display_info" in params:
params["display_info"] = self._merge_dict(
dashboard_vo.display_info, params["display_info"]
)

version_change_keys = ["layouts", "variables", "variables_schema"]
if self._has_version_key_in_params(dashboard_vo, params, version_change_keys):
self.dashboard_mgr.increase_version(dashboard_vo)
Expand Down Expand Up @@ -427,11 +432,11 @@ def _has_version_key_in_params(
return False

@staticmethod
def _merge_settings(old_settings: dict, new_settings: dict) -> dict:
settings = copy.deepcopy(old_settings)
def _merge_dict(old_dict: dict, new_dict: dict) -> dict:
settings = copy.deepcopy(old_dict)

if old_settings:
settings.update(new_settings)
if old_dict:
settings.update(new_dict)
return settings
else:
return new_settings
return new_dict

0 comments on commit dc4a808

Please sign in to comment.