Skip to content

Commit

Permalink
Merge pull request #4514 from mikhailprivalov/saveChangeGroupFroField
Browse files Browse the repository at this point in the history
Save change group fro field
  • Loading branch information
urchinpro authored Dec 2, 2024
2 parents 088c651 + 04de1d4 commit 55c3b3b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
2 changes: 2 additions & 0 deletions api/researches/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
path('get-research-performer', views.get_research_performer),
path('get-research-permissions', views.get_research_permissions),
path('save-research-permissions', views.save_research_permissions),
path('change-group-field', views.change_group_field),

]
35 changes: 35 additions & 0 deletions api/researches/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,19 @@ def researches_update(request):
f.save()
if department_template_field:
department_template_field.save()
if field.get("newGroupId"):
new_group_id = field.get("newGroupId")
new_group = ParaclinicInputGroups.objects.filter(pk=new_group_id).first()
if new_group.research != res:
request_data["changeGroup"] = "Попытка указать id из другой услуги"
else:
old_group_id = f.group_id
fields_new_group = ParaclinicInputField.objects.filter(group_id=field.get("newGroupId")).order_by('order').last()
new_order_number = fields_new_group.order + 1
f.group_id = new_group_id
f.order = new_order_number
f.save()
request_data["changeGroup"] = f"Изменена группа с {old_group_id} на {new_group_id}"

if f.default_value == '':
continue
Expand Down Expand Up @@ -1260,3 +1273,25 @@ def save_research_permissions(request):
user_ids = request_data.get('userIds')
result = ConstructorEditAccessResearch.save_permissions(research_id, department_id, user_ids)
return JsonResponse(result)


@login_required
@group_required("Оператор", "Конструктор: Параклинические (описательные) исследования")
def change_group_field(request):
request_data = json.loads(request.body)
field_id = request_data.get('fieldId')
new_group_id = request_data.get('groupId')
research_id = request_data.get('researchId')
current_field = ParaclinicInputField.objects.filter(id=field_id).first()
current_research_id = current_field.group.research_id
if current_research_id != research_id:
result = {"ok": False, "message": "ошибка услуги"}
else:
fields_new_group = ParaclinicInputField.objects.filter(group_id=new_group_id).order_by('order').last()
new_order_number = fields_new_group.order + 1
current_field.group_id = new_group_id
current_field.order = new_order_number
current_field.save()
result = {"ok": True, "message": "Группа изменена"}

return JsonResponse(result)
11 changes: 4 additions & 7 deletions l2-frontend/src/construct/ParaclinicResearchEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ export default {
showAllDepartmentForTemplateField: false,
userDepartmentId: null,
showPermissionsModal: false,
possibleGroupsForField: [],
possibleGroupForField: [],
};
},
computed: {
Expand Down Expand Up @@ -1400,6 +1400,7 @@ export default {
await this.loadDepartmentsForPermissions();
await this.load_deparments();
await this.loadDynamicDirectories();
this.findPossibleGroupForField();
},
mounted() {
window.$(window).on('beforeunload', () => {
Expand Down Expand Up @@ -1705,7 +1706,6 @@ export default {
if (this.ex_deps.length > 0 && this.site_type === null) {
this.site_type = this.ex_deps[0].pk;
}
this.findPossibleGroupsForField();
},
cancel() {
// eslint-disable-next-line no-restricted-globals,no-alert
Expand Down Expand Up @@ -1799,8 +1799,8 @@ export default {
closePermissionsModal() {
this.showPermissionsModal = false;
},
findPossibleGroupsForField() {
this.possibleGroupsForField = this.groups.map(group => ({ id: group.pk, label: group.pk }));
findPossibleGroupForField() {
this.possibleGroupForField = this.groups.map(group => ({ id: group.pk, label: group.pk }));
},
},
};
Expand Down Expand Up @@ -2015,7 +2015,4 @@ export default {
.no-margin-left {
margin-left: 0 !important;
}
.change-field-group {
margin-top: 6px;
}
</style>

0 comments on commit 55c3b3b

Please sign in to comment.