diff options
author | Zuul <zuul@review.opendev.org> | 2020-09-24 02:58:27 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2020-09-24 02:58:27 +0000 |
commit | 63adae95ba035debee0421e15f9baad9015e94b3 (patch) | |
tree | 763098d4c7909f78422a9f762d13768de28cf505 | |
parent | 110664b4beec592b037c42ad6e3f031ccdccd106 (diff) | |
parent | 1b8627c0988d18eaad0d5c4285acab5fa7b8dad4 (diff) | |
download | horizon-63adae95ba035debee0421e15f9baad9015e94b3.tar.gz |
Merge "Set unique identifier for Django messages"
-rw-r--r-- | horizon/karma.conf.js | 1 | ||||
-rw-r--r-- | horizon/static/framework/util/uuid/uuid.js | 15 | ||||
-rw-r--r-- | horizon/static/horizon/js/horizon.messages.js | 2 | ||||
-rw-r--r-- | horizon/static/horizon/js/horizon.uuid.js | 27 | ||||
-rw-r--r-- | horizon/templates/horizon/_messages.html | 6 | ||||
-rw-r--r-- | horizon/templates/horizon/client_side/_alert_message.html | 4 | ||||
-rw-r--r-- | openstack_dashboard/templates/horizon/_scripts.html | 1 |
7 files changed, 38 insertions, 18 deletions
diff --git a/horizon/karma.conf.js b/horizon/karma.conf.js index f05dc11f9..91b80f86c 100644 --- a/horizon/karma.conf.js +++ b/horizon/karma.conf.js @@ -81,6 +81,7 @@ module.exports = function (config) { // from jasmine_tests.py; only those that are deps for others 'horizon/js/horizon.js', + 'horizon/js/horizon.uuid.js', /** * First, list all the files that defines application's angular modules. diff --git a/horizon/static/framework/util/uuid/uuid.js b/horizon/static/framework/util/uuid/uuid.js index a728934f5..569349e84 100644 --- a/horizon/static/framework/util/uuid/uuid.js +++ b/horizon/static/framework/util/uuid/uuid.js @@ -27,19 +27,8 @@ * have unique IDs for interactions. */ function uuidService() { - var service = { - generate: generate + return { + generate: horizon.uuid.generate }; - return service; - - function generate() { - var d = new Date().getTime(); - var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - var r = (d + Math.random() * 16) % 16 | 0; - d = Math.floor(d / 16); - return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); - }); - return uuid; - } } })(); diff --git a/horizon/static/horizon/js/horizon.messages.js b/horizon/static/horizon/js/horizon.messages.js index 33cb8f4ca..94d654efe 100644 --- a/horizon/static/horizon/js/horizon.messages.js +++ b/horizon/static/horizon/js/horizon.messages.js @@ -39,9 +39,11 @@ horizon.alert = function (type, message, extra_tags, details) { return str.split('\u2026'); } + var id = horizon.uuid.generate(); var template = horizon.templates.compiled_templates["#alert_message_template"], params = { "type": type || 'default', + "id": id, "type_display": type_display, "message": message, "safe": safe, diff --git a/horizon/static/horizon/js/horizon.uuid.js b/horizon/static/horizon/js/horizon.uuid.js new file mode 100644 index 000000000..53a6b732d --- /dev/null +++ b/horizon/static/horizon/js/horizon.uuid.js @@ -0,0 +1,27 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +horizon.uuid = { + + generate: function() { + var d = new Date().getTime(); + var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = (d + Math.random() * 16) % 16 | 0; + d = Math.floor(d / 16); + return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); + }); + return uuid; + } +}; + diff --git a/horizon/templates/horizon/_messages.html b/horizon/templates/horizon/_messages.html index 7d19a48a2..e18925396 100644 --- a/horizon/templates/horizon/_messages.html +++ b/horizon/templates/horizon/_messages.html @@ -35,9 +35,9 @@ {% with message.message|split_message as messages %} <strong>{% trans "Error: " %}</strong>{{ messages|first }} {% if messages|length > 1 %} - <a href="#message_details" data-toggle="collapse" - data-target="#message_details">Details</a> - <div id="message_details" class="collapse"> + <a href="#message_details" data-toggle="collapse" + data-target="#message_details_{{ forloop.counter }}">Details</a> + <div id="message_details_{{ forloop.counter }}" class="collapse"> {{ messages|last }} </div> {% endif %} diff --git a/horizon/templates/horizon/client_side/_alert_message.html b/horizon/templates/horizon/client_side/_alert_message.html index cc2863718..c5a28349c 100644 --- a/horizon/templates/horizon/client_side/_alert_message.html +++ b/horizon/templates/horizon/client_side/_alert_message.html @@ -16,8 +16,8 @@ [[^safe]] [[message]] <a id="details_link" href="#message_details" data-toggle="collapse" - data-target="#message_details">Details</a> - <div id="message_details" class="collapse"> + data-target="#message_details_[[id]]">Details</a> + <div id="message_details_[[id]]" class="collapse"> [[details]] </div> [[/safe]] diff --git a/openstack_dashboard/templates/horizon/_scripts.html b/openstack_dashboard/templates/horizon/_scripts.html index 7e56f029f..a400a2eab 100644 --- a/openstack_dashboard/templates/horizon/_scripts.html +++ b/openstack_dashboard/templates/horizon/_scripts.html @@ -28,6 +28,7 @@ <script src='{{ STATIC_URL }}horizon/js/horizon.messages.js'></script> <script src='{{ STATIC_URL }}horizon/js/horizon.modals.js'></script> <script src='{{ STATIC_URL }}horizon/js/horizon.hacks.js'></script> +<script src='{{ STATIC_URL }}horizon/js/horizon.uuid.js'></script> <script type="text/javascript"> horizon.modals.MODAL_BACKDROP = "{% firstof HORIZON_CONFIG.modal_backdrop 'static' %}"; </script> |