fix editing task name and time from webui

This commit is contained in:
Ziad-I
2024-07-03 22:18:52 +03:00
committed by Dion Moult
parent 166e75db3f
commit 78dd4856eb
2 changed files with 17 additions and 5 deletions
@@ -1544,6 +1544,13 @@ class Sequence(blenderbim.core.tool.Sequence):
def generate_gantt_browser_chart(
cls, task_json: list[dict[str, Any]], work_schedule: ifcopenshell.entity_instance
) -> None:
# with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html"), "w") as f:
# with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.mustache"), "r") as t:
# task_b64 = base64.b64encode(bytes(json.dumps(task_json), "utf-8")).decode("utf-8")
# f.write(
# pystache.render(t.read(), {"json_data": task_b64, "data": json.dumps(work_schedule.get_info())})
# )
# webbrowser.open("file://" + os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html"))
gantt_data = {"tasks": task_json, "work_schedule": work_schedule.get_info(recursive=True)}
tool.Web.send_webui_data(extra_data=gantt_data, extra_data_key="gantt_data", event="gantt_data")
+10 -5
View File
@@ -39,7 +39,7 @@ web_operator_queue = queue.Queue()
IFC_TASK_ATTRIBUTE_MAP = {
"pStart": "ScheduleStart",
"pEnd": "ScheduleFinish",
"pName": "",
"pName": "Name",
"pRes": "",
}
@@ -175,17 +175,22 @@ class Web(blenderbim.core.tool.Web):
ifc_file = tool.Ifc.get()
if operator_data["type"] == "editTask":
task_id = int(operator_data["taskId"])
task_time = ifc_file.by_id(task_id).TaskTime
task = ifc_file.by_id(task_id)
task_time = task.TaskTime
column = operator_data["column"]
new_value = operator_data["value"]
# editing a parent task time will throw an exception
try:
ifcopenshell.api.sequence.edit_task(
ifc_file, task, attributes={IFC_TASK_ATTRIBUTE_MAP[column]: str(new_value)}
)
except AttributeError:
if task_time is None:
ifcopenshell.api.sequence.add_task_time(ifc_file, task)
task_time = task.TaskTime
ifcopenshell.api.sequence.edit_task_time(
ifc_file, task_time=task_time, attributes={IFC_TASK_ATTRIBUTE_MAP[column]: str(new_value)}
)
except AttributeError:
pass
bpy.ops.bim.load_task_properties()