Merge "Set unique identifier for Django messages"

This commit is contained in:
Zuul 2020-09-24 02:58:27 +00:00 committed by Gerrit Code Review
commit 63adae95ba
7 changed files with 38 additions and 18 deletions

View File

@ -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.

View File

@ -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;
}
}
})();

View File

@ -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,

View File

@ -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;
}
};

View File

@ -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 %}

View File

@ -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]]

View File

@ -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>