From c375c485eb22fa1a068e77d5af23b78a66e51fd0 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 17 2016 16:09:24 +0000 Subject: [PATCH 1/4] Only send notification to redis when the value of the custom field changed --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 126e2e2..3995f2c 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -3368,16 +3368,34 @@ def set_custom_key_value(session, issue, key, value): ) current_field = query.first() + updated = False if current_field: - current_field.value = value + if current_field.key.key_type == 'boolean': + value = value or False + if current_field.value != value: + current_field.value = value + updated = True else: current_field = model.IssueValues( issue_uid=issue.uid, key_id=key.id, value=value, ) + updated = True session.add(current_field) + if REDIS and updated: + if issue.private: + REDIS.publish('pagure.%s' % issue.uid, json.dumps({ + 'issue': 'private', + 'custom_fields': [key.name], + })) + else: + REDIS.publish('pagure.%s' % issue.uid, json.dumps({ + 'custom_fields': [key.name], + 'issue': issue.to_json(public=True, with_comments=False), + })) + return 'Custom key adjusted' From 51417f8447de63ecf2faf607498e4aa0c3db73a2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 17 2016 16:09:24 +0000 Subject: [PATCH 2/4] Improve a little the debugging in the issue page --- diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index dcb098a..38dd952 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -594,7 +594,6 @@ source.addEventListener('message', function(e) { {% if authenticated and form %} function set_ui_for_comment(setting){ - console.log(setting) if (setting == false) { $(document.body).find('input[type="submit"]').removeAttr("disabled"); document.body.style.cursor = 'default'; @@ -604,6 +603,7 @@ function set_ui_for_comment(setting){ } } function try_async_comment(form) { + console.log('Submitting form:'); console.log(form); set_ui_for_comment(true); var _data = $(form).serialize(); From bcb222a887e23925ad7ed0e4f1ceb9d0e881860e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 17 2016 16:09:24 +0000 Subject: [PATCH 3/4] Let the backend worry about the value sent by the user This is required for the boolean type of custom fields to work --- diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index eb73d85..3ae3542 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -269,11 +269,10 @@ def update_issue(repo, issueid, username=None, namespace=None): # Update the custom keys/fields for key in repo.issue_keys: value = flask.request.form.get(key.name) - if value: - messages.add( - pagure.lib.set_custom_key_value( - SESSION, issue, key, value) - ) + messages.add( + pagure.lib.set_custom_key_value( + SESSION, issue, key, value) + ) # Update ticket this one depends on messages.union(set(pagure.lib.update_dependency_issue( From fbb2a2331370321fe9ccca4b476b274652aa5243 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 17 2016 16:09:24 +0000 Subject: [PATCH 4/4] Add support for custom fields live update on SSE events --- diff --git a/pagure/static/issue_ev.js b/pagure/static/issue_ev.js index f7af738..43a3cc7 100644 --- a/pagure/static/issue_ev.js +++ b/pagure/static/issue_ev.js @@ -200,6 +200,37 @@ update_issue = function(data) { } } +update_custom_fields = function(data) { + console.log('Adjusting custom fields ' + data.custom_fields); + for (i=0; i