Add track-by for updating hz-resource-table
hz-resource-table needs track-by attribute for refreshing rows. And the identifier for track-by in each items needs timestamp (created_at, updated_at or somthing) to detect difference between old and new records. This patch adds track-by attribute for hz-resource-table tag, and set ID and timestamp into trackBy attribute for each items. Change-Id: I6217b1397bf4448f21b0bb1663d09bd552c0280a
This commit is contained in:
parent
196c7af8f0
commit
5f161d21b6
@ -21,6 +21,7 @@ from openstack_dashboard.api import base
|
||||
|
||||
# for stab, should remove when use CLI API
|
||||
import copy
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
|
||||
@ -78,6 +79,7 @@ def {{cookiecutter.panel}}_create(request, **kwargs):
|
||||
|
||||
# create dummy response
|
||||
args["uuid"] = uuid.uuid1().hex
|
||||
args["created_at"] = datetime.now().isoformat()
|
||||
created = StubResponse(args)
|
||||
for k in args:
|
||||
setattr(created, k, args[k])
|
||||
@ -98,6 +100,7 @@ def {{cookiecutter.panel}}_update(request, id, **kwargs):
|
||||
|
||||
# update dummy response
|
||||
args["uuid"] = id
|
||||
args["updated_at"] = datetime.now().isoformat()
|
||||
updated = StubResponse(args)
|
||||
for k in args:
|
||||
setattr(updated, k, args[k])
|
||||
|
@ -1,5 +1,6 @@
|
||||
<hz-resource-panel resource-type-name="OS::{{cookiecutter.api_name}}::{{cookiecutter.panel_func}}">
|
||||
<hz-resource-table resource-type-name="OS::{{cookiecutter.api_name}}::{{cookiecutter.panel_func}}">
|
||||
<hz-resource-table resource-type-name="OS::{{cookiecutter.api_name}}::{{cookiecutter.panel_func}}"
|
||||
track-by="trackBy">
|
||||
</hz-resource-table>
|
||||
</hz-resource-panel>
|
||||
|
||||
|
@ -41,7 +41,17 @@
|
||||
};
|
||||
|
||||
function getPromise(params) {
|
||||
return api.get{{cookiecutter.panel_func}}s(params);
|
||||
return api.get{{cookiecutter.panel_func}}s(params).then(modifyResponse);
|
||||
}
|
||||
|
||||
function modifyResponse(response) {
|
||||
return {data: {items: response.data.items.map(modifyItem)}};
|
||||
|
||||
function modifyItem(item) {
|
||||
var timestamp = item.updated_at ? item.updated_at : item.created_at;
|
||||
item.trackBy = item.id.concat(timestamp);
|
||||
return item;
|
||||
};
|
||||
}
|
||||
|
||||
function urlFunction(item) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user